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'),