예제 #1
0
 function showTab($context, $context_id)
 {
     $tpl = DevblocksPlatform::getTemplateService();
     $active_worker = CerberusApplication::getActiveWorker();
     $tpl->assign('context', $context);
     $tpl->assign('context_id', $context_id);
     // Check permissions on this ticket for this worker
     if (0 != strcasecmp($context, CerberusContexts::CONTEXT_TICKET)) {
         return;
     }
     if (null == ($ticket = DAO_Ticket::get($context_id))) {
         return;
     }
     $tpl->assign('csrf_token', $_SESSION['csrf_token']);
     // if(!$active_worker->isGroupMember($ticket->group_id))
     //   return;
     // // Load the message IDs for this ticket
     // $messages = DAO_Message::getMessagesByTicket($context_id);
     $requesters = $ticket->getRequesters();
     //    error_log(var_export($requesters,true),3,'/var/www/cerb-7.0.4/logs/foo.log');
     $requester = array_shift($requesters);
     $contacts = Infusionsoft_DataService::findByField(new Infusionsoft_Contact(), 'email', $requester->email);
     $contact = array_shift($contacts);
     $convertToInt = function ($str) {
         return (int) $str;
     };
     $groupIds = array_map($convertToInt, explode(',', $contact->Groups));
     $extractData = function ($group) {
         return $group->toArray();
     };
     $groups = array_map($extractData, Infusionsoft_DataService::query(new Infusionsoft_ContactGroup(), array('Id' => $groupIds)));
     // Template
     $tpl->assign('contact', $contact);
     $tpl->assign('groups', $groups);
     $tpl->display('devblocks:bmoelk.infusionsoft::tab.tpl');
 }
예제 #2
0
 private function _sendForwards($event, $is_inbound)
 {
     @($ticket_id = $event->params['ticket_id']);
     @($send_worker_id = $event->params['worker_id']);
     $url_writer = DevblocksPlatform::getUrlService();
     $ticket = DAO_Ticket::get($ticket_id);
     // (Action) Forward Email To:
     // Sanitize and combine all the destination addresses
     $context_workers = CerberusContexts::getWorkers(CerberusContexts::CONTEXT_TICKET, $ticket->id);
     if (!is_array($context_workers)) {
         return;
     }
     foreach ($context_workers as $next_worker) {
         $notify_emails = $next_worker->email;
         if (empty($notify_emails)) {
             continue;
         }
     }
     // [TODO] This could be more efficient
     $messages = DAO_Message::getMessagesByTicket($ticket_id);
     $message = end($messages);
     // last message
     unset($messages);
     $headers = $message->getHeaders();
     // The whole flipping Swift section needs wrapped to catch exceptions
     try {
         $settings = DevblocksPlatform::getPluginSettingsService();
         $reply_to = $settings->get('cerberusweb.core', CerberusSettings::DEFAULT_REPLY_FROM, CerberusSettingsDefaults::DEFAULT_REPLY_FROM);
         // See if we need a group-specific reply-to
         if (!empty($ticket->team_id)) {
             @($group_from = DAO_GroupSettings::get($ticket->team_id, DAO_GroupSettings::SETTING_REPLY_FROM, ''));
             if (!empty($group_from)) {
                 $reply_to = $group_from;
             }
         }
         $sender = DAO_Address::get($message->address_id);
         $sender_email = strtolower($sender->email);
         $sender_split = explode('@', $sender_email);
         if (!is_array($sender_split) || count($sender_split) != 2) {
             return;
         }
         // If return-path is blank
         if (isset($headers['return-path']) && $headers['return-path'] == '<>') {
             return;
         }
         // Ignore bounces
         if ($sender_split[0] == "postmaster" || $sender_split[0] == "mailer-daemon") {
             return;
         }
         // Ignore autoresponses autoresponses
         if (isset($headers['auto-submitted']) && $headers['auto-submitted'] != 'no') {
             return;
         }
         // Attachments
         $attachments = $message->getAttachments();
         $mime_attachments = array();
         if (is_array($attachments)) {
             foreach ($attachments as $attachment) {
                 if (0 == strcasecmp($attachment->display_name, 'original_message.html')) {
                     continue;
                 }
                 $attachment_path = APP_STORAGE_PATH . '/attachments/';
                 // [TODO] This is highly redundant in the codebase
                 if (!file_exists($attachment_path . $attachment->filepath)) {
                     continue;
                 }
                 $attach = Swift_Attachment::fromPath($attachment_path . $attachment->filepath);
                 if (!empty($attachment->display_name)) {
                     $attach->setFilename($attachment->display_name);
                 }
                 $mime_attachments[] = $attach;
             }
         }
         // Send copies
         $mail_service = DevblocksPlatform::getMailService();
         $mailer = $mail_service->getMailer(CerberusMail::getMailerDefaults());
         $mail = $mail_service->createMessage();
         /* @var $mail Swift_Message */
         $mail->setTo(array($notify_emails));
         $mail->setFrom(array($sender->email));
         $mail->setReplyTo($reply_to);
         $mail->setReturnPath($reply_to);
         $mail->setSubject(sprintf("[RW: %s #%s]: %s", $is_inbound ? 'inbound' : 'outbound', $ticket->mask, $ticket->subject));
         $hdrs = $mail->getHeaders();
         if (null !== @($msgid = $headers['message-id'])) {
             $hdrs->addTextHeader('Message-Id', $msgid);
         }
         if (null !== @($in_reply_to = $headers['in-reply-to'])) {
             $hdrs->addTextHeader('References', $in_reply_to);
             $hdrs->addTextHeader('In-Reply-To', $in_reply_to);
         }
         $hdrs->addTextHeader('X-Mailer', 'Cerberus Helpdesk (Build ' . APP_BUILD . ')');
         $hdrs->addTextHeader('Precedence', 'List');
         $hdrs->addTextHeader('Auto-Submitted', 'auto-generated');
         $mail->setBody($message->getContent());
         // Send message attachments with watcher
         if (is_array($mime_attachments)) {
             foreach ($mime_attachments as $mime_attachment) {
                 $mail->attach($mime_attachment);
             }
         }
         $result = $mailer->send($mail);
     } catch (Exception $e) {
         if (!empty($message_id)) {
             $fields = array(DAO_MessageNote::MESSAGE_ID => $message_id, DAO_MessageNote::CREATED => time(), DAO_MessageNote::WORKER_ID => 0, DAO_MessageNote::CONTENT => 'Exception thrown while sending watcher email: ' . $e->getMessage(), DAO_MessageNote::TYPE => Model_MessageNote::TYPE_ERROR);
             DAO_MessageNote::create($fields);
         }
     }
 }
