예제 #1
0
 function isVisible()
 {
     // check login
     $visit = PortSensorApplication::getVisit();
     if (empty($visit)) {
         return false;
     } else {
         return true;
     }
 }
예제 #2
0
 function run(DevblocksHttpResponse $response, Smarty $tpl)
 {
     $path = $response->path;
     $callouts = PortSensorApplication::getTourCallouts();
     switch (array_shift($path)) {
         case 'welcome':
             $tour = array('title' => 'Welcome!', 'body' => "This assistant will help you become familiar with the application by following along and providing information about the current page.  You may follow the 'Points of Interest' links highlighted below to read tips about nearby functionality.", 'callouts' => array($callouts['tourHeaderMenu']));
             break;
         case "preferences":
             $tour = array('title' => 'Preferences', 'body' => 'This screen allows you to change the personal preferences on your account.');
             break;
         case "setup":
             $tour = array('title' => 'Setup', 'body' => '...');
             break;
         case NULL:
         case 'home':
             $tour = array('title' => 'Home', 'body' => '...', 'callouts' => array());
             break;
     }
     if (!empty($tour)) {
         $tpl->assign('tour', $tour);
     }
 }
예제 #3
0
 function showTabSensorsAction()
 {
     $visit = PortSensorApplication::getVisit();
     $translate = DevblocksPlatform::getTranslationService();
     $active_worker = PortSensorApplication::getActiveWorker();
     $tpl = DevblocksPlatform::getTemplateService();
     $tpl->assign('path', $this->_TPL_PATH);
     // Select tab
     //		$visit->set(PortSensorVisit::KEY_HOME_SELECTED_TAB, 'sensors');
     // My Notifications
     $sensorsView = Ps_AbstractViewLoader::getView(self::VIEW_ACTIVE_SENSORS);
     //		$title = vsprintf($translate->_('home.my_notifications.view.title'), $active_worker->getName());
     if (null == $sensorsView) {
         $sensorsView = new Ps_SensorView();
         $sensorsView->id = self::VIEW_ACTIVE_SENSORS;
         //			$sensorsView->name = $title;
         $sensorsView->renderLimit = 25;
         $sensorsView->renderPage = 0;
         $sensorsView->renderSortBy = SearchFields_Sensor::NAME;
         $sensorsView->renderSortAsc = 1;
     }
     // Overload criteria
     $sensorsView->name = 'Active Sensors';
     $sensorsView->params = array(SearchFields_Sensor::IS_DISABLED => new DevblocksSearchCriteria(SearchFields_Sensor::IS_DISABLED, '=', 0));
     /*
      * [TODO] This doesn't need to save every display, but it was possible to 
      * lose the params in the saved version of the view in the DB w/o recovery.
      * This should be moved back into the if(null==...) check in a later build.
      */
     Ps_AbstractViewLoader::setView($sensorsView->id, $sensorsView);
     $tpl->assign('view', $sensorsView);
     $tpl->display('file:' . $this->_TPL_PATH . 'home/tabs/sensors/index.tpl');
 }
예제 #4
0
 function saveLicensesAction()
 {
     $translate = DevblocksPlatform::getTranslationService();
     $settings = DevblocksPlatform::getPluginSettingsService();
     $worker = PortSensorApplication::getActiveWorker();
     if (!$worker || !$worker->is_superuser) {
         echo $translate->_('common.access_denied');
         return;
     }
     @($key = DevblocksPlatform::importGPC($_POST['key'], 'string', ''));
     @($email = DevblocksPlatform::importGPC($_POST['email'], 'string', ''));
     @($do_delete = DevblocksPlatform::importGPC($_POST['do_delete'], 'integer', 0));
     if (!empty($do_delete)) {
         $settings->set('portsensor.core', PortSensorSettings::LICENSE, '');
         DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('setup', 'settings')));
         return;
     }
     if (empty($key) || empty($email)) {
         DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('setup', 'settings', 'empty')));
         return;
     }
     if (null == ($valid = PortSensorLicense::validate($key, $email)) || 5 != count($valid)) {
         DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('setup', 'settings', 'invalid')));
         return;
     }
     /*
      * [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.portsensor.com/
      */
     $license = $valid;
     $settings->set('portsensor.core', PortSensorSettings::LICENSE, serialize($license));
     DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('setup', 'settings')));
 }
