Example #1
0
File: App.php Project: rmiddle/feg
 /**
  * Proxy page actions from an extension's render() to the extension's scope.
  *
  */
 function actionAction()
 {
     @($extid = DevblocksPlatform::importGPC($_REQUEST['extid']));
     @($extid_a = DevblocksPlatform::strAlphaNumDash($_REQUEST['extid_a']));
     $action = $extid_a . 'Action';
     $reportMft = DevblocksPlatform::getExtension($extid);
     // If it's a value report extension, proxy the action
     if (null != ($reportInst = DevblocksPlatform::getExtension($extid, true)) && $reportInst instanceof Extension_Report) {
         // If we asked for a value method on the extension, call it
         if (method_exists($reportInst, $action)) {
             call_user_func(array(&$reportInst, $action));
         }
     }
     return;
 }
Example #2
0
 function handleRequest(DevblocksHttpRequest $request)
 {
     if (!$this->isVisible()) {
         return;
     }
     $path = $request->path;
     $controller = array_shift($path);
     // timetracking
     @($action = DevblocksPlatform::strAlphaNumDash(array_shift($path)) . 'Action');
     switch ($action) {
         case NULL:
             // [TODO] Index/page render
             break;
         default:
             // Default action, call arg as a method suffixed with Action
             if (method_exists($this, $action)) {
                 call_user_func(array(&$this, $action));
             }
             break;
     }
 }
Example #3
0
 public function handleRequest(DevblocksHttpRequest $request)
 {
     $path = $request->path;
     $controller = array_shift($path);
     // [TODO] _getAllowedPages() should take over, but it currently blocks hidden stubs
     $page_id = $this->_getPageIdByUri($controller);
     $page = DevblocksPlatform::getExtension($page_id, true);
     /* @var $page FegPageExtension */
     if (empty($page)) {
         switch ($controller) {
             //	        	case "portal":
             //				    header("Status: 404");
             //	        		die(); // 404
             //	        		break;
             default:
                 return;
                 // default page
                 break;
         }
     }
     @($action = DevblocksPlatform::strAlphaNumDash(array_shift($path)) . 'Action');
     switch ($action) {
         case NULL:
             // [TODO] Index/page render
             break;
         default:
             // Default action, call arg as a method suffixed with Action
             if ($page->isVisible()) {
                 if (method_exists($page, $action)) {
                     call_user_func(array(&$page, $action));
                     // [TODO] Pass HttpRequest as arg?
                 }
             } else {
                 // if Ajax [TODO] percolate isAjax from platform to handleRequest
                 // die("Access denied.  Session expired?");
             }
             break;
     }
 }
