diff --git a/include/ajax.thread.php b/include/ajax.thread.php index 235a5540b09a649a73127976910a1d75ee409986..0523d851b771ed0eb6839f509d1ca44547382b21 100644 --- a/include/ajax.thread.php +++ b/include/ajax.thread.php @@ -42,7 +42,7 @@ class ThreadAjaxAPI extends AjaxController { } - $hits = TicketModel::objects() + $hits = Ticket::objects() ->filter(Q::any(array( 'number__startswith' => $_REQUEST['q'], ))) diff --git a/include/ajax.tickets.php b/include/ajax.tickets.php index 3a157a511e6ba92c666e25738401ab4320db74f3..9b8afb9785e002540cf54e0864282475d5abf711 100644 --- a/include/ajax.tickets.php +++ b/include/ajax.tickets.php @@ -41,7 +41,7 @@ class TicketsAjaxAPI extends AjaxController { $visibility->add(array('dept_id__in' => $depts)); } - $hits = TicketModel::objects() + $hits = Ticket::objects() ->filter($visibility) ->values('user__default_email__address') ->annotate(array( @@ -59,7 +59,7 @@ class TicketsAjaxAPI extends AjaxController { ->order_by(new SqlCode('__relevance__'), QuerySet::DESC); if (preg_match('/\d{2,}[^*]/', $q, $T = array())) { - $hits = TicketModel::objects() + $hits = Ticket::objects() ->values('user__default_email__address', 'number') ->annotate(array( 'tickets' => new SqlCode('1'), @@ -594,7 +594,7 @@ class TicketsAjaxAPI extends AjaxController { $depts = array(); $tids = $_POST['tids'] ?: array_filter(explode(',', $_REQUEST['tids'])); if ($tids) { - $tickets = TicketModel::objects() + $tickets = Ticket::objects() ->distinct('dept_id') ->filter(array('ticket_id__in' => $tids)); @@ -830,7 +830,7 @@ class TicketsAjaxAPI extends AjaxController { $state = 'open'; break; case 'close': - if (!$role->hasPerm(TicketModel::PERM_CLOSE)) + if (!$role->hasPerm(Ticket::PERM_CLOSE)) Http::response(403, 'Access denied'); $state = 'closed'; @@ -840,7 +840,7 @@ class TicketsAjaxAPI extends AjaxController { break; case 'delete': - if (!$role->hasPerm(TicketModel::PERM_DELETE)) + if (!$role->hasPerm(Ticket::PERM_DELETE)) Http::response(403, 'Access denied'); $state = 'deleted'; break; @@ -877,18 +877,18 @@ class TicketsAjaxAPI extends AjaxController { // Make sure the agent has permission to set the status switch(mb_strtolower($status->getState())) { case 'open': - if (!$role->hasPerm(TicketModel::PERM_CLOSE) - && !$role->hasPerm(TicketModel::PERM_CREATE)) + if (!$role->hasPerm(Ticket::PERM_CLOSE) + && !$role->hasPerm(Ticket::PERM_CREATE)) $errors['err'] = sprintf(__('You do not have permission %s'), __('to reopen tickets')); break; case 'closed': - if (!$role->hasPerm(TicketModel::PERM_CLOSE)) + if (!$role->hasPerm(Ticket::PERM_CLOSE)) $errors['err'] = sprintf(__('You do not have permission %s'), __('to resolve/close tickets')); break; case 'deleted': - if (!$role->hasPerm(TicketModel::PERM_DELETE)) + if (!$role->hasPerm(Ticket::PERM_DELETE)) $errors['err'] = sprintf(__('You do not have permission %s'), __('to archive/delete tickets')); break; @@ -948,12 +948,12 @@ class TicketsAjaxAPI extends AjaxController { $state = 'open'; break; case 'close': - if (!$thisstaff->hasPerm(TicketModel::PERM_CLOSE, false)) + if (!$thisstaff->hasPerm(Ticket::PERM_CLOSE, false)) Http::response(403, 'Access denied'); $state = 'closed'; break; case 'delete': - if (!$thisstaff->hasPerm(TicketModel::PERM_DELETE, false)) + if (!$thisstaff->hasPerm(Ticket::PERM_DELETE, false)) Http::response(403, 'Access denied'); $state = 'deleted'; @@ -987,18 +987,18 @@ class TicketsAjaxAPI extends AjaxController { // Make sure the agent has permission to set the status switch(mb_strtolower($status->getState())) { case 'open': - if (!$thisstaff->hasPerm(TicketModel::PERM_CLOSE, false) - && !$thisstaff->hasPerm(TicketModel::PERM_CREATE, false)) + if (!$thisstaff->hasPerm(Ticket::PERM_CLOSE, false) + && !$thisstaff->hasPerm(Ticket::PERM_CREATE, false)) $errors['err'] = sprintf(__('You do not have permission %s'), __('to reopen tickets')); break; case 'closed': - if (!$thisstaff->hasPerm(TicketModel::PERM_CLOSE, false)) + if (!$thisstaff->hasPerm(Ticket::PERM_CLOSE, false)) $errors['err'] = sprintf(__('You do not have permission %s'), __('to resolve/close tickets')); break; case 'deleted': - if (!$thisstaff->hasPerm(TicketModel::PERM_DELETE, false)) + if (!$thisstaff->hasPerm(Ticket::PERM_DELETE, false)) $errors['err'] = sprintf(__('You do not have permission %s'), __('to archive/delete tickets')); break; diff --git a/include/class.list.php b/include/class.list.php index 3cd9eec9e953f788d5f0ed35c46fba27a2768e46..13c9bf817a18445997077d539868915c2b8ebd8d 100644 --- a/include/class.list.php +++ b/include/class.list.php @@ -1102,7 +1102,7 @@ implements CustomListItem, TemplateVariable, Searchable { 'pk' => array('id'), 'joins' => array( 'tickets' => array( - 'reverse' => 'TicketModel.status', + 'reverse' => 'Ticket.status', ) ) ); diff --git a/include/class.lock.php b/include/class.lock.php index c0e8c2823e696ffd0bdef3fd8c98988bfc6dd815..a1ac1df0fd171e53bfcb2b229d1afa84af9fad67 100644 --- a/include/class.lock.php +++ b/include/class.lock.php @@ -25,7 +25,7 @@ class Lock extends VerySimpleModel { 'pk' => array('lock_id'), 'joins' => array( 'ticket' => array( - 'reverse' => 'TicketModel.lock', + 'reverse' => 'Ticket.lock', 'list' => false, ), 'task' => array( diff --git a/include/class.nav.php b/include/class.nav.php index 9597d0b7daca86bf79a87fcf939d9d4007f8cab5..448b3553942ff8e6d0f904556b45f8ec5ada6cce 100644 --- a/include/class.nav.php +++ b/include/class.nav.php @@ -166,7 +166,7 @@ class StaffNav { 'iconclass'=>'assignedTickets', 'droponly'=>true); - if ($staff->hasPerm(TicketModel::PERM_CREATE, false)) + if ($staff->hasPerm(Ticket::PERM_CREATE, false)) $subnav[]=array('desc'=>__('New Ticket'), 'title' => __('Open a New Ticket'), 'href'=>'tickets.php?a=open', diff --git a/include/class.search.php b/include/class.search.php index d7d44eff5003d23959eff714d6600dcfeb49d9bd..f838606890697fa213aa7f2eff66657c733c5dcb 100644 --- a/include/class.search.php +++ b/include/class.search.php @@ -372,7 +372,7 @@ class MysqlSearchBackend extends SearchBackend { switch ($criteria->model) { case false: - case 'TicketModel': + case 'Ticket': if ($addRelevance) { $criteria = $criteria->extra(array( 'select' => array( diff --git a/include/class.staff.php b/include/class.staff.php index 4f0784b52b985a2f896fac268f12eeadaadc0a40..9d160e64797e14b15972d178bed17b5b5dc23887 100644 --- a/include/class.staff.php +++ b/include/class.staff.php @@ -475,10 +475,10 @@ implements AuthenticatedUser, EmailContact, TemplateVariable, Searchable { } function canManageTickets() { - return $this->hasPerm(TicketModel::PERM_DELETE, false) - || $this->hasPerm(TicketModel::PERM_TRANSFER, false) - || $this->hasPerm(TicketModel::PERM_ASSIGN, false) - || $this->hasPerm(TicketModel::PERM_CLOSE, false); + return $this->hasPerm(Ticket::PERM_DELETE, false) + || $this->hasPerm(Ticket::PERM_TRANSFER, false) + || $this->hasPerm(Ticket::PERM_ASSIGN, false) + || $this->hasPerm(Ticket::PERM_CLOSE, false); } function isManager() { diff --git a/include/class.thread.php b/include/class.thread.php index 3911f714b672fd98287a9ac5578fbbc3d1567473..256b09cfd75d8e7755b23862fd70be227a4d17d9 100644 --- a/include/class.thread.php +++ b/include/class.thread.php @@ -27,7 +27,7 @@ class Thread extends VerySimpleModel { 'ticket' => array( 'constraint' => array( 'object_type' => "'T'", - 'object_id' => 'TicketModel.ticket_id', + 'object_id' => 'Ticket.ticket_id', ), ), 'task' => array( diff --git a/include/class.ticket.php b/include/class.ticket.php index 773296f5acb79f494641526c2aabec37d73b9139..184963136a538910eea0607c582b4e5cd828608c 100644 --- a/include/class.ticket.php +++ b/include/class.ticket.php @@ -36,7 +36,8 @@ require_once(INCLUDE_DIR.'class.collaborator.php'); require_once(INCLUDE_DIR.'class.task.php'); require_once(INCLUDE_DIR.'class.faq.php'); -class TicketModel extends VerySimpleModel { +class Ticket extends VerySimpleModel +implements RestrictedAccess, Threadable, Searchable { static $meta = array( 'table' => TICKET_TABLE, 'pk' => array('ticket_id'), @@ -154,104 +155,6 @@ class TicketModel extends VerySimpleModel { /* @trans */ 'Other', ); - function getId() { - return $this->ticket_id; - } - - function getEffectiveDate() { - return Format::datetime(max( - strtotime($this->thread->lastmessage), - strtotime($this->closed), - strtotime($this->reopened), - strtotime($this->created) - )); - } - - static function registerCustomData(DynamicForm $form) { - if (!isset(static::$meta['joins']['cdata+'.$form->id])) { - $cdata_class = <<<EOF -class DynamicForm{$form->id} extends DynamicForm { - static function getInstance() { - static \$instance; - if (!isset(\$instance)) - \$instance = static::lookup({$form->id}); - return \$instance; - } -} -class TicketCdataForm{$form->id} -extends VerySimpleModel { - static \$meta = array( - 'view' => true, - 'pk' => array('ticket_id'), - 'joins' => array( - 'ticket' => array( - 'constraint' => array('ticket_id' => 'TicketModel.ticket_id'), - ), - ) - ); - static function getQuery(\$compiler) { - return '('.DynamicForm{$form->id}::getCrossTabQuery('T', 'ticket_id').')'; - } -} -EOF; - eval($cdata_class); - $join = array( - 'constraint' => array('ticket_id' => 'TicketCdataForm'.$form->id.'.ticket_id'), - 'list' => true, - ); - // This may be necessary if the model has already been inspected - if (static::$meta instanceof ModelMeta) - static::$meta->addJoin('cdata+'.$form->id, $join); - else { - static::$meta['joins']['cdata+'.$form->id] = array( - 'constraint' => array('ticket_id' => 'TicketCdataForm'.$form->id.'.ticket_id'), - 'list' => true, - ); - } - } - } - - static function getPermissions() { - return self::$perms; - } - - static function getSources() { - static $translated = false; - if (!$translated) { - foreach (static::$sources as $k=>$v) - static::$sources[$k] = __($v); - } - - return static::$sources; - } -} - -RolePermission::register(/* @trans */ 'Tickets', TicketModel::getPermissions(), true); - -class TicketCData extends VerySimpleModel { - static $meta = array( - 'table' => TICKET_CDATA_TABLE, - 'pk' => array('ticket_id'), - 'joins' => array( - 'ticket' => array( - 'constraint' => array('ticket_id' => 'TicketModel.ticket_id'), - ), - ':priority' => array( - 'constraint' => array('priority' => 'Priority.priority_id'), - 'null' => true, - ), - ), - ); -} - -class Ticket extends TicketModel -implements RestrictedAccess, Threadable, Searchable { - - static $meta = array( - 'select_related' => array('topic', 'staff', 'user', 'team', 'dept', 'sla', 'thread', - 'user__default_email'), - ); - var $lastMsgId; var $last_message; @@ -284,6 +187,10 @@ implements RestrictedAccess, Threadable, Searchable { return $this->_answers; } + function getId() { + return $this->ticket_id; + } + function hasState($state) { return strcasecmp($this->getState(), $state) == 0; } @@ -1181,12 +1088,12 @@ implements RestrictedAccess, Threadable, Searchable { if ($role && $this->getStatusId()) { switch ($status->getState()) { case 'closed': - if (!($role->hasPerm(TicketModel::PERM_CLOSE))) + if (!($role->hasPerm(Ticket::PERM_CLOSE))) return false; break; case 'deleted': // XXX: intercept deleted status and do hard delete - if ($role->hasPerm(TicketModel::PERM_DELETE)) + if ($role->hasPerm(Ticket::PERM_DELETE)) return $this->delete($comments); // Agent doesn't have permission to delete tickets return false; @@ -2311,7 +2218,7 @@ implements RestrictedAccess, Threadable, Searchable { if (!$user || ($user->getId() == $this->getOwnerId()) || !($this->checkStaffPerm($thisstaff, - TicketModel::PERM_EDIT)) + Ticket::PERM_EDIT)) ) { return false; } @@ -2800,7 +2707,7 @@ implements RestrictedAccess, Threadable, Searchable { if (!$cfg || !($this->checkStaffPerm($thisstaff, - TicketModel::PERM_EDIT)) + Ticket::PERM_EDIT)) ) { return false; } @@ -3579,7 +3486,7 @@ implements RestrictedAccess, Threadable, Searchable { if ($vars['deptId'] && ($role = $thisstaff->getRole($vars['deptId'])) - && !$role->hasPerm(TicketModel::PERM_CREATE) + && !$role->hasPerm(Ticket::PERM_CREATE) ) { $errors['err'] = sprintf(__('You do not have permission to create a ticket in %s'), __('this department')); return false; @@ -3604,8 +3511,8 @@ implements RestrictedAccess, Threadable, Searchable { // department if ($vars['assignId'] && !( $role - ? $role->hasPerm(TicketModel::PERM_ASSIGN) - : $thisstaff->hasPerm(TicketModel::PERM_ASSIGN, false) + ? $role->hasPerm(Ticket::PERM_ASSIGN) + : $thisstaff->hasPerm(Ticket::PERM_ASSIGN, false) )) { $errors['assignId'] = __('Action Denied. You are not allowed to assign/reassign tickets.'); } @@ -3628,7 +3535,7 @@ implements RestrictedAccess, Threadable, Searchable { // post response - if any $response = null; - if($vars['response'] && $role->hasPerm(TicketModel::PERM_REPLY)) { + if($vars['response'] && $role->hasPerm(Ticket::PERM_REPLY)) { $vars['response'] = $ticket->replaceVars($vars['response']); // $vars['cannedatachments'] contains the attachments placed on // the response form. @@ -3738,5 +3645,79 @@ implements RestrictedAccess, Threadable, Searchable { return ROOT_PATH . sprintf('scp/tickets.php?id=%s', $id); } } + + static function getPermissions() { + return self::$perms; + } + + static function getSources() { + static $translated = false; + if (!$translated) { + foreach (static::$sources as $k=>$v) + static::$sources[$k] = __($v); + } + + return static::$sources; + } + + static function registerCustomData(DynamicForm $form) { + if (!isset(static::$meta['joins']['cdata+'.$form->id])) { + $cdata_class = <<<EOF +class DynamicForm{$form->id} extends DynamicForm { + static function getInstance() { + static \$instance; + if (!isset(\$instance)) + \$instance = static::lookup({$form->id}); + return \$instance; + } +} +class TicketCdataForm{$form->id} +extends VerySimpleModel { + static \$meta = array( + 'view' => true, + 'pk' => array('ticket_id'), + 'joins' => array( + 'ticket' => array( + 'constraint' => array('ticket_id' => 'TicketModel.ticket_id'), + ), + ) + ); + static function getQuery(\$compiler) { + return '('.DynamicForm{$form->id}::getCrossTabQuery('T', 'ticket_id').')'; + } +} +EOF; + eval($cdata_class); + $join = array( + 'constraint' => array('ticket_id' => 'TicketCdataForm'.$form->id.'.ticket_id'), + 'list' => true, + ); + // This may be necessary if the model has already been inspected + if (static::$meta instanceof ModelMeta) + static::$meta->addJoin('cdata+'.$form->id, $join); + else { + static::$meta['joins']['cdata+'.$form->id] = array( + 'constraint' => array('ticket_id' => 'TicketCdataForm'.$form->id.'.ticket_id'), + 'list' => true, + ); + } + } + } +} +RolePermission::register(/* @trans */ 'Tickets', Ticket::getPermissions(), true); + +class TicketCData extends VerySimpleModel { + static $meta = array( + 'pk' => array('ticket_id'), + 'joins' => array( + 'ticket' => array( + 'constraint' => array('ticket_id' => 'Ticket.ticket_id'), + ), + 'priority' => array( + 'constraint' => array('priority' => 'Priority.priority_id'), + 'null' => true, + ), + ), + ); } -?> +TicketCData::$meta['table'] = TABLE_PREFIX . 'ticket__cdata'; diff --git a/include/class.user.php b/include/class.user.php index ce61aa838733778ac0aa54209d196e71d998967b..b8f000af5ab3a5e7fdd134847248d4aefdf1e566 100644 --- a/include/class.user.php +++ b/include/class.user.php @@ -47,7 +47,7 @@ class UserModel extends VerySimpleModel { ), 'tickets' => array( 'null' => true, - 'reverse' => 'TicketModel.user', + 'reverse' => 'Ticket.user', ), 'account' => array( 'list' => false, diff --git a/include/cli/modules/file.php b/include/cli/modules/file.php index ed7916ad8c7c930ece31fd6b9deb88e7901ad909..d70364922e5c4286b1b7e42892bcbd177cf114cf 100644 --- a/include/cli/modules/file.php +++ b/include/cli/modules/file.php @@ -295,7 +295,8 @@ class FileManager extends Module { // Find or create the file record $finfo = $header['file']; - // TODO: Consider the $version code + // TODO: Consider the $version code, drop columns which do + // not exist in this database schema $f = AttachmentFile::lookup($finfo['id']); if ($f) { // Verify file information @@ -319,7 +320,6 @@ class FileManager extends Module { // Bypass the AttachmentFile::create() because we do not // have the data to send yet. $f = new AttachmentFile($finfo); - $f->__new__ = true; if (!$f->save(true)) { $this->fail(sprintf( '%s: Unable to create new file record', @@ -447,10 +447,9 @@ class FileManager extends Module { $files = AttachmentFile::objects(); $this->_applyCriteria($options, $files); - foreach ($files as $m) { + foreach ($files as $f) { // Drop associated attachment links - $m->tickets->expunge(); - $f = AttachmentFile::lookup($m->id); + $f->attachments->expunge(); // Drop file contents if ($bk = $f->open()) diff --git a/include/staff/templates/status-options.tmpl.php b/include/staff/templates/status-options.tmpl.php index 3b493f37927b9cbf608f0a698fa06a8ca5c6e469..1c9bad9e894146e8818a8b34b5fded288cbdda72 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->getRole($ticket ? $ticket->getDeptId() : null)->hasPerm(TicketModel::PERM_CLOSE) +if ($thisstaff->getRole($ticket ? $ticket->getDeptId() : null)->hasPerm(Ticket::PERM_CLOSE) && (!$ticket || !$ticket->getMissingRequiredFields())) $states = array_merge($states, array('closed')); diff --git a/include/staff/templates/ticket-preview.tmpl.php b/include/staff/templates/ticket-preview.tmpl.php index 3533c8af7d8fef1dff05e00b25580e39bcf83d53..671201c48a37007083c00643d17f1088c29e6819 100644 --- a/include/staff/templates/ticket-preview.tmpl.php +++ b/include/staff/templates/ticket-preview.tmpl.php @@ -159,15 +159,15 @@ if($ticket->getNumNotes()) if($ticket->isOpen()) $options[]=array('action'=>__('Reply'),'url'=>"tickets.php?id=$tid#reply"); -if ($role->hasPerm(TicketModel::PERM_ASSIGN)) +if ($role->hasPerm(Ticket::PERM_ASSIGN)) $options[]=array('action'=>($ticket->isAssigned()?__('Reassign'):__('Assign')),'url'=>"tickets.php?id=$tid#assign"); -if ($role->hasPerm(TicketModel::PERM_TRANSFER)) +if ($role->hasPerm(Ticket::PERM_TRANSFER)) $options[]=array('action'=>__('Transfer'),'url'=>"tickets.php?id=$tid#transfer"); $options[]=array('action'=>__('Post Note'),'url'=>"tickets.php?id=$tid#note"); -if ($role->hasPerm(TicketModel::PERM_EDIT)) +if ($role->hasPerm(Ticket::PERM_EDIT)) $options[]=array('action'=>__('Edit Ticket'),'url'=>"tickets.php?id=$tid&a=edit"); if($options) { diff --git a/include/staff/templates/tickets.tmpl.php b/include/staff/templates/tickets.tmpl.php index 71dc0470a6524ed0a4f094c0affebeca37f6ea68..543ecaf7cae5e195333f5390cd8c2533853a5c46 100644 --- a/include/staff/templates/tickets.tmpl.php +++ b/include/staff/templates/tickets.tmpl.php @@ -4,7 +4,7 @@ parse_str($_SERVER['QUERY_STRING'], $args); $args['t'] = 'tickets'; unset($args['p'], $args['_pjax']); -$tickets = TicketModel::objects(); +$tickets = Ticket::objects(); if ($user) { $filter = $tickets->copy() diff --git a/include/staff/ticket-edit.inc.php b/include/staff/ticket-edit.inc.php index e15e8554d3d67afeea3ed47de83429638524dfbd..c3e7e0e4dcef19c80f9aee62776c99a6266d029c 100644 --- a/include/staff/ticket-edit.inc.php +++ b/include/staff/ticket-edit.inc.php @@ -1,7 +1,7 @@ <?php if (!defined('OSTSCPINC') || !$ticket - || !($ticket->checkStaffPerm($thisstaff, TicketModel::PERM_EDIT))) + || !($ticket->checkStaffPerm($thisstaff, Ticket::PERM_EDIT))) die('Access Denied'); $info=Format::htmlchars(($errors && $_POST)?$_POST:$ticket->getUpdateInfo()); diff --git a/include/staff/ticket-open.inc.php b/include/staff/ticket-open.inc.php index 6d383e580aa55714518ab59a7e6707f9b1402940..78912dfb5f1b7655d61e1b6713b575d027552be7 100644 --- a/include/staff/ticket-open.inc.php +++ b/include/staff/ticket-open.inc.php @@ -1,6 +1,6 @@ <?php if (!defined('OSTSCPINC') || !$thisstaff - || !$thisstaff->hasPerm(TicketModel::PERM_CREATE, false)) + || !$thisstaff->hasPerm(Ticket::PERM_CREATE, false)) die('Access Denied'); $info=array(); @@ -248,7 +248,7 @@ if ($_POST) </tr> <?php - if($thisstaff->hasPerm(TicketModel::PERM_ASSIGN, false)) { ?> + if($thisstaff->hasPerm(Ticket::PERM_ASSIGN, false)) { ?> <tr> <td width="160"><?php echo __('Assign To');?>:</td> <td> @@ -291,7 +291,7 @@ if ($_POST) <tbody> <?php //is the user allowed to post replies?? - if ($thisstaff->getRole()->hasPerm(TicketModel::PERM_REPLY)) { ?> + if ($thisstaff->getRole()->hasPerm(Ticket::PERM_REPLY)) { ?> <tr> <th colspan="2"> <em><strong><?php echo __('Response');?></strong>: <?php echo __('Optional response to the above issue.');?></em> @@ -345,7 +345,7 @@ print $response_form->getField('attachments')->render(); <?php $statusId = $info['statusId'] ?: $cfg->getDefaultTicketStatusId(); $states = array('open'); - if ($thisstaff->hasPerm(TicketModel::PERM_CLOSE, false)) + if ($thisstaff->hasPerm(Ticket::PERM_CLOSE, false)) $states = array_merge($states, array('closed')); foreach (TicketStatusList::getStatuses( array('states' => $states)) as $s) { diff --git a/include/staff/ticket-view.inc.php b/include/staff/ticket-view.inc.php index 21d6cf62b6b0c5970d72188c10c133185d2e9126..eb4dee649ab2f1b52d53e64e73bc4204ee3f1d21 100644 --- a/include/staff/ticket-view.inc.php +++ b/include/staff/ticket-view.inc.php @@ -59,7 +59,7 @@ if($ticket->isOverdue()) <div class="pull-right flush-right"> <?php if ($thisstaff->hasPerm(Email::PERM_BANLIST) - || $role->hasPerm(TicketModel::PERM_EDIT) + || $role->hasPerm(Ticket::PERM_EDIT) || ($dept && $dept->isManager($thisstaff))) { ?> <span class="action-button pull-right" data-placement="bottom" data-dropdown="#action-dropdown-more" data-toggle="tooltip" title="<?php echo __('More');?>"> <i class="icon-caret-down pull-right"></i> @@ -68,7 +68,7 @@ if($ticket->isOverdue()) <?php } - if ($role->hasPerm(TicketModel::PERM_EDIT)) { ?> + if ($role->hasPerm(Ticket::PERM_EDIT)) { ?> <span class="action-button pull-right"><a data-placement="bottom" data-toggle="tooltip" title="<?php echo __('Edit'); ?>" href="tickets.php?id=<?php echo $ticket->getId(); ?>&a=edit"><i class="icon-edit"></i></a></span> <?php } ?> @@ -86,7 +86,7 @@ if($ticket->isOverdue()) </div> <?php // Transfer - if ($role->hasPerm(TicketModel::PERM_TRANSFER)) {?> + if ($role->hasPerm(Ticket::PERM_TRANSFER)) {?> <span class="action-button pull-right"> <a class="ticket-action" id="ticket-transfer" data-placement="bottom" data-toggle="tooltip" title="<?php echo __('Transfer'); ?>" data-redirect="tickets.php" @@ -97,7 +97,7 @@ if($ticket->isOverdue()) <?php // Assign - if ($ticket->isOpen() && $role->hasPerm(TicketModel::PERM_ASSIGN)) {?> + if ($ticket->isOpen() && $role->hasPerm(Ticket::PERM_ASSIGN)) {?> <span class="action-button pull-right" data-dropdown="#action-dropdown-assign" data-placement="bottom" @@ -138,7 +138,7 @@ if($ticket->isOverdue()) <div id="action-dropdown-more" class="action-dropdown anchor-right"> <ul> <?php - if ($role->hasPerm(TicketModel::PERM_EDIT)) { ?> + if ($role->hasPerm(Ticket::PERM_EDIT)) { ?> <li><a class="change-user" href="#tickets/<?php echo $ticket->getId(); ?>/change-user"><i class="icon-user"></i> <?php echo __('Change Owner'); ?></a></li> @@ -194,7 +194,7 @@ if($ticket->isOverdue()) <?php } } - if ($role->hasPerm(TicketModel::PERM_DELETE)) { + if ($role->hasPerm(Ticket::PERM_DELETE)) { ?> <li class="danger"><a class="ticket-action" href="#tickets/<?php echo $ticket->getId(); ?>/status/delete" @@ -525,7 +525,7 @@ if ($errors['err'] && isset($_POST['a'])) { > <ul class="tabs" id="response-tabs"> <?php - if ($role->hasPerm(TicketModel::PERM_REPLY)) { ?> + if ($role->hasPerm(Ticket::PERM_REPLY)) { ?> <li class="active <?php echo isset($errors['reply']) ? 'error' : ''; ?>"><a href="#reply" id="post-reply-tab"><?php echo __('Post Reply');?></a></li> @@ -536,7 +536,7 @@ if ($errors['err'] && isset($_POST['a'])) { id="post-note-tab"><?php echo __('Post Internal Note');?></a></li> </ul> <?php - if ($role->hasPerm(TicketModel::PERM_REPLY)) { ?> + if ($role->hasPerm(Ticket::PERM_REPLY)) { ?> <form id="reply" class="tab_content spellcheck exclusive save" data-lock-object-id="ticket/<?php echo $ticket->getId(); ?>" data-lock-id="<?php echo $mylock ? $mylock->getId() : ''; ?>" @@ -696,7 +696,7 @@ if ($errors['err'] && isset($_POST['a'])) { <td> <?php $outstanding = false; - if ($role->hasPerm(TicketModel::PERM_CLOSE) + if ($role->hasPerm(Ticket::PERM_CLOSE) && is_string($warning=$ticket->isCloseable())) { $outstanding = true; echo sprintf('<div class="warning-banner">%s</div>', $warning); @@ -705,7 +705,7 @@ if ($errors['err'] && isset($_POST['a'])) { <?php $statusId = $info['reply_status_id'] ?: $ticket->getStatusId(); $states = array('open'); - if ($role->hasPerm(TicketModel::PERM_CLOSE) && !$outstanding) + if ($role->hasPerm(Ticket::PERM_CLOSE) && !$outstanding) $states = array_merge($states, array('closed')); foreach (TicketStatusList::getStatuses( @@ -794,7 +794,7 @@ if ($errors['err'] && isset($_POST['a'])) { $statusId = $info['note_status_id'] ?: $ticket->getStatusId(); $states = array('open'); if ($ticket->isCloseable() === true - && $role->hasPerm(TicketModel::PERM_CLOSE)) + && $role->hasPerm(Ticket::PERM_CLOSE)) $states = array_merge($states, array('closed')); foreach (TicketStatusList::getStatuses( array('states' => $states)) as $s) { diff --git a/scp/tickets.php b/scp/tickets.php index f381c30593ec5a242d07141c9f63eb6dbbcd2e87..4a5c2a6d6ca3be6aaf2e9892f403a4dc75f9391d 100644 --- a/scp/tickets.php +++ b/scp/tickets.php @@ -85,7 +85,7 @@ if($_POST && !$errors): $role = $thisstaff->getRole($ticket->getDeptId()); switch(strtolower($_POST['a'])): case 'reply': - if (!$role || !$role->hasPerm(TicketModel::PERM_REPLY)) { + if (!$role || !$role->hasPerm(Ticket::PERM_REPLY)) { $errors['err'] = __('Action denied. Contact admin for access'); } else { @@ -196,7 +196,7 @@ if($_POST && !$errors): break; case 'edit': case 'update': - if(!$ticket || !$role->hasPerm(TicketModel::PERM_EDIT)) + if(!$ticket || !$role->hasPerm(Ticket::PERM_EDIT)) $errors['err']=__('Permission Denied. You are not allowed to edit tickets'); elseif($ticket->update($_POST,$errors)) { $msg=__('Ticket updated successfully'); @@ -228,7 +228,7 @@ if($_POST && !$errors): } break; case 'claim': - if(!$role->hasPerm(TicketModel::PERM_EDIT)) { + if(!$role->hasPerm(Ticket::PERM_EDIT)) { $errors['err'] = __('Permission Denied. You are not allowed to assign/claim tickets.'); } elseif(!$ticket->isOpen()) { $errors['err'] = __('Only open tickets can be assigned'); @@ -296,7 +296,7 @@ if($_POST && !$errors): } break; case 'changeuser': - if (!$role->hasPerm(TicketModel::PERM_EDIT)) { + if (!$role->hasPerm(Ticket::PERM_EDIT)) { $errors['err']=__('Permission Denied. You are not allowed to edit tickets'); } elseif (!$_POST['user_id'] || !($user=User::lookup($_POST['user_id']))) { $errors['err'] = __('Unknown user selected'); @@ -320,7 +320,7 @@ if($_POST && !$errors): case 'open': $ticket=null; if (!$thisstaff || - !$thisstaff->hasPerm(TicketModel::PERM_CREATE, false)) { + !$thisstaff->hasPerm(Ticket::PERM_CREATE, false)) { $errors['err'] = sprintf('%s %s', sprintf(__('You do not have permission %s'), __('to create tickets')), @@ -425,7 +425,7 @@ $nav->addSubMenu(function() use ($queue, $adhoc) { }); -if ($thisstaff->hasPerm(TicketModel::PERM_CREATE, false)) { +if ($thisstaff->hasPerm(Ticket::PERM_CREATE, false)) { $nav->addSubMenu(array('desc'=>__('New Ticket'), 'title'=> __('Open a New Ticket'), 'href'=>'tickets.php?a=open', @@ -445,7 +445,7 @@ if($ticket) { $nav->setActiveSubMenu(-1); $inc = 'ticket-view.inc.php'; if ($_REQUEST['a']=='edit' - && $ticket->checkStaffPerm($thisstaff, TicketModel::PERM_EDIT)) { + && $ticket->checkStaffPerm($thisstaff, Ticket::PERM_EDIT)) { $inc = 'ticket-edit.inc.php'; if (!$forms) $forms=DynamicFormEntry::forTicket($ticket->getId()); // Auto add new fields to the entries @@ -459,7 +459,7 @@ if($ticket) { } else { $inc = 'templates/queue-tickets.tmpl.php'; if ($_REQUEST['a']=='open' && - $thisstaff->hasPerm(TicketModel::PERM_CREATE, false)) + $thisstaff->hasPerm(Ticket::PERM_CREATE, false)) $inc = 'ticket-open.inc.php'; elseif($_REQUEST['a'] == 'export') { $ts = strftime('%Y%m%d');