Example #1
0
 function handleRequest(DevblocksHttpRequest $request)
 {
     $translate = DevblocksPlatform::getTranslationService();
     $stack = $request->path;
     // URLS like: /files/10000/plaintext.txt
     array_shift($stack);
     // files
     $file_id = array_shift($stack);
     // 10000
     $file_name = array_shift($stack);
     // plaintext.txt
     // Security
     if (null == ($active_worker = CerberusApplication::getActiveWorker())) {
         die($translate->_('common.access_denied'));
     }
     if (empty($file_id) || empty($file_name) || null == ($file = DAO_Attachment::get($file_id))) {
         die($translate->_('files.not_found'));
     }
     // Security
     $message = DAO_Ticket::getMessage($file->message_id);
     if (null == ($ticket = DAO_Ticket::getTicket($message->ticket_id))) {
         die($translate->_('common.access_denied'));
     }
     // Security
     $active_worker_memberships = $active_worker->getMemberships();
     if (null == $active_worker_memberships[$ticket->team_id]) {
         die($translate->_('common.access_denied'));
     }
     // Set headers
     header("Expires: Mon, 26 Nov 1962 00:00:00 GMT\n");
     header("Last-Modified: " . gmdate("D,d M YH:i:s") . " GMT\n");
     header("Cache-control: private\n");
     header("Pragma: no-cache\n");
     header("Content-Type: " . $file->mime_type . "\n");
     header("Content-transfer-encoding: binary\n");
     header("Content-Length: " . $file->getFileSize() . "\n");
     echo $file->getFileContents();
     exit;
 }
Example #2
0
File: App.php Project: Hildy/cerb5
 function showTab()
 {
     @($ticket_id = DevblocksPlatform::importGPC($_REQUEST['ticket_id'], 'integer', 0));
     $tpl = DevblocksPlatform::getTemplateService();
     $tpl_path = dirname(dirname(__FILE__)) . '/templates/';
     $tpl->assign('path', $tpl_path);
     $ticket = DAO_Ticket::getTicket($ticket_id);
     $tpl->assign('ticket_id', $ticket_id);
     $tpl->assign('ticket', $ticket);
     // Receate the original spam decision
     $words = DevblocksPlatform::parseCsvString($ticket->interesting_words);
     $words = DAO_Bayes::lookupWordIds($words);
     // Calculate word probabilities
     foreach ($words as $idx => $word) {
         /* @var $word CerberusBayesWord */
         $word->probability = CerberusBayes::calculateWordProbability($word);
     }
     $tpl->assign('words', $words);
     // Determine what the spam probability would be if the decision was made right now
     $analysis = CerberusBayes::calculateTicketSpamProbability($ticket_id, true);
     $tpl->assign('analysis', $analysis);
     $tpl->display('file:' . $tpl_path . 'ticket_tab/index.tpl');
 }
Example #3
0
 function showTab()
 {
     @($ticket_id = DevblocksPlatform::importGPC($_REQUEST['ticket_id'], 'integer', 0));
     $tpl = DevblocksPlatform::getTemplateService();
     $tpl_path = dirname(dirname(__FILE__)) . '/templates/';
     $tpl->assign('path', $tpl_path);
     $tpl->cache_lifetime = "0";
     $ticket = DAO_Ticket::getTicket($ticket_id);
     $tpl->assign('ticket_id', $ticket_id);
     $address = DAO_Address::get($ticket->first_wrote_address_id);
     $tpl->assign('address', $address);
     if (null == ($view = C4_AbstractViewLoader::getView('', 'ticket_opps'))) {
         $view = new C4_CrmOpportunityView();
         $view->id = 'ticket_opps';
     }
     if (!empty($address->contact_org_id)) {
         // org
         @($org = DAO_ContactOrg::get($address->contact_org_id));
         $view->name = "Org: " . $org->name;
         $view->params = array(SearchFields_CrmOpportunity::ORG_ID => new DevblocksSearchCriteria(SearchFields_CrmOpportunity::ORG_ID, '=', $org->id));
     } else {
         // address
         $view->name = "Requester: " . $address->email;
         $view->params = array(SearchFields_CrmOpportunity::PRIMARY_EMAIL_ID => new DevblocksSearchCriteria(SearchFields_CrmOpportunity::PRIMARY_EMAIL_ID, '=', $ticket->first_wrote_address_id));
     }
     C4_AbstractViewLoader::setView($view->id, $view);
     $tpl->assign('view', $view);
     $tpl->display('file:' . $tpl_path . 'crm/opps/ticket/tab.tpl');
 }