예제 #5
0
 function saveSensorPeekAction()
 {
     $translate = DevblocksPlatform::getTranslationService();
     $active_worker = PortSensorApplication::getActiveWorker();
     // [TODO] ACL
     // return;
     @($id = DevblocksPlatform::importGPC($_POST['id'], 'integer'));
     @($view_id = DevblocksPlatform::importGPC($_POST['view_id'], 'string'));
     @($name = DevblocksPlatform::importGPC($_POST['name'], 'string'));
     @($extension_id = DevblocksPlatform::importGPC($_POST['extension_id'], 'string'));
     @($disabled = DevblocksPlatform::importGPC($_POST['is_disabled'], 'integer', 0));
     @($delete = DevblocksPlatform::importGPC($_POST['do_delete'], 'integer', 0));
     // [TODO] The superuser set bit here needs to be protected by ACL
     if (empty($name)) {
         $name = "New Sensor";
     }
     if (!empty($id) && !empty($delete)) {
         DAO_Sensor::delete($id);
     } else {
         $fields = array(DAO_Sensor::NAME => $name, DAO_Sensor::EXTENSION_ID => $extension_id, DAO_Sensor::IS_DISABLED => $disabled);
         if (empty($id)) {
             $id = DAO_Sensor::create($fields);
         } else {
             DAO_Sensor::update($id, $fields);
         }
         // Save sensor extension config
         if (!empty($extension_id)) {
             if (null != ($ext = DevblocksPlatform::getExtension($extension_id, true))) {
                 if (null != ($sensor = DAO_Sensor::get($id)) && $ext instanceof Extension_Sensor) {
                     $ext->saveConfig($sensor);
                 }
             }
         }
         // Custom field saves
         @($field_ids = DevblocksPlatform::importGPC($_POST['field_ids'], 'array', array()));
         DAO_CustomFieldValue::handleFormPost(PsCustomFieldSource_Sensor::ID, $id, $field_ids);
     }
     if (!empty($view_id)) {
         $view = Ps_AbstractViewLoader::getView($view_id);
         $view->render();
     }
 }
예제 #6
0
require getcwd() . '/framework.config.php';
require DEVBLOCKS_PATH . 'Devblocks.class.php';
require APP_PATH . '/api/Application.class.php';
header("Content-type: text/html; charset=" . LANG_CHARSET_CODE);
$request = DevblocksPlatform::readRequest();
DevblocksPlatform::init();
DevblocksPlatform::setExtensionDelegate('PS_DevblocksExtensionDelegate');
$session = DevblocksPlatform::getSessionService();
$settings = DevblocksPlatform::getPluginSettingsService();
$worker = PortSensorApplication::getActiveWorker();
// Localization
DevblocksPlatform::setLocale(isset($_SESSION['locale']) && !empty($_SESSION['locale']) ? $_SESSION['locale'] : 'en_US');
if (isset($_SESSION['timezone'])) {
    @date_default_timezone_set($_SESSION['timezone']);
}
$tpl = DevblocksPlatform::getTemplateService();
$tpl->assign('translate', DevblocksPlatform::getTranslationService());
$tpl->assign('session', $_SESSION);
$tpl->assign('visit', $session->getVisit());
$tpl->assign('active_worker', $worker);
$tpl->assign('settings', $settings);
$tpl->assign('core_tpl', APP_PATH . '/features/portsensor.core/templates/');
if (!empty($worker)) {
    //	$active_worker_memberships = $worker->getMemberships();
    //	$tpl->assign('active_worker_memberships', $active_worker_memberships);
    //	$keyboard_shortcuts = intval(DAO_WorkerPref::get($worker->id,'keyboard_shortcuts', 1));
    //	$tpl->assign('pref_keyboard_shortcuts', $keyboard_shortcuts);
}
PortSensorApplication::processRequest($request, true);
exit;
예제 #7
0
 function doRecoverStep1Action()
 {
     $translate = DevblocksPlatform::getTranslationService();
     @($email = DevblocksPlatform::importGPC($_REQUEST['email'], 'string'));
     $worker = null;
     $results = DAO_Worker::getWhere(sprintf("%s = %s", DAO_Worker::EMAIL, Ps_ORMHelper::qstr($email)));
     if (!empty($results)) {
         $worker = array_shift($results);
     }
     if (empty($email) || empty($worker)) {
         return;
     }
     $_SESSION[self::KEY_FORGOT_EMAIL] = $email;
     try {
         $code = PortSensorApplication::generatePassword(10);
         $_SESSION[self::KEY_FORGOT_SENTCODE] = $code;
         $to = $email;
         $subject = $translate->_('login.forgot.mail.subject');
         $body = vsprintf($translate->_('login.forgot.mail.body'), $code);
         PortSensorMail::quickSend($to, $subject, $body);
     } catch (Exception $e) {
         DevblocksPlatform::redirect(new DevblocksHttpResponse(array('login', 'forgot', 'step1', 'failed')));
     }
     DevblocksPlatform::redirect(new DevblocksHttpResponse(array('login', 'forgot', 'step2')));
 }
