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'))); }
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'))); }