/** * Generates a table with ticket information. * * @param array $tickets A list of tickets. * @param string $tableClass The DOM ID to use for the generated table. * * @return string Table HTML code. */ protected function _table($tickets, $tableId = null) { if (!$tableId) { $tableId = get_class($this); } $columns = isset($this->_params['columns']) ? $this->_params['columns'] : null; $sortby = $GLOBALS['prefs']->getValue('sortby'); $sortdirclass = ' class="' . ($GLOBALS['prefs']->getValue('sortdir') ? 'sortup' : 'sortdown') . '"'; $html = '<thead><tr><th' . ($sortby == 'id' ? $sortdirclass : '') . '>' . _("Id") . '</th>'; foreach (Whups::getSearchResultColumns('block', $this->_params['columns']) as $name => $column) { if ($column == 'id') { continue; } $html .= '<th' . ($sortby == $column ? $sortdirclass : '') . '>' . $name . '</th>'; } $html .= '</tr></thead><tbody>'; Whups::sortTickets($tickets); foreach ($tickets as $ticket) { foreach (Whups::getSearchResultColumns('block', $columns) as $column) { $thevalue = Whups::formatColumn($ticket, $column); $sortval = ''; if ($column == 'timestamp' || $column == 'due' || substr($column, 0, 5) == 'date_') { $sortval = strlen($ticket[$column]) ? ' sortval="' . $ticket[$column] . '"' : ''; } $html .= '<td' . $sortval . '>' . (strlen($thevalue) ? $thevalue : ' ') . '</td>'; } $html .= '</tr>'; } $GLOBALS['page_output']->addScriptFile('tables.js', 'horde'); return '<table id="' . htmlspecialchars($tableId) . '" class="horde-table sortable" style="width:100%">' . $html . '</tbody></table>'; }
Horde_Registry::appInit('whups'); // See if we were passed a slug or id. Slug is tried first. $slug = Horde_Util::getFormData('slug'); if ($slug) { $queue = $whups_driver->getQueueBySlugInternal($slug); $id = $queue['id']; } else { $id = Horde_Util::getFormData('id'); $queue = $whups_driver->getQueue($id); } if (!$id) { $notification->push(_("Invalid queue"), 'horde.error'); Horde::url($prefs->getValue('whups_default_view') . '.php', true)->redirect(); } Whups::addFeedLink(); $page_output->ajax = true; $page_output->header(array('title' => sprintf(_("Open tickets in %s"), $queue['name']))); $notification->notify(array('listeners' => 'status')); $criteria = array('queue' => $id, 'category' => array('unconfirmed', 'new', 'assigned')); try { $tickets = $whups_driver->getTicketsByProperties($criteria); Whups::sortTickets($tickets); $values = Whups::getSearchResultColumns(); $self = Whups::urlFor('queue', $queue); $results = new Whups_View_Results(array('title' => sprintf(_("Open tickets in %s"), $queue['name']), 'results' => $tickets, 'values' => $values, 'url' => $self)); $session->set('whups', 'last_search', $self); $results->html(); } catch (Whups_Exception $e) { $notification->push(sprintf(_("There was an error locating tickets in this queue: %s"), $e->getMessage()), 'horde.error'); } $page_output->footer();
// See if we were passed a slug or id. Slug is tried first. $whups_query = null; $slug = Horde_Util::getFormData('slug'); if ($slug) { $whups_query = $qManager->getQueryBySlug($slug); } else { $whups_query = $qManager->getQuery(Horde_Util::getFormData('query')); } if (!isset($whups_query) || $whups_query->parameters || !$whups_query->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::READ)) { exit; } $tickets = $whups_driver->executeQuery($whups_query, $vars); if (!count($tickets)) { exit; } Whups::sortTickets($tickets, 'date_updated', 'desc'); $cnt = 0; foreach (array_keys($tickets) as $i) { $description = 'Type: ' . $tickets[$i]['type_name'] . '; State: ' . $tickets[$i]['state_name']; $items[$i]['title'] = htmlspecialchars(sprintf('[%s] %s', $tickets[$i]['id'], $tickets[$i]['summary'])); $items[$i]['description'] = htmlspecialchars($description); $items[$i]['url'] = Whups::urlFor('ticket', $tickets[$i]['id'], true, -1); $items[$i]['pubDate'] = htmlspecialchars(date('r', $tickets[$i]['timestamp'])); } $template = $injector->createInstance('Horde_Template'); $template->set('xsl', Horde_Themes::getFeedXsl()); $template->set('pubDate', htmlspecialchars(date('r'))); $template->set('title', htmlspecialchars($whups_query->name ? $whups_query->name : _("Query Results"))); $template->set('items', $items, true); $url_param = isset($slug) ? array('slug' => $slug) : array('id' => Horde_Util::getFormData('query')); $template->set('url', Whups::urlFor('query', $url_param, true, -1));
/** * @throws Whups_Exception */ public function download(Horde_Variables $vars) { global $injector, $whups_driver; switch ($vars->actionID) { case 'download_file': // Get the ticket details first. if (empty($vars->ticket)) { exit; } $details = $whups_driver->getTicketDetails($vars->ticket); // Check permissions on this ticket. if (!count(Whups::permissionsFilter($whups_driver->getHistory($vars->ticket), 'comment', Horde_Perms::READ))) { throw new Whups_Exception(sprintf(_("You are not allowed to view ticket %d."), $vars->ticket)); } try { $vfs = $injector->getInstance('Horde_Core_Factory_Vfs')->create(); } catch (Horde_Exception $e) { throw new Whups_Exception(_("The VFS backend needs to be configured to enable attachment uploads.")); } try { return array('data' => $vfs->read(Whups::VFS_ATTACH_PATH . '/' . $vars->ticket, $vars->file), 'name' => $vars->file); } catch (Horde_Vfs_Exception $e) { throw new Whups_Exception(sprintf(_("Access denied to %s"), $vars->file)); } break; case 'report': $_templates = Horde::loadConfiguration('templates.php', '_templates', 'whups'); $tpl = $vars->template; if (empty($_templates[$tpl])) { throw new Whups_Exception(_("The requested template does not exist.")); } if ($_templates[$tpl]['type'] != 'searchresults') { throw new Whups_Exception(_("This is not a search results template.")); } // Fetch all unresolved tickets assigned to the current user. $info = array('id' => explode(',', $vars->ids)); $tickets = $whups_driver->getTicketsByProperties($info); foreach ($tickets as $id => $info) { $tickets[$id]['#'] = $id + 1; $tickets[$id]['link'] = Whups::urlFor('ticket', $info['id'], true, -1); $tickets[$id]['date_created'] = strftime('%x', $info['timestamp']); $tickets[$id]['owners'] = Whups::getOwners($info['id']); $tickets[$id]['owner_name'] = Whups::getOwners($info['id'], false, true); $tickets[$id]['owner_email'] = Whups::getOwners($info['id'], true, false); if (!empty($info['date_assigned'])) { $tickets[$id]['date_assigned'] = strftime('%x', $info['date_assigned']); } if (!empty($info['date_resolved'])) { $tickets[$id]['date_resolved'] = strftime('%x', $info['date_resolved']); } // If the template has a callback function defined for data // filtering, call it now. if (!empty($_templates[$tpl]['callback'])) { array_walk($tickets[$id], $_templates[$tpl]['callback']); } } Whups::sortTickets($tickets, isset($_templates[$tpl]['sortby']) ? $_templates[$tpl]['sortby'] : null, isset($_templates[$tpl]['sortdir']) ? $_templates[$tpl]['sortdir'] : null); $template = $injector->createInstance('Horde_Template'); $template->set('tickets', $tickets); $template->set('now', strftime('%x')); $template->set('values', Whups::getSearchResultColumns(null, true)); return array('data' => $template->parse($_templates[$tpl]['template']), 'name' => isset($_templates[$tpl]['filename']) ? $_templates[$tpl]['filename'] : 'report.html'); } }