Example #4
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()));
     // Load the answers to any situational questions
     $aFollowUpA = array();
     if (is_array($aFollowUpQ)) {
         foreach ($aFollowUpQ as $idx => $q) {
             @($answer = DevblocksPlatform::importGPC($_POST['followup_a_' . $idx], 'string', ''));
             $aFollowUpA[$idx] = $answer;
         }
     }
     $umsession = $this->getSession();
     $fingerprint = parent::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_q',$aFollowUpQ);
     $umsession->setProperty('support.write.last_followup_a', $aFollowUpA);
     $sNature = $umsession->getProperty('support.write.last_nature', '');
     $captcha_enabled = DAO_CommunityToolProperty::get($this->getPortal(), UmScApp::PARAM_CAPTCHA_ENABLED, 1);
     if (empty($sFrom) || $captcha_enabled && 0 != strcasecmp($sCaptcha, @$umsession->getProperty(UmScApp::SESSION_CAPTCHA, '***'))) {
         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.');
         }
         // [TODO] Need to report the captcha didn't match and redraw the form
         DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('portal', $this->getPortal(), 'contact', 'step2')));
         return;
     }
     // Dispatch
     $to = $default_from;
     $subject = 'Contact me: Other';
     $sDispatch = DAO_CommunityToolProperty::get($this->getPortal(), UmScApp::PARAM_DISPATCH, '');
     $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;
     $ticket_id = CerberusParser::parseMessage($message);
     $ticket = DAO_Ticket::getTicket($ticket_id);
     // Auto-save any custom fields
     $fields = DAO_CustomField::getBySource('cerberusweb.fields.source.ticket');
     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:
                         @($value = trim($aFollowUpA[$iIdx]));
                         break;
                     case Model_CustomField::TYPE_NUMBER:
                         @($value = intval($aFollowUpA[$iIdx]));
                         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_CHECKBOX:
                         @($value = isset($aFollowUpA[$iIdx]) && !empty($aFollowUpA[$iIdx]) ? 1 : 0);
                         break;
                 }
                 if (!empty($value)) {
                     DAO_CustomFieldValue::setFieldValue('cerberusweb.fields.source.ticket', $ticket_id, $iFieldId, $value);
                 }
             }
         }
     }
     // 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);
     $umsession->setProperty('support.write.last_opened', $ticket->mask);
     DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('portal', $this->getPortal(), 'contact', 'confirm')));
 }
Example #5
0
 function showInboxFilterPanelAction()
 {
     @($id = DevblocksPlatform::importGPC($_REQUEST['id'], 'integer', 0));
     @($group_id = DevblocksPlatform::importGPC($_REQUEST['group_id'], 'integer', 0));
     @($ticket_id = DevblocksPlatform::importGPC($_REQUEST['ticket_id'], 'integer', 0));
     @($view_id = DevblocksPlatform::importGPC($_REQUEST['view_id'], 'string', ''));
     $active_worker = CerberusApplication::getActiveWorker();
     $tpl = DevblocksPlatform::getTemplateService();
     $tpl_path = $this->_TPL_PATH;
     $tpl->assign('path', $tpl_path);
     $tpl->assign('group_id', $group_id);
     $tpl->assign('view_id', $view_id);
     if (null != ($filter = DAO_GroupInboxFilter::get($id))) {
         $tpl->assign('filter', $filter);
     }
     // Make sure we're allowed to change this group's setup
     if (!$active_worker->isTeamManager($group_id) && !$active_worker->is_superuser) {
         return;
     }
     // Load the example ticket + headers if provided
     if (!empty($ticket_id)) {
         $ticket = DAO_Ticket::getTicket($ticket_id);
         $tpl->assign('ticket', $ticket);
         $messages = $ticket->getMessages();
         $message = array_shift($messages);
         /* @var $message CerberusMessage */
         $message_headers = $message->getHeaders();
         $tpl->assign('message', $message);
         $tpl->assign('message_headers', $message_headers);
     }
     $category_name_hash = DAO_Bucket::getCategoryNameHash();
     $tpl->assign('category_name_hash', $category_name_hash);
     $groups = DAO_Group::getAll();
     $tpl->assign('groups', $groups);
     $team_categories = DAO_Bucket::getTeams();
     $tpl->assign('team_categories', $team_categories);
     $workers = DAO_Worker::getAll();
     $tpl->assign('workers', $workers);
     // Custom Fields: Address
     $address_fields = DAO_CustomField::getBySource(ChCustomFieldSource_Address::ID);
     $tpl->assign('address_fields', $address_fields);
     // Custom Fields: Orgs
     $org_fields = DAO_CustomField::getBySource(ChCustomFieldSource_Org::ID);
     $tpl->assign('org_fields', $org_fields);
     // Custom Fields: Tickets
     $ticket_fields = DAO_CustomField::getBySource(ChCustomFieldSource_Ticket::ID);
     $tpl->assign('ticket_fields', $ticket_fields);
     $tpl->display('file:' . $tpl_path . 'groups/manage/filters/peek.tpl');
 }
