Skip to content

Commit

Permalink
Merge pull request osTicket#477 from protich/issue/475
Browse files Browse the repository at this point in the history
Issue/475
  • Loading branch information
protich committed Mar 6, 2013
2 parents 7fa2f56 + 1fe92c2 commit 78334a2
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 64 deletions.
32 changes: 21 additions & 11 deletions include/ajax.tickets.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ';

Expand All @@ -107,11 +107,18 @@ 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';
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;
Expand All @@ -121,19 +128,23 @@ 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") ';
$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']) {
Expand Down Expand Up @@ -163,7 +174,6 @@ function search() {
." OR thread.title LIKE '%$queryterm%'"
." OR thread.body LIKE '%$queryterm%'"
.' )';
$groupby = 'GROUP BY ticket.ticket_id ';
}

$sql="$select $from $where $groupby";
Expand Down
1 change: 1 addition & 0 deletions include/class.export.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class Export {
'name' => 'From',
'priority_desc' => 'Priority',
'dept_name' => 'Department',
'helptopic' => 'Help Topic',
'source' => 'Source',
'status' => 'Current Status'
),
Expand Down
27 changes: 17 additions & 10 deletions include/class.ticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand All @@ -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));
}

Expand Down
115 changes: 79 additions & 36 deletions include/staff/tickets.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,7 +31,7 @@
break;
case 'closed':
$status='closed';
$showassigned=false;
$showassigned=true; //closed by.
break;
case 'overdue':
$status='open';
Expand All @@ -51,7 +50,7 @@
break;
default:
if(!$search)
$status='open';
$_REQUEST['status']=$status='open';
}

$qwhere ='';
Expand All @@ -77,23 +76,29 @@
$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.
}elseif($showoverdue) { //overdue
$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):
Expand Down Expand Up @@ -137,25 +142,36 @@
$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($_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") ';
$qstr.='&staffId='.urlencode($_REQUEST['staffId']);
}elseif(isset($_REQUEST['staffId'])) {
$qwhere.= ' OR ticket.status="closed" ';
$qstr.='&staffId='.urlencode($_REQUEST['staffId']);
}

$qwhere.= ' ) ';
Expand Down Expand Up @@ -263,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()
Expand All @@ -272,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;
Expand Down Expand Up @@ -346,20 +366,23 @@
<?php
}

if($showassigned){ ?>
<th width="150">
<a <?php echo $assignee_sort; ?> href="tickets.php?sort=assignee&order=<?php echo $negorder; ?><?php echo $qstr; ?>"
title="Sort By Assignee <?php echo $negorder;?>">Assigned To</a></th>
<?php
} elseif(!strcasecmp($status,'closed')) { ?>
<th width="150">
<a <?php echo $staff_sort; ?> href="tickets.php?sort=staff&order=<?php echo $negorder; ?><?php echo $qstr; ?>"
title="Sort By Closing Staff Name <?php echo $negorder; ?>">Closed By</a></th>
<?php
if($showassigned ) {
//Closed by
if(!strcasecmp($status,'closed')) { ?>
<th width="150">
<a <?php echo $staff_sort; ?> href="tickets.php?sort=staff&order=<?php echo $negorder; ?><?php echo $qstr; ?>"
title="Sort By Closing Staff Name <?php echo $negorder; ?>">Closed By</a></th>
<?php
} else { //assigned to ?>
<th width="150">
<a <?php echo $assignee_sort; ?> href="tickets.php?sort=assignee&order=<?php echo $negorder; ?><?php echo $qstr; ?>"
title="Sort By Assignee <?php echo $negorder;?>">Assigned To</a></th>
<?php
}
} else { ?>
<th width="150">
<a <?php echo $dept_sort; ?> href="tickets.php?sort=dept&order=<?php echo $negorder;?><?php echo $qstr; ?>"
title="Sort By Department <?php echo $negorder; ?>">Department</a></th>
<th width="150">
<a <?php echo $dept_sort; ?> href="tickets.php?sort=dept&order=<?php echo $negorder;?><?php echo $qstr; ?>"
title="Sort By Department <?php echo $negorder; ?>">Department</a></th>
<?php
} ?>
</tr>
Expand All @@ -379,7 +402,7 @@
$flag='overdue';

$lc='';
if($showassigned || !strcasecmp($status,'closed')) {
if($showassigned) {
if($row['staff_id'])
$lc=sprintf('<span class="Icon staffAssigned">%s</span>',Format::truncate($row['staff'],40));
elseif($row['team_id'])
Expand Down Expand Up @@ -544,6 +567,11 @@
<select id="status" name="status">
<option value="">&mdash; Any Status &mdash;</option>
<option value="open">Open</option>
<?php
if(!$cfg->showAnsweredTickets()) {?>
<option value="answered">Answered</option>
<?php
} ?>
<option value="overdue">Overdue</option>
<option value="closed">Closed</option>
</select>
Expand All @@ -563,7 +591,9 @@
<fieldset class="owner">
<label for="assignee">Assigned To:</label>
<select id="assignee" name="assignee">
<option value="0">&mdash; Anyone &mdash;</option>
<option value="">&mdash; Anyone &mdash;</option>
<option value="0">&mdash; Unassigned &mdash;</option>
<option value="<?php echo $thisstaff->getId(); ?>">Me</option>
<?php
if(($users=Staff::getStaffMembers())) {
echo '<OPTGROUP label="Staff Members ('.count($users).')">';
Expand All @@ -587,6 +617,7 @@
<label for="staffId">Closed By:</label>
<select id="staffId" name="staffId">
<option value="0">&mdash; Anyone &mdash;</option>
<option value="<?php echo $thisstaff->getId(); ?>">Me</option>
<?php
if(($users=Staff::getStaffMembers())) {
foreach($users as $id => $name)
Expand All @@ -595,6 +626,18 @@
?>
</select>
</fieldset>
<fieldset>
<label for="topicId">Help Topic:</label>
<select id="topicId" name="topicId">
<option value="" selected >&mdash; All Help Topics &mdash;</option>
<?php
if($topics=Topic::getHelpTopics()) {
foreach($topics as $id =>$name)
echo sprintf('<option value="%d" >%s</option>', $id, $name);
}
?>
</select>
</fieldset>
<fieldset class="date_range">
<label>Date Range:</label>
<input class="dp" type="input" size="20" name="startDate">
Expand Down
1 change: 1 addition & 0 deletions scp/js/scp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Loading

0 comments on commit 78334a2

Please sign in to comment.