예제 #8
0
 function handleRequest(DevblocksHttpRequest $request)
 {
     @set_time_limit(0);
     // no timelimit (when possible)
     $translate = DevblocksPlatform::getTranslationService();
     $stack = $request->path;
     array_shift($stack);
     // update
     $cache = DevblocksPlatform::getCacheService();
     /* @var $cache _DevblocksCacheManager */
     switch (array_shift($stack)) {
         case 'locked':
             if (!DevblocksPlatform::versionConsistencyCheck()) {
                 $url = DevblocksPlatform::getUrlService();
                 echo "<h1>PortSensor</h1>";
                 echo "The application is currently waiting for an administrator to finish upgrading. " . "Please wait a few minutes and then " . sprintf("<a href='%s'>try again</a>.<br><br>", $url->write('c=update&a=locked'));
                 echo sprintf("If you're an admin you may <a href='%s'>finish the upgrade</a>.", $url->write('c=update'));
             } else {
                 DevblocksPlatform::redirect(new DevblocksHttpResponse(array('login')));
             }
             break;
         default:
             $path = APP_TEMP_PATH . DIRECTORY_SEPARATOR;
             $file = $path . 'psupdate_lock';
             $settings = DevblocksPlatform::getPluginSettingsService();
             $authorized_ips_str = $settings->get('portsensor.core', PortSensorSettings::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 this IP authorized?
             $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->_('update.ip_unauthorized'), $_SERVER['REMOTE_ADDR']);
                 return;
             }
             // Check requirements
             $errors = PortSensorApplication::checkRequirements();
             if (!empty($errors)) {
                 echo $translate->_('update.correct_errors');
                 echo "<ul style='color:red;'>";
                 foreach ($errors as $error) {
                     echo "<li>" . $error . "</li>";
                 }
                 echo "</ul>";
                 exit;
             }
             // If authorized, lock and attempt update
             if (!file_exists($file) || @filectime($file) + 600 < time()) {
                 // 10 min lock
                 touch($file);
                 //echo "Running plugin patches...<br>";
                 if (DevblocksPlatform::runPluginPatches('core.patches')) {
                     @unlink($file);
                     // [JAS]: Clear all caches
                     $cache->clean();
                     DevblocksPlatform::getClassLoaderService()->destroy();
                     // Clear compiled templates
                     $tpl = DevblocksPlatform::getTemplateService();
                     $tpl->clear_compiled_tpl();
                     // Reload plugin translations
                     DAO_Translation::reloadPluginStrings();
                     DevblocksPlatform::redirect(new DevblocksHttpResponse(array('login')));
                 } else {
                     @unlink($file);
                     echo "Failure!";
                     // [TODO] Needs elaboration
                 }
                 break;
             } else {
                 echo $translate->_('update.locked_another');
             }
     }
     exit;
 }