Example #6
0
 function render()
 {
     $tpl = DevblocksPlatform::getTemplateService();
     $response = DevblocksPlatform::getHttpResponse();
     @($ticket_id = $response->path[2]);
     @($page_type = DevblocksPlatform::importGPC($_REQUEST['page_type'], 'string', 'reply'));
     $message_id = $response->path[3];
     if (empty($ticket_id)) {
         $session = DevblocksPlatform::getSessionService();
         $visit = $session->getVisit();
         return;
     }
     if (!is_numeric($ticket_id)) {
         $ticket_id = DAO_Ticket::getTicketIdByMask($ticket_id);
     }
     $ticket = DAO_Ticket::getTicket($ticket_id);
     $tpl->assign('ticket', $ticket);
     $tpl->assign('ticket_id', $ticket_id);
     $tpl->assign('message_id', $message_id);
     $tpl->assign('page_type', $page_type);
     if (0 == strcasecmp($message_id, 'full')) {
         $tpl->display('file:' . dirname(__FILE__) . '/templates/display.tpl');
     } else {
         $message = DAO_Ticket::getMessage($message_id);
         if (empty($message)) {
             $message = array_pop($ticket->getMessages());
         }
         $tpl->assign('message', $message);
         $tpl->display('file:' . dirname(__FILE__) . '/templates/display_brief.tpl');
     }
 }
