Esempio n. 1
0
File: App.php Progetto: Hildy/cerb5
 function render()
 {
     $db = DevblocksPlatform::getDatabaseService();
     $tpl = DevblocksPlatform::getTemplateService();
     $tpl->assign('path', $this->tpl_path);
     // Custom Field sources (tickets, orgs, etc.)
     $source_manifests = DevblocksPlatform::getExtensions('cerberusweb.fields.source', false);
     uasort($source_manifests, create_function('$a, $b', "return strcasecmp(\$a->name,\$b->name);\n"));
     $tpl->assign('source_manifests', $source_manifests);
     // Custom Fields
     $custom_fields = DAO_CustomField::getAll();
     $tpl->assign('custom_fields', $custom_fields);
     // Table + Chart
     @($field_id = DevblocksPlatform::importGPC($_REQUEST['field_id'], 'integer', 0));
     $tpl->assign('field_id', $field_id);
     if (!empty($field_id) && isset($custom_fields[$field_id])) {
         $field = $custom_fields[$field_id];
         $tpl->assign('field', $field);
         // Table
         $value_counts = self::_getValueCounts($field_id);
         $tpl->assign('value_counts', $value_counts);
         // Chart
         $data = array();
         $iter = 0;
         if (is_array($value_counts)) {
             foreach ($value_counts as $value => $hits) {
                 $data[$iter++] = array('value' => $value, 'hits' => $hits);
             }
         }
         $tpl->assign('data', $data);
     }
     $tpl->display('file:' . $this->tpl_path . '/reports/custom_fields/usage/index.tpl');
 }
Esempio n. 2
0
 function run(Model_PreParseRule $filter, CerberusParserMessage $message)
 {
     $message_headers = $message->headers;
     $ticket_fields = DAO_CustomField::getAll();
     $params = $filter->actions[self::EXTENSION_ID];
     $headers = $params['headers'];
     $custom_fields = $params['custom_fields'];
     print_r($custom_fields);
     foreach ($headers as $idx => $header) {
         if ($message_headers[strtolower($header)] != null) {
             $header_value = $message_headers[strtolower($header)];
             // handle array headers
             if (is_array($header_value)) {
                 $value = DevblocksPlatform::parseCrlfString(implode('\\r\\n', $header_value));
             } else {
                 $value = DevblocksPlatform::parseCrlfString($header_value);
             }
             // collapse multi-line headers to single line for single-line text fields
             if ($ticket_fields[$custom_fields[$idx]]->type == Model_CustomField::TYPE_SINGLE_LINE) {
                 $message->custom_fields[$custom_fields[$idx]] = trim(implode(' ', $value));
             } elseif ($ticket_fields[$custom_fields[$idx]]->type == Model_CustomField::TYPE_MULTI_LINE) {
                 $message->custom_fields[$custom_fields[$idx]] = trim(implode('\\r\\n', $value));
             }
         }
     }
 }
Esempio n. 3
0
 function render()
 {
     $tpl = DevblocksPlatform::getTemplateService();
     $tpl->cache_lifetime = "0";
     $tpl->assign('path', $this->tpl_path);
     // Custom Field sources (tickets, orgs, etc.)
     $source_manifests = DevblocksPlatform::getExtensions('cerberusweb.fields.source', false);
     uasort($source_manifests, create_function('$a, $b', "return strcasecmp(\$a->name,\$b->name);\n"));
     $tpl->assign('source_manifests', $source_manifests);
     // Custom Fields
     $custom_fields = DAO_CustomField::getAll();
     $tpl->assign('custom_fields', $custom_fields);
     $tpl->display('file:' . $this->tpl_path . '/reports/custom_fields/usage/index.tpl');
 }
Esempio n. 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')));
 }
