Beispiel #1
0
 private function _newTicketComment($event)
 {
     @($comment_id = $event->params['comment_id']);
     @($ticket_id = $event->params['ticket_id']);
     @($address_id = $event->params['address_id']);
     @($comment = $event->params['comment']);
     if (empty($ticket_id) || empty($address_id) || empty($comment)) {
         return;
     }
     // Resolve the address ID
     if (null == ($address = DAO_Address::get($address_id))) {
         return;
     }
     // Try to associate the author with a worker
     if (null == ($worker_addy = DAO_AddressToWorker::getByAddress($address->email))) {
         return;
     }
     if (null == ($worker = DAO_Worker::getAgent($worker_addy->worker_id))) {
         return;
     }
     $url_writer = DevblocksPlatform::getUrlService();
     $mail_service = DevblocksPlatform::getMailService();
     $mailer = null;
     // lazy load
     $settings = DevblocksPlatform::getPluginSettingsService();
     $default_from = $settings->get('cerberusweb.core', CerberusSettings::DEFAULT_REPLY_FROM, '');
     $default_personal = $settings->get('cerberusweb.core', CerberusSettings::DEFAULT_REPLY_PERSONAL, '');
     if (null == ($ticket = DAO_Ticket::getTicket($ticket_id))) {
         return;
     }
     // Find all our matching filters
     if (empty($ticket) || false == ($matches = Model_WatcherMailFilter::getMatches($ticket, 'ticket_comment'))) {
         return;
     }
     // Remove any matches from the author
     if (is_array($matches)) {
         foreach ($matches as $idx => $filter) {
             if ($filter->worker_id == $worker_addy->worker_id) {
                 unset($matches[$idx]);
             }
         }
     }
     // (Action) Send Notification
     $this->_sendNotifications($matches, $url_writer->write('c=display&mask=' . $ticket->mask, true, false), sprintf("[Ticket] %s", $ticket->subject));
     // (Action) Forward E-mail:
     // Sanitize and combine all the destination addresses
     $notify_emails = $this->_getMailingListFromMatches($matches);
     if (empty($notify_emails)) {
         return;
     }
     if (null == @($last_message = end($ticket->getMessages()))) {
         /* @var $last_message CerberusMessage */
         continue;
     }
     if (null == @($last_headers = $last_message->getHeaders())) {
         continue;
     }
     $reply_to = $default_from;
     $reply_personal = $default_personal;
     // 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;
         }
         @($group_personal = DAO_GroupSettings::get($ticket->team_id, DAO_GroupSettings::SETTING_REPLY_PERSONAL));
         if (!empty($group_personal)) {
             $reply_personal = $group_personal;
         }
     }
     if (is_array($notify_emails)) {
         foreach ($notify_emails as $send_to) {
             try {
                 if (null == $mailer) {
                     $mailer = $mail_service->getMailer(CerberusMail::getMailerDefaults());
                 }
                 // Create the message
                 $mail = $mail_service->createMessage();
                 $mail->setTo(array($send_to));
                 $mail->setFrom(array($reply_to => $reply_personal));
                 $mail->setReplyTo($reply_to);
                 $mail->setSubject(sprintf("[comment #%s]: %s [comment]", $ticket->mask, $ticket->subject));
                 $headers = $mail->getHeaders();
                 if (false !== @($in_reply_to = $last_headers['in-reply-to'])) {
                     $headers->addTextHeader('References', $in_reply_to);
                     $headers->addTextHeader('In-Reply-To', $in_reply_to);
                 }
                 // Build the body
                 $comment_text = sprintf("%s (%s) comments:\r\n%s\r\n", $worker->getName(), $address->email, $comment);
                 $headers->addTextHeader('X-Mailer', 'Cerberus Helpdesk (Build ' . APP_BUILD . ')');
                 $headers->addTextHeader('Precedence', 'List');
                 $headers->addTextHeader('Auto-Submitted', 'auto-generated');
                 $mail->setBody($comment_text);
                 $result = $mailer->send($mail);
             } catch (Exception $e) {
                 //
             }
         }
     }
 }