Example #7
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;
     }
     $setting_manifest = DevblocksPlatform::getExtension(AnswernetLastActionAndAuditLogConfigTab::ID);
     $setting = $setting_manifest->createInstance();
     $al_merge_enabled = intval($setting->getParam(AnswernetLastActionAndAuditLogConfigTab::AL_MERGE_ENABLED, 0));
     $uf_merge_enabled = intval($setting->getParam(AnswernetLastActionAndAuditLogConfigTab::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::getTicket($old_id);
                 $translate_str = $translate->_('answernet.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 => "answernet.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::updateTicket($new_ticket_id, $new_change_fields);
         unset($new_change_fields);
     }
 }
Example #8
0
 function getSourceInfo($object_id)
 {
     if (null == ($ticket = DAO_Ticket::getTicket($object_id))) {
         return;
     }
     $url = DevblocksPlatform::getUrlService();
     return array('name' => '[Ticket] ' . $ticket->subject, 'url' => $url->write(sprintf('c=display&mask=%s&tab=tasks', $ticket->mask), true));
 }
Example #9
0
 function handleRequest(DevblocksHttpRequest $request)
 {
     $worker = CerberusApplication::getActiveWorker();
     if (empty($worker)) {
         return;
     }
     $stack = $request->path;
     array_shift($stack);
     // print
     @($object = strtolower(array_shift($stack)));
     // ticket|message|etc
     $tpl = DevblocksPlatform::getTemplateService();
     $tpl->assign('path', $this->_TPL_PATH);
     $settings = DevblocksPlatform::getPluginSettingsService();
     $tpl->assign('settings', $settings);
     $translate = DevblocksPlatform::getTranslationService();
     $tpl->assign('translate', $translate);
     $teams = DAO_Group::getAll();
     $tpl->assign('teams', $teams);
     $buckets = DAO_Bucket::getAll();
     $tpl->assign('buckets', $buckets);
     $workers = DAO_Worker::getAll();
     $tpl->assign('workers', $workers);
     // Security
     $active_worker = CerberusApplication::getActiveWorker();
     $active_worker_memberships = $active_worker->getMemberships();
     // [TODO] Make this pluggable
     // Subcontroller
     switch ($object) {
         case 'ticket':
             @($id = array_shift($stack));
             @($ticket = is_numeric($id) ? DAO_Ticket::getTicket($id) : DAO_Ticket::getTicketByMask($id));
             $convo_timeline = array();
             $messages = $ticket->getMessages();
             foreach ($messages as $message_id => $message) {
                 /* @var $message CerberusMessage */
                 $key = $message->created_date . '_m' . $message_id;
                 // build a chrono index of messages
                 $convo_timeline[$key] = array('m', $message_id);
             }
             @($mail_inline_comments = DAO_WorkerPref::get($active_worker->id, 'mail_inline_comments', 1));
             if ($mail_inline_comments) {
                 // if inline comments are enabled
                 $comments = DAO_TicketComment::getByTicketId($ticket->id);
                 arsort($comments);
                 $tpl->assign('comments', $comments);
                 // build a chrono index of comments
                 foreach ($comments as $comment_id => $comment) {
                     /* @var $comment Model_TicketComment */
                     $key = $comment->created . '_c' . $comment_id;
                     $convo_timeline[$key] = array('c', $comment_id);
                 }
             }
             ksort($convo_timeline);
             $tpl->assign('convo_timeline', $convo_timeline);
             // Comment parent addresses
             $comment_addresses = array();
             foreach ($comments as $comment) {
                 /* @var $comment Model_TicketComment */
                 $address_id = intval($comment->address_id);
                 if (!isset($comment_addresses[$address_id])) {
                     $address = DAO_Address::get($address_id);
                     $comment_addresses[$address_id] = $address;
                 }
             }
             $tpl->assign('comment_addresses', $comment_addresses);
             // Message Notes
             $notes = DAO_MessageNote::getByTicketId($ticket->id);
             $message_notes = array();
             // Index notes by message id
             if (is_array($notes)) {
                 foreach ($notes as $note) {
                     if (!isset($message_notes[$note->message_id])) {
                         $message_notes[$note->message_id] = array();
                     }
                     $message_notes[$note->message_id][$note->id] = $note;
                 }
             }
             $tpl->assign('message_notes', $message_notes);
             // Make sure we're allowed to view this ticket or message
             if (!isset($active_worker_memberships[$ticket->team_id])) {
                 echo "<H1>" . $translate->_('common.access_denied') . "</H1>";
                 return;
             }
             $tpl->assign('ticket', $ticket);
             $tpl->display('file:' . $this->_TPL_PATH . 'print/ticket.tpl');
             break;
         case 'message':
             @($id = array_shift($stack));
             @($message = DAO_Ticket::getMessage($id));
             @($ticket = DAO_Ticket::getTicket($message->ticket_id));
             // Make sure we're allowed to view this ticket or message
             if (!isset($active_worker_memberships[$ticket->team_id])) {
                 echo "<H1>" . $translate->_('common.access_denied') . "</H1>";
                 return;
             }
             // Message Notes
             $notes = DAO_MessageNote::getByTicketId($ticket->id);
             $message_notes = array();
             // Index notes by message id
             if (is_array($notes)) {
                 foreach ($notes as $note) {
                     if (!isset($message_notes[$note->message_id])) {
                         $message_notes[$note->message_id] = array();
                     }
                     $message_notes[$note->message_id][$note->id] = $note;
                 }
             }
             $tpl->assign('message_notes', $message_notes);
             $tpl->assign('message', $message);
             $tpl->assign('ticket', $ticket);
             $tpl->display('file:' . $this->_TPL_PATH . 'print/message.tpl');
             break;
     }
 }
Example #10
0
 function logTicketAction()
 {
     $active_worker = CerberusApplication::getActiveWorker();
     if (!$active_worker->hasPriv('core.mail.log_ticket')) {
         return;
     }
     @($to = DevblocksPlatform::importGPC($_POST['to'], 'string'));
     @($reqs = DevblocksPlatform::importGPC($_POST['reqs'], 'string'));
     @($subject = DevblocksPlatform::importGPC($_POST['subject'], 'string'));
     @($content = DevblocksPlatform::importGPC($_POST['content'], 'string'));
     @($send_to_requesters = DevblocksPlatform::importGPC($_POST['send_to_requesters'], 'integer', 0));
     @($closed = DevblocksPlatform::importGPC($_POST['closed'], 'integer', 0));
     @($move_bucket = DevblocksPlatform::importGPC($_POST['bucket_id'], 'string', ''));
     @($next_worker_id = DevblocksPlatform::importGPC($_POST['next_worker_id'], 'integer', 0));
     @($ticket_reopen = DevblocksPlatform::importGPC($_POST['ticket_reopen'], 'string', ''));
     @($unlock_date = DevblocksPlatform::importGPC($_POST['unlock_date'], 'string', ''));
     if (DEMO_MODE) {
         DevblocksPlatform::redirect(new DevblocksHttpResponse(array('tickets', 'create')));
         return;
     }
     // ********
     $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(rtrim($reqs, ', '), '');
     if (empty($fromList) || !is_array($fromList)) {
         return;
         // abort with message
     }
     $from = array_shift($fromList);
     $from_address = $from->mailbox . '@' . $from->host;
     $message->headers['from'] = $from_address;
     $message->body = sprintf("(... This message was manually created by %s on behalf of the requesters ...)\r\n", $active_worker->getName());
     //		// 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);
     $ticket = DAO_Ticket::getTicket($ticket_id);
     // Add additional requesters to ticket
     if (is_array($fromList) && !empty($fromList)) {
         foreach ($fromList as $requester) {
             if (empty($requester)) {
                 continue;
             }
             $host = empty($requester->host) ? 'localhost' : $requester->host;
             $requester_addy = DAO_Address::lookupAddress($requester->mailbox . '@' . $host, true);
             DAO_Ticket::createRequester($requester_addy->id, $ticket_id);
         }
     }
     // Worker reply
     $properties = array('message_id' => $ticket->first_message_id, 'ticket_id' => $ticket_id, 'subject' => $subject, 'content' => $content, 'files' => @$_FILES['attachment'], 'next_worker_id' => $next_worker_id, 'closed' => $closed, 'bucket_id' => $move_bucket, 'ticket_reopen' => $ticket_reopen, 'unlock_date' => $unlock_date, 'agent_id' => $active_worker->id, 'dont_send' => false == $send_to_requesters);
     CerberusMail::sendTicketMessage($properties);
     // ********
     //		if(empty($to) || empty($team_id)) {
     //			DevblocksPlatform::redirect(new DevblocksHttpResponse(array('tickets','create')));
     //			return;
     //		}
     $visit = CerberusApplication::getVisit();
     /* @var CerberusVisit $visit */
     $visit->set('compose.last_ticket', $ticket->mask);
     DevblocksPlatform::redirect(new DevblocksHttpResponse(array('tickets', 'create')));
 }
Example #11
0
File: Mail.php Project: Hildy/cerb5
 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)));
     }
 }