Esempio n. 5
0
File: App.php Progetto: Hildy/cerb5
 /**
  * @return Model_WatcherMailFilter[]|false
  */
 static function getMatches(CerberusTicket $ticket, $event, $only_worker_id = null)
 {
     $matches = array();
     if (!empty($only_worker_id)) {
         $filters = DAO_WatcherMailFilter::getWhere(sprintf("%s = %d AND %s = %d", DAO_WatcherMailFilter::WORKER_ID, $only_worker_id, DAO_WatcherMailFilter::IS_DISABLED, 0));
     } else {
         $filters = DAO_WatcherMailFilter::getWhere(sprintf("%s = %d", DAO_WatcherMailFilter::IS_DISABLED, 0));
     }
     // [JAS]: Don't send obvious spam to watchers.
     if ($ticket->spam_score >= 0.9) {
         return false;
     }
     // Build our objects
     $ticket_from = DAO_Address::get($ticket->last_wrote_address_id);
     $ticket_group_id = $ticket->team_id;
     // [TODO] These expensive checks should only populate when needed
     $messages = DAO_Ticket::getMessagesByTicket($ticket->id);
     $message_headers = array();
     if (empty($messages)) {
         return false;
     }
     if (null != @($message_last = array_pop($messages))) {
         /* @var $message_last CerberusMessage */
         $message_headers = $message_last->getHeaders();
     }
     // Clear the rest of the message manifests
     unset($messages);
     $custom_fields = DAO_CustomField::getAll();
     // Lazy load when needed on criteria basis
     $ticket_field_values = null;
     $address_field_values = null;
     $org_field_values = null;
     // Worker memberships (for checking permissions)
     $workers = DAO_Worker::getAll();
     $group_rosters = DAO_Group::getRosters();
     // Check filters
     if (is_array($filters)) {
         foreach ($filters as $filter) {
             /* @var $filter Model_WatcherMailFilter */
             $passed = 0;
             // check the worker's group memberships
             if (!isset($workers[$filter->worker_id]) || $workers[$filter->worker_id]->is_disabled || !$workers[$filter->worker_id]->is_superuser && !isset($group_rosters[$ticket->team_id][$filter->worker_id])) {
                 // no membership
                 continue;
             }
             // check criteria
             foreach ($filter->criteria as $rule_key => $rule) {
                 @($value = $rule['value']);
                 switch ($rule_key) {
                     case 'dayofweek':
                         $current_day = strftime('%w');
                         //$current_day = 1;
                         // Forced to English abbrevs as indexes
                         $days = array('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat');
                         // Is the current day enabled?
                         if (isset($rule[$days[$current_day]])) {
                             $passed++;
                         }
                         break;
                     case 'timeofday':
                         $current_hour = strftime('%H');
                         $current_min = strftime('%M');
                         //$current_hour = 17;
                         //$current_min = 5;
                         if (null != ($from_time = @$rule['from'])) {
                             list($from_hour, $from_min) = explode(':', $from_time);
                         }
                         if (null != ($to_time = @$rule['to'])) {
                             if (list($to_hour, $to_min) = explode(':', $to_time)) {
                             }
                         }
                         // Do we need to wrap around to the next day's hours?
                         if ($from_hour > $to_hour) {
                             // yes
                             $to_hour += 24;
                             // add 24 hrs to the destination (1am = 25th hour)
                         }
                         // Are we in the right 24 hourly range?
                         if ((int) $current_hour >= $from_hour && (int) $current_hour <= $to_hour) {
                             // If we're in the first hour, are we minutes early?
                             if ($current_hour == $from_hour && (int) $current_min < $from_min) {
                                 break;
                             }
                             // If we're in the last hour, are we minutes late?
                             if ($current_hour == $to_hour && (int) $current_min > $to_min) {
                                 break;
                             }
                             $passed++;
                         }
                         break;
                     case 'event':
                         if (!empty($event) && is_array($rule) && isset($rule[$event])) {
                             $passed++;
                         }
                         break;
                     case 'groups':
                         if (null !== @($group_buckets = $rule['groups'][$ticket->team_id]) && (empty($group_buckets) || in_array($ticket->category_id, $group_buckets))) {
                             $passed++;
                         }
                         break;
                     case 'next_worker_id':
                         // If it's an assigned event, we only care about the filter's owner
                         if (!empty($event) && 0 == strcasecmp($event, 'ticket_assignment')) {
                             if (intval($value) == intval($filter->worker_id)) {
                                 $passed++;
                                 break;
                             }
                         }
                         if (intval($value) == intval($ticket->next_worker_id)) {
                             $passed++;
                         }
                         break;
                     case 'mask':
                         $regexp_mask = DevblocksPlatform::strToRegExp($value);
                         if (@preg_match($regexp_mask, $ticket->mask)) {
                             $passed++;
                         }
                         break;
                     case 'from':
                         $regexp_from = DevblocksPlatform::strToRegExp($value);
                         if (@preg_match($regexp_from, $ticket_from->email)) {
                             $passed++;
                         }
                         break;
                     case 'subject':
                         $regexp_subject = DevblocksPlatform::strToRegExp($value);
                         if (@preg_match($regexp_subject, $ticket->subject)) {
                             $passed++;
                         }
                         break;
                     case 'body':
                         if (null == ($message_body = $message_last->getContent())) {
                             break;
                         }
                         // Line-by-line body scanning (sed-like)
                         $lines = preg_split("/[\r\n]/", $message_body);
                         if (is_array($lines)) {
                             foreach ($lines as $line) {
                                 if (@preg_match($value, $line)) {
                                     $passed++;
                                     break;
                                 }
                             }
                         }
                         break;
                     case 'header1':
                     case 'header2':
                     case 'header3':
                     case 'header4':
                     case 'header5':
                         @($header = strtolower($rule['header']));
                         if (empty($header)) {
                             $passed++;
                             break;
                         }
                         if (empty($value)) {
                             // we're checking for null/blanks
                             if (!isset($message_headers[$header]) || empty($message_headers[$header])) {
                                 $passed++;
                             }
                         } elseif (isset($message_headers[$header]) && !empty($message_headers[$header])) {
                             $regexp_header = DevblocksPlatform::strToRegExp($value);
                             // Flatten CRLF
                             if (@preg_match($regexp_header, str_replace(array("\r", "\n"), ' ', $message_headers[$header]))) {
                                 $passed++;
                             }
                         }
                         break;
                     default:
                         // ignore invalids
                         // Custom Fields
                         if (0 == strcasecmp('cf_', substr($rule_key, 0, 3))) {
                             $field_id = substr($rule_key, 3);
                             // Make sure it exists
                             if (null == @($field = $custom_fields[$field_id])) {
                                 continue;
                             }
                             // Lazy values loader
                             $field_values = array();
                             switch ($field->source_extension) {
                                 case ChCustomFieldSource_Address::ID:
                                     if (null == $address_field_values) {
                                         $address_field_values = array_shift(DAO_CustomFieldValue::getValuesBySourceIds(ChCustomFieldSource_Address::ID, $ticket_from->id));
                                     }
                                     $field_values =& $address_field_values;
                                     break;
                                 case ChCustomFieldSource_Org::ID:
                                     if (null == $org_field_values) {
                                         $org_field_values = array_shift(DAO_CustomFieldValue::getValuesBySourceIds(ChCustomFieldSource_Org::ID, $ticket_from->contact_org_id));
                                     }
                                     $field_values =& $org_field_values;
                                     break;
                                 case ChCustomFieldSource_Ticket::ID:
                                     if (null == $ticket_field_values) {
                                         $ticket_field_values = array_shift(DAO_CustomFieldValue::getValuesBySourceIds(ChCustomFieldSource_Ticket::ID, $ticket->id));
                                     }
                                     $field_values =& $ticket_field_values;
                                     break;
                             }
                             // Type sensitive value comparisons
                             // [TODO] Operators
                             switch ($field->type) {
                                 case 'S':
                                     // string
                                 // string
                                 case 'T':
                                     // clob
                                 // clob
                                 case 'U':
                                     // URL
                                     $field_val = isset($field_values[$field_id]) ? $field_values[$field_id] : '';
                                     $oper = isset($rule['oper']) ? $rule['oper'] : "=";
                                     if ($oper == "=" && @preg_match(DevblocksPlatform::strToRegExp($value, true), $field_val)) {
                                         $passed++;
                                     } elseif ($oper == "!=" && @(!preg_match(DevblocksPlatform::strToRegExp($value, true), $field_val))) {
                                         $passed++;
                                     }
                                     break;
                                 case 'N':
                                     // number
                                     $field_val = isset($field_values[$field_id]) ? $field_values[$field_id] : 0;
                                     $oper = isset($rule['oper']) ? $rule['oper'] : "=";
                                     if ($oper == "=" && intval($field_val) == intval($value)) {
                                         $passed++;
                                     } elseif ($oper == "!=" && intval($field_val) != intval($value)) {
                                         $passed++;
                                     } elseif ($oper == ">" && intval($field_val) > intval($value)) {
                                         $passed++;
                                     } elseif ($oper == "<" && intval($field_val) < intval($value)) {
                                         $passed++;
                                     }
                                     break;
                                 case 'E':
                                     // date
                                     $field_val = isset($field_values[$field_id]) ? intval($field_values[$field_id]) : 0;
                                     $from = isset($rule['from']) ? $rule['from'] : "0";
                                     $to = isset($rule['to']) ? $rule['to'] : "now";
                                     if (intval(@strtotime($from)) <= $field_val && intval(@strtotime($to)) >= $field_val) {
                                         $passed++;
                                     }
                                     break;
                                 case 'C':
                                     // checkbox
                                     $field_val = isset($field_values[$field_id]) ? $field_values[$field_id] : 0;
                                     if (intval($value) == intval($field_val)) {
                                         $passed++;
                                     }
                                     break;
                                 case 'D':
                                     // dropdown
                                 // dropdown
                                 case 'X':
                                     // multi-checkbox
                                 // multi-checkbox
                                 case 'M':
                                     // multi-picklist
                                 // multi-picklist
                                 case 'W':
                                     // worker
                                     $field_val = isset($field_values[$field_id]) ? $field_values[$field_id] : array();
                                     if (!is_array($value)) {
                                         $value = array($value);
                                     }
                                     if (is_array($field_val)) {
                                         // if multiple things set
                                         foreach ($field_val as $v) {
                                             // loop through possible
                                             if (isset($value[$v])) {
                                                 // is any possible set?
                                                 $passed++;
                                                 break;
                                             }
                                         }
                                     } else {
                                         // single
                                         if (isset($value[$field_val])) {
                                             // is our set field in possibles?
                                             $passed++;
                                             break;
                                         }
                                     }
                                     break;
                             }
                         }
                         break;
                 }
             }
             // If our rule matched every criteria, stop and return the filter
             if ($passed == count($filter->criteria)) {
                 DAO_WatcherMailFilter::increment($filter->id);
                 // ++ the times we've matched
                 $matches[$filter->id] = $filter;
             }
         }
     }
     if (!empty($matches)) {
         return $matches;
     }
     // No matches
     return false;
 }
