/** * Build the query list * * @return void */ public function listTask() { $obj = new Ticket($this->database); // Get query list $sf = new QueryFolder($this->database); $this->view->folders = $sf->find('list', array('user_id' => User::get('id'), 'sort' => 'ordering', 'sort_Dir' => 'asc')); $sq = new Query($this->database); $queries = $sq->find('list', array('user_id' => User::get('id'), 'sort' => 'ordering', 'sort_Dir' => 'asc')); foreach ($queries as $query) { $query->query = $sq->getQuery($query->conditions); $query->count = $obj->getCount($query->query); foreach ($this->view->folders as $k => $v) { if (!isset($this->view->folders[$k]->queries)) { $this->view->folders[$k]->queries = array(); } if ($query->folder_id == $v->id) { $this->view->folders[$k]->queries[] = $query; } } } $this->view->show = 0; // Set any errors foreach ($this->getErrors() as $error) { $this->view->setError($error); } // Output the HTML $this->view->setLayout('list')->display(); }
/** * Serves up files only after passing access checks * * @return void */ public function downloadTask() { // Check logged in status if (User::isGuest()) { $return = base64_encode(Request::getVar('REQUEST_URI', Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&task=' . $this->_task, false, true), 'server')); App::redirect(Route::url('index.php?option=com_users&view=login&return=' . $return, false)); return; } // Get the ID of the file requested $id = Request::getInt('id', 0); // Instantiate an attachment object $attach = new Tables\Attachment($this->database); $attach->load($id); if (!$attach->filename) { throw new Exception(Lang::txt('COM_SUPPORT_ERROR_FILE_NOT_FOUND'), 404); } $file = $attach->filename; // Get the parent ticket the file is attached to $row = new Tables\Ticket($this->database); $row->load($attach->ticket); if (!$row->report) { throw new Exception(Lang::txt('COM_SUPPORT_ERROR_TICKET_NOT_FOUND'), 404); } // Load ACL if ($row->login == User::get('username') || $row->owner == User::get('id')) { if (!$this->acl->check('read', 'tickets')) { $this->acl->setAccess('read', 'tickets', 1); } } if ($this->acl->authorize($row->group)) { $this->acl->setAccess('read', 'tickets', 1); } // Ensure the user is authorized to view this file if (!$this->acl->check('read', 'tickets')) { throw new Exception(Lang::txt('COM_SUPPORT_ERROR_NOT_AUTH'), 403); } // Ensure we have a path if (empty($file)) { throw new Exception(Lang::txt('COM_SUPPORT_ERROR_FILE_NOT_FOUND'), 404); } // Get the configured upload path $basePath = DS . trim($this->config->get('webpath', '/site/tickets'), DS) . DS . $attach->ticket; // Does the path start with a slash? $file = DS . ltrim($file, DS); // Does the beginning of the $attachment->path match the config path? if (substr($file, 0, strlen($basePath)) == $basePath) { // Yes - this means the full path got saved at some point } else { // No - append it $file = $basePath . $file; } // Add root path $filename = PATH_APP . $file; // Ensure the file exist if (!file_exists($filename)) { throw new Exception(Lang::txt('COM_SUPPORT_ERROR_FILE_NOT_FOUND') . ' ' . $filename, 404); } // Initiate a new content server and serve up the file $xserver = new Server(); $xserver->filename($filename); $xserver->disposition('inline'); $xserver->acceptranges(false); // @TODO fix byte range support if (!$xserver->serve()) { // Should only get here on error throw new Exception(Lang::txt('COM_SUPPORT_ERROR_SERVING_FILE'), 500); } else { exit; } return; }
/** * Removes a ticket and all associated records (tags, comments, etc.) * * @return void */ public function removeTask() { // Check for request forgeries Request::checkToken(); // Incoming $ids = Request::getVar('id', array()); // Check for an ID if (count($ids) < 1) { App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_SUPPORT_ERROR_SELECT_TICKET_TO_DELETE'), 'error'); return; } foreach ($ids as $id) { $id = intval($id); // Delete tags $tags = new Tags($id); $tags->removeAll(); // Delete comments $comment = new Tables\Comment($this->database); $comment->deleteComments($id); // Delete attachments $attach = new Tables\Attachment($this->database); $attach->deleteAllForTicket($id); // Delete ticket $ticket = new Tables\Ticket($this->database); $ticket->delete($id); } // Output messsage and redirect App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_SUPPORT_TICKET_SUCCESSFULLY_DELETED', count($ids))); }
/** * Display module contents * * @return void */ public function display() { if (!App::isAdmin()) { return; } include_once Component::path('com_support') . DS . 'tables' . DS . 'query.php'; include_once Component::path('com_support') . DS . 'tables' . DS . 'ticket.php'; $database = App::get('db'); $st = new Ticket($database); $sq = new Query($database); $types = array('common' => $sq->getCommon()); // Loop through each grouping foreach ($types as $key => $queries) { if (!is_array($queries) || count($queries) <= 0) { $one = new stdClass(); $one->count = 0; $one->id = 0; $two = new stdClass(); $two->count = 0; $two->id = 0; $three = new stdClass(); $three->count = 0; $three->id = 0; $types[$key] = $queries = array($one, $two, $three); } // Loop through each query in a group foreach ($queries as $k => $query) { if ($query->id) { // Build the query from the condition set if (!$query->query) { $query->query = $sq->getQuery($query->conditions); } // Get a record count $types[$key][$k]->count = $st->getCount($query->query); } } } $this->topened = $types['common']; $this->offset = Config::get('offset'); $year = Request::getInt('year', strftime("%Y", time() + $this->offset * 60 * 60)); $month = strftime("%m", time() + $this->offset * 60 * 60); $this->year = $year; $this->opened = array(); $this->closed = array(); // First ticket $sql = "SELECT YEAR(created)\n\t\t\t\tFROM `#__support_tickets`\n\t\t\t\tWHERE report!=''\n\t\t\t\tAND type='0' ORDER BY created ASC LIMIT 1"; $database->setQuery($sql); $first = intval($database->loadResult()); // Opened tickets $sql = "SELECT id, created, YEAR(created) AS `year`, MONTH(created) AS `month`, status, owner\n\t\t\t\tFROM `#__support_tickets`\n\t\t\t\tWHERE report!=''\n\t\t\t\tAND type=0"; $sql .= " AND (`group`='' OR `group` IS NULL)"; $sql .= " ORDER BY created ASC"; $database->setQuery($sql); $openTickets = $database->loadObjectList(); $open = array(); $this->opened['open'] = 0; $this->opened['new'] = 0; $this->opened['unassigned'] = 0; foreach ($openTickets as $o) { if (!isset($open[$o->year])) { $open[$o->year] = array(); } if (!isset($open[$o->year][$o->month])) { $open[$o->year][$o->month] = 0; } $open[$o->year][$o->month]++; $this->opened['open']++; if (!$o->status) { $this->opened['new']++; } if (!$o->owner) { $this->opened['unassigned']++; } } // Closed tickets $sql = "SELECT c.ticket, c.created_by, c.created, YEAR(c.created) AS `year`, MONTH(c.created) AS `month`, UNIX_TIMESTAMP(t.created) AS opened, UNIX_TIMESTAMP(c.created) AS closed\n\t\t\t\tFROM `#__support_comments` AS c\n\t\t\t\tLEFT JOIN `#__support_tickets` AS t ON c.ticket=t.id\n\t\t\t\tWHERE t.report!=''\n\t\t\t\tAND type=0 AND open=0"; $sql .= " AND (`group`='' OR `group` IS NULL)"; $sql .= " ORDER BY c.created ASC"; $database->setQuery($sql); $clsd = $database->loadObjectList(); $this->opened['closed'] = 0; $closedTickets = array(); foreach ($clsd as $closed) { if (!isset($closedTickets[$closed->ticket])) { $closedTickets[$closed->ticket] = $closed; } else { if ($closedTickets[$closed->ticket]->created < $closed->created) { $closedTickets[$closed->ticket] = $closed; } } } $this->closedTickets = $closedTickets; $closed = array(); foreach ($closedTickets as $o) { if (!isset($closed[$o->year])) { $closed[$o->year] = array(); } if (!isset($closed[$o->year][$o->month])) { $closed[$o->year][$o->month] = 0; } $closed[$o->year][$o->month]++; $this->opened['closed']++; } // Group data by year and gather some info for each user $y = date("Y"); $y++; $this->closedmonths = array(); $this->openedmonths = array(); for ($k = $first, $n = $y; $k < $n; $k++) { $this->closedmonths[$k] = array(); $this->openedmonths[$k] = array(); for ($i = 1; $i <= 12; $i++) { if ($k == $year && $i > $month) { break; } else { $this->closedmonths[$k][$i] = isset($closed[$k]) && isset($closed[$k][$i]) ? $closed[$k][$i] : 0; $this->openedmonths[$k][$i] = isset($open[$k]) && isset($open[$k][$i]) ? $open[$k][$i] : 0; } } } // Get the view parent::display(); }