Filters a list of resources based on whether a user has certain
permissions on it.
public static permissionsFilter ( array $in, string $filter, integer $permission = Horde_Perms::READ, string $user = null, string $creator = null ) : array | ||
$in | array | A list of resources to check. |
$filter | string | The kind of resource specified in $in, one of 'queue', 'queue_id', 'reply', or 'comment'. |
$permission | integer | A permission, one of the PERM_* constants. |
$user | string | A user name. |
$creator | string | The creator of an object in the resource, e.g. a ticket creator. |
return | array | The list of resources matching the permission criteria. |
/** */ protected function _content() { global $whups_driver; $queues = Whups::permissionsFilter($whups_driver->getQueues(), 'queue', Horde_Perms::READ); $qsummary = $whups_driver->getQueueSummary(array_keys($queues)); if (!$qsummary) { return '<p class="horde-content"><em>' . _("There are no open tickets.") . '</em></p>'; } $summary = $types = array(); foreach ($qsummary as $queue) { $types[$queue['type']] = $queue['type']; if (!isset($summary[$queue['id']])) { $summary[$queue['id']] = $queue; } $summary[$queue['id']][$queue['type']] = $queue['open_tickets']; } $html = '<thead><tr>'; $sortby = 'queue_name'; foreach (array_merge(array('queue_name' => _("Queue")), $types) as $column => $name) { $html .= '<th' . ($sortby == $column ? ' class="sortdown"' : '') . '>' . $name . '</th>'; } $html .= '</tr></thead><tbody>'; foreach ($summary as $queue) { $html .= '<tr><td>' . Horde::link(Whups::urlFor('queue', $queue, true), $queue['description']) . htmlspecialchars($queue['name']) . '</a></td>'; foreach ($types as $type) { $html .= '<td>' . (isset($queue[$type]) ? $queue[$type] : ' ') . '</td>'; } $html .= '</tr>'; } $GLOBALS['page_output']->addScriptFile('tables.js', 'horde'); return '<table id="whups_block_queuesummary" class="horde-table sortable" style="width:100%">' . $html . '</tbody></table>'; }
/** */ protected function _content() { $queue_ids = array_keys(Whups::permissionsFilter($GLOBALS['whups_driver']->getQueues(), 'queue', Horde_Perms::READ)); $info = array('owner' => Whups::getOwnerCriteria($GLOBALS['registry']->getAuth()), 'nores' => true, 'queue' => $queue_ids); $assigned = $GLOBALS['whups_driver']->getTicketsByProperties($info); if (!$assigned) { return '<p class="horde-content"><em>' . _("No tickets are assigned to you.") . '</em></p>'; } return $this->_table($assigned); }
/** */ protected function _content() { global $whups_driver, $prefs; $queue_ids = array_keys(Whups::permissionsFilter($GLOBALS['whups_driver']->getQueues(), 'queue', Horde_Perms::READ)); $info = array('requester' => $GLOBALS['registry']->getAuth(), 'notowner' => 'user:'******'registry']->getAuth(), 'nores' => true, 'queue' => $queue_ids); $requests = $GLOBALS['whups_driver']->getTicketsByProperties($info); if (!$requests) { return '<p class="horde-content"><em>' . _("You have no open requests.") . '</em></p>'; } return $this->_table($requests); }
/** */ private function _getQueue() { if (empty($this->_params['queue'])) { return false; } if (!Whups::permissionsFilter(array($this->_params['queue'] => true), 'queue', Horde_Perms::READ)) { return false; } try { return $GLOBALS['whups_driver']->getQueue($this->_params['queue']); } catch (Whups_Exception $e) { return false; } }
public function __construct(&$vars) { global $whups_driver; parent::__construct($vars, _("Send Reminders")); $queues = Whups::permissionsFilter($whups_driver->getQueues(), 'queue', Horde_Perms::EDIT); if (count($queues)) { $modtype = 'enum'; $type_params = array($queues); } else { $modtype = 'invalid'; $type_params = array(_("There are no queues available.")); } $this->addVariable(_("Send only for this list of ticket ids"), 'id', 'intlist', false); $this->addVariable(_("For tickets from these queues"), 'queue', $modtype, false, false, null, $type_params); $cats = $whups_driver->getCategories(); unset($cats['resolved']); $categories = $this->addVariable(_("For tickets which are"), 'category', 'multienum', false, false, null, array($cats, 3)); $categories->setDefault(array('assigned')); $this->addVariable(_("Unassigned tickets"), 'unassigned', 'email', false, false, _("If you select any tickets that do not have an owner, who should we send email to?")); }
public function __construct(&$vars) { global $whups_driver, $registry; if ($registry->hasMethod('tickets/listQueues') == $registry->getApp()) { parent::__construct($vars, _("Edit or Delete Queues")); $this->setButtons(array(_("Edit Queue"), array('class' => 'horde-delete', 'value' => _("Delete Queue")))); } else { parent::__construct($vars, _("Edit Queues")); $this->setButtons(array(_("Edit Queue"))); } $queues = Whups::permissionsFilter($whups_driver->getQueues(), 'queue', Horde_Perms::EDIT); if ($queues) { $modtype = 'enum'; $type_params = array($queues); } else { $modtype = 'invalid'; $type_params = array(_("There are no queues to edit")); } $this->addVariable(_("Queue Name"), 'queue', $modtype, true, false, null, $type_params); }
public function __construct(&$vars, $title = '') { parent::__construct($vars, $title); $this->addHidden('', 'id', 'int', true, true); /* Queues. */ $this->addVariable(_("New Queue"), 'queue', 'enum', true, false, null, array(Whups::permissionsFilter($GLOBALS['whups_driver']->getQueues(), 'queue', Horde_Perms::EDIT))); $this->addVariable(_("Comment"), 'newcomment', 'longtext', false); /* Group restrictions. */ if ($GLOBALS['registry']->isAdmin(array('permission' => 'whups:admin', 'permlevel' => Horde_Perms::EDIT)) || $GLOBALS['injector']->getInstance('Horde_Perms')->hasPermission('whups:hiddenComments', $GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) { $groups = $GLOBALS['injector']->getInstance('Horde_Group'); $mygroups = $groups->listGroups($GLOBALS['registry']->getAuth()); if ($mygroups) { foreach (array_keys($mygroups) as $gid) { $grouplist[$gid] = $groups->getName($gid, true); } asort($grouplist); $grouplist = array_merge(array(0 => _("Any Group")), $grouplist); $this->addVariable(_("Viewable only by members of"), 'group', 'enum', true, false, null, array($grouplist)); } } }
/** * Fetch the field values of the submitted form. * * @param Horde_Variables $vars A Horde_Variables instance, optional since Horde 3.2. * @param array $info Array to be filled with the submitted field * values. */ public function getInfo($vars, &$info) { parent::getInfo($vars, $info); if (empty($info['queue'])) { $info['queue'] = array_keys(Whups::permissionsFilter($GLOBALS['whups_driver']->getQueues(), 'queue', Horde_Perms::READ, $GLOBALS['registry']->getAuth(), $GLOBALS['registry']->getAuth())); } else { $info['queue'] = array($info['queue']); } if (empty($info['states'])) { unset($info['states']); } // ... if we were given a set of states if (isset($info['states'])) { // collect them into a list of state_id $info['state_id'] = array(); foreach ($info['states'] as $states) { if (isset($states)) { // because null === array_merge(array, null) $info['state_id'] = array_merge($info['state_id'], $states); } } unset($info['states']); } // Remove any queues that don't have a state selected. $types = array(); foreach ($info['queue'] as $queue) { foreach ($GLOBALS['whups_driver']->getTypeIds($queue) as $type) { $types[$type][$queue] = true; } } $queues = array(); foreach ($info['state_id'] as $stateId) { $state = $GLOBALS['whups_driver']->getState($stateId); if (isset($types[$state['type']])) { $queues = array_merge($queues, array_keys($types[$state['type']])); } } $info['queue'] = array_intersect($info['queue'], $queues); }
public function __construct($vars) { global $whups_driver; parent::__construct($vars, _("Create Ticket - Step 1")); $queues = Whups::permissionsFilter($whups_driver->getQueues(), 'queue', Horde_Perms::EDIT); if (!$queues) { $this->addVariable(_("Queue Name"), 'queue', 'invalid', true, false, null, array(_("There are no queues which you can create tickets in."))); } else { foreach (array_keys($queues) as $queue_id) { $info = $whups_driver->getQueue($queue_id); if (!empty($info['description'])) { $queues[$queue_id] .= ' [' . $info['description'] . ']'; } } // Auto-select the only queue if only one option is available if (count($queues) == 1) { $vars->set('queue', array_pop(array_keys($queues))); } $queues = $this->addVariable(_("Queue Name"), 'queue', 'enum', true, false, null, array($queues, _("Choose:"))); $queues->setAction(Horde_Form_Action::factory('submit')); } }
public function __construct($vars) { global $whups_driver; parent::__construct($vars, $vars->get('edit') ? _("Edit Property Criterion") : _("Add Property Criterion"), 'Whups_Form_Query_PropertyCriterion'); $this->addHidden('', 'edit', 'boolean', false); $this->addVariable(_("Id"), 'id', 'intlist', false); /* Types. */ $this->addVariable(_("Type"), 'ttype', 'enum', false, false, null, array($whups_driver->getAllTypes(), _("Any"))); /* Queues. */ $queues = Whups::permissionsFilter($whups_driver->getQueues(), 'queue', Horde_Perms::READ); if (count($queues)) { $v = $this->addVariable(_("Queue"), 'queue', 'enum', false, false, null, array($queues, _("Any"))); $v->setAction(Horde_Form_Action::factory('reload')); if ($vars->get('queue')) { $this->addVariable(_("Version"), 'version', 'enum', false, false, null, array($whups_driver->getVersions($vars->get('queue')), _("Any"))); } } /* States. */ $states = $whups_driver->getStates(); $this->addVariable(_("State"), 'state', 'enum', false, false, null, array($states, _("Any"))); /* Priorities. */ $priorities = $whups_driver->getPriorities(); $this->addVariable(_("Priority"), 'priority', 'enum', false, false, null, array($priorities, _("Any"))); }
/** * Loads a set of tickets, and cache the result inside the Whups_Reports:: * object to save on database access. * * @param string $type 'open', 'closed', or 'all' - the set of * tickets to fetch. A previously cached set * will be returned if it is available. * @param boolean $expanded List tickets once for each owner of the * ticket? * * @return array The ticket set. */ protected function &_getTicketSet($type, $expanded = false) { $queues = array_keys(Whups::permissionsFilter($this->_backend->getQueues(), 'queue')); $expanded = (int) $expanded; switch ($type) { case 'open': if (is_null($this->_opentickets[$expanded])) { $this->_opentickets[$expanded] = $this->_backend->getTicketsByProperties(array('nores' => true, 'queue' => $queues), true, $expanded); } return $this->_opentickets[$expanded]; case 'closed': if (is_null($this->_closedtickets[$expanded])) { $this->_closedtickets[$expanded] = $this->_backend->getTicketsByProperties(array('res' => true, 'queue' => $queues), true, $expanded); } return $this->_closedtickets[$expanded]; case 'all': if (is_null($this->_alltickets[$expanded])) { $this->_alltickets[$expanded] = $this->_backend->getTicketsByProperties(array('queue' => $queues), true, $expanded); } return $this->_alltickets[$expanded]; } }
<?php /** * Copyright 2002-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file LICENSE for license information (BSD). If you * did not receive this file, see http://www.horde.org/licenses/bsdl.php. * * @author Chuck Hagenbuch <*****@*****.**> */ require_once __DIR__ . '/lib/Application.php'; Horde_Registry::appInit('whups'); Whups::addTopbarSearch(); /* Supported graph types. Unused at the moment. */ $graphs = array('open|queue_name' => array('chart', _("Open Tickets by Queue")), 'open|state_name' => array('chart', _("Open Tickets by State")), 'open|type_name' => array('chart', _("Open Tickets by Type")), 'open|priority_name' => array('chart', _("Open Tickets by Priority")), 'open|user_id_requester' => array('chart', _("Open Tickets by Requester")), 'open|owner' => array('chart', _("Open Tickets by Owner")), '@closed:avg:open|owner' => array('plot', _("Average days to close by Owner")), '@closed:avg:open|user_id_requester' => array('plot', _("Average days to close by Requester")), '@closed:avg:open|queue_name' => array('plot', _("Average days to close by Queue"))); /* Supported statistic types. */ $stats = array('avg|open' => _("Average time a ticket is unresolved"), 'max|open' => _("Maximum time a ticket is unresolved"), 'min|open' => _("Minimum time a ticket is unresolved")); $queues = Whups::permissionsFilter($whups_driver->getQueues(), 'queue', Horde_Perms::READ); $reporter = new Whups_Reports($whups_driver); $page_output->header(array('title' => _("Reports"))); $notification->notify(array('listeners' => 'status')); require WHUPS_TEMPLATES . '/reports/stats.inc'; $page_output->footer();
if ($varname == 'owners') { $owners = $gowners = array(); foreach ($value as $owner) { if (strpos($owner, 'user:'******'owners', $owners); $vars->add('group_owners', $gowners); } $vars->add($varname, $value); } if ($tid = $vars->get('transaction')) { $history = Whups::permissionsFilter($whups_driver->getHistory($ticket->getId()), 'comment', Horde_Perms::READ); if (!empty($history[$tid]['comment'])) { // If this was a restricted comment, load the group_id it was // restricted to and default to keeping that restriction on // the reply. foreach ($history[$tid]['changes'] as $change) { if (!empty($change['private'])) { $permission = $GLOBALS['injector']->getInstance('Horde_Perms')->getPermission('whups:comments:' . $change['value']); $group_id = array_shift(array_keys($permission->getGroupPermissions())); $vars->set('group', $group_id); break; } } $flowed = new Horde_Text_Flowed(preg_replace("/\\s*\n/U", "\n", $history[$tid]['comment']), 'UTF-8'); $vars->set('newcomment', $flowed->toFlowed(true)); }
/** * Returns ticket details. * * @param integer $ticket A ticket ID. * @param boolean $checkPerms Enforce permissions? * * @return array A ticket information hash. * @throws Horde_Exception_NotFound * @throws Horde_Exception_PermissionDenied */ public function getTicketDetails($ticket, $checkPerms = true) { $result = $this->getTicketsByProperties(array('id' => $ticket)); if (!isset($result[0])) { throw new Horde_Exception_NotFound(sprintf(_("Ticket %s was not found."), $ticket)); } $queues = Whups::permissionsFilter($this->getQueues(), 'queue', Horde_Perms::READ, $GLOBALS['registry']->getAuth(), $result[0]['user_id_requester']); if ($checkPerms && !in_array($result[0]['queue'], array_flip($queues))) { throw new Horde_Exception_PermissionDenied(sprintf(_("You do not have permission to access this ticket (%s)."), $ticket)); } return $result[0]; }
Horde_Registry::appInit('whups'); $id = Horde_Util::getFormData('ticket'); $filename = Horde_Util::getFormData('file'); $type = Horde_Util::getFormData('type'); // Get the ticket details first. if (empty($id)) { exit; } try { $details = $whups_driver->getTicketDetails($id); } catch (Horde_Exception_PermissionDenied $e) { // No permissions to this ticket. Horde::url($registry->get('webroot', 'horde') . '/login.php', true)->add('url', Horde::selfUrl(true))->redirect(); } // Check permissions on this ticket. if (!count(Whups::permissionsFilter($whups_driver->getHistory($id), 'comment', Horde_Perms::READ))) { throw new Horde_Exception(sprintf(_("You are not allowed to view ticket %d."), $id)); } try { $vfs = $injector->getInstance('Horde_Core_Factory_Vfs')->create(); } catch (Horde_Exception $e) { throw new Horde_Exception(_("The VFS backend needs to be configured to enable attachment uploads.")); } try { $data = $vfs->read(Whups::VFS_ATTACH_PATH . '/' . $id, $filename); } catch (Horde_Vfs_Exception $e) { throw Horde_Exception(sprintf(_("Access denied to %s"), $filename)); } $mime_part = new Horde_Mime_Part(); $mime_part->setType(Horde_Mime_Magic::extToMime($type)); $mime_part->setContents($data);
/** * Sends email notifications to a list of recipients. * * We do some ugly work in here to make sure that no one gets comments * mailed to them that they shouldn't see (because of group permissions). * * @param array $opts Option hash with notification information. * Possible values: * - ticket: (Whups_Ticket) A ticket. If not set, * this is assumed to be a reminder * message. * - recipients: (array|string) The list of recipients, * with user names as keys and user roles * as values. * - subject: (string) The email subject. * - view: (Horde_View) The view object for the * message text. * - template: (string) The template file for the * message text. * - from: (string) The email sender. * - new: (boolean, optional) Whether the passed * ticket was just created. */ public function mail(array $opts) { global $conf, $registry, $prefs; $opts = array_merge(array('ticket' => false, 'new' => false), $opts); /* Set up recipients and message headers. */ $mail = new Horde_Mime_Mail(array('X-Whups-Generated' => 1, 'User-Agent' => 'Whups ' . $registry->getVersion(), 'Precedence' => 'bulk', 'Auto-Submitted' => $opts['ticket'] ? 'auto-replied' : 'auto-generated')); $mail_always = null; if ($opts['ticket'] && !empty($conf['mail']['always_copy'])) { $mail_always = $conf['mail']['always_copy']; if (strpos($mail_always, '<@>') !== false) { try { $mail_always = str_replace('<@>', $opts['ticket']->get('queue_name'), $mail_always); } catch (Whups_Exception $e) { $mail_always = null; } } if ($mail_always && !isset($opts['recipients'][$mail_always])) { $opts['recipients'][$mail_always] = 'always'; } } if ($opts['ticket'] && ($queue = $this->getQueue($opts['ticket']->get('queue'))) && !empty($queue['email'])) { $mail->addHeader('From', $queue['email']); } elseif (!empty($conf['mail']['from_addr'])) { $mail->addHeader('From', $conf['mail']['from_addr']); } else { $mail->addHeader('From', Whups::formatUser($opts['from'])); } if (!empty($conf['mail']['return_path'])) { $mail->addHeader('Return-Path', $conf['mail']['return_path']); } if ($opts['ticket']) { $opts['subject'] = '[' . $registry->get('name') . ' #' . $opts['ticket']->getId() . '] ' . $opts['subject']; } $mail->addHeader('Subject', $opts['subject']); /* Get our array of comments, sorted in the appropriate order. */ if ($opts['ticket']) { $comments = $this->getHistory($opts['ticket']->getId()); if ($conf['mail']['commenthistory'] == 'new' && count($comments)) { $comments = array_pop($comments); $comments = array($comments); } elseif ($conf['mail']['commenthistory'] != 'chronological') { $comments = array_reverse($comments); } } else { $comments = array(); } /* Don't notify any email address more than once. */ $seen_email_addresses = array(); /* Get VFS handle for attachments. */ if ($opts['ticket']) { $vfs = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Vfs')->create(); try { $attachments = Whups::getAttachments($opts['ticket']->getId()); } catch (Whups_Exception $e) { $attachments = array(); Horde::log($e); } } $from = Whups::getUserAttributes($opts['from']); foreach ($opts['recipients'] as $user => $role) { /* Make sure to check permissions as a guest for the 'always_copy' * address, and as the recipient for all others. */ $to = $full_name = ''; if (!empty($mail_always) && $user == $mail_always) { $details = null; $mycomments = Whups::permissionsFilter($comments, 'comment', Horde_Perms::READ, ''); $to = $mail_always; } else { $details = Whups::getUserAttributes($user); if (!empty($details['email'])) { $to = Whups::formatUser($details); $mycomments = Whups::permissionsFilter($comments, 'comment', Horde_Perms::READ, $details['user']); } $full_name = $details['name']; } /* We may have no recipients due to users excluding themselves * from self notifies. */ if (!$to) { continue; } if ($details && $details['type'] == 'user') { $user_prefs = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Prefs')->create('whups', array('user' => $details['user'])); if (($details['user'] == $registry->getAuth() || !$registry->getAuth()) && $from['type'] == 'user' && $details['user'] == $from['user'] && $user_prefs->getValue('email_others_only')) { continue; } } if ($opts['ticket']) { /* Add attachments. */ $attachmentAdded = false; if (empty($GLOBALS['conf']['mail']['link_attach'])) { /* We need to remove all attachments because the attachment * list is potentially limited by permissions. */ $mail->clearParts(); foreach ($mycomments as $comment) { foreach ($comment['changes'] as $change) { if ($change['type'] != 'attachment') { continue; } foreach ($attachments as $attachment) { if ($attachment['name'] != $change['value']) { continue; } if (!isset($attachment['part'])) { $attachment['part'] = new Horde_Mime_Part(); $attachment['part']->setType(Horde_Mime_Magic::filenameToMime($change['value'], false)); $attachment['part']->setDisposition('attachment'); $attachment['part']->setContents($vfs->read(Whups::VFS_ATTACH_PATH . '/' . $opts['ticket']->getId(), $change['value'])); $attachment['part']->setName($change['value']); } $mail->addMimePart($attachment['part']); $attachmentAdded = true; break; } } } } $formattedComment = $this->formatComments($mycomments, $opts['ticket']->getId()); if (!$attachmentAdded && !strlen(trim($formattedComment)) && $details && $details['type'] == 'user' && $user_prefs->getValue('email_comments_only')) { continue; } $opts['view']->comment = $formattedComment; } $addr_ob = new Horde_Mail_Rfc822_Address($to); if ($addr_ob->valid) { $bare_address = $addr_ob->bare_address; if (!empty($seen_email_addresses[$bare_address])) { continue; } $seen_email_addresses[$bare_address] = true; if (empty($full_name) && !is_null($addr_ob->personal)) { $full_name = $addr_ob->personal; } } // Use email address as fallback. if (empty($full_name)) { $full_name = $to; } $opts['view']->full_name = $full_name; $opts['view']->role = $role; $body = $opts['view']->render($opts['template']); if (!strlen(trim($body))) { continue; } $mail->setBody($body); $mail->addHeaderOb(Horde_Mime_Headers_MessageId::create()); if ($opts['ticket']) { $message_id = '<whups-' . $opts['ticket']->getId() . '-' . md5($user) . '@' . $conf['server']['name'] . '>'; if ($opts['new']) { $mail->addHeader('Message-ID', $message_id); } else { $mail->addHeader('In-Reply-To', $message_id); $mail->addHeader('References', $message_id); } } $mail->clearRecipients(); $mail->addHeader('To', $to); try { $mail->send($GLOBALS['injector']->getInstance('Horde_Mail'), true); $entry = sprintf('%s Message sent to %s from "%s"', $_SERVER['REMOTE_ADDR'], $to, $GLOBALS['registry']->getAuth()); Horde::log($entry, 'INFO'); } catch (Horde_Mime_Exception $e) { Horde::log($e, 'ERR'); } } }
public function __construct(&$vars, &$ticket, $title = '') { global $whups_driver; parent::__construct($vars, $title); $type = $vars->get('type'); $start_year = date('Y'); if (is_numeric($d = $vars->get('due'))) { $start_year = min($start_year, date('Y', $d)); } $fields = array('summary'); $qinfo = $whups_driver->getQueue($vars->get('queue')); if (!empty($qinfo['versioned'])) { $fields[] = 'version'; } $fields = array_merge($fields, array('state', 'priority', 'due')); try { $attributes = $ticket->addAttributes(); } catch (Whups_Exception $e) { $attributes = array(); } foreach ($attributes as $attribute) { $fields[] = 'attribute_' . $attribute['id']; } $fields = array_merge($fields, array('owner', 'attachments', 'comment')); $grouped_fields = array($fields); $grouped_hook = false; try { $grouped_fields = Horde::callHook('group_fields', array($ticket->get('type'), $fields), 'whups'); $grouped_hook = true; } catch (Horde_Exception_HookNotSet $e) { } catch (Horde_Exception $e) { Horde::log($e, 'ERR'); } $this->addHidden('', 'id', 'int', true, true); $this->addHidden('', 'type', 'int', true, true); foreach ($grouped_fields as $header => $fields) { if ($grouped_hook) { $this->addVariable($header, null, 'header', false); } foreach ($fields as $field) { switch ($field) { case 'summary': $this->addVariable(_("Summary"), 'summary', 'text', true); break; case 'version': $versions = $whups_driver->getVersions($vars->get('queue')); if (count($versions) == 0) { $vtype = 'invalid'; $v_params = array(_("This queue requires that you specify a version, but there are no versions associated with it. Until versions are created for this queue, you will not be able to create tickets.")); } else { $vtype = 'enum'; $v_params = array($versions); } $this->addVariable(_("Queue Version"), 'version', $vtype, true, false, null, $v_params); break; case 'state': $this->addVariable(_("State"), 'state', 'enum', true, false, null, array($whups_driver->getStates($type))); break; case 'priority': $this->addVariable(_("Priority"), 'priority', 'enum', true, false, null, array($whups_driver->getPriorities($type))); break; case 'due': $this->addVariable(_("Due Date"), 'due', 'datetime', false, false, null, array($start_year)); break; case 'owner': if (Whups::hasPermission($vars->get('queue'), 'queue', 'assign')) { $groups = $GLOBALS['injector']->getInstance('Horde_Group'); $mygroups = $groups->listAll($GLOBALS['conf']['prefs']['assign_all_groups'] ? null : $GLOBALS['registry']->getAuth()); asort($mygroups); $f_users = array(); $users = $whups_driver->getQueueUsers($vars->get('queue')); foreach ($users as $user) { $f_users['user:'******'group:' . $id] = $groups->getName($id); } } if (count($f_users)) { asort($f_users); $this->addVariable(_("Owners"), 'owners', 'multienum', false, false, null, array($f_users)); } if (count($f_groups)) { asort($f_groups); $this->addVariable(_("Group Owners"), 'group_owners', 'multienum', false, false, null, array($f_groups)); } } break; case 'attachments': $this->addVariable(_("Attachment"), 'newattachment', 'file', false); break; case 'comment': $cvar = $this->addVariable(_("Comment"), 'newcomment', 'longtext', false); /* Form replies. */ try { $replies = Whups::permissionsFilter($whups_driver->getReplies($type), 'reply'); } catch (Whups_Exception $e) { $replies = array(); } if (count($replies)) { $params = array(); foreach ($replies as $key => $reply) { $params[$key] = $reply['reply_name']; } $rvar = $this->addVariable(_("Form Reply:"), 'reply', 'enum', false, false, null, array($params, true)); $rvar->setAction(Horde_Form_Action::factory('reload')); if ($vars->get('reply')) { $reply = $vars->get('newcomment'); if (strlen($reply)) { $reply .= "\n\n"; } $reply .= $replies[$vars->get('reply')]['reply_text']; $vars->set('newcomment', $reply); $vars->remove('reply'); } } /* Comment permissions. */ $groups = $GLOBALS['injector']->getInstance('Horde_Group'); $mygroups = $groups->listGroups($GLOBALS['registry']->getAuth()); if ($mygroups) { foreach (array_keys($mygroups) as $gid) { $grouplist[$gid] = $groups->getName($gid, true); } asort($grouplist); $grouplist = array(0 => _("This comment is visible to everyone")) + $grouplist; $this->addVariable(_("Make this comment visible only to members of a group?"), 'group', 'enum', false, false, null, array($grouplist)); } break; default: /* Ticket attributes. */ if ($ticket && substr($field, 0, 10) == 'attribute_' && isset($attributes[substr($field, 10)])) { $attribute = $attributes[substr($field, 10)]; $var = $this->addVariable($attribute['human_name'], 'attribute_' . $attribute['id'], $attribute['type'], $attribute['required'], $attribute['readonly'], $attribute['desc'], $attribute['params']); $var->setDefault($attribute['value']); } } } } }
/** * @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'); } }
/** * List the versions associated with a queue * * @param integer $queue The queue id to get versions for. * * @return array Array of queue versions */ public function listVersions($queue) { $queues = Whups::permissionsFilter(array($queue), 'queue_id'); if (!$queues) { return array(); } $versions = array(); $version_list = $GLOBALS['whups_driver']->getVersionInfoInternal($queue); foreach ($version_list as $version) { $versions[] = array('id' => $version['version_id'], 'name' => $version['version_name'], 'description' => $version['version_description'], 'active' => !empty($version['version_active']), 'readonly' => false); } usort($versions, array($this, '_sortVersions')); return $versions; }