Example #12
0
 function logTicketAction()
 {
     $active_worker = CerberusApplication::getActiveWorker();
     if (!$active_worker->hasPriv('core.mail.log_ticket')) {
         return;
     }
     @($team_id = DevblocksPlatform::importGPC($_POST['team_id'], 'integer'));
     @($to = DevblocksPlatform::importGPC($_POST['to'], 'string'));
     @($subject = DevblocksPlatform::importGPC($_POST['subject'], 'string'));
     @($content = DevblocksPlatform::importGPC($_POST['content'], 'string'));
     @($files = $_FILES['attachment']);
     @($closed = DevblocksPlatform::importGPC($_POST['closed'], 'integer', 0));
     @($move_bucket = DevblocksPlatform::importGPC($_POST['bucket_id'], 'string', ''));
     @($next_worker_id = DevblocksPlatform::importGPC($_POST['next_worker_id'], 'integer', 0));
     @($ticket_reopen = DevblocksPlatform::importGPC($_POST['ticket_reopen'], 'string', ''));
     @($unlock_date = DevblocksPlatform::importGPC($_POST['unlock_date'], 'string', ''));
     if (DEMO_MODE) {
         DevblocksPlatform::redirect(new DevblocksHttpResponse(array('tickets', 'create')));
         return;
     }
     if (empty($to) || empty($team_id)) {
         DevblocksPlatform::redirect(new DevblocksHttpResponse(array('tickets', 'create')));
         return;
     }
     // [TODO] "Opened/sent on behalf of..."
     $properties = array('team_id' => $team_id, 'to' => $to, 'subject' => $subject, 'content' => $content, 'files' => $files, 'closed' => $closed, 'move_bucket' => $move_bucket, 'next_worker_id' => $next_worker_id, 'ticket_reopen' => $ticket_reopen, 'unlock_date' => $unlock_date, 'no_mail' => true);
     $ticket_id = CerberusMail::compose($properties);
     // [TODO] The problem here is the requester isn't the real sender (worker is)
     // Run group filters
     //if(false !== ($rules = CerberusApplication::runGroupRouting($team_id, $ticket_id))) { /* @var $rule Model_GroupInboxFilter */
     // ...
     //}
     $ticket = DAO_Ticket::getTicket($ticket_id);
     $visit = CerberusApplication::getVisit();
     /* @var CerberusVisit $visit */
     $visit->set('compose.last_ticket', $ticket->mask);
     //DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('display',$ticket_id)));
     DevblocksPlatform::redirect(new DevblocksHttpResponse(array('tickets', 'create')));
 }
Example #13
0
 function doSendMessageAction()
 {
     @($sFrom = DevblocksPlatform::importGPC($_POST['from'], 'string', ''));
     @($sContent = DevblocksPlatform::importGPC($_POST['content'], 'string', ''));
     @($sCaptcha = DevblocksPlatform::importGPC($_POST['captcha'], 'string', ''));
     $umsession = $this->getSession();
     $fingerprint = parent::getFingerprint();
     $settings = CerberusSettings::getInstance();
     $default_from = $settings->get(CerberusSettings::DEFAULT_REPLY_FROM);
     $umsession->setProperty('support.write.last_from', $sFrom);
     $umsession->setProperty('support.write.last_content', $sContent);
     $sNature = $umsession->getProperty('support.write.last_nature', '');
     $captcha_enabled = DAO_CommunityToolProperty::get($this->getPortal(), self::PARAM_CAPTCHA_ENABLED, 1);
     if (empty($sFrom) || $captcha_enabled && 0 != strcasecmp($sCaptcha, @$umsession->getProperty(self::SESSION_CAPTCHA, '***'))) {
         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.');
         }
         // [TODO] Need to report the captcha didn't match and redraw the form
         DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('portal', $this->getPortal(), 'write', 'step3')));
         return;
     }
     // Dispatch
     $to = $default_from;
     $subject = 'Contact me: Other';
     $sDispatch = DAO_CommunityToolProperty::get($this->getPortal(), self::PARAM_DISPATCH, '');
     $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;
         }
     }
     $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;
     $message->body = $sContent;
     $ticket_id = CerberusParser::parseMessage($message);
     $ticket = DAO_Ticket::getTicket($ticket_id);
     //		echo "Created Ticket ID: $ticket_id<br>";
     // [TODO] Could set this ID/mask into the UMsession
     // 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);
     $umsession->setProperty('support.write.last_opened', $ticket->mask);
     DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('portal', $this->getPortal(), 'write', 'confirm')));
 }
