function saveConfiguration(Model_CommunityTool $instance) { // KB @($aFnrTopics = DevblocksPlatform::importGPC($_POST['topic_ids'], 'array', array())); $aFnrTopics = array_flip($aFnrTopics); DAO_CommunityToolProperty::set($instance->code, self::PARAM_FNR_TOPICS, serialize($aFnrTopics)); }
private function _handleCronSensorsPost($event) { $logger = DevblocksPlatform::getConsoleLog(); $translate = DevblocksPlatform::getTranslationService(); $sensors = DAO_Sensor::getAll(); // Check that all external sensors aren't over their M.I.A. time if (is_array($sensors)) { foreach ($sensors as $sensor) { /* @var $sensor Model_Sensor */ // Only external sensors if ('sensor.external' != $sensor->extension_id) { continue; } // Skip if the sensor hasn't run once yet if (0 == $sensor->updated_date) { continue; } $mia_secs = intval($sensor->params->mia_secs); $elapsed = time() - $sensor->updated_date; if ($mia_secs && $elapsed > $mia_secs) { $fields = array(DAO_Sensor::STATUS => 2, DAO_Sensor::FAIL_COUNT => intval($sensor->fail_count) + 1, DAO_Sensor::METRIC => $translate->_('sensor.status.mia'), DAO_Sensor::OUTPUT => $translate->_('sensor.status.mia')); DAO_Sensor::update($sensor->id, $fields); $logger->info($sensor->name . " is M.I.A. for {$elapsed} seconds."); } } } }
public static function getTemplateHandler() { $tpl = DevblocksPlatform::getTemplateService(); $tpl_path = dirname(__FILE__) . '/templates/'; $tpl->assign('path', $tpl_path); $tpl->cache_lifetime = "0"; $total_new_count = 0; foreach (DAO_WorkflowView::getGroupTotals() as $data) { $total_new_count += $data["total"]; } $tpl->assign('total_new_count', $total_new_count); $newest = isset($_SESSION["fluid_latest_seen"]) ? $_SESSION["fluid_latest_seen"] : time() - 3600; $worker = CerberusApplication::getActiveWorker(); $memberships = $worker->getMemberships(); $params = array(SearchFields_Ticket::TICKET_TEAM_ID => new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_TEAM_ID, 'in', array_keys($memberships)), SearchFields_Ticket::TICKET_DELETED => new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_DELETED, 'eq', 0), SearchFields_Ticket::TICKET_WAITING => new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_WAITING, 'eq', 0), SearchFields_Ticket::TICKET_CLOSED => new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_CLOSED, 'eq', 0), SearchFields_Ticket::TICKET_UPDATED_DATE => new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_UPDATED_DATE, '>', $newest)); list($results, $total) = DAO_Ticket::search(array(SearchFields_Ticket::TICKET_ID, SearchFields_Ticket::TICKET_MASK, SearchFields_Ticket::TICKET_SUBJECT, SearchFields_Ticket::TICKET_LAST_WROTE), $params, 5, 0, SearchFields_Ticket::TICKET_UPDATED_DATE, false, true); $tickets = array(); foreach ($results as $ticket) { if ($ticket[SearchFields_Ticket::TICKET_UPDATED_DATE] > $newest) { $newest = $ticket[SearchFields_Ticket::TICKET_UPDATED_DATE]; } $tickets[] = $ticket; } $_SESSION["fluid_latest_seen"] = $newest; $tpl->assign("recent_tickets_json", json_encode($tickets)); $tpl->assign("recent_ticket_count", json_encode($total)); return $tpl; }
function saveConfiguration() { // KB @($aFnrTopics = DevblocksPlatform::importGPC($_POST['topic_ids'], 'array', array())); $aFnrTopics = array_flip($aFnrTopics); DAO_CommunityToolProperty::set(UmPortalHelper::getCode(), self::PARAM_FNR_TOPICS, serialize($aFnrTopics)); }
function showTabAction() { @($ext_id = DevblocksPlatform::importGPC($_REQUEST['ext_id'], 'string', '')); if (null != ($tab_mft = DevblocksPlatform::getExtension($ext_id)) && null != ($inst = $tab_mft->createInstance()) && $inst instanceof Extension_ResearchTab) { $inst->showTab(); } }
function configure($instance) { $tpl = DevblocksPlatform::getTemplateService(); $tpl_path = dirname(dirname(__FILE__)) . '/templates/'; $tpl->assign('path', $tpl_path); $tpl->display($tpl_path . 'cron/heartbeat/config.tpl'); }
function render() { $tpl = DevblocksPlatform::getTemplateService(); $tpl->assign('path', $this->_TPL_PATH); $response = DevblocksPlatform::getHttpResponse(); $stack = $response->path; $tpl->display('file:' . $this->_TPL_PATH . 'welcome/index.tpl'); }
public static function isDatabaseEmpty() { $db = DevblocksPlatform::getDatabaseService(); if (is_null($db)) { return true; } $tables = $db->MetaTables('TABLE', true); return empty($tables); }
function saveConfiguration() { // @$iRequireLogin = DevblocksPlatform::importGPC($_POST['kb_require_login'],'integer',0); // DAO_CommunityToolProperty::set(UmPortalHelper::getCode(), self::PARAM_REQUIRE_LOGIN, $iRequireLogin); // KB @($aFnrTopics = DevblocksPlatform::importGPC($_POST['topic_ids'], 'array', array())); $aFnrTopics = array_flip($aFnrTopics); DAO_CommunityToolProperty::set(UmPortalHelper::getCode(), self::PARAM_FNR_TOPICS, serialize($aFnrTopics)); }
function generateTicketsAction() { require_once dirname(__FILE__) . '/api/API.class.php'; $tpl = DevblocksPlatform::getTemplateService(); $tpl_path = dirname(__FILE__) . '/templates/'; $tpl->assign('path', $tpl_path); $tpl->cache_lifetime = "0"; @($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'); }
function smarty_block_devblocks_url($params, $content, &$smarty) { $url = DevblocksPlatform::getUrlService(); $contents = $url->write($content, !empty($params['full']) ? true : false); if (!empty($params['assign'])) { $smarty->assign($params['assign'], $contents); } else { return $contents; } }
function saveConfiguration() { // RSS Feeds @($aNewsRssTitles = DevblocksPlatform::importGPC($_POST['news_rss_title'], 'array', array())); @($aNewsRssUrls = DevblocksPlatform::importGPC($_POST['news_rss_url'], 'array', array())); $aNewsRss = array(); foreach ($aNewsRssUrls as $idx => $rss) { if (empty($rss)) { unset($aNewsRss[$idx]); continue; } $aNewsRss[$aNewsRssTitles[$idx]] = $rss; } DAO_CommunityToolProperty::set(UmPortalHelper::getCode(), self::PARAM_NEWS_RSS, serialize($aNewsRss)); }
function authenticate() { // Pull from $_POST @($email = DevblocksPlatform::importGPC($_POST['email'])); @($password = DevblocksPlatform::importGPC($_POST['password'])); $worker = DAO_Worker::login($email, $password); if (!is_null($worker)) { $session = DevblocksPlatform::getSessionService(); $visit = new CerberusVisit(); $visit->setWorker($worker); $session->setVisit($visit); // [TODO] Only direct to /welcome when tour is enabled return true; } else { return false; } }
private function _renderRecentChangesRss($portal) { header("Content-Type: text/xml"); $xmlstr = <<<XML \t\t<rss version='2.0' xmlns:atom='http://www.w3.org/2005/Atom'> \t\t</rss> XML; $xml = new SimpleXMLElement($xmlstr); $translate = DevblocksPlatform::getTranslationService(); $url = DevblocksPlatform::getUrlService(); // Portal details $portal_name = DAO_CommunityToolProperty::get($portal, UmScApp::PARAM_PAGE_TITLE, ''); // Channel $channel = $xml->addChild('channel'); $channel->addChild('title', (!empty($portal_name) ? '[' . $portal_name . '] ' : '') . "Recently Changed Articles"); $channel->addChild('link', $url->write(sprintf('c=rss&kb=kb&a=recent_changes', $portal), true)); $channel->addChild('description', ''); // Limit topics to portal config @($topics = unserialize(DAO_CommunityToolProperty::get($portal, UmScKbController::PARAM_KB_ROOTS, ''))); if (empty($topics)) { return; } // Search Results list($results, $null) = DAO_KbArticle::search(array(SearchFields_KbArticle::TOP_CATEGORY_ID => new DevblocksSearchCriteria(SearchFields_KbArticle::TOP_CATEGORY_ID, 'in', array_keys($topics))), 25, 0, SearchFields_KbArticle::UPDATED, false, false); // [TODO] We should probably be building this feed with Zend Framework for compliance foreach ($results as $article) { $created = intval($article[SearchFields_KbArticle::UPDATED]); if (empty($created)) { $created = time(); } $eItem = $channel->addChild('item'); $escapedSubject = htmlspecialchars($article[SearchFields_KbArticle::TITLE], null, LANG_CHARSET_CODE); //filter out a couple non-UTF-8 characters (0xC and ESC) $escapedSubject = preg_replace("/[\f]/", '', $escapedSubject); $eTitle = $eItem->addChild('title', $escapedSubject); $eDesc = $eItem->addChild('description', htmlspecialchars($article[SearchFields_KbArticle::CONTENT], null, LANG_CHARSET_CODE)); $link = $url->write('c=kb&a=article&id=' . $article[SearchFields_KbArticle::ID], true); $eLink = $eItem->addChild('link', $link); $eDate = $eItem->addChild('pubDate', gmdate('D, d M Y H:i:s T', $created)); $eGuid = $eItem->addChild('guid', md5($escapedSubject . $link . $created)); $eGuid->addAttribute('isPermaLink', "false"); } echo $xml->asXML(); }
function showTab() { @($ticket_id = DevblocksPlatform::importGPC($_REQUEST['ticket_id'], 'integer', 0)); $tpl = DevblocksPlatform::getTemplateService(); $tpl->cache_lifetime = "0"; $tpl_path = dirname(dirname(__FILE__)) . '/templates/'; // $tpl->assign('response_uri', 'config/attachments'); $defaults = new C4_AbstractViewModel(); $defaults->class_name = 'C4_AttachmentView'; $defaults->name = 'Attachements View'; $defaults->id = 'ticket_view_attachements'; $defaults->renderLimit = 15; $view_attachements = C4_AbstractViewLoader::getView('ticket_view_attachements', $defaults); $view_attachements->params = array(SearchFields_Attachment::TICKET_ID => new DevblocksSearchCriteria(SearchFields_Attachment::TICKET_ID, DevblocksSearchCriteria::OPER_EQ, $ticket_id)); $view_attachements->renderPage = 0; C4_AbstractViewLoader::setView($view_attachements->id, $view_attachements); $tpl->assign('view_attachements', $view_attachements); $tpl->display('file:' . $tpl_path . 'attachments/index.tpl'); }
/** * exec_sendfax * * @param string command * @return array */ function sendFax($phone_number, $message, $subject, $to, $account_name, $from = null) { // sendfax -f "*****@*****.**" -D -R -r "Test Fax" -x "Account Name" -d "RecipientName@4106311699" /home/rmiddle/test.txt $settings = DevblocksPlatform::getPluginSettingsService(); if (empty($from)) { @($from = $settings->get('feg.core', FegSettings::DEFAULT_REPLY_FROM, $_SERVER['SERVER_ADMIN'])); } $command = "sendfax "; $command .= sprintf("-f '%s' ", $from); $command .= "-D -R "; $command .= sprintf("-r '%s' ", $subject); $command .= sprintf("-x '%s' ", $account_name); $command .= sprintf("-d '%s@%s' ", $to, $phone_number); $tempfilename = tempnam(APP_TEMP_PATH . "/fax_cache", 'fax_message-'); $temp_fh = fopen($tempfilename, 'w') or die($php_errormsg); fputs($temp_fh, $message); fclose($temp_fh) or die($php_errormsg); // Generate Text file of message. $command .= sprintf("'%s' ", $tempfilename); $o = exec($command . " 2>&1", $sendfax_output, $retval); $debug = DEBUG_MODE; if ($retval == 0) { // success if ($debug) { echo "<p>{$command}"; } $result = str_replace("(", "", $sendfax_output[0]); $result = str_replace(")", "", $result); // request id is 80 (group id 80) for host localhost (3 files) // request id is 81 (group id 81) for host localhost (1 file) $output = split(" ", $result); return array('status' => true, 'jobid' => $output[3], 'groupid' => $output[6], 'host' => $output[9], 'numfiles' => $output[10]); } if ($debug) { echo "<p>"; print_r($o); echo "<p>"; print_r($sendfax_output); echo "<p>{$command}<br>"; } $forlog = implode("\n", $sendfax_output); return array('status' => false, 'output' => $forlog); }
function showTab() { @($org = DevblocksPlatform::importGPC($_REQUEST['org_id'])); $tpl = DevblocksPlatform::getTemplateService(); $tpl_path = dirname(dirname(__FILE__)) . '/templates/'; $tpl->assign('path', $tpl_path); $contact = DAO_ContactOrg::get($org); $tpl->assign('contact', $contact); $defaults = new C4_AbstractViewModel(); $defaults->class_name = 'View_ContactOrg'; $defaults->id = View_ContactOrg::DEFAULT_ID; $view = C4_AbstractViewLoader::getView(View_ContactOrg::DEFAULT_ID, $defaults); $view->params = array(new DevblocksSearchCriteria(SearchFields_ContactOrg::PARENT_ORG_ID, '=', $contact->id)); $tpl->assign('view', $view); $tpl->assign('contacts_page', 'orgs'); $tpl->assign('response_uri', 'contacts/orgs'); $tpl->assign('view_fields', View_ContactOrg::getFields()); $tpl->assign('view_searchable_fields', View_ContactOrg::getSearchFields()); $tpl->display('file:' . $tpl_path . 'childorgs.tpl'); exit; }
static function getValue($context, $context_values) { $total_time_all = -1; if ($context_values['id']) { // Adds total time worked per ticket to the token list. $db = DevblocksPlatform::getDatabaseService(); $sql = "SELECT sum(tte.time_actual_mins) mins "; $sql .= "FROM timetracking_entry tte "; $sql .= sprintf("WHERE tte.source_id = %d ", $context_values['id']); $sql .= "AND tte.source_extension_id = 'timetracking.source.ticket' "; $sql .= "GROUP BY tte.source_id "; $rs = $db->Execute($sql) or die(__CLASS__ . '(' . __LINE__ . ')' . ':' . $db->ErrorMsg()); if ($row = mysql_fetch_assoc($rs)) { $total_time_all = intval($row['mins']); } else { $total_time_all = 0; } mysql_free_result($rs); } return $total_time_all; }
function handleRequest(DevblocksHttpRequest $request) { $translate = DevblocksPlatform::getTranslationService(); // [TODO] Do we want any concept of authentication here? $stack = $request->path; array_shift($stack); // rss $hash = array_shift($stack); $feed = DAO_ViewRss::getByHash($hash); if (empty($feed)) { die($translate->_('rss.bad_feed')); } // Sources $rss_sources = DevblocksPlatform::getExtensions('cerberusweb.rss.source', true); if (isset($rss_sources[$feed->source_extension])) { $rss_source =& $rss_sources[$feed->source_extension]; /* @var $rss_source Extension_RssSource */ header("Content-Type: text/xml"); echo $rss_source->getFeedAsRss($feed); } exit; }
function handleRequest(DevblocksHttpRequest $request) { $translate = DevblocksPlatform::getTranslationService(); $stack = $request->path; // URLS like: /files/10000/plaintext.txt array_shift($stack); // files $file_id = array_shift($stack); // 10000 $file_name = array_shift($stack); // plaintext.txt // Security if (null == ($active_worker = CerberusApplication::getActiveWorker())) { die($translate->_('common.access_denied')); } if (empty($file_id) || empty($file_name) || null == ($file = DAO_Attachment::get($file_id))) { die($translate->_('files.not_found')); } // Security $message = DAO_Ticket::getMessage($file->message_id); if (null == ($ticket = DAO_Ticket::getTicket($message->ticket_id))) { die($translate->_('common.access_denied')); } // Security $active_worker_memberships = $active_worker->getMemberships(); if (null == $active_worker_memberships[$ticket->team_id]) { die($translate->_('common.access_denied')); } // Set headers header("Expires: Mon, 26 Nov 1962 00:00:00 GMT\n"); header("Last-Modified: " . gmdate("D,d M YH:i:s") . " GMT\n"); header("Cache-control: private\n"); header("Pragma: no-cache\n"); header("Content-Type: " . $file->mime_type . "\n"); header("Content-transfer-encoding: binary\n"); header("Content-Length: " . $file->getFileSize() . "\n"); echo $file->getFileContents(); exit; }
function showTab() { @($ticket_id = DevblocksPlatform::importGPC($_REQUEST['ticket_id'], 'integer', 0)); $tpl_path = dirname(dirname(__FILE__)) . '/templates/'; $tpl = DevblocksPlatform::getTemplateService(); //$visit = CerberusApplication::getVisit(); //$visit->set(Extension_ConfigTab::POINT, 'attachments'); $message_ids = array_keys(DAO_Message::getMessagesByTicket($ticket_id)); $comment_ids = array_keys(DAO_Comment::getByContext(CerberusContexts::CONTEXT_TICKET, $ticket_id)); $attachment_links = array_merge(DAO_AttachmentLink::getByContextIds(CerberusContexts::CONTEXT_MESSAGE, $message_ids), DAO_AttachmentLink::getByContextIds(CerberusContexts::CONTEXT_COMMENT, $comment_ids)); $defaults = new C4_AbstractViewModel(); $defaults->class_name = 'View_AttachmentLink'; $defaults->name = 'Attachements'; $defaults->id = '_ticket_view_attachements'; $defaults->renderLimit = 15; $view = C4_AbstractViewLoader::getView($defaults->id, $defaults); $view->renderPage = 0; $view->addParams(array(SearchFields_AttachmentLink::GUID => new DevblocksSearchCriteria(SearchFields_AttachmentLink::GUID, 'in', array_keys($attachment_links))), true); C4_AbstractViewLoader::setView($view->id, $view); $tpl->assign('view', $view); $tpl->display('file:' . $tpl_path . 'attachments/index.tpl'); }
/** * @param Model_DevblocksEvent $event */ function handleEvent(Model_DevblocksEvent $event) { switch ($event->id) { case 'cron.maint': $records_removed = 0; $logger = DevblocksPlatform::getConsoleLog(); $logger->info("[Answernet.com Maint] Starting Purging Contact Addresses task"); @set_time_limit(0); // Unlimited (if possible) @ini_set('memory_limit', '128M'); $logger->info("[Answernet.com Maint] Overloaded memory_limit to: " . ini_get('memory_limit')); $logger->info("[Answernet.com Maint] Overloaded max_execution_time to: " . ini_get('max_execution_time')); $runtime = microtime(true); //Do something $db = DevblocksPlatform::getDatabaseService(); $sql = "SELECT a.id "; $sql .= "FROM address a "; $sql .= "LEFT JOIN message m ON a.id = m.address_id "; $sql .= "LEFT JOIN requester r ON a.id = r.address_id "; $sql .= "LEFT JOIN ticket_comment tc ON a.id = tc.address_id "; $sql .= "WHERE a.contact_org_id = 0 "; $sql .= "AND m.address_id IS NULL "; $sql .= "AND r.address_id IS NULL "; $sql .= "AND tc.address_id IS NULL "; $sql .= "ORDER BY a.id ASC "; $rs = $db->Execute($sql); while (!$rs->EOF) { // Loop though the records. DAO_Address::delete($rs->fields['id']); // Increament the records removed connecter $records_removed++; $rs->MoveNext(); } $logger->info("[Answernet.com Maint] Total Records Removed: " . $records_removed); $logger->info("[Answernet.com Maint] Total Runtime: " . (microtime(true) - $runtime) * 1000 . " ms"); break; } }
function saveAccountAction() { @($first_name = DevblocksPlatform::importGPC($_REQUEST['first_name'], 'string', '')); @($last_name = DevblocksPlatform::importGPC($_REQUEST['last_name'], 'string', '')); @($change_password = DevblocksPlatform::importGPC($_REQUEST['change_password'], 'string', '')); @($change_password2 = DevblocksPlatform::importGPC($_REQUEST['change_password2'], 'string', '')); $tpl = DevblocksPlatform::getTemplateService(); $umsession = UmPortalHelper::getSession(); $active_user = $umsession->getProperty('sc_login', null); if (!empty($active_user)) { $fields = array(DAO_Address::FIRST_NAME => $first_name, DAO_Address::LAST_NAME => $last_name); DAO_Address::update($active_user->id, $fields); $tpl->assign('account_success', true); if (!empty($change_password)) { if (0 == strcmp($change_password, $change_password2)) { DAO_AddressAuth::update($active_user->id, array(DAO_AddressAuth::PASS => md5($change_password))); } else { $tpl->assign('account_error', "The passwords you entered did not match."); } } } DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('portal', UmPortalHelper::getCode(), 'account'))); }
function showTab() { @($ticket_id = DevblocksPlatform::importGPC($_REQUEST['ticket_id'], 'integer', 0)); $tpl = DevblocksPlatform::getTemplateService(); $tpl_path = dirname(dirname(__FILE__)) . '/templates/'; $tpl->assign('path', $tpl_path); $ticket = DAO_Ticket::getTicket($ticket_id); $tpl->assign('ticket_id', $ticket_id); $tpl->assign('ticket', $ticket); // Receate the original spam decision $words = DevblocksPlatform::parseCsvString($ticket->interesting_words); $words = DAO_Bayes::lookupWordIds($words); // Calculate word probabilities foreach ($words as $idx => $word) { /* @var $word CerberusBayesWord */ $word->probability = CerberusBayes::calculateWordProbability($word); } $tpl->assign('words', $words); // Determine what the spam probability would be if the decision was made right now $analysis = CerberusBayes::calculateTicketSpamProbability($ticket_id, true); $tpl->assign('analysis', $analysis); $tpl->display('file:' . $tpl_path . 'ticket_tab/index.tpl'); }
/** * Loads parameters unique to this extension instance. Returns an * associative array indexed by parameter key. * * @private * @return array */ private function _getParams() { // static $params = null; if (empty($this->id)) { return null; } // if(null != $params) // return $params; $params = $this->manifest->params; $db = DevblocksPlatform::getDatabaseService(); $prefix = APP_DB_PREFIX != '' ? APP_DB_PREFIX . '_' : ''; // [TODO] Cleanup $sql = sprintf("SELECT property,value " . "FROM %sproperty_store " . "WHERE extension_id=%s ", $prefix, $db->qstr($this->id)); $rs = $db->Execute($sql) or die(__CLASS__ . ':' . $db->ErrorMsg()); /* @var $rs ADORecordSet */ if (is_a($rs, 'ADORecordSet')) { while (!$rs->EOF) { $params[$rs->fields['property']] = $rs->fields['value']; $rs->MoveNext(); } } return $params; }
function handleRequest(DevblocksHttpRequest $request) { @($reload = DevblocksPlatform::importGPC($_REQUEST['reload'], 'integer', 0)); @($loglevel = DevblocksPlatform::importGPC($_REQUEST['loglevel'], 'integer', 0)); $logger = DevblocksPlatform::getConsoleLog(); $translate = DevblocksPlatform::getTranslationService(); $settings = CerberusSettings::getInstance(); $authorized_ips_str = $settings->get(CerberusSettings::AUTHORIZED_IPS); $authorized_ips = DevblocksPlatform::parseCrlfString($authorized_ips_str); $authorized_ip_defaults = DevblocksPlatform::parseCsvString(AUTHORIZED_IPS_DEFAULTS); $authorized_ips = array_merge($authorized_ips, $authorized_ip_defaults); @($is_ignoring_wait = DevblocksPlatform::importGPC($_REQUEST['ignore_wait'], 'integer', 0)); $pass = false; foreach ($authorized_ips as $ip) { if (substr($ip, 0, strlen($ip)) == substr($_SERVER['REMOTE_ADDR'], 0, strlen($ip))) { $pass = true; break; } } if (!$pass) { echo vsprintf($translate->_('cron.ip_unauthorized'), $_SERVER['REMOTE_ADDR']); return; } $stack = $request->path; array_shift($stack); // cron $job_id = array_shift($stack); @set_time_limit(0); // Unlimited (if possible) $url = DevblocksPlatform::getUrlService(); $timelimit = intval(ini_get('max_execution_time')); if ($reload) { $reload_url = sprintf("%s?reload=%d&loglevel=%d&ignore_wait=%d", $url->write('c=cron' . ($job_id ? "&a=" . $job_id : "")), intval($reload), intval($loglevel), intval($is_ignoring_wait)); echo "<HTML>" . "<HEAD>" . "<TITLE></TITLE>" . "<meta http-equiv='Refresh' content='" . intval($reload) . ";" . $reload_url . "'>" . "<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>" . "</HEAD>" . "<BODY>"; // onload=\"setTimeout(\\\"window.location.replace('".$url->write('c=cron')."')\\\",30);\" } // [TODO] Determine if we're on a time limit under 60 seconds $cron_manifests = DevblocksPlatform::getExtensions('cerberusweb.cron', true, true); $jobs = array(); if (empty($job_id)) { // do everything // Determine who wants to go first by next time and longest waiting $nexttime = time() + 86400; if (is_array($cron_manifests)) { foreach ($cron_manifests as $idx => $instance) { /* @var $instance CerberusCronPageExtension */ $lastrun = $instance->getParam(CerberusCronPageExtension::PARAM_LASTRUN, 0); if ($instance->isReadyToRun($is_ignoring_wait)) { if ($timelimit) { if ($lastrun < $nexttime) { $jobs[0] = $cron_manifests[$idx]; $nexttime = $lastrun; } } else { $jobs[] =& $cron_manifests[$idx]; } } } } } else { // single job $manifest = DevblocksPlatform::getExtension($job_id, false, true); if (empty($manifest)) { exit; } $instance = $manifest->createInstance(); if ($instance) { if ($instance->isReadyToRun($is_ignoring_wait)) { $jobs[0] =& $instance; } } } if (!empty($jobs)) { foreach ($jobs as $nextjob) { $nextjob->setParam(CerberusCronPageExtension::PARAM_LOCKED, time()); $nextjob->_run(); } } elseif ($reload) { $logger->info(vsprintf($translate->_('cron.nothing_to_do'), intval($reload))); } if ($reload) { echo "</BODY>" . "</HTML>"; } exit; }
private function _sendForwards($event, $is_inbound) { @($ticket_id = $event->params['ticket_id']); @($send_worker_id = $event->params['worker_id']); $url_writer = DevblocksPlatform::getUrlService(); $ticket = DAO_Ticket::get($ticket_id); // (Action) Forward Email To: // Sanitize and combine all the destination addresses $context_workers = CerberusContexts::getWorkers(CerberusContexts::CONTEXT_TICKET, $ticket->id); if (!is_array($context_workers)) { return; } foreach ($context_workers as $next_worker) { $notify_emails = $next_worker->email; if (empty($notify_emails)) { continue; } } // [TODO] This could be more efficient $messages = DAO_Message::getMessagesByTicket($ticket_id); $message = end($messages); // last message unset($messages); $headers = $message->getHeaders(); // The whole flipping Swift section needs wrapped to catch exceptions try { $settings = DevblocksPlatform::getPluginSettingsService(); $reply_to = $settings->get('cerberusweb.core', CerberusSettings::DEFAULT_REPLY_FROM, CerberusSettingsDefaults::DEFAULT_REPLY_FROM); // See if we need a group-specific reply-to if (!empty($ticket->team_id)) { @($group_from = DAO_GroupSettings::get($ticket->team_id, DAO_GroupSettings::SETTING_REPLY_FROM, '')); if (!empty($group_from)) { $reply_to = $group_from; } } $sender = DAO_Address::get($message->address_id); $sender_email = strtolower($sender->email); $sender_split = explode('@', $sender_email); if (!is_array($sender_split) || count($sender_split) != 2) { return; } // If return-path is blank if (isset($headers['return-path']) && $headers['return-path'] == '<>') { return; } // Ignore bounces if ($sender_split[0] == "postmaster" || $sender_split[0] == "mailer-daemon") { return; } // Ignore autoresponses autoresponses if (isset($headers['auto-submitted']) && $headers['auto-submitted'] != 'no') { return; } // Attachments $attachments = $message->getAttachments(); $mime_attachments = array(); if (is_array($attachments)) { foreach ($attachments as $attachment) { if (0 == strcasecmp($attachment->display_name, 'original_message.html')) { continue; } $attachment_path = APP_STORAGE_PATH . '/attachments/'; // [TODO] This is highly redundant in the codebase if (!file_exists($attachment_path . $attachment->filepath)) { continue; } $attach = Swift_Attachment::fromPath($attachment_path . $attachment->filepath); if (!empty($attachment->display_name)) { $attach->setFilename($attachment->display_name); } $mime_attachments[] = $attach; } } // Send copies $mail_service = DevblocksPlatform::getMailService(); $mailer = $mail_service->getMailer(CerberusMail::getMailerDefaults()); $mail = $mail_service->createMessage(); /* @var $mail Swift_Message */ $mail->setTo(array($notify_emails)); $mail->setFrom(array($sender->email)); $mail->setReplyTo($reply_to); $mail->setReturnPath($reply_to); $mail->setSubject(sprintf("[RW: %s #%s]: %s", $is_inbound ? 'inbound' : 'outbound', $ticket->mask, $ticket->subject)); $hdrs = $mail->getHeaders(); if (null !== @($msgid = $headers['message-id'])) { $hdrs->addTextHeader('Message-Id', $msgid); } if (null !== @($in_reply_to = $headers['in-reply-to'])) { $hdrs->addTextHeader('References', $in_reply_to); $hdrs->addTextHeader('In-Reply-To', $in_reply_to); } $hdrs->addTextHeader('X-Mailer', 'Cerberus Helpdesk (Build ' . APP_BUILD . ')'); $hdrs->addTextHeader('Precedence', 'List'); $hdrs->addTextHeader('Auto-Submitted', 'auto-generated'); $mail->setBody($message->getContent()); // Send message attachments with watcher if (is_array($mime_attachments)) { foreach ($mime_attachments as $mime_attachment) { $mail->attach($mime_attachment); } } $result = $mailer->send($mail); } catch (Exception $e) { if (!empty($message_id)) { $fields = array(DAO_MessageNote::MESSAGE_ID => $message_id, DAO_MessageNote::CREATED => time(), DAO_MessageNote::WORKER_ID => 0, DAO_MessageNote::CONTENT => 'Exception thrown while sending watcher email: ' . $e->getMessage(), DAO_MessageNote::TYPE => Model_MessageNote::TYPE_ERROR); DAO_MessageNote::create($fields); } } }
function viewSortByAction(DevblocksHttpRequest $request) { @($view_id = DevblocksPlatform::importGPC($_REQUEST['id'], 'string', '')); @($sort_by = DevblocksPlatform::importGPC($_REQUEST['sort_by'], 'string', '')); if (null != ($view = UmScAbstractViewLoader::getView('', $view_id))) { $fields = $view->getColumns(); if (isset($fields[$sort_by])) { if (0 == strcasecmp($view->renderSortBy, $sort_by)) { // clicked same col? $view->renderSortAsc = !(bool) $view->renderSortAsc; // flip order } else { $view->renderSortBy = $sort_by; $view->renderSortAsc = true; } $view->renderPage = 0; UmScAbstractViewLoader::setView($view->id, $view); } $view->render(); } }
function writeResponse(DevblocksHttpResponse $response) { $tpl = DevblocksPlatform::getTemplateService(); $tpl->display("devblocks:usermeet.core:support_center/home/index.tpl:portal_" . UmPortalHelper::getCode()); }
function savePluginsAction() { $translate = DevblocksPlatform::getTranslationService(); $worker = CerberusApplication::getActiveWorker(); if (!$worker || !$worker->is_superuser) { echo $translate->_('common.access_denied'); return; } if (DEMO_MODE) { DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('config', 'plugins'))); return; } @($plugins_enabled = DevblocksPlatform::importGPC($_REQUEST['plugins_enabled'], 'array')); $pluginStack = DevblocksPlatform::getPluginRegistry(); if (is_array($plugins_enabled)) { foreach ($plugins_enabled as $plugin_id) { $plugin = $pluginStack[$plugin_id]; $plugin->setEnabled(true); unset($pluginStack[$plugin_id]); } } // [JAS]: Clear unchecked plugins foreach ($pluginStack as $plugin) { // [JAS]: We can't force disable core here [TODO] Improve if ($plugin->id == 'cerberusweb.core') { continue; } $plugin->setEnabled(false); } DevblocksPlatform::clearCache(); // Run any enabled plugin patches // [TODO] Should the platform do this automatically on enable in order? $patchMgr = DevblocksPlatform::getPatchService(); $patches = DevblocksPlatform::getExtensions("devblocks.patch.container", false, true); if (is_array($patches)) { foreach ($patches as $patch_manifest) { /* @var $patch_manifest DevblocksExtensionManifest */ $container = $patch_manifest->createInstance(); /* @var $container DevblocksPatchContainerExtension */ $patchMgr->registerPatchContainer($container); } } if (!$patchMgr->run()) { // fail die("Failed updating plugins."); // [TODO] Make this more graceful } // Reload plugin translations DAO_Translation::reloadPluginStrings(); DevblocksPlatform::redirect(new DevblocksHttpResponse(array('config', 'plugins'))); }