formatUser() public static method

Returns a user string from the user's name and email address.
public static formatUser ( string | array $user = null, boolean $showemail = true, boolean $showname = true, boolean $html = false )
$user string | array A user name or a hash as returned from {@link self::getUserAttributes()}.
$showemail boolean Whether to include the email address.
$showname boolean Whether to include the full name.
$html boolean Whether to "prettify" the result. If true, email addresses are obscured, the result is escaped for HTML output, and a group icon might be added.
Esempio n. 1
0
 public function __construct(&$vars)
 {
     global $whups_driver, $conf;
     parent::__construct($vars, _("Create Ticket - Step 4"));
     /* Preserve previously uploaded attachments. */
     $this->addHidden('', 'deferred_attachment', 'text', false);
     /* Groups. */
     $mygroups = $GLOBALS['injector']->getInstance('Horde_Group')->listAll($conf['prefs']['assign_all_groups'] ? null : $GLOBALS['registry']->getAuth());
     asort($mygroups);
     $users = $whups_driver->getQueueUsers($vars->get('queue'));
     $f_users = array();
     foreach ($users as $user) {
         $f_users['user:'******'group:' . $id] = $group;
         }
     }
     if (count($f_users)) {
         asort($f_users);
         $owners = $this->addVariable(_("Owners"), 'owners', 'multienum', false, false, null, array($f_users));
     }
     if (count($f_groups)) {
         asort($f_groups);
         $group_owners = $this->addVariable(_("Group Owners"), 'group_owners', 'multienum', false, false, null, array($f_groups));
     }
     if (!count($f_users) && !count($f_groups)) {
         $owner_params = array(_("There are no users to which this ticket can be assigned."));
         $this->addVariable(_("Owners"), 'owners', 'invalid', false, false, null, $owner_params);
     }
 }
Esempio n. 2
0
 public function __construct(&$vars)
 {
     global $whups_driver, $registry;
     parent::__construct($vars);
     $queue = $vars->get('queue');
     try {
         $info = $whups_driver->getQueue($queue);
     } catch (Whups_Exception $e) {
         $this->addVariable(_("Invalid Queue"), 'invalid', 'invalid', true, false, null, array(_("Invalid Queue")));
         return;
     }
     $this->setTitle(sprintf(_("Edit %s"), $info['name']));
     $this->addHidden('', 'queue', 'int', true, true);
     $mname = $this->addVariable(_("Queue Name"), 'name', 'text', true, $info['readonly']);
     $mname->setDefault($info['name']);
     $mdesc = $this->addVariable(_("Queue Description"), 'description', 'text', true, $info['readonly']);
     $mdesc->setDefault($info['description']);
     $mslug = $this->addVariable(_("Queue Slug"), 'slug', 'text', false, $info['readonly']);
     $mslug->setDefault($info['slug']);
     $memail = $this->addVariable(_("Queue Email"), 'email', 'email', false, $info['readonly']);
     $memail->setDefault($info['email']);
     $types = $whups_driver->getAllTypes();
     $mtypes = $this->addVariable(_("Ticket Types associated with this Queue"), 'types', 'set', true, false, null, array($types));
     $mtypes->setDefault(array_keys($whups_driver->getTypes($queue)));
     $mdefaults = $this->addVariable(_("Default Ticket Type"), 'default', 'enum', false, false, null, array($types));
     $mdefaults->setDefault($whups_driver->getDefaultType($queue));
     /* Versioned and version link. */
     $mversioned = $this->addVariable(_("Keep a set of versions for this queue?"), 'versioned', 'boolean', false, $info['readonly']);
     $mversioned->setDefault($info['versioned']);
     if ($registry->hasMethod('tickets/listVersions') == $registry->getApp()) {
         $versionlink = array('text' => _("Edit the versions for this queue"), 'url' => Horde::url('admin/?formname=whups_form_admin_editversionstepone')->add('queue', $queue));
         $this->addVariable('', 'link', 'link', false, true, null, array($versionlink));
     }
     /* Usertype and usertype link. */
     $users = $whups_driver->getQueueUsers($queue);
     $f_users = array();
     foreach ($users as $user) {
         $f_users[$user] = Whups::formatUser($user);
     }
     asort($f_users);
     $musers = $this->addVariable(_("Users responsible for this Queue"), 'users', 'set', false, true, null, array($f_users));
     $musers->setDefault($whups_driver->getQueueUsers($queue));
     $userlink = array('text' => _("Edit the users responsible for this queue"), 'url' => Horde::url('admin/?formname=edituserform')->add('queue', $queue));
     $this->addVariable('', 'link', 'link', false, true, null, array($userlink));
     /* Permissions link. */
     if ($GLOBALS['registry']->isAdmin(array('permission' => 'whups:admin', 'permlevel' => Horde_Perms::EDIT))) {
         $permslink = array('text' => _("Edit the permissions on this queue"), 'url' => Horde::url('admin/perms/edit.php', false, array('app' => 'horde'))->add(array('category' => 'whups:queues:' . $queue, 'autocreate' => '1')));
         $this->addVariable('', 'link', 'link', false, true, null, array($permslink));
     }
 }