Example #4
0
 function saveMailRoutingRuleAddAction()
 {
     $translate = DevblocksPlatform::getTranslationService();
     @($id = DevblocksPlatform::importGPC($_REQUEST['id'], 'integer', 0));
     @($active_worker = CerberusApplication::getActiveWorker());
     if (!$active_worker->is_superuser) {
         return;
     }
     /*****************************/
     @($name = DevblocksPlatform::importGPC($_POST['name'], 'string', ''));
     @($is_sticky = DevblocksPlatform::importGPC($_POST['is_sticky'], 'integer', 0));
     //		@$is_stackable = DevblocksPlatform::importGPC($_POST['is_stackable'],'integer',0);
     @($rules = DevblocksPlatform::importGPC($_POST['rules'], 'array', array()));
     @($do = DevblocksPlatform::importGPC($_POST['do'], 'array', array()));
     if (empty($name)) {
         $name = $translate->_('Mail Routing Rule');
     }
     $criterion = array();
     $actions = array();
     // Custom fields
     $custom_fields = DAO_CustomField::getAll();
     // 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 'subject':
                     break;
                 case 'from':
                     break;
                 case 'tocc':
                     break;
                 case 'header1':
                 case 'header2':
                 case 'header3':
                 case 'header4':
                 case 'header5':
                     if (null != @($header = DevblocksPlatform::importGPC($_POST[$rule], 'string', null))) {
                         $criteria['header'] = strtolower($header);
                     }
                     break;
                 case 'body':
                     break;
                     //				case 'attachment':
                     //					break;
                 //				case 'attachment':
                 //					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;
                         }
                         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;
                         }
                     } else {
                         continue;
                     }
                     break;
             }
             $criterion[$rule] = $criteria;
         }
     }
     // Actions
     if (is_array($do)) {
         foreach ($do as $act) {
             $action = array();
             switch ($act) {
                 // Move group/bucket
                 case 'move':
                     @($move_code = DevblocksPlatform::importGPC($_REQUEST['do_move'], 'string', null));
                     if (0 != strlen($move_code)) {
                         list($g_id, $b_id) = CerberusApplication::translateTeamCategoryCode($move_code);
                         $action = array('group_id' => intval($g_id), 'bucket_id' => intval($b_id));
                     }
                     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;
                         }
                     } else {
                         continue;
                     }
                     break;
             }
             $actions[$act] = $action;
         }
     }
     $fields = array(DAO_MailToGroupRule::NAME => $name, DAO_MailToGroupRule::IS_STICKY => $is_sticky, DAO_MailToGroupRule::CRITERIA_SER => serialize($criterion), DAO_MailToGroupRule::ACTIONS_SER => serialize($actions));
     // Only sticky filters can manual order and be stackable
     if (!$is_sticky) {
         $fields[DAO_MailToGroupRule::STICKY_ORDER] = 0;
         //   			$fields[DAO_MailToGroupRule::IS_STACKABLE] = 0;
         //   		} else { // is sticky
         //   			$fields[DAO_MailToGroupRule::IS_STACKABLE] = $is_stackable;
     }
     // Create
     if (empty($id)) {
         $fields[DAO_MailToGroupRule::POS] = 0;
         $id = DAO_MailToGroupRule::create($fields);
         // Update
     } else {
         DAO_MailToGroupRule::update($id, $fields);
     }
     DevblocksPlatform::redirect(new DevblocksHttpResponse(array('config', 'parser')));
 }
Example #5
0
File: App.php Project: Hildy/cerb5
 function saveWatcherPanelAction()
 {
     $translate = DevblocksPlatform::getTranslationService();
     @($id = DevblocksPlatform::importGPC($_REQUEST['id'], 'integer', 0));
     @($active_worker = CerberusApplication::getActiveWorker());
     //	    if(!$active_worker->is_superuser)
     //	    	return;
     /*****************************/
     @($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()));
     if (empty($name)) {
         $name = $translate->_('Watcher Filter');
     }
     $criterion = array();
     $actions = array();
     // Custom fields
     $custom_fields = DAO_CustomField::getAll();
     // 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 'groups':
                     @($groups = DevblocksPlatform::importGPC($_REQUEST['value_groups'], 'array', array()));
                     if (is_array($groups) && !empty($groups)) {
                         $criteria['groups'] = array();
                         foreach ($groups as $group_id) {
                             @($all = DevblocksPlatform::importGPC($_REQUEST['value_group' . $group_id . '_all'], 'integer', 0));
                             // Did we only want to watch specific buckets in this group?
                             $bucket_ids = array();
                             if (!$all) {
                                 @($bucket_ids = DevblocksPlatform::importGPC($_REQUEST['value_group' . $group_id . '_buckets'], 'array', array()));
                             }
                             // Add to criteria (key=group id, val=array of bucket ids)
                             $criteria['groups'][$group_id] = $bucket_ids;
                         }
                     }
                     unset($criteria['value']);
                     break;
                 case 'next_worker_id':
                     break;
                 case 'subject':
                     break;
                 case 'from':
                     break;
                     //				case 'tocc':
                     //					break;
                 //				case 'tocc':
                 //					break;
                 case 'header1':
                 case 'header2':
                 case 'header3':
                 case 'header4':
                 case 'header5':
                     if (null != @($header = DevblocksPlatform::importGPC($_POST[$rule], 'string', null))) {
                         $criteria['header'] = strtolower($header);
                     }
                     break;
                 case 'body':
                     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;
                         }
                     } else {
                         continue;
                     }
                     break;
             }
             $criterion[$rule] = $criteria;
         }
     }
     // 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;
             }
             $actions[$act] = $action;
         }
     }
     $fields = array(DAO_WatcherMailFilter::NAME => $name, DAO_WatcherMailFilter::IS_DISABLED => $is_disabled, DAO_WatcherMailFilter::WORKER_ID => $worker_id, DAO_WatcherMailFilter::CRITERIA_SER => serialize($criterion), DAO_WatcherMailFilter::ACTIONS_SER => serialize($actions));
     // Create
     if (empty($id)) {
         $fields[DAO_WatcherMailFilter::POS] = 0;
         $id = DAO_WatcherMailFilter::create($fields);
         // Update
     } else {
         DAO_WatcherMailFilter::update($id, $fields);
     }
     exit;
     //DevblocksPlatform::redirect(new DevblocksHttpResponse(array('preferences','watchers')));
 }