Esempio n. 6
0
 function run(Model_PreParseRule $filter, CerberusParserMessage $message)
 {
     $message_headers = $message->headers;
     $subject = $message->headers['subject'];
     $ticket_fields = DAO_CustomField::getAll();
     $params = $filter->actions[self::EXTENSION_ID];
     $day_of_week = date('N');
     $logger = DevblocksPlatform::getConsoleLog();
     $logger->info("Answernet: Running Filter on New Mail");
     // Houser,Colin <1034179><Missing Serviced Customer information>
     // Current custom_fields numbers
     // 1 = Due Date
     // 2 = RM Employee ID
     // 3 = RM Name
     // 4 = Topic_metlife /0/2/4/6/8/10/12/14
     // 5 = SLA
     // 6 = New Hire Yes = 0 / No = 2
     //
     $sub = explode(',', $subject, 2);
     $lname = $sub[0];
     $sub2 = explode("<", $sub[1]);
     $fname = $sub2[0];
     $emp_id = $sub2[1];
     $topic_metlife = $sub2[2];
     $message->custom_fields['2'] = substr($emp_id, 0, -1);
     $message->custom_fields['3'] = trim($fname) . " " . trim($lname);
     // If topic == Import contacts
     if (preg_match('/import/i', $topic_metlife)) {
         $message->custom_fields['4'] = "Import contacts";
         $message->custom_fields['5'] = 1;
         $message->custom_fields['6'] = "Yes";
     }
     // If topic == Create mailing list from existing data
     if (preg_match('/mailing/i', $topic_metlife)) {
         $message->custom_fields['4'] = "Create mailing list from existing data";
         $message->custom_fields['5'] = 3;
         $message->custom_fields['6'] = "Yes";
     }
     // If topic == Update existing contacts
     if (preg_match('/Update/i', $topic_metlife)) {
         $message->custom_fields['4'] = "Update existing contacts";
         $message->custom_fields['5'] = 3;
         $message->custom_fields['6'] = "No";
     }
     // If topic == Research missing customer info
     if (preg_match('/Research/i', $topic_metlife)) {
         $message->custom_fields['4'] = "Research missing customer info";
         $message->custom_fields['5'] = 5;
         $message->custom_fields['6'] = "No";
     }
     // If topic == Create labels
     if (preg_match('/labels/i', $topic_metlife)) {
         $message->custom_fields['4'] = "Create labels";
         $message->custom_fields['5'] = 1;
         $message->custom_fields['6'] = "No";
     }
     // If topic == Export third-party file
     if (preg_match('/third/i', $topic_metlife)) {
         $message->custom_fields['4'] = "Export third-party file";
         $message->custom_fields['5'] = 3;
         $message->custom_fields['6'] = "No";
     }
     // If topic == Other
     if (preg_match('/Other/i', $topic_metlife)) {
         $message->custom_fields['4'] = "Other";
         $message->custom_fields['5'] = 5;
         $message->custom_fields['6'] = "No";
     }
     // SLA of 1.  Process day of week Busness Days suck.
     if ($message->custom_fields['5'] == 1) {
         if ($day_of_week < 5 || $day_of_week == 7) {
             $message->custom_fields['1'] = strtotime("+1 Days");
         }
         if ($day_of_week == 6) {
             $message->custom_fields['1'] = strtotime("+2 Days");
         }
         if ($day_of_week == 5) {
             $message->custom_fields['1'] = strtotime("+3 Days");
         }
     }
     // SLA of 3.  Process day of week Busness Days suck.
     if ($message->custom_fields['5'] == 3) {
         if ($day_of_week < 4 || $day_of_week == 7) {
             $message->custom_fields['1'] = strtotime("+3 Days");
         }
         if ($day_of_week == 6) {
             $message->custom_fields['1'] = strtotime("+4 Days");
         }
         if ($day_of_week > 3 && $day_of_week < 6) {
             $message->custom_fields['1'] = strtotime("+5 Days");
         }
     }
     // SLA of 5.  Process day of week Busness Days suck.
     if ($message->custom_fields['5'] == 5) {
         if ($day_of_week == 1 || $day_of_week == 7) {
             $message->custom_fields['1'] = strtotime("+5 Days");
         }
         if ($day_of_week == 6) {
             $message->custom_fields['1'] = strtotime("+6 Days");
         }
         if ($day_of_week > 1 && $day_of_week < 6) {
             $message->custom_fields['1'] = strtotime("+7 Days");
         }
     }
 }
