PDA

View Full Version : Next/Previous Ticket


sornman
04-06-2008, 12:19 AM
Couldn't find anything by searching, but some of my users have asked about 'previous/next' links while viewing a ticket. That way you can view another ticket without having to go back to the queue and select it, just hit the 'previous' or 'next' button to go to that ticket.

jpowers40828
10-02-2008, 04:44 PM
In include/staff/viewticket.inc.php ~ line 22 find

if(!$errors['err'] && ($emailBanned=BanList::isbanned($ticket->getEmail())))
$errors['err']='Email is in banlist! Must be removed before any reply/response';
if($ticket->isOverdue())
$warn.='<span class="Icon overdueTicket">Marked overdue!</span>';

After it, add

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);
}


Then in include/staff/viewticket.inc.php ~ line 34 find

<td colspan=2 class="msg">
Ticket #<?=$ticket->getExtId()?>&nbsp;<a href="tickets.php?id=<?=$id?>" title="Reload"><span class="Icon refresh">&nbsp;</span></a></td>


And replace it with

<td class="msg">
Ticket #<?=$ticket->getExtId()?>&nbsp;<a href="tickets.php?id=<?=$id?>" title="Reload"><span class="Icon refresh">&nbsp;</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>

donp_iri
12-11-2008, 12:04 PM
Excellent! This is a great addition. If you are going to do this mod it will look a little better if you remove the colspan="2" attribute from the <td> tag that holds the ticket number.

jpowers40828
12-11-2008, 12:17 PM
Thanks for that, I had done it in my code, but forgot about it when putting in the mod. I've changed the original post to include your change.

masino_sinaga
04-12-2009, 02:50 AM
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:44 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()?>&nbsp;<a href="tickets.php?id=<?=$id?>" title="Reload"><span class="Icon refresh">&nbsp;</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()?>&nbsp;<a href="tickets.php?id=<?php echo $id?>" title="Reload/refresh"><span class="Icon refresh">&nbsp;</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

kilahimm
05-04-2009, 04:01 PM
I tried the mod you suggested and I'm getting two small errors:

On the last ticket:
Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 38 in ..\include\staff\viewticket.inc.php on line 28

Line 28 is $next

On the first ticket:

Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 36 in ..\include\staff\viewticket.inc.php on line 27

Line 27 is $prev

This is happening for non-admin users as well.

Anything in-between displays fine. Any what might be wrong?

jpowers40828
05-04-2009, 04:59 PM
Do the links still work? It may be warning you because the query is not returning anything? Can you send a screen shot?

jpowers40828@gmail.com

Its returning a warning because there is no result because it is at their are no results. The warning is hurting anything, but you should check your php.ini You will want to turn off error displaying.

display_errors = Off
display_startup_errors = Off

kilahimm
05-05-2009, 09:51 AM
I took a look at it again and it seems that my problem has something to do with this mod plus the print preview mod. When I use this mod without that one the errors aren't produced.

scottro
07-24-2009, 04:52 PM
Masino,

I think this may be deprecated now. I'm on the latest osTickets as of five days ago and I have done a 'grep -r "ORDER BY ticket_id DESC"' under my base install directory but I cannot find this entry. Also specifically looked in the file you mentioned include/staff/viewticket.inc.php and found nothing there. Please let me know if this is something I can implement in another location.

Thanks!

scottro
07-24-2009, 04:54 PM
Nevermind! I see I probably need to implement jpowers40828 MOD first and then enter in yours.

dcabai
08-10-2009, 01:54 AM
Nice work, but it works fine for me without the second modification. I don't have the errors for the first or last ticket, so works fine with the first set of code.

I made some modification for the style of the Next Previous text to fit my theme, but works fine.

Thanks!

CurtisPenner
08-14-2009, 02:14 PM
Nice mod. Thanks for your efforts.

scottro
08-17-2009, 01:05 PM
I modified this on mine to only pay attention to tickets with an 'open' status.

Works great, thanks!