The results can depend on the current user preferences, which search
function was executed, and the $columns parameter.
public static getSearchResultColumns ( integer $search_type = null, array $columns = null ) | ||
$search_type | integer | The type of search that was executed. Currently only 'block' is supported. |
$columns | array | The columns to return, overriding the defaults for some $search_type. |
/** * 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();
$whups_query->insertCriterion($path, Whups_Query::CRITERION_DUE, null, Whups_Query::OPERATOR_LESS, $info['date_due']['to']); } if ($info['state_id']) { $path = $whups_query->insertBranch('', Whups_Query::TYPE_OR); foreach ($info['state_id'] as $state) { $whups_query->insertCriterion($path, Whups_Query::CRITERION_STATE, null, Whups_Query::OPERATOR_EQUAL, $state); } } $session->set('whups', 'query', $whups_query); Horde::url('query/index.php', true)->add('action', 'save')->redirect(); } try { $tickets = $whups_driver->getTicketsByProperties($info); Whups::sortTickets($tickets); $session->set('whups', 'last_search', Horde::url('search.php?' . _getSearchUrl($vars))); $results = new Whups_View_Results(array('title' => _("Search Results"), 'results' => $tickets, 'values' => Whups::getSearchResultColumns(), 'url' => $session->get('whups', 'last_search'))); $beendone = true; } catch (Whups_Exception $e) { $notification->push(sprintf(_("There was an error performing your search: %s"), $tickets->getMessage()), 'horde.error'); } } Whups::addFeedLink(); $page_output->ajax = true; $page_output->header(array('title' => _("Search"))); $notification->notify(array('listeners' => 'status')); if ($results) { $results->html(); if (is_object($form)) { $form->setTitle(_("Refine Search")); $form->renderActive($renderer, $vars, Horde::url('search.php'), 'get'); }
/** * @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'); } }
$tickets = $whups_driver->executeQuery($whups_query, $vars); $session->set('whups', 'last_search', Horde::url('query/run.php')); } if ($whups_query->id) { $page_output->addLinkTag($whups_query->feedLink()); } $title = $whups_query->name ? $whups_query->name : _("Query Results"); Whups::addFeedLink(); $page_output->ajax = true; $page_output->header(array('title' => $title)); $notification->notify(array('listeners' => 'status')); echo $tabs->render($vars->get('action') ? $vars->get('action') : 'run'); if (!is_null($tickets)) { Whups::sortTickets($tickets); $subscription = null; if (isset($whups_query->id)) { $params = empty($whups_query->slug) ? array('id' => $whups_query->id) : array('slug' => $whups_query->slug); $subscription = Horde::link(Whups::urlFor('query_rss', $params, true, -1), _("Subscribe to this query")) . Horde::img('feed.png', _("Subscribe to this query")) . '</a>'; } $results = new Whups_View_Results(array('title' => $title, 'results' => $tickets, 'extra' => $subscription, 'values' => Whups::getSearchResultColumns(), 'url' => Horde::url('query/run.php'))); $results->html(); } else { $form->open($renderer, $vars, 'query/run.php'); $renderer->beginActive($form->getTitle()); $renderer->renderFormActive($form, $vars); $renderer->submit(_("Execute Query")); $renderer->end(); $form->close($renderer); } $page_output->footer(); $session->set('whups', 'query', $whups_query);