예제 #9
0
 function showCalloutAction()
 {
     @($id = DevblocksPlatform::importGPC($_REQUEST['id'], 'string'));
     $tpl = DevblocksPlatform::getTemplateService();
     $tpl->assign('path', $this->_TPL_PATH);
     $callouts = PortSensorApplication::getTourCallouts();
     $callout = array();
     if (isset($callouts[$id])) {
         $callout = $callouts[$id];
     }
     $tpl->assign('callout', $callout);
     $tpl->display('file:' . $this->_TPL_PATH . 'internal/tour/callout.tpl');
 }
예제 #10
0
파일: App.php 프로젝트: jstanden/portsensor
 function saveAddLanguagePanelAction()
 {
     $active_worker = PortSensorApplication::getActiveWorker();
     // Make sure we're an active worker
     if (empty($active_worker) || empty($active_worker->id)) {
         return;
     }
     $codes = DAO_Translation::getDefinedLangCodes();
     @($add_lang_code = DevblocksPlatform::importGPC($_REQUEST['add_lang_code'], 'string', ''));
     @($copy_lang_code = DevblocksPlatform::importGPC($_REQUEST['copy_lang_code'], 'string', ''));
     @($del_lang_ids = DevblocksPlatform::importGPC($_REQUEST['del_lang_ids'], 'array', array()));
     if (!empty($del_lang_ids)) {
         if (is_array($del_lang_ids)) {
             foreach ($del_lang_ids as $lang_id) {
                 DAO_Translation::deleteByLangCodes($lang_id);
             }
         }
     }
     // Don't add blanks or the same language twice.
     if (!empty($add_lang_code) && !isset($codes[$add_lang_code])) {
         // English reference strings (to know our scope)
         $english_strings = DAO_Translation::getMapByLang('en_US');
         $copy_strings = array();
         // If we have a desired source language for defaults, load it.
         if (!empty($copy_lang_code)) {
             if (0 == strcasecmp('en_US', $copy_lang_code)) {
                 $copy_strings = $english_strings;
             } else {
                 $copy_strings = DAO_Translation::getMapByLang($copy_lang_code);
             }
         }
         // Loop through English strings for new language
         if (is_array($english_strings)) {
             foreach ($english_strings as $string_id => $src_en) {
                 /* @var $src_en Model_Translation */
                 $override = '';
                 // If we have a valid source, copy its override or its default (in that order)
                 @($copy_string = $copy_strings[$string_id]);
                 if (is_a($copy_string, 'Model_Translation')) {
                     $override = !empty($copy_string->string_override) ? $copy_string->string_override : $copy_string->string_default;
                 }
                 // Insert the new string as an override.  Only official translations are defaults
                 $fields = array(DAO_Translation::STRING_ID => $string_id, DAO_Translation::LANG_CODE => $add_lang_code, DAO_Translation::STRING_DEFAULT => '', DAO_Translation::STRING_OVERRIDE => $override);
                 DAO_Translation::create($fields);
             }
         }
     }
     // If we added a new language then change the view to display it
     if (!empty($add_lang_code)) {
         $defaults = new Ps_AbstractViewModel();
         $defaults->class_name = 'Ps_TranslationView';
         $defaults->id = Ps_TranslationView::DEFAULT_ID;
         // Clear the existing view
         $view = Ps_AbstractViewLoader::getView(Ps_TranslationView::DEFAULT_ID, $defaults);
         $view->doResetCriteria();
         // Set search to untranslated strings that aren't English
         $view->renderSortBy = SearchFields_Translation::STRING_ID;
         $view->renderSortAsc = true;
         $view->params = array(SearchFields_Translation::LANG_CODE => new DevblocksSearchCriteria(SearchFields_Translation::LANG_CODE, DevblocksSearchCriteria::OPER_EQ, $add_lang_code));
         /*
          * If we didn't copy from another language, only show empty strings 
          * which makes it easier to translate in the GUI.
          */
         if (empty($copy_lang_code)) {
             $view->params[SearchFields_Translation::STRING_OVERRIDE] = new DevblocksSearchCriteria(SearchFields_Translation::STRING_OVERRIDE, DevblocksSearchCriteria::OPER_EQ, '');
         }
         Ps_AbstractViewLoader::setView($view->id, $view);
     }
     self::_clearCache();
     DevblocksPlatform::redirect(new DevblocksHttpResponse(array('setup', 'translations')));
 }
