Пример #1
0
 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');
 }
Пример #2
0
 function doContactSendAction()
 {
     @($sFrom = DevblocksPlatform::importGPC($_POST['from'], 'string', ''));
     @($sSubject = DevblocksPlatform::importGPC($_POST['subject'], 'string', ''));
     @($sContent = DevblocksPlatform::importGPC($_POST['content'], 'string', ''));
     @($sCaptcha = DevblocksPlatform::importGPC($_POST['captcha'], 'string', ''));
     @($aFieldIds = DevblocksPlatform::importGPC($_POST['field_ids'], 'array', array()));
     @($aFollowUpQ = DevblocksPlatform::importGPC($_POST['followup_q'], 'array', array()));
     // Load the answers to any situational questions
     $aFollowUpA = array();
     if (is_array($aFollowUpQ)) {
         foreach ($aFollowUpQ as $idx => $q) {
             @($answer = DevblocksPlatform::importGPC($_POST['followup_a_' . $idx], 'string', ''));
             $aFollowUpA[$idx] = $answer;
         }
     }
     $umsession = $this->getSession();
     $fingerprint = parent::getFingerprint();
     $settings = CerberusSettings::getInstance();
     $default_from = $settings->get(CerberusSettings::DEFAULT_REPLY_FROM);
     $umsession->setProperty('support.write.last_from', $sFrom);
     $umsession->setProperty('support.write.last_subject', $sSubject);
     $umsession->setProperty('support.write.last_content', $sContent);
     //		$umsession->setProperty('support.write.last_followup_q',$aFollowUpQ);
     $umsession->setProperty('support.write.last_followup_a', $aFollowUpA);
     $sNature = $umsession->getProperty('support.write.last_nature', '');
     $captcha_enabled = DAO_CommunityToolProperty::get($this->getPortal(), UmScApp::PARAM_CAPTCHA_ENABLED, 1);
     if (empty($sFrom) || $captcha_enabled && 0 != strcasecmp($sCaptcha, @$umsession->getProperty(UmScApp::SESSION_CAPTCHA, '***'))) {
         if (empty($sFrom)) {
             $umsession->setProperty('support.write.last_error', 'Invalid e-mail address.');
         } else {
             $umsession->setProperty('support.write.last_error', 'What you typed did not match the image.');
         }
         // [TODO] Need to report the captcha didn't match and redraw the form
         DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('portal', $this->getPortal(), 'contact', 'step2')));
         return;
     }
     // Dispatch
     $to = $default_from;
     $subject = 'Contact me: Other';
     $sDispatch = DAO_CommunityToolProperty::get($this->getPortal(), UmScApp::PARAM_DISPATCH, '');
     $dispatch = !empty($sDispatch) ? unserialize($sDispatch) : array();
     foreach ($dispatch as $k => $v) {
         if (md5($k) == $sNature) {
             $to = $v['to'];
             $subject = 'Contact me: ' . strip_tags($k);
             break;
         }
     }
     if (!empty($sSubject)) {
         $subject = $sSubject;
     }
     $fieldContent = '';
     if (!empty($aFollowUpQ)) {
         $fieldContent = "\r\n\r\n";
         $fieldContent .= "--------------------------------------------\r\n";
         if (!empty($sNature)) {
             $fieldContent .= $subject . "\r\n";
             $fieldContent .= "--------------------------------------------\r\n";
         }
         foreach ($aFollowUpQ as $idx => $q) {
             $answer = isset($aFollowUpA[$idx]) ? $aFollowUpA[$idx] : '';
             $fieldContent .= "Q) " . $q . "\r\n" . "A) " . $answer . "\r\n";
             if ($idx + 1 < count($aFollowUpQ)) {
                 $fieldContent .= "\r\n";
             }
         }
         $fieldContent .= "--------------------------------------------\r\n";
         "\r\n";
     }
     $message = new CerberusParserMessage();
     $message->headers['date'] = date('r');
     $message->headers['to'] = $to;
     $message->headers['subject'] = $subject;
     $message->headers['message-id'] = CerberusApplication::generateMessageId();
     $message->headers['x-cerberus-portal'] = 1;
     // Sender
     $fromList = imap_rfc822_parse_adrlist($sFrom, '');
     if (empty($fromList) || !is_array($fromList)) {
         return;
         // abort with message
     }
     $from = array_shift($fromList);
     $message->headers['from'] = $from->mailbox . '@' . $from->host;
     $message->body = 'IP: ' . $fingerprint['ip'] . "\r\n\r\n" . $sContent . $fieldContent;
     $ticket_id = CerberusParser::parseMessage($message);
     $ticket = DAO_Ticket::getTicket($ticket_id);
     // Auto-save any custom fields
     $fields = DAO_CustomField::getBySource('cerberusweb.fields.source.ticket');
     if (!empty($aFieldIds)) {
         foreach ($aFieldIds as $iIdx => $iFieldId) {
             if (!empty($iFieldId)) {
                 $field =& $fields[$iFieldId];
                 /* @var $field Model_CustomField */
                 $value = "";
                 switch ($field->type) {
                     case Model_CustomField::TYPE_SINGLE_LINE:
                     case Model_CustomField::TYPE_MULTI_LINE:
                         @($value = trim($aFollowUpA[$iIdx]));
                         break;
                     case Model_CustomField::TYPE_NUMBER:
                         @($value = intval($aFollowUpA[$iIdx]));
                         break;
                     case Model_CustomField::TYPE_DATE:
                         if (false !== ($time = strtotime($aFollowUpA[$iIdx]))) {
                             @($value = intval($time));
                         }
                         break;
                     case Model_CustomField::TYPE_DROPDOWN:
                         @($value = $aFollowUpA[$iIdx]);
                         break;
                     case Model_CustomField::TYPE_CHECKBOX:
                         @($value = isset($aFollowUpA[$iIdx]) && !empty($aFollowUpA[$iIdx]) ? 1 : 0);
                         break;
                 }
                 if (!empty($value)) {
                     DAO_CustomFieldValue::setFieldValue('cerberusweb.fields.source.ticket', $ticket_id, $iFieldId, $value);
                 }
             }
         }
     }
     // Clear any errors
     $umsession->setProperty('support.write.last_nature', null);
     $umsession->setProperty('support.write.last_nature_string', null);
     $umsession->setProperty('support.write.last_content', null);
     $umsession->setProperty('support.write.last_error', null);
     $umsession->setProperty('support.write.last_opened', $ticket->mask);
     DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('portal', $this->getPortal(), 'contact', 'confirm')));
 }
