diff --git a/include/class.client.php b/include/class.client.php index 25b03281b9abd31d359d265592dcdc7058061a24..eb4ef00a870c62a6355d3269ec5b6c0476ed27c5 100644 --- a/include/class.client.php +++ b/include/class.client.php @@ -245,6 +245,19 @@ class EndUser extends BaseAuthenticatedUser { return ($stats=$this->getTicketStats())?$stats['closed']:0; } + function getNumOrganizationTickets() { + if (!($stats=$this->getTicketStats())) + return 0; + + return $stats['org-open']+$stats['org-closed']; + } + function getNumOpenOrganizationTickets() { + return ($stats=$this->getTicketStats())?$stats['org-open']:0; + } + function getNumClosedOrganizationTickets() { + return ($stats=$this->getTicketStats())?$stats['org-closed']:0; + } + function getAccount() { if ($this->_account === false) $this->_account = @@ -263,6 +276,8 @@ class EndUser extends BaseAuthenticatedUser { $where = ' WHERE ticket.user_id = '.db_input($this->getId()) .' OR collab.user_id = '.db_input($this->getId()).' '; + $where2 = ' WHERE user.org_id > 0 AND user.org_id = '.db_input($this->getOrgId()).' '; + $join = 'LEFT JOIN '.THREAD_TABLE.' thread ON (ticket.ticket_id = thread.object_id and thread.object_type = \'T\') LEFT JOIN '.THREAD_COLLABORATOR_TABLE.' collab @@ -283,7 +298,25 @@ class EndUser extends BaseAuthenticatedUser { ON (ticket.status_id=status.id AND status.state=\'closed\' ) ' . $join - . $where; + . $where + + .'UNION SELECT \'org-open\', count( ticket.ticket_id ) AS tickets ' + .'FROM ' . TICKET_TABLE . ' ticket ' + .'INNER JOIN '.USER_TABLE.' user ON (ticket.user_id = user.id) ' + .'INNER JOIN '.TICKET_STATUS_TABLE. ' status + ON (ticket.status_id=status.id + AND status.state=\'open\' ) ' + . $join + . $where2 + + .'UNION SELECT \'org-closed\', count( ticket.ticket_id ) AS tickets ' + .'FROM ' . TICKET_TABLE . ' ticket ' + .'INNER JOIN '.USER_TABLE.' user ON (ticket.user_id = user.id) ' + .'INNER JOIN '.TICKET_STATUS_TABLE. ' status + ON (ticket.status_id=status.id + AND status.state=\'closed\' ) ' + . $join + . $where2; $res = db_query($sql); $stats = array(); diff --git a/include/staff/ticket-view.inc.php b/include/staff/ticket-view.inc.php index fe5bfd04aced74215f6dd7e856288b5ee5ab877c..83cb718ea1a20acd10e8919f378ffce7aa8d07bc 100644 --- a/include/staff/ticket-view.inc.php +++ b/include/staff/ticket-view.inc.php @@ -213,10 +213,13 @@ if($ticket->isOverdue()) ><?php echo Format::htmlchars($ticket->getName()); ?></span></a> <?php - if($user) { - echo sprintf(' <a href="tickets.php?a=search&uid=%d" title="%s" data-dropdown="#action-dropdown-stats">(<b>%d</b>)</a>', - urlencode($user->getId()), __('Related Tickets'), $user->getNumTickets()); - ?> + if ($user) { ?> + <a href="tickets.php?<?php echo Http::build_query(array( + 'status'=>'open', 'a'=>'search', 'uid'=> $user->getId() + )); ?>" title="<?php echo __('Related Tickets'); ?>" + data-dropdown="#action-dropdown-stats"> + (<b><?php echo $user->getNumTickets(); ?></b>) + </a> <div id="action-dropdown-stats" class="action-dropdown anchor-right"> <ul> <?php @@ -234,16 +237,48 @@ if($ticket->isOverdue()) <li><a href="users.php?id=<?php echo $user->getId(); ?>"><i class="icon-user icon-fixed-width"></i> <?php echo __('Manage User'); ?></a></li> -<?php if ($user->getOrgId()) { ?> +<?php } ?> + </ul> + </div> +<?php if ($user->getOrgId()) { ?> + <span style="display:inline-block"> + <i class="icon-building"></i> + <?php echo Format::htmlchars($user->getOrganization()->getName()); ?> + <a href="tickets.php?<?php echo Http::build_query(array( + 'status'=>'open', 'a'=>'search', 'orgid'=> $user->getOrgId() + )); ?>" title="<?php echo __('Related Tickets'); ?>" + data-dropdown="#action-dropdown-org-stats"> + (<b><?php echo $user->getNumOrganizationTickets(); ?></b>) + </a> + </span> + <div id="action-dropdown-org-stats" class="action-dropdown anchor-right"> + <ul> +<?php if ($open = $user->getNumOpenOrganizationTickets()) { ?> + <li><a href="tickets.php?<?php echo Http::build_query(array( + 'a' => 'search', 'status' => 'open', 'orgid' => $user->getOrgId() + )); ?>"><i class="icon-folder-open-alt icon-fixed-width"></i> + <?php echo sprintf(_N('%d Open Ticket', '%d Open Tickets', $open), $open); ?> + </a></li> +<?php } + if ($closed = $user->getNumClosedOrganizationTickets()) { ?> + <li><a href="tickets.php?<?php echo Http::build_query(array( + 'a' => 'search', 'status' => 'closed', 'orgid' => $user->getOrgId() + )); ?>"><i class="icon-folder-close-alt icon-fixed-width"></i> + <?php echo sprintf(_N('%d Closed Ticket', '%d Closed Tickets', $closed), $closed); ?> + </a></li> + <li><a href="tickets.php?<?php echo Http::build_query(array( + 'a' => 'search', 'orgid' => $user->getOrgId() + )); ?>"><i class="icon-double-angle-right icon-fixed-width"></i> <?php echo __('All Tickets'); ?></a></li> +<?php } + if ($thisstaff->getRole()->hasPerm(User::PERM_DIRECTORY)) { ?> <li><a href="orgs.php?id=<?php echo $user->getOrgId(); ?>"><i class="icon-building icon-fixed-width"></i> <?php echo __('Manage Organization'); ?></a></li> -<?php } - } ?> +<?php } ?> </ul> </div> - <?php - } +<?php } # end if (user->org) + } # end if ($user) ?> </td> </tr> diff --git a/include/staff/tickets.inc.php b/include/staff/tickets.inc.php index 612f76f1759a62230fc2fc9a87410b7b9ed17ed7..528deb9c0a43d5df1c627576af8c01ae0af467ad 100644 --- a/include/staff/tickets.inc.php +++ b/include/staff/tickets.inc.php @@ -12,7 +12,7 @@ parse_str($_SERVER['QUERY_STRING'], $args); // Remove commands from query unset($args['id']); -unset($args['a']); +if ($args['a'] !== 'search') unset($args['a']); $refresh_url = $path . '?' . http_build_query($args); @@ -30,7 +30,7 @@ $sort_options = array( ); $use_subquery = true; -$queue_name = strtolower($_GET['status'] ?: $_GET['a']); //Status is overloaded +$queue_name = strtolower($_GET['a'] ?: $_GET['status']); //Status is overloaded // Stash current queue view $_SESSION['::Q'] = $queue_name; @@ -69,6 +69,9 @@ case 'answered': break; default: case 'search': + $queue_sort_options = array('priority,updated', 'priority,created', + 'priority,due', 'due', 'updated', 'answered', + 'closed', 'number', 'hot'); // Consider basic search if ($_REQUEST['query']) { $results_type=__('Search Results'); @@ -95,9 +98,6 @@ case 'search': $view_all_tickets = $thisstaff->getRole()->hasPerm(SearchBackend::PERM_EVERYTHING); $results_type=__('Advanced Search') . '<a class="action-button" href="?clear_filter"><i style="top:0" class="icon-ban-circle"></i> <em>' . __('clear') . '</em></a>'; - $queue_sort_options = array('priority,updated', 'priority,created', - 'priority,due', 'due', 'updated', 'answered', - 'closed', 'number', 'hot'); $has_relevance = false; foreach ($tickets->getSortFields() as $sf) { if ($sf instanceof SqlCode && $sf->code == '`relevance`') { @@ -115,6 +115,21 @@ case 'search': break; } + // Apply user filter + elseif (isset($_GET['uid']) && ($user = User::lookup($_GET['uid']))) { + $tickets->filter(array('user__id'=>$_GET['uid'])); + $results_type = sprintf('%s — %s', __('Search Results'), + $user->getName()); + // Don't apply normal open ticket + break; + } + elseif (isset($_GET['orgid']) && ($org = Organization::lookup($_GET['orgid']))) { + $tickets->filter(array('user__org_id'=>$_GET['orgid'])); + $results_type = sprintf('%s — %s', __('Search Results'), + $org->getName()); + // Don't apply normal open ticket + break; + } // Fall-through and show open tickets case 'open': $status='open'; @@ -132,13 +147,9 @@ case 'open': break; } -// Apply user filter -if (isset($_GET['uid'])) { - $tickets->filter(array('user__id'=>$_GET['uid'])); -} - - // Apply primary ticket status +if (!isset($status) && isset($_GET['status'])) + $status = $_GET['status']; if ($status) $tickets->filter(array('status__state'=>$status));