Example #6
0
 function saveTabInboxAddAction()
 {
     $translate = DevblocksPlatform::getTranslationService();
     @($id = DevblocksPlatform::importGPC($_REQUEST['id'], 'integer', 0));
     @($group_id = DevblocksPlatform::importGPC($_REQUEST['group_id'], 'integer'));
     @($view_id = DevblocksPlatform::importGPC($_REQUEST['view_id'], 'string', ''));
     @($active_worker = CerberusApplication::getActiveWorker());
     if (!$active_worker->isTeamManager($group_id) && !$active_worker->is_superuser) {
         return;
     }
     /*****************************/
     @($name = DevblocksPlatform::importGPC($_POST['name'], 'string', ''));
     @($is_sticky = DevblocksPlatform::importGPC($_POST['is_sticky'], 'integer', 0));
     @($is_stackable = DevblocksPlatform::importGPC($_POST['is_stackable'], 'integer', 0));
     @($rules = DevblocksPlatform::importGPC($_POST['rules'], 'array', array()));
     @($do = DevblocksPlatform::importGPC($_POST['do'], 'array', array()));
     if (empty($name)) {
         $name = $translate->_('mail.inbox_filter');
     }
     $criterion = array();
     $actions = array();
     // Custom fields
     $custom_fields = DAO_CustomField::getAll();
     // 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 'subject':
                     break;
                 case 'from':
                     break;
                 case 'tocc':
                     break;
                 case 'header1':
                 case 'header2':
                 case 'header3':
                 case 'header4':
                 case 'header5':
                     if (null != @($header = DevblocksPlatform::importGPC($_POST[$rule], 'string', null))) {
                         $criteria['header'] = strtolower($header);
                     }
                     break;
                 case 'body':
                     break;
                 case 'attachment':
                     break;
                 default:
                     // ignore invalids
                     // 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;
                         }
                     } else {
                         continue;
                     }
                     break;
             }
             $criterion[$rule] = $criteria;
         }
     }
     // Actions
     if (is_array($do)) {
         foreach ($do as $act) {
             $action = array();
             switch ($act) {
                 // Move group/bucket
                 case 'move':
                     @($move_code = DevblocksPlatform::importGPC($_REQUEST['do_move'], 'string', null));
                     if (0 != strlen($move_code)) {
                         list($g_id, $b_id) = CerberusApplication::translateTeamCategoryCode($move_code);
                         $action = array('group_id' => intval($g_id), 'bucket_id' => intval($b_id));
                     }
                     break;
                     // Assign to worker
                 // Assign to worker
                 case 'assign':
                     @($worker_id = DevblocksPlatform::importGPC($_REQUEST['do_assign'], 'string', null));
                     if (0 != strlen($worker_id)) {
                         $action = array('worker_id' => intval($worker_id));
                     }
                     break;
                     // Spam training
                 // Spam training
                 case 'spam':
                     @($is_spam = DevblocksPlatform::importGPC($_REQUEST['do_spam'], 'string', null));
                     if (0 != strlen($is_spam)) {
                         $action = array('is_spam' => !$is_spam ? 0 : 1);
                     }
                     break;
                     // Set status
                 // Set status
                 case 'status':
                     @($status = DevblocksPlatform::importGPC($_REQUEST['do_status'], 'string', null));
                     if (0 != strlen($status)) {
                         $action = array('is_waiting' => 3 == $status ? 1 : 0, 'is_closed' => 0 == $status || 3 == $status ? 0 : 1, 'is_deleted' => 2 == $status ? 1 : 0);
                     }
                     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();
                         // [TODO] Operators
                         switch ($custom_fields[$field_id]->type) {
                             case 'S':
                                 // string
                             // string
                             case 'T':
                                 // clob
                             // clob
                             case 'D':
                                 // dropdown
                             // dropdown
                             case 'U':
                                 // URL
                             // URL
                             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;
                         }
                     } else {
                         continue;
                     }
                     break;
             }
             $actions[$act] = $action;
         }
     }
     $fields = array(DAO_GroupInboxFilter::NAME => $name, DAO_GroupInboxFilter::IS_STICKY => $is_sticky, DAO_GroupInboxFilter::CRITERIA_SER => serialize($criterion), DAO_GroupInboxFilter::ACTIONS_SER => serialize($actions));
     // Only sticky filters can manual order and be stackable
     if (!$is_sticky) {
         $fields[DAO_GroupInboxFilter::STICKY_ORDER] = 0;
         $fields[DAO_GroupInboxFilter::IS_STACKABLE] = 0;
     } else {
         // is sticky
         $fields[DAO_GroupInboxFilter::IS_STACKABLE] = $is_stackable;
     }
     // Create
     if (empty($id)) {
         $fields[DAO_GroupInboxFilter::GROUP_ID] = $group_id;
         $fields[DAO_GroupInboxFilter::POS] = 0;
         $id = DAO_GroupInboxFilter::create($fields);
         // Update
     } else {
         DAO_GroupInboxFilter::update($id, $fields);
     }
     $defaults = new C4_AbstractViewModel();
     $defaults->class_name = 'C4_TicketView';
     $defaults->id = $view_id;
     $view = C4_AbstractViewLoader::getView($view_id, $defaults);
     if (!empty($view_id) && null != $view) {
         /* @var $view C4_TicketView */
         // Loop through all the tickets in this inbox
         list($inbox_tickets, $null) = DAO_Ticket::search(null, array(new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_TEAM_ID, '=', $group_id), new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_CATEGORY_ID, '=', '0')), -1, 0, null, null, false);
         if (is_array($inbox_tickets)) {
             foreach ($inbox_tickets as $inbox_ticket) {
                 /* @var $inbox_ticket CerberusTicket */
                 // Run only this new rule against all tickets in the group inbox
                 CerberusApplication::runGroupRouting($group_id, intval($inbox_ticket[SearchFields_Ticket::TICKET_ID]), $id);
             }
         }
         $view->render();
         return;
     }
     DevblocksPlatform::redirect(new DevblocksHttpResponse(array('groups', $group_id, 'inbox')));
 }
