<%INIT>

# Show status in colour.
sub statusInColor {
	my $Ticket = shift;
	my $status = $Ticket->Status;
	my $css = "status" . lc $status;
	my $cssreply = "status" . lc "reply";
	my $LastUpdater = $Ticket->LastUpdatedByObj->EmailAddress;
	my $TicketRequestors = $Ticket->Requestors->MemberEmailAddressesAsString;
	my $TicketCC = $Ticket->Cc->MemberEmailAddressesAsString;
	my $CurrentUser = $session{'CurrentUser'}->EmailAddress;

# Added $CurentUser ne $LastUpdater to prevent showing New Reply tag when the last updater is the current user.
	if (($CurrentUser ne $LastUpdater) && ($TicketRequestors =~ $LastUpdater) || ($TicketCC =~ $LastUpdater))
	{
		my $txn = $Ticket->SeenUpTo or return \"<div class=\"$css\">$status</div>";
#       my $TicketLink = RT->Config->Get('WebPath') ."/Ticket/Display.html?id=". $Ticket->id. "#txn-".$txn->id;
# Comment out the line above and uncomment the following line to mark posts as seen when following link.
		my $TicketLink = RT->Config->Get('WebPath') ."/Ticket/Display.html?id=". $Ticket->id ."&MarkAsSeen=1".  "#txn-".$txn->id;
		$status = "<div class=\"$css\">$status <a href=\"$TicketLink\"><span class=\"$cssreply\">New Reply</span></a></div>";
	}
	else {
		$status = "<div class=\"$css\">$status</div>";
	}

	return \"$status";

}

# Show extended status in colour. This will change the front page and other search pages where the ExtendedStatus is displayed.
sub extStatusInColor {
	my $Ticket = shift;
	if ( my $count = $Ticket->HasUnresolvedDependencies ) {
		my $status;

		if ( $Ticket->HasUnresolvedDependencies( Type => 'approval' )
				or $Ticket->HasUnresolvedDependencies( Type => 'code' ) ) {
			$status = "<em>" . loc('(pending approval)') . "</em>";
		} else {
			$status = "<font color=#000090><em>" . loc('(pending [quant,_1,other ticket])',$count) . "</em></font>";
			}
		return \$status;
	} else {
		return statusInColor($Ticket);

	}
}

# Set the priority numbers to a colour.
sub PriorityInColor {
	my $Ticket = shift;

	my $priority = $Ticket->Priority;
	my $colors = undef;

# Change priority numbers to reflect your priority system.
	if ($priority >= '50') {
		$colors = "#FF0000";
	} elsif ($priority >= '45') {
		$colors = "#FF2000";
	} elsif ($priority >= '40') {
		$colors = "#FF4000";
	} elsif ($priority >= '35') {
		$colors = "#FF6A00";
	} elsif ($priority >= '30') {
		$colors = "#FF6600";
	} elsif ($priority >= '25') {
		$colors = "#FFA000";
	} elsif ($priority >= '20') {
		$colors = "#0033CC";
	} elsif ($priority >= '15') {
		$colors = "#809FFE";
	} elsif ($priority >= '10') {
		$colors = "#004600";
	} elsif ($priority >= '5') {
		$colors = "#006400";
	} elsif ($priority >= '0') {
		$colors = "#009000";
	}

	if ($colors) {
		$priority = "<div style=\"color: $colors;\">$priority</div>"
	}

		return \"<b>$priority</b>";
}

# Comment out any line to disable colour change.
$COLUMN_MAP->{Priority}->{value} = \&PriorityInColor;
$COLUMN_MAP->{Status}->{value} = \&statusInColor;
$COLUMN_MAP->{ExtendedStatus}->{value} = \&extStatusInColor;

</%INIT>
<%ARGS>
$COLUMN_MAP => undef
</%ARGS>