Beispiel #2
0
 function showWorkerPeekAction()
 {
     @($id = DevblocksPlatform::importGPC($_REQUEST['id'], 'integer', 0));
     @($view_id = DevblocksPlatform::importGPC($_REQUEST['view_id'], 'string', ''));
     $tpl = DevblocksPlatform::getTemplateService();
     $tpl->assign('path', $this->_TPL_PATH);
     $tpl->assign('view_id', $view_id);
     $worker = DAO_Worker::getAgent($id);
     $tpl->assign('worker', $worker);
     $teams = DAO_Group::getAll();
     $tpl->assign('teams', $teams);
     // Custom Fields
     $custom_fields = DAO_CustomField::getBySource(ChCustomFieldSource_Worker::ID);
     $tpl->assign('custom_fields', $custom_fields);
     $custom_field_values = DAO_CustomFieldValue::getValuesBySourceIds(ChCustomFieldSource_Worker::ID, $id);
     if (isset($custom_field_values[$id])) {
         $tpl->assign('custom_field_values', $custom_field_values[$id]);
     }
     $tpl->display('file:' . $this->_TPL_PATH . 'configuration/tabs/workers/peek.tpl');
 }
Beispiel #3
0
 function getWorkerAction()
 {
     $translate = DevblocksPlatform::getTranslationService();
     $worker = CerberusApplication::getActiveWorker();
     if (!$worker || !$worker->is_superuser) {
         echo $translate->_('common.access_denied');
         return;
     }
     @($id = DevblocksPlatform::importGPC($_REQUEST['id']));
     $tpl = DevblocksPlatform::getTemplateService();
     $tpl->cache_lifetime = "0";
     $tpl->assign('path', $this->_TPL_PATH);
     $worker = DAO_Worker::getAgent($id);
     $tpl->assign('worker', $worker);
     $teams = DAO_Group::getAll();
     $tpl->assign('teams', $teams);
     $tpl->display('file:' . $this->_TPL_PATH . 'configuration/tabs/workers/edit_worker.tpl');
 }
Beispiel #4
0
 function authenticate($params = array())
 {
     $server = $params['server'];
     $port = $params['port'];
     $dn = $params['dn'];
     $password = $params['password'];
     $worker_id = null;
     // attempt login
     $conn = ldap_connect($server, $port);
     ldap_set_option($conn, LDAP_OPT_PROTOCOL_VERSION, 3);
     if ($conn) {
         $auth = ldap_bind($conn, $dn, $password);
         if ($auth) {
             // search for this user
             $search_results = ldap_search($conn, $dn, '(objectclass=*)', array('mail'));
             if ($search_results) {
                 $user_entry = ldap_first_entry($conn, $search_results);
                 if ($user_entry) {
                     // get email addresses for this user
                     $emails = ldap_get_values($conn, $user_entry, 'mail');
                     if ($emails) {
                         foreach ($emails as $email) {
                             if (is_null($worker_id)) {
                                 $worker_id = DAO_Worker::lookupAgentEmail($email);
                             }
                         }
                     }
                 }
             }
         }
     }
     // we found a worker, continue login
     if (!is_null($worker_id)) {
         $worker = DAO_Worker::getAgent($worker_id);
         $session = DevblocksPlatform::getSessionService();
         $visit = new CerberusVisit();
         $visit->setWorker($worker);
         $session->setVisit($visit);
         return true;
     } else {
         return false;
     }
 }
Beispiel #5
0
 public function getRenderedContent($message_id)
 {
     $raw = $this->content;
     $replace = array();
     $with = array();
     $replace[] = '#timestamp#';
     $with[] = date('r');
     if (!empty($message_id)) {
         $message = DAO_Ticket::getMessage($message_id);
         $ticket = DAO_Ticket::getTicket($message->ticket_id);
         $sender = DAO_Address::get($message->address_id);
         $sender_org = DAO_ContactOrg::get($sender->contact_org_id);
         $replace[] = '#sender_first_name#';
         $replace[] = '#sender_last_name#';
         $replace[] = '#sender_org#';
         $with[] = $sender->first_name;
         $with[] = $sender->last_name;
         $with[] = !empty($sender_org) ? $sender_org->name : "";
         $replace[] = '#ticket_id#';
         $replace[] = '#ticket_mask#';
         $replace[] = '#ticket_subject#';
         $with[] = $ticket->id;
         $with[] = $ticket->mask;
         $with[] = $ticket->subject;
     }
     if (null != ($active_worker = CerberusApplication::getActiveWorker())) {
         $worker = DAO_Worker::getAgent($active_worker->id);
         // most recent info (not session)
         $replace[] = '#worker_first_name#';
         $replace[] = '#worker_last_name#';
         $replace[] = '#worker_title#';
         $with[] = $worker->first_name;
         $with[] = $worker->last_name;
         $with[] = $worker->title;
     }
     return str_replace($replace, $with, $raw);
 }