예제 #3
0
 private function mergeTicket($event)
 {
     // Listen for ticket merges and update our internal ticket_id records
     @($new_ticket_id = $event->params['new_ticket_id']);
     @($old_ticket_ids = $event->params['old_ticket_ids']);
     $translate = DevblocksPlatform::getTranslationService();
     if (empty($new_ticket_id) || empty($old_ticket_ids)) {
         return;
     }
     $settings = DevblocksPlatform::getPluginSettingsService();
     $al_merge_enabled = intval($settings->get('cerb5blog.last_action_and_audit_log', 'al_merge_enabled', 0));
     $uf_merge_enabled = intval($settings->get('cerb5blog.last_action_and_audit_log', 'uf_merge_enabled', 0));
     if (!($al_merge_enabled || $uf_merge_enabled)) {
         return;
     }
     $active_worker = CerberusApplication::getActiveWorker();
     $worker_id = $active_worker->id;
     if (class_exists('DAO_TicketAuditLog', true)) {
         if ($al_merge_enabled) {
             foreach ($old_ticket_ids as $old_id) {
                 $old_ticket = DAO_Ticket::get($old_id);
                 $translate_str = $translate->_('cerb5blog.last_action_and_audit_log.post.merge.new_ticket');
                 $translated = sprintf($translate_str, $old_id, $old_ticket->mask);
                 $fields = array(DAO_TicketAuditLog::TICKET_ID => $new_ticket_id, DAO_TicketAuditLog::WORKER_ID => $worker_id, DAO_TicketAuditLog::CHANGE_DATE => time(), DAO_TicketAuditLog::CHANGE_FIELD => "cerb5blog.last_action_and_audit_log.type.merge", DAO_TicketAuditLog::CHANGE_VALUE => substr($translated, 0, 128));
                 $log_id = DAO_TicketAuditLog::create($fields);
             }
             unset($fields);
         }
     }
     if ($uf_merge_enabled) {
         $new_change_fields[DAO_Ticket::UPDATED_DATE] = time();
         DAO_Ticket::update($new_ticket_id, $new_change_fields);
         unset($new_change_fields);
     }
 }