newTicket() public static method

Pretty bare wrapper around Whups_Driver::addTicket().
public static newTicket ( array $info, $requester ) : Whups_Ticket
$info array A hash with ticket information.
return Whups_Ticket Whups_Ticket object.
示例#1
0
文件: Api.php 项目: raz0rsdge/horde
 /**
  * Create a new ticket.
  *
  * @param array $ticket_info An array of form variables representing all of the
  * data collected by CreateStep1Form, CreateStep2Form, CreateStep3Form, and
  * optionally CreateStep4Form.
  *
  * @return integer The new ticket id.
  */
 public function addTicket($ticket_info)
 {
     global $whups_driver;
     if (!is_array($ticket_info)) {
         throw new Whups_Exception('Invalid arguments');
     }
     $vars = new Horde_Variables($ticket_info);
     $form1 = new Whups_Form_Ticket_CreateStepOne($vars);
     $form2 = new Whups_Form_Ticket_CreateStepTwo($vars);
     $form3 = new Whups_Form_Ticket_CreateStepThree($vars);
     // FIXME: This is an almighty hack, but we can't have form
     // tokens in rpc calls.
     $form1->useToken(false);
     $form2->useToken(false);
     $form3->useToken(false);
     // Complain if we've been given bad parameters.
     if (!$form1->validate($vars, true)) {
         $f1 = var_export($form1->getErrors(), true);
         throw new Whups_Exception("Invalid arguments ({$f1})");
     }
     if (!$form2->validate($vars, true)) {
         $f2 = var_export($form2->getErrors(), true);
         throw new Whups_Exception("Invalid arguments ({$f2})");
     }
     if (!$form3->validate($vars, true)) {
         $f3 = var_export($form3->getErrors(), true);
         throw new Whups_Exception("Invalid arguments ({$f3})");
     }
     $form1->getInfo($vars, $info);
     $form2->getInfo($vars, $info);
     $form3->getInfo($vars, $info);
     // More checks if we're assigning the ticket at create-time.
     if ($GLOBALS['registry']->getAuth() && $whups_driver->isCategory('assigned', $vars->get('state'))) {
         $form4 = new Whups_Form_Ticket_CreateStepFour($vars);
         $form4->useToken(false);
         if (!$form4->validate($vars, true)) {
             throw new Whups_Exception('Invalid arguments (' . var_export($form4->getErrors(), true) . ')');
         }
         $form4->getInfo($vars, $info);
     }
     $ticket = Whups_Ticket::newTicket($info, $GLOBALS['registry']->getAuth());
     return $ticket->getId();
 }
