Here's the code for the whole page:
Code: Select all
<?
if (!$_GET['strip']){include 'header.htm';} else {include 'functions.php';echo "<html><head><link href=\"css/style.css\" rel=\"stylesheet\" type=\"text/css\" /></head><body leftmargin=0 topmargin=0>";}
include 'dbcon.php';
//echo "C:" . $_SESSION['companyfilter'];
//Set Default Filters
if ($_SESSION['statfilter']==NULL){$_GET['statfilter']="My Calls";}
if ($_SESSION['timefilter']==NULL){$_GET['timefilter']="All";}
if ($_SESSION['durfilter']==NULL){$_GET['durfilter']="All";}
if ($_SESSION['queuefilter']==NULL){$_GET['queuefilter']="All";}
if ($_SESSION['chargefilter']==NULL){$_GET['chargefilter']="All";}
if ($_GET['page']!=NULL)
{
$_SESSION['page'] = $_GET['page'];
}
if ($_SESSION['page']==NULL){$_SESSION['page']=1;}
//Does the user want to change or reverse the sort field?
if ($_GET['sort']!=NULL)
{
if ($_GET['sort'] == $_SESSION['sort']){if ($_SESSION['sort_dir']=='DESC'){$_SESSION['sort_dir'] = 'ASC';} else {$_SESSION['sort_dir'] = 'DESC';}}
$_SESSION['sort'] = $_GET['sort'];
}
if ($_GET['statfilter']!=NULL)
{
if ($_GET['statfilter']!=$_SESSION['statfilter'])
{
$_SESSION['statfilter'] = $_GET['statfilter'];
$_SESSION['page']=1;
}
}
if ($_GET['timefilter']!=NULL)
{
$_SESSION['timefilter'] = $_GET['timefilter'];
}
if ($_GET['durfilter']!=NULL)
{
$_SESSION['durfilter'] = $_GET['durfilter'];
}
if ($_GET['queuefilter']!=NULL)
{
$_SESSION['queuefilter'] = $_GET['queuefilter'];
}
if ($_GET['chargefilter']!=NULL)
{
$_SESSION['chargefilter'] = $_GET['chargefilter'];
}
//Convert the sort info into a variable
switch ($_SESSION['sort']){
case NULL:
$sort = "logged DESC, priority DESC,(faultlog.id_prefix + faultlog.id)";
$_GET['sort'][1]='r';
break;
case 0:
$sort = "priority";
break;
case 1:
$sort = "(faultlog.id_prefix + faultlog.id)";
break;
case 2:
$sort = "description";
break;
case 3:
$sort = "logged";
break;
case 4:
$sort = "elapsed";
break;
case 5:
$sort = "engineer";
break;
case 6:
$sort = "company";
break;
case 7:
$sort = "status";
break;
}
$status_low=0;
//Apply any filters
switch ($_SESSION['statfilter'])
{
case 'All Calls':
$filter = "";
$status_low=0;
$status_up=100;
break;
case 'My Calls':
$filter = " AND (faultlog.engid='" . $_SESSION['guid'] . "' OR faultlog.engid='0')";
$status_up=14;
break;
case 'Unassigned Calls':
$filter = " AND faultlog.engid='0'";
$status_up=14;
break;
case 'Open Calls':
$filter = "";
$status_up=14;
break;
case 'Closed Calls':
$filter = "";
$status_low=15;
$status_up=15;
break;
case 'Invoiced Calls':
$filter = "";
$status_low=25;
$status_up=30;
break;
case 'Contract Calls':
$filter = " AND contract=1";
$status_up=100;
break;
}
switch ($_SESSION['timefilter'])
{
case 'All':
break;
case 'Today':
$filter .= " AND logged>DATEADD(d,-1,CURRENT_TIMESTAMP)";
break;
case 'Last Week':
$filter .= " AND logged>DATEADD(d,-7,CURRENT_TIMESTAMP)";
break;
case 'Last Month':
$filter .= " AND logged>DATEADD(m,-1,CURRENT_TIMESTAMP)";
break;
case 'This Year':
$filter .= " AND logged>DATEADD(yyyy,-1,CURRENT_TIMESTAMP)";
break;
}
switch ($_SESSION['durfilter'])
{
case 'All':
break;
case '2 Days':
$filter .= " AND DATEDIFF(s,notes.date,GETDATE())>172800";
break;
case '1 Week':
$filter .= " AND DATEDIFF(s,notes.date,GETDATE())>604800";
break;
}
switch ($_SESSION['chargefilter'])
{
case 'All':
break;
case 'Chargeable':
$filter .= " AND chargable=1";
break;
case 'Non Chargeable':
$filter .= " AND chargable=0";
break;
}
if ($_GET['companyfilter']){$filter .= " AND contact.company='" . $_GET['companyfilter'] . "'";}
if ($_GET['textfilter']){$filter .= " AND ((faultlog.id_prefix+faultlog.id) LIKE '%" . $_GET['textfilter'] . "%' OR faultlog.company LIKE '%" . $_GET['textfilter'] . "%' OR faultlog.description LIKE '%" . $_GET['textfilter'] . "%')";}
$query = mssql_query("SELECT id FROM queue WHERE description='" . $_SESSION['queuefilter'] . "'",$db);
if (mssql_num_rows($query)!=0){$filter .= "AND queueid=" . mssql_result($query,0,0);}
//Compile the database query
$query_string = "
DATEDIFF(s,date,GETDATE()) AS elapsed,
logged,CONVERT(char(10),logged,103) as logged_fmt, faultlog.enduser , faultlog.description, faultlog.id, faultlog.id_prefix, callstatus.name AS
status , contact.forename, calltype.name AS
type , contact.response,company = (case faultlog.company WHEN 'None' THEN faultlog.enduser ELSE faultlog.company END), DATEDIFF(s,logged,faultlog.closed) AS closed, (contact.forename + ' ' + contact.surname) as contact,(engineer.forename + ' ' + engineer.surname) as engineer, priority
FROM faultlog
INNER JOIN engineer ON engineer.id = faultlog.engid
INNER JOIN calltype ON calltype.id = faultlog.typeid
LEFT OUTER JOIN contact ON contact.id = faultlog.contid
INNER JOIN callstatus ON callstatus.id = faultlog.status
LEFT OUTER JOIN notes ON (notes.id = faultlog.id AND notes.id_prefix=faultlog.id_prefix)
WHERE (accountstatus!=2 OR accountstatus IS NULL) AND status<=$status_up AND status>=$status_low AND ((
(
SELECT COUNT( date )
FROM notes
WHERE notes.id = faultlog.id AND notes.id_prefix=faultlog.id_prefix
) =0
) OR (
date !=0 AND date = (
SELECT TOP 1 date
FROM notes
WHERE notes.id = faultlog.id AND notes.id_prefix=faultlog.id_prefix ORDER BY date DESC
))
)";
if ($_SESSION['conts'] && $_SESSION['level']<=3)
{
$query_string .= " AND (";
foreach ($_SESSION['conts'] as $c)
{
$query_string .= "contact.id=" . $c . " OR ";
}
$query_string = substr($query_string,0,strlen($query_string)-3) . ")";
}
$query_string .= $filter;
$query_string .= " ORDER BY " . $sort . " " . $_SESSION['sort_dir'];
$nopages = mssql_num_rows(mssql_query("SELECT " . $query_string));
$query = mssql_query("SELECT TOP (10+ " .($_SESSION['page']-1)*20 . ")" . $query_string,$db);
$_SESSION['curquery'] = $query_string;
//$nopages = mssql_num_rows($query);
if (!$_GET['strip']){
?>
<br>
<table width=100% cellspacing=1 cellpadding=0 class=smooth>
<tr><th class=smooth_title colspan=8><?echo "Last 10 Calls...";?></th><th class=smooth_title style='text-align:center;color:332233;cursor:pointer;' onclick="document.location='printlist.php';">Print</th></tr>
<? } else { echo "<table width=800 cellspacing=1 cellpadding=0 class=smooth>";}// Strip?>
<tr><th class=smooth width=20 onclick="document.location='calllist.php?sort=0&page=1';"> </th><th class=smooth onclick="document.location='calllist.php?sort=1&page=1';">Call ID</th><th class=smooth onclick="document.location='calllist.php?sort=2&page=1';">Description</th><th class=smooth onclick="document.location='calllist.php?sort=3&page=1';">Logged</th><th class=smooth onclick="document.location='calllist.php?sort=4&page=1';">Elapsed</th><th class=smooth>SLA</th><th class=smooth onclick="document.location='calllist.php?sort=5&page=1';">Engineer</th><th class=smooth onclick="document.location='calllist.php?sort=6&page=1';">Company</th><th class=smooth onclick="document.location='calllist.php?sort=7&page=1';">Status</th></tr>
<?
mssql_data_seek($query,($_SESSION['page']-1)*20);
$stripe='';
while ($item = mssql_fetch_array($query))
{
if ($item['closed']==NULL){$el = $item['elapsed'];} else {$el = $item['closed'];}
$days = floor($el / 86400);
$hours = floor(($el - ($days * 86400))/ 3600);
$mins = floor(($el - ($days * 86400) - ($hours * 3600)) / 60);
if ($_SESSION['level']==3)
{
echo "<tr onclick=\"document.location='viewcall.php?id=" . $item['id'] . "&pfx=" . $item['id_prefix']; if($HTTP_SERVER_VARS['QUERY_STRING']){ echo "&";} echo $HTTP_SERVER_VARS['QUERY_STRING'] . "';\"><td class=smooth" . $stripe . "><img src='/images/icons/pri" . $item['priority'] . ".gif'/></td><td align=center class=smooth" . $stripe .">" . $item['id_prefix'] . $item['id'] . "</td><td class=smooth" . $stripe .">" . substr($item['description'],0,50) . "</td><td class=smooth" . $stripe .">" . $item['logged_fmt'] . "</td><td class=smooth" . $stripe .">" . $days . "d " . $hours . "h " . $mins . "m </td><td class=smooth>" . $item['response'] . "</td><td class=smooth" . $stripe ." style=\"color:DD5555;\">" . $item['engineer'] . "</td><td class=smooth" . $stripe .">" . $item['contact'] . "</td><td class=smooth" . $stripe ." style=\"color:5555AA;\">" . $item['status'] . "</td></tr>";
} else {
echo "<tr onclick=\"document.location='viewcall.php?id=" . $item['id'] . "&pfx=" . $item['id_prefix']; if($HTTP_SERVER_VARS['QUERY_STRING']){ echo "&";} echo $HTTP_SERVER_VARS['QUERY_STRING'] . "';\"><td class=smooth" . $stripe . "><img src='/images/icons/pri" . $item['priority'] . ".gif'/></td><td align=center class=smooth" . $stripe .">" . $item['id_prefix'] . $item['id'] . "</td><td class=smooth" . $stripe .">" . substr($item['description'],0,50) . "</td><td class=smooth" . $stripe .">" . $item['logged_fmt'] . "</td><td class=smooth" . $stripe .">" . $days . "d " . $hours . "h " . $mins . "m </td><td class=smooth>" . $item['response'] . "</td><td class=smooth" . $stripe ." style=\"color:DD5555;\">" . $item['engineer'] . "</td><td class=smooth" . $stripe .">" . $item['company'] . "</td><td class=smooth" . $stripe ." style=\"color:5555AA;\">" . $item['status'] . "</td></tr>";
}
if ($stripe=='1'){$stripe='';} else {$stripe='1';}
}
?>
<style="font-size:3px;">
<?
//Summary Table
?>
<table width=100% height=66% cellspacing=1 cellpadding=0 class=smooth>
<tr><th colspan=8 style='text-align:center;background:red;font-size:30px;'><a href='index.php' style=color:white;><?echo"Priority"?></th><th colspan=8 style='text-align:center;background:orange;font-size:30px;'><a href='index.php' style=color:white;><?echo"Routine"?></th></tr>
<tr><th colspan=8 style='text-align:center;background:green;font-size:30px;'><a href='index.php' style=color:white;><?echo"Workshop"?></th><th colspan=8 style='text-align:center;background:blue;font-size:30px;'><a href='index.php' style=color:white;><?echo"Work Req"?></th></tr>
</table>
<meta http-equiv="refresh" content="120;url=calllist.php">
</table>
</td>
</tr>
</table>
<?
include 'footer.htm';
?>