Example #7
0
 function saveAddInboxRulePanelAction()
 {
     $translate = DevblocksPlatform::getTranslationService();
     @($view_id = DevblocksPlatform::importGPC($_REQUEST['view_id'], 'string', ''));
     @($group_id = DevblocksPlatform::importGPC($_REQUEST['group_id'], 'integer'));
     $view = C4_AbstractViewLoader::getView('C4_TicketView', $view_id);
     /* @var $view C4_TicketView */
     if (empty($group_id)) {
         $view->render();
         exit;
     }
     @($name = DevblocksPlatform::importGPC($_POST['name'], 'string', ''));
     @($rules = DevblocksPlatform::importGPC($_POST['rules'], 'array', array()));
     @($do = DevblocksPlatform::importGPC($_POST['do'], 'array', array()));
     if (empty($name)) {
         $name = $translate->_('mail.inbox_filter');
     }
     $criterion = array();
     $actions = array();
     // 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 'subject':
                     break;
                 case 'from':
                     break;
                 case 'tocc':
                     break;
                 case 'header1':
                 case 'header2':
                 case 'header3':
                 case 'header4':
                 case 'header5':
                     if (null != @($header = DevblocksPlatform::importGPC($_POST[$rule], 'string', null))) {
                         $criteria['header'] = strtolower($header);
                     }
                     break;
                 case 'body':
                     break;
                 case 'attachment':
                     break;
                 default:
                     // ignore invalids
                     continue;
                     break;
             }
             $criterion[$rule] = $criteria;
         }
     }
     // Actions
     if (is_array($do)) {
         foreach ($do as $act) {
             $action = array();
             switch ($act) {
                 // Move group/bucket
                 case 'move':
                     @($move_code = DevblocksPlatform::importGPC($_REQUEST['do_move'], 'string', null));
                     if (0 != strlen($move_code)) {
                         list($g_id, $b_id) = CerberusApplication::translateTeamCategoryCode($move_code);
                         $action = array('group_id' => intval($g_id), 'bucket_id' => intval($b_id));
                     }
                     break;
                     // Assign to worker
                 // Assign to worker
                 case 'assign':
                     @($worker_id = DevblocksPlatform::importGPC($_REQUEST['do_assign'], 'string', null));
                     if (0 != strlen($worker_id)) {
                         $action = array('worker_id' => intval($worker_id));
                     }
                     break;
                     // Spam training
                 // Spam training
                 case 'spam':
                     @($is_spam = DevblocksPlatform::importGPC($_REQUEST['do_spam'], 'string', null));
                     if (0 != strlen($is_spam)) {
                         $action = array('is_spam' => !$is_spam ? 0 : 1);
                     }
                     break;
                     // Set status
                 // Set status
                 case 'status':
                     @($status = DevblocksPlatform::importGPC($_REQUEST['do_status'], 'string', null));
                     if (0 != strlen($status)) {
                         $action = array('is_closed' => 0 == $status ? 0 : 1, 'is_deleted' => 2 == $status ? 1 : 0);
                     }
                     break;
                 default:
                     // ignore invalids
                     continue;
                     break;
             }
             $actions[$act] = $action;
         }
     }
     $fields = array(DAO_GroupInboxFilter::NAME => $name, DAO_GroupInboxFilter::GROUP_ID => $group_id, DAO_GroupInboxFilter::CRITERIA_SER => serialize($criterion), DAO_GroupInboxFilter::ACTIONS_SER => serialize($actions), DAO_GroupInboxFilter::POS => 0);
     $routing_id = DAO_GroupInboxFilter::create($fields);
     // Loop through all the tickets in this inbox
     list($inbox_tickets, $null) = DAO_Ticket::search(null, array(new DevblocksSearchCriteria(SearchFields_Ticket::TEAM_ID, '=', $group_id), new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_CATEGORY_ID, '=', '0')), -1, 0, null, null, false);
     if (is_array($inbox_tickets)) {
         foreach ($inbox_tickets as $inbox_ticket) {
             /* @var $inbox_ticket CerberusTicket */
             // Run only this new rule against all tickets in the group inbox
             CerberusApplication::runGroupRouting($group_id, intval($inbox_ticket[SearchFields_Ticket::TICKET_ID]), $routing_id);
         }
     }
     $view->render();
     exit;
 }
