public function writeResponse(DevblocksHttpResponse $response) { $umsession = UmPortalHelper::getSession(); $stack = $response->path; $tpl = DevblocksPlatform::getTemplateService(); $tpl_path = dirname(dirname(__FILE__)) . '/templates/'; $tpl->assign('portal_code', UmPortalHelper::getCode()); $page_title = DAO_CommunityToolProperty::get(UmPortalHelper::getCode(), self::PARAM_PAGE_TITLE, 'Support Center'); $tpl->assign('page_title', $page_title); $login_handler = DAO_CommunityToolProperty::get(UmPortalHelper::getCode(), self::PARAM_LOGIN_HANDLER, ''); $tpl->assign('login_handler', $login_handler); $login_extension = DevblocksPlatform::getExtension($login_handler, true); $tpl->assign('login_extension', $login_extension); @($visible_modules = unserialize(DAO_CommunityToolProperty::get(UmPortalHelper::getCode(), self::PARAM_VISIBLE_MODULES, ''))); $tpl->assign('visible_modules', $visible_modules); @($active_user = $umsession->getProperty('sc_login', null)); $tpl->assign('active_user', $active_user); // Usermeet Session if (null == ($fingerprint = UmPortalHelper::getFingerprint())) { die("A problem occurred."); } $tpl->assign('fingerprint', $fingerprint); $module_uri = array_shift($stack); switch ($module_uri) { case 'ajax': $controller = new UmScAjaxController(null); $controller->handleRequest(new DevblocksHttpRequest($stack)); break; case 'rss': $controller = new UmScRssController(null); $controller->handleRequest(new DevblocksHttpRequest($stack)); break; case 'captcha': @($color = DevblocksPlatform::parseCsvString(DevblocksPlatform::importGPC($_REQUEST['color'], 'string', '40,40,40'))); @($bgcolor = DevblocksPlatform::parseCsvString(DevblocksPlatform::importGPC($_REQUEST['bgcolor'], 'string', '240,240,240'))); // Sanitize colors // [TODO] Sanitize numeric range for elements 0-2 if (3 != count($color)) { $color = array(40, 40, 40); } if (3 != count($bgcolor)) { $color = array(240, 240, 240); } header('Cache-control: max-age=0', true); // 1 wk // , must-revalidate header('Expires: ' . gmdate('D, d M Y H:i:s', time() - 604800) . ' GMT'); // 1 wk header('Content-type: image/jpeg'); // Get CAPTCHA secret passphrase $phrase = CerberusApplication::generatePassword(4); $umsession->setProperty(UmScApp::SESSION_CAPTCHA, $phrase); $im = @imagecreate(150, 70) or die("Cannot Initialize new GD image stream"); $background_color = imagecolorallocate($im, $bgcolor[0], $bgcolor[1], $bgcolor[2]); $text_color = imagecolorallocate($im, $color[0], $color[1], $color[2]); $font = DEVBLOCKS_PATH . 'resources/font/ryanlerch_-_Tuffy_Bold(2).ttf'; imagettftext($im, 24, mt_rand(0, 20), 5, 60 + 6, $text_color, $font, $phrase); imagejpeg($im, null, 85); imagedestroy($im); exit; break; case 'captcha.check': $entered = DevblocksPlatform::importGPC($_REQUEST['captcha'], 'string', ''); $captcha = $umsession->getProperty(UmScApp::SESSION_CAPTCHA, ''); if (!empty($entered) && !empty($captcha) && 0 == strcasecmp($entered, $captcha)) { echo 'true'; exit; } echo 'false'; exit; break; default: // Build the menu $modules = $this->_getModules(); $menu_modules = array(); if (is_array($modules)) { foreach ($modules as $uri => $module) { // Must be menu renderable if (!empty($module->manifest->params['menu_title']) && !empty($uri)) { $menu_modules[$uri] = $module; } } } $tpl->assign('menu', $menu_modules); // Modules if (isset($modules[$module_uri])) { $controller = $modules[$module_uri]; } else { // First menu item $controller = reset($menu_modules); } array_unshift($stack, $module_uri); $tpl->assign('module', $controller); $tpl->assign('module_response', new DevblocksHttpResponse($stack)); $tpl->display('devblocks:usermeet.core:support_center/index.tpl:portal_' . UmPortalHelper::getCode()); break; } }
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'))); }
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 = UmPortalHelper::getSession(); $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_q',$aFollowUpQ); $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); // 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, @$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.'); } // 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; $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', UmPortalHelper::getCode(), 'contact', 'confirm'))); }
public function writeResponse(DevblocksHttpResponse $response) { $umsession = UmPortalHelper::getSession(); $stack = $response->path; $tpl = DevblocksPlatform::getTemplateService(); $tpl->cache_lifetime = "0"; $tpl_path = dirname(dirname(__FILE__)) . '/templates/'; $tpl->assign('tpl_path', $tpl_path); $logo_url = DAO_CommunityToolProperty::get(UmPortalHelper::getCode(), self::PARAM_LOGO_URL, ''); $tpl->assign('logo_url', $logo_url); $page_title = DAO_CommunityToolProperty::get(UmPortalHelper::getCode(), self::PARAM_PAGE_TITLE, 'Support Center'); $tpl->assign('page_title', $page_title); $style_css = DAO_CommunityToolProperty::get(UmPortalHelper::getCode(), self::PARAM_STYLE_CSS, ''); $tpl->assign('style_css', $style_css); $footer_html = DAO_CommunityToolProperty::get(UmPortalHelper::getCode(), self::PARAM_FOOTER_HTML, ''); $tpl->assign('footer_html', $footer_html); $allow_logins = DAO_CommunityToolProperty::get(UmPortalHelper::getCode(), self::PARAM_ALLOW_LOGINS, 0); $tpl->assign('allow_logins', $allow_logins); $enabled_modules = DevblocksPlatform::parseCsvString(DAO_CommunityToolProperty::get(UmPortalHelper::getCode(), self::PARAM_ENABLED_MODULES, '')); $tpl->assign('enabled_modules', $enabled_modules); @($active_user = $umsession->getProperty('sc_login', null)); $tpl->assign('active_user', $active_user); // Usermeet Session if (null == ($fingerprint = UmPortalHelper::getFingerprint())) { die("A problem occurred."); } $tpl->assign('fingerprint', $fingerprint); $module_uri = array_shift($stack); switch ($module_uri) { case 'ajax': $controller = new UmScAjaxController(null); $controller->handleRequest(new DevblocksHttpRequest($stack)); break; case 'rss': $controller = new UmScRssController(null); $controller->handleRequest(new DevblocksHttpRequest($stack)); break; case 'captcha': header('Cache-control: max-age=0', true); // 1 wk // , must-revalidate header('Expires: ' . gmdate('D, d M Y H:i:s', time() - 604800) . ' GMT'); // 1 wk header('Content-type: image/jpeg'); // Get CAPTCHA secret passphrase $phrase = CerberusApplication::generatePassword(4); $umsession->setProperty(UmScApp::SESSION_CAPTCHA, $phrase); $im = @imagecreate(150, 70) or die("Cannot Initialize new GD image stream"); $background_color = imagecolorallocate($im, 240, 240, 240); $text_color = imagecolorallocate($im, 40, 40, 40); //233, 14, 91 $font = DEVBLOCKS_PATH . 'resources/font/ryanlerch_-_Tuffy_Bold(2).ttf'; imagettftext($im, 24, mt_rand(0, 20), 5, 60 + 6, $text_color, $font, $phrase); imagejpeg($im, null, 85); imagedestroy($im); exit; break; default: // Build the menu $modules = $this->_getModules(); $menu_modules = array(); if (is_array($modules)) { foreach ($modules as $uri => $module) { // Must be menu renderable if (!empty($module->manifest->params['menu_title']) && !empty($uri)) { $menu_modules[$uri] = $module; } } } $tpl->assign('menu', $menu_modules); if (isset($modules[$module_uri])) { $controller = $modules[$module_uri]; } else { // First menu item $controller = reset($menu_modules); } array_unshift($stack, $module_uri); $tpl->assign('module', $controller); $tpl->assign('module_response', new DevblocksHttpResponse($stack)); $tpl->display('file:' . $tpl_path . 'portal/sc/module/index.tpl'); break; } }