示例#2
0
$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.
示例#3
0
文件: Mail.php 项目: jubinpatel/horde
 /**
  * Parse a MIME message and create a new ticket.
  *
  * @param string $text       This is the full text of the MIME message.
  * @param array $info        An array of information for the new ticket.
  *                           This should include:
  *                           - 'queue'    => queue id
  *                           - 'type'     => type id
  *                           - 'state'    => state id
  *                           - 'priority' => priority id
  *                           - 'ticket'   => ticket id (prevents creation
  *                                           of new tickets)
  * @param string $auth_user  This will be the Horde user that creates the
  *                           ticket. If null, we will try to deduce from
  *                           the message's From: header. We do NOT default
  *                           to $GLOBALS['registry']->getAuth().
  *
  * @return Whups_Ticket  Ticket.
  */
 public static function processMail($text, array $info, $auth_user = null)
 {
     global $conf;
     $message = Horde_Mime_Part::parseMessage($text);
     if (preg_match("/^(.*?)\r?\n\r?\n/s", $text, $matches)) {
         $hdrText = $matches[1];
     } else {
         $hdrText = $text;
     }
     $headers = Horde_Mime_Headers::parseHeaders($hdrText);
     // If this message was generated by Whups, don't process it.
     if ($headers->getValue('X-Whups-Generated')) {
         return true;
     }
     // Try to avoid bounces, auto-replies, and mailing list responses.
     $from = $headers->getValue('from');
     if (strpos($headers->getValue('Content-Type'), 'multipart/report') !== false || stripos($from, 'mailer-daemon@') !== false || stripos($from, 'postmaster@') !== false || !is_null($headers->getValue('X-Failed-Recipients')) || !is_null($headers->getValue('X-Autoreply-Domain')) || $headers->getValue('Auto-Submitted') == 'auto-replied' || $headers->getValue('Precedence') == 'auto_reply' || $headers->getValue('X-Precedence') == 'auto_reply' || $headers->getValue('X-Auto-Response-Suppress') == 'All' || $headers->getValue('X-List-Administrivia') == 'Yes') {
         return true;
     }
     // Use the message subject as the ticket summary.
     $info['summary'] = trim($headers->getValue('subject'));
     if (empty($info['summary'])) {
         $info['summary'] = _("[No Subject]");
     }
     // Format the message into a comment.
     $comment = _("Received message:") . "\n\n";
     if (!empty($GLOBALS['conf']['mail']['include_headers'])) {
         foreach ($headers->toArray(array('nowrap' => true)) as $name => $vals) {
             if (!in_array(strtolower($name), array('subject', 'from', 'to', 'cc', 'date'))) {
                 if (is_array($vals)) {
                     foreach ($vals as $val) {
                         $comment .= $name . ': ' . $val . "\n";
                     }
                 } else {
                     $comment .= $name . ': ' . $vals . "\n";
                 }
             }
         }
         $comment .= "\n";
     }
     // Look for the body part.
     $body_id = $message->findBody();
     if ($body_id) {
         $part = $message->getPart($body_id);
         $content = Horde_String::convertCharset($part->getContents(), $part->getCharset(), 'UTF-8');
         switch ($part->getType()) {
             case 'text/plain':
                 $comment .= $content;
                 break;
             case 'text/html':
                 $comment .= Horde_Text_Filter::filter($content, array('Html2text'), array(array('width' => 0)));
                 break;
             default:
                 $comment .= _("[ Could not render body of message. ]");
                 break;
         }
     } else {
         $comment .= _("[ Could not render body of message. ]");
     }
     $info['comment'] = $comment . "\n";
     // Try to determine the Horde user for creating the ticket.
     if (empty($auth_user)) {
         $tmp = new Horde_Mail_Rfc822_Address($from);
         $auth_user = self::_findAuthUser($tmp->bare_address);
     }
     $author = $auth_user;
     if (empty($auth_user) && !empty($info['default_auth'])) {
         $auth_user = $info['default_auth'];
         if (!empty($from)) {
             $info['user_email'] = $from;
         }
     }
     if (empty($auth_user) && !empty($conf['mail']['username'])) {
         $auth_user = $conf['mail']['username'];
         if (!empty($from)) {
             $info['user_email'] = $from;
         }
     }
     // Authenticate as the correct Horde user.
     if (!empty($auth_user) && $auth_user != $GLOBALS['registry']->getAuth()) {
         $GLOBALS['registry']->setAuth($auth_user, array());
     }
     // Attach message.
     $attachments = array();
     if (!empty($GLOBALS['conf']['mail']['attach_message'])) {
         $tmp_name = Horde::getTempFile('whups');
         $fp = @fopen($tmp_name, 'wb');
         if (!$fp) {
             throw new Whups_Exception(sprintf('Cannot open file %s for writing.', $tmp_name));
         }
         fwrite($fp, $text);
         fclose($fp);
         $attachments[] = array('name' => _("Original Message") . '.eml', 'tmp_name' => $tmp_name);
     }
     // Extract attachments.
     $dl_list = array_slice(array_keys($message->contentTypeMap()), 1);
     foreach ($dl_list as $key) {
         $part = $message->getPart($key);
         if ($key == $body_id && $part->getType() == 'text/plain' || $part->getType() == 'multipart/alternative' || $part->getType() == 'multipart/mixed') {
             continue;
         }
         $tmp_name = Horde::getTempFile('whups');
         $fp = @fopen($tmp_name, 'wb');
         if (!$fp) {
             throw new Whups_Exception(sprintf('Cannot open file %s for writing.', $tmp_name));
         }
         fwrite($fp, $part->getContents());
         fclose($fp);
         $part_name = $part->getName(true);
         if (!$part_name) {
             $ptype = $part->getPrimaryType();
             switch ($ptype) {
                 case 'multipart':
                 case 'application':
                     $part_name = sprintf(_("%s part"), ucfirst($part->getSubType()));
                     break;
                 default:
                     $part_name = sprintf(_("%s part"), ucfirst($ptype));
                     break;
             }
             if ($ext = Horde_Mime_Magic::mimeToExt($part->getType())) {
                 $part_name .= '.' . $ext;
             }
         }
         $attachments[] = array('name' => $part_name, 'tmp_name' => $tmp_name);
     }
     // See if we can match this message to an existing ticket.
     if ($ticket = self::_findTicket($info)) {
         $ticket->change('comment', $info['comment']);
         $ticket->change('comment-email', $from);
         if ($attachments) {
             $ticket->change('attachments', $attachments);
         }
         $ticket->commit($author);
     } elseif (!empty($info['ticket'])) {
         // Didn't match an existing ticket though a ticket number had been
         // specified.
         throw new Whups_Exception(sprintf(_("Could not find ticket \"%s\"."), $info['ticket']));
     } else {
         if (!empty($info['guess-queue'])) {
             // Try to guess the queue name for the new ticket from the
             // message subject.
             $queues = $GLOBALS['whups_driver']->getQueues();
             foreach ($queues as $queueId => $queueName) {
                 if (preg_match('/\\b' . preg_quote($queueName, '/') . '\\b/i', $info['summary'])) {
                     $info['queue'] = $queueId;
                     break;
                 }
             }
         }
         $info['attachments'] = $attachments;
         // Create a new ticket.
         $ticket = Whups_Ticket::newTicket($info, $author);
     }
 }