Example #8
0
 function saveTabPreParserAction()
 {
     @($id = DevblocksPlatform::importGPC($_POST['id'], 'integer', 0));
     @($name = DevblocksPlatform::importGPC($_POST['name'], 'string', ''));
     @($rules = DevblocksPlatform::importGPC($_POST['rules'], 'array', array()));
     @($do = DevblocksPlatform::importGPC($_POST['do'], 'array', array()));
     if (DEMO_MODE) {
         DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('config', 'preparser')));
         return;
     }
     $criterion = array();
     $actions = array();
     // 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 'type':
                     break;
                 case 'from':
                     break;
                 case 'to':
                     break;
                 case 'header1':
                 case 'header2':
                 case 'header3':
                 case 'header4':
                 case 'header5':
                     if (null != @($header = DevblocksPlatform::importGPC($_POST[$rule], 'string', null))) {
                         $criteria['header'] = strtolower($header);
                     }
                     break;
                 case 'body':
                     break;
                 case 'body_encoding':
                     break;
                 case 'attachment':
                     break;
                 default:
                     // ignore invalids
                     continue;
                     break;
             }
             $criterion[$rule] = $criteria;
         }
     }
     // Actions
     if (is_array($do)) {
         foreach ($do as $act) {
             $action = array();
             switch ($act) {
                 case 'blackhole':
                     $action = array();
                     break;
                 case 'redirect':
                     if (null != @($to = DevblocksPlatform::importGPC($_POST['do_redirect'], 'string', null))) {
                         $action = array('to' => $to);
                     }
                     break;
                 case 'bounce':
                     if (null != @($msg = DevblocksPlatform::importGPC($_POST['do_bounce'], 'string', null))) {
                         $action = array('message' => $msg);
                     }
                     break;
                 default:
                     // ignore invalids
                     continue;
                     break;
             }
             $actions[$act] = $action;
         }
     }
     if (!empty($criterion) && !empty($actions)) {
         if (empty($id)) {
             $fields = array(DAO_PreParseRule::NAME => $name, DAO_PreParseRule::CRITERIA_SER => serialize($criterion), DAO_PreParseRule::ACTIONS_SER => serialize($actions), DAO_PreParseRule::POS => 0);
             $id = DAO_PreParseRule::create($fields);
         } else {
             $fields = array(DAO_PreParseRule::NAME => $name, DAO_PreParseRule::CRITERIA_SER => serialize($criterion), DAO_PreParseRule::ACTIONS_SER => serialize($actions));
             DAO_PreParseRule::update($id, $fields);
         }
     }
     DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('config', 'preparser')));
 }
