diff --git a/include/class.sla.php b/include/class.sla.php index 66e06d94cf188098e1f2b92dcff636283e5e9a8f..936f300a40b32e6d2071fcfe59391bab43511590 100644 --- a/include/class.sla.php +++ b/include/class.sla.php @@ -188,6 +188,11 @@ implements TemplateVariable { return $entries; } + static function getSLAName($id) { + $slas = static::getSLAs(); + return @$slas[$id]; + } + static function getIdByName($name) { $row = static::objects() ->filter(array('name'=>$name)) diff --git a/include/class.thread.php b/include/class.thread.php index 20cb0f8f246a26e351813595d7c778a640422c70..9df67a1e0142bd15b2d15c6e96afb95227cc2edd 100644 --- a/include/class.thread.php +++ b/include/class.thread.php @@ -1606,9 +1606,13 @@ class ThreadEvent extends VerySimpleModel { return __('None'); case 'data': $val = $self->getData($m['data']); + if (is_array($val)) + list($val, $fallback) = $val; if ($m['type'] && class_exists($m['type'])) $val = $m['type']::lookup($val); - return (string) $val; + if (!$val && $fallback) + $val = $fallback; + return Format::htmlchars((string) $val); } return $m[0]; }, @@ -1779,7 +1783,7 @@ class CloseEvent extends ThreadEvent { static $state = 'closed'; function getDescription($mode=self::MODE_STAFF) { - return $this->template(__('Closed by <b>{somebody}</b> {timestamp}')); + return $this->template(__('Closed by <b>{somebody}</b> with status of {<TicketStatus>data.status} {timestamp}')); } } @@ -1862,7 +1866,6 @@ class EditEvent extends ThreadEvent { $desc = __('<b>{somebody}</b> changed the status to <strong>{<TicketStatus>data.status}</strong> {timestamp}'); break; case isset($data['fields']): - $base = __('Updated by <b>{somebody}</b> {timestamp} — %s'); $fields = $changes = array(); foreach (DynamicFormField::objects()->filter(array( 'id__in' => array_keys($data['fields']) @@ -1880,6 +1883,48 @@ class EditEvent extends ThreadEvent { $changes[] = sprintf('<strong>%s</strong> %s', $field->getLocal('label'), $impl->whatChanged($before, $after)); } + // Fallthrough to other editable fields + case isset($data['topic_id']): + case isset($data['sla_id']): + case isset($data['source']): + case isset($data['user_id']): + case isset($data['duedate']): + $base = __('Updated by <b>{somebody}</b> {timestamp} — %s'); + foreach (array( + 'topic_id' => array(__('Help Topic'), array('Topic', 'getTopicName')), + 'sla_id' => array(__('SLA'), array('SLA', 'getSLAName')), + 'duedate' => array(__('Duedate'), array('Format', 'date')), + 'user_id' => array(__('Ticket Owner'), array('User', 'getNameById')), + 'source' => array(__('Source'), null) + ) as $f => $info) { + if (isset($data[$f])) { + list($name, $desc) = $info; + list($old, $new) = $data[$f]; + if ($desc && is_callable($desc)) { + $new = call_user_func($desc, $new); + if ($old) + $old = call_user_func($desc, $old); + } + if ($old and $new) { + $changes[] = sprintf( + __('<strong>%1$s</strong> changed from <strong>%2$s</strong> to <strong>%3$s</strong>'), + Format::htmlchars($name), Format::htmlchars($old), Format::htmlchars($new) + ); + } + elseif ($new) { + $changes[] = sprintf( + __('<strong>%1$s</strong> set to <strong>%2$s</strong>'), + Format::htmlchars($name), Format::htmlchars($new) + ); + } + else { + $changes[] = sprintf( + __('unset <strong>%1$s</strong>'), + Format::htmlchars($name) + ); + } + } + } $desc = $changes ? sprintf($base, implode(', ', $changes)) : ''; break; diff --git a/include/class.ticket.php b/include/class.ticket.php index 11bcda3db6cecb7a821110c15b048f284bf6eb6b..f13fc2c5855bf2e0c51b812603733c4f234321c4 100644 --- a/include/class.ticket.php +++ b/include/class.ticket.php @@ -1047,8 +1047,8 @@ implements RestrictedAccess, Threadable { $this->staff = $thisstaff; $this->clearOverdue(false); - $ecb = function($t) { - $t->logEvent('closed'); + $ecb = function($t) use ($status) { + $t->logEvent('closed', array('status' => array($status->getId(), $status->getName()))); $t->deleteDrafts(); }; break; @@ -2528,6 +2528,18 @@ implements RestrictedAccess, Threadable { // We are setting new duedate... $this->isoverdue = 0; + $changes = array(); + foreach ($this->dirty as $F=>$old) { + switch ($F) { + case 'topic_id': + case 'user_id': + case 'source': + case 'duedate': + case 'sla_id': + $changes[$F] = array($old, $this->{$F}); + } + } + if (!$this->save()) return false; @@ -2538,9 +2550,9 @@ implements RestrictedAccess, Threadable { $keepSLA = ($this->getSLAId() != $vars['slaId']); // Update dynamic meta-data - $changes = array(); foreach ($forms as $f) { - $changes += $f->getChanges(); + if ($C = $f->getChanges()) + $changes['fields'] = ($changes['fields'] ?: array()) + $C; // Drop deleted forms $idx = array_search($f->getId(), $vars['forms']); if ($idx === false) { @@ -2553,7 +2565,7 @@ implements RestrictedAccess, Threadable { } if ($changes) - $this->logEvent('edited', array('fields' => $changes)); + $this->logEvent('edited', $changes); // Reselect SLA if transient if (!$keepSLA diff --git a/include/class.user.php b/include/class.user.php index d9a7328616065df3be453037ee676b1af0902c8a..8eb17ba4896af48b8c44ba119d7bdc70e9deb94b 100644 --- a/include/class.user.php +++ b/include/class.user.php @@ -701,6 +701,11 @@ implements TemplateVariable { static function lookupByEmail($email) { return static::lookup(array('emails__address'=>$email)); } + + static function getNameById($id) { + if ($user = static::lookup($id)) + return $user->getName(); + } } class EmailAddress diff --git a/include/staff/templates/status-options.tmpl.php b/include/staff/templates/status-options.tmpl.php index e12960def51b8ef35e31f6b5e1ff3b76bb83f0b4..71e05981f349a83830ab8c980f5f5daaa7e8beab 100644 --- a/include/staff/templates/status-options.tmpl.php +++ b/include/staff/templates/status-options.tmpl.php @@ -14,7 +14,7 @@ $actions= array( ); $states = array('open'); -if ($thisstaff->hasPerm(TicketModel::PERM_CLOSE) +if ($thisstaff->getRole($ticket ? $ticket->getDeptId() : null)->hasPerm(TicketModel::PERM_CLOSE) && (!$ticket || !$ticket->getMissingRequiredFields())) $states = array_merge($states, array('closed')); diff --git a/include/staff/templates/ticket-status.tmpl.php b/include/staff/templates/ticket-status.tmpl.php index 5da0e6619c563f15a7bea49f722f95113fae1ead..2caffaae69ea27a2d67548e2d86df093a0fe351f 100644 --- a/include/staff/templates/ticket-status.tmpl.php +++ b/include/staff/templates/ticket-status.tmpl.php @@ -2,7 +2,7 @@ global $cfg; if (!$info['title']) - $info['title'] = 'Change Tickets Status'; + $info['title'] = __('Change Tickets Status'); ?> <h3 class="drag-handle"><?php echo $info['title']; ?></h3>