Esempio n. 3
0
 /**
  * Get the data set
  *
  * @param string $report  The report
  *
  * @return array  The dataset
  */
 public function getDataSet($report)
 {
     $operation = 'inc';
     $state = null;
     list($type, $field) = explode('|', $report);
     if (substr($type, 0, 1) == '@') {
         list($type, $operation, $state) = explode(':', substr($type, 1));
     }
     $tickets = $this->_getTicketSet($type, $field == 'owner');
     if (substr($field, 0, 7) == 'user_id' || $field == 'owner') {
         $user = true;
     } else {
         $user = false;
     }
     $dataset = array();
     foreach ($tickets as $info) {
         switch ($state) {
             case 'open':
                 $date1 = new Horde_Date($info['date_resolved']);
                 $newdata = $date1->diff(new Horde_Date($info['timestamp']));
                 break;
             default:
                 $newdata = 1;
         }
         if (empty($info[$field])) {
             $this->_updateDataSet($dataset, _("None"), $newdata, $operation);
         } else {
             if ($user) {
                 $col = Whups::formatUser($info[$field], false);
             } else {
                 $col = $info[$field];
             }
             $this->_updateDataSet($dataset, $col, $newdata, $operation);
         }
     }
     // Perform any necessary post-processing on the dataset - process
     // averages, for example.
     switch ($operation) {
         case 'avg':
             foreach ($dataset as $index => $data) {
                 $dataset[$index] = number_format(array_sum($data) / count($data), 2);
             }
             break;
     }
     // Sort
     ksort($dataset);
     // Return the final data.
     return $dataset;
 }
Esempio n. 4
0
 public function __construct(&$vars)
 {
     global $whups_driver;
     $this->appendButtons(array(array('class' => 'horde-delete', 'value' => _("Remove User"))));
     parent::__construct($vars, _("Responsible Users"));
     $queue = $vars->get('queue');
     $users = $whups_driver->getQueueUsers($queue);
     $f_users = array();
     foreach ($users as $user) {
         $f_users[$user] = Whups::formatUser($user);
     }
     if ($f_users) {
         asort($f_users);
         $usertype = 'enum';
         $type_params = array($f_users);
     } else {
         $usertype = 'invalid';
         $type_params = array(_("There are no users responsible for this queue."));
     }
     $this->addHidden('', 'queue', 'int', true, true);
     $this->addVariable(_("Users responsible for this queue"), 'user', $usertype, true, false, null, $type_params);
 }