Пример #3
0
                    }
                    if (!empty($support_gid)) {
                        DAO_Group::setTeamMember($support_gid, $worker_id, true);
                    }
                    if (!empty($sales_gid)) {
                        DAO_Group::setTeamMember($sales_gid, $worker_id, true);
                    }
                }
                // Send a first ticket which allows people to reply for support
                if (null !== ($default_from = $settings->get(CerberusSettings::DEFAULT_REPLY_FROM, ''))) {
                    $message = new CerberusParserMessage();
                    $message->headers['from'] = '"WebGroup Media, LLC." <*****@*****.**>';
                    $message->headers['to'] = $default_from;
                    $message->headers['subject'] = "Welcome to Cerberus Helpdesk 4.x!";
                    $message->headers['date'] = date('r');
                    $message->headers['message-id'] = CerberusApplication::generateMessageId();
                    $message->body = <<<EOF
Welcome to Cerberus Helpdesk 4.x (Cerb4)!

We automatically set up a few things for you during the installation process.

You'll notice you have three groups:
* Dispatch: All your mail will be delivered to this group by default.
* Support: This is a group for holding tickets related to customer service.
* Sales: This is a group for holding tickets relates to sales.

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.
Пример #4
0
 function logTicketAction()
 {
     $active_worker = CerberusApplication::getActiveWorker();
     if (!$active_worker->hasPriv('core.mail.log_ticket')) {
         return;
     }
     @($to = DevblocksPlatform::importGPC($_POST['to'], 'string'));
     @($reqs = DevblocksPlatform::importGPC($_POST['reqs'], 'string'));
     @($subject = DevblocksPlatform::importGPC($_POST['subject'], 'string'));
     @($content = DevblocksPlatform::importGPC($_POST['content'], 'string'));
     @($send_to_requesters = DevblocksPlatform::importGPC($_POST['send_to_requesters'], 'integer', 0));
     @($closed = DevblocksPlatform::importGPC($_POST['closed'], 'integer', 0));
     @($move_bucket = DevblocksPlatform::importGPC($_POST['bucket_id'], 'string', ''));
     @($next_worker_id = DevblocksPlatform::importGPC($_POST['next_worker_id'], 'integer', 0));
     @($ticket_reopen = DevblocksPlatform::importGPC($_POST['ticket_reopen'], 'string', ''));
     @($unlock_date = DevblocksPlatform::importGPC($_POST['unlock_date'], 'string', ''));
     if (DEMO_MODE) {
         DevblocksPlatform::redirect(new DevblocksHttpResponse(array('tickets', 'create')));
         return;
     }
     // ********
     $message = new CerberusParserMessage();
     $message->headers['date'] = date('r');
     $message->headers['to'] = $to;
     $message->headers['subject'] = $subject;
     $message->headers['message-id'] = CerberusApplication::generateMessageId();
     //$message->headers['x-cerberus-portal'] = 1;
     // Sender
     $fromList = imap_rfc822_parse_adrlist(rtrim($reqs, ', '), '');
     if (empty($fromList) || !is_array($fromList)) {
         return;
         // abort with message
     }
     $from = array_shift($fromList);
     $from_address = $from->mailbox . '@' . $from->host;
     $message->headers['from'] = $from_address;
     $message->body = sprintf("(... This message was manually created by %s on behalf of the requesters ...)\r\n", $active_worker->getName());
     //		// Custom Fields
     //
     //		if(!empty($aFieldIds))
     //		foreach($aFieldIds as $iIdx => $iFieldId) {
     //			if(!empty($iFieldId)) {
     //				$field =& $fields[$iFieldId]; /* @var $field Model_CustomField */
     //				$value = "";
     //
     //				switch($field->type) {
     //					case Model_CustomField::TYPE_SINGLE_LINE:
     //					case Model_CustomField::TYPE_MULTI_LINE:
     //					case Model_CustomField::TYPE_URL:
     //						@$value = trim($aFollowUpA[$iIdx]);
     //						break;
     //
     //					case Model_CustomField::TYPE_NUMBER:
     //						@$value = $aFollowUpA[$iIdx];
     //						if(!is_numeric($value) || 0 == strlen($value))
     //							$value = null;
     //						break;
     //
     //					case Model_CustomField::TYPE_DATE:
     //						if(false !== ($time = strtotime($aFollowUpA[$iIdx])))
     //							@$value = intval($time);
     //						break;
     //
     //					case Model_CustomField::TYPE_DROPDOWN:
     //						@$value = $aFollowUpA[$iIdx];
     //						break;
     //
     //					case Model_CustomField::TYPE_MULTI_PICKLIST:
     //						@$value = DevblocksPlatform::importGPC($_POST['followup_a_'.$iIdx],'array',array());
     //						break;
     //
     //					case Model_CustomField::TYPE_CHECKBOX:
     //						@$value = (isset($aFollowUpA[$iIdx]) && !empty($aFollowUpA[$iIdx])) ? 1 : 0;
     //						break;
     //
     //					case Model_CustomField::TYPE_MULTI_CHECKBOX:
     //						@$value = DevblocksPlatform::importGPC($_POST['followup_a_'.$iIdx],'array',array());
     //						break;
     //
     //					case Model_CustomField::TYPE_WORKER:
     //						@$value = DevblocksPlatform::importGPC($_POST['followup_a_'.$iIdx],'integer',0);
     //						break;
     //				}
     //
     //				if((is_array($value) && !empty($value))
     //					|| (!is_array($value) && 0 != strlen($value)))
     //						$message->custom_fields[$iFieldId] = $value;
     //			}
     //		}
     // Parse
     $ticket_id = CerberusParser::parseMessage($message);
     $ticket = DAO_Ticket::getTicket($ticket_id);
     // Add additional requesters to ticket
     if (is_array($fromList) && !empty($fromList)) {
         foreach ($fromList as $requester) {
             if (empty($requester)) {
                 continue;
             }
             $host = empty($requester->host) ? 'localhost' : $requester->host;
             $requester_addy = DAO_Address::lookupAddress($requester->mailbox . '@' . $host, true);
             DAO_Ticket::createRequester($requester_addy->id, $ticket_id);
         }
     }
     // Worker reply
     $properties = array('message_id' => $ticket->first_message_id, 'ticket_id' => $ticket_id, 'subject' => $subject, 'content' => $content, 'files' => @$_FILES['attachment'], 'next_worker_id' => $next_worker_id, 'closed' => $closed, 'bucket_id' => $move_bucket, 'ticket_reopen' => $ticket_reopen, 'unlock_date' => $unlock_date, 'agent_id' => $active_worker->id, 'dont_send' => false == $send_to_requesters);
     CerberusMail::sendTicketMessage($properties);
     // ********
     //		if(empty($to) || empty($team_id)) {
     //			DevblocksPlatform::redirect(new DevblocksHttpResponse(array('tickets','create')));
     //			return;
     //		}
     $visit = CerberusApplication::getVisit();
     /* @var CerberusVisit $visit */
     $visit->set('compose.last_ticket', $ticket->mask);
     DevblocksPlatform::redirect(new DevblocksHttpResponse(array('tickets', 'create')));
 }
Пример #5
0
 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])));
 }