Example #14
0
 function getStopTimerPanelAction()
 {
     $total_secs = $this->_stopTimer();
     $this->_stopTimer();
     $object = new Model_TimeTrackingEntry();
     $object->id = 0;
     // Time
     //		$tpl->assign('total_secs', $total_secs);
     //		$tpl->assign('total_mins', ceil($total_secs/60));
     $object->time_actual_mins = ceil($total_secs / 60);
     // Source
     @($source_ext_id = strtolower($_SESSION['timetracking_source_ext_id']));
     @($source_id = intval($_SESSION['timetracking_source_id']));
     $object->source_extension_id = $source_ext_id;
     $object->source_id = $source_id;
     //		$tpl->assign('source_ext_id', $source_ext_id);
     //		$tpl->assign('source_id', $source_id);
     switch ($source_ext_id) {
         // Ticket
         case 'timetracking.source.ticket':
             if (null != ($ticket = DAO_Ticket::getTicket($source_id))) {
                 // Timeslip Responsible Party
                 if (null != ($address = DAO_Address::get($ticket->first_wrote_address_id))) {
                     //						$tpl->assign('performed_for', $address->email);
                     // Timeslip Org
                     if (!empty($address->contact_org_id)) {
                         //							&& null != ($org = DAO_ContactOrg::get($address->contact_org_id))) {
                         //							$tpl->assign('org', $org->name);
                         $object->debit_org_id = $address->contact_org_id;
                     }
                 }
                 // Timeslip reference
                 //					$tpl->assign('reference', sprintf("Ticket #%s",
                 //						$ticket->mask
                 //						//((strlen($ticket->subject)>45) ? (substr($ticket->subject,0,45).'...') : $ticket->subject)
                 //					));
                 // Timeslip note
                 $object->notes = sprintf("Ticket #%s ", $ticket->mask);
                 //					$tpl->assign('note', sprintf("Replied to %s",
                 //						$ticket->mask,
                 //						(!empty($address->email) ? $address->email : '')
                 //					));
             }
             break;
     }
     $this->showEntryAction($object);
 }
Example #15
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')));
 }
Example #16
0
 private function _sendForwards($event, $is_inbound)
 {
     @($ticket_id = $event->params['ticket_id']);
     @($message_id = $event->params['message_id']);
     @($send_worker_id = $event->params['worker_id']);
     $ticket = DAO_Ticket::getTicket($ticket_id);
     $helpdesk_senders = CerberusApplication::getHelpdeskSenders();
     $workers = DAO_Worker::getAllActive();
     // [JAS]: Don't send obvious spam to watchers.
     if ($ticket->spam_score >= 0.9) {
         return true;
     }
     @($notifications = DAO_WorkerMailForward::getWhere(sprintf("%s = %d", DAO_WorkerMailForward::GROUP_ID, $ticket->team_id)));
     // Bail out early if we have no forwards for this group
     if (empty($notifications)) {
         return;
     }
     $message = DAO_Ticket::getMessage($message_id);
     $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[1] == "postmaster" || $sender_split[1] == "mailer-daemon") {
             return;
         }
         // Ignore autoresponses autoresponses
         if (isset($headers['auto-submitted']) && $headers['auto-submitted'] != 'no') {
             return;
         }
         // Headers
         //==========
         // Build mailing list
         $send_to = array();
         foreach ($notifications as $n) {
             /* @var $n Model_WorkerMailForward */
             if (!isset($n->group_id) || !isset($n->bucket_id)) {
                 continue;
             }
             // if worker no longer exists or is disabled
             if (!isset($workers[$n->worker_id])) {
                 continue;
             }
             // Don't allow a worker to usurp a helpdesk address
             if (isset($helpdesk_senders[$n->email])) {
                 continue;
             }
             if ($n->group_id == $ticket->team_id && ($n->bucket_id == -1 || $n->bucket_id == $ticket->category_id)) {
                 // Event checking
                 if ($is_inbound && ($n->event == 'i' || $n->event == 'io') || !$is_inbound && ($n->event == 'o' || $n->event == 'io') || $is_inbound && $n->event == 'r' && $ticket->next_worker_id == $n->worker_id) {
                     $send_to[$n->email] = true;
                 }
             }
         }
         // 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;
                 }
                 $file =& new Swift_File($attachment_path . $attachment->filepath);
                 $mime_attachments[] =& new Swift_Message_Attachment($file, $attachment->display_name, $attachment->mime_type);
             }
         }
         // Send copies
         if (is_array($send_to) && !empty($send_to)) {
             $mail_service = DevblocksPlatform::getMailService();
             $mailer = $mail_service->getMailer(CerberusMail::getMailerDefaults());
             foreach ($send_to as $to => $bool) {
                 // Proxy the message
                 $rcpt_to = new Swift_RecipientList();
                 $a_rcpt_to = array();
                 $mail_from = new Swift_Address($sender->email);
                 $rcpt_to->addTo($to);
                 $a_rcpt_to = new Swift_Address($to);
                 $mail = $mail_service->createMessage();
                 /* @var $mail Swift_Message */
                 $mail->setTo($a_rcpt_to);
                 $mail->setFrom($mail_from);
                 $mail->setReplyTo($reply_to);
                 $mail->setReturnPath($reply_to);
                 $mail->setSubject(sprintf("[%s #%s]: %s", $is_inbound ? 'inbound' : 'outbound', $ticket->mask, $ticket->subject));
                 if (false !== @($msgid = $headers['message-id'])) {
                     $mail->headers->set('Message-Id', $msgid);
                 }
                 if (false !== @($in_reply_to = $headers['in-reply-to'])) {
                     $mail->headers->set('References', $in_reply_to);
                     $mail->headers->set('In-Reply-To', $in_reply_to);
                 }
                 $mail->headers->set('X-Mailer', 'Cerberus Helpdesk (Build ' . APP_BUILD . ')');
                 $mail->headers->set('Precedence', 'List');
                 $mail->headers->set('Auto-Submitted', 'auto-generated');
                 $mail->attach(new Swift_Message_Part($message->getContent(), 'text/plain', 'base64', LANG_CHARSET_CODE));
                 // Send message attachments with watcher
                 if (is_array($mime_attachments)) {
                     foreach ($mime_attachments as $mime_attachment) {
                         $mail->attach($mime_attachment);
                     }
                 }
                 $mailer->send($mail, $rcpt_to, $mail_from);
             }
         }
     } catch (Exception $e) {
         $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);
     }
 }
