/api/Model.class.php
PHP | 4404 lines | 3227 code | 715 blank | 462 comment | 503 complexity | ace8680c2cbe2b4f2bb02556c858870a MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- <?php
- /***********************************************************************
- | Cerberus Helpdesk(tm) developed by WebGroup Media, LLC.
- |-----------------------------------------------------------------------
- | All source code & content (c) Copyright 2007, WebGroup Media LLC
- | unless specifically noted otherwise.
- |
- | This source code is released under the Cerberus Public License.
- | The latest version of this license can be found here:
- | http://www.cerberusweb.com/license.php
- |
- | By using this software, you acknowledge having read this license
- | and agree to be bound thereby.
- | ______________________________________________________________________
- | http://www.cerberusweb.com http://www.webgroupmedia.com/
- ***********************************************************************/
- /*
- * IMPORTANT LICENSING NOTE from your friends on the Cerberus Helpdesk Team
- *
- * Sure, it would be so easy to just cheat and edit this file to use the
- * software without paying for it. But we trust you anyway. In fact, we're
- * writing this software for you!
- *
- * Quality software backed by a dedicated team takes money to develop. We
- * don't want to be out of the office bagging groceries when you call up
- * needing a helping hand. We'd rather spend our free time coding your
- * feature requests than mowing the neighbors' lawns for rent money.
- *
- * We've never believed in encoding our source code out of paranoia over not
- * getting paid. We want you to have the full source code and be able to
- * make the tweaks your organization requires to get more done -- despite
- * having less of everything than you might need (time, people, money,
- * energy). We shouldn't be your bottleneck.
- *
- * We've been building our expertise with this project since January 2002. We
- * promise spending a couple bucks [Euro, Yuan, Rupees, Galactic Credits] to
- * let us take over your shared e-mail headache is a worthwhile investment.
- * It will give you a sense of control over your in-box that you probably
- * haven't had since spammers found you in a game of "E-mail Address
- * Battleship". Miss. Miss. You sunk my in-box!
- *
- * A legitimate license entitles you to support, access to the developer
- * mailing list, the ability to participate in betas and the warm fuzzy
- * feeling of feeding a couple obsessed developers who want to help you get
- * more done than 'the other guy'.
- *
- * - Jeff Standen, Mike Fogg, Brenan Cavish, Darren Sugita, Dan Hildebrandt
- * and Joe Geck.
- * WEBGROUP MEDIA LLC. - Developers of Cerberus Helpdesk
- */
- class Model_PreParseRule {
- public $id;
- public $created;
- public $name;
- public $criteria;
- public $actions;
- public $pos;
- public $is_sticky = 0;
- public $sticky_order = 0;
-
- /**
- * Returns a Model_PreParserRule on a match, or NULL
- *
- * @param boolean $is_new
- * @param string $from
- * @param string $to
- * @param CerberusParserMessage $message
- * @return Model_PreParserRule[]
- */
- static function getMatches(CerberusParserMessage $message) {
- $filters = DAO_PreParseRule::getAll();
- $headers = $message->headers;
- // New or reply?
- $is_new = (isset($message->headers['in-reply-to']) || isset($message->headers['references'])) ? false : true;
- // From address
- $fromInst = CerberusParser::getAddressFromHeaders($headers);
-
- // Stackable
- $matches = array();
-
- // Custom fields
- $custom_fields = DAO_CustomField::getAll();
-
- // Criteria extensions
- $filter_criteria_exts = DevblocksPlatform::getExtensions('cerberusweb.mail_filter.criteria', false);
-
- // Lazy load when needed on criteria basis
- $address_field_values = null;
- $org_field_values = null;
-
- // check filters
- if(is_array($filters))
- foreach($filters as $filter) {
- $passed = 0;
- // 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((integer)$current_hour >= $from_hour && (integer)$current_hour <= $to_hour) {
- // If we're in the first hour, are we minutes early?
- if($current_hour==$from_hour && (integer)$current_min < $from_min)
- break;
- // If we're in the last hour, are we minutes late?
- if($current_hour==$to_hour && (integer)$current_min > $to_min)
- break;
-
- $passed++;
- }
- break;
- case 'type':
- if(($is_new && 0 == strcasecmp($value,'new'))
- || (!$is_new && 0 == strcasecmp($value,'reply')))
- $passed++;
- break;
-
- case 'from':
- $regexp_from = DevblocksPlatform::strToRegExp($value);
- if(preg_match($regexp_from, $fromInst->email)) {
- $passed++;
- }
- break;
-
- case 'tocc':
- $tocc = array();
- $destinations = DevblocksPlatform::parseCsvString($value);
- // Build a list of To/Cc addresses on this message
- @$to_list = imap_rfc822_parse_adrlist($headers['to'],'localhost');
- @$cc_list = imap_rfc822_parse_adrlist($headers['cc'],'localhost');
-
- if(is_array($to_list))
- foreach($to_list as $addy) {
- $tocc[] = $addy->mailbox . '@' . $addy->host;
- }
- if(is_array($cc_list))
- foreach($cc_list as $addy) {
- $tocc[] = $addy->mailbox . '@' . $addy->host;
- }
-
- $dest_flag = false; // bail out when true
- if(is_array($destinations) && is_array($tocc))
- foreach($destinations as $dest) {
- if($dest_flag) break;
- $regexp_dest = DevblocksPlatform::strToRegExp($dest);
-
- foreach($tocc as $addy) {
- if(@preg_match($regexp_dest, $addy)) {
- $passed++;
- $dest_flag = false;
- break;
- }
- }
- }
- break;
-
- case 'header1':
- case 'header2':
- case 'header3':
- case 'header4':
- case 'header5':
- $header = strtolower($rule['header']);
- if(empty($value)) { // we're checking for null/blanks
- if(!isset($headers[$header]) || empty($headers[$header])) {
- $passed++;
- }
-
- } elseif(isset($headers[$header]) && !empty($headers[$header])) {
- $regexp_header = DevblocksPlatform::strToRegExp($value);
-
- // handle arrays like Received: and (broken)Content-Type headers (farking spammers)
- if(is_array($headers[$header])) {
- foreach($headers[$header] as $array_header) {
- if(preg_match($regexp_header, str_replace(array("\r","\n"),' ',$array_header))) {
- $passed++;
- break;
- }
- }
- } else {
- // Flatten CRLF
- if(preg_match($regexp_header, str_replace(array("\r","\n"),' ',$headers[$header]))) {
- $passed++;
- }
- }
- }
-
- break;
-
- case 'body':
- // 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 'body_encoding':
- $regexp_bodyenc = DevblocksPlatform::strToRegExp($value);
- if(preg_match($regexp_bodyenc, $message->body_encoding))
- $passed++;
- break;
-
- case 'attachment':
- $regexp_file = DevblocksPlatform::strToRegExp($value);
- // check the files in the raw message
- foreach($message->files as $file_name => $file) { /* @var $file ParserFile */
- if(preg_match($regexp_file, $file_name)) {
- $passed++;
- break;
- }
- }
- 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, $fromInst->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, $fromInst->contact_org_id));
- $field_values =& $org_field_values;
- break;
- }
-
- // Type sensitive value comparisons
- // [TODO] Operators
- // [TODO] Highly redundant
- switch($field->type) {
- case 'S': // string
- case 'T': // 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
- if(!isset($field_values[$field_id]))
- break;
-
- $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
- case 'M': // multi-picklist
- case 'X': // multi-checkbox
- 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;
- }
-
- } elseif(isset($filter_criteria_exts[$rule_key])) { // criteria extensions
- try {
- $crit_ext = $filter_criteria_exts[$rule_key]->createInstance();
- if($crit_ext->matches($filter, $message)) {
- $passed++;
- break;
- }
-
- } catch(Exception $e) {
- // Oops!
- //print_r($e);
- }
-
- }
-
- break;
- }
- }
-
- // If our rule matched every criteria, stop and return the filter
- if($passed == count($filter->criteria)) {
- DAO_PreParseRule::increment($filter->id); // ++ the times we've matched
- $matches[] = $filter;
-
- // Check our actions and see if we should bail out early
- if(isset($filter->actions) && !empty($filter->actions))
- foreach($filter->actions as $action_key => $action) {
- switch($action_key) {
- case 'nothing':
- case 'blackhole':
- case 'redirect':
- case 'bounce':
- return $matches;
- break;
- }
- }
- }
- }
-
- return $matches;
- }
-
- }
- class Model_GroupInboxFilter {
- public $id = 0;
- public $name = '';
- public $group_id = 0;
- public $criteria = array();
- public $actions = array();
- public $pos = 0;
- public $is_sticky = 0;
- public $sticky_order = 0;
- public $is_stackable = 0;
-
- /**
- * @return Model_GroupInboxFilter|false
- */
- static function getMatches($group_id, $ticket_id, $only_rule_id=0) {
- $matches = array();
-
- if(empty($group_id))
- return false;
- if(!empty($only_rule_id)) {
- $filters = array(
- DAO_GroupInboxFilter::get($only_rule_id)
- );
- } else {
- $filters = DAO_GroupInboxFilter::getByGroupId($group_id);
- }
- // Check the ticket
- if(null === ($ticket = DAO_Ticket::getTicket($ticket_id)))
- 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;
-
- // Check filters
- if(is_array($filters))
- foreach($filters as $filter) { /* @var $filter Model_GroupInboxFilter */
- $passed = 0;
- // Skip filters with no criteria
- if(!is_array($filter->criteria) || empty($filter->criteria))
- 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((integer)$current_hour >= $from_hour && (integer)$current_hour <= $to_hour) {
- // If we're in the first hour, are we minutes early?
- if($current_hour==$from_hour && (integer)$current_min < $from_min)
- break;
- // If we're in the last hour, are we minutes late?
- if($current_hour==$to_hour && (integer)$current_min > $to_min)
- break;
-
- $passed++;
- }
- break;
-
- case 'tocc':
- $tocc = array();
- $destinations = DevblocksPlatform::parseCsvString($value);
- // Build a list of To/Cc addresses on this message
- @$to_list = imap_rfc822_parse_adrlist($message_headers['to'],'localhost');
- @$cc_list = imap_rfc822_parse_adrlist($message_headers['cc'],'localhost');
-
- if(is_array($to_list))
- foreach($to_list as $addy) {
- $tocc[] = $addy->mailbox . '@' . $addy->host;
- }
- if(is_array($cc_list))
- foreach($cc_list as $addy) {
- $tocc[] = $addy->mailbox . '@' . $addy->host;
- }
-
- $dest_flag = false; // bail out when true
- if(is_array($destinations) && is_array($tocc))
- foreach($destinations as $dest) {
- if($dest_flag) break;
- $regexp_dest = DevblocksPlatform::strToRegExp($dest);
-
- foreach($tocc as $addy) {
- if(@preg_match($regexp_dest, $addy)) {
- $passed++;
- $dest_flag = false;
- break;
- }
- }
- }
- 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;
- }
-
- // No values, default.
- // if(!isset($field_values[$field_id]))
- // continue;
-
- // Type sensitive value comparisons
- // [TODO] Operators
- switch($field->type) {
- case 'S': // string
- case 'T': // 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
- if(!isset($field_values[$field_id]))
- break;
-
- $field_val = intval($field_values[$field_id]);
- $oper = isset($rule['oper']) ? $rule['oper'] : "=";
-
- if($oper=="=" && $field_val == intval($value))
- $passed++;
- elseif($oper=="!=" && $field_val != intval($value))
- $passed++;
- elseif($oper==">" && $field_val > intval($value))
- $passed++;
- elseif($oper=="<" && $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
- case 'X': // multi-checkbox
- case 'M': // 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_GroupInboxFilter::increment($filter->id); // ++ the times we've matched
- $matches[$filter->id] = $filter;
-
- // If we're not stackable anymore, bail out.
- if(!$filter->is_stackable)
- return $matches;
- }
- }
-
- // If last rule was still stackable...
- if(!empty($matches))
- return $matches;
-
- // No matches
- return false;
- }
-
- /**
- * @param integer[] $ticket_ids
- */
- function run($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;
- 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);
- }
- }
- };
- /**
- * Enter description here...
- *
- */
- abstract class C4_AbstractView {
- public $id = 0;
- public $name = "";
- public $view_columns = array();
- public $params = array();
- public $renderPage = 0;
- public $renderLimit = 10;
- public $renderSortBy = '';
- public $renderSortAsc = 1;
- function getData() {
- }
- function render() {
- echo ' '; // Expect Override
- }
- function renderCriteria($field) {
- echo ' '; // Expect Override
- }
- protected function _renderCriteriaCustomField($tpl, $field_id) {
- $field = DAO_CustomField::get($field_id);
- $tpl_path = APP_PATH . '/features/cerberusweb.core/templates/';
-
- switch($field->type) {
- case Model_CustomField::TYPE_DROPDOWN:
- case Model_CustomField::TYPE_MULTI_PICKLIST:
- case Model_CustomField::TYPE_MULTI_CHECKBOX:
- $tpl->assign('field', $field);
- $tpl->display('file:' . $tpl_path . 'internal/views/criteria/__cfield_picklist.tpl');
- break;
- case Model_CustomField::TYPE_CHECKBOX:
- $tpl->display('file:' . $tpl_path . 'internal/views/criteria/__cfield_checkbox.tpl');
- break;
- case Model_CustomField::TYPE_DATE:
- $tpl->display('file:' . $tpl_path . 'internal/views/criteria/__date.tpl');
- break;
- case Model_CustomField::TYPE_NUMBER:
- $tpl->display('file:' . $tpl_path . 'internal/views/criteria/__number.tpl');
- break;
- case Model_CustomField::TYPE_WORKER:
- $tpl->assign('workers', DAO_Worker::getAllActive());
- $tpl->display('file:' . $tpl_path . 'internal/views/criteria/__worker.tpl');
- break;
- default:
- $tpl->display('file:' . $tpl_path . 'internal/views/criteria/__string.tpl');
- break;
- }
- }
-
- /**
- * Enter description here...
- *
- * @param string $field
- * @param string $oper
- * @param string $value
- * @abstract
- */
- function doSetCriteria($field, $oper, $value) {
- // Expect Override
- }
- protected function _doSetCriteriaCustomField($token, $field_id) {
- $field = DAO_CustomField::get($field_id);
- @$oper = DevblocksPlatform::importGPC($_POST['oper'],'string','');
- @$value = DevblocksPlatform::importGPC($_POST['value'],'string','');
-
- $criteria = null;
-
- switch($field->type) {
- case Model_CustomField::TYPE_DROPDOWN:
- case Model_CustomField::TYPE_MULTI_PICKLIST:
- case Model_CustomField::TYPE_MULTI_CHECKBOX:
- @$options = DevblocksPlatform::importGPC($_POST['options'],'array',array());
- if(!empty($options)) {
- $criteria = new DevblocksSearchCriteria($token,$oper,$options);
- } else {
- $criteria = new DevblocksSearchCriteria($token,DevblocksSearchCriteria::OPER_IS_NULL);
- }
- break;
- case Model_CustomField::TYPE_CHECKBOX:
- $criteria = new DevblocksSearchCriteria($token,$oper,!empty($value) ? 1 : 0);
- break;
- case Model_CustomField::TYPE_NUMBER:
- $criteria = new DevblocksSearchCriteria($token,$oper,intval($value));
- break;
- case Model_CustomField::TYPE_DATE:
- @$from = DevblocksPlatform::importGPC($_REQUEST['from'],'string','');
- @$to = DevblocksPlatform::importGPC($_REQUEST['to'],'string','');
-
- if(empty($from)) $from = 0;
- if(empty($to)) $to = 'today';
-
- $criteria = new DevblocksSearchCriteria($token,$oper,array($from,$to));
- break;
- case Model_CustomField::TYPE_WORKER:
- @$oper = DevblocksPlatform::importGPC($_REQUEST['oper'],'string','eq');
- @$worker_ids = DevblocksPlatform::importGPC($_POST['worker_id'],'array',array());
-
- $criteria = new DevblocksSearchCriteria($token,$oper,$worker_ids);
- break;
- default: // TYPE_SINGLE_LINE || TYPE_MULTI_LINE
- if(($oper == DevblocksSearchCriteria::OPER_LIKE || $oper == DevblocksSearchCriteria::OPER_NOT_LIKE)
- && false === (strpos($value,'*'))) {
- $value = '*'.$value.'*';
- }
- $criteria = new DevblocksSearchCriteria($token,$oper,$value);
- break;
- }
-
- return $criteria;
- }
-
- /**
- * This method automatically fixes any cached strange options, like
- * deleted custom fields.
- *
- */
- protected function _sanitize() {
- $fields = $this->getColumns();
- $custom_fields = DAO_CustomField::getAll();
- $needs_save = false;
-
- // Parameter sanity check
- if(is_array($this->params))
- foreach($this->params as $pidx => $null) {
- if(substr($pidx,0,3)!="cf_")
- continue;
-
- if(0 != ($cf_id = intval(substr($pidx,3)))) {
- // Make sure our custom fields still exist
- if(!isset($custom_fields[$cf_id])) {
- unset($this->params[$pidx]);
- $needs_save = true;
- }
- }
- }
-
- // View column sanity check
- if(is_array($this->view_columns))
- foreach($this->view_columns as $cidx => $c) {
- // Custom fields
- if(substr($c,0,3) == "cf_") {
- if(0 != ($cf_id = intval(substr($c,3)))) {
- // Make sure our custom fields still exist
- if(!isset($custom_fields[$cf_id])) {
- unset($this->view_columns[$cidx]);
- $needs_save = true;
- }
- }
- } else {
- // If the column no longer exists (rare but worth checking)
- if(!isset($fields[$c])) {
- unset($this->view_columns[$cidx]);
- $needs_save = true;
- }
- }
- }
-
- // Sort by sanity check
- if(substr($this->renderSortBy,0,3)=="cf_") {
- if(0 != ($cf_id = intval(substr($this->renderSortBy,3)))) {
- if(!isset($custom_fields[$cf_id])) {
- $this->renderSortBy = null;
- $needs_save = true;
- }
- }
- }
-
- if($needs_save) {
- C4_AbstractViewLoader::setView($this->id, $this);
- }
- }
-
- function renderCriteriaParam($param) {
- $field = $param->field;
- $vals = $param->value;
- if(!is_array($vals))
- $vals = array($vals);
- // Do we need to do anything special on custom fields?
- if('cf_'==substr($field,0,3)) {
- $field_id = intval(substr($field,3));
- $custom_fields = DAO_CustomField::getAll();
-
- switch($custom_fields[$field_id]->type) {
- case Model_CustomField::TYPE_WORKER:
- $workers = DAO_worker::getAll();
- foreach($vals as $idx => $worker_id) {
- if(isset($workers[$worker_id]))
- $vals[$idx] = $workers[$worker_id]->getName();
- }
- break;
- }
- }
-
- echo implode(', ', $vals);
- }
- /**
- * All the view's available fields
- *
- * @return array
- */
- static function getFields() {
- // Expect Override
- return array();
- }
- /**
- * All searchable fields
- *
- * @return array
- */
- static function getSearchFields() {
- // Expect Override
- return array();
- }
- /**
- * All fields that can be displayed as columns in the view
- *
- * @return array
- */
- static function getColumns() {
- // Expect Override
- return array();
- }
- function doCustomize($columns, $num_rows=10) {
- $this->renderLimit = $num_rows;
- $viewColumns = array();
- foreach($columns as $col) {
- if(empty($col))
- continue;
- $viewColumns[] = $col;
- }
- $this->view_columns = $viewColumns;
- }
- function doSortBy($sortBy) {
- $iSortAsc = intval($this->renderSortAsc);
- // [JAS]: If clicking the same header, toggle asc/desc.
- if(0 == strcasecmp($sortBy,$this->renderSortBy)) {
- $iSortAsc = (0 == $iSortAsc) ? 1 : 0;
- } else { // [JAS]: If a new header, start with asc.
- $iSortAsc = 1;
- }
- $this->renderSortBy = $sortBy;
- $this->renderSortAsc = $iSortAsc;
- }
- function doPage($page) {
- $this->renderPage = $page;
- }
- function doRemoveCriteria($field) {
- unset($this->params[$field]);
- $this->renderPage = 0;
- }
- function doResetCriteria() {
- $this->params = array();
- $this->renderPage = 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);
- }
- }
- }
- }
- };
- /**
- * Used to persist a C4_AbstractView instance and not be encumbered by
- * classloading issues (out of the session) from plugins that might have
- * concrete AbstractView implementations.
- */
- class C4_AbstractViewModel {
- public $class_name = '';
- public $id = 0;
- public $name = "";
- public $view_columns = array();
- public $params = array();
- public $renderPage = 0;
- public $renderLimit = 10;
- public $renderSortBy = '';
- public $renderSortAsc = 1;
- };
- /**
- * This is essentially an AbstractView Factory
- */
- class C4_AbstractViewLoader {
- static $views = null;
- const VISIT_ABSTRACTVIEWS = 'abstractviews_list';
- static private function _init() {
- $visit = CerberusApplication::getVisit();
- self::$views = $visit->get(self::VISIT_ABSTRACTVIEWS,array());
- }
- /**
- * @param string $view_label Abstract view identifier
- * @return boolean
- */
- static function exists($view_label) {
- if(is_null(self::$views)) self::_init();
- return isset(self::$views[$view_label]);
- }
- /**
- * Enter description here...
- *
- * @param string $class C4_AbstractView
- * @param string $view_label ID
- * @return C4_AbstractView instance
- */
- static function getView($view_label, C4_AbstractViewModel $defaults=null) {
- $active_worker = CerberusApplication::getActiveWorker();
- if(is_null(self::$views)) self::_init();
- if(self::exists($view_label)) {
- $model = self::$views[$view_label];
- return self::unserializeAbstractView($model);
-
- } else {
- // See if the worker has their own saved prefs
- @$prefs = unserialize(DAO_WorkerPref::get($active_worker->id, 'view'.$view_label));
- // If no worker prefsd, check if we're passed defaults
- if((empty($prefs) || !$prefs instanceof C4_AbstractViewModel) && !empty($defaults))
- $prefs = $defaults;
-
- // Create a default view if it doesn't exist
- if(!empty($prefs) && $prefs instanceof C4_AbstractViewModel) {
- if(!empty($prefs->class_name) || class_exists($prefs->class_name)) {
- $view = new $prefs->class_name;
- $view->id = $view_label;
- if(!empty($prefs->view_columns))
- $view->view_columns = $prefs->view_columns;
- if(!empty($prefs->renderLimit))
- $view->renderLimit = $prefs->renderLimit;
- if(null !== $prefs->renderSortBy)
- $view->renderSortBy = $prefs->renderSortBy;
- if(null !== $prefs->renderSortAsc)
- $view->renderSortAsc = $prefs->renderSortAsc;
- self::setView($view_label, $view);
- return $view;
- }
- }
-
- }
- return null;
- }
- /**
- * Enter description here...
- *
- * @param string $class C4_AbstractView
- * @param string $view_label ID
- * @param C4_AbstractView $view
- */
- static function setView($view_label, $view) {
- if(is_null(self::$views)) self::_init();
- self::$views[$view_label] = self::serializeAbstractView($view);
- self::_save();
- }
- static function deleteView($view_label) {
- unset(self::$views[$view_label]);
- self::_save();
- }
-
- static private function _save() {
- // persist
- $visit = CerberusApplication::getVisit();
- $visit->set(self::VISIT_ABSTRACTVIEWS, self::$views);
- }
- static function serializeAbstractView($view) {
- if(!$view instanceof C4_AbstractView) {
- return null;
- }
- $model = new C4_AbstractViewModel();
-
- $model->class_name = get_class($view);
- $model->id = $view->id;
- $model->name = $view->name;
- $model->view_columns = $view->view_columns;
- $model->params = $view->params;
- $model->renderPage = $view->renderPage;
- $model->renderLimit = $view->renderLimit;
- $model->renderSortBy = $view->renderSortBy;
- $model->renderSortAsc = $view->renderSortAsc;
- return $model;
- }
- static function unserializeAbstractView(C4_AbstractViewModel $model) {
- if(!class_exists($model->class_name, true))
- return null;
-
- if(null == ($inst = new $model->class_name))
- return null;
- /* @var $inst C4_AbstractView */
-
- $inst->id = $model->id;
- $inst->name = $model->name;
- $inst->view_columns = $model->view_columns;
- $inst->params = $model->params;
- $inst->renderPage = $model->renderPage;
- $inst->renderLimit = $model->renderLimit;
- $inst->renderSortBy = $model->renderSortBy;
- $inst->renderSortAsc = $model->renderSortAsc;
- return $inst;
- }
- };
- class Model_Address {
- public $id;
- public $email = '';
- public $first_name = '';
- public $last_name = '';
- public $contact_org_id = 0;
- public $num_spam = 0;
- public $num_nonspam = 0;
- public $is_banned = 0;
- public $is_registered = 0;
- public $pass = '';
- public $last_autoreply;
- function Model_Address() {}
-
- function getName() {
- return sprintf("%s%s%s",
- $this->first_name,
- (!empty($this->first_name) && !empty($this->last_name)) ? " " : "",
- $this->last_name
- );
- }
- };
- class Model_AddressToWorker {
- public $address;
- public $worker_id;
- public $is_confirmed;
- public $code;
- public $code_expire;
- }
- class View_DevblocksTemplate extends C4_AbstractView {
- const DEFAULT_ID = 'templates';
- function __construct() {
- $this->id = self::DEFAULT_ID;
- $this->name = 'Templates';
- $this->renderLimit = 25;
- $this->renderSortBy = SearchFields_DevblocksTemplate::PATH;
- $this->renderSortAsc = true;
- $this->view_columns = array(
- SearchFields_DevblocksTemplate::PLUGIN_ID,
- // SearchFields_DevblocksTemplate::TAG,
- SearchFields_DevblocksTemplate::LAST_UPDATED,
- );
-
- $this->doResetCriteria();
- }
- function getData() {
- return DAO_DevblocksTemplate::search(
- $this->view_columns,
- $this->params,
- $this->renderLimit,
- $this->renderPage,
- $this->renderSortBy,
- $this->renderSortAsc
- );
- }
- function render() {
- $this->_sanitize();
-
- $tpl = DevblocksPlatform::getTemplateService();
- $tpl->assign('id', $this->id);
- $tpl->assign('view', $this);
- // $custom_fields = DAO_CustomField::getBySource(ChCustomFieldSource_Worker::ID);
- // $tpl->assign('custom_fields', $custom_fields);
- $tpl->assign('view_fields', $this->getColumns());
- $tpl->display('file:' . APP_PATH . '/features/usermeet.core/templates/community/display/tabs/templates/view.tpl');
- }
- function renderCriteria($field) {
- $tpl = DevblocksPlatform::getTemplateService();
- $tpl->assign('id', $this->id);
- switch($field) {
- case SearchFields_DevblocksTemplate::CONTENT:
- case SearchFields_DevblocksTemplate::PATH:
- case SearchFields_DevblocksTemplate::PLUGIN_ID:
- case SearchFields_DevblocksTemplate::TAG:
- $tpl->display('file:' . APP_PATH . '/features/cerberusweb.core/templates/internal/views/criteria/__string.tpl');
- break;
- case SearchFields_DevblocksTemplate::LAST_UPDATED:
- $tpl->display('file:' . APP_PATH . '/features/cerberusweb.core/templates/internal/views/criteria/__date.tpl');
- break;
- default:
- // Custom Fields
- // if('cf_' == substr($field,0,3)) {
- // $this->_renderCriteriaCustomField($tpl, substr($field,3));
- // } else {
- // echo ' ';
- // }
- break;
- }
- }
- function renderCriteriaParam($param) {
- $field = $param->field;
- $values = !is_array($param->value) ? array($param->value) : $param->value;
- switch($field) {
- // case SearchFields_WorkerEvent::WORKER_ID:
- // $workers = DAO_Worker::getAll();
- // $strings = array();
- //
- // foreach($values as $val) {
- // if(empty($val))
- // $strings[] = "Nobody";
- // elseif(!isset($workers[$val]))
- // continue;
- // else
- // $strings[] = $workers[$val]->getName();
- // }
- // echo implode(", ", $strings);
- // break;
- default:
- parent::renderCriteriaParam($param);
- break;
- }
- }
- static function getFields() {
- return SearchFields_DevblocksTemplate::getFields();
- }
- static function getSearchFields() {
- $fields = self::getFields();
- return $fields;
- }
- static function getColumns() {
- $fields = self::getFields();
- return $fields;
- }
- function doResetCriteria() {
- parent::doResetCriteria();
-
- // $this->params = array(
- // SearchFields_WorkerEvent::NUM_NONSPAM => new DevblocksSearchCriteria(SearchFields_WorkerEvent::NUM_NONSPAM,'>',0),
- // );
- }
-
- function doSetCriteria($field, $oper, $value) {
- $criteria = null;
- switch($field) {
- case SearchFields_DevblocksTemplate::CONTENT:
- case SearchFields_DevblocksTemplate::PATH:
- case SearchFields_DevblocksTemplate::PLUGIN_ID:
- case SearchFields_DevblocksTemplate::TAG:
- // force wildcards if none used on a LIKE
- if(($oper == DevblocksSearchCriteria::OPER_LIKE || $oper == DevblocksSearchCriteria::OPER_NOT_LIKE)
- && false === (strpos($value,'*'))) {
- $value = '*'.$value.'*';
- }
- $criteria = new DevblocksSearchCriteria($field, $oper, $value);
- break;
-
- case SearchFields_DevblocksTemplate::LAST_UPDATED:
- @$from = DevblocksPlatform::importGPC($_REQUEST['from'],'string','');
- @$to = DevblocksPlatform::importGPC($_REQUEST['to'],'string','');
- if(empty($from)) $from = 0;
- if(empty($to)) $to = 'today';
- $criteria = new DevblocksSearchCriteria($field,$oper,array($from,$to));
- break;
-
- default:
- // Custom Fields
- // if(substr($field,0,3)=='cf_') {
- // $criteria = $this->_doSetCriteriaCustomField($field, substr($field,3));
- // }
- break;
- }
- if(!empty($criteria)) {
- $this->params[$field] = $criteria;
- $this->renderPage = 0;
- }
- }
- function doBulkUpdate($filter, $do, $ids=array()) {
- @set_time_limit(600); // [TODO] Temp!
-
- $change_fields = array();
- $deleted = false;
- $custom_fields = array();
- if(empty($do))
- return;
- // Make sure we have checked items if we want a checked list
- if(0 == strcasecmp($filter,"checks") && empty($ids))
- return;
- if(is_array($do))
- foreach($do as $k => $v) {
- switch($k) {
- case 'deleted':
- $deleted = true;
- break;
- default:
- // Custom fields
- if(substr($k,0,3)=="cf_") {
- $custom_fields[substr($k,3)] = $v;
- }
- break;
- }
- }
- $pg = 0;
- if(empty($ids))
- do {
- list($objects,$null) = DAO_DevblocksTemplate::search(
- array(),
- $this->params,
- 100,
- $pg++,
- DAO_DevblocksTemplate::ID,
- true,
- false
- );
-
- $ids = array_merge($ids, array_keys($objects));
-
- } while(!empty($objects));
- $batch_total = count($ids);
- for($x=0;$x<=$batch_total;$x+=100) {
- $batch_ids = array_slice($ids,$x,100);
-
- if(!$deleted)
- DAO_DevblocksTemplate::update($batch_ids, $change_fields);
- else
- DAO_DevblocksTemplate::delete($batch_ids);
-
- // Custom Fields
- // self::_doBulkSetCustomFields(ChCustomFieldSource_Worker::ID, $custom_fields, $batch_ids);
-
- unset($batch_ids);
- }
-
- if($deleted) {
- // Clear template cache
- $tpl = DevblocksPlatform::getTemplateService();
- $tpl->clear_compiled_tpl();
- }
- unset($ids);
- }
- };
- class C4_TicketView extends C4_AbstractView {
- const DEFAULT_ID = 'tickets_workspace';
- function __construct() {
- $this->id = self::DEFAULT_ID;
- $this->name = 'Tickets';
- $this->renderLimit = 10;
- $this->renderSortBy = SearchFields_Ticket::TICKET_UPDATED_DATE;
- $this->renderSortAsc = false;
- $this->view_columns = array(
- SearchFields_Ticket::TICKET_LAST_ACTION_CODE,
- SearchFields_Ticket::TICKET_UPDATED_DATE,
- SearchFields_Ticket::TICKET_TEAM_ID,
- SearchFields_Ticket::TICKET_CATEGORY_ID,
- SearchFields_Ticket::TICKET_SPAM_SCORE,
- );
- }
- function getData() {
- $objects = DAO_Ticket::search(
- $this->view_columns,
- $this->params,
- $this->renderLimit,
- $this->renderPage,
- $this->renderSortBy,
- $this->renderSortAsc
- );
- return $objects;
- }
- function render() {
- $this->_sanitize();
-
- $tpl = DevblocksPlatform::getTemplateService();
- $tpl->assign('id', $this->id);
- $view_path = APP_PATH . '/features/cerberusweb.core/templates/tickets/';
- $tpl->assign('view_path',$view_path);
- $tpl->assign('view', $this);
- $visit = CerberusApplication::getVisit();
- $results = self::getData();
- $tpl->assign('results', $results);
-
- @$ids = array_keys($results[0]);
-
- $workers = DAO_Worker::getAll();
- $tpl->assign('workers', $workers);
- $teams = DAO_Group::getAll();
- $tpl->assign('teams', $teams);
- $buckets = DAO_Bucket::getAll();
- $tpl->assign('buckets', $buckets);
- $team_categories = DAO_Bucket::getTeams();
- $tpl->assign('team_categories', $team_categories);
- $custom_fields = DAO_CustomField::getBySource(ChCustomFieldSource_Ticket::ID);
- $tpl->assign('custom_fields', $custom_fields);
-
- // Undo?
- $last_action = C4_TicketView::getLastAction($this->id);
- $tpl->assign('last_action', $last_action);
- if(!empty($last_action) && !is_null($last_action->ticket_ids)) {
- $tpl->assign('last_action_count', count($last_action->ticket_ids));
- }
- $tpl->assign('timestamp_now', time());
-
- $tpl->assign('view_fields', $this->getColumns());
- $tpl->display('file:' . $view_path . 'ticket_view.tpl');
- }
- function doResetCriteria() {
- $active_worker = CerberusApplication::getActiveWorker(); /* @var $active_worker CerberusWorker */
- $active_worker_memberships = $active_worker->getMemberships();
-
- $this->params = array(
- SearchFields_Ticket::TICKET_CLOSED => new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_CLOSED,'=',0),
- SearchFields_Ticket::TICKET_TEAM_ID => new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_TEAM_ID,'in',array_keys($active_worker_memberships)), // censor
- );
- $this->renderPage = 0;
- }
-
- function renderCriteria($field) {
- $tpl = DevblocksPlatform::getTemplateService();
- $tpl->assign('id', $this->id);
- $tpl_path = APP_PATH . '/features/cerberusweb.core/templates/';
- switch($field) {
- case SearchFields_Ticket::TICKET_ID:
- case SearchFields_Ticket::TICKET_MASK:
- case SearchFields_Ticket::TICKET_SUBJECT:
- case SearchFields_Ticket::TICKET_FIRST_WROTE:
- case SearchFields_Ticket::TICKET_LAST_WROTE:
- case SearchFields_Ticket::REQUESTER_ADDRESS:
- case SearchFields_Ticket::TICKET_INTERESTING_WORDS:
- case SearchFields_Ticket::ORG_NAME:
- $tpl->display('file:' . $tpl_path . 'internal/views/criteria/__string.tpl');
- break;
- case SearchFields_Ticket::TICKET_MESSAGE_CONTENT:
- $tpl->display('file:' . $tpl_path . 'internal/views/criteria/__fulltext.tpl');
- break;
-
- case SearchFields_Ticket::TICKET_FIRST_WROTE_SPAM:
- case SearchFields_Ticket::TICKET_FIRST_WROTE_NONSPAM:
- $tpl->display('file:' . $tpl_path . 'internal/views/criteria/__number.tpl');
- break;
-
- case SearchFields_Ticket::TICKET_WAITING:
- case SearchFields_Ticket::TICKET_DELETED:
- case SearchFields_Ticket::TICKET_CLOSED:
- $tpl->display('file:' . $tpl_path . 'internal/views/criteria/__bool.tpl');
- break;
-
- case SearchFields_Ticket::TICKET_CREATED_DATE:
- case SearchFields_Ticket::TICKET_UPDATED_DATE:
- case SearchFields_Ticket::TICKET_DUE_DATE:
- $tpl->display('file:' . $tpl_path . 'internal/views/criteria/__date.tpl');
- break;
-
- case SearchFields_Ticket::TICKET_SPAM_TRAINING:
- $tpl->display('file:' . $tpl_path . 'tickets/search/criteria/ticket_spam_training.tpl');
- break;
-
- case SearchFields_Ticket::TICKET_SPAM_SCORE:
- $tpl->display('file:' . $tpl_path . 'tickets/search/criteria/ticket_spam_score.tpl');
- break;
- case SearchFields_Ticket::TICKET_LAST_ACTION_CODE:
- $tpl->display('file:' . $tpl_path . 'tickets/search/criteria/ticket_last_action.tpl');
- break;
- case SearchFields_Ticket::TICKET_NEXT_WORKER_ID:
- case SearchFields_Ticket::TICKET_LAST_WORKER_ID:
- $workers = DAO_Worker::getAll();
- $tpl->assign('workers', $workers);
- $tpl->display('file:' . $tpl_path . 'internal/views/criteria/__worker.tpl');
- break;
-
- case SearchFields_Ticket::TICKET_TEAM_ID:
- $teams = DAO_Group::getAll();
- $tpl->assign('teams', $teams);
- $team_categories = DAO_Bucket::getTeams();
- $tpl->assign('team_categories', $team_categories);
- $tpl->display('file:' . $tpl_path . 'tickets/search/criteria/ticket_team.tpl');
- break;
- default:
- // Custom Fields
- if('cf_' == substr($field,0,3)) {
- $this->_renderCriteria…
Large files files are truncated, but you can click here to view the full file