/** * Display a form for adding/editing a record * * @return void */ public function editTask() { $this->view->setLayout('edit'); $this->view->lists = array(); // Get resolutions $sr = new Resolution($this->database); $this->view->lists['resolutions'] = $sr->getResolutions(); $this->view->lists['severities'] = Utilities::getSeverities($this->config->get('severities')); $id = Request::getInt('id', 0); $this->view->row = new Query($this->database); $this->view->row->load($id); if (!$this->view->row->sort) { $this->view->row->sort = 'created'; } if (!$this->view->row->sort_dir) { $this->view->row->sort_dir = 'desc'; } include_once dirname(dirname(__DIR__)) . DS . 'models' . DS . 'conditions.php'; $con = new Conditions(); $this->view->conditions = $con->getConditions(); // Set any errors foreach ($this->getErrors() as $error) { $this->view->setError($error); } // Output the HTML $this->view->display(); }
</label> <?php echo Html::input('calendar', 'target_date', $this->row->get('target_date') != '0000-00-00 00:00:00' ? $this->escape(Date::of($this->row->get('target_date'))->toLocal('Y-m-d H:i:s')) : '', array('id' => 'field-target_date')); ?> </div> <div class="grid"> <div class="col span6"> <div class="input-wrap"> <label for="ticket-field-severity"> <?php echo Lang::txt('COM_SUPPORT_TICKET_COMMENT_SEVERITY'); ?> <select name="severity" id="ticket-field-severity"> <?php foreach (\Components\Support\Helpers\Utilities::getSeverities() as $severity) { ?> <option value="<?php echo $severity; ?> "<?php if ($severity == $this->row->get('severity')) { echo ' selected="selected"'; } ?> ><?php echo Lang::txt('COM_SUPPORT_TICKET_SEVERITY_' . strtoupper($severity)); ?> </option> <?php }
/** * Send emails reminding people of their open tickets * * @param object $job \Components\Cron\Models\Job * @return boolean */ public function sendTicketList(\Components\Cron\Models\Job $job) { $params = $job->get('params'); $database = App::get('db'); $sconfig = Component::params('com_support'); Lang::load('com_support') || Lang::load('com_support', PATH_CORE . DS . 'components' . DS . 'com_support' . DS . 'site'); $sql = "SELECT t.*, o.`name` AS owner_name FROM `#__support_tickets` AS t LEFT JOIN `#__users` AS o ON o.`id`=t.`owner`"; $where = array(); $where[] = "t.`type`=0"; if (is_object($params)) { if ($val = $params->get('support_ticketlist_open', 1)) { $where[] = "t.`open`=" . $val; } $statuses = array(); if (is_numeric($params->get('support_ticketlist_status1'))) { $statuses[] = $params->get('support_ticketlist_status1'); } if (is_numeric($params->get('support_ticketlist_status2'))) { $statuses[] = $params->get('support_ticketlist_status2'); } if (is_numeric($params->get('support_ticketlist_status3'))) { $statuses[] = $params->get('support_ticketlist_status3'); } if (count($statuses)) { $where[] = "t.`status` IN (" . implode(',', $statuses) . ")"; } if ($group = $params->get('support_ticketlist_group')) { $where[] = "t.`group`=" . $database->quote($group); } if ($owners = $params->get('support_ticketlist_owners')) { $usernames = explode(',', $owners); $usernames = array_map('trim', $usernames); foreach ($usernames as $k => $username) { $user = User::getInstance($username); $usernames[$k] = $database->quote($user->get('id')); } $where[] = "t.`owner` IN (" . implode(", ", $usernames) . ")"; } if ($severity = $params->get('support_ticketlist_severity')) { if ($severity != 'all') { $severities = explode(',', $severity); $severities = array_map('trim', $severities); foreach ($severities as $k => $severity) { $severities[$k] = $database->quote($severity); } $where[] = "t.`severity` IN (" . implode(", ", $severities) . ")"; } } if ($owned = intval($params->get('support_ticketlist_owned', 0))) { if ($owned == 1) { $where[] = "(t.`owner` IS NULL OR t.`owner`='0')"; } else { if ($owned == 2) { $where[] = "(t.`owner` IS NOT NULL AND t.`owner` !='0')"; } } } if ($submitters = $params->get('support_ticketlist_submitters')) { $usernames = explode(',', $submitters); $usernames = array_map('trim', $usernames); foreach ($usernames as $k => $username) { $usernames[$k] = $database->quote($username); } $where[] = "t.`login` IN (" . implode(", ", $usernames) . ")"; } if ($tags = $params->get('support_ticketlist_excludeTags')) { $tags = explode(',', $tags); $tags = array_map('trim', $tags); foreach ($tags as $k => $tag) { $tags[$k] = $database->quote($tag); } $where[] = "t.`id` NOT IN (\n\t\t\t\t\t\t\tSELECT jto.`objectid` FROM `#__tags_object` AS jto\n\t\t\t\t\t\t\tJOIN `#__tags` AS jt ON jto.`tagid`=jt.`id`\n\t\t\t\t\t\t\tWHERE jto.`tbl`='support'\n\t\t\t\t\t\t\tAND (\n\t\t\t\t\t\t\t\tjt.`tag` IN (" . implode(", ", $tags) . ") OR jt.`raw_tag` IN (" . implode(", ", $tags) . ")\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t)"; } if ($tags = $params->get('support_ticketlist_includeTags')) { $tags = explode(',', $tags); $tags = array_map('trim', $tags); foreach ($tags as $k => $tag) { $tags[$k] = $database->quote($tag); } $where[] = "t.`id` IN (\n\t\t\t\t\t\t\tSELECT jto.`objectid` FROM `#__tags_object` AS jto\n\t\t\t\t\t\t\tJOIN `#__tags` AS jt ON jto.`tagid`=jt.`id`\n\t\t\t\t\t\t\tWHERE jto.`tbl`='support'\n\t\t\t\t\t\t\tAND (\n\t\t\t\t\t\t\t\tjt.`tag` IN (" . implode(", ", $tags) . ") OR jt.`raw_tag` IN (" . implode(", ", $tags) . ")\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t)"; } if ($created = $params->get('support_ticketlist_created', '+week')) { $op = ''; switch ($created) { // Created before (older than) case '-day': $op = '<='; $timestamp = Date::modify('-1 day'); break; case '-week': $op = '<='; $timestamp = Date::modify('-1 week'); break; case '-2week': $op = '<='; $timestamp = Date::modify('-2 week'); break; case '-3week': $op = '<='; $timestamp = Date::modify('-3 week'); break; case '-month': $op = '<='; $timestamp = Date::modify('-1 month'); break; case '-6month': $op = '<='; $timestamp = Date::modify('-6 month'); break; case '-year': $op = '<='; $timestamp = Date::modify('-1 year'); break; // Created since (newer than) // Created since (newer than) case '+day': $op = '>='; $timestamp = Date::modify('-1 day'); break; case '+week': $op = '>='; $timestamp = Date::modify('-1 week'); break; case '+2week': $op = '>='; $timestamp = Date::modify('-2 week'); break; case '+3week': $op = '>='; $timestamp = Date::modify('-3 week'); break; case '+month': $op = '>='; $timestamp = Date::modify('-1 month'); break; case '+6month': $op = '>='; $timestamp = Date::modify('-6 month'); break; case '+year': $op = '>='; $timestamp = Date::modify('-1 year'); break; } if ($op) { $where[] = "t.`created`" . $op . $database->quote($timestamp->toSql()); } } if ($created = $params->get('support_ticketlist_activity', '--')) { $op = ''; switch ($created) { // Created before (older than) case '-day': $op = '<='; $timestamp = Date::modify('-1 day'); break; case '-week': $op = '<='; $timestamp = Date::modify('-1 week'); break; case '-2week': $op = '<='; $timestamp = Date::modify('-2 week'); break; case '-3week': $op = '<='; $timestamp = Date::modify('-3 week'); break; case '-month': $op = '<='; $timestamp = Date::modify('-1 month'); break; case '-6month': $op = '<='; $timestamp = Date::modify('-6 month'); break; case '-year': $op = '<='; $timestamp = Date::modify('-1 year'); break; case 'all': case '--': $op = ''; break; } if ($op) { $where[] = "(SELECT MAX(c.`created`) FROM `#__support_comments` AS c WHERE c.`ticket`=t.`id`) " . $op . $database->quote($timestamp->toSql()); } } } else { $where[] = "t.`open`=1"; } if (count($where) > 0) { $sql .= " WHERE " . implode(" AND ", $where); } $sql .= " ORDER BY t.`created` ASC LIMIT 0, 500"; $database->setQuery($sql); if (!($results = $database->loadObjectList())) { return true; } include_once PATH_CORE . DS . 'components' . DS . 'com_support' . DS . 'models' . DS . 'ticket.php'; if ($params->get('support_ticketlist_severity', 'all') != 'all') { $severities = explode(',', $params->get('support_ticketlist_severity', 'all')); } else { include_once PATH_CORE . DS . 'components' . DS . 'com_support' . DS . 'helpers' . DS . 'utilities.php'; $severities = \Components\Support\Helpers\Utilities::getSeverities($sconfig->get('severities')); } $from = array(); $from['name'] = Config::get('sitename') . ' ' . Lang::txt('COM_SUPPORT'); $from['email'] = Config::get('mailfrom'); $from['multipart'] = md5(date('U')); // Set mail additional args (mail return path - used for bounces) if ($host = Request::getVar('HTTP_HOST', '', 'server')) { $args = '-f hubmail-bounces@' . $host; } $subject = Lang::txt('COM_SUPPORT') . ': ' . Lang::txt('COM_SUPPORT_TICKETS'); $usernames = array(); if ($users = $params->get('support_ticketlist_notify')) { $usernames = explode(',', $users); $usernames = array_map('trim', $usernames); } $mailed = array(); foreach ($usernames as $owner) { if ($owner == '{config.mailfrom}') { $name = Config::get('mailfrom'); $email = Config::get('mailfrom'); } else { if (strstr($owner, '@')) { $name = $owner; $email = $owner; } else { // Get the user's account $user = User::getInstance($owner); if (!is_object($user) || !$user->get('id')) { continue; } $name = $user->get('name'); $email = $user->get('email'); } } // Try to ensure no duplicates if (in_array($email, $mailed)) { continue; } $eview = new \Hubzero\Mail\View(array('base_path' => PATH_CORE . DS . 'components' . DS . 'com_support' . DS . 'site', 'name' => 'emails', 'layout' => 'ticketlist_plain')); $eview->option = 'com_support'; $eview->controller = 'tickets'; $eview->delimiter = '~!~!~!~!~!~!~!~!~!~!'; $eview->boundary = $from['multipart']; $eview->tickets = $results; $eview->config = $sconfig; $plain = $eview->loadTemplate(false); $plain = str_replace("\n", "\r\n", $plain); // HTML $eview->setLayout('ticketlist_html'); $html = $eview->loadTemplate(); $html = str_replace("\n", "\r\n", $html); // Build message $message = new \Hubzero\Mail\Message(); $message->setSubject($subject)->addFrom($from['email'], $from['name'])->addTo($email, $name)->addHeader('X-Component', 'com_support')->addHeader('X-Component-Object', 'support_ticket_list'); $message->addPart($plain, 'text/plain'); $message->addPart($html, 'text/html'); // Send mail if (!$message->send()) { //$this->setError(Lang::txt('Failed to mail %s', $fullEmailAddress)); Log::error('CRON email failed: ' . Lang::txt('Failed to mail %s', $email)); } $mailed[] = $email; } return true; }
?> </th> <th scope="col"><?php echo Lang::txt('COM_SUPPORT_STATS_COL_NUMBER'); ?> </th> <th scope="col"><?php echo Lang::txt('COM_SUPPORT_STATS_COL_PERCENT'); ?> </th> </tr> </thead> <tbody> <?php $colors = array('#7c7c7c', '#515151', '#404040', '#3d3d3d', '#797979', '#595959', '#e5e5e5', '#828282', '#404040', '#6a6a6a', '#bcbcbc', '#515151', '#d9d9d9', '#3d3d3d', '#797979', '#595959', '#e5e5e5', '#828282', '#404040', '#3a3a3a'); $severities = \Components\Support\Helpers\Utilities::getSeverities($this->config->get('severities')); $cls = 'odd'; $data = array(); $i = 0; foreach ($severities as $severity) { $r = "{label: '" . $this->escape(addslashes($severity)) . "', data: "; $r .= isset($sev[$severity]) ? round($sev[$severity] / $total * 100, 2) : 0; $r .= ", color: '" . $colors[$i] . "'}"; $data[] = $r; $cls = $cls == 'even' ? 'odd' : 'even'; ?> <tr class="<?php echo $cls; ?> "> <th scope="row"><?php
/** * Display a form for processing tickets in a batch * * @return void */ public function batchTask() { Request::setVar('hidemainmenu', 1); // Incoming $this->view->ids = Request::getVar('id', array()); $this->view->tmpl = Request::getVar('tmpl', ''); $this->view->filters = Utilities::getFilters(); $this->view->lists = array(); // Get categories $sa = new Tables\Category($this->database); $this->view->lists['categories'] = $sa->find('list'); // Get severities $this->view->lists['severities'] = Utilities::getSeverities($this->config->get('severities')); $this->view->lists['owner'] = $this->_userSelect('owner', '', 1); // Output the HTML $this->view->display(); }
/** * Create a new record * * @return object */ public function getConditions() { $conditions = new stdClass(); $conditions->owner = $this->_expression(array($this->_operator('=', 'is', true), $this->_operator('!=', 'is not', false), $this->_operator('LIKE \'%$1%\'', 'contains', false), $this->_operator('LIKE \'$1%\'', 'starts with', false), $this->_operator('LIKE \'%$1\'', 'ends with', false), $this->_operator('NOT LIKE \'%$1%\'', 'does not contain', false), $this->_operator('NOT LIKE \'$1%\'', 'does not start with', false), $this->_operator('NOT LIKE \'%$1\'', 'does not end with', false)), 'text'); // Groups $items = array($this->_value('*', Lang::txt('(any of mine)'), true)); if ($xgroups = \Hubzero\User\Helper::getGroups(User::get('id'), 'members')) { foreach ($xgroups as $xgroup) { $xgroup->description = trim($xgroup->description) ?: $xgroup->cn; $items[] = $this->_value($xgroup->cn, stripslashes($this->escape($xgroup->description)), false); } } $conditions->group = $this->_expression(array($this->_operator('=', 'is', true), $this->_operator('!=', 'is not', false), $this->_operator('LIKE \'%$1%\'', 'contains', false), $this->_operator('LIKE \'$1%\'', 'starts with', false), $this->_operator('LIKE \'%$1\'', 'ends with', false), $this->_operator('NOT LIKE \'%$1%\'', 'does not contain', false), $this->_operator('NOT LIKE \'$1%\'', 'does not start with', false), $this->_operator('NOT LIKE \'%$1\'', 'does not end with', false)), $items); $conditions->login = $this->_expression(array($this->_operator('=', 'is', true), $this->_operator('!=', 'is not', false), $this->_operator('LIKE \'%$1%\'', 'contains', false), $this->_operator('LIKE \'$1%\'', 'starts with', false), $this->_operator('LIKE \'%$1\'', 'ends with', false), $this->_operator('NOT LIKE \'%$1%\'', 'does not contain', false), $this->_operator('NOT LIKE \'$1%\'', 'does not start with', false), $this->_operator('NOT LIKE \'%$1\'', 'does not end with', false)), 'text'); $conditions->id = $this->_expression(array($this->_operator('=', 'is', true), $this->_operator('!=', 'is not', false), $this->_operator('lt', 'less than', false), $this->_operator('gt', 'grater than', false), $this->_operator('=lt', 'less than or equal to', false), $this->_operator('gt=', 'greater than or equal to', false)), 'text'); $conditions->report = $this->_expression(array($this->_operator('=', 'is', false), $this->_operator('!=', 'is not', false), $this->_operator('LIKE \'%$1%\'', 'contains', true), $this->_operator('LIKE \'$1%\'', 'starts with', false), $this->_operator('LIKE \'%$1\'', 'ends with', false), $this->_operator('NOT LIKE \'%$1%\'', 'does not contain', false), $this->_operator('NOT LIKE \'$1%\'', 'does not start with', false), $this->_operator('NOT LIKE \'%$1\'', 'does not end with', false)), 'text'); $conditions->open = $this->_expression(array($this->_operator('=', 'is', true), $this->_operator('!=', 'is not', false)), array($this->_value('1', 'open', true), $this->_value('0', 'closed', false))); $sr = new \Components\Support\Tables\Status($this->database); $status = $sr->find('list', array('sort' => 'open', 'sort_Dir' => 'DESC')); $items = array(); $items[] = $this->_value(0, $this->escape('open: New'), true); if (isset($status) && is_array($status)) { $switched = false; foreach ($status as $anode) { if (!$anode->open && !$switched) { $items[] = $this->_value(-1, $this->escape('closed: No resolution'), false); $switched = true; } $items[] = $this->_value($anode->id, $this->escape(($anode->open ? 'open: ' : 'closed: ') . stripslashes($anode->title)), false); } } $conditions->status = $this->_expression(array($this->_operator('=', 'is', true), $this->_operator('!=', 'is not', false)), $items); $conditions->created = $this->_expression(array($this->_operator('=', 'on', true), $this->_operator('lt', 'before', false), $this->_operator('gt', 'after', false)), 'text'); $conditions->closed = $this->_expression(array($this->_operator('=', 'on', true), $this->_operator('lt', 'before', false), $this->_operator('gt', 'after', false)), 'text'); $conditions->tag = $this->_expression(array($this->_operator('=', 'is', true), $this->_operator('!=', 'is not', false)), 'text'); $conditions->type = $this->_expression(array($this->_operator('=', 'is', true), $this->_operator('!=', 'is not', false)), array($this->_value('0', 'user submitted', true), $this->_value('1', 'automatic', false), $this->_value('3', 'tool', false))); $severities = Utilities::getSeverities($this->config->get('severities')); $items = 'text'; if (isset($severities) && is_array($severities)) { $items = array(); foreach ($severities as $severity) { $sel = false; if ($severity == 'normal') { $sel = true; } $items[] = $this->_value($severity, $severity, $sel); } } $conditions->severity = $this->_expression(array($this->_operator('=', 'is', true), $this->_operator('!=', 'is not', false)), $items); $sc = new Category($this->database); $categories = $sc->find('list'); $items = 'text'; if (isset($categories) && is_array($categories)) { $items = array(); foreach ($categories as $anode) { $sel = false; $items[] = $this->_value($this->escape($anode->alias), $this->escape(stripslashes($anode->title)), $sel); } } $conditions->category = $this->_expression(array($this->_operator('=', 'is', true), $this->_operator('!=', 'is not', false)), $items); return $conditions; }
/** * Display a form for adding/editing a record * * @return void */ public function editTask() { Request::setVar('hidemainmenu', 1); $this->view->lists = array(); $this->view->lists['severities'] = Utilities::getSeverities($this->config->get('severities')); $id = Request::getVar('id', array(0)); if (is_array($id)) { $id = !empty($id) ? $id[0] : 0; } $this->view->row = new Query($this->database); $this->view->row->load($id); if (!$this->view->row->sort) { $this->view->row->sort = 'created'; } if (!$this->view->row->sort_dir) { $this->view->row->sort_dir = 'desc'; } include_once dirname(dirname(__DIR__)) . DS . 'models' . DS . 'conditions.php'; $con = new Conditions(); $this->view->conditions = $con->getConditions(); // Set any errors foreach ($this->getErrors() as $error) { $this->view->setError($error); } // Output the HTML $this->view->setLayout('edit')->display(); }
/** * Display a ticket and associated comments * * @param mixed $comment * @return void */ public function ticketTask($comment = null) { // Get the ticket ID $id = Request::getInt('id', 0); if (!$id) { App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->controller . '&task=tickets'), Lang::txt('COM_SUPPORT_ERROR_MISSING_TICKET_ID'), 'error'); return; } // Initiate database class and load info $this->view->row = Ticket::getInstance($id); if (!$this->view->row->exists()) { App::abort(404, Lang::txt('COM_SUPPORT_ERROR_TICKET_NOT_FOUND')); return; } // Check authorization if (User::isGuest()) { $return = base64_encode(Route::url($this->view->row->link(), false, true)); App::redirect(Route::url('index.php?option=com_users&view=login&return=' . $return, false)); return; } // Ensure the user is authorized to view this ticket if (!$this->view->row->access('read', 'tickets')) { App::abort(403, Lang::txt('COM_SUPPORT_ERROR_NOT_AUTH')); return; } $this->view->filters = array('limit' => Request::getState($this->_option . '.' . $this->_controller . '.limit', 'limit', Config::get('list_limit'), 'int'), 'start' => Request::getState($this->_option . '.' . $this->_controller . '.limitstart', 'limitstart', 0, 'int'), 'show' => Request::getState($this->_option . '.' . $this->_controller . '.show', 'show', 0, 'int'), 'search' => urldecode(Request::getState($this->_option . '.' . $this->_controller . '.search', 'search', ''))); if ($watch = Request::getWord('watch', '')) { // Already watching if ($this->view->row->isWatching(User::get('id'))) { // Stop watching? if ($watch == 'stop') { $this->view->row->stopWatching(User::get('id')); } } else { // Start watching? if ($watch == 'start') { $this->view->row->watch(User::get('id')); if (!$this->view->row->isWatching(User::get('id'), true)) { $this->setError(Lang::txt('COM_SUPPORT_ERROR_FAILED_TO_WATCH')); } } } } $this->view->lists = array(); $sc = new Tables\Category($this->database); $this->view->lists['categories'] = $sc->find('list'); // Get messages $sm = new Tables\Message($this->database); $this->view->lists['messages'] = $sm->getMessages(); // Get severities $this->view->lists['severities'] = Utilities::getSeverities($this->config->get('severities')); // Populate the list of assignees based on if the ticket belongs to a group or not if (trim($this->view->row->get('group'))) { $this->view->lists['owner'] = $this->_userSelectGroup('ticket[owner]', $this->view->row->get('owner'), 1, '', trim($this->view->row->get('group'))); } elseif (trim($this->config->get('group'))) { $this->view->lists['owner'] = $this->_userSelectGroup('ticket[owner]', $this->view->row->get('owner'), 1, '', trim($this->config->get('group'))); } else { $this->view->lists['owner'] = $this->_userSelect('ticket[owner]', $this->view->row->get('owner'), 1); } // Set the pathway $this->_buildPathway($this->view->row); // Set the page title $this->_buildTitle($this->view->row); $this->view->title = $this->_title; $this->view->database = $this->database; if (\Notify::any('support')) { foreach (\Notify::messages('support') as $error) { if ($error['type'] == 'error') { $this->view->setError($error['message']); } } } if (!$comment) { $comment = new Comment(); } $this->view->comment = $comment; // Output HTML foreach ($this->getErrors() as $error) { $this->view->setError($error); } $this->view->set('config', $this->config)->setLayout('ticket')->display(); }