/** * Set ticket attributes * * @param array $info Attributes to set * @param Whups_Ticket $ticket The ticket which attributes to set. */ public function setAttributes(array $info, Whups_Ticket &$ticket) { $ticket_id = $ticket->getId(); foreach ($info as $name => $value) { if (substr($name, 0, 10) == 'attribute_' && $ticket->get($name) != $value) { $attribute_id = (int) substr($name, 10); $serialized = $this->_serializeAttribute($value); $ticket->change($name, $value); $this->_setAttributeValue($ticket_id, $attribute_id, $serialized); $this->updateLog($ticket_id, $GLOBALS['registry']->getAuth(), array('attribute' => $attribute_id . ':' . $serialized)); } } }
$form4 = new Whups_Form_Ticket_CreateStepFour($vars); $r = new Horde_Form_Renderer(array('varrenderer_driver' => array('whups', 'whups'))); $valid4 = $form4->validate($vars) && $formname == 'whups_form_ticket_createstepfour'; $valid3 = $form3->validate($vars, true); $valid2 = $form2->validate($vars, !$form1->isSubmitted()); $valid1 = $form1->validate($vars, true); $doAssignForm = $GLOBALS['registry']->getAuth() && $whups_driver->isCategory('assigned', $vars->get('state')); if ($valid1 && $valid2 && $valid3 && (!$doAssignForm || $valid4)) { $form1->getInfo($vars, $info); $form2->getInfo($vars, $info); $form3->getInfo($vars, $info); if ($doAssignForm) { $form4->getInfo($vars, $info); } try { $ticket = Whups_Ticket::newTicket($info, $GLOBALS['registry']->getAuth()); } catch (Whups_Exception $e) { Horde::log($e, 'ERR'); $notification->push(sprintf(_("Adding your ticket failed: %s."), $e->getMessage()), 'horde.error'); Horde::url('ticket/create.php', true)->redirect(); } $notification->push(sprintf(_("Your ticket ID is %s. An appropriate person has been notified of this request."), $ticket->getId()), 'horde.success'); $ticket->show(); exit; } // Start the page. $page_output->header(array('title' => _("New Ticket"))); $notification->notify(array('listeners' => 'status')); if ($valid3 && $valid2 && $valid1) { $form4->open($r, $vars, 'create.php', 'post'); // Preserve previous forms.
/** * Adds a ticket. * * @param array $info A ticket info hash. Will get a * 'last-transaction' value added. * @param string $requester A ticket requester. * * @return integer The new ticket ID. * @throws Whups_Exception */ public function addTicket(array &$info, $requester) { $timestamp = time(); $type = (int) $info['type']; $state = $this->getState((int) $info['state']); $priority = (int) $info['priority']; $queue = (int) $info['queue']; $summary = $info['summary']; $version = (int) isset($info['version']) ? $info['version'] : null; $due = isset($info['due']) ? $info['due'] : null; $comment = $info['comment']; $attributes = isset($info['attributes']) ? $info['attributes'] : array(); // Create the ticket. try { $ticket_id = $this->_db->insert('INSERT INTO whups_tickets (ticket_summary, ' . 'user_id_requester, type_id, state_id, priority_id, ' . 'queue_id, ticket_timestamp, ticket_due, date_updated, ' . 'date_assigned, version_id)' . ' VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', array($this->_toBackend($summary), $requester, $type, $state['id'], $priority, $queue, $timestamp, $due, $timestamp, $state['category'] == 'assigned' ? $timestamp : null, $version)); } catch (Horde_Db_Exception $e) { throw new Whups_Exception($e); } // Is there a more effecient way to do this? Need the ticketId before // we can insert this. if (!empty($info['user_email'])) { $requester = $ticket_id * -1; try { $this->_db->update('UPDATE whups_tickets SET user_id_requester = ? WHERE ' . 'ticket_id = ?', array($requester, $ticket_id)); } catch (Horde_Db_Exception $e) { throw new Whups_Exception($e); } } if ($requester < 0) { try { $this->_db->insert('INSERT INTO whups_guests (guest_id, guest_email) ' . 'VALUES (?, ?)', array((string) $requester, $info['user_email'])); } catch (Horde_Db_Exception $e) { throw new Whups_Exception($e); } } $commentId = $this->addComment($ticket_id, $comment, $requester, isset($info['user_email']) ? $info['user_email'] : null); // If permissions were specified, set them. if (!empty($info['group'])) { Whups_Ticket::addCommentPerms($commentId, $info['group']); } $transaction = $this->updateLog($ticket_id, $requester, array('state' => $state['id'], 'priority' => $priority, 'type' => $type, 'summary' => $summary, 'due' => $due, 'comment' => $commentId, 'queue' => $queue)); // Store the last-transaction id in the ticket's info for later use if // needed. $info['last-transaction'] = $transaction; // Assign the ticket, if requested. $owners = array_merge(isset($info['owners']) ? $info['owners'] : array(), isset($info['group_owners']) ? $info['group_owners'] : array()); foreach ($owners as $owner) { $this->addTicketOwner($ticket_id, $owner); $this->updateLog($ticket_id, $requester, array('assign' => $owner), $transaction); } // Set timestamps, if necessary. if ($state['category'] == 'assigned') { $this->updateLog($ticket_id, $requester, array('date_assigned' => $timestamp), $transaction); } // Add any supplied attributes for this ticket. foreach ($attributes as $attribute_id => $attribute_value) { $attribute_value = $this->_serializeAttribute($attribute_value); $this->_setAttributeValue($ticket_id, $attribute_id, $attribute_value); $this->updateLog($ticket_id, $requester, array('attribute' => $attribute_id . ':' . $attribute_value, 'attribute_' . $attribute_id => $attribute_value), $transaction); } return $ticket_id; }
/** * Lists tickets with due dates as time objects. * * @param array $categories The time categories (from listTimeObjectCategories) to list. * @param mixed $start The start date of the period. * @param mixed $end The end date of the period. */ public function listTimeObjects($categories, $start, $end) { global $whups_driver; $start = new Horde_Date($start); $start_ts = $start->timestamp(); $end = new Horde_Date($end); $end_ts = $end->timestamp(); $criteria['owner'] = Whups::getOwnerCriteria($GLOBALS['registry']->getAuth()); /* @TODO Use $categories */ $category = 'due'; switch ($category) { case 'assigned': $label = _("Assigned"); $criteria['ass'] = true; break; case 'created': $label = _("Created"); break; case 'due': $label = _("Due"); $criteria['nores'] = true; break; case 'resolved': $label = _("Resolved"); $criteria['res'] = true; break; } try { $tickets = $whups_driver->getTicketsByProperties($criteria); } catch (Whups_Exception $e) { return array(); } $objects = array(); foreach ($tickets as $ticket) { switch ($category) { case 'assigned': $t_start = $ticket['date_assigned']; break; case 'created': $t_start = $ticket['timestamp']; break; case 'due': if (empty($ticket['due'])) { continue 2; } $t_start = $ticket['due']; break; case 'resolved': $t_start = $ticket['date_resolved']; break; } if ($t_start + 1 < $start_ts || $t_start > $end_ts) { continue; } $t = new Whups_Ticket($ticket['id'], $ticket); $objects[$ticket['id']] = array('title' => sprintf('%s: [#%s] %s', $label, $ticket['id'], $ticket['summary']), 'description' => $t->toString(), 'id' => $ticket['id'], 'start' => date('Y-m-d\\TH:i:s', $t_start), 'end' => date('Y-m-d\\TH:i:s', $t_start + 1), 'params' => array('id' => $ticket['id']), 'link' => Whups::urlFor('ticket', $ticket['id'], true)); } return $objects; }
/** * Returns the tabs for navigating between ticket actions. */ public static function getTicketTabs(&$vars, $id) { $tabs = new Horde_Core_Ui_Tabs(null, $vars); $queue = Whups_Ticket::makeTicket($id)->get('queue'); $tabs->addTab(_("_History"), self::urlFor('ticket', $id), 'history'); $tabs->addTab(_("_Attachments"), self::urlFor('ticket_action', array('attachments', $id)), 'attachments'); if (self::hasPermission($queue, 'queue', 'update')) { $tabs->addTab(_("_Update"), self::urlFor('ticket_action', array('update', $id)), 'update'); } else { $tabs->addTab(_("_Comment"), self::urlFor('ticket_action', array('comment', $id)), 'comment'); } $tabs->addTab(_("_Watch"), self::urlFor('ticket_action', array('watch', $id)), 'watch'); if (self::hasPermission($queue, 'queue', Horde_Perms::DELETE)) { $tabs->addTab(_("S_et Queue"), self::urlFor('ticket_action', array('queue', $id)), 'queue'); } if (self::hasPermission($queue, 'queue', 'update')) { $tabs->addTab(_("Set _Type"), self::urlFor('ticket_action', array('type', $id)), 'type'); } if (self::hasPermission($queue, 'queue', Horde_Perms::DELETE)) { $tabs->addTab(_("_Delete"), self::urlFor('ticket_action', array('delete', $id)), 'delete'); } return $tabs; }
* did not receive this file, see http://www.horde.org/licenses/bsdl.php. */ require_once __DIR__ . '/../lib/Application.php'; Horde_Registry::appInit('whups'); Whups::addTopbarSearch(); $vars = Horde_Variables::getDefaultVariables(); $deleteform = new Whups_Form_Ticket_DeleteMultiple($vars); $title = sprintf(_("Delete %d tickets?"), count($deleteform->getTickets())); $deleteform->setTitle($title); if ($vars->get('formname') == 'whups_form_ticket_deletemultiple' && $deleteform->validate($vars)) { if ($vars->get('submitbutton') == _("Delete")) { $deleteform->getInfo($vars, $info); $tickets = @unserialize($info['tickets']); foreach ($tickets as $id) { try { Whups_Ticket::makeTicket($id)->delete(); $notification->push(sprintf(_("Ticket %d has been deleted."), $id), 'horde.success'); } catch (Whups_Exception $e) { $notification->push(_("There was an error deleting the ticket:") . ' ' . $e->getMessage(), 'horde.error'); } catch (Horde_Exception_NotFound $e) { $notification->push(sprintf(_("Ticket %d not found."), $id)); } } } else { $notification->push(_("The tickets were not deleted."), 'horde.message'); } Horde::url($vars->get('url', $prefs->getValue('whups_default_view') . '.php'), true)->redirect(); } $vars->set('tickets', serialize($deleteform->getTickets())); $page_output->header(array('title' => $title)); $notification->notify(array('listeners' => 'status'));
/** * Creates a new ticket. * * Pretty bare wrapper around Whups_Driver::addTicket(). * * @static * * @param array $info A hash with ticket information. * * @return Whups_Ticket Whups_Ticket object. */ public static function newTicket($info, $requester) { global $whups_driver; if (!isset($info['type'])) { $info['type'] = $whups_driver->getDefaultType($info['queue']); if (!$info['type']) { $queue = $whups_driver->getQueue($info['queue']); throw new Whups_Exception(sprintf(_("No type for this ticket and no default type for queue \"%s\" specified."), $queue['name'])); } } if (!isset($info['state'])) { $info['state'] = $whups_driver->getDefaultState($info['type']); if (!$info['state']) { throw new Whups_Exception(sprintf(_("No state for this ticket and no default state for ticket type \"%s\" specified."), $whups_driver->getTypeName($info['type']))); } } if (!isset($info['priority'])) { $info['priority'] = $whups_driver->getDefaultPriority($info['type']); if (!$info['priority']) { throw new Whups_Exception(sprintf(_("No priority for this ticket and no default priority for ticket type \"%s\" specified."), $whups_driver->getTypeName($info['type']))); } } // Run hook. try { $info = Horde::callHook('ticket_create', array($info, $requester), 'whups'); } catch (Horde_Exception_HookNotSet $e) { } $id = $whups_driver->addTicket($info, $requester); $details = $whups_driver->getTicketDetails($id, false); $ticket = new Whups_Ticket($id, $details); // Add attachment if one was uploaded. if (!empty($info['newattachment']['name'])) { $ticket->change('attachment', array('name' => $info['newattachment']['name'], 'tmp_name' => $info['newattachment']['tmp_name'])); } // Check for a deferred attachment upload. $a_name = null; if (!empty($info['deferred_attachment']) && ($a_name = $GLOBALS['session']->get('whups', 'deferred_attachment/' . $info['deferred_attachment']))) { $ticket->change('attachment', array('name' => $info['deferred_attachment'], 'tmp_name' => $a_name)); } // Check for manually added attachments. if (!empty($info['attachments'])) { $ticket->change('attachments', $info['attachments']); } // Commit any changes (new attachments, etc.) $ticket->commit($ticket->get('user_id_requester'), $info['last-transaction'], false); // Delete deferred attachment now, because it will be attached in the // commit() call above. if ($a_name) { unlink($a_name); } // Send email notifications. $ticket->notify($ticket->get('user_id_requester'), true); return $ticket; }
/** * Returns the ticket number matching the provided information. * * @param array $info A hash with ticket information. * * @return integer The ticket number if has been passed in the subject, * false otherwise. */ protected static function _findTicket(array $info) { if (!empty($info['ticket'])) { $ticketnum = $info['ticket']; } elseif (preg_match('/\\[[\\w\\s]*#(\\d+)\\]/', $info['summary'], $matches)) { $ticketnum = $matches[1]; } else { return false; } try { return Whups_Ticket::makeTicket($ticketnum); } catch (Whups_Exception $e) { return false; } }