Page 1 of 1
Changing category name color
Posted: Sat Dec 19, 2009 9:14 pm
by fanta
/*************************************
Title: Changing category name color
Version: 2
Short description:
I have used
thispost to add the category name to the table on the admin home page, and it works great.
My question is, how can I set a different color to a specific category name in the table?
I tried wrapping the category name with <font color="red">New category</font> but that just printed out the font tag as well.
Thanks.
*************************************/
(Here below you can write additional info, longer description and comments)
Posted: Mon Dec 21, 2009 4:52 pm
by Klemen
That's because HTML tags are encoded for security. Try using something like
Code: Select all
$newcategory['name'] = preg_replace('/<font color="(.+)">(.*)<\/font>/','<font color="$1">$2</font>',$newcategory['name']);
before printing the category name (assuming you have the category name stored in $newcategory['name'] variable).
Posted: Mon Dec 21, 2009 8:57 pm
by fanta
Thank you Klemen for your reply, but this change brings up a blank table.
What I want to achieve is to have my Category Name 1 in red color, not all categories. other categories should remain with the default color.
Thanks.
Posted: Tue Dec 22, 2009 9:28 am
by Klemen
Post the exact code you use for printing the category name.
Posted: Tue Dec 22, 2009 4:21 pm
by fanta
This is the sql to fetch the category:
$sql = "SELECT * FROM `hesk_categories` WHERE `id`=$ticket[category] LIMIT 1";
$newresult = hesk_dbQuery($sql) or hesk_error("$hesklang[cant_sql]: $sql</p><p>$hesklang[mysql_said]:<br>".mysql_error()."</p><p>$hesklang[contact_webmsater] $hesk_settings[webmaster_mail]");
$newcategory = hesk_dbFetchAssoc($newresult);
This is the print category name:
<td class="$color">$newcategory[name]</td>
thanks for your help.
Posted: Tue Dec 22, 2009 6:16 pm
by Klemen
How about if you add something like
Code: Select all
if ($newcategory['name'] == 'Your category')
{
$newcategory['name'] = '<font color="red">'.$newcategory['name'].'</font>';
}
just below
Code: Select all
$newcategory = hesk_dbFetchAssoc($newresult);
? Change 'Your category' to the exact name of your category (case sensitive).
Posted: Tue Dec 22, 2009 7:06 pm
by fanta
Thank you Klemen, this works like a charm!