Example #17
0
 static function calculateTicketSpamProbability($ticket_id, $readonly = false)
 {
     // pull up text of first ticket message
     $messages = DAO_Ticket::getMessagesByTicket($ticket_id);
     $first_message = array_shift($messages);
     $ticket = DAO_Ticket::getTicket($ticket_id);
     if (empty($ticket) || empty($first_message) || !$first_message instanceof CerberusMessage) {
         return FALSE;
     }
     // Pass text to analyze() to get back interesting words
     $content = '';
     if (!empty($ticket->subject)) {
         // SplitCamelCapsSubjects
         $hits = preg_split("{(?<=[a-z])(?=[A-Z])}x", $ticket->subject);
         if (is_array($hits) && !empty($hits)) {
             $content .= implode(' ', $hits);
         }
     }
     $content .= ' ' . $first_message->getContent();
     // Only check the first 15000 characters for spam, rounded to a sentence
     if (strlen($content) > self::MAX_BODY_LENGTH) {
         $content = substr($content, 0, strrpos(substr($content, 0, self::MAX_BODY_LENGTH), ' '));
     }
     $words = self::processText($content);
     $out = self::_calculateSpamProbability($words);
     // Make a word list
     $rawwords = array();
     foreach ($out['words'] as $k => $v) {
         /* @var $v CerberusBayesWord */
         $rawwords[] = $v->word;
     }
     // Cache probability
     if (!$readonly) {
         $fields = array(DAO_Ticket::SPAM_SCORE => $out['probability'], DAO_Ticket::INTERESTING_WORDS => substr(implode(',', array_reverse($rawwords)), 0, 255));
         DAO_Ticket::updateTicket($ticket_id, $fields);
     }
     return $out;
 }
Example #18
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);
 }
Example #19
0
 function showTasksAction()
 {
     $translate = DevblocksPlatform::getTranslationService();
     @($ticket_id = DevblocksPlatform::importGPC($_REQUEST['ticket_id'], 'integer'));
     $tpl = DevblocksPlatform::getTemplateService();
     $tpl->assign('path', $this->_TPL_PATH);
     $ticket = DAO_Ticket::getTicket($ticket_id);
     $tpl->assign('ticket', $ticket);
     $view = C4_AbstractViewLoader::getView('C4_TaskView', 'ticket_tasks');
     $view->id = 'ticket_tasks';
     $view->name = $translate->_('tasks.ticket.tab.view');
     $view->view_columns = array(SearchFields_Task::SOURCE_EXTENSION, SearchFields_Task::DUE_DATE, SearchFields_Task::WORKER_ID);
     $view->params = array(SearchFields_Task::SOURCE_EXTENSION => new DevblocksSearchCriteria(SearchFields_Task::SOURCE_EXTENSION, '=', 'cerberusweb.tasks.ticket'), SearchFields_Task::SOURCE_ID => new DevblocksSearchCriteria(SearchFields_Task::SOURCE_ID, '=', $ticket_id));
     $tpl->assign('view', $view);
     C4_AbstractViewLoader::setView($view->id, $view);
     $tpl->display('file:' . $this->_TPL_PATH . 'display/modules/tasks/index.tpl');
 }
