diff --git a/include/ajax.tickets.php b/include/ajax.tickets.php index de6610dd6b0c1a27a5d032f4aca6582078f200c1..67e0257d48de234426bf1e3fa4c3f53e57e10461 100644 --- a/include/ajax.tickets.php +++ b/include/ajax.tickets.php @@ -301,13 +301,13 @@ class TicketsAjaxAPI extends AjaxController { Format::db_datetime($ticket->getCloseDate()), ($staff?$staff->getName():'staff') ); - } elseif($ticket->getDueDate()) { + } elseif($ticket->getEstDueDate()) { echo sprintf(' <tr> <th>Due Date:</th> <td>%s</td> </tr>', - Format::db_datetime($ticket->getDueDate())); + Format::db_datetime($ticket->getEstDueDate())); } echo '</table>'; diff --git a/include/class.pdf.php b/include/class.pdf.php index 87fcd69ad4a97f694bf60235c8c15f8ef5529d88..a456461ba1e8bf7b2ce071cbe877f5615ddc7b8c 100644 --- a/include/class.pdf.php +++ b/include/class.pdf.php @@ -189,7 +189,7 @@ class Ticket2PDF extends FPDF if($ticket->isOpen()) { $this->Cell($l, 7, 'Due Date', 1, 0, 'L', true); $this->SetFont(''); - $this->Cell($c, 7, Format::db_datetime($ticket->getDueDate()), 1, 0, 'L', true); + $this->Cell($c, 7, Format::db_datetime($ticket->getEstDueDate()), 1, 0, 'L', true); } else { $this->Cell($l, 7, 'Close Date', 1, 0, 'L', true); $this->SetFont(''); diff --git a/include/class.sla.php b/include/class.sla.php index 7055977a8a752408bf2671f6e87cd404f9f32409..fc673d5a2b2c49f737b7edcaff9f818f4e8ed493 100644 --- a/include/class.sla.php +++ b/include/class.sla.php @@ -117,12 +117,13 @@ class SLA { function getSLAs() { $slas=array(); - - $sql='SELECT id, name FROM '.SLA_TABLE; + $sql='SELECT id, name, isactive, grace_period FROM '.SLA_TABLE.' ORDER BY name'; if(($res=db_query($sql)) && db_num_rows($res)) { - while(list($id, $name)=db_fetch_row($res)) - $slas[$id]=$name; - + while($row=db_fetch_array($res)) + $slas[$row['id']] = sprintf('%s (%d hrs - %s)', + $row['name'], + $row['grace_period'], + $row['isactive']?'Active':'Disabled'); } return $slas; diff --git a/include/class.ticket.php b/include/class.ticket.php index e68f8d4f8c75c0b001d0f3f0cfd66953a69db5cd..e6817e0dafa8682df6ccdb696741dce4c7cff1b2 100644 --- a/include/class.ticket.php +++ b/include/class.ticket.php @@ -78,12 +78,14 @@ class Ticket { //TODO: delete helptopic field in ticket table. $sql='SELECT ticket.*, lock_id, dept_name, priority_desc ' + .' ,IF(sla.id IS NULL, NULL, DATE_ADD(ticket.created, INTERVAL sla.grace_period HOUR)) as sla_duedate ' .' ,count(attach.attach_id) as attachments ' .' ,count(DISTINCT message.id) as messages ' .' ,count(DISTINCT response.id) as responses ' .' ,count(DISTINCT note.id) as notes ' .' FROM '.TICKET_TABLE.' ticket ' .' LEFT JOIN '.DEPT_TABLE.' dept ON (ticket.dept_id=dept.dept_id) ' + .' LEFT JOIN '.SLA_TABLE.' sla ON (ticket.sla_id=sla.id AND sla.isactive=1) ' .' LEFT JOIN '.TICKET_PRIORITY_TABLE.' pri ON (' .'ticket.priority_id=pri.priority_id) ' .' LEFT JOIN '.TICKET_LOCK_TABLE.' tlock ON (' @@ -259,6 +261,20 @@ class Ticket { return $this->duedate; } + function getSLADuedate() { + return $this->ht['sla_duedate']; + } + + function getEstDueDate() { + + //Real due date + if(($duedate=$this->getDueDate())) + return $duedate; + + //return sla due date (If ANY) + return $this->getSLADueDate(); + } + function getCloseDate(){ return $this->closed; } @@ -1245,8 +1261,10 @@ class Ticket { if($this->isClosed()) $this->reopen(); $this->reload(); - // Change to SLA of the new department - $this->selectSLAId(); + + // Set SLA of the new department + if(!$this->getSLAId()) + $this->selectSLAId(); /*** log the transfer comments as internal note - with alerts disabled - ***/ $title='Ticket transfered from '.$currentDept.' to '.$this->getDeptName(); @@ -1477,6 +1495,7 @@ class Ticket { 'response' => $this->replaceVars($canned->getResponse()), 'cannedattachments' => $files); + $errors = array(); if(!($respId=$this->postReply($info, $errors, false))) return false; @@ -1632,6 +1651,7 @@ class Ticket { //Insert Internal Notes function logNote($title, $note, $poster='SYSTEM', $alert=true) { + $errors = array(); return $this->postNote( array('title' => $title, 'note' => $note), $errors, diff --git a/include/staff/department.inc.php b/include/staff/department.inc.php index b900087331721347ee1b1c57dd37f43e274ed2d2..00a65ebc54cfc1345d55ea365e00f5ff9aaa12ca 100644 --- a/include/staff/department.inc.php +++ b/include/staff/department.inc.php @@ -108,11 +108,10 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); <select name="sla_id"> <option value="0">— System default —</option> <?php - $sql='SELECT id,name FROM '.SLA_TABLE.' sla ORDER by name'; - if(($res=db_query($sql)) && db_num_rows($res)){ - while(list($id,$name)=db_fetch_row($res)){ - $selected=($info['sla_id'] && $id==$info['sla_id'])?'selected="selected"':''; - echo sprintf('<option value="%d" %s>%s</option>',$id,$selected,$name); + if($slas=SLA::getSLAs()) { + foreach($slas as $id =>$name) { + echo sprintf('<option value="%d" %s>%s</option>', + $id, ($info['sla_id']==$id)?'selected="selected"':'',$name); } } ?> diff --git a/include/staff/filter.inc.php b/include/staff/filter.inc.php index 36186838bd93cdba6977add500645becba4d673e..3743d5c9e062f112489d229c8f9e3cfb71a68adc 100644 --- a/include/staff/filter.inc.php +++ b/include/staff/filter.inc.php @@ -258,13 +258,12 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); </td> <td> <select name="sla_id"> - <option value="0">— Default —</option> + <option value="0">— System Default —</option> <?php - $sql='SELECT id,name FROM '.SLA_TABLE.' sla ORDER by name'; - if(($res=db_query($sql)) && db_num_rows($res)){ - while(list($id,$name)=db_fetch_row($res)){ - $selected=($info['sla_id'] && $id==$info['sla_id'])?'selected="selected"':''; - echo sprintf('<option value="%d" %s>%s</option>',$id,$selected,$name); + if($slas=SLA::getSLAs()) { + foreach($slas as $id =>$name) { + echo sprintf('<option value="%d" %s>%s</option>', + $id, ($info['sla_id']==$id)?'selected="selected"':'',$name); } } ?> diff --git a/include/staff/helptopic.inc.php b/include/staff/helptopic.inc.php index c222f745c9419eca924b1a975781791b7142e418..e5dac76027006cdbbd6631a66c3df119c758d292 100644 --- a/include/staff/helptopic.inc.php +++ b/include/staff/helptopic.inc.php @@ -137,11 +137,10 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); <select name="sla_id"> <option value="0">— Department's Default —</option> <?php - $sql='SELECT id,name FROM '.SLA_TABLE.' sla ORDER by name'; - if(($res=db_query($sql)) && db_num_rows($res)){ - while(list($id,$name)=db_fetch_row($res)){ - $selected=($info['sla_id'] && $id==$info['sla_id'])?'selected="selected"':''; - echo sprintf('<option value="%d" %s>%s</option>',$id,$selected,$name); + if($slas=SLA::getSLAs()) { + foreach($slas as $id =>$name) { + echo sprintf('<option value="%d" %s>%s</option>', + $id, ($info['sla_id']==$id)?'selected="selected"':'',$name); } } ?> diff --git a/include/staff/settings-tickets.inc.php b/include/staff/settings-tickets.inc.php index 992e9900425c19d708f7cb35d75a59f7b18c36bf..60d61257fe3ba781a4e98ae3bfd6ebab280f4259 100644 --- a/include/staff/settings-tickets.inc.php +++ b/include/staff/settings-tickets.inc.php @@ -34,11 +34,12 @@ if(!($maxfileuploads=ini_get('max_file_uploads'))) <select name="default_sla_id"> <option value="0">— None —</option> <?php - $sql='SELECT id,name FROM '.SLA_TABLE.' sla ORDER by name'; - if(($res=db_query($sql)) && db_num_rows($res)){ - while(list($id,$name)=db_fetch_row($res)){ - $selected=($config['default_sla_id'] && $id==$config['default_sla_id'])?'selected="selected"':''; - echo sprintf('<option value="%d" %s>%s</option>',$id,$selected,$name); + if($slas=SLA::getSLAs()) { + foreach($slas as $id => $name) { + echo sprintf('<option value="%d" %s>%s</option>', + $id, + ($config['default_sla_id'] && $id==$config['default_sla_id'])?'selected="selected"':'', + $name); } } ?> diff --git a/include/staff/ticket-view.inc.php b/include/staff/ticket-view.inc.php index b14a4654af003d0c5dd6b85635d8d91a63048940..7069b888efd02035e344a9a588bf55318bea4f46 100644 --- a/include/staff/ticket-view.inc.php +++ b/include/staff/ticket-view.inc.php @@ -220,7 +220,7 @@ if($ticket->isOverdue()) if($ticket->isOpen()){ ?> <tr> <th>Due Date:</th> - <td><?php echo Format::db_datetime($ticket->getDueDate()); ?></td> + <td><?php echo Format::db_datetime($ticket->getEstDueDate()); ?></td> </tr> <?php }else { ?> diff --git a/include/staff/tickets.inc.php b/include/staff/tickets.inc.php index a8db757b1e8517cb8090a74e568ca2d00e5249ef..bef30bfcc4bd9c47d35f41de5187173125f56a0b 100644 --- a/include/staff/tickets.inc.php +++ b/include/staff/tickets.inc.php @@ -217,8 +217,10 @@ if(!$order_by ) { $order_by='ticket.lastresponse, ticket.created'; //No priority sorting for answered tickets. elseif(!strcasecmp($status,'closed')) $order_by='ticket.closed, ticket.created'; //No priority sorting for closed tickets. - else - $order_by='priority_urgency ASC, effective_date, ticket.created'; + elseif($showoverdue) //priority> duedate > age in ASC order. + $order_by='priority_urgency ASC, ISNULL(duedate) ASC, duedate ASC, effective_date ASC, ticket.created'; + else //XXX: Add due date here?? No - + $order_by='priority_urgency ASC, effective_date DESC, ticket.created'; } $order=$order?$order:'DESC'; @@ -256,6 +258,7 @@ $pageNav->setURL('tickets.php',$qstr.'&sort='.urlencode($_REQUEST['sort']).'&ord //ADD attachment,priorities, lock and other crap $qselect.=' ,count(attach.attach_id) as attachments ' .' ,count(DISTINCT thread.id) as thread_count ' + .' ,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 '; @@ -266,7 +269,8 @@ $qfrom.=' LEFT JOIN '.TICKET_PRIORITY_TABLE.' pri ON (ticket.priority_id=pri.pri .' LEFT JOIN '.TICKET_ATTACHMENT_TABLE.' attach ON (ticket.ticket_id=attach.ticket_id) ' .' 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 '.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) '; $query="$qselect $qfrom $qwhere $qgroup ORDER BY $order_by $order LIMIT ".$pageNav->getStart().",".$pageNav->getLimit(); //echo $query;