<?php

include("postget.php");
checklevel(2, $_REQUEST['clientid']);

if ($_SESSION['hd_userdept']>0) {
    $depto = "AND depid=".$_SESSION['hd_userdept'];
}else{
    $depto = "";
}
$query = "SELECT * FROM hd_tickets WHERE (status=1 OR status=2 OR status=4 OR followup=1) $depto ORDER BY lastreply ASC";
$result = mysql_query($query, $db_link);

echo '<div class="container">
    <div class="row">';

echo mysql_affected_rows() . " " . _TICKETS;
echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href='tickets_panel.php?c=" . $config[37][1] . "' target='_blank' class='btn'>" . ucfirst(_OPEN_TICKETS_PANEL) . "</a>";


echo '<br>

<table class="table table-striped">
';

print("<thead><tr>
	<th>" . ucfirst(_STATUS) . "</th> 
	<th>" . ucfirst(_VIEW) . "</th> 
	<th>" . ucfirst(_LAST_REPLY) . "</th> 
	<th>" . ucfirst(_ID) . "</th> 
	<th>" . ucfirst(_PRIORITY) . "</th> 
	<th>" . ucfirst(_DEPARTMENT) . "</th> 
	<th>" . ucfirst(_SUBJECT) . "</th> 
	<th>" . ucfirst(_MESSAGE) . "</th> 
	</tr></thead><tbody>");



$bgc = true;
$now = time() + $config[31][1] * 3600;
while ($tickets = mysql_fetch_array($result)) {
    echo '<tr>';
    if ($tickets[followup] == '1') {
        $fondo = 'bgcolor=gray';
        $img_followup = "<img class='sprites followup' src='images/transparent.gif' title='" . ucfirst(_FOLLOW_UP) . "'>&nbsp;&nbsp;&nbsp;";
    } else {
        $fondo = '';
        $img_followup = '';
    }



    if ($tickets[status] == '1') {
        print("<td align='center'><b><font color='red'>" . strtoupper(_NEW) . "</font></b>$img_followup</td>");
    } elseif ($tickets[status] == '2') {
        print("<td align='center'><b><font color='yellow'>" . strtoupper(_PENDING) . "</font></b>$img_followup</td>");
    } elseif ($tickets[status] == '3') {
        print("<td align='center'><b><font color='green'>" . strtoupper(_ANSWERED) . "</font></b>$img_followup</td>");
    } elseif ($tickets[status] == '4') {
        print("<td align='center'><b><font color='orange'>" . strtoupper(_CUSTOMER_REPLY) . "</font></b>$img_followup</td>");
    } elseif ($tickets[status] == '5') {
        print("<td align='center'><b><font color='gray'>" . strtoupper(_CLOSED) . "</font></b>$img_followup</td>");
    } else {
        print("<td>&nbsp;</td>");
    }

    print("<td>
	<a href='ticketsview.php?ticketid=$tickets[ticketid]&clientid=$tickets[clientid]&reference=$tickets[reference]'><b>" . _VIEW . "</b></a>
	</td>");

    print("<td>");
    print(TimeAgo($tickets[lastreply], $now));
    print("</td>");

    print("<td>$tickets[ticketid]</td>");

    switch (strtolower($tickets[priority])) {
        case 'low':
            print("<td>");
            echo lang('_' . $tickets[priority]);
            break;
        case 'medium':
            print("<td>");
            echo lang('_' . $tickets[priority]);
            break;
        case 'high':
            print("<td>");
            echo lang('_' . $tickets[priority]);
            break;
    }
    print("</td>");

    $depto = query('SELECT name FROM hd_tickets_dep WHERE hd_tickets_dep.depid = ' . $tickets[depid], 1);
    print("<td>$depto[0]</td>");



    print("<td>" . substr(strip_tags($tickets[title]), 0, 20) . "...</td>");
    print("<td>" . substr(strip_tags($tickets[message]), 0, 60) . "...</td>");



    print("</tr>");
}

echo '
		</td>
		</tr></tbody>
		</table>
</div>
</div>
';
?> 