Beispiel #6
0
 function getComposeSignatureAction()
 {
     @($group_id = DevblocksPlatform::importGPC($_REQUEST['group_id'], 'integer', 0));
     $settings = DevblocksPlatform::getPluginSettingsService();
     $group = DAO_Group::getTeam($group_id);
     $active_worker = CerberusApplication::getActiveWorker();
     $worker = DAO_Worker::getAgent($active_worker->id);
     // Use the most recent info (not session)
     $sig = $settings->get('cerberusweb.core', CerberusSettings::DEFAULT_SIGNATURE, '');
     if (!empty($group->signature)) {
         $sig = $group->signature;
     }
     /*
      * [TODO] This is the 3rd place this replace happens, we really need 
      * to move the signature translation into something like CerberusApplication
      */
     echo sprintf("\r\n%s\r\n", str_replace(array('#first_name#', '#last_name#', '#title#'), array($worker->first_name, $worker->last_name, $worker->title), $sig));
 }
Beispiel #7
0
 static function sendTicketMessage($properties = array())
 {
     $settings = DevblocksPlatform::getPluginSettingsService();
     $helpdesk_senders = CerberusApplication::getHelpdeskSenders();
     @($from_addy = $settings->get('cerberusweb.core', CerberusSettings::DEFAULT_REPLY_FROM, $_SERVER['SERVER_ADMIN']));
     @($from_personal = $settings->get('cerberusweb.core', CerberusSettings::DEFAULT_REPLY_PERSONAL, ''));
     // [TODO] If we still don't have a $from_addy we need a graceful failure.
     /*
     	     * [TODO] Move these into constants?
     	    'message_id'
     	    -----'ticket_id'
     'subject'
     	    'to'
     	    'cc'
     	    'bcc'
     	    'content'
     	    'files'
     	    'closed'
     	    'ticket_reopen'
     	    'unlock_date'
     	    'bucket_id'
     	    'agent_id',
     'is_autoreply',
     'dont_send',
     'dont_save_copy'
     */
     $mail_succeeded = true;
     try {
         // objects
         $mail_service = DevblocksPlatform::getMailService();
         $mailer = $mail_service->getMailer(CerberusMail::getMailerDefaults());
         $mail = $mail_service->createMessage();
         // properties
         @($reply_message_id = $properties['message_id']);
         @($content = $properties['content']);
         @($files = $properties['files']);
         @($forward_files = $properties['forward_files']);
         @($worker_id = $properties['agent_id']);
         @($subject = $properties['subject']);
         $message = DAO_Ticket::getMessage($reply_message_id);
         $message_headers = DAO_MessageHeader::getAll($reply_message_id);
         $ticket_id = $message->ticket_id;
         $ticket = DAO_Ticket::getTicket($ticket_id);
         // [TODO] Check that message|ticket isn't NULL
         // If this ticket isn't spam trained and our outgoing message isn't an autoreply
         if ($ticket->spam_training == CerberusTicketSpamTraining::BLANK && (!isset($properties['is_autoreply']) || !$properties['is_autoreply'])) {
             CerberusBayes::markTicketAsNotSpam($ticket_id);
         }
         // Allow teams to override the default from/personal
         @($group_reply = DAO_GroupSettings::get($ticket->team_id, DAO_GroupSettings::SETTING_REPLY_FROM, ''));
         @($group_personal = DAO_GroupSettings::get($ticket->team_id, DAO_GroupSettings::SETTING_REPLY_PERSONAL, ''));
         @($group_personal_with_worker = DAO_GroupSettings::get($ticket->team_id, DAO_GroupSettings::SETTING_REPLY_PERSONAL_WITH_WORKER, 0));
         if (!empty($group_reply)) {
             $from_addy = $group_reply;
         }
         if (!empty($group_personal)) {
             $from_personal = $group_personal;
         }
         // Prefix the worker name on the personal line?
         if (!empty($group_personal_with_worker) && null != ($reply_worker = DAO_Worker::getAgent($worker_id))) {
             $from_personal = $reply_worker->getName() . (!empty($from_personal) ? ', ' . $from_personal : "");
         }
         // Headers
         $mail->setFrom(array($from_addy => $from_personal));
         $mail->generateId();
         $headers = $mail->getHeaders();
         $headers->addTextHeader('X-Mailer', 'Cerberus Helpdesk (Build ' . APP_BUILD . ')');
         // Subject
         if (empty($subject)) {
             $subject = $ticket->subject;
         }
         if (!empty($properties['to'])) {
             // forward
             $mail->setSubject($subject);
         } else {
             // reply
             @($group_has_subject = intval(DAO_GroupSettings::get($ticket->team_id, DAO_GroupSettings::SETTING_SUBJECT_HAS_MASK, 0)));
             @($group_subject_prefix = DAO_GroupSettings::get($ticket->team_id, DAO_GroupSettings::SETTING_SUBJECT_PREFIX, ''));
             $prefix = sprintf("[%s#%s] ", !empty($group_subject_prefix) ? $group_subject_prefix . ' ' : '', $ticket->mask);
             $mail->setSubject(sprintf('Re: %s%s', $group_has_subject ? $prefix : '', $subject));
         }
         // References
         if (!empty($message) && false !== @($in_reply_to = $message_headers['message-id'])) {
             $headers->addTextHeader('References', $in_reply_to);
             $headers->addTextHeader('In-Reply-To', $in_reply_to);
         }
         // Auto-reply handling (RFC-3834 compliant)
         if (isset($properties['is_autoreply']) && $properties['is_autoreply']) {
             $headers->addTextHeader('Auto-Submitted', 'auto-replied');
             if (null == ($first_address = DAO_Address::get($ticket->first_wrote_address_id))) {
                 return;
             }
             // Don't send e-mail to ourselves
             if (isset($helpdesk_senders[$first_address->email])) {
                 return;
             }
             // Make sure we haven't mailed this address an autoreply within 5 minutes
             if ($first_address->last_autoreply > 0 && $first_address->last_autoreply > time() - 300) {
                 return;
             }
             $first_email = strtolower($first_address->email);
             $first_split = explode('@', $first_email);
             if (!is_array($first_split) || count($first_split) != 2) {
                 return;
             }
             // If return-path is blank
             if (isset($message_headers['return-path']) && $message_headers['return-path'] == '<>') {
                 return;
             }
             // Ignore bounces
             if ($first_split[0] == "postmaster" || $first_split[0] == "mailer-daemon") {
                 return;
             }
             // Ignore autoresponses to autoresponses
             if (isset($message_headers['auto-submitted']) && $message_headers['auto-submitted'] != 'no') {
                 return;
             }
             if (isset($message_headers['precedence']) && ($message_headers['precedence'] == 'list' || $message_headers['precedence'] == 'junk' || ($message_headers['precedence'] = 'bulk'))) {
                 return;
             }
             // Set the auto-reply date for this address to right now
             DAO_Address::update($ticket->first_wrote_address_id, array(DAO_Address::LAST_AUTOREPLY => time()));
             // Auto-reply just to the initial requester
             $mail->addTo($first_address->email);
             // Not an auto-reply
         } else {
             // Forwards
             if (!empty($properties['to'])) {
                 $aTo = DevblocksPlatform::parseCsvString(str_replace(';', ',', $properties['to']));
                 if (is_array($aTo)) {
                     foreach ($aTo as $to_addy) {
                         $mail->addTo($to_addy);
                     }
                 }
                 // Replies
             } else {
                 // Recipients
                 $requesters = DAO_Ticket::getRequestersByTicket($ticket_id);
                 if (is_array($requesters)) {
                     foreach ($requesters as $requester) {
                         /* @var $requester Model_Address */
                         $mail->addTo($requester->email);
                     }
                 }
             }
             // Ccs
             if (!empty($properties['cc'])) {
                 $aCc = DevblocksPlatform::parseCsvString(str_replace(';', ',', $properties['cc']));
                 $mail->setCc($aCc);
             }
             // Bccs
             if (!empty($properties['bcc'])) {
                 $aBcc = DevblocksPlatform::parseCsvString(str_replace(';', ',', $properties['bcc']));
                 $mail->setBcc($aBcc);
             }
         }
         /*
          * [IMPORTANT -- Yes, this is simply a line in the sand.]
          * You're welcome to modify the code to meet your needs, but please respect 
          * our licensing.  Buy a legitimate copy to help support the project!
          * http://www.cerberusweb.com/
          */
         $license = CerberusLicense::getInstance();
         if (empty($license) || @empty($license['serial'])) {
             $content .= base64_decode("DQoNCi0tLQ0KQ29tYmF0IHNwYW0gYW5kIGltcHJvdmUgcmVzc" . "G9uc2UgdGltZXMgd2l0aCBDZXJiZXJ1cyBIZWxwZGVzayA0LjAhDQpodHRwOi8vd3d3LmNlc" . "mJlcnVzd2ViLmNvbS8NCg");
         }
         // Body
         $mail->setBody($content);
         // Mime Attachments
         if (is_array($files) && !empty($files)) {
             foreach ($files['tmp_name'] as $idx => $file) {
                 if (empty($file) || empty($files['name'][$idx])) {
                     continue;
                 }
                 $mail->attach(Swift_Attachment::fromPath($file)->setFilename($files['name'][$idx]));
             }
         }
         // Forward Attachments
         if (!empty($forward_files) && is_array($forward_files)) {
             $attachments_path = APP_STORAGE_PATH . '/attachments/';
             foreach ($forward_files as $file_id) {
                 $attachment = DAO_Attachment::get($file_id);
                 $attachment_path = $attachments_path . $attachment->filepath;
                 $mail->attach(Swift_Attachment::fromPath($attachment_path)->setFilename($attachment->display_name));
             }
         }
         if (!DEMO_MODE) {
             // If we're not supposed to send
             if (isset($properties['dont_send']) && $properties['dont_send']) {
                 // ...do nothing
             } else {
                 // otherwise send
                 if (!$mailer->send($mail)) {
                     $mail_succeeded = false;
                     throw new Exception('Mail not sent.');
                 }
             }
         }
     } catch (Exception $e) {
         // tag failure, so we can add a note to the message later
         $mail_succeeded = false;
     }
     // Handle post-mail actions
     $change_fields = array();
     $fromAddressInst = CerberusApplication::hashLookupAddress($from_addy, true);
     $fromAddressId = $fromAddressInst->id;
     if ((!isset($properties['dont_keep_copy']) || !$properties['dont_keep_copy']) && (!isset($properties['is_autoreply']) || !$properties['is_autoreply'])) {
         $change_fields[DAO_Ticket::LAST_WROTE_ID] = $fromAddressId;
         $change_fields[DAO_Ticket::UPDATED_DATE] = time();
         if (!empty($worker_id)) {
             $change_fields[DAO_Ticket::LAST_WORKER_ID] = $worker_id;
             $change_fields[DAO_Ticket::LAST_ACTION_CODE] = CerberusTicketActionCode::TICKET_WORKER_REPLY;
         }
         // Only change the subject if not forwarding
         if (!empty($subject) && empty($properties['to'])) {
             $change_fields[DAO_Ticket::SUBJECT] = $subject;
         }
         $fields = array(DAO_Message::TICKET_ID => $ticket_id, DAO_Message::CREATED_DATE => time(), DAO_Message::ADDRESS_ID => $fromAddressId, DAO_Message::IS_OUTGOING => 1, DAO_Message::WORKER_ID => !empty($worker_id) ? $worker_id : 0);
         $message_id = DAO_Message::create($fields);
         // Content
         DAO_MessageContent::create($message_id, $content);
         $headers = $mail->getHeaders();
         // Headers
         foreach ($headers->getAll() as $hdr) {
             if (null != ($hdr_val = $hdr->getFieldBody())) {
                 if (!empty($hdr_val)) {
                     DAO_MessageHeader::create($message_id, $hdr->getFieldName(), CerberusParser::fixQuotePrintableString($hdr_val));
                 }
             }
         }
         // Attachments
         if (is_array($files) && !empty($files)) {
             $attachment_path = APP_STORAGE_PATH . '/attachments/';
             reset($files);
             foreach ($files['tmp_name'] as $idx => $file) {
                 if (empty($file) || empty($files['name'][$idx]) || !file_exists($file)) {
                     continue;
                 }
                 $fields = array(DAO_Attachment::MESSAGE_ID => $message_id, DAO_Attachment::DISPLAY_NAME => $files['name'][$idx], DAO_Attachment::MIME_TYPE => $files['type'][$idx], DAO_Attachment::FILE_SIZE => filesize($file));
                 $file_id = DAO_Attachment::create($fields);
                 $attachment_bucket = sprintf("%03d/", mt_rand(1, 100));
                 $attachment_file = $file_id;
                 if (!file_exists($attachment_path . $attachment_bucket)) {
                     mkdir($attachment_path . $attachment_bucket, 0775, true);
                 }
                 if (!is_writeable($attachment_path . $attachment_bucket)) {
                     echo "Can't write to bucket " . $attachment_path . $attachment_bucket . "<BR>";
                 }
                 copy($file, $attachment_path . $attachment_bucket . $attachment_file);
                 @unlink($file);
                 DAO_Attachment::update($file_id, array(DAO_Attachment::FILEPATH => $attachment_bucket . $attachment_file));
             }
         }
         // add note to message if email failed
         if ($mail_succeeded === false) {
             $fields = array(DAO_MessageNote::MESSAGE_ID => $message_id, DAO_MessageNote::CREATED => time(), DAO_MessageNote::WORKER_ID => 0, DAO_MessageNote::CONTENT => 'Exception thrown while sending email: ' . $e->getMessage(), DAO_MessageNote::TYPE => Model_MessageNote::TYPE_ERROR);
             DAO_MessageNote::create($fields);
         }
     }
     // Post-Reply Change Properties
     if (isset($properties['closed'])) {
         switch ($properties['closed']) {
             case 0:
                 // open
                 $change_fields[DAO_Ticket::IS_WAITING] = 0;
                 $change_fields[DAO_Ticket::IS_CLOSED] = 0;
                 $change_fields[DAO_Ticket::IS_DELETED] = 0;
                 $change_fields[DAO_Ticket::DUE_DATE] = 0;
                 break;
             case 1:
                 // closed
                 $change_fields[DAO_Ticket::IS_WAITING] = 0;
                 $change_fields[DAO_Ticket::IS_CLOSED] = 1;
                 $change_fields[DAO_Ticket::IS_DELETED] = 0;
                 if (isset($properties['ticket_reopen'])) {
                     @($time = intval(strtotime($properties['ticket_reopen'])));
                     $change_fields[DAO_Ticket::DUE_DATE] = $time;
                 }
                 break;
             case 2:
                 // waiting
                 $change_fields[DAO_Ticket::IS_WAITING] = 1;
                 $change_fields[DAO_Ticket::IS_CLOSED] = 0;
                 $change_fields[DAO_Ticket::IS_DELETED] = 0;
                 if (isset($properties['ticket_reopen'])) {
                     @($time = intval(strtotime($properties['ticket_reopen'])));
                     $change_fields[DAO_Ticket::DUE_DATE] = $time;
                 }
                 break;
         }
     }
     // Who should handle the followup?
     if (isset($properties['next_worker_id'])) {
         $change_fields[DAO_Ticket::NEXT_WORKER_ID] = $properties['next_worker_id'];
     }
     // Allow anybody to reply after
     if (isset($properties['unlock_date']) && !empty($properties['unlock_date'])) {
         $unlock = strtotime($properties['unlock_date']);
         if (intval($unlock) > 0) {
             $change_fields[DAO_Ticket::UNLOCK_DATE] = $unlock;
         }
     }
     // Move
     if (!empty($properties['bucket_id'])) {
         // [TODO] Use API to move, or fire event
         // [TODO] Ensure team/bucket exist
         list($team_id, $bucket_id) = CerberusApplication::translateTeamCategoryCode($properties['bucket_id']);
         $change_fields[DAO_Ticket::TEAM_ID] = $team_id;
         $change_fields[DAO_Ticket::CATEGORY_ID] = $bucket_id;
     }
     if (!empty($ticket_id) && !empty($change_fields)) {
         DAO_Ticket::updateTicket($ticket_id, $change_fields);
     }
     // Outbound Reply Event (not automated reply, etc.)
     if (!empty($worker_id)) {
         $eventMgr = DevblocksPlatform::getEventService();
         $eventMgr->trigger(new Model_DevblocksEvent('ticket.reply.outbound', array('ticket_id' => $ticket_id, 'worker_id' => $worker_id)));
     }
 }
