Complete Solution for Next/Previous Ticket
Hi everyone,
I had tried the code above, and I have found something as follow:
- If you are on the first record, then the "Previous | Next" link doesn't appear
- If you are on the last record, then the "Next" link has value "" and if you click on it, you would be redirected to the list page that showing all records.
I have modified the code above in order:
- If you are on the first record, then the "Previous | Next" still appear but the "Previous" without link on it.
- If you are on the last record, then the "Previous | Next" still appear but the "Next" without link on it.
- I also added "First" and "Last" link on Next/Previous link. Of course, with verification process which link should be appear or not. Is it wonderful for you? ;-)
Because the modification I made based on jpowers40828's post on 10-03-2008 03 AM, I assuming I still refer to his modification he made on that post. So, in these instructions below, "find" meaning "search for jpowers40828's modification" on the file. I hope you understand what I mean.
Let's getting started now:
In include/staff/viewticket.inc.php find:
if($thisuser->isAdmin()) {
$prev = mysql_result(mysql_query("SELECT ticket_id FROM ".TICKET_TABLE." WHERE ticket_id < ".$id." AND status = '".$ticket->getStatus()."' ORDER BY ticket_id DESC"),0);
$next = mysql_result(mysql_query("SELECT ticket_id FROM ".TICKET_TABLE." WHERE ticket_id > ".$id." AND status = '".$ticket->getStatus()."' ORDER BY ticket_id ASC"),0);
}
else{
$prev = mysql_result(mysql_query("SELECT ticket_id FROM ".TICKET_TABLE." WHERE ticket_id < ".$id." AND status = '".$ticket->getStatus()."' AND dept_id = '".$ticket->getDeptId()."' AND (staff_id = 0 OR staff_id = '".$thisuser->getId()."') ORDER BY ticket_id DESC"),0);
$next = mysql_result(mysql_query("SELECT ticket_id FROM ".TICKET_TABLE." WHERE ticket_id > ".$id." AND status = '".$ticket->getStatus()."' AND dept_id = '".$ticket->getDeptId()."' AND (staff_id = 0 OR staff_id = '".$thisuser->getId()."') ORDER BY ticket_id ASC"),0);
}
replace with:
if($thisuser->isAdmin()) {
$prev = mysql_result(mysql_query("SELECT ticket_id FROM ".TICKET_TABLE." WHERE ticket_id < ".$id." AND status = '".$ticket->getStatus()."' ORDER BY ticket_id DESC"),0);
$next = mysql_result(mysql_query("SELECT ticket_id FROM ".TICKET_TABLE." WHERE ticket_id > ".$id." AND status = '".$ticket->getStatus()."' ORDER BY ticket_id ASC"),0);
$maxid = mysql_result(mysql_query("SELECT MAX(ticket_id) FROM ".TICKET_TABLE." WHERE status = '".$ticket->getStatus()."'"),0);;
$minid = mysql_result(mysql_query("SELECT MIN(ticket_id) FROM ".TICKET_TABLE." WHERE status = '".$ticket->getStatus()."'"),0);;
}
else{
$prev = mysql_result(mysql_query("SELECT ticket_id FROM ".TICKET_TABLE." WHERE ticket_id < ".$id." AND status = '".$ticket->getStatus()."' AND dept_id = '".$ticket->getDeptId()."' AND (staff_id = 0 OR staff_id = '".$thisuser->getId()."') ORDER BY ticket_id DESC"),0);
$next = mysql_result(mysql_query("SELECT ticket_id FROM ".TICKET_TABLE." WHERE ticket_id > ".$id." AND status = '".$ticket->getStatus()."' AND dept_id = '".$ticket->getDeptId()."' AND (staff_id = 0 OR staff_id = '".$thisuser->getId()."') ORDER BY ticket_id ASC"),0);
$maxid = mysql_result(mysql_query("SELECT MAX(ticket_id) FROM ".TICKET_TABLE." WHERE status = '".$ticket->getStatus()."' AND dept_id = '".$ticket->getDeptId()."' AND (staff_id = 0 OR staff_id = '".$thisuser->getId()."')"),0);;
$minid = mysql_result(mysql_query("SELECT MIN(ticket_id) FROM ".TICKET_TABLE." WHERE status = '".$ticket->getStatus()."' AND dept_id = '".$ticket->getDeptId()."' AND (staff_id = 0 OR staff_id = '".$thisuser->getId()."')"),0);;
}
In include/staff/viewticket.inc.php find:
<td class="msg">
Ticket #<?=$ticket->getExtId()?> <a href="tickets.php?id=<?=$id?>" title="Reload"><span class="Icon refresh"> </span></a></td><td align="right"><? if($prev!="") {?><a href="tickets.php?id=<?=$prev?>">Previous</a><? }?><? if($prev!="" && $next!="") echo " | ";?><? if($next!="") {?><a href="tickets.php?id=<?=$next?>">Next</a><? }?></td>
replace with:
<td class="msg">
Ticket #<?php echo $ticket->getExtId()?> <a href="tickets.php?id=<?php echo $id?>" title="Reload/refresh"><span class="Icon refresh"> </span></a></td>
<td align="right">
<?php if (($prev=="") && ($next=="") ) { ?>
First | Previous | Next | Last
<?php } else if(($prev=="") && ($id==$minid)) {?>
First | Previous | <a href="tickets.php?id=<?php echo $next?>">Next</a> | <a href="tickets.php?id=<?php echo $maxid?>">Last</a>
<?php } else if (($prev!="") && ($next!="") && ($id!=$minid) && ($id!=$maxid)) { ?>
<a href="tickets.php?id=<?php echo $minid?>">First</a> | <a href="tickets.php?id=<?php echo $prev?>">Previous</a> | <a href="tickets.php?id=<?php echo $next?>">Next</a> | <a href="tickets.php?id=<?php echo $maxid?>">Last</a>
<?php } else { ?>
<a href="tickets.php?id=<?php echo $minid?>">First</a> | <a href="tickets.php?id=<?php echo $prev?>">Previous</a> | Next | Last
<?php } ?>
</td>
That's all, everyone. Hope this helpful for you. :-)
Best regards,
Masino Sinaga