Пример #6
0
 function doSendMessageAction()
 {
     @($sFrom = DevblocksPlatform::importGPC($_POST['from'], 'string', ''));
     @($sContent = DevblocksPlatform::importGPC($_POST['content'], 'string', ''));
     @($sCaptcha = DevblocksPlatform::importGPC($_POST['captcha'], 'string', ''));
     $umsession = $this->getSession();
     $fingerprint = parent::getFingerprint();
     $settings = CerberusSettings::getInstance();
     $default_from = $settings->get(CerberusSettings::DEFAULT_REPLY_FROM);
     $umsession->setProperty('support.write.last_from', $sFrom);
     $umsession->setProperty('support.write.last_content', $sContent);
     $sNature = $umsession->getProperty('support.write.last_nature', '');
     $captcha_enabled = DAO_CommunityToolProperty::get($this->getPortal(), self::PARAM_CAPTCHA_ENABLED, 1);
     if (empty($sFrom) || $captcha_enabled && 0 != strcasecmp($sCaptcha, @$umsession->getProperty(self::SESSION_CAPTCHA, '***'))) {
         if (empty($sFrom)) {
             $umsession->setProperty('support.write.last_error', 'Invalid e-mail address.');
         } else {
             $umsession->setProperty('support.write.last_error', 'What you typed did not match the image.');
         }
         // [TODO] Need to report the captcha didn't match and redraw the form
         DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('portal', $this->getPortal(), 'write', 'step3')));
         return;
     }
     // Dispatch
     $to = $default_from;
     $subject = 'Contact me: Other';
     $sDispatch = DAO_CommunityToolProperty::get($this->getPortal(), self::PARAM_DISPATCH, '');
     $dispatch = !empty($sDispatch) ? unserialize($sDispatch) : array();
     foreach ($dispatch as $k => $v) {
         if (md5($k) == $sNature) {
             $to = $v['to'];
             $subject = 'Contact me: ' . strip_tags($k);
             break;
         }
     }
     $message = new CerberusParserMessage();
     $message->headers['date'] = date('r');
     $message->headers['to'] = $to;
     $message->headers['subject'] = $subject;
     $message->headers['message-id'] = CerberusApplication::generateMessageId();
     $message->headers['x-cerberus-portal'] = 1;
     // Sender
     $fromList = imap_rfc822_parse_adrlist($sFrom, '');
     if (empty($fromList) || !is_array($fromList)) {
         return;
         // abort with message
     }
     $from = array_shift($fromList);
     $message->headers['from'] = $from->mailbox . '@' . $from->host;
     //$message->body = 'IP: ' . $fingerprint['ip'] . "\r\n\r\n" . $sContent;
     $message->body = $sContent;
     $ticket_id = CerberusParser::parseMessage($message);
     $ticket = DAO_Ticket::getTicket($ticket_id);
     //		echo "Created Ticket ID: $ticket_id<br>";
     // [TODO] Could set this ID/mask into the UMsession
     // Clear any errors
     $umsession->setProperty('support.write.last_nature', null);
     $umsession->setProperty('support.write.last_nature_string', null);
     $umsession->setProperty('support.write.last_content', null);
     $umsession->setProperty('support.write.last_error', null);
     $umsession->setProperty('support.write.last_opened', $ticket->mask);
     DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('portal', $this->getPortal(), 'write', 'confirm')));
 }