Esempio n. 7
0
 public static function getValuesBySourceIds($source_ext_id, $source_ids)
 {
     if (is_null($source_ids)) {
         return array();
     } elseif (!is_array($source_ids)) {
         $source_ids = array($source_ids);
     }
     if (empty($source_ids)) {
         return array();
     }
     $db = DevblocksPlatform::getDatabaseService();
     $results = array();
     $fields = DAO_CustomField::getAll();
     // [TODO] This is inefficient (and redundant)
     // STRINGS
     $sql = sprintf("SELECT source_id, field_id, field_value " . "FROM custom_field_stringvalue " . "WHERE source_extension = '%s' AND source_id IN (%s)", $source_ext_id, implode(',', $source_ids));
     $rs = $db->Execute($sql) or die(__CLASS__ . '(' . __LINE__ . ')' . ':' . $db->ErrorMsg());
     while ($row = mysql_fetch_assoc($rs)) {
         $source_id = intval($row['source_id']);
         $field_id = intval($row['field_id']);
         $field_value = $row['field_value'];
         if (!isset($results[$source_id])) {
             $results[$source_id] = array();
         }
         $source =& $results[$source_id];
         // If multiple value type (multi-picklist, multi-checkbox)
         if ($fields[$field_id]->type == 'M' || $fields[$field_id]->type == 'X') {
             if (!isset($source[$field_id])) {
                 $source[$field_id] = array();
             }
             $source[$field_id][$field_value] = $field_value;
         } else {
             // single value
             $source[$field_id] = $field_value;
         }
     }
     mysql_free_result($rs);
     // CLOBS
     $sql = sprintf("SELECT source_id, field_id, field_value " . "FROM custom_field_clobvalue " . "WHERE source_extension = '%s' AND source_id IN (%s)", $source_ext_id, implode(',', $source_ids));
     $rs = $db->Execute($sql) or die(__CLASS__ . '(' . __LINE__ . ')' . ':' . $db->ErrorMsg());
     while ($row = mysql_fetch_assoc($rs)) {
         $source_id = intval($row['source_id']);
         $field_id = intval($row['field_id']);
         $field_value = $row['field_value'];
         if (!isset($results[$source_id])) {
             $results[$source_id] = array();
         }
         $source =& $results[$source_id];
         $source[$field_id] = $field_value;
     }
     mysql_free_result($rs);
     // NUMBERS
     $sql = sprintf("SELECT source_id, field_id, field_value " . "FROM custom_field_numbervalue " . "WHERE source_extension = '%s' AND source_id IN (%s)", $source_ext_id, implode(',', $source_ids));
     $rs = $db->Execute($sql) or die(__CLASS__ . '(' . __LINE__ . ')' . ':' . $db->ErrorMsg());
     while ($row = mysql_fetch_assoc($rs)) {
         $source_id = intval($row['source_id']);
         $field_id = intval($row['field_id']);
         $field_value = $row['field_value'];
         if (!isset($results[$source_id])) {
             $results[$source_id] = array();
         }
         $source =& $results[$source_id];
         $source[$field_id] = $field_value;
     }
     mysql_free_result($rs);
     return $results;
 }