Example #20
0
 private function _postSourceParseAction($path)
 {
     $xml_in = simplexml_load_string($this->getPayload());
     @($source = (string) $xml_in->source);
     if (empty($source)) {
         $this->_error("No message source was provided.");
     }
     //echo("<pre>");print_r($source);echo("</pre>");exit();
     $file = CerberusParser::saveMimeToFile($source);
     $mime = mailparse_msg_parse_file($file);
     $message = CerberusParser::parseMime($mime, $file);
     mailparse_msg_free($mime);
     @unlink($file);
     $ticket_id = CerberusParser::parseMessage($message);
     if (null != ($ticket = DAO_Ticket::getTicket($ticket_id))) {
         // [TODO] Denote if ticket is new or reply?
         $xml_out = new SimpleXMLElement("<ticket></ticket>");
         $xml_out->addChild("id", $ticket_id);
         $xml_out->addChild("mask", $ticket->mask);
         $this->_render($xml_out->asXML());
     } else {
         $this->_error("Message could not be parsed.");
     }
 }
Example #21
0
File: App.php Project: Hildy/cerb5
 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);
     // Find all our matching filters
     if (empty($ticket) || false == ($matches = Model_WatcherMailFilter::getMatches($ticket, $is_inbound ? 'mail_incoming' : 'mail_outgoing'))) {
         return;
     }
     // (Action) Send Notification
     $this->_sendNotifications($matches, $url_writer->write('c=display&mask=' . $ticket->mask, true, false), sprintf("[Ticket] %s", $ticket->subject));
     // (Action) Forward Email To:
     // Sanitize and combine all the destination addresses
     $notify_emails = $this->_getMailingListFromMatches($matches);
     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 = DevblocksPlatform::getPluginSettingsService();
         $reply_to = $settings->get('cerberusweb.core', 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
         if (is_array($notify_emails) && !empty($notify_emails)) {
             $mail_service = DevblocksPlatform::getMailService();
             $mailer = $mail_service->getMailer(CerberusMail::getMailerDefaults());
             foreach ($notify_emails as $to) {
                 // Proxy the message
                 $mail = $mail_service->createMessage();
                 /* @var $mail Swift_Message */
                 $mail->setTo(array($to));
                 $mail->setFrom(array($sender->email));
                 $mail->setReplyTo($reply_to);
                 $mail->setReturnPath($reply_to);
                 $mail->setSubject(sprintf("[%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);
         }
     }
 }
Example #22
0
 function showTab()
 {
     $tpl = DevblocksPlatform::getTemplateService();
     $response = DevblocksPlatform::getHttpResponse();
     $translate = DevblocksPlatform::getTranslationService();
     // are we displaying the main home page?
     $path = $response->path;
     array_shift($path);
     // iphone
     array_shift($path);
     // tickets
     $action = array_shift($path);
     // current action (display)
     $id = array_shift($path);
     // ticket id
     array_shift($path);
     // other
     $sub_tab = array_shift($path);
     // mailhistory
     $page = array_shift($path);
     // page
     $ticket = DAO_Ticket::getTicket($id);
     $defaults = new C4_AbstractViewModel();
     $defaults->class_name = 'View_Ticket_iPhone';
     $defaults->id = 'iphone_opp_contact_history';
     $defaults->name = $translate->_('addy_book.history.view.title');
     $defaults->view_columns = array(SearchFields_Ticket::TICKET_LAST_ACTION_CODE, SearchFields_Ticket::TICKET_CREATED_DATE, SearchFields_Ticket::TICKET_TEAM_ID, SearchFields_Ticket::TICKET_CATEGORY_ID);
     $defaults->renderLimit = 10;
     $defaults->renderSortBy = SearchFields_Ticket::TICKET_CREATED_DATE;
     $defaults->renderSortAsc = false;
     $view = C4_AbstractViewLoader::getView('iphone_opp_contact_history', $defaults);
     $params[SearchFields_Ticket::REQUESTER_ADDRESS] = new DevblocksSearchCriteria(SearchFields_Ticket::REQUESTER_ADDRESS, '=', $address);
     $searchView->params = $params;
     if (isset($page)) {
         $view->renderPage = $page;
     }
     C4_AbstractViewLoader::setView($view->id, $view);
     $uri = "tickets/display/{$id}/other/mailhistory";
     $tpl->assign('uri', $uri);
     $tpl->assign('view', $view);
     $tpl->assign('tickets', $tickets);
     $tpl->display('file:' . $this->_TPL_PATH . 'display/sub_tabs/mailhistory.tpl');
 }