Пример #7
0
 function doContactSendAction()
 {
     @($sFrom = DevblocksPlatform::importGPC($_POST['from'], 'string', ''));
     @($sSubject = DevblocksPlatform::importGPC($_POST['subject'], 'string', ''));
     @($sContent = DevblocksPlatform::importGPC($_POST['content'], 'string', ''));
     @($sCaptcha = DevblocksPlatform::importGPC($_POST['captcha'], 'string', ''));
     @($aFieldIds = DevblocksPlatform::importGPC($_POST['field_ids'], 'array', array()));
     @($aFollowUpQ = DevblocksPlatform::importGPC($_POST['followup_q'], 'array', array()));
     $fields = DAO_CustomField::getBySource('cerberusweb.fields.source.ticket');
     // Load the answers to any situational questions
     $aFollowUpA = array();
     if (is_array($aFollowUpQ)) {
         foreach ($aFollowUpQ as $idx => $q) {
             // Only form values we were passed
             if (!isset($_POST['followup_a_' . $idx])) {
                 continue;
             }
             if (is_array($_POST['followup_a_' . $idx])) {
                 @($answer = DevblocksPlatform::importGPC($_POST['followup_a_' . $idx], 'array', array()));
                 $aFollowUpA[$idx] = implode(', ', $answer);
             } else {
                 @($answer = DevblocksPlatform::importGPC($_POST['followup_a_' . $idx], 'string', ''));
                 $aFollowUpA[$idx] = $answer;
             }
             // Translate field values into something human-readable (if needed)
             if (isset($aFieldIds[$idx]) && !empty($aFieldIds[$idx])) {
                 // Were we given a legit field id?
                 if (null != @($field = $fields[$aFieldIds[$idx]])) {
                     switch ($field->type) {
                         // Translate 'worker' fields into worker name (not ID)
                         case Model_CustomField::TYPE_WORKER:
                             if (null != ($worker = DAO_Worker::getAgent($answer))) {
                                 $aFollowUpA[$idx] = $worker->getName();
                             }
                             break;
                     }
                     // switch
                 }
                 // if
             }
             // if
         }
     }
     $umsession = UmPortalHelper::getSession();
     $active_user = $umsession->getProperty('sc_login', null);
     $fingerprint = UmPortalHelper::getFingerprint();
     $settings = CerberusSettings::getInstance();
     $default_from = $settings->get(CerberusSettings::DEFAULT_REPLY_FROM);
     $umsession->setProperty('support.write.last_from', $sFrom);
     $umsession->setProperty('support.write.last_subject', $sSubject);
     $umsession->setProperty('support.write.last_content', $sContent);
     $umsession->setProperty('support.write.last_followup_a', $aFollowUpA);
     $sNature = $umsession->getProperty('support.write.last_nature', '');
     $captcha_enabled = DAO_CommunityToolProperty::get(UmPortalHelper::getCode(), self::PARAM_CAPTCHA_ENABLED, 1);
     $captcha_session = $umsession->getProperty(UmScApp::SESSION_CAPTCHA, '***');
     // Subject is required if the field  is on the form
     if (isset($_POST['subject']) && empty($sSubject)) {
         $umsession->setProperty('support.write.last_error', 'A subject is required.');
         DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('portal', UmPortalHelper::getCode(), 'contact', 'step2')));
         return;
     }
     // Sender and CAPTCHA required
     if (empty($sFrom) || $captcha_enabled && 0 != strcasecmp($sCaptcha, $captcha_session)) {
         if (empty($sFrom)) {
             $umsession->setProperty('support.write.last_error', 'Invalid e-mail address.');
         } else {
             $umsession->setProperty('support.write.last_error', 'What you typed did not match the image.');
         }
         // Need to report the captcha didn't match and redraw the form
         DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('portal', UmPortalHelper::getCode(), 'contact', 'step2')));
         return;
     }
     // Dispatch
     $to = $default_from;
     $subject = 'Contact me: Other';
     $sDispatch = DAO_CommunityToolProperty::get(UmPortalHelper::getCode(), self::PARAM_SITUATIONS, '');
     $dispatch = !empty($sDispatch) ? unserialize($sDispatch) : array();
     foreach ($dispatch as $k => $v) {
         if (md5($k) == $sNature) {
             $to = $v['to'];
             $subject = 'Contact me: ' . strip_tags($k);
             break;
         }
     }
     if (!empty($sSubject)) {
         $subject = $sSubject;
     }
     $fieldContent = '';
     if (!empty($aFollowUpQ)) {
         $fieldContent = "\r\n\r\n";
         $fieldContent .= "--------------------------------------------\r\n";
         if (!empty($sNature)) {
             $fieldContent .= $subject . "\r\n";
             $fieldContent .= "--------------------------------------------\r\n";
         }
         foreach ($aFollowUpQ as $idx => $q) {
             $answer = isset($aFollowUpA[$idx]) ? $aFollowUpA[$idx] : '';
             $fieldContent .= "Q) " . $q . "\r\n" . "A) " . $answer . "\r\n";
             if ($idx + 1 < count($aFollowUpQ)) {
                 $fieldContent .= "\r\n";
             }
         }
         $fieldContent .= "--------------------------------------------\r\n";
         "\r\n";
     }
     $message = new CerberusParserMessage();
     $message->headers['date'] = date('r');
     $message->headers['to'] = $to;
     $message->headers['subject'] = $subject;
     $message->headers['message-id'] = CerberusApplication::generateMessageId();
     $message->headers['x-cerberus-portal'] = 1;
     // Sender
     $fromList = imap_rfc822_parse_adrlist($sFrom, '');
     if (empty($fromList) || !is_array($fromList)) {
         return;
         // abort with message
     }
     $from = array_shift($fromList);
     $message->headers['from'] = $from->mailbox . '@' . $from->host;
     $message->body = 'IP: ' . $fingerprint['ip'] . "\r\n\r\n" . $sContent . $fieldContent;
     // Attachments
     $attachments_mode = DAO_CommunityToolProperty::get(UmPortalHelper::getCode(), self::PARAM_ATTACHMENTS_MODE, 0);
     if (0 == $attachments_mode || 1 == $attachments_mode && !empty($active_user)) {
         if (is_array($_FILES) && !empty($_FILES)) {
             foreach ($_FILES as $name => $files) {
                 // field[]
                 if (is_array($files['name'])) {
                     foreach ($files['name'] as $idx => $name) {
                         $attach = new ParserFile();
                         $attach->setTempFile($files['tmp_name'][$idx], 'application/octet-stream');
                         $attach->file_size = filesize($files['tmp_name'][$idx]);
                         $message->files[$name] = $attach;
                     }
                 } else {
                     $attach = new ParserFile();
                     $attach->setTempFile($files['tmp_name'], 'application/octet-stream');
                     $attach->file_size = filesize($files['tmp_name']);
                     $message->files[$files['name']] = $attach;
                 }
             }
         }
     }
     // Custom Fields
     if (!empty($aFieldIds)) {
         foreach ($aFieldIds as $iIdx => $iFieldId) {
             if (!empty($iFieldId)) {
                 $field =& $fields[$iFieldId];
                 /* @var $field Model_CustomField */
                 $value = "";
                 switch ($field->type) {
                     case Model_CustomField::TYPE_SINGLE_LINE:
                     case Model_CustomField::TYPE_MULTI_LINE:
                     case Model_CustomField::TYPE_URL:
                         @($value = trim($aFollowUpA[$iIdx]));
                         break;
                     case Model_CustomField::TYPE_NUMBER:
                         @($value = $aFollowUpA[$iIdx]);
                         if (!is_numeric($value) || 0 == strlen($value)) {
                             $value = null;
                         }
                         break;
                     case Model_CustomField::TYPE_DATE:
                         if (false !== ($time = strtotime($aFollowUpA[$iIdx]))) {
                             @($value = intval($time));
                         }
                         break;
                     case Model_CustomField::TYPE_DROPDOWN:
                         @($value = $aFollowUpA[$iIdx]);
                         break;
                     case Model_CustomField::TYPE_MULTI_PICKLIST:
                         @($value = DevblocksPlatform::importGPC($_POST['followup_a_' . $iIdx], 'array', array()));
                         break;
                     case Model_CustomField::TYPE_CHECKBOX:
                         @($value = isset($aFollowUpA[$iIdx]) && !empty($aFollowUpA[$iIdx]) ? 1 : 0);
                         break;
                     case Model_CustomField::TYPE_MULTI_CHECKBOX:
                         @($value = DevblocksPlatform::importGPC($_POST['followup_a_' . $iIdx], 'array', array()));
                         break;
                     case Model_CustomField::TYPE_WORKER:
                         @($value = DevblocksPlatform::importGPC($_POST['followup_a_' . $iIdx], 'integer', 0));
                         break;
                 }
                 if (is_array($value) && !empty($value) || !is_array($value) && 0 != strlen($value)) {
                     $message->custom_fields[$iFieldId] = $value;
                 }
             }
         }
     }
     // Parse
     $ticket_id = CerberusParser::parseMessage($message);
     // It's possible for the parser to reject the message using pre-filters
     if (!empty($ticket_id) && null != ($ticket = DAO_Ticket::getTicket($ticket_id))) {
         $umsession->setProperty('support.write.last_opened', $ticket->mask);
     } else {
         $umsession->setProperty('support.write.last_opened', null);
     }
     // Clear any errors
     $umsession->setProperty('support.write.last_nature', null);
     $umsession->setProperty('support.write.last_nature_string', null);
     $umsession->setProperty('support.write.last_content', null);
     $umsession->setProperty('support.write.last_error', null);
     DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('portal', UmPortalHelper::getCode(), 'contact', 'confirm')));
 }