Esempio n. 8
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')));
 }
Esempio n. 9
0
 public static function _doBulkSetCustomFields($source_extension, $custom_fields, $ids)
 {
     $fields = DAO_CustomField::getAll();
     if (!empty($custom_fields)) {
         foreach ($custom_fields as $cf_id => $params) {
             if (!is_array($params) || !isset($params['value'])) {
                 continue;
             }
             $cf_val = $params['value'];
             // Data massaging
             switch ($fields[$cf_id]->type) {
                 case Model_CustomField::TYPE_DATE:
                     $cf_val = intval(@strtotime($cf_val));
                     break;
                 case Model_CustomField::TYPE_CHECKBOX:
                 case Model_CustomField::TYPE_NUMBER:
                     $cf_val = 0 == strlen($cf_val) ? '' : intval($cf_val);
                     break;
             }
             // If multi-selection types, handle delta changes
             if (Model_CustomField::TYPE_MULTI_PICKLIST == $fields[$cf_id]->type || Model_CustomField::TYPE_MULTI_CHECKBOX == $fields[$cf_id]->type) {
                 if (is_array($cf_val)) {
                     foreach ($cf_val as $val) {
                         $op = substr($val, 0, 1);
                         $val = substr($val, 1);
                         if (is_array($ids)) {
                             foreach ($ids as $id) {
                                 if ($op == '+') {
                                     DAO_CustomFieldValue::setFieldValue($source_extension, $id, $cf_id, $val, true);
                                 } elseif ($op == '-') {
                                     DAO_CustomFieldValue::unsetFieldValue($source_extension, $id, $cf_id, $val);
                                 }
                             }
                         }
                     }
                 }
                 // Otherwise, set/unset as a single field
             } else {
                 if (is_array($ids)) {
                     foreach ($ids as $id) {
                         if (0 != strlen($cf_val)) {
                             DAO_CustomFieldValue::setFieldValue($source_extension, $id, $cf_id, $cf_val);
                         } else {
                             DAO_CustomFieldValue::unsetFieldValue($source_extension, $id, $cf_id);
                         }
                     }
                 }
             }
         }
     }
 }