예제 #11
0
 private static function _save()
 {
     // persist
     $visit = PortSensorApplication::getVisit();
     $visit->set(self::VISIT_ABSTRACTVIEWS, self::$views);
 }
예제 #12
0
 function saveAlertPeekAction()
 {
     $translate = DevblocksPlatform::getTranslationService();
     @($id = DevblocksPlatform::importGPC($_REQUEST['id'], 'integer', 0));
     @($view_id = DevblocksPlatform::importGPC($_POST['view_id'], 'string'));
     @($active_worker = PortSensorApplication::getActiveWorker());
     /*****************************/
     @($name = DevblocksPlatform::importGPC($_POST['name'], 'string', ''));
     @($is_disabled = DevblocksPlatform::importGPC($_POST['is_disabled'], 'integer', 0));
     @($worker_id = DevblocksPlatform::importGPC($_POST['worker_id'], 'integer', 0));
     @($rules = DevblocksPlatform::importGPC($_POST['rules'], 'array', array()));
     @($do = DevblocksPlatform::importGPC($_POST['do'], 'array', array()));
     @($delete = DevblocksPlatform::importGPC($_POST['do_delete'], 'integer', 0));
     if (!empty($id) && !empty($delete)) {
         DAO_Alert::delete($id);
     } else {
         if (empty($name)) {
             $name = $translate->_('Alert');
         }
         $criterion = array();
         $actions = array();
         // Custom fields
         $custom_fields = DAO_CustomField::getAll();
         $alert_criteria_exts = DevblocksPlatform::getExtensions('portsensor.alert.criteria', false);
         // Criteria
         if (is_array($rules)) {
             foreach ($rules as $rule) {
                 $rule = DevblocksPlatform::strAlphaNumDash($rule);
                 @($value = DevblocksPlatform::importGPC($_POST['value_' . $rule], 'string', ''));
                 // [JAS]: Allow empty $value (null/blank checking)
                 $criteria = array('value' => $value);
                 // Any special rule handling
                 switch ($rule) {
                     case 'dayofweek':
                         // days
                         $days = DevblocksPlatform::importGPC($_REQUEST['value_dayofweek'], 'array', array());
                         if (in_array(0, $days)) {
                             $criteria['sun'] = 'Sunday';
                         }
                         if (in_array(1, $days)) {
                             $criteria['mon'] = 'Monday';
                         }
                         if (in_array(2, $days)) {
                             $criteria['tue'] = 'Tuesday';
                         }
                         if (in_array(3, $days)) {
                             $criteria['wed'] = 'Wednesday';
                         }
                         if (in_array(4, $days)) {
                             $criteria['thu'] = 'Thursday';
                         }
                         if (in_array(5, $days)) {
                             $criteria['fri'] = 'Friday';
                         }
                         if (in_array(6, $days)) {
                             $criteria['sat'] = 'Saturday';
                         }
                         unset($criteria['value']);
                         break;
                     case 'timeofday':
                         $from = DevblocksPlatform::importGPC($_REQUEST['timeofday_from'], 'string', '');
                         $to = DevblocksPlatform::importGPC($_REQUEST['timeofday_to'], 'string', '');
                         $criteria['from'] = $from;
                         $criteria['to'] = $to;
                         unset($criteria['value']);
                         break;
                     case 'event':
                         @($events = DevblocksPlatform::importGPC($_REQUEST['value_event'], 'array', array()));
                         if (is_array($events)) {
                             foreach ($events as $event) {
                                 $criteria[$event] = true;
                             }
                         }
                         unset($criteria['value']);
                         break;
                     case 'alert_last_ran':
                         @($from = DevblocksPlatform::importGPC($_REQUEST['value_alert_last_ran_from'], 'string', ''));
                         @($to = DevblocksPlatform::importGPC($_REQUEST['value_alert_last_ran_to'], 'string', ''));
                         $criteria['from'] = $from;
                         $criteria['to'] = $to;
                         unset($criteria['value']);
                         break;
                     case 'sensor_name':
                         break;
                     case 'sensor_fail_count':
                         $oper = DevblocksPlatform::importGPC($_REQUEST['oper_sensor_fail_count'], 'string', '=');
                         $criteria['oper'] = $oper;
                         break;
                     case 'sensor_type':
                         @($types = DevblocksPlatform::importGPC($_REQUEST['value_sensor_types'], 'array', array()));
                         if (is_array($types)) {
                             foreach ($types as $type) {
                                 $criteria[$type] = true;
                             }
                         }
                         unset($criteria['value']);
                         break;
                     default:
                         // ignore invalids // [TODO] Very redundant
                         // Custom fields
                         if ("cf_" == substr($rule, 0, 3)) {
                             $field_id = intval(substr($rule, 3));
                             if (!isset($custom_fields[$field_id])) {
                                 continue;
                             }
                             // [TODO] Operators
                             switch ($custom_fields[$field_id]->type) {
                                 case 'S':
                                     // string
                                 // string
                                 case 'T':
                                     // clob
                                 // clob
                                 case 'U':
                                     // URL
                                     @($oper = DevblocksPlatform::importGPC($_REQUEST['value_cf_' . $field_id . '_oper'], 'string', 'regexp'));
                                     $criteria['oper'] = $oper;
                                     break;
                                 case 'D':
                                     // dropdown
                                 // dropdown
                                 case 'M':
                                     // multi-dropdown
                                 // multi-dropdown
                                 case 'X':
                                     // multi-checkbox
                                 // multi-checkbox
                                 case 'W':
                                     // worker
                                     @($in_array = DevblocksPlatform::importGPC($_REQUEST['value_cf_' . $field_id], 'array', array()));
                                     $out_array = array();
                                     // Hash key on the option for quick lookup later
                                     if (is_array($in_array)) {
                                         foreach ($in_array as $k => $v) {
                                             $out_array[$v] = $v;
                                         }
                                     }
                                     $criteria['value'] = $out_array;
                                     break;
                                 case 'E':
                                     // date
                                     @($from = DevblocksPlatform::importGPC($_REQUEST['value_cf_' . $field_id . '_from'], 'string', '0'));
                                     @($to = DevblocksPlatform::importGPC($_REQUEST['value_cf_' . $field_id . '_to'], 'string', 'now'));
                                     $criteria['from'] = $from;
                                     $criteria['to'] = $to;
                                     unset($criteria['value']);
                                     break;
                                 case 'N':
                                     // number
                                     @($oper = DevblocksPlatform::importGPC($_REQUEST['value_cf_' . $field_id . '_oper'], 'string', '='));
                                     $criteria['oper'] = $oper;
                                     $criteria['value'] = intval($value);
                                     break;
                                 case 'C':
                                     // checkbox
                                     $criteria['value'] = intval($value);
                                     break;
                             }
                         } elseif (isset($alert_criteria_exts[$rule])) {
                             // Extensions
                             // Save custom criteria properties
                             try {
                                 $crit_ext = $alert_criteria_exts[$rule]->createInstance();
                                 /* @var $crit_ext Extension_AlertCriteria */
                                 $criteria = $crit_ext->saveConfig();
                             } catch (Exception $e) {
                                 // print_r($e);
                             }
                         } else {
                             continue;
                         }
                         break;
                 }
                 $criterion[$rule] = $criteria;
             }
         }
         $alert_action_exts = DevblocksPlatform::getExtensions('portsensor.alert.action', false);
         // Actions
         if (is_array($do)) {
             foreach ($do as $act) {
                 $action = array();
                 switch ($act) {
                     // Forward a copy to...
                     case 'email':
                         @($emails = DevblocksPlatform::importGPC($_REQUEST['do_email'], 'array', array()));
                         if (!empty($emails)) {
                             $action = array('to' => $emails);
                         }
                         break;
                         // Watcher notification
                     // Watcher notification
                     case 'notify':
                         //@$emails = DevblocksPlatform::importGPC($_REQUEST['do_email'],'array',array());
                         //if(!empty($emails)) {
                         $action = array();
                         //}
                         break;
                     default:
                         // ignore invalids
                         // Custom fields
                         if ("cf_" == substr($act, 0, 3)) {
                             $field_id = intval(substr($act, 3));
                             if (!isset($custom_fields[$field_id])) {
                                 continue;
                             }
                             $action = array();
                             switch ($custom_fields[$field_id]->type) {
                                 case 'S':
                                     // string
                                 // string
                                 case 'T':
                                     // clob
                                 // clob
                                 case 'U':
                                     // URL
                                 // URL
                                 case 'D':
                                     // dropdown
                                 // dropdown
                                 case 'W':
                                     // worker
                                     $value = DevblocksPlatform::importGPC($_REQUEST['do_cf_' . $field_id], 'string', '');
                                     $action['value'] = $value;
                                     break;
                                 case 'M':
                                     // multi-dropdown
                                 // multi-dropdown
                                 case 'X':
                                     // multi-checkbox
                                     $in_array = DevblocksPlatform::importGPC($_REQUEST['do_cf_' . $field_id], 'array', array());
                                     $out_array = array();
                                     // Hash key on the option for quick lookup later
                                     if (is_array($in_array)) {
                                         foreach ($in_array as $k => $v) {
                                             $out_array[$v] = $v;
                                         }
                                     }
                                     $action['value'] = $out_array;
                                     break;
                                 case 'E':
                                     // date
                                     $value = DevblocksPlatform::importGPC($_REQUEST['do_cf_' . $field_id], 'string', '');
                                     $action['value'] = $value;
                                     break;
                                 case 'N':
                                     // number
                                 // number
                                 case 'C':
                                     // checkbox
                                     $value = DevblocksPlatform::importGPC($_REQUEST['do_cf_' . $field_id], 'string', '');
                                     $action['value'] = intval($value);
                                     break;
                             }
                         } elseif (isset($alert_action_exts[$act])) {
                             // Save custom action properties
                             try {
                                 $action_ext = $alert_action_exts[$act]->createInstance();
                                 $action = $action_ext->saveConfig();
                             } catch (Exception $e) {
                                 // print_r($e);
                             }
                         } else {
                             continue;
                         }
                         break;
                 }
                 $actions[$act] = $action;
             }
         }
         $fields = array(DAO_Alert::NAME => $name, DAO_Alert::IS_DISABLED => $is_disabled, DAO_Alert::WORKER_ID => $worker_id, DAO_Alert::CRITERIA_JSON => json_encode($criterion), DAO_Alert::ACTIONS_JSON => json_encode($actions));
         // Create
         if (empty($id)) {
             $fields[DAO_Alert::POS] = 0;
             $id = DAO_Alert::create($fields);
             // Update
         } else {
             DAO_Alert::update($id, $fields);
         }
     }
     if (!empty($view_id)) {
         $view = Ps_AbstractViewLoader::getView($view_id);
         $view->render();
     }
 }
