/** * Enter description here... * * @param CerberusParserMessage $message * @return integer */ public static function parseMessage(CerberusParserMessage $message, $options = array()) { /* * options: * 'no_autoreply' */ $logger = DevblocksPlatform::getConsoleLog(); $settings = DevblocksPlatform::getPluginSettingsService(); $helpdesk_senders = CerberusApplication::getHelpdeskSenders(); // Pre-parse mail filters $pre_filters = Model_PreParseRule::getMatches($message); if (is_array($pre_filters) && !empty($pre_filters)) { // Load filter action manifests for reuse $ext_action_mfts = DevblocksPlatform::getExtensions('cerberusweb.mail_filter.action', false); // Loop through all matching filters foreach ($pre_filters as $pre_filter) { // Do something with matching filter's actions foreach ($pre_filter->actions as $action_key => $action) { switch ($action_key) { case 'blackhole': return NULL; break; case 'redirect': @($to = $action['to']); CerberusMail::reflect($message, $to); return NULL; break; case 'bounce': @($msg = $action['message']); @($subject = 'Delivery failed: ' . self::fixQuotePrintableString($message->headers['subject'])); // [TODO] Follow the RFC spec on a true bounce if (null != ($fromAddressInst = CerberusParser::getAddressFromHeaders($message->headers))) { CerberusMail::quickSend($fromAddressInst->email, $subject, $msg); } return NULL; break; default: // Plugin pre-parser filter actions if (isset($ext_action_mfts[$action_key])) { if (null != @($ext_action = $ext_action_mfts[$action_key]->createInstance())) { try { /* @var $ext_action Extension_MailFilterAction */ $ext_action->run($pre_filter, $message); } catch (Exception $e) { } } } break; } } } } $headers =& $message->headers; // From if (null == ($fromAddressInst = CerberusParser::getAddressFromHeaders($headers))) { $logger->err("[Parser] 'From' address could not be created."); return NULL; } // To/Cc/Bcc $to = array(); $sTo = @$headers['to']; $bIsNew = true; if (!empty($sTo)) { // [TODO] Do we still need this RFC address parser? $to = CerberusParser::parseRfcAddress($sTo); } // Subject // Fix quote printable subject (quoted blocks can appear anywhere in subject) $sSubject = ""; if (isset($headers['subject']) && !empty($headers['subject'])) { $sSubject = $headers['subject']; if (is_array($sSubject)) { $sSubject = array_shift($sSubject); } } // The subject can still end up empty after QP decode if (empty($sSubject)) { $sSubject = "(no subject)"; } // Date $iDate = @strtotime($headers['date']); // If blank, or in the future, set to the current date if (empty($iDate) || $iDate > time()) { $iDate = time(); } // Is banned? if (1 == $fromAddressInst->is_banned) { $logger->info("[Parser] Ignoring ticket from banned address: " . $fromAddressInst->email); return NULL; } // Overloadable $enumSpamTraining = ''; // Message Id / References / In-Reply-To @($sMessageId = $headers['message-id']); $body_append_text = array(); $body_append_html = array(); // [mdf]Check attached files before creating the ticket because we may need to overwrite the message-id // also store any contents of rfc822 files so we can include them after the body foreach ($message->files as $filename => $file) { /* @var $file ParserFile */ switch ($file->mime_type) { case 'message/rfc822': $full_filename = $file->tmpname; $mail = mailparse_msg_parse_file($full_filename); $struct = mailparse_msg_get_structure($mail); $msginfo = mailparse_msg_get_part_data($mail); $inline_headers = $msginfo['headers']; if (isset($headers['from']) && (strtolower(substr($headers['from'], 0, 11)) == 'postmaster@' || strtolower(substr($headers['from'], 0, 14)) == 'mailer-daemon@')) { $headers['in-reply-to'] = $inline_headers['message-id']; } break; } } // [JAS] [TODO] References header may contain multiple message-ids to find if (null != ($ids = self::findParentMessage($headers))) { $bIsNew = false; $id = $ids['ticket_id']; $msgid = $ids['message_id']; // Is it a worker reply from an external client? If so, proxy if (null != ($worker_address = DAO_AddressToWorker::getByAddress($fromAddressInst->email))) { $logger->info("[Parser] Handling an external worker response from " . $fromAddressInst->email); if (!DAO_Ticket::isTicketRequester($worker_address->address, $id)) { // Watcher Commands [TODO] Document on wiki/etc if (0 != ($matches = preg_match_all("/\\[(.*?)\\]/i", $message->headers['subject'], $commands))) { @($command = strtolower(array_pop($commands[1]))); $logger->info("[Parser] Worker command: " . $command); switch ($command) { case 'close': DAO_Ticket::updateTicket($id, array(DAO_Ticket::IS_CLOSED => CerberusTicketStatus::CLOSED)); break; case 'take': DAO_Ticket::updateTicket($id, array(DAO_Ticket::NEXT_WORKER_ID => $worker_address->worker_id)); break; case 'comment': $comment_id = DAO_TicketComment::create(array(DAO_TicketComment::ADDRESS_ID => $fromAddressInst->id, DAO_TicketComment::CREATED => time(), DAO_TicketComment::TICKET_ID => $id, DAO_TicketComment::COMMENT => $message->body)); return $id; break; default: // Typo? break; } } $attachment_files = array(); $attachment_files['name'] = array(); $attachment_files['type'] = array(); $attachment_files['tmp_name'] = array(); $attachment_files['size'] = array(); $i = 0; foreach ($message->files as $filename => $file) { $attachment_files['name'][$i] = $filename; $attachment_files['type'][$i] = $file->mime_type; $attachment_files['tmp_name'][$i] = $file->tmpname; $attachment_files['size'][$i] = $file->file_size; $i++; } CerberusMail::sendTicketMessage(array('message_id' => $msgid, 'content' => $message->body, 'files' => $attachment_files, 'agent_id' => $worker_address->worker_id)); return $id; } else { // ... worker is a requester, treat as normal $logger->info("[Parser] The external worker was a ticket requester, so we're not treating them as a watcher."); } } else { // Reply: Not sent by a worker /* * [TODO] check that this sender is a requester on the matched ticket * Otherwise blank out the $id */ } } $group_id = 0; if (empty($id)) { // New Ticket $sMask = CerberusApplication::generateTicketMask(); $groups = DAO_Group::getAll(); // Routing new tickets if (null != ($routing_rules = Model_MailToGroupRule::getMatches($fromAddressInst, $message))) { if (is_array($routing_rules)) { foreach ($routing_rules as $rule) { // Only end up with the last 'move' action (ignore the previous) if (isset($rule->actions['move'])) { $group_id = intval($rule->actions['move']['group_id']); // We don't need to move again when running rule actions unset($rule->actions['move']); } } } } // Make sure the group exists if (!isset($groups[$group_id])) { $group_id = null; } // Last ditch effort to check for a default group to deliver to if (empty($group_id)) { if (null != ($default_team = DAO_Group::getDefaultGroup())) { $group_id = $default_team->id; } else { // Bounce return null; } } // [JAS] It's important to not set the group_id on the ticket until the messages exist // or inbox filters will just abort. $fields = array(DAO_Ticket::MASK => $sMask, DAO_Ticket::SUBJECT => $sSubject, DAO_Ticket::IS_CLOSED => 0, DAO_Ticket::FIRST_WROTE_ID => intval($fromAddressInst->id), DAO_Ticket::LAST_WROTE_ID => intval($fromAddressInst->id), DAO_Ticket::CREATED_DATE => $iDate, DAO_Ticket::UPDATED_DATE => $iDate, DAO_Ticket::LAST_ACTION_CODE => CerberusTicketActionCode::TICKET_OPENED); $id = DAO_Ticket::createTicket($fields); // Apply routing actions to our new ticket ID if (isset($routing_rules) && is_array($routing_rules)) { foreach ($routing_rules as $rule) { $rule->run($id); } } } // [JAS]: Add requesters to the ticket if (!empty($fromAddressInst->id) && !empty($id)) { // Don't add a requester if the sender is a helpdesk address if (isset($helpdesk_senders[$fromAddressInst->email])) { $logger->info("[Parser] Not adding ourselves as a requester: " . $fromAddressInst->email); } else { DAO_Ticket::createRequester($fromAddressInst->id, $id); } } // Add the other TO/CC addresses to the ticket // [TODO] This should be cleaned up and optimized if ($settings->get('cerberusweb.core', CerberusSettings::PARSER_AUTO_REQ, 0)) { @($autoreq_exclude_list = $settings->get('cerberusweb.core', CerberusSettings::PARSER_AUTO_REQ_EXCLUDE, '')); $destinations = self::getDestinations($headers); if (is_array($destinations) && !empty($destinations)) { // Filter out any excluded requesters if (!empty($autoreq_exclude_list)) { @($autoreq_exclude = DevblocksPlatform::parseCrlfString($autoreq_exclude_list)); if (is_array($autoreq_exclude) && !empty($autoreq_exclude)) { foreach ($autoreq_exclude as $excl_pattern) { $excl_regexp = DevblocksPlatform::parseStringAsRegExp($excl_pattern); // Check all destinations for this pattern foreach ($destinations as $idx => $dest) { if (@preg_match($excl_regexp, $dest)) { unset($destinations[$idx]); } } } } } foreach ($destinations as $dest) { if (null != ($destInst = CerberusApplication::hashLookupAddress($dest, true))) { // Skip if the destination is one of our senders or the matching TO if (isset($helpdesk_senders[$destInst->email])) { continue; } DAO_Ticket::createRequester($destInst->id, $id); } } } } $attachment_path = APP_STORAGE_PATH . '/attachments/'; // [TODO] This should allow external attachments (S3) $fields = array(DAO_Message::TICKET_ID => $id, DAO_Message::CREATED_DATE => $iDate, DAO_Message::ADDRESS_ID => $fromAddressInst->id); $email_id = DAO_Message::create($fields); // Content DAO_MessageContent::create($email_id, $message->body); // Headers foreach ($headers as $hk => $hv) { DAO_MessageHeader::create($email_id, $hk, $hv); } // [mdf] Loop through files to insert attachment records in the db, and move temporary files if (!empty($email_id)) { foreach ($message->files as $filename => $file) { /* @var $file ParserFile */ //[mdf] skip rfc822 messages since we extracted their content above if ($file->mime_type == 'message/rfc822') { continue; } $fields = array(DAO_Attachment::MESSAGE_ID => $email_id, DAO_Attachment::DISPLAY_NAME => $filename, DAO_Attachment::MIME_TYPE => $file->mime_type, DAO_Attachment::FILE_SIZE => intval($file->file_size)); $file_id = DAO_Attachment::create($fields); if (empty($file_id)) { @unlink($file->tmpname); // remove our temp file continue; } // Make file attachments use buckets so we have a max per directory $attachment_bucket = sprintf("%03d/", mt_rand(1, 100)); $attachment_file = $file_id; if (!file_exists($attachment_path . $attachment_bucket)) { @mkdir($attachment_path . $attachment_bucket, 0770, true); // [TODO] Needs error checking } rename($file->getTempFile(), $attachment_path . $attachment_bucket . $attachment_file); // [TODO] Split off attachments into its own DAO DAO_Attachment::update($file_id, array(DAO_Attachment::FILEPATH => $attachment_bucket . $attachment_file)); } } // Pre-load custom fields if (isset($message->custom_fields) && !empty($message->custom_fields)) { foreach ($message->custom_fields as $cf_id => $cf_val) { if (is_array($cf_val) && !empty($cf_val) || !is_array($cf_val) && 0 != strlen($cf_val)) { DAO_CustomFieldValue::setFieldValue('cerberusweb.fields.source.ticket', $id, $cf_id, $cf_val); } } } // Finalize our new ticket details (post-message creation) if ($bIsNew && !empty($id) && !empty($email_id)) { // First thread (needed for anti-spam) DAO_Ticket::updateTicket($id, array(DAO_Ticket::FIRST_MESSAGE_ID => $email_id)); // Prime the change fields (which a few things like anti-spam might change before we commit) $change_fields = array(DAO_Ticket::TEAM_ID => $group_id); $out = CerberusBayes::calculateTicketSpamProbability($id); if (!empty($group_id)) { @($spam_threshold = DAO_GroupSettings::get($group_id, DAO_GroupSettings::SETTING_SPAM_THRESHOLD, 80)); @($spam_action = DAO_GroupSettings::get($group_id, DAO_GroupSettings::SETTING_SPAM_ACTION, '')); @($spam_action_param = DAO_GroupSettings::get($group_id, DAO_GroupSettings::SETTING_SPAM_ACTION_PARAM, '')); if ($out['probability'] * 100 >= $spam_threshold) { $enumSpamTraining = CerberusTicketSpamTraining::SPAM; switch ($spam_action) { default: case 0: // do nothing break; case 1: // delete $change_fields[DAO_Ticket::IS_CLOSED] = 1; $change_fields[DAO_Ticket::IS_DELETED] = 1; break; case 2: // move $buckets = DAO_Bucket::getAll(); // Verify bucket exists if (!empty($spam_action_param) && isset($buckets[$spam_action_param])) { $change_fields[DAO_Ticket::TEAM_ID] = $group_id; $change_fields[DAO_Ticket::CATEGORY_ID] = $spam_action_param; } break; } } } // end spam training // Save properties if (!empty($change_fields)) { DAO_Ticket::updateTicket($id, $change_fields); } } // Reply notifications (new messages are handled by 'move' listener) if (!$bIsNew) { // Inbound Reply Event $eventMgr = DevblocksPlatform::getEventService(); $eventMgr->trigger(new Model_DevblocksEvent('ticket.reply.inbound', array('ticket_id' => $id))); } // New ticket processing if ($bIsNew) { // Auto reply @($autoreply_enabled = DAO_GroupSettings::get($group_id, DAO_GroupSettings::SETTING_AUTO_REPLY_ENABLED, 0)); @($autoreply = DAO_GroupSettings::get($group_id, DAO_GroupSettings::SETTING_AUTO_REPLY, '')); /* * Send the group's autoreply if one exists, as long as this ticket isn't spam */ if (!isset($options['no_autoreply']) && $autoreply_enabled && !empty($autoreply) && $enumSpamTraining != CerberusTicketSpamTraining::SPAM) { CerberusMail::sendTicketMessage(array('ticket_id' => $id, 'message_id' => $email_id, 'content' => str_replace(array('#ticket_id#', '#mask#', '#subject#', '#timestamp#', '#sender#', '#sender_first#', '#orig_body#'), array($id, $sMask, $sSubject, date('r'), $fromAddressInst->email, $fromAddressInst->first_name, ltrim($message->body)), $autoreply), 'is_autoreply' => true, 'dont_keep_copy' => true)); } } // end bIsNew unset($message); // Re-open and update our date on new replies if (!$bIsNew) { DAO_Ticket::updateTicket($id, array(DAO_Ticket::UPDATED_DATE => time(), DAO_Ticket::IS_WAITING => 0, DAO_Ticket::IS_CLOSED => 0, DAO_Ticket::IS_DELETED => 0, DAO_Ticket::LAST_WROTE_ID => $fromAddressInst->id, DAO_Ticket::LAST_ACTION_CODE => CerberusTicketActionCode::TICKET_CUSTOMER_REPLY)); // [TODO] The TICKET_CUSTOMER_REPLY should be sure of this message address not being a worker } @imap_errors(); // Prevent errors from spilling out into STDOUT return $id; }
function _parseFile($full_filename) { $logger = DevblocksPlatform::getConsoleLog(); $fileparts = pathinfo($full_filename); $logger->info("[Parser] Reading " . $fileparts['basename'] . "..."); $time = microtime(true); $mime = mailparse_msg_parse_file($full_filename); $message = CerberusParser::parseMime($mime, $full_filename); $time = microtime(true) - $time; $logger->info("[Parser] Decoded! (" . sprintf("%d", $time * 1000) . " ms)"); // echo "<b>Plaintext:</b> ", $message->body,"<BR>"; // echo "<BR>"; // echo "<b>HTML:</b> ", htmlspecialchars($message->htmlbody), "<BR>"; // echo "<BR>"; // echo "<b>Files:</b> "; print_r($message->files); echo "<BR>"; // echo "<HR>"; $time = microtime(true); $ticket_id = CerberusParser::parseMessage($message); $time = microtime(true) - $time; $logger->info("[Parser] Parsed! (" . sprintf("%d", $time * 1000) . " ms) " . (!empty($ticket_id) ? "(Ticket ID: " . $ticket_id . ")" : "(Local Delivery Rejected.)")); @unlink($full_filename); mailparse_msg_free($mime); // flush(); }
private function _postSourceQueueAction($path) { $xml_in = simplexml_load_string($this->getPayload()); @($source = (string) $xml_in->source); if (empty($source)) { $this->_error("No message source was provided."); } // Queue up in the new mail directory $path = APP_MAIL_PATH . DIRECTORY_SEPARATOR . 'new'; $file = CerberusParser::saveMimeToFile($source, $path); $out_xml = new SimpleXMLElement('<success></success>'); $this->_render($out_xml->asXML()); }
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'))); }
function generateTicketsAction() { require_once dirname(__FILE__) . '/api/API.class.php'; $tpl = DevblocksPlatform::getTemplateService(); $tpl_path = dirname(__FILE__) . '/templates/'; $tpl->assign('path', $tpl_path); @($address = DevblocksPlatform::importGPC($_POST['address'], 'string')); @($dataset = DevblocksPlatform::importGPC($_POST['dataset'], 'string')); @($how_many = DevblocksPlatform::importGPC($_POST['how_many'], 'integer', 0)); if (empty($address)) { $tpl->assign('error', sprintf("Oops! '%s' is not a valid e-mail address.", htmlspecialchars($address))); $tpl->display('file:' . $tpl_path . 'config_tab/output.tpl'); return; } // [JAS]: [TODO] This should probably move to an extension point later switch ($dataset) { default: case "retail": $dataset = new RetailDataset(); break; case "hosting": $dataset = new HostingDataset(); break; case "edu": $dataset = new EduDataset(); break; case "gov": $dataset = new GovDataset(); break; case "npo": $dataset = new NPODataset(); break; case "spam": $dataset = new SpamDataset(); break; } $simulator = CerberusSimulator::getInstance(); $emails = $simulator->generateEmails($dataset, $how_many); foreach ($emails as $template) { if (preg_match("/\"(.*?)\" \\<(.*?)\\>/", $template['sender'], $matches)) { $personal = $matches[1]; $from = $matches[1]; } // [TODO] error checking $message = new CerberusParserMessage(); $message->headers['from'] = $template['sender']; $message->headers['to'] = $address; $message->headers['subject'] = $template['subject']; $message->headers['message-id'] = CerberusApplication::generateMessageId(); $message->body = sprintf("%s\r\n" . "\r\n" . "--\r\n%s\r\n", $template['body'], $personal); CerberusParser::parseMessage($message, array('no_autoreply' => true)); } $tpl->assign('output', sprintf("Success! %d simulated tickets were generated for %s", $how_many, htmlspecialchars($address))); $tpl->display('file:' . $tpl_path . 'config_tab/output.tpl'); }
/** * Returns a Model_PreParserRule on a match, or NULL * * @param boolean $is_new * @param string $from * @param string $to * @param CerberusParserMessage $message * @return Model_PreParserRule[] */ static function getMatches(CerberusParserMessage $message) { $filters = DAO_PreParseRule::getAll(); $headers = $message->headers; // New or reply? $is_new = isset($message->headers['in-reply-to']) || isset($message->headers['references']) ? false : true; // From address $fromInst = CerberusParser::getAddressFromHeaders($headers); // Stackable $matches = array(); // Custom fields $custom_fields = DAO_CustomField::getAll(); // Criteria extensions $filter_criteria_exts = DevblocksPlatform::getExtensions('cerberusweb.mail_filter.criteria', false); // Lazy load when needed on criteria basis $address_field_values = null; $org_field_values = null; // check filters if (is_array($filters)) { foreach ($filters as $filter) { $passed = 0; // check criteria foreach ($filter->criteria as $rule_key => $rule) { @($value = $rule['value']); switch ($rule_key) { case 'dayofweek': $current_day = strftime('%w'); // $current_day = 1; // Forced to English abbrevs as indexes $days = array('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'); // Is the current day enabled? if (isset($rule[$days[$current_day]])) { $passed++; } break; case 'timeofday': $current_hour = strftime('%H'); $current_min = strftime('%M'); // $current_hour = 17; // $current_min = 5; if (null != ($from_time = @$rule['from'])) { list($from_hour, $from_min) = explode(':', $from_time); } if (null != ($to_time = @$rule['to'])) { if (list($to_hour, $to_min) = explode(':', $to_time)) { } } // Do we need to wrap around to the next day's hours? if ($from_hour > $to_hour) { // yes $to_hour += 24; // add 24 hrs to the destination (1am = 25th hour) } // Are we in the right 24 hourly range? if ((int) $current_hour >= $from_hour && (int) $current_hour <= $to_hour) { // If we're in the first hour, are we minutes early? if ($current_hour == $from_hour && (int) $current_min < $from_min) { break; } // If we're in the last hour, are we minutes late? if ($current_hour == $to_hour && (int) $current_min > $to_min) { break; } $passed++; } break; case 'type': if ($is_new && 0 == strcasecmp($value, 'new') || !$is_new && 0 == strcasecmp($value, 'reply')) { $passed++; } break; case 'from': $regexp_from = DevblocksPlatform::strToRegExp($value); if (preg_match($regexp_from, $fromInst->email)) { $passed++; } break; case 'tocc': $tocc = array(); $destinations = DevblocksPlatform::parseCsvString($value); // Build a list of To/Cc addresses on this message @($to_list = imap_rfc822_parse_adrlist($headers['to'], 'localhost')); @($cc_list = imap_rfc822_parse_adrlist($headers['cc'], 'localhost')); if (is_array($to_list)) { foreach ($to_list as $addy) { $tocc[] = $addy->mailbox . '@' . $addy->host; } } if (is_array($cc_list)) { foreach ($cc_list as $addy) { $tocc[] = $addy->mailbox . '@' . $addy->host; } } $dest_flag = false; // bail out when true if (is_array($destinations) && is_array($tocc)) { foreach ($destinations as $dest) { if ($dest_flag) { break; } $regexp_dest = DevblocksPlatform::strToRegExp($dest); foreach ($tocc as $addy) { if (@preg_match($regexp_dest, $addy)) { $passed++; $dest_flag = false; break; } } } } break; case 'header1': case 'header2': case 'header3': case 'header4': case 'header5': $header = strtolower($rule['header']); if (empty($value)) { // we're checking for null/blanks if (!isset($headers[$header]) || empty($headers[$header])) { $passed++; } } elseif (isset($headers[$header]) && !empty($headers[$header])) { $regexp_header = DevblocksPlatform::strToRegExp($value); // handle arrays like Received: and (broken)Content-Type headers (farking spammers) if (is_array($headers[$header])) { foreach ($headers[$header] as $array_header) { if (preg_match($regexp_header, str_replace(array("\r", "\n"), ' ', $array_header))) { $passed++; break; } } } else { // Flatten CRLF if (preg_match($regexp_header, str_replace(array("\r", "\n"), ' ', $headers[$header]))) { $passed++; } } } break; case 'body': // Line-by-line body scanning (sed-like) $lines = preg_split("/[\r\n]/", $message->body); if (is_array($lines)) { foreach ($lines as $line) { if (@preg_match($value, $line)) { $passed++; break; } } } break; case 'body_encoding': $regexp_bodyenc = DevblocksPlatform::strToRegExp($value); if (preg_match($regexp_bodyenc, $message->body_encoding)) { $passed++; } break; case 'attachment': $regexp_file = DevblocksPlatform::strToRegExp($value); // check the files in the raw message foreach ($message->files as $file_name => $file) { /* @var $file ParserFile */ if (preg_match($regexp_file, $file_name)) { $passed++; break; } } break; default: // ignore invalids // Custom Fields if (0 == strcasecmp('cf_', substr($rule_key, 0, 3))) { $field_id = substr($rule_key, 3); // Make sure it exists if (null == @($field = $custom_fields[$field_id])) { continue; } // Lazy values loader $field_values = array(); switch ($field->source_extension) { case ChCustomFieldSource_Address::ID: if (null == $address_field_values) { $address_field_values = array_shift(DAO_CustomFieldValue::getValuesBySourceIds(ChCustomFieldSource_Address::ID, $fromInst->id)); } $field_values =& $address_field_values; break; case ChCustomFieldSource_Org::ID: if (null == $org_field_values) { $org_field_values = array_shift(DAO_CustomFieldValue::getValuesBySourceIds(ChCustomFieldSource_Org::ID, $fromInst->contact_org_id)); } $field_values =& $org_field_values; break; } // Type sensitive value comparisons // [TODO] Operators // [TODO] Highly redundant switch ($field->type) { case 'S': // string // string case 'T': // clob // clob case 'U': // URL $field_val = isset($field_values[$field_id]) ? $field_values[$field_id] : ''; $oper = isset($rule['oper']) ? $rule['oper'] : "="; if ($oper == "=" && @preg_match(DevblocksPlatform::strToRegExp($value, true), $field_val)) { $passed++; } elseif ($oper == "!=" && @(!preg_match(DevblocksPlatform::strToRegExp($value, true), $field_val))) { $passed++; } break; case 'N': // number if (!isset($field_values[$field_id])) { break; } $field_val = isset($field_values[$field_id]) ? $field_values[$field_id] : 0; $oper = isset($rule['oper']) ? $rule['oper'] : "="; if ($oper == "=" && intval($field_val) == intval($value)) { $passed++; } elseif ($oper == "!=" && intval($field_val) != intval($value)) { $passed++; } elseif ($oper == ">" && intval($field_val) > intval($value)) { $passed++; } elseif ($oper == "<" && intval($field_val) < intval($value)) { $passed++; } break; case 'E': // date $field_val = isset($field_values[$field_id]) ? intval($field_values[$field_id]) : 0; $from = isset($rule['from']) ? $rule['from'] : "0"; $to = isset($rule['to']) ? $rule['to'] : "now"; if (intval(@strtotime($from)) <= $field_val && intval(@strtotime($to)) >= $field_val) { $passed++; } break; case 'C': // checkbox $field_val = isset($field_values[$field_id]) ? $field_values[$field_id] : 0; if (intval($value) == intval($field_val)) { $passed++; } break; case 'D': // dropdown // dropdown case 'M': // multi-picklist // multi-picklist case 'X': // multi-checkbox // multi-checkbox case 'W': // worker $field_val = isset($field_values[$field_id]) ? $field_values[$field_id] : array(); if (!is_array($value)) { $value = array($value); } if (is_array($field_val)) { // if multiple things set foreach ($field_val as $v) { // loop through possible if (isset($value[$v])) { // is any possible set? $passed++; break; } } } else { // single if (isset($value[$field_val])) { // is our set field in possibles? $passed++; break; } } break; } } elseif (isset($filter_criteria_exts[$rule_key])) { // criteria extensions try { $crit_ext = $filter_criteria_exts[$rule_key]->createInstance(); if ($crit_ext->matches($filter, $message)) { $passed++; break; } } catch (Exception $e) { // Oops! //print_r($e); } } break; } } // If our rule matched every criteria, stop and return the filter if ($passed == count($filter->criteria)) { DAO_PreParseRule::increment($filter->id); // ++ the times we've matched $matches[] = $filter; // Check our actions and see if we should bail out early if (isset($filter->actions) && !empty($filter->actions)) { foreach ($filter->actions as $action_key => $action) { switch ($action_key) { case 'nothing': case 'blackhole': case 'redirect': case 'bounce': return $matches; break; } } } } } } return $matches; }
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'))); }
If these default groups don't meet your needs, feel free to change them by clicking 'Helpdesk Setup' in the top-right and selecting the 'Groups' tab. We also set up a 'Spam' bucket inside each group to start quarantining junk mail. Your helpdesk's spam training functionality is adaptive and will become increasingly accurate as you use your helpdesk. If you have any questions about your new helpdesk, simply reply to this message. Our response will show up on this page as a new message. Subscribe to the Cerb4 blog for project news, sneak peeks of development progress, tips & tricks, and more: http://www.cerb4.com/blog/ Thanks for your interest! --- The Cerb4 Team WebGroup Media, LLC. http://www.cerberusweb.com/ EOF; CerberusParser::parseMessage($message); } $tpl->assign('step', STEP_REGISTER); $tpl->display('steps/redirect.tpl'); exit; } else { $tpl->assign('failed', true); } } else { // Defaults } $tpl->assign('template', 'steps/step_defaults.tpl'); break; case STEP_REGISTER: @($form_submit = DevblocksPlatform::importGPC($_POST['form_submit'], 'integer')); @($skip = DevblocksPlatform::importGPC($_POST['skip'], 'integer', 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))); } }
function doReplyAction() { @($mask = DevblocksPlatform::importGPC($_REQUEST['mask'], 'string', '')); @($content = DevblocksPlatform::importGPC($_REQUEST['content'], 'string', '')); $umsession = UmPortalHelper::getSession(); $active_user = $umsession->getProperty('sc_login', null); // Secure retrieval (address + mask) list($tickets) = DAO_Ticket::search(array(), array(new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_MASK, '=', $mask), new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_FIRST_WROTE_ID, '=', $active_user->id)), 1, 0, null, null, false); $ticket = array_shift($tickets); $messages = DAO_Ticket::getMessagesByTicket($ticket[SearchFields_Ticket::TICKET_ID]); $last_message = array_pop($messages); /* @var $last_message CerberusMessage */ $last_message_headers = $last_message->getHeaders(); unset($messages); // Helpdesk settings $settings = CerberusSettings::getInstance(); $global_from = $settings->get(CerberusSettings::DEFAULT_REPLY_FROM, null); // Ticket group settings $group_id = $ticket[SearchFields_Ticket::TICKET_TEAM_ID]; @($group_from = DAO_GroupSettings::get($group_id, DAO_GroupSettings::SETTING_REPLY_FROM, '')); // Headers $to = !empty($group_from) ? $group_from : $global_from; @($in_reply_to = $last_message_headers['message-id']); @($message_id = CerberusApplication::generateMessageId()); $message = new CerberusParserMessage(); $message->headers['from'] = $active_user->email; $message->headers['to'] = $to; $message->headers['date'] = gmdate('r'); $message->headers['subject'] = 'Re: ' . $ticket[SearchFields_Ticket::TICKET_SUBJECT]; $message->headers['message-id'] = $message_id; $message->headers['in-reply-to'] = $in_reply_to; $message->body = sprintf("%s", $content); CerberusParser::parseMessage($message, array('no_autoreply' => true)); DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('portal', UmPortalHelper::getCode(), 'history', $ticket[SearchFields_Ticket::TICKET_MASK]))); }
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'))); }
function AnswernetMetlifeReportGroupReport1Action() { $db = DevblocksPlatform::getDatabaseService(); $translate = DevblocksPlatform::getTranslationService(); $url = DevblocksPlatform::getUrlService(); $workers = DAO_Worker::getAll(); $radius = 12; // Security if (null == ($active_worker = CerberusApplication::getActiveWorker())) { die($translate->_('common.access_denied')); } // import dates from form @($start_time = DevblocksPlatform::importGPC($_REQUEST['start'], 'string', '')); @($group = DevblocksPlatform::importGPC($_REQUEST['group'], 'string', '')); if (empty($start_time) || !is_numeric($start_time)) { return; } if (empty($group)) { return; } $end_time = $start_time + 604800; print $translate->_('answernet.er.metlife.week.number'); print date("W", $start_time); print '<br>'; print $translate->_('answernet.er.metlife.generate.report'); switch ($group) { case "All": $filename = "report-metlife-week-" . date("W", $start_time) . ".xls"; $group_sql = "and (t.team_id = 756 or t.team_id = 782) "; print " Group: ALL "; $group_text = "All"; break; case "fp": $filename = "report-metlife-first-person-week-" . date("W", $start_time) . ".xls"; $group_sql = "and t.team_id = 756 "; print " Group: First Person "; $group_text = "First Person"; break; case "iDesign": $filename = "report-metlife-iDesign-week-" . date("W", $start_time) . ".xls"; $group_sql = "and team_id = 782 "; print " Group: iDesign "; $group_text = "iDesign"; break; default: print "Error: Group not set: " . $group; return; } print '<br>'; print $translate->_('answernet.er.metlife.generating'); $full_filename = getcwd() . '/storage/answernet/' . $filename; $href_filename = $url->write('storage/answernet/' . $filename, true); $week_range_text = "Week # " . date("W - n/j/y", $start_time) . " - " . date("n/j/y", $start_time + 518400); // Create new Excel Spreadsheet. $workbook = new Spreadsheet_Excel_Writer($full_filename); // Create metrics Tab and set Column Width and Row Hight. $worksheet_metrics =& $workbook->addWorksheet('Weekly Metrics'); $worksheet_metrics->setColumn(0, 0, $radius * 1.71); $worksheet_metrics->setColumn(0, 0, $radius * 0.5); $worksheet_metrics->setRow(0, 56); // Create ACD Calls(Inbound) Tab and set Column Width and Row Hight. $worksheet_acd_in =& $workbook->addWorksheet('ACD calls(Inbound)'); $worksheet_acd_in->setColumn(0, 1, $radius * 0.78); $worksheet_acd_in->setColumn(2, 2, $radius * 1.05); $worksheet_acd_in->setColumn(3, 3, $radius * 1.23); $worksheet_acd_in->setColumn(4, 4, $radius * 1.11); $worksheet_acd_in->setColumn(5, 5, $radius * 1.15); $worksheet_acd_in->setColumn(6, 6, $radius * 2.0); $worksheet_acd_in->setColumn(7, 7, $radius * 0.78); $worksheet_acd_in->setColumn(8, 8, $radius * 2.0); $worksheet_acd_in->setColumn(9, 9, $radius * 0.78); $worksheet_acd_in->setRow(0, 28); $worksheet_acd_in->setRow(2, 32); // Create ACD Calls(Outbound) Tab and set Column Width and Row Hight. $worksheet_acd_out =& $workbook->addWorksheet('ACD calls(Outbound)'); // Create Phone Tickets Tab and set Column Width and Row Hight. $worksheet_phone_tickets =& $workbook->addWorksheet('Phone Tickets'); // Create Email Tickets Tab and set Column Width and Row Hight. $worksheet_email_tickets =& $workbook->addWorksheet('Email Tickets'); // Create Email Tickets Tab and set Column Width and Row Hight. $worksheet_call_count =& $workbook->addWorksheet('Call Count'); // Create Inbound Count Tab and set Column Width and Row Hight. $worksheet_in_count =& $workbook->addWorksheet('Inbound Email Count'); $worksheet_in_count->setColumn(0, 0, $radius * 2.87); $worksheet_in_count->setColumn(1, 1, $radius * 0.66); $worksheet_in_count->setColumn(2, 2, $radius * 2.87); $worksheet_in_count->setColumn(3, 3, $radius * 0.62); $worksheet_in_count->setColumn(4, 4, $radius * 0.66); $worksheet_in_count->setColumn(5, 5, $radius * 2.87); $worksheet_in_count->setColumn(6, 6, $radius * 0.66); $worksheet_in_count->setRow(0, 32); $worksheet_in_count->freezePanes(array(2, 0, 2, 0)); // Create Outbound Count Tab and set Column Width and Row Hight. $worksheet_out_count =& $workbook->addWorksheet('Outbound Email Count'); $worksheet_out_count->setColumn(0, 0, $radius * 2.87); $worksheet_out_count->setColumn(1, 1, $radius * 0.66); $worksheet_out_count->setColumn(2, 2, $radius * 2.87); $worksheet_out_count->setColumn(3, 3, $radius * 0.62); $worksheet_out_count->setColumn(4, 4, $radius * 0.66); $worksheet_out_count->setColumn(5, 5, $radius * 2.87); $worksheet_out_count->setColumn(6, 6, $radius * 0.66); $worksheet_out_count->setRow(0, 32); $worksheet_out_count->freezePanes(array(2, 0, 2, 0)); // Create Inbound Tab and set Column Width and Row Hight. $worksheet_inbound =& $workbook->addWorksheet('Inbound Emails'); $worksheet_inbound->setColumn(0, 0, $radius * 2.78); $worksheet_inbound->setColumn(1, 1, $radius * 1.55); $worksheet_inbound->setColumn(2, 2, $radius * 0.72); $worksheet_inbound->setColumn(3, 4, $radius * 1.51); $worksheet_inbound->setColumn(5, 5, $radius * 2.76); $worksheet_inbound->setColumn(6, 9, $radius * 2.22); $worksheet_inbound->setColumn(10, 10, $radius * 0.83); $worksheet_inbound->setRow(0, 36); $worksheet_inbound->freezePanes(array(2, 0, 2, 0)); // Create Outbound Tab and set Column Width and Row Hight. $worksheet_outbound =& $workbook->addWorksheet('Outbound Emails'); $worksheet_outbound->setColumn(0, 0, $radius * 2.78); $worksheet_outbound->setColumn(1, 1, $radius * 1.55); $worksheet_outbound->setColumn(2, 2, $radius * 0.72); $worksheet_outbound->setColumn(3, 4, $radius * 1.51); $worksheet_outbound->setColumn(5, 5, $radius * 2.76); $worksheet_outbound->setColumn(6, 9, $radius * 2.22); $worksheet_outbound->setColumn(10, 10, $radius * 1.2); $worksheet_outbound->setColumn(11, 11, $radius * 0.83); $worksheet_outbound->setRow(0, 36); $worksheet_outbound->freezePanes(array(2, 0, 2, 0)); // Formats used thoughout the workbook. $format_general =& $workbook->addFormat(); $format_general->setBorder(1); $format_general->setHAlign('center'); $format_general->setTextWrap(); $format_general_nowrap =& $workbook->addFormat(); $format_general_nowrap->setBorder(1); // Setup templating for the formating of certain cells in the Metics Group. $format_metrics_title =& $workbook->addFormat(); $format_metrics_title->setBorder(1); $format_metrics_title->setBold(); $format_metrics_title->setColor(9); $format_metrics_title->setFgColor(32); $format_metrics_title->setHAlign('center'); $format_metrics_title->setVAlign('vjustify'); $format_metrics_title->setVAlign('vcenter'); $format_metrics_title->setTextWrap(); $format_metrics_title2 =& $workbook->addFormat(); $format_metrics_title2->setBorder(1); $format_metrics_title2->setBold(); $format_metrics_title2->setColor(8); $format_metrics_title2->setFgColor(43); $format_metrics_title2->setHAlign('center'); $format_metrics_title2->setVAlign('vjustify'); $format_metrics_title2->setVAlign('vcenter'); $format_metrics_title2->setTextWrap(); $format_metrics_weekly =& $workbook->addFormat(); $format_metrics_weekly->setBorder(1); $format_metrics_weekly->setBold(); $format_metrics_weekly->setColor(8); $format_metrics_weekly->setFgColor(29); $format_metrics_weekly->setHAlign('center'); $format_metrics_weekly->setVAlign('vjustify'); $format_metrics_weekly->setVAlign('vcenter'); $format_metrics_weekly->setTextWrap(); $format_metrics_daily =& $workbook->addFormat(); $format_metrics_daily->setBorder(1); $format_metrics_daily->setBold(); $format_metrics_daily->setColor(8); $format_metrics_daily->setFgColor(29); $format_metrics_daily->setHAlign('center'); $format_metrics_daily->setVAlign('vjustify'); $format_metrics_daily->setVAlign('vcenter'); $format_metrics_daily->setTextWrap(); // Added headers since they never change in the Metics Group. $worksheet_metrics->write(0, 0, 'Week Range', $format_metrics_title); $worksheet_metrics->write(0, 1, 'Inbnd Field Emails', $format_metrics_title); $worksheet_metrics->write(0, 2, 'Inbnd Admin Emails', $format_metrics_title); $worksheet_metrics->write(0, 3, 'Weekly Total Inbnd', $format_metrics_title); $worksheet_metrics->write(0, 4, 'Outbnd Field Emails', $format_metrics_title); $worksheet_metrics->write(0, 5, 'Outbnd Admin Emails', $format_metrics_title); $worksheet_metrics->write(0, 6, 'Weekly Total Outbnd', $format_metrics_title); $worksheet_metrics->write(0, 7, 'Avg time to respond (hrs)', $format_metrics_title); $worksheet_metrics->write(0, 8, ' ', $format_metrics_title2); $worksheet_metrics->write(0, 9, ' ', $format_metrics_title2); $worksheet_metrics->write(0, 10, ' ', $format_metrics_title2); $worksheet_metrics->write(0, 11, ' ', $format_metrics_title2); $worksheet_metrics->write(0, 12, ' ', $format_metrics_title2); $worksheet_metrics->write(0, 13, ' ', $format_metrics_title2); $worksheet_metrics->write(0, 14, ' ', $format_metrics_title2); $week_range_text_metrics = date("n/j/y", $start_time) . " - " . date("n/j/y", $start_time + 518400); $worksheet_metrics->write(1, 0, $week_range_text_metrics, $format_general); $worksheet_metrics->write(5, 0, 'Grand Total', $format_general); $worksheet_metrics->write(6, 0, 'Weekly Averages', $format_metrics_weekly); $worksheet_metrics->write(7, 0, 'Daily Averages', $format_metrics_daily); $worksheet_metrics->write(8, 0, '%', $format_general); // Setup templating for the formating of certain cells in the Inbound Count Group. $format_acd_in_title =& $workbook->addFormat(); $format_acd_in_title->setSize(18); $format_acd_in_title->setColor(8); $format_acd_in_title->setFgColor(34); $format_acd_in_title->setBorder(1); $format_acd_in_title->setBold(); $format_acd_in_title->setHAlign('center'); $format_acd_in_title->setVAlign('vjustify'); $format_acd_in_title->setVAlign('top'); $format_acd_in_title->setTextWrap(); $format_acd_in_title->setAlign('merge'); $format_acd_in_title2 =& $workbook->addFormat(); $format_acd_in_title2->setColor(8); $format_acd_in_title2->setFgColor(43); $format_acd_in_title2->setBorder(1); $format_acd_in_title2->setBold(); $format_acd_in_title2->setHAlign('center'); $format_acd_in_title2->setVAlign('vjustify'); $format_acd_in_title2->setVAlign('top'); $format_acd_in_title2->setTextWrap(); $format_acd_in_title2->setAlign('merge'); $format_acd_in_title3 =& $workbook->addFormat(); $format_acd_in_title3->setColor(8); $format_acd_in_title3->setFgColor(47); $format_acd_in_title2->setBorder(1); $format_acd_in_title3->setBold(); $format_acd_in_title3->setHAlign('center'); $format_acd_in_title3->setVAlign('vjustify'); $format_acd_in_title3->setVAlign('top'); $format_acd_in_title3->setTextWrap(); $format_acd_in_total =& $workbook->addFormat(); $format_acd_in_title->setSize(15); $format_acd_in_total->setBorder(1); $format_acd_in_total->setColor(8); $format_acd_in_total->setFgColor(6); $format_acd_in_total->setBold(); $format_acd_in_total->setHAlign('left'); $format_acd_in_total->setVAlign('vjustify'); $format_acd_in_total->setVAlign('top'); // Added headers since they never change in the acd in Group. $worksheet_acd_in->write(0, 0, 'MetLife / ' . $group_text, $format_acd_in_title); $worksheet_acd_in->write(0, 1, '', $format_acd_in_title); $worksheet_acd_in->write(0, 2, '', $format_acd_in_title); $worksheet_acd_in->write(0, 3, '', $format_acd_in_title); $worksheet_acd_in->write(0, 4, '', $format_acd_in_title); $worksheet_acd_in->write(0, 5, '', $format_acd_in_title); $worksheet_acd_in->write(0, 6, 'WEEKLY TOTALS', $format_acd_in_title); $worksheet_acd_in->write(0, 7, '', $format_acd_in_title); $worksheet_acd_in->write(0, 8, '', $format_acd_in_title); $worksheet_acd_in->write(0, 9, '', $format_acd_in_title); $worksheet_acd_in->write(1, 0, $week_range_text, $format_acd_in_title2); $worksheet_acd_in->write(1, 1, '', $format_acd_in_title2); $worksheet_acd_in->write(1, 2, '', $format_acd_in_title2); $worksheet_acd_in->write(1, 3, '', $format_acd_in_title2); $worksheet_acd_in->write(1, 4, '', $format_acd_in_title2); $worksheet_acd_in->write(1, 5, '', $format_acd_in_title2); $worksheet_acd_in->write(2, 0, 'Date', $format_acd_in_title3); $worksheet_acd_in->write(2, 1, 'Call Times', $format_acd_in_title3); $worksheet_acd_in->write(2, 2, 'Agent Talk', $format_acd_in_title3); $worksheet_acd_in->write(2, 3, '(MIN.SEC) Hold time', $format_acd_in_title3); $worksheet_acd_in->write(2, 4, '(MIN.SEC) Patch Time', $format_acd_in_title3); $worksheet_acd_in->write(2, 5, 'ANI', $format_acd_in_title3); $worksheet_acd_in->write(1, 6, 'Weekly Total Calls', $format_acd_in_total); $worksheet_acd_in->writeFormula(1, 7, "=count(A1:A1000)", $format_acd_in_title2); $worksheet_acd_in->write(1, 8, 'Weekly Average Patch Time', $format_acd_in_total); $worksheet_acd_in->writeFormula(1, 9, "=SUM(B2,E2)", $format_acd_in_title2); $worksheet_acd_in->write(2, 6, 'Weekly Agent Talk Time', $format_acd_in_total); $worksheet_acd_in->writeFormula(2, 7, "=SUM(B2,E2)", $format_acd_in_title2); $worksheet_acd_in->write(2, 8, 'Weekly Average Hold Time', $format_acd_in_total); $worksheet_acd_in->writeFormula(2, 9, "=SUM(B2,E2)", $format_acd_in_title2); // Setup templating for the formating of certain cells in the Inbound Count Group. $format_in_count_title =& $workbook->addFormat(); $format_in_count_title->setSize(15); $format_in_count_title->setColor(8); $format_in_count_title->setBorder(1); $format_in_count_title->setFgColor(35); $format_in_count_title->setBold(); $format_in_count_title->setHAlign('center'); $format_in_count_title->setVAlign('vjustify'); $format_in_count_title->setVAlign('top'); $format_in_count_title->setTextWrap(); $format_in_count_title2 =& $workbook->addFormat(); $format_in_count_title2->setColor(8); $format_in_count_title2->setFgColor(47); $format_in_count_title2->setBold(); $format_in_count_title2->setHAlign('center'); $format_in_count_title2->setVAlign('vjustify'); $format_in_count_title2->setVAlign('top'); $format_in_count_title2->setTextWrap(); $format_in_count_total =& $workbook->addFormat(); $format_in_count_total->setBorder(1); $format_in_count_total->setColor(8); $format_in_count_total->setFgColor(6); $format_in_count_total->setBold(); $format_in_count_total->setSize(18); $format_in_count_total->setHAlign('left'); $format_in_count_total->setVAlign('vjustify'); $format_in_count_total->setVAlign('top'); $format_in_count_grand =& $workbook->addFormat(); $format_in_count_grand->setBorder(1); $format_in_count_grand->setColor(8); $format_in_count_grand->setFgColor(43); $format_in_count_grand->setBold(); $format_in_count_grand->setSize(18); $format_in_count_grand->setHAlign('left'); $format_in_count_grand->setVAlign('vjustify'); $format_in_count_grand->setVAlign('top'); // Added headers since they never change in the Inbound Count Group. $worksheet_in_count->write(0, 0, 'Email Count Admin', $format_in_count_title); $worksheet_in_count->write(0, 1, 'Totals', $format_in_count_title); $worksheet_in_count->write(0, 2, 'Email Count Field', $format_in_count_title); $worksheet_in_count->write(0, 3, 'ID', $format_in_count_title); $worksheet_in_count->write(0, 4, 'Totals', $format_in_count_title); // Setup templating for the formating of certain cells in the Outbound Count Group. $format_out_count_title =& $workbook->addFormat(); $format_out_count_title->setSize(15); $format_out_count_title->setColor(8); $format_out_count_title->setBorder(1); $format_out_count_title->setFgColor(14); $format_out_count_title->setBold(); $format_out_count_title->setHAlign('center'); $format_out_count_title->setVAlign('vjustify'); $format_out_count_title->setVAlign('top'); $format_out_count_title->setTextWrap(); $format_out_count_title2 =& $workbook->addFormat(); $format_out_count_title2->setColor(8); $format_out_count_title2->setFgColor(47); $format_out_count_title2->setBold(); $format_out_count_title2->setHAlign('center'); $format_out_count_title2->setVAlign('vjustify'); $format_out_count_title2->setVAlign('top'); $format_out_count_title2->setTextWrap(); $format_out_count_total =& $workbook->addFormat(); $format_out_count_total->setBorder(1); $format_out_count_total->setColor(8); $format_out_count_total->setFgColor(42); $format_out_count_total->setBold(); $format_out_count_total->setSize(18); $format_out_count_total->setHAlign('left'); $format_out_count_total->setVAlign('vjustify'); $format_out_count_total->setVAlign('top'); $format_out_count_grand =& $workbook->addFormat(); $format_out_count_grand->setBorder(1); $format_out_count_grand->setColor(8); $format_out_count_grand->setFgColor(43); $format_out_count_grand->setBold(); $format_out_count_grand->setSize(18); $format_out_count_grand->setHAlign('left'); $format_out_count_grand->setVAlign('vjustify'); $format_out_count_grand->setVAlign('top'); // Added headers since they never change in the Outbound Count Group. $worksheet_out_count->write(0, 0, 'Email Count Admin', $format_out_count_title); $worksheet_out_count->write(0, 1, 'Totals', $format_out_count_title); $worksheet_out_count->write(0, 2, 'Email Count Field', $format_out_count_title); $worksheet_out_count->write(0, 3, 'ID', $format_out_count_title); $worksheet_out_count->write(0, 4, 'Totals', $format_out_count_title); // Setup templating for the formating of certain cells in the Inbound Group. $format_inbound_title =& $workbook->addFormat(); $format_inbound_title->setSize(15); $format_inbound_title->setColor(8); $format_inbound_title->setBorder(1); $format_inbound_title->setFgColor(35); $format_inbound_title->setBold(); $format_inbound_title->setHAlign('center'); $format_inbound_title->setVAlign('vjustify'); $format_inbound_title->setVAlign('top'); $format_inbound_title->setTextWrap(); $format_inbound_title2 =& $workbook->addFormat(); $format_inbound_title2->setColor(8); $format_inbound_title2->setFgColor(47); $format_inbound_title2->setBold(); $format_inbound_title2->setHAlign('center'); $format_inbound_title2->setVAlign('vjustify'); $format_inbound_title2->setVAlign('top'); $format_inbound_title2->setTextWrap(); // Setup templating for the formating of certain cells in the Inbound Group. $format_inbound_title3 =& $workbook->addFormat(); $format_inbound_title3->setSize(15); $format_inbound_title3->setColor(8); $format_inbound_title3->setBorder(1); $format_inbound_title3->setFgColor(34); $format_inbound_title3->setBold(); $format_inbound_title3->setHAlign('center'); $format_inbound_title3->setVAlign('vjustify'); $format_inbound_title3->setVAlign('top'); $format_inbound_title3->setTextWrap(); // Added headers since they never change in the Inbound Group. $worksheet_inbound->setInputEncoding('utf-8'); $worksheet_inbound->write(0, 0, 'Inbound Email From', $format_inbound_title); $worksheet_inbound->write(0, 1, 'User Name', $format_inbound_title); $worksheet_inbound->write(0, 2, 'ID', $format_inbound_title); $worksheet_inbound->write(0, 3, 'Date Email Received', $format_inbound_title); $worksheet_inbound->write(0, 4, 'Ticket Mask', $format_inbound_title); $worksheet_inbound->write(0, 5, 'Subject Line', $format_inbound_title); $worksheet_inbound->write(0, 6, 'Email Contents', $format_inbound_title); $worksheet_inbound->write(0, 7, 'Category', $format_inbound_title3); $worksheet_inbound->write(0, 8, 'Code', $format_inbound_title3); $worksheet_inbound->write(0, 9, 'Description(or snapshot)', $format_inbound_title3); $worksheet_inbound->write(0, 10, 'Group', $format_inbound_title); $worksheet_inbound->write(1, 0, $week_range_text, $format_inbound_title2); $worksheet_inbound->write(1, 1, "", $format_inbound_title2); $worksheet_inbound->write(1, 2, "", $format_inbound_title2); $worksheet_inbound->write(1, 3, "", $format_inbound_title2); $worksheet_inbound->write(1, 4, "", $format_inbound_title2); $worksheet_inbound->write(1, 5, "", $format_inbound_title2); $worksheet_inbound->write(1, 6, "", $format_inbound_title2); $worksheet_inbound->write(1, 7, "", $format_inbound_title2); $worksheet_inbound->write(1, 8, "", $format_inbound_title2); $worksheet_inbound->write(1, 9, "", $format_inbound_title2); $worksheet_inbound->write(1, 10, "", $format_inbound_title2); // Setup templating for the formating of certain cells in the Outbound Group. $format_outbound_title =& $workbook->addFormat(); $format_outbound_title->setSize(15); $format_outbound_title->setColor(8); $format_outbound_title->setBorder(1); $format_outbound_title->setFgColor(11); $format_outbound_title->setBold(); $format_outbound_title->setHAlign('center'); $format_outbound_title->setVAlign('vjustify'); $format_outbound_title->setVAlign('top'); $format_outbound_title->setTextWrap(); $format_outbound_title2 =& $workbook->addFormat(); $format_outbound_title2->setColor(8); $format_outbound_title2->setFgColor(6); $format_outbound_title2->setBold(); $format_outbound_title2->setHAlign('center'); $format_outbound_title2->setVAlign('vjustify'); $format_outbound_title2->setVAlign('top'); $format_outbound_title2->setTextWrap(); $format_outbound_title3 =& $workbook->addFormat(); $format_outbound_title3->setSize(15); $format_outbound_title3->setColor(8); $format_outbound_title3->setBorder(1); $format_outbound_title3->setFgColor(34); $format_outbound_title3->setBold(); $format_outbound_title3->setHAlign('center'); $format_outbound_title3->setVAlign('vjustify'); $format_outbound_title3->setVAlign('top'); $format_outbound_title3->setTextWrap(); // Added headers since they never change in the Outbound Group. $worksheet_outbound->setInputEncoding('utf-8'); $worksheet_outbound->write(0, 0, 'Outbound Email To', $format_outbound_title); $worksheet_outbound->write(0, 1, 'User Name', $format_outbound_title); $worksheet_outbound->write(0, 2, 'ID', $format_outbound_title); $worksheet_outbound->write(0, 3, 'Date Email Sent', $format_outbound_title); $worksheet_outbound->write(0, 4, 'Ticket Mask', $format_outbound_title); $worksheet_outbound->write(0, 5, 'Subject Line', $format_outbound_title); $worksheet_outbound->write(0, 6, 'Email Contents', $format_outbound_title); $worksheet_outbound->write(0, 7, 'Category', $format_outbound_title3); $worksheet_outbound->write(0, 8, 'Code', $format_outbound_title3); $worksheet_outbound->write(0, 9, 'Description(or snapshot)', $format_outbound_title3); $worksheet_outbound->write(0, 10, 'Responder', $format_outbound_title); $worksheet_outbound->write(0, 11, 'Group', $format_outbound_title); $worksheet_outbound->write(1, 0, $week_range_text, $format_outbound_title2); $worksheet_outbound->write(1, 1, "", $format_outbound_title2); $worksheet_outbound->write(1, 2, "", $format_outbound_title2); $worksheet_outbound->write(1, 3, "", $format_outbound_title2); $worksheet_outbound->write(1, 4, "", $format_outbound_title2); $worksheet_outbound->write(1, 5, "", $format_outbound_title2); $worksheet_outbound->write(1, 6, "", $format_outbound_title2); $worksheet_outbound->write(1, 7, "", $format_outbound_title2); $worksheet_outbound->write(1, 8, "", $format_outbound_title2); $worksheet_outbound->write(1, 9, "", $format_outbound_title2); $worksheet_outbound->write(1, 10, "", $format_outbound_title2); $worksheet_outbound->write(1, 11, "", $format_outbound_title2); print $translate->_('answernet.er.metlife.metlife.done'); print '<br>'; print $translate->_('answernet.er.metlife.generating.email.detail'); $groups = DAO_Group::getAll(); $buckets = DAO_Bucket::getAll(); $sql = "SELECT t.mask, a.email, m.address_id, a.contact_org_id, "; $sql .= "t.created_date ticket_created_date, t.team_id, "; $sql .= "m.created_date message_created_date, mc.content, "; $sql .= "mh.header_value message_subject, m.worker_id, "; $sql .= "m.is_outgoing, mh_to.header_value outbound_email, t.team_id "; $sql .= "FROM message m "; $sql .= "INNER JOIN ticket t ON m.ticket_id = t.id "; $sql .= "INNER JOIN address a ON m.address_id = a.id "; $sql .= "INNER JOIN message_content mc on m.id = mc.message_id "; $sql .= "INNER JOIN message_header mh on m.id = mh.message_id "; $sql .= "and mh.header_name = 'subject' "; $sql .= "INNER JOIN message_header mh_to on m.id = mh_to.message_id "; $sql .= "and mh_to.header_name = 'to' "; $sql .= sprintf("WHERE m.created_date > %d AND m.created_date <= %d ", $start_time, $end_time); // Set abouve based on group selected. $sql .= $group_sql; $sql .= "ORDER BY m.id "; $rs = $db->Execute($sql); $row_inbound = 2; $row_outbound = 2; $in_count_admin = array(); $in_count_other = array(); $out_count_admin = array(); $out_count_other = array(); if (is_a($rs, 'ADORecordSet')) { while (!$rs->EOF) { $mask = $rs->fields['mask']; $ticket_created_date = intval($rs->fields['ticket_created_date']); $team_id = intval($rs->fields['team_id']); // Date Format Month/Day/Year Hour:Min:Sec AM/PM $message_created_date = date("n/j/y g:i:s A", intval($rs->fields['message_created_date'])); $message_content = $rs->fields['content']; $message_subject = $rs->fields['message_subject']; $worker_id = $rs->fields['worker_id']; $is_outgoing = $rs->fields['is_outgoing']; if ($team_id == 756) { $team_text = 'First Person'; } elseif ($team_id == 782) { $team_text = 'iDesign'; } else { $team_text = 'Error'; } if ($worker_id) { $worker_name = $workers[$worker_id]->first_name; } else { $worker_name = ""; } if ($is_outgoing) { $outbound_email = $rs->fields['outbound_email']; $to = array(); $to = CerberusParser::parseRfcAddress($outbound_email); @($toAddress = $to[0]->mailbox . '@' . $to[0]->host); $toAddressInst = CerberusApplication::hashLookupAddress($toAddress, true); $address_id = $toAddressInst->id; $contact_org_id = $toAddressInst->contact_org_id; $email = $toAddressInst->email; } else { $address_id = $rs->fields['address_id']; $contact_org_id = $rs->fields['contact_org_id']; $email = $rs->fields['email']; } if ($is_outgoing) { $worksheet_outbound->setRow($row_outbound, 12); $worksheet_outbound->write($row_outbound, 0, $email, $format_general); $worksheet_outbound->write($row_outbound, 1, "", $format_general); $worksheet_outbound->write($row_outbound, 2, "", $format_general); $worksheet_outbound->write($row_outbound, 3, $message_created_date, $format_general); $worksheet_outbound->write($row_outbound, 4, $mask, $format_general); $worksheet_outbound->write($row_outbound, 5, trim($message_subject), $format_general_nowrap); $worksheet_outbound->write($row_outbound, 6, trim(strip_tags($message_content))); $worksheet_outbound->writeString($row_outbound, 10, $worker_name, $format_general); $worksheet_outbound->write($row_outbound, 11, $team_text, $format_general); $row_outbound++; } else { $worksheet_inbound->setRow($row_inbound, 12); $worksheet_inbound->write($row_inbound, 0, $email, $format_general); $worksheet_inbound->write($row_inbound, 1, "", $format_general); $worksheet_inbound->write($row_inbound, 2, "", $format_general); $worksheet_inbound->write($row_inbound, 3, $message_created_date, $format_general); $worksheet_inbound->write($row_inbound, 4, $mask, $format_general); $worksheet_inbound->write($row_inbound, 5, trim($message_subject), $format_general_nowrap); $worksheet_inbound->writeString($row_inbound, 6, trim(strip_tags($message_content))); $worksheet_inbound->write($row_inbound, 10, $team_text, $format_general); $row_inbound++; } if ($is_outgoing) { if ($contact_org_id == 1) { if (!isset($out_count_admin[$address_id]['count'])) { $out_count_admin[$address_id]['email'] = $email; $out_count_admin[$address_id]['count'] = 1; } else { $out_count_admin[$address_id]['count']++; } } else { if (!isset($out_count_other[$address_id]['count'])) { $out_count_other[$address_id]['email'] = $email; $out_count_other[$address_id]['count'] = 1; } else { $out_count_other[$address_id]['count']++; } } } else { if ($contact_org_id == 1) { if (!isset($in_count_admin[$address_id]['count'])) { $in_count_admin[$address_id]['email'] = $email; $in_count_admin[$address_id]['count'] = 1; } else { $in_count_admin[$address_id]['count']++; } } else { if (!isset($in_count_other[$address_id]['count'])) { $in_count_other[$address_id]['email'] = $email; $in_count_other[$address_id]['count'] = 1; } else { $in_count_other[$address_id]['count']++; } } } $rs->MoveNext(); } } print $translate->_('answernet.er.metlife.metlife.done'); print '<br>'; print $translate->_('answernet.er.metlife.generating.email.count'); $worksheet_in_count->setRow(1, 24); $row_count = 2; foreach ($in_count_admin as $record) { $worksheet_in_count->write($row_count, 0, $record['email'], $format_general); $worksheet_in_count->write($row_count, 1, $record['count'], $format_general); $row_count++; } $worksheet_in_count->write(1, 0, 'Total Admin Email', $format_in_count_total); $worksheet_in_count->writeFormula(1, 1, "=SUM(B3:B" . $row_count . ")", $format_in_count_total); $row_count = 2; foreach ($in_count_other as $record) { $worksheet_in_count->write($row_count, 2, $record['email'], $format_general); $worksheet_in_count->write($row_count, 3, '', $format_general); $worksheet_in_count->write($row_count, 4, $record['count'], $format_general); $row_count++; } $worksheet_in_count->write(1, 2, 'Total Field Email', $format_in_count_total); $worksheet_in_count->write(1, 3, '', $format_in_count_total); $worksheet_in_count->writeFormula(1, 4, "=SUM(E3:E" . $row_count . ")", $format_in_count_total); // Grand Total $worksheet_in_count->write(1, 5, 'Grand Total Email', $format_in_count_grand); $worksheet_in_count->writeFormula(1, 6, "=SUM(B2,E2)", $format_in_count_grand); $worksheet_out_count->setRow(1, 24); $row_count = 2; foreach ($out_count_admin as $record) { $worksheet_out_count->write($row_count, 0, $record['email'], $format_general); $worksheet_out_count->write($row_count, 1, $record['count'], $format_general); $row_count++; } $worksheet_out_count->write(1, 0, 'Total Admin Email', $format_out_count_total); $worksheet_out_count->writeFormula(1, 1, "=SUM(B3:B" . $row_count . ")", $format_out_count_total); $row_count = 2; foreach ($out_count_other as $record) { $worksheet_out_count->write($row_count, 2, $record['email'], $format_general); $worksheet_out_count->write($row_count, 3, '', $format_general); $worksheet_out_count->write($row_count, 4, $record['count'], $format_general); $row_count++; } $worksheet_out_count->write(1, 2, 'Total Field Email', $format_out_count_total); $worksheet_out_count->write(1, 3, '', $format_out_count_total); $worksheet_out_count->writeFormula(1, 4, "=SUM(E3:E" . $row_count . ")", $format_out_count_total); // Grand Total $worksheet_out_count->write(1, 5, 'Grand Total Email', $format_out_count_grand); $worksheet_out_count->writeFormula(1, 6, "=SUM(B2,E2)", $format_out_count_grand); $workbook->close(); print $translate->_('answernet.er.metlife.metlife.done'); print '<br>'; print $translate->_('ranswernet.er.metlife.generating'); print $translate->_('answernet.er.metlife.metlife.done'); print '<br><br>'; print '<b><a href=' . $href_filename . '>' . $translate->_('answernet.er.metlife.download.xls') . '</a></b>'; print '<br><br>'; }
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'))); }