Example #9
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();
     }
 }
Example #10
0
 function saveTabInboxAddAction()
 {
     $translate = DevblocksPlatform::getTranslationService();
     @($id = DevblocksPlatform::importGPC($_REQUEST['id'], 'integer', 0));
     @($group_id = DevblocksPlatform::importGPC($_REQUEST['group_id'], 'integer'));
     @($active_worker = CerberusApplication::getActiveWorker());
     if (!$active_worker->isTeamManager($group_id) && !$active_worker->is_superuser) {
         return;
     }
     /*****************************/
     @($name = DevblocksPlatform::importGPC($_POST['name'], 'string', ''));
     @($is_sticky = DevblocksPlatform::importGPC($_POST['is_sticky'], 'integer', 0));
     @($is_stackable = DevblocksPlatform::importGPC($_POST['is_stackable'], 'integer', 0));
     @($rules = DevblocksPlatform::importGPC($_POST['rules'], 'array', array()));
     @($do = DevblocksPlatform::importGPC($_POST['do'], 'array', array()));
     if (empty($name)) {
         $name = $translate->_('mail.inbox_filter');
     }
     $criterion = array();
     $actions = array();
     // Custom fields
     $custom_fields = DAO_CustomField::getAll();
     // 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 'subject':
                     break;
                 case 'from':
                     break;
                 case 'tocc':
                     break;
                 case 'header1':
                 case 'header2':
                 case 'header3':
                 case 'header4':
                 case 'header5':
                     if (null != @($header = DevblocksPlatform::importGPC($_POST[$rule], 'string', null))) {
                         $criteria['header'] = strtolower($header);
                     }
                     break;
                 case 'body':
                     break;
                 case 'attachment':
                     break;
                 default:
                     // ignore invalids
                     // 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
                                 $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
                                 $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;
                         }
                     } else {
                         continue;
                     }
                     break;
             }
             $criterion[$rule] = $criteria;
         }
     }
     // Actions
     if (is_array($do)) {
         foreach ($do as $act) {
             $action = array();
             switch ($act) {
                 // Move group/bucket
                 case 'move':
                     @($move_code = DevblocksPlatform::importGPC($_REQUEST['do_move'], 'string', null));
                     if (0 != strlen($move_code)) {
                         list($g_id, $b_id) = CerberusApplication::translateTeamCategoryCode($move_code);
                         $action = array('group_id' => intval($g_id), 'bucket_id' => intval($b_id));
                     }
                     break;
                     // Assign to worker
                 // Assign to worker
                 case 'assign':
                     @($worker_id = DevblocksPlatform::importGPC($_REQUEST['do_assign'], 'string', null));
                     if (0 != strlen($worker_id)) {
                         $action = array('worker_id' => intval($worker_id));
                     }
                     break;
                     // Spam training
                 // Spam training
                 case 'spam':
                     @($is_spam = DevblocksPlatform::importGPC($_REQUEST['do_spam'], 'string', null));
                     if (0 != strlen($is_spam)) {
                         $action = array('is_spam' => !$is_spam ? 0 : 1);
                     }
                     break;
                     // Set status
                 // Set status
                 case 'status':
                     @($status = DevblocksPlatform::importGPC($_REQUEST['do_status'], 'string', null));
                     if (0 != strlen($status)) {
                         $action = array('is_waiting' => 3 == $status ? 1 : 0, 'is_closed' => 0 == $status || 3 == $status ? 0 : 1, 'is_deleted' => 2 == $status ? 1 : 0);
                     }
                     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();
                         // [TODO] Operators
                         switch ($custom_fields[$field_id]->type) {
                             case 'S':
                                 // string
                             // string
                             case 'T':
                                 // clob
                             // clob
                             case 'D':
                                 // dropdown
                                 $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;
                         }
                     } else {
                         continue;
                     }
                     break;
             }
             $actions[$act] = $action;
         }
     }
     $fields = array(DAO_GroupInboxFilter::NAME => $name, DAO_GroupInboxFilter::IS_STICKY => $is_sticky, DAO_GroupInboxFilter::CRITERIA_SER => serialize($criterion), DAO_GroupInboxFilter::ACTIONS_SER => serialize($actions));
     // Only sticky filters can manual order and be stackable
     if (!$is_sticky) {
         $fields[DAO_GroupInboxFilter::STICKY_ORDER] = 0;
         $fields[DAO_GroupInboxFilter::IS_STACKABLE] = 0;
     } else {
         // is sticky
         $fields[DAO_GroupInboxFilter::IS_STACKABLE] = $is_stackable;
     }
     // Create
     if (empty($id)) {
         $fields[DAO_GroupInboxFilter::GROUP_ID] = $group_id;
         $fields[DAO_GroupInboxFilter::POS] = 0;
         $id = DAO_GroupInboxFilter::create($fields);
         // Update
     } else {
         DAO_GroupInboxFilter::update($id, $fields);
     }
     DevblocksPlatform::redirect(new DevblocksHttpResponse(array('groups', $group_id, 'inbox')));
 }