예제 #13
0
 public function writeResponse(DevblocksHttpResponse $response)
 {
     $path = $response->path;
     // [JAS]: Ajax? // [TODO] Explore outputting whitespace here for Safari
     //	    if(empty($path))
     //			return;
     $tpl = DevblocksPlatform::getTemplateService();
     $session = DevblocksPlatform::getSessionService();
     $settings = DevblocksPlatform::getPluginSettingsService();
     $translate = DevblocksPlatform::getTranslationService();
     $active_worker = PortSensorApplication::getActiveWorker();
     $visit = $session->getVisit();
     $page_manifests = $this->_getAllowedPages();
     $controller = array_shift($path);
     // Default page [TODO] This is supposed to come from framework.config.php
     if (empty($controller)) {
         $controller = 'home';
     }
     // [JAS]: Require us to always be logged in for PortSensor pages
     if (empty($visit) && 0 != strcasecmp($controller, 'login')) {
         $query = array();
         if (!empty($response->path)) {
             $query = array('url' => urlencode(implode('/', $response->path)));
         }
         DevblocksPlatform::redirect(new DevblocksHttpRequest(array('login'), $query));
     }
     $page_id = $this->_getPageIdByUri($controller);
     @($page = DevblocksPlatform::getExtension($page_id, true));
     /* @var $page PortSensorPageExtension */
     if (empty($page)) {
         header("Status: 404");
         return;
         // [TODO] 404
     }
     // [JAS]: Listeners (Step-by-step guided tour, etc.)
     $listenerManifests = DevblocksPlatform::getExtensions('devblocks.listener.http');
     foreach ($listenerManifests as $listenerManifest) {
         /* @var $listenerManifest DevblocksExtensionManifest */
         $inst = $listenerManifest->createInstance();
         /* @var $inst DevblocksHttpRequestListenerExtension */
         $inst->run($response, $tpl);
     }
     $tpl->assign('active_worker', $active_worker);
     $tour_enabled = false;
     if (!empty($visit) && !is_null($active_worker)) {
         $tour_enabled = intval(DAO_WorkerPref::get($active_worker->id, 'assist_mode', 1));
         $keyboard_shortcuts = intval(DAO_WorkerPref::get($active_worker->id, 'keyboard_shortcuts', 1));
         $tpl->assign('pref_keyboard_shortcuts', $keyboard_shortcuts);
         //	    	$active_worker_memberships = $active_worker->getMemberships();
         //	    	$tpl->assign('active_worker_memberships', $active_worker_memberships);
         $unread_notifications = DAO_WorkerEvent::getUnreadCountByWorker($active_worker->id);
         $tpl->assign('active_worker_notify_count', $unread_notifications);
         DAO_Worker::logActivity($active_worker->id, $page->getActivity());
     }
     $tpl->assign('tour_enabled', $tour_enabled);
     // [JAS]: Variables provided to all page templates
     $tpl->assign('settings', $settings);
     $tpl->assign('session', $_SESSION);
     $tpl->assign('translate', $translate);
     $tpl->assign('visit', $visit);
     $tpl->assign('license', PortSensorLicense::getInstance());
     $tpl->assign('page_manifests', $page_manifests);
     $tpl->assign('page', $page);
     $tpl->assign('response_uri', implode('/', $response->path));
     $core_tpl = APP_PATH . '/features/portsensor.core/templates/';
     $tpl->assign('core_tpl', $core_tpl);
     // Prebody Renderers
     $preBodyRenderers = DevblocksPlatform::getExtensions('portsensor.renderer.prebody', true);
     if (!empty($preBodyRenderers)) {
         $tpl->assign('prebody_renderers', $preBodyRenderers);
     }
     // Postbody Renderers
     $postBodyRenderers = DevblocksPlatform::getExtensions('portsensor.renderer.postbody', true);
     if (!empty($postBodyRenderers)) {
         $tpl->assign('postbody_renderers', $postBodyRenderers);
     }
     // Timings
     $tpl->assign('render_time', microtime(true) - DevblocksPlatform::getStartTime());
     if (function_exists('memory_get_usage') && function_exists('memory_get_peak_usage')) {
         $tpl->assign('render_memory', memory_get_usage() - DevblocksPlatform::getStartMemory());
         $tpl->assign('render_peak_memory', memory_get_peak_usage() - DevblocksPlatform::getStartPeakMemory());
     }
     $tpl->display($core_tpl . 'border.tpl');
     //		$cache = DevblocksPlatform::getCacheService();
     //		$cache->printStatistics();
 }
예제 #14
0
 static function shouldLoadExtension(DevblocksExtensionManifest $extension_manifest)
 {
     // Always allow core
     if ("portsensor.core" == $extension_manifest->plugin_id) {
         return true;
     }
     // [TODO] This should limit to just things we can run with no session
     // Community Tools, Cron/Update.  They are still limited by their own
     // isVisible() otherwise.
     if (null == ($active_worker = PortSensorApplication::getActiveWorker())) {
         return true;
     }
     // [TODO] ACL
     //return $active_worker->hasPriv('plugin.'.$extension_manifest->plugin_id);
     return true;
 }