Esempio n. 5
0
     _open();
     $form1->renderActive($renderer, $vars, $adminurl, 'post');
     echo '<br />';
     $vars = new Horde_Variables(array('queue' => $vars->get('queue')));
     $form2 = new Whups_Form_Admin_AddUser($vars);
     $form2->renderActive($renderer, $vars, $adminurl, 'post');
     break;
 case 'whups_form_admin_edituser':
     $form = new Whups_Form_Admin_EditUser($vars);
     if ($form->validate($vars)) {
         $info = $whups_driver->getQueue($vars->get('queue'));
         try {
             $whups_driver->removeQueueUser($vars->get('queue'), $vars->get('user'));
             $notification->push(sprintf(_("\"%s\" is no longer among those responsible for \"%s\""), Whups::formatUser($vars->get('user')), $info['name']), 'horde.success');
         } catch (Whups_Exception $e) {
             $notification->push(sprintf(_("There was an error removing \"%s\" from the responsible list for \"%s\":"), Whups::formatUser($vars->get('user')), $info['name']) . ' ' . $e->getMessage(), 'horde.error');
         }
     }
     _open();
     $vars = new Horde_Variables(array('queue' => $vars->get('queue')));
     $form = new Whups_Form_Admin_EditUser($vars);
     $form->renderActive($renderer, $vars, $adminurl, 'get');
     $form1 = new Whups_Form_Admin_AddUser($vars);
     $form1->renderActive($renderer, $vars, $adminurl, 'get');
     break;
 case 'whups_form_admin_addversion':
     $form = new Whups_Form_Admin_AddVersion($vars);
     if ($form->validate($vars)) {
         try {
             $whups_driver->addVersion($vars->get('queue'), $vars->get('name'), $vars->get('description'), $vars->get('active') == 'on');
             $queuename = $whups_driver->getQueue($vars->get('queue'));
Esempio n. 6
0
 /**
  * Returns tickets by searching for its properties.
  *
  * @param array $info        An array of properties to search for.
  * @param boolean $munge     Munge the query (?)
  * @param boolean $perowner  Group the results per owner?
  *
  * @return array  An array of ticket information hashes.
  * @throws Whups_Exception
  */
 public function getTicketsByProperties(array $info, $munge = true, $perowner = false)
 {
     if (isset($info['queue']) && !count($info['queue'])) {
         return array();
     }
     // Search conditions.
     $where = $this->_generateWhere('whups_tickets', array('ticket_id', 'type_id', 'state_id', 'priority_id', 'queue_id'), $info, 'integer');
     $where2 = $this->_generateWhere('whups_tickets', array('user_id_requester'), $info, 'string');
     if (empty($where)) {
         $where = $where2;
     } elseif (!empty($where2)) {
         $where .= ' AND ' . $where2;
     }
     // Add summary filter if present.
     if (!empty($info['summary'])) {
         $where = $this->_addWhere($where, 1, 'LOWER(whups_tickets.ticket_summary) LIKE ' . $this->_db->quotestring('%' . Horde_String::lower($info['summary']) . '%'));
     }
     // Add date fields.
     if (!empty($info['ticket_timestamp'])) {
         $where = $this->_addDateWhere($where, $info['ticket_timestamp'], 'ticket_timestamp');
     }
     if (!empty($info['date_updated'])) {
         $where = $this->_addDateWhere($where, $info['date_updated'], 'date_updated');
     }
     if (!empty($info['date_assigned'])) {
         $where = $this->_addDateWhere($where, $info['date_assigned'], 'date_assigned');
     }
     if (!empty($info['date_resolved'])) {
         $where = $this->_addDateWhere($where, $info['date_resolved'], 'date_resolved');
     }
     if (!empty($info['ticket_due'])) {
         $where = $this->_addDateWhere($where, $info['ticket_due'], 'ticket_due');
     }
     $fields = array('ticket_id AS id', 'ticket_summary AS summary', 'user_id_requester', 'state_id AS state', 'type_id AS type', 'priority_id AS priority', 'queue_id AS queue', 'date_updated', 'date_assigned', 'date_resolved', 'version_id AS version');
     $fields = $this->_prefixTableToColumns('whups_tickets', $fields) . ', whups_tickets.ticket_timestamp AS timestamp, whups_tickets.ticket_due AS due';
     $tables = 'whups_tickets';
     $join = '';
     $groupby = 'whups_tickets.ticket_id, whups_tickets.ticket_summary, whups_tickets.user_id_requester, whups_tickets.state_id, whups_tickets.type_id, whups_tickets.priority_id, whups_tickets.queue_id, whups_tickets.ticket_timestamp, whups_tickets.ticket_due, whups_tickets.date_updated, whups_tickets.date_assigned, whups_tickets.date_resolved';
     // State filters.
     if (isset($info['category'])) {
         if (is_array($info['category'])) {
             $cat = '';
             foreach ($info['category'] as $category) {
                 if (!empty($cat)) {
                     $cat .= ' OR ';
                 }
                 $cat .= 'whups_states.state_category = ' . $this->_db->quotestring($category);
             }
             $cat = ' AND (' . $cat . ')';
         } else {
             $cat = isset($info['category']) ? ' AND whups_states.state_category = ' . $this->_db->quotestring($info['category']) : '';
         }
     } else {
         $cat = '';
     }
     // Type filters.
     if (isset($info['type_id'])) {
         if (is_array($info['type_id'])) {
             $t = array();
             foreach ($info['type_id'] as $type) {
                 $t[] = 'whups_tickets.type_id = ' . $this->_db->quotestring($type);
             }
             $t = ' AND (' . implode(' OR ', $t) . ')';
         } else {
             $t = isset($info['type_id']) ? ' AND whups_tickets.type_id = ' . $this->_db->quotestring($info['type_id']) : '';
         }
         $this->_addWhere($where, $t, $t);
     }
     $nouc = isset($info['nouc']) ? " AND whups_states.state_category <> 'unconfirmed'" : '';
     $nores = isset($info['nores']) ? " AND whups_states.state_category <> 'resolved'" : '';
     $nonew = isset($info['nonew']) ? " AND whups_states.state_category <> 'new'" : '';
     $noass = isset($info['noass']) ? " AND whups_states.state_category <> 'assigned'" : '';
     $uc = isset($info['uc']) ? " AND whups_states.state_category = 'unconfirmed'" : '';
     $res = isset($info['res']) ? " AND whups_states.state_category = 'resolved'" : '';
     $new = isset($info['new']) ? " AND whups_states.state_category = 'new'" : '';
     $ass = isset($info['ass']) ? " AND whups_states.state_category = 'assigned'" : '';
     // If there are any state filters, add them in.
     if ($nouc || $nores || $nonew || $noass || $uc || $res || $new || $ass || $cat) {
         $where = $this->_addWhere($where, 1, "(whups_tickets.type_id = whups_states.type_id AND whups_tickets.state_id = whups_states.state_id{$nouc}{$nores}{$nonew}{$noass}{$uc}{$res}{$new}{$ass}{$cat})");
     }
     // Initialize join clauses.
     $join = '';
     // Handle owner properties.
     if (isset($info['owner'])) {
         $join .= ' INNER JOIN whups_ticket_owners ON whups_tickets.ticket_id = whups_ticket_owners.ticket_id AND ';
         if (is_array($info['owner'])) {
             $clauses = array();
             foreach ($info['owner'] as $owner) {
                 $clauses[] = 'whups_ticket_owners.ticket_owner = ' . $this->_db->quotestring($owner);
             }
             $join .= '(' . implode(' OR ', $clauses) . ')';
         } else {
             $join .= 'whups_ticket_owners.ticket_owner = ' . $this->_db->quotestring($info['owner']);
         }
     }
     if (isset($info['notowner'])) {
         if ($info['notowner'] === true) {
             // Filter for tickets with no owner.
             $join .= ' LEFT JOIN whups_ticket_owners ON whups_tickets.ticket_id = whups_ticket_owners.ticket_id AND whups_ticket_owners.ticket_owner IS NOT NULL';
         } else {
             $join .= ' LEFT JOIN whups_ticket_owners ON whups_tickets.ticket_id = whups_ticket_owners.ticket_id AND whups_ticket_owners.ticket_owner = ' . $this->_db->quotestring($info['notowner']);
         }
         $where = $this->_addWhere($where, 1, 'whups_ticket_owners.ticket_id IS NULL');
     }
     if ($munge) {
         $myqueues = $GLOBALS['registry']->hasMethod('tickets/listQueues') == $GLOBALS['registry']->getApp();
         $myversions = $GLOBALS['registry']->hasMethod('tickets/listVersions') == $GLOBALS['registry']->getApp();
         $fields = "{$fields}, " . 'whups_types.type_name AS type_name, ' . 'whups_states.state_name AS state_name, ' . 'whups_states.state_category AS state_category, ' . 'whups_priorities.priority_name AS priority_name';
         $join .= ' INNER JOIN whups_types ON whups_tickets.type_id = whups_types.type_id' . ' INNER JOIN whups_states ON whups_tickets.state_id = whups_states.state_id' . ' INNER JOIN whups_priorities ON whups_tickets.priority_id = whups_priorities.priority_id' . ' INNER JOIN whups_states state2 ON whups_tickets.type_id = state2.type_id';
         $groupby .= ', whups_types.type_name, whups_states.state_name, whups_states.state_category';
         if ($myversions) {
             $versions = array();
             $fields .= ', whups_versions.version_name AS version_name' . ', whups_versions.version_description AS version_description' . ', whups_versions.version_active AS version_active';
             $join .= ' LEFT JOIN whups_versions ON whups_tickets.version_id = whups_versions.version_id';
             $groupby .= ', whups_versions.version_name, whups_versions.version_description, whups_versions.version_active, whups_tickets.version_id';
         }
         if ($myqueues) {
             $queues = array();
             $fields .= ', whups_queues.queue_name AS queue_name';
             $join .= ' INNER JOIN whups_queues ON whups_tickets.queue_id = whups_queues.queue_id';
             $groupby .= ', whups_queues.queue_name';
         }
         $groupby .= ', whups_priorities.priority_name';
     }
     if ($perowner) {
         $join .= ' LEFT JOIN whups_ticket_owners ON whups_tickets.ticket_id = whups_ticket_owners.ticket_id';
         $fields .= ', whups_ticket_owners.ticket_owner AS owner';
         $groupby .= ', whups_ticket_owners.ticket_owner';
     }
     $query = "SELECT {$fields} FROM {$tables}{$join} " . (!empty($where) ? "WHERE {$where} " : '') . 'GROUP BY ' . $groupby;
     try {
         $info = $this->_db->selectAll($query);
     } catch (Horde_Db_Exception $e) {
         throw new Whups_Exception($e);
     }
     if (!count($info)) {
         return array();
     }
     $info = $this->_fromBackend($info);
     $tickets = array();
     foreach ($info as $ticket) {
         if ($munge) {
             if (!$myqueues) {
                 if (!isset($queues[$ticket['queue']])) {
                     $queues[$ticket['queue']] = $GLOBALS['registry']->call('tickets/getQueueDetails', array($ticket['queue']));
                 }
                 $ticket['queue_name'] = $queues[$ticket['queue']]['name'];
                 if (isset($queues[$ticket['queue']]['link'])) {
                     $ticket['queue_link'] = $queues[$ticket['queue']]['link'];
                 }
             }
             if (!$myversions) {
                 if (!isset($versions[$ticket['version']])) {
                     $versions[$ticket['version']] = $GLOBALS['registry']->call('tickets/getVersionDetails', array($ticket['version']));
                 }
                 $ticket['version_name'] = $versions[$ticket['version']]['name'];
                 if (isset($versions[$ticket['version']]['link'])) {
                     $ticket['version_link'] = $versions[$ticket['version']]['link'];
                 }
             }
             $ticket['requester_formatted'] = Whups::formatUser($ticket['user_id_requester'], false, true, true);
         }
         $tickets[$ticket['id']] = $ticket;
     }
     foreach ($this->getOwners(array_keys($tickets)) as $id => $owners) {
         $tickets[$id]['owners'] = $owners;
         foreach ($owners as $owner) {
             $tickets[$id]['owners_formatted'][] = Whups::formatUser($owner, false, true, true);
         }
     }
     $attributes = $this->getTicketAttributesWithNames(array_keys($tickets));
     foreach ($attributes as $row) {
         $attribute_id = 'attribute_' . $row['attribute_id'];
         try {
             $tickets[$row['id']][$attribute_id] = Horde_Serialize::unserialize($row['attribute_value'], Horde_Serialize::JSON);
         } catch (Horde_Serialize_Exception $e) {
             $tickets[$row['id']][$attribute_id] = $row['attribute_value'];
         }
         $tickets[$row['id']][$attribute_id . '_name'] = $row['attribute_name'];
     }
     return array_values($tickets);
 }
Esempio n. 7
0
 * did not receive this file, see http://www.horde.org/licenses/bsdl.php.
 *
 * @author Jan Schneider <*****@*****.**>
 */
require_once __DIR__ . '/../lib/Application.php';
Horde_Registry::appInit('whups');
$vars = Horde_Variables::getDefaultVariables();
$ticket = Whups::getCurrentTicket();
$view = $injector->createInstance('Horde_View');
try {
    $files = $ticket->listAllAttachments();
} catch (Whups_Exception $e) {
    $notification->push($e);
}
if ($files) {
    $format = array($prefs->getValue('date_format'), $prefs->getValue('time_format'));
    $attachments = Whups::getAttachments($ticket->getId());
    $view->attachments = array();
    foreach ($files as $file) {
        $view->attachments[] = array_merge(array('timestamp' => $file['timestamp'], 'date' => strftime($format[0], $file['timestamp']) . ' ' . strftime($format[1], $file['timestamp']), 'user' => Whups::formatUser(Whups::getUserAttributes($file['user_id']), true, true, true)), Whups::attachmentUrl($ticket->getId(), $attachments[$file['value']], $ticket->get('queue')));
    }
}
Whups::addTopbarSearch();
Whups::addFeedLink();
$page_output->addLinkTag($ticket->feedLink());
$page_output->addScriptFile('tables.js', 'horde');
$page_output->header(array('title' => sprintf(_("Attachments for %s"), '[#' . $id . '] ' . $ticket->get('summary'))));
$notification->notify(array('listeners' => 'status'));
echo Whups::getTicketTabs($vars, $ticket->getId())->render('attachments');
echo $view->render('ticket/attachments');
$page_output->footer();
Esempio n. 8
0
    public function render($transaction, &$vars)
    {
        global $prefs, $conf, $registry;
        static $canUpdate, $comment_count = 0;
        if (!isset($canUpdate)) {
            $canUpdate = $GLOBALS['registry']->getAuth() && Whups::hasPermission($vars->get('queue'), 'queue', 'update');
        }
        $comment = '';
        $private = false;
        $changes = array();
        $changelist = $vars->get('changes');
        if (!$changelist) {
            return '';
        }
        /* Format each change in this history entry, including comments,
         * etc. */
        foreach ($changelist as $change) {
            switch ($change['type']) {
                case 'summary':
                    $changes[] = sprintf(_("Summary &rArr; %s"), htmlspecialchars($change['value']));
                    break;
                case 'message':
                    $ticket = $vars->get('ticket_id');
                    try {
                        if (Whups::hasMessage($ticket, $change['value'])) {
                            $changes[] = implode(' ', Whups::messageUrls($ticket, $change['value'], $vars->get('queue')));
                        }
                    } catch (Whups_Exception $e) {
                    }
                    break;
                case 'delete-attachment':
                    $changes[] = _("Deleted Original Message");
                    break;
                case 'attachment':
                    $ticket = $vars->get('ticket_id');
                    try {
                        if ($file = Whups::getAttachments($ticket, $change['value'])) {
                            $changes[] = sprintf(_("New Attachment: %s"), implode(' ', Whups::attachmentUrl($ticket, $file, $vars->get('queue'))));
                        } else {
                            $changes[] = sprintf(_("New Attachment: %s"), htmlspecialchars($change['value']));
                        }
                    } catch (Whups_Exception $e) {
                        $changes[] = sprintf(_("New Attachment: %s"), htmlspecialchars($change['value']));
                    }
                    break;
                case 'delete-attachment':
                    $changes[] = sprintf(_("Deleted Attachment: %s"), htmlspecialchars($change['value']));
                    break;
                case 'assign':
                    $changes[] = sprintf(_("Assigned to %s"), Whups::formatUser($change['value'], false, true, true));
                    break;
                case 'unassign':
                    $changes[] = sprintf(_("Taken from %s"), Whups::formatUser($change['value'], false, true, true));
                    break;
                case 'comment':
                    $comment = $change['comment'];
                    $private = !empty($change['private']);
                    if ($comment) {
                        $reply = Horde::link(Horde::url($canUpdate ? 'ticket/update.php' : 'ticket/comment.php')->add(array('id' => $vars->get('ticket_id'), 'transaction' => $transaction))) . _("Reply to this comment") . '</a>';
                    }
                    break;
                case 'queue':
                    $changes[] = sprintf(_("Queue &rArr; %s"), htmlspecialchars($change['label']));
                    break;
                case 'version':
                    $changes[] = sprintf(_("Version &rArr; %s"), htmlspecialchars($change['label']));
                    break;
                case 'type':
                    $changes[] = sprintf(_("Type &rArr; %s"), htmlspecialchars($change['label']));
                    break;
                case 'state':
                    $changes[] = sprintf(_("State &rArr; %s"), htmlspecialchars($change['label']));
                    break;
                case 'priority':
                    $changes[] = sprintf(_("Priority &rArr; %s"), htmlspecialchars($change['label']));
                    break;
                case 'attribute':
                    $changes[] = sprintf(_("%s &rArr; %s"), htmlspecialchars($change['label']), htmlspecialchars($change['human']));
                    break;
                case 'due':
                    if ($change['label']) {
                        $changes[] = sprintf(_("Due &rArr; %s"), strftime($prefs->getValue('date_format'), $change['label']));
                    }
                    break;
            }
        }
        if ($comment) {
            $flowed = new Horde_Text_Flowed($comment, 'UTF-8');
            $flowed->setDelSp(true);
            $comment = $flowed->toFlowed(false);
            $comment = $GLOBALS['injector']->getInstance('Horde_Core_Factory_TextFilter')->filter($comment, array('text2html', 'simplemarkup', 'highlightquotes'), array(array('parselevel' => Horde_Text_Filter_Text2html::MICRO), array('html' => true), array('hideBlocks' => true)));
            if ($prefs->getValue('autolink_tickets') && $conf['prefs']['autolink_terms']) {
                // Replace existing links by tokens to avoid double linking.
                $comment = preg_replace_callback('/<a.*?<\\/a>/', array($this, '_writeTokens'), $comment);
                $comment = preg_replace_callback('/(' . $conf['prefs']['autolink_terms'] . ')\\s*#?(\\d+)/i', array($this, '_autolink'), $comment);
                $comment = preg_replace_callback('/\\0/', array($this, '_readTokens'), $comment);
            }
            $comment_count++;
            if ($private) {
                $comment_label = Horde::img('locked.png') . sprintf(_("Comment #%d (Private)"), $comment_count);
            } else {
                $comment_label = sprintf(_("Comment #%d"), $comment_count);
            }
            array_unshift($changes, '<a href="#c' . $comment_count . '" id="c' . $comment_count . '">' . $comment_label . '</a>');
        }
        if (count($changes)) {
            // Admins can delete entries.
            $delete_link = '';
            if (Whups::hasPermission($vars->get('queue'), 'queue', Horde_Perms::DELETE)) {
                $delete_link = Horde::url('ticket/delete_history.php')->add(array('transaction' => $transaction, 'id' => $vars->get('ticket_id'), 'url' => Whups::urlFor('ticket', $vars->get('ticket_id'), true)))->link(array('title' => _("Delete entry"), 'onclick' => 'return window.confirm(\'' . addslashes(_("Permanently delete entry?")) . '\');')) . Horde::img('delete.png', _("Delete entry")) . '</a>';
            }
            Horde::startBuffer();
            $class = $private ? 'pc' : 'c';
            ?>
<div id="t<?php 
            echo (int) $transaction;
            ?>
">
<table cellspacing="0" width="100%">
 <tr>
  <td width="20%" class="<?php 
            echo $class;
            ?>
_l nowrap" valign="top"><?php 
            echo strftime($prefs->getValue('date_format') . ' ' . $prefs->getValue('time_format'), $vars->get('timestamp'));
            ?>
</td>
  <td width="20%" class="<?php 
            echo $class;
            ?>
_m" valign="top"><?php 
            echo $vars->get('user_id') ? Whups::formatUser($vars->get('user_id'), false, true, true) : '&nbsp;';
            ?>
</td>
  <td width="30%" class="<?php 
            echo $class;
            ?>
_m" valign="top"><?php 
            echo implode('<br />', $changes);
            ?>
</td>
  <td width="30%" class="<?php 
            echo $class;
            ?>
_r rightAlign" valign="top"><?php 
            if ($comment && !$private) {
                echo $reply . ' ';
            }
            echo $delete_link;
            ?>
</td>
 </tr>
<?php 
            if ($comment) {
                ?>
 <tr><td colspan="4" class="<?php 
                echo $class;
                ?>
_b">
  <div class="comment-body fixed">
   <?php 
                echo $comment;
                ?>
  </div>
 </td></tr>
<?php 
            } else {
                ?>
 <tr><td colspan="4" class="c_b">&nbsp;</td></tr>
<?php 
            }
            ?>
</table>
</div>
<?php 
            $html = Horde::endBuffer();
            return $html;
        }
        return '';
    }
Esempio n. 9
0
 /**
  * Converts a changeset array to a plain text comment snippet.
  *
  * @param array $comments  A changeset list.
  * @param integer $ticket  A ticket ID.
  *
  * @return string  The formatted comment text, if any.
  */
 public function formatComments($comments, $ticket)
 {
     $text = '';
     foreach ($comments as $comment) {
         if (!empty($comment['comment_text'])) {
             $text .= "\n" . sprintf(_("%s (%s) wrote:"), Whups::formatUser($comment['user_id']), strftime('%Y-%m-%d %H:%M', $comment['timestamp'])) . "\n\n" . $comment['comment_text'] . "\n\n\n";
         }
         /* Add attachment links. */
         if (empty($GLOBALS['conf']['mail']['link_attach'])) {
             continue;
         }
         foreach ($comment['changes'] as $change) {
             if ($change['type'] != 'attachment') {
                 continue;
             }
             $url_params = array('actionID' => 'download_file', 'file' => $change['value'], 'ticket' => $ticket);
             $text .= "\n" . sprintf(_("%s (%s) uploaded: %s"), Whups::formatUser($comment['user_id']), strftime('%Y-%m-%d %H:%M', $comment['timestamp']), $change['value']) . "\n\n" . Horde::url($GLOBALS['registry']->downloadUrl($change['value'], $url_params), true) . "\n\n\n";
         }
     }
     return $text;
 }
Esempio n. 10
0
 /**
  * Notifies all appropriate people of the creation/update of this ticket.
  *
  * @param string  $author   Who created/changed the ticket?
  * @param boolean $isNew    Is this a new ticket or a change to an existing
  *                          one?
  * @param array $listeners  The list of listener that should receive the
  *                          notification, with user names as keys and user
  *                          roles as values. If empty, the list will be
  *                          created automatically.
  */
 public function notify($author, $isNew, $listeners = array())
 {
     global $conf, $whups_driver;
     /* Get the attributes for this ticket. */
     $attributes = $whups_driver->getAttributesForType($this->get('type'));
     $fields = array('queue' => _("Queue"), 'version' => _("Version"), 'type' => _("Type"), 'state' => _("State"), 'priority' => _("Priority"), 'due' => _("Due"));
     $field_names = array_merge($fields, array(_("Created By"), _("Updated By"), _("Summary"), _("Owners"), _("New Attachment"), _("Deleted Attachment")));
     foreach ($attributes as $attribute) {
         $field_names[] = $attribute['human_name'];
     }
     /* Find the longest translated field name. */
     $length = 0;
     foreach ($field_names as $field_name) {
         $length = max($length, Horde_String::length($field_name));
     }
     $wrap_break = "\n" . str_repeat(' ', $length + 2) . '| ';
     $wrap_width = 73 - $length;
     /* Ticket URL. */
     $url = sprintf(_("Ticket URL: %s"), Whups::urlFor('ticket', $this->_id, true, -1));
     /* Ticket properties. */
     $table = "------------------------------------------------------------------------------\n" . ' ' . Horde_String::pad(_("Ticket"), $length) . ' | ' . $this->_id . "\n" . ' ' . Horde_String::pad($isNew ? _("Created By") : _("Updated By"), $length) . ' | ' . Whups::formatUser($author) . "\n";
     if (isset($this->_changes['summary'])) {
         $table .= '-' . Horde_String::pad(_("Summary"), $length) . ' | ' . Horde_String::wrap($this->_changes['summary']['from'], $wrap_width, $wrap_break) . "\n" . '+' . Horde_String::pad(_("Summary"), $length) . ' | ' . Horde_String::wrap($this->get('summary'), $wrap_width, $wrap_break) . "\n";
     } else {
         $table .= ' ' . Horde_String::pad(_("Summary"), $length) . ' | ' . Horde_String::wrap($this->get('summary'), $wrap_width, $wrap_break) . "\n";
     }
     foreach ($fields as $field => $label) {
         if ($name = $this->get($field . '_name')) {
             if (isset($this->_changes[$field])) {
                 $table .= '-' . Horde_String::pad($label, $length) . ' | ' . Horde_String::wrap($this->_changes[$field]['from_name'], $wrap_width, $wrap_break) . "\n" . '+' . Horde_String::pad($label, $length) . ' | ' . Horde_String::wrap($name, $wrap_width, $wrap_break) . "\n";
             } else {
                 $table .= ' ' . Horde_String::pad($label, $length) . ' | ' . Horde_String::wrap($name, $wrap_width, $wrap_break) . "\n";
             }
         }
     }
     /* Attribute changes. */
     foreach ($attributes as $id => $attribute) {
         $attribute_id = 'attribute_' . $id;
         $label = $attribute['human_name'];
         if (isset($this->_changes[$attribute_id])) {
             $table .= '-' . Horde_String::pad($label, $length) . ' | ' . Horde_String::wrap($this->_changes[$attribute_id]['from'], $wrap_width, $wrap_break) . "\n" . '+' . Horde_String::pad($label, $length) . ' | ' . Horde_String::wrap($this->_changes[$attribute_id]['to'], $wrap_width, $wrap_break) . "\n";
         } else {
             $table .= ' ' . Horde_String::pad($label, $length) . ' | ' . Horde_String::wrap($this->get($attribute_id), $wrap_width, $wrap_break) . "\n";
         }
     }
     /* Show any change in ticket owners. */
     $owners = $oldOwners = Horde_String::wrap(Whups::getOwners($this->_id, false, true), $wrap_width, $wrap_break);
     if (isset($this->_changes['oldowners'])) {
         $oldOwners = Horde_String::wrap(Whups::getOwners($this->_id, false, true, $this->_changes['oldowners']), $wrap_width, $wrap_break);
     }
     if ($owners != $oldOwners) {
         $table .= '-' . Horde_String::pad(_("Owners"), $length) . ' | ' . $oldOwners . "\n" . '+' . Horde_String::pad(_("Owners"), $length) . ' | ' . $owners . "\n";
     } else {
         $table .= ' ' . Horde_String::pad(_("Owners"), $length) . ' | ' . $owners . "\n";
     }
     /* New Attachments. */
     if (isset($this->_changes['attachment'])) {
         $table .= '+' . Horde_String::pad(_("New Attachment"), $length) . ' | ' . $this->_changes['attachment']['to']['name'] . "\n";
     }
     if (!empty($this->_changes['attachments'])) {
         foreach ($this->_changes['attachments']['to'] as $attachment) {
             $table .= '+' . Horde_String::pad(_("New Attachment"), $length) . ' | ' . $attachment['name'] . "\n";
         }
     }
     /* Deleted Attachments. */
     if (isset($this->_changes['delete-attachment'])) {
         $table .= '+' . Horde_String::pad(_("Deleted Attachment"), $length) . ' | ' . $this->_changes['delete-attachment']['to'] . "\n";
     }
     $table .= "------------------------------------------------------------------------------";
     /* Build message template. */
     $view = new Horde_View(array('templatePath' => WHUPS_BASE . '/config'));
     $view->ticket_url = $url;
     $view->table = $table;
     $view->dont_reply = empty($conf['mail']['reply']);
     $view->date = strftime($GLOBALS['prefs']->getValue('date_format'));
     $view->auth_name = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create()->getValue('fullname');
     if (empty($view->auth_name)) {
         $view->auth_name = $GLOBALS['registry']->getAuth('bare');
     }
     /* Get queue specific notification message text, if available. */
     $message_file = WHUPS_BASE . '/config/' . ($isNew ? 'create_email.plain' : 'notify_email.plain');
     if (file_exists($message_file . '.' . $this->get('queue') . '.php')) {
         $message_file .= '.' . $this->get('queue') . '.php';
     } elseif (file_exists($message_file . '.local.php')) {
         $message_file .= '.local.php';
     } else {
         $message_file .= '.php';
     }
     $message_file = basename($message_file);
     /* Include Re: if the ticket isn't new for easy
      * filtering/eyeballing. */
     $subject = $this->get('summary');
     if (!$isNew) {
         $subject = 'Re: ' . $subject;
     }
     if (empty($listeners)) {
         if ($conf['mail']['incl_resp'] || !count($whups_driver->getOwners($this->_id))) {
             /* Include all responsible.  */
             $listeners = $whups_driver->getListeners($this->_id, true, true, true);
         } else {
             /* Don't include all responsible unless ticket is assigned. */
             $listeners = $whups_driver->getListeners($this->_id, true, true, false);
         }
         /* Notify both old and new queue users if the queue has changed. */
         if (isset($this->_changes['queue'])) {
             foreach ($whups_driver->getQueueUsers($this->_changes['queue']['from_name']) as $user) {
                 $listeners[$user] = 'queue';
             }
         }
     }
     /* Pass off to Whups_Driver::mail() to do the actual comment fetching,
      * permissions checks, etc. */
     $whups_driver->mail(array('ticket' => $this, 'recipients' => $listeners, 'subject' => $subject, 'view' => $view, 'template' => $message_file, 'from' => $author, 'new' => $isNew));
 }
Esempio n. 11
0
 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']);
                     }
             }
         }
     }
 }