From 9b9dc57b5f3c560cbed36fba40d8c2614f7eb1a9 Mon Sep 17 00:00:00 2001 From: Peter Rotich Date: Fri, 22 Feb 2013 10:45:56 -0500 Subject: [PATCH 1/5] Refactor how ticket count on open queue is done depending on 'show assigned tickets' settings. -> Open - only contains unasssined tickets if 'show assigned tickets' is off. --- include/ajax.tickets.php | 11 ++++++----- include/class.ticket.php | 27 +++++++++++++++++---------- include/staff/tickets.inc.php | 32 ++++++++++++++++++++------------ scp/tickets.php | 14 +++++++------- 4 files changed, 50 insertions(+), 34 deletions(-) diff --git a/include/ajax.tickets.php b/include/ajax.tickets.php index bb834578..d1df0f6c 100644 --- a/include/ajax.tickets.php +++ b/include/ajax.tickets.php @@ -85,10 +85,10 @@ function lookupByEmail() { } function search() { - global $thisstaff; + global $thisstaff, $cfg; $result=array(); - $select = 'SELECT count(ticket.ticket_id) as tickets '; + $select = 'SELECT count( DISTINCT ticket.ticket_id) as tickets '; $from = ' FROM '.TICKET_TABLE.' ticket '; $where = ' WHERE 1 '; @@ -109,7 +109,7 @@ function search() { //Status switch(strtolower($_REQUEST['status'])) { - case 'open'; + case 'open': $where.=' AND ticket.status="open" '; break; case 'overdue': @@ -133,7 +133,9 @@ function search() { $where.=' (ticket.staff_id='.db_input($id). ' AND ticket.status="open") '; if($_REQUEST['staffId'] && !$_REQUEST['status']) //Assigned TO + Closed By - $where.= ' OR (ticket.staff_id='.db_input($_REQUEST['staffId']). ' AND ticket.status="closed") '; + $where.= ' OR (ticket.staff_id='.db_input($_REQUEST['staffId']). ' AND ticket.status="closed") '; + elseif(isset($_REQUEST['staffId'])) // closed by any + $where.= ' OR ticket.status="closed" '; $where.= ' ) '; } elseif($_REQUEST['staffId']) { @@ -163,7 +165,6 @@ function search() { ." OR thread.title LIKE '%$queryterm%'" ." OR thread.body LIKE '%$queryterm%'" .' )'; - $groupby = 'GROUP BY ticket.ticket_id '; } $sql="$select $from $where $groupby"; diff --git a/include/class.ticket.php b/include/class.ticket.php index a7a16e46..d94a3818 100644 --- a/include/class.ticket.php +++ b/include/class.ticket.php @@ -2013,20 +2013,31 @@ function getStaffStats($staff) { if(!$staff || (!is_object($staff) && !($staff=Staff::lookup($staff))) || !$staff->isStaff() || $cfg->getDBVersion()) return null; - $sql='SELECT count(open.ticket_id) as open, count(answered.ticket_id) as answered ' .' ,count(overdue.ticket_id) as overdue, count(assigned.ticket_id) as assigned, count(closed.ticket_id) as closed ' .' FROM '.TICKET_TABLE.' ticket ' .' LEFT JOIN '.TICKET_TABLE.' open - ON (open.ticket_id=ticket.ticket_id AND open.status=\'open\' AND open.isanswered=0) ' + ON (open.ticket_id=ticket.ticket_id + AND open.status=\'open\' + AND open.isanswered=0 + '.((!($cfg->showAssignedTickets() || $staff->showAssignedTickets()))? + ' AND open.staff_id=0 ':'').') ' .' LEFT JOIN '.TICKET_TABLE.' answered - ON (answered.ticket_id=ticket.ticket_id AND answered.status=\'open\' AND answered.isanswered=1) ' + ON (answered.ticket_id=ticket.ticket_id + AND answered.status=\'open\' + AND answered.isanswered=1) ' .' LEFT JOIN '.TICKET_TABLE.' overdue - ON (overdue.ticket_id=ticket.ticket_id AND overdue.status=\'open\' AND overdue.isoverdue=1) ' + ON (overdue.ticket_id=ticket.ticket_id + AND overdue.status=\'open\' + AND overdue.isoverdue=1) ' .' LEFT JOIN '.TICKET_TABLE.' assigned - ON (assigned.ticket_id=ticket.ticket_id AND assigned.status=\'open\' AND assigned.staff_id='.db_input($staff->getId()).')' + ON (assigned.ticket_id=ticket.ticket_id + AND assigned.status=\'open\' + AND assigned.staff_id='.db_input($staff->getId()).')' .' LEFT JOIN '.TICKET_TABLE.' closed - ON (closed.ticket_id=ticket.ticket_id AND closed.status=\'closed\' AND closed.staff_id='.db_input($staff->getId()).')' + ON (closed.ticket_id=ticket.ticket_id + AND closed.status=\'closed\' + AND closed.staff_id='.db_input($staff->getId()).')' .' WHERE (ticket.staff_id='.db_input($staff->getId()); if(($teams=$staff->getTeams())) @@ -2037,10 +2048,6 @@ function getStaffStats($staff) { $sql.=')'; - if(!$cfg || !($cfg->showAssignedTickets() || $staff->showAssignedTickets())) - $sql.=' AND (ticket.staff_id=0 OR ticket.staff_id='.db_input($staff->getId()).') '; - - return db_fetch_array(db_query($sql)); } diff --git a/include/staff/tickets.inc.php b/include/staff/tickets.inc.php index ecbedfc6..5afb5bfa 100644 --- a/include/staff/tickets.inc.php +++ b/include/staff/tickets.inc.php @@ -19,10 +19,9 @@ $searchTerm=''; } } -$showoverdue=$showanswered=$showassigned=false; +$showoverdue=$showanswered=false; $staffId=0; //Nothing for now...TODO: Allow admin and manager to limit tickets to single staff level. -//show Assigned To column, if enabled. Admins and managers can overwrite system settings! -$showassigned=(($cfg->showAssignedTickets() || $thisstaff->showAssignedTickets()) && !$search); +$showassigned= true; //show Assigned To column - defaults to true //Get status we are actually going to use on the query...making sure it is clean! $status=null; @@ -32,7 +31,7 @@ break; case 'closed': $status='closed'; - $showassigned=false; + $showassigned=true; //closed by. break; case 'overdue': $status='open'; @@ -77,8 +76,8 @@ $qwhere.=' AND status='.db_input(strtolower($status)); } -//Overloaded sub-statuses - you've got to just have faith! -if($staffId && ($staffId==$thisstaff->getId())) { //Staff's assigned tickets. +//Queues: Overloaded sub-statuses - you've got to just have faith! +if($staffId && ($staffId==$thisstaff->getId())) { //My tickets $results_type='Assigned Tickets'; $qwhere.=' AND ticket.staff_id='.db_input($staffId); $showassigned=false; //My tickets...already assigned to the staff. @@ -86,14 +85,20 @@ $qwhere.=' AND isoverdue=1 '; }elseif($showanswered) { ////Answered $qwhere.=' AND isanswered=1 '; -}elseif(!$search && !$cfg->showAnsweredTickets() && !strcasecmp($status,'open')) { - $qwhere.=' AND isanswered=0 '; +}elseif(!strcasecmp($status, 'open') && !$search) { //Open queue (on search OPEN means all open tickets - regardless of state). + //Showing answered tickets on open queue?? + if(!$cfg->showAnsweredTickets()) + $qwhere.=' AND isanswered=0 '; + + /* Showing assigned tickets on open queue? + Don't confuse it with show assigned To column -> F'it it's confusing - just trust me! + */ + if(!($cfg->showAssignedTickets() || $thisstaff->showAssignedTickets())) { + $qwhere.=' AND ticket.staff_id=0 '; //XXX: NOT factoring in team assignments - only staff assignments. + $showassigned=false; //Not showing Assigned To column since assigned tickets are not part of open queue + } } -//******* Showing assigned tickets? (don't confuse it with show assigned To column). F'it it's confusing - just trust me! ***/ -if(!($cfg->showAssignedTickets() || $thisstaff->showAssignedTickets()) && strcasecmp($status,'closed') && !$search) - $sql.=' AND (ticket.staff_id=0 OR ticket.staff_id='.db_input($thisstaff->getId()).') '; - //Search?? Somebody...get me some coffee $deep_search=false; if($search): @@ -156,6 +161,9 @@ if($_REQUEST['staffId'] && !$_REQUEST['status']) { //Assigned TO + Closed By $qwhere.= ' OR (ticket.staff_id='.db_input($_REQUEST['staffId']). ' AND ticket.status="closed") '; $qstr.='&staffId='.urlencode($_REQUEST['staffId']); + }elseif(isset($_REQUEST['staffId'])) { + $qwhere.= ' OR ticket.status="closed" '; + $qstr.='&staffId='.urlencode($_REQUEST['staffId']); } $qwhere.= ' ) '; diff --git a/scp/tickets.php b/scp/tickets.php index 9e436f20..37683eab 100644 --- a/scp/tickets.php +++ b/scp/tickets.php @@ -450,7 +450,7 @@ //Navigation $nav->setTabActive('tickets'); if($cfg->showAnsweredTickets()) { - $nav->addSubMenu(array('desc'=>'Open ('.($stats['open']+$stats['answered']).')', + $nav->addSubMenu(array('desc'=>'Open ('.number_format($stats['open']+$stats['answered']).')', 'title'=>'Open Tickets', 'href'=>'tickets.php', 'iconclass'=>'Ticket'), @@ -458,7 +458,7 @@ } else { if($stats) { - $nav->addSubMenu(array('desc'=>'Open ('.$stats['open'].')', + $nav->addSubMenu(array('desc'=>'Open ('.number_format($stats['open']).')', 'title'=>'Open Tickets', 'href'=>'tickets.php', 'iconclass'=>'Ticket'), @@ -466,7 +466,7 @@ } if($stats['answered']) { - $nav->addSubMenu(array('desc'=>'Answered ('.$stats['answered'].')', + $nav->addSubMenu(array('desc'=>'Answered ('.number_format($stats['answered']).')', 'title'=>'Answered Tickets', 'href'=>'tickets.php?status=answered', 'iconclass'=>'answeredTickets'), @@ -478,7 +478,7 @@ if(!$ost->getWarning() && $stats['assigned']>10) $ost->setWarning($stats['assigned'].' tickets assigned to you! Do something about it!'); - $nav->addSubMenu(array('desc'=>'My Tickets ('.$stats['assigned'].')', + $nav->addSubMenu(array('desc'=>'My Tickets ('.number_format($stats['assigned']).')', 'title'=>'Assigned Tickets', 'href'=>'tickets.php?status=assigned', 'iconclass'=>'assignedTickets'), @@ -486,7 +486,7 @@ } if($stats['overdue']) { - $nav->addSubMenu(array('desc'=>'Overdue ('.$stats['overdue'].')', + $nav->addSubMenu(array('desc'=>'Overdue ('.number_format($stats['overdue']).')', 'title'=>'Stale Tickets', 'href'=>'tickets.php?status=overdue', 'iconclass'=>'overdueTickets'), @@ -497,14 +497,14 @@ } if($thisstaff->showAssignedOnly() && $stats['closed']) { - $nav->addSubMenu(array('desc'=>'My Closed Tickets ('.$stats['closed'].')', + $nav->addSubMenu(array('desc'=>'My Closed Tickets ('.number_format($stats['closed']).')', 'title'=>'My Closed Tickets', 'href'=>'tickets.php?status=closed', 'iconclass'=>'closedTickets'), ($_REQUEST['status']=='closed')); } else { - $nav->addSubMenu(array('desc'=>'Closed Tickets', + $nav->addSubMenu(array('desc'=>'Closed Tickets ('.number_format($stats['closed']).')', 'title'=>'Closed Tickets', 'href'=>'tickets.php?status=closed', 'iconclass'=>'closedTickets'), From b5fbfdb7bd3d92ea52c68b5ccf91b8eeef7a2503 Mon Sep 17 00:00:00 2001 From: Peter Rotich Date: Fri, 22 Feb 2013 10:59:27 -0500 Subject: [PATCH 2/5] Show assigned to column based on flag - which now factors in if assigned tickets are being shown on open queue. --- include/staff/tickets.inc.php | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/include/staff/tickets.inc.php b/include/staff/tickets.inc.php index 5afb5bfa..f13c22a0 100644 --- a/include/staff/tickets.inc.php +++ b/include/staff/tickets.inc.php @@ -354,20 +354,23 @@ - - href="tickets.php?sort=assignee&order=" - title="Sort By Assignee ">Assigned To - - - href="tickets.php?sort=staff&order=" - title="Sort By Closing Staff Name ">Closed By - + + href="tickets.php?sort=staff&order=" + title="Sort By Closing Staff Name ">Closed By + + + href="tickets.php?sort=assignee&order=" + title="Sort By Assignee ">Assigned To + - - href="tickets.php?sort=dept&order=" - title="Sort By Department ">Department + + href="tickets.php?sort=dept&order=" + title="Sort By Department ">Department @@ -387,7 +390,7 @@ $flag='overdue'; $lc=''; - if($showassigned || !strcasecmp($status,'closed')) { + if($showassigned) { if($row['staff_id']) $lc=sprintf('%s',Format::truncate($row['staff'],40)); elseif($row['team_id']) From 4b184bf5b1ba276c46717d76ebd94015783c8129 Mon Sep 17 00:00:00 2001 From: Peter Rotich Date: Fri, 22 Feb 2013 11:15:12 -0500 Subject: [PATCH 3/5] Add Answered queue to advanced search --- include/ajax.tickets.php | 3 +++ include/staff/tickets.inc.php | 5 +++++ scp/js/scp.js | 1 + 3 files changed, 9 insertions(+) diff --git a/include/ajax.tickets.php b/include/ajax.tickets.php index d1df0f6c..56093119 100644 --- a/include/ajax.tickets.php +++ b/include/ajax.tickets.php @@ -112,6 +112,9 @@ function search() { case 'open': $where.=' AND ticket.status="open" '; break; + case 'answered': + $where.=' AND ticket.status="open" AND ticket.isanswered=1 '; + break; case 'overdue': $where.=' AND ticket.status="open" AND ticket.isoverdue=1 '; break; diff --git a/include/staff/tickets.inc.php b/include/staff/tickets.inc.php index f13c22a0..64cd52cc 100644 --- a/include/staff/tickets.inc.php +++ b/include/staff/tickets.inc.php @@ -555,6 +555,11 @@ diff --git a/scp/js/scp.js b/scp/js/scp.js index cf32e42d..8ce35149 100644 --- a/scp/js/scp.js +++ b/scp/js/scp.js @@ -369,6 +369,7 @@ $(document).ready(function(){ break; case 'open': case 'overdue': + case 'answered': $('select#staffId').find('option:first').attr('selected', 'selected').parent('select'); $('select#staffId').attr('disabled','disabled'); $('select#assignee').removeAttr('disabled'); From 1f1dd0384ebc859f1888f25eeece062916b819a3 Mon Sep 17 00:00:00 2001 From: Peter Rotich Date: Fri, 22 Feb 2013 11:18:24 -0500 Subject: [PATCH 4/5] Add ability to filter by unassigned on advanced search. --- include/ajax.tickets.php | 14 ++++++++------ include/staff/tickets.inc.php | 21 +++++++++++++-------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/include/ajax.tickets.php b/include/ajax.tickets.php index 56093119..0e010879 100644 --- a/include/ajax.tickets.php +++ b/include/ajax.tickets.php @@ -124,16 +124,18 @@ function search() { } //Assignee - if($_REQUEST['assignee'] && strcasecmp($_REQUEST['status'], 'closed')) { + if(isset($_REQUEST['assignee']) && strcasecmp($_REQUEST['status'], 'closed')) { $id=preg_replace("/[^0-9]/", "", $_REQUEST['assignee']); $assignee = $_REQUEST['assignee']; - $where.= ' AND ( '; + $where.= ' AND ( ( ticket.status="open" '; if($assignee[0]=='t') - $where.=' (ticket.team_id='.db_input($id). ' AND ticket.status="open") '; + $where.=' AND ticket.team_id='.db_input($id); elseif($assignee[0]=='s') - $where.=' (ticket.staff_id='.db_input($id). ' AND ticket.status="open") '; - else - $where.=' (ticket.staff_id='.db_input($id). ' AND ticket.status="open") '; + $where.=' AND ticket.staff_id='.db_input($id); + elseif(is_numeric($id)) + $where.=' AND ticket.staff_id='.db_input($id); + + $where.=')'; if($_REQUEST['staffId'] && !$_REQUEST['status']) //Assigned TO + Closed By $where.= ' OR (ticket.staff_id='.db_input($_REQUEST['staffId']). ' AND ticket.status="closed") '; diff --git a/include/staff/tickets.inc.php b/include/staff/tickets.inc.php index 64cd52cc..0d14cf4a 100644 --- a/include/staff/tickets.inc.php +++ b/include/staff/tickets.inc.php @@ -50,7 +50,7 @@ break; default: if(!$search) - $status='open'; + $_REQUEST['status']=$status='open'; } $qwhere =''; @@ -144,19 +144,21 @@ } //Assignee - if($_REQUEST['assignee'] && strcasecmp($_REQUEST['status'], 'closed')) { + if(isset($_REQUEST['assignee']) && strcasecmp($_REQUEST['status'], 'closed')) { $id=preg_replace("/[^0-9]/", "", $_REQUEST['assignee']); $assignee = $_REQUEST['assignee']; $qstr.='&assignee='.urlencode($_REQUEST['assignee']); - $qwhere.= ' AND ( '; + $qwhere.= ' AND ( + ( ticket.status="open" '; if($assignee[0]=='t') - $qwhere.=' (ticket.team_id='.db_input($id). ' AND ticket.status="open") '; + $qwhere.=' AND ticket.team_id='.db_input($id); elseif($assignee[0]=='s') - $qwhere.=' (ticket.staff_id='.db_input($id). ' AND ticket.status="open") '; - else - $qwhere.=' (ticket.staff_id='.db_input($id). ' AND ticket.status="open") '; + $qwhere.=' AND ticket.staff_id='.db_input($id); + elseif(is_numeric($id)) + $qwhere.=' AND ticket.staff_id='.db_input($id); + $qwhere.=' ) '; if($_REQUEST['staffId'] && !$_REQUEST['status']) { //Assigned TO + Closed By $qwhere.= ' OR (ticket.staff_id='.db_input($_REQUEST['staffId']). ' AND ticket.status="closed") '; @@ -579,7 +581,9 @@
+ $name) From 1fe92c2c6bfc41fe9981d4ab2f85dce7f29e8817 Mon Sep 17 00:00:00 2001 From: Peter Rotich Date: Fri, 22 Feb 2013 15:11:43 -0500 Subject: [PATCH 5/5] Add help topics to advanced search and csv export --- include/ajax.tickets.php | 4 ++++ include/class.export.php | 1 + include/staff/tickets.inc.php | 26 ++++++++++++++++++++++++-- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/include/ajax.tickets.php b/include/ajax.tickets.php index 0e010879..1d887f04 100644 --- a/include/ajax.tickets.php +++ b/include/ajax.tickets.php @@ -107,6 +107,10 @@ function search() { if($_REQUEST['deptId']) $where.=' AND ticket.dept_id='.db_input($_REQUEST['deptId']); + //Help topic + if($_REQUEST['topicId']) + $where.=' AND ticket.topic_id='.db_input($_REQUEST['topicId']); + //Status switch(strtolower($_REQUEST['status'])) { case 'open': diff --git a/include/class.export.php b/include/class.export.php index 3c289550..372cf62e 100644 --- a/include/class.export.php +++ b/include/class.export.php @@ -41,6 +41,7 @@ class Export { 'name' => 'From', 'priority_desc' => 'Priority', 'dept_name' => 'Department', + 'helptopic' => 'Help Topic', 'source' => 'Source', 'status' => 'Current Status' ), diff --git a/include/staff/tickets.inc.php b/include/staff/tickets.inc.php index 0d14cf4a..ed591619 100644 --- a/include/staff/tickets.inc.php +++ b/include/staff/tickets.inc.php @@ -142,6 +142,12 @@ $qwhere.=' AND ticket.dept_id='.db_input($_REQUEST['deptId']); $qstr.='&deptId='.urlencode($_REQUEST['deptId']); } + + //Help topic + if($_REQUEST['topicId']) { + $qwhere.=' AND ticket.topic_id='.db_input($_REQUEST['topicId']); + $qstr.='&topicId='.urlencode($_REQUEST['topicId']); + } //Assignee if(isset($_REQUEST['assignee']) && strcasecmp($_REQUEST['status'], 'closed')) { @@ -273,7 +279,8 @@ .' ,IF(ticket.duedate IS NULL,IF(sla.id IS NULL, NULL, DATE_ADD(ticket.created, INTERVAL sla.grace_period HOUR)), ticket.duedate) as duedate ' .' ,IF(ticket.reopened is NULL,IF(ticket.lastmessage is NULL,ticket.created,ticket.lastmessage),ticket.reopened) as effective_date ' .' ,CONCAT_WS(" ", staff.firstname, staff.lastname) as staff, team.name as team ' - .' ,IF(staff.staff_id IS NULL,team.name,CONCAT_WS(" ", staff.lastname, staff.firstname)) as assigned '; + .' ,IF(staff.staff_id IS NULL,team.name,CONCAT_WS(" ", staff.lastname, staff.firstname)) as assigned ' + .' ,IF(ptopic.topic_pid IS NULL, topic.topic, CONCAT_WS(" / ", ptopic.topic, topic.topic)) as helptopic '; $qfrom.=' LEFT JOIN '.TICKET_PRIORITY_TABLE.' pri ON (ticket.priority_id=pri.priority_id) ' .' LEFT JOIN '.TICKET_LOCK_TABLE.' tlock ON (ticket.ticket_id=tlock.ticket_id AND tlock.expire>NOW() @@ -282,7 +289,10 @@ .' LEFT JOIN '.TICKET_THREAD_TABLE.' thread ON ( ticket.ticket_id=thread.ticket_id) ' .' LEFT JOIN '.STAFF_TABLE.' staff ON (ticket.staff_id=staff.staff_id) ' .' LEFT JOIN '.TEAM_TABLE.' team ON (ticket.team_id=team.team_id) ' - .' LEFT JOIN '.SLA_TABLE.' sla ON (ticket.sla_id=sla.id AND sla.isactive=1) '; + .' LEFT JOIN '.SLA_TABLE.' sla ON (ticket.sla_id=sla.id AND sla.isactive=1) ' + .' LEFT JOIN '.TOPIC_TABLE.' topic ON (ticket.topic_id=topic.topic_id) ' + .' LEFT JOIN '.TOPIC_TABLE.' ptopic ON (ptopic.topic_id=topic.topic_pid) '; + $query="$qselect $qfrom $qwhere $qgroup ORDER BY $order_by $order LIMIT ".$pageNav->getStart().",".$pageNav->getLimit(); //echo $query; @@ -616,6 +626,18 @@ ?>
+
+ + +