Change color of text

I am trying to change the color of text on a list based on date.

For example I have employees that have certifications with expiration dates What I would like to do is when the certification is coming near expiration I want it to change colors.

  • > 120 days Green
  • < 120 days Orange
  • < 90 day Red
How would I go about this....

Here is a link to my list
http://daymarems.com/employees
 
You would have to create a custom template for this or you could do it via a calc element.

This is a very basic example with a calc element, not exactly what you are asking but the principle would eb the same modiying the PHP.

http://fabrikar.com/forums/showthread.php?t=27059


There's a few template examples as well on the forums.

What's you PHP like?
 
Not strictly, there is some stuff on the Wiki and tons of examples on the forums.

I created this for you which seems to work, you would place this text in a calc element.

Code:
$date = '{[B][COLOR=Red]colortext___date[/COLOR][/B]_raw}';

if ( strtotime( $date ) < strtotime( '90 days' ) ) {
    return "<FONT style=\"COLOR: red\">" . $date . " </FONT>";
} // If less than 90 days

else if ( strtotime( $date ) < strtotime( '120 days' ) ) {
    return "<FONT style=\"COLOR: orange\">" . $date . " </FONT>";
} // If less than 120 days

else
    return "<FONT style=\"COLOR: green\">" . $date . " </FONT>";
    // Otherwise be Green!
You need to change the colortext___date above to the listname___elementname of your date field. This is all assuming everything is in the same table.

see attachment
 

Attachments

  • Colours with a U.png
    Colours with a U.png
    24.2 KB · Views: 279
I am also trying to calculate days until expired this is what I was using in the calc

DATEDIFF(day,'CURDATE ()','employeecertifications___expiration') AS DiffDate

I get no response from the code
 
This worked GREAT!!!!!!!!!!!! is there a way to take off the time at the end of the date and make the date read mm/dd/yyyy

Code:
$date = '{colortext___date_raw}';

if ( strtotime( $date ) < strtotime( '90 days' ) ) {
    return "<FONT style=\"COLOR: red\">" . date("m/d/Y", strtotime($date)) . " </FONT>";
} // If less than 90 days

else if ( strtotime( $date ) < strtotime( '120 days' ) ) {
    return "<FONT style=\"COLOR: orange\">" . date("m/d/Y", strtotime($date)) . " </FONT>";
} // If less than 120 days

else
    return "<FONT style=\"COLOR: green\">" . date("m/d/Y", strtotime($date)) . " </FONT>";
    // Otherwise be Green!
 
I guess because that's the earliest date Linux knows......


So I guess you need to put in something to cater for a null value.

There are a couple of approaches but you need to decide what you want to display if there is a null value.
 
Well this did fix the solution some what..... If a course does not have any students enrolled then it works.... But if I enroll the student to the course the date shows up when it is not entered?
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top