Beispiel #8
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::getTicket($ticket_id);
     // (Action) Forward Email To:
     // Sanitize and combine all the destination addresses
     $next_worker = DAO_Worker::getAgent($ticket->next_worker_id);
     $notify_emails = $next_worker->email;
     if (empty($notify_emails)) {
         return;
     }
     // [TODO] This could be more efficient
     $messages = DAO_Ticket::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 = CerberusSettings::getInstance();
         $reply_to = $settings->get(CerberusSettings::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);
         }
     }
 }
Beispiel #9
0
 function doContactSendAction()
 {
     @($sFrom = DevblocksPlatform::importGPC($_POST['from'], 'string', ''));
     @($sSubject = DevblocksPlatform::importGPC($_POST['subject'], 'string', ''));
     @($sContent = DevblocksPlatform::importGPC($_POST['content'], 'string', ''));
     @($sCaptcha = DevblocksPlatform::importGPC($_POST['captcha'], 'string', ''));
     @($aFieldIds = DevblocksPlatform::importGPC($_POST['field_ids'], 'array', array()));
     @($aFollowUpQ = DevblocksPlatform::importGPC($_POST['followup_q'], 'array', array()));
     $fields = DAO_CustomField::getBySource('cerberusweb.fields.source.ticket');
     // Load the answers to any situational questions
     $aFollowUpA = array();
     if (is_array($aFollowUpQ)) {
         foreach ($aFollowUpQ as $idx => $q) {
             // Only form values we were passed
             if (!isset($_POST['followup_a_' . $idx])) {
                 continue;
             }
             if (is_array($_POST['followup_a_' . $idx])) {
                 @($answer = DevblocksPlatform::importGPC($_POST['followup_a_' . $idx], 'array', array()));
                 $aFollowUpA[$idx] = implode(', ', $answer);
             } else {
                 @($answer = DevblocksPlatform::importGPC($_POST['followup_a_' . $idx], 'string', ''));
                 $aFollowUpA[$idx] = $answer;
             }
             // Translate field values into something human-readable (if needed)
             if (isset($aFieldIds[$idx]) && !empty($aFieldIds[$idx])) {
                 // Were we given a legit field id?
                 if (null != @($field = $fields[$aFieldIds[$idx]])) {
                     switch ($field->type) {
                         // Translate 'worker' fields into worker name (not ID)
                         case Model_CustomField::TYPE_WORKER:
                             if (null != ($worker = DAO_Worker::getAgent($answer))) {
                                 $aFollowUpA[$idx] = $worker->getName();
                             }
                             break;
                     }
                     // switch
                 }
                 // if
             }
             // if
         }
     }
     $umsession = UmPortalHelper::getSession();
     $active_user = $umsession->getProperty('sc_login', null);
     $fingerprint = UmPortalHelper::getFingerprint();
     $settings = CerberusSettings::getInstance();
     $default_from = $settings->get(CerberusSettings::DEFAULT_REPLY_FROM);
     $umsession->setProperty('support.write.last_from', $sFrom);
     $umsession->setProperty('support.write.last_subject', $sSubject);
     $umsession->setProperty('support.write.last_content', $sContent);
     $umsession->setProperty('support.write.last_followup_a', $aFollowUpA);
     $sNature = $umsession->getProperty('support.write.last_nature', '');
     $captcha_enabled = DAO_CommunityToolProperty::get(UmPortalHelper::getCode(), self::PARAM_CAPTCHA_ENABLED, 1);
     $captcha_session = $umsession->getProperty(UmScApp::SESSION_CAPTCHA, '***');
     // Subject is required if the field  is on the form
     if (isset($_POST['subject']) && empty($sSubject)) {
         $umsession->setProperty('support.write.last_error', 'A subject is required.');
         DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('portal', UmPortalHelper::getCode(), 'contact', 'step2')));
         return;
     }
     // Sender and CAPTCHA required
     if (empty($sFrom) || $captcha_enabled && 0 != strcasecmp($sCaptcha, $captcha_session)) {
         if (empty($sFrom)) {
             $umsession->setProperty('support.write.last_error', 'Invalid e-mail address.');
         } else {
             $umsession->setProperty('support.write.last_error', 'What you typed did not match the image.');
         }
         // Need to report the captcha didn't match and redraw the form
         DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('portal', UmPortalHelper::getCode(), 'contact', 'step2')));
         return;
     }
     // Dispatch
     $to = $default_from;
     $subject = 'Contact me: Other';
     $sDispatch = DAO_CommunityToolProperty::get(UmPortalHelper::getCode(), self::PARAM_SITUATIONS, '');
     $dispatch = !empty($sDispatch) ? unserialize($sDispatch) : array();
     foreach ($dispatch as $k => $v) {
         if (md5($k) == $sNature) {
             $to = $v['to'];
             $subject = 'Contact me: ' . strip_tags($k);
             break;
         }
     }
     if (!empty($sSubject)) {
         $subject = $sSubject;
     }
     $fieldContent = '';
     if (!empty($aFollowUpQ)) {
         $fieldContent = "\r\n\r\n";
         $fieldContent .= "--------------------------------------------\r\n";
         if (!empty($sNature)) {
             $fieldContent .= $subject . "\r\n";
             $fieldContent .= "--------------------------------------------\r\n";
         }
         foreach ($aFollowUpQ as $idx => $q) {
             $answer = isset($aFollowUpA[$idx]) ? $aFollowUpA[$idx] : '';
             $fieldContent .= "Q) " . $q . "\r\n" . "A) " . $answer . "\r\n";
             if ($idx + 1 < count($aFollowUpQ)) {
                 $fieldContent .= "\r\n";
             }
         }
         $fieldContent .= "--------------------------------------------\r\n";
         "\r\n";
     }
     $message = new CerberusParserMessage();
     $message->headers['date'] = date('r');
     $message->headers['to'] = $to;
     $message->headers['subject'] = $subject;
     $message->headers['message-id'] = CerberusApplication::generateMessageId();
     $message->headers['x-cerberus-portal'] = 1;
     // Sender
     $fromList = imap_rfc822_parse_adrlist($sFrom, '');
     if (empty($fromList) || !is_array($fromList)) {
         return;
         // abort with message
     }
     $from = array_shift($fromList);
     $message->headers['from'] = $from->mailbox . '@' . $from->host;
     $message->body = 'IP: ' . $fingerprint['ip'] . "\r\n\r\n" . $sContent . $fieldContent;
     // Attachments
     $attachments_mode = DAO_CommunityToolProperty::get(UmPortalHelper::getCode(), self::PARAM_ATTACHMENTS_MODE, 0);
     if (0 == $attachments_mode || 1 == $attachments_mode && !empty($active_user)) {
         if (is_array($_FILES) && !empty($_FILES)) {
             foreach ($_FILES as $name => $files) {
                 // field[]
                 if (is_array($files['name'])) {
                     foreach ($files['name'] as $idx => $name) {
                         $attach = new ParserFile();
                         $attach->setTempFile($files['tmp_name'][$idx], 'application/octet-stream');
                         $attach->file_size = filesize($files['tmp_name'][$idx]);
                         $message->files[$name] = $attach;
                     }
                 } else {
                     $attach = new ParserFile();
                     $attach->setTempFile($files['tmp_name'], 'application/octet-stream');
                     $attach->file_size = filesize($files['tmp_name']);
                     $message->files[$files['name']] = $attach;
                 }
             }
         }
     }
     // Custom Fields
     if (!empty($aFieldIds)) {
         foreach ($aFieldIds as $iIdx => $iFieldId) {
             if (!empty($iFieldId)) {
                 $field =& $fields[$iFieldId];
                 /* @var $field Model_CustomField */
                 $value = "";
                 switch ($field->type) {
                     case Model_CustomField::TYPE_SINGLE_LINE:
                     case Model_CustomField::TYPE_MULTI_LINE:
                     case Model_CustomField::TYPE_URL:
                         @($value = trim($aFollowUpA[$iIdx]));
                         break;
                     case Model_CustomField::TYPE_NUMBER:
                         @($value = $aFollowUpA[$iIdx]);
                         if (!is_numeric($value) || 0 == strlen($value)) {
                             $value = null;
                         }
                         break;
                     case Model_CustomField::TYPE_DATE:
                         if (false !== ($time = strtotime($aFollowUpA[$iIdx]))) {
                             @($value = intval($time));
                         }
                         break;
                     case Model_CustomField::TYPE_DROPDOWN:
                         @($value = $aFollowUpA[$iIdx]);
                         break;
                     case Model_CustomField::TYPE_MULTI_PICKLIST:
                         @($value = DevblocksPlatform::importGPC($_POST['followup_a_' . $iIdx], 'array', array()));
                         break;
                     case Model_CustomField::TYPE_CHECKBOX:
                         @($value = isset($aFollowUpA[$iIdx]) && !empty($aFollowUpA[$iIdx]) ? 1 : 0);
                         break;
                     case Model_CustomField::TYPE_MULTI_CHECKBOX:
                         @($value = DevblocksPlatform::importGPC($_POST['followup_a_' . $iIdx], 'array', array()));
                         break;
                     case Model_CustomField::TYPE_WORKER:
                         @($value = DevblocksPlatform::importGPC($_POST['followup_a_' . $iIdx], 'integer', 0));
                         break;
                 }
                 if (is_array($value) && !empty($value) || !is_array($value) && 0 != strlen($value)) {
                     $message->custom_fields[$iFieldId] = $value;
                 }
             }
         }
     }
     // Parse
     $ticket_id = CerberusParser::parseMessage($message);
     // It's possible for the parser to reject the message using pre-filters
     if (!empty($ticket_id) && null != ($ticket = DAO_Ticket::getTicket($ticket_id))) {
         $umsession->setProperty('support.write.last_opened', $ticket->mask);
     } else {
         $umsession->setProperty('support.write.last_opened', null);
     }
     // Clear any errors
     $umsession->setProperty('support.write.last_nature', null);
     $umsession->setProperty('support.write.last_nature_string', null);
     $umsession->setProperty('support.write.last_content', null);
     $umsession->setProperty('support.write.last_error', null);
     DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('portal', UmPortalHelper::getCode(), 'contact', 'confirm')));
 }