Esempio n. 10
0
 /**
  * @param integer[] $ticket_ids
  */
 function run($ticket_ids)
 {
     if (!is_array($ticket_ids)) {
         $ticket_ids = array($ticket_ids);
     }
     $fields = array();
     $field_values = array();
     $groups = DAO_Group::getAll();
     $buckets = DAO_Bucket::getAll();
     //		$workers = DAO_Worker::getAll();
     $custom_fields = DAO_CustomField::getAll();
     // actions
     if (is_array($this->actions)) {
         foreach ($this->actions as $action => $params) {
             switch ($action) {
                 //				case 'status':
                 //					if(isset($params['is_waiting']))
                 //						$fields[DAO_Ticket::IS_WAITING] = intval($params['is_waiting']);
                 //					if(isset($params['is_closed']))
                 //						$fields[DAO_Ticket::IS_CLOSED] = intval($params['is_closed']);
                 //					if(isset($params['is_deleted']))
                 //						$fields[DAO_Ticket::IS_DELETED] = intval($params['is_deleted']);
                 //					break;
                 //				case 'assign':
                 //					if(isset($params['worker_id'])) {
                 //						$w_id = intval($params['worker_id']);
                 //						if(0 == $w_id || isset($workers[$w_id]))
                 //							$fields[DAO_Ticket::NEXT_WORKER_ID] = $w_id;
                 //					}
                 //					break;
                 case 'move':
                     if (isset($params['group_id']) && isset($params['bucket_id'])) {
                         $g_id = intval($params['group_id']);
                         $b_id = intval($params['bucket_id']);
                         if (isset($groups[$g_id]) && (0 == $b_id || isset($buckets[$b_id]))) {
                             $fields[DAO_Ticket::TEAM_ID] = $g_id;
                             $fields[DAO_Ticket::CATEGORY_ID] = $b_id;
                         }
                     }
                     break;
                     //				case 'spam':
                     //					if(isset($params['is_spam'])) {
                     //						if(intval($params['is_spam'])) {
                     //							foreach($ticket_ids as $ticket_id)
                     //								CerberusBayes::markTicketAsSpam($ticket_id);
                     //						} else {
                     //							foreach($ticket_ids as $ticket_id)
                     //								CerberusBayes::markTicketAsNotSpam($ticket_id);
                     //						}
                     //					}
                     //					break;
                 //				case 'spam':
                 //					if(isset($params['is_spam'])) {
                 //						if(intval($params['is_spam'])) {
                 //							foreach($ticket_ids as $ticket_id)
                 //								CerberusBayes::markTicketAsSpam($ticket_id);
                 //						} else {
                 //							foreach($ticket_ids as $ticket_id)
                 //								CerberusBayes::markTicketAsNotSpam($ticket_id);
                 //						}
                 //					}
                 //					break;
                 default:
                     // Custom fields
                     if (substr($action, 0, 3) == "cf_") {
                         $field_id = intval(substr($action, 3));
                         if (!isset($custom_fields[$field_id]) || !isset($params['value'])) {
                             break;
                         }
                         $field_values[$field_id] = $params;
                     }
                     break;
             }
         }
     }
     if (!empty($ticket_ids)) {
         if (!empty($fields)) {
             DAO_Ticket::updateTicket($ticket_ids, $fields);
         }
         // Custom Fields
         C4_AbstractView::_doBulkSetCustomFields(ChCustomFieldSource_Ticket::ID, $field_values, $ticket_ids);
     }
 }
Esempio n. 11
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();
     }
 }
Esempio n. 12
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')));
 }