function showSensorPeekAction() { @($id = DevblocksPlatform::importGPC($_REQUEST['id'], 'integer', 0)); @($view_id = DevblocksPlatform::importGPC($_REQUEST['view_id'], 'string', '')); $tpl = DevblocksPlatform::getTemplateService(); $tpl->assign('path', $this->_TPL_PATH); $tpl->assign('view_id', $view_id); if (null == ($sensor = DAO_Sensor::get($id))) { $sensor = new Model_Sensor(); $sensor->extension_id = 'sensor.external'; } $tpl->assign('sensor', $sensor); $sensor_types = DevblocksPlatform::getExtensions('portsensor.sensor', false); $tpl->assign('sensor_types', $sensor_types); // Sensor extension instance if (!empty($sensor->extension_id) && isset($sensor_types[$sensor->extension_id])) { $tpl->assign('sensor_extension', DevblocksPlatform::getExtension($sensor->extension_id, true)); } // Custom Fields $custom_fields = DAO_CustomField::getBySource(PsCustomFieldSource_Sensor::ID); $tpl->assign('custom_fields', $custom_fields); $custom_field_values = DAO_CustomFieldValue::getValuesBySourceIds(PsCustomFieldSource_Sensor::ID, $id); if (isset($custom_field_values[$id])) { $tpl->assign('custom_field_values', $custom_field_values[$id]); } $tpl->display('file:' . $this->_TPL_PATH . 'sensors/peek.tpl'); }
function showEntryAction() { @($active_worker = CerberusApplication::getActiveWorker()); @($view_id = DevblocksPlatform::importGPC($_REQUEST['view_id'], 'string', '')); $tpl = DevblocksPlatform::getTemplateService(); $tpl_path = dirname(dirname(__FILE__)) . '/templates/'; $tpl->assign('path', $this->plugin_path . '/templates/'); $tpl->assign('view_id', $view_id); // Editing @($id = DevblocksPlatform::importGPC($_REQUEST['id'], 'integer', 0)); // Creating @($msg_id = DevblocksPlatform::importGPC($_REQUEST['msg_id'], 'integer', 0)); @($quote = DevblocksPlatform::importGPC($_REQUEST['quote'], 'string', '')); @($url = DevblocksPlatform::importGPC($_REQUEST['url'], 'string', '')); @($source_ext_id = DevblocksPlatform::importGPC($_REQUEST['source_ext_id'], 'string', '')); @($source_id = DevblocksPlatform::importGPC($_REQUEST['source_id'], 'integer', 0)); /* * This treats procedurally created model objects * the same as existing objects */ if (empty($id)) { $model = new Model_FeedbackEntry(); if (!empty($msg_id)) { if (null != ($message = DAO_Ticket::getMessage($msg_id))) { $model->id = 0; $model->log_date = time(); $model->quote_address_id = $message->address_id; $model->quote_mood = 0; $model->quote_text = $quote; $model->worker_id = $active_worker->id; $model->source_url = $url; $tpl->assign('model', $model); } } } elseif (!empty($id)) { // Were we given a model ID to load? if (null != ($model = DAO_FeedbackEntry::get($id))) { $tpl->assign('model', $model); } } // Author (if not anonymous) if (!empty($model->quote_address_id)) { if (null != ($address = DAO_Address::get($model->quote_address_id))) { $tpl->assign('address', $address); } } if (!empty($source_ext_id)) { $tpl->assign('source_extension_id', $source_ext_id); $tpl->assign('source_id', $source_id); } // Custom fields $custom_fields = DAO_CustomField::getBySource(ChCustomFieldSource_FeedbackEntry::ID); $tpl->assign('custom_fields', $custom_fields); $custom_field_values = DAO_CustomFieldValue::getValuesBySourceIds(ChCustomFieldSource_FeedbackEntry::ID, $id); if (isset($custom_field_values[$id])) { $tpl->assign('custom_field_values', $custom_field_values[$id]); } $types = Model_CustomField::getTypes(); $tpl->assign('types', $types); $tpl->display('file:' . $this->plugin_path . '/templates/feedback/ajax/feedback_entry_panel.tpl'); }
function showTaskPeekAction() { @($id = DevblocksPlatform::importGPC($_REQUEST['id'], 'integer', '')); @($view_id = DevblocksPlatform::importGPC($_REQUEST['view_id'], 'string', '')); @($link_namespace = DevblocksPlatform::importGPC($_REQUEST['link_namespace'], 'string', '')); // opt @($link_object_id = DevblocksPlatform::importGPC($_REQUEST['link_object_id'], 'integer', 0)); // opt $tpl = DevblocksPlatform::getTemplateService(); $tpl->cache_lifetime = "0"; $path = $this->_TPL_PATH; $tpl->assign('path', $path); if (!empty($id)) { $task = DAO_Task::get($id); $tpl->assign('task', $task); if (!empty($task->source_extension) && !empty($task->source_id)) { if (null != ($mft = DevblocksPlatform::getExtension($task->source_extension))) { $source_info = $mft->createInstance(); @$tpl->assign('source_info', $source_info->getSourceInfo($task->source_id)); } } } // Only used on create if (!empty($link_namespace) && !empty($link_object_id)) { $tpl->assign('link_namespace', $link_namespace); $tpl->assign('link_object_id', $link_object_id); } $workers = DAO_Worker::getAllActive(); $tpl->assign('workers', $workers); // Custom fields $custom_fields = DAO_CustomField::getBySource(ChCustomFieldSource_Task::ID); $tpl->assign('custom_fields', $custom_fields); $custom_field_values = DAO_CustomFieldValue::getValuesBySourceIds(ChCustomFieldSource_Task::ID, $id); if (isset($custom_field_values[$id])) { $tpl->assign('custom_field_values', $custom_field_values[$id]); } $types = Model_CustomField::getTypes(); $tpl->assign('types', $types); // View $tpl->assign('id', $id); $tpl->assign('view_id', $view_id); $tpl->display('file:' . $path . 'tasks/rpc/peek.tpl'); }
function showOrgPeekAction() { @($id = DevblocksPlatform::importGPC($_REQUEST['id'], 'integer', '')); @($view_id = DevblocksPlatform::importGPC($_REQUEST['view_id'], 'string', '')); $tpl = DevblocksPlatform::getTemplateService(); $tpl->assign('path', $this->_TPL_PATH); $contact = DAO_ContactOrg::get($id); $tpl->assign('contact', $contact); // Custom fields $custom_fields = DAO_CustomField::getBySource(ChCustomFieldSource_Org::ID); $tpl->assign('custom_fields', $custom_fields); $custom_field_values = DAO_CustomFieldValue::getValuesBySourceIds(ChCustomFieldSource_Org::ID, $id); if (isset($custom_field_values[$id])) { $tpl->assign('custom_field_values', $custom_field_values[$id]); } $types = Model_CustomField::getTypes(); $tpl->assign('types', $types); // View $tpl->assign('view_id', $view_id); $tpl->display('file:' . $this->_TPL_PATH . 'contacts/orgs/org_peek.tpl'); }
static function getMatches(Model_Address $fromAddress, CerberusParserMessage $message) { // print_r($fromAddress); // print_r($message); $matches = array(); $rules = DAO_MailToGroupRule::getWhere(); $message_headers = $message->headers; $custom_fields = DAO_CustomField::getAll(); // Lazy load when needed on criteria basis $address_field_values = null; $org_field_values = null; // Check filters if (is_array($rules)) { foreach ($rules as $rule) { /* @var $rule Model_MailToGroupRule */ $passed = 0; // check criteria foreach ($rule->criteria as $crit_key => $crit) { @($value = $crit['value']); switch ($crit_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($crit[$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 = @$crit['from'])) { list($from_hour, $from_min) = explode(':', $from_time); } if (null != ($to_time = @$crit['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 '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, $fromAddress->email)) { $passed++; } break; case 'subject': // [TODO] Decode if necessary @($subject = $message_headers['subject']); $regexp_subject = DevblocksPlatform::strToRegExp($value); if (@preg_match($regexp_subject, $subject)) { $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 'header1': case 'header2': case 'header3': case 'header4': case 'header5': @($header = strtolower($crit['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($crit_key, 0, 3))) { $field_id = substr($crit_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, $fromAddress->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, $fromAddress->contact_org_id)); } $field_values =& $org_field_values; break; } // No values, default. if (!isset($field_values[$field_id])) { continue; } // Type sensitive value comparisons 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($crit['oper']) ? $crit['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($crit['oper']) ? $crit['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($crit['from']) ? $crit['from'] : "0"; $to = isset($crit['to']) ? $crit['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($rule->criteria)) { DAO_MailToGroupRule::increment($rule->id); // ++ the times we've matched $matches[$rule->id] = $rule; // Bail out if this rule had a move action if (isset($rule->actions['move'])) { return $matches; } } } } // If we're at the end of rules and didn't bail out yet if (!empty($matches)) { return $matches; } // No matches return NULL; }
function AnswernetMetlifeReportDRReport($RunFromCron = 0) { $db = DevblocksPlatform::getDatabaseService(); $translate = DevblocksPlatform::getTranslationService(); if ($RunFromCron) { $logger = DevblocksPlatform::getConsoleLog(); } $radius = 12; $start_time = 0; date_default_timezone_set('Etc/UTC'); // Security if (null == ($active_worker = CerberusApplication::getActiveWorker())) { die($translate->_('common.access_denied')); } // import dates from form @($start = DevblocksPlatform::importGPC($_REQUEST['start'], 'string', '')); if (empty($start)) { $start = "Yesterday"; } $start_time = strtotime($start); if ($start_time === false) { $start = "Yesterday"; $start_time = strtotime($start); } if (empty($start_time) || !is_numeric($start_time)) { return; } $start_ofday = mktime(0, 0, 0, date("m", $start_time), date("d", $start_time), date("Y", $start_time)); $end_ofday = $start_ofday + 86400; if ($RunFromCron) { $logger->info("[Answernet.com] Gerating the Metlife DR Report."); $logger->info("[Answernet.com] " . $translate->_('answernet.er.metlife.report.dr.date.from.text') . date(" Y-m-d H:i:s ", $start_ofday) . $translate->_('answernet.er.metlife.report.dr.date.to.text') . date(" Y-m-d H:i:s T", $end_ofday)); $logger->info("[Answernet.com] " . $translate->_('answernet.er.metlife.generate.report')); } else { print '<br><br><br>'; print $translate->_('answernet.er.metlife.report.dr.date.from.text'); print date(" Y-m-d H:i:s ", $start_ofday); print $translate->_('answernet.er.metlife.report.dr.date.to.text'); print date(" Y-m-d H:i:s T", $end_ofday); print '<br>'; print $translate->_('answernet.er.metlife.generate.report'); } $filename = "report-metlife-dr-" . date("Ymd", $start_time) . ".xls"; $full_filename = getcwd() . '/storage/answernet/' . $filename; if ($RunFromCron) { $logger->info("[Answernet.com] " . $translate->_('answernet.er.metlife.generating')); } else { print '<br>'; print $translate->_('answernet.er.metlife.generating'); } // Create new Excel Spreadsheet. $workbook = new Spreadsheet_Excel_Writer($full_filename); // Create Open Status Tab and set Column Width and Row Hight. $worksheet_transaction =& $workbook->addWorksheet('Transaction Report'); $worksheet_transaction->setColumn(0, 0, $radius * 0.85); $worksheet_transaction->setColumn(1, 1, $radius * 0.85); $worksheet_transaction->setColumn(2, 2, $radius * 0.35); $worksheet_transaction->setColumn(3, 3, $radius * 1.65); $worksheet_transaction->setColumn(4, 4, $radius * 1.85); $worksheet_transaction->setColumn(5, 5, $radius * 1.16); $worksheet_transaction->setColumn(6, 6, $radius * 2.6); $worksheet_transaction->setColumn(7, 8, $radius * 0.87); $worksheet_transaction->setColumn(9, 9, $radius * 3.28); $worksheet_transaction->setColumn(10, 10, $radius * 1.34); // $worksheet_open_status->setRow(0, 28); // $worksheet_open_status->setRow(2, 32); // Create Open Status Tab and set Column Width and Row Hight. $worksheet_open_status =& $workbook->addWorksheet('Open DR Report'); $worksheet_open_status->setColumn(0, 0, $radius * 0.85); $worksheet_open_status->setColumn(1, 1, $radius * 0.35); $worksheet_open_status->setColumn(2, 2, $radius * 0.7); $worksheet_open_status->setColumn(3, 3, $radius * 1.65); $worksheet_open_status->setColumn(4, 4, $radius * 1.85); $worksheet_open_status->setColumn(5, 5, $radius * 1.16); $worksheet_open_status->setColumn(6, 6, $radius * 2.6); $worksheet_open_status->setColumn(7, 8, $radius * 0.87); $worksheet_open_status->setColumn(9, 9, $radius * 3.28); $worksheet_open_status->setColumn(10, 10, $radius * 1.34); // $worksheet_open_status->setRow(0, 28); // $worksheet_open_status->setRow(2, 32); // Create monthly Tab and set Column Width and Row Hight. $worksheet_monthly =& $workbook->addWorksheet('Month DR Summary'); $worksheet_monthly->setColumn(0, 0, $radius * 2.46); $worksheet_monthly->setColumn(1, 1, $radius * 0.47); $worksheet_monthly->setColumn(2, 2, $radius * 0.63); $worksheet_monthly->setColumn(3, 3, $radius * 0.6899999999999999); $worksheet_monthly->setColumn(4, 4, $radius * 0.6899999999999999); $worksheet_monthly->setColumn(5, 5, $radius * 0.6899999999999999); // $worksheet_monthly->setRow(0, 56); // Formats used thoughout the workbook. $format_general =& $workbook->addFormat(); $format_general->setBorder(1); $format_general->setHAlign('left'); $format_general->setTextWrap(); $format_general_title =& $workbook->addFormat(); $format_general_title->setBorder(1); $format_general_title->setColor('black'); $format_general_title->setFgColor('silver'); $format_general_title->setHAlign('left'); $format_general_title->setVAlign('vjustify'); $format_general_title->setVAlign('top'); $format_general_nowrap =& $workbook->addFormat(); $format_general_nowrap->setBorder(1); // Setup templating for the formating of certain cells in the Monthly Group. $format_monthly_title =& $workbook->addFormat(); $format_monthly_title->setColor(8); $format_monthly_title->setFgColor(35); $format_monthly_title->setBorder(1); $format_monthly_title->setBold(); $format_monthly_title->setHAlign('center'); $format_monthly_title->setVAlign('vjustify'); $format_monthly_title->setVAlign('top'); $format_monthly_title->setTextWrap(); $format_monthly_title->setAlign('merge'); // Added headers since they never change in the transaction Group. $worksheet_transaction->write(0, 0, 'Status', $format_general_title); $worksheet_transaction->write(0, 1, 'Due Date', $format_general_title); $worksheet_transaction->write(0, 2, 'SLA', $format_general_title); $worksheet_transaction->write(0, 3, 'Date Received', $format_general_title); $worksheet_transaction->write(0, 4, 'RM Name', $format_general_title); $worksheet_transaction->write(0, 5, 'RM Employee id', $format_general_title); $worksheet_transaction->write(0, 6, 'Request Type', $format_general_title); $worksheet_transaction->write(0, 7, 'MetLife Staff', $format_general_title); $worksheet_transaction->write(0, 8, 'New Hire', $format_general_title); $worksheet_transaction->write(0, 9, 'Nates (email body)', $format_general_title); $worksheet_transaction->write(0, 10, 'Ticket Mask', $format_general_title); // Added headers since they never change in the Open Status Group. $worksheet_open_status->write(0, 0, 'Due Date', $format_general_title); $worksheet_open_status->write(0, 1, 'SLA', $format_general_title); $worksheet_open_status->write(0, 2, 'Overdue', $format_general_title); $worksheet_open_status->write(0, 3, 'Date Received', $format_general_title); $worksheet_open_status->write(0, 4, 'RM Name', $format_general_title); $worksheet_open_status->write(0, 5, 'RM Employee id', $format_general_title); $worksheet_open_status->write(0, 6, 'Request Type', $format_general_title); $worksheet_open_status->write(0, 7, 'MetLife Staff', $format_general_title); $worksheet_open_status->write(0, 8, 'New Hire', $format_general_title); $worksheet_open_status->write(0, 9, 'Nates (email body)', $format_general_title); $worksheet_open_status->write(0, 10, 'Ticket Mask', $format_general_title); // Added headers since they never change in the monthly Group. $month_text = date("F-y", $start_time); $worksheet_monthly->write(0, 0, $month_text, $format_monthly_title); $worksheet_monthly->write(0, 1, '', $format_monthly_title); $worksheet_monthly->write(0, 2, '', $format_monthly_title); $worksheet_monthly->write(0, 3, '', $format_monthly_title); $worksheet_monthly->write(0, 4, '', $format_monthly_title); $worksheet_monthly->write(0, 5, '', $format_monthly_title); $worksheet_monthly->write(1, 0, 'DR Summary', $format_general_title); $worksheet_monthly->write(1, 1, '', $format_general_title); $worksheet_monthly->write(2, 0, 'All DRs incoming*', $format_general); $worksheet_monthly->write(3, 0, 'DRs Sent to MetLife', $format_general); $worksheet_monthly->write(4, 0, 'DRs Completed', $format_general); $worksheet_monthly->write(5, 0, 'Average time to reply (day)', $format_general); $worksheet_monthly->write(6, 0, 'Missed DR SLA', $format_general); $worksheet_monthly->write(7, 0, 'DR escalations', $format_general); $worksheet_monthly->write(8, 0, 'DR Unique Users', $format_general); $worksheet_monthly->write(9, 0, 'New Hires (30 Days)', $format_general); $worksheet_monthly->write(10, 0, '', $format_general); $worksheet_monthly->write(10, 1, '', $format_general); $worksheet_monthly->write(11, 0, 'DR Categories', $format_general_title); $worksheet_monthly->write(11, 1, '#s', $format_general_title); $worksheet_monthly->write(11, 2, 'Avg SLA', $format_general_title); $worksheet_monthly->write(11, 3, 'Linda #s', $format_general_title); $worksheet_monthly->write(11, 4, 'Colin #s', $format_general_title); $worksheet_monthly->write(11, 5, 'Sarfraz #s', $format_general_title); $worksheet_monthly->write(12, 0, 'Import Contacts - New hire', $format_general); $worksheet_monthly->write(13, 0, 'Import Contacts', $format_general); $worksheet_monthly->write(14, 0, 'Create mailing list from exiting date', $format_general); $worksheet_monthly->write(15, 0, 'Update existing contacts - batch', $format_general); $worksheet_monthly->write(16, 0, 'Missing or incorrect customer info', $format_general); $worksheet_monthly->write(17, 0, 'Fix duplicate contacts', $format_general); $worksheet_monthly->write(18, 0, 'Export third party file', $format_general); $worksheet_monthly->write(19, 0, 'Other', $format_general); $worksheet_monthly->write(20, 0, 'Total', $format_general_title); $worksheet_monthly->write(20, 1, '', $format_general_title); $worksheet_monthly->write(20, 2, '', $format_general_title); $worksheet_monthly->write(20, 3, '', $format_general_title); $worksheet_monthly->write(20, 4, '', $format_general_title); $worksheet_monthly->write(20, 5, '', $format_general_title); $worksheet_monthly->write(22, 0, '* Some DRs will be deemed normal care and should use other reporting codes, remove from DR reporting', $format_general_nowrap); $worksheet_monthly->write(23, 0, '** Days should be tracked as business days', $format_general_nowrap); $worksheet_monthly->write(25, 0, 'SLA Goals', $format_general_title); $worksheet_monthly->write(25, 1, '', $format_general_title); $worksheet_monthly->write(26, 0, 'Import Contacts - New hire', $format_general); $worksheet_monthly->write(27, 0, 'Import Contacts', $format_general); $worksheet_monthly->write(28, 0, 'Create mailing list from exiting date', $format_general); $worksheet_monthly->write(29, 0, 'Update existing contacts - batch', $format_general); $worksheet_monthly->write(30, 0, 'Missing or incorrect customer info', $format_general); $worksheet_monthly->write(31, 0, 'Fix duplicate contacts', $format_general); $worksheet_monthly->write(32, 0, 'Export third party file', $format_general); $worksheet_monthly->write(33, 0, 'Other', $format_general); $worksheet_monthly->write(34, 0, 'Avgerage', $format_general_title); $worksheet_monthly->write(34, 1, '', $format_general_title); if ($RunFromCron) { $logger->info("[Answernet.com] " . $translate->_('answernet.er.metlife.metlife.done')); $logger->info("[Answernet.com] " . $translate->_('answernet.er.metlife.generating.dr.daily.report')); } else { print $translate->_('answernet.er.metlife.metlife.done'); print '<br>'; print $translate->_('answernet.er.metlife.generating.dr.daily.report'); } //SELECT t.id, t.mask, t.created_date ticket_created_date, mc.content, t.is_closed //FROM ticket t //INNER JOIN message_content mc on t.first_message_id = mc.message_id //INNER JOIN message m on t.first_message_id = m.id //and team_id = 1721 //ORDER BY t.id $sql = "SELECT t.id, t.mask, "; $sql .= "t.created_date ticket_created_date, mc.content "; $sql .= "FROM ticket t "; $sql .= "INNER JOIN message_content mc on t.first_message_id = mc.message_id "; $sql .= "WHERE t.is_closed = 0 "; $sql .= "and t.team_id = 1721 "; $sql .= "ORDER BY t.id "; $rs = $db->Execute($sql); $row = 1; if (is_a($rs, 'ADORecordSet')) { while (!$rs->EOF) { $worksheet_open_status->setRow($row, 12); $custom_fields = DAO_CustomFieldValue::getValuesBySourceIds(ChCustomFieldSource_Ticket::ID, $rs->fields['id']); //print "<pre>"; //print_r($custom_fields); //print "</pre>"; // Due Date, SLA, Date Recived, RM Name, RM Employee ID, Topic, Staff, New Hire, Notes/Email Body // Due Date Column 0 $due_date_int = intval($custom_fields[$rs->fields['id']][1]); if ($due_date_int) { $ticket_due_date = date("n/j/y", $due_date_int); } else { $ticket_due_date = ""; } $worksheet_open_status->writeString($row, 0, $ticket_due_date, $format_general); // SLA Column 1 $worksheet_open_status->write($row, 1, $custom_fields[$rs->fields['id']][5], $format_general); // Overdue Column 2 if (date("U", $due_date_int) >= time()) { $worksheet_open_status->write($row, 2, "No", $format_general); } else { $worksheet_open_status->write($row, 2, "Yes", $format_general); } // Date Recieved Column 3 $ticket_created_date = date("n/j/y g:i:s A", intval($rs->fields['ticket_created_date'])); $worksheet_open_status->writeString($row, 3, $ticket_created_date, $format_general); // RM Name Column 4 $worksheet_open_status->write($row, 4, $custom_fields[$rs->fields['id']][3], $format_general); // RM Employee ID Column 5 $worksheet_open_status->write($row, 5, $custom_fields[$rs->fields['id']][2], $format_general); // Topic / Request Type Column 6 $worksheet_open_status->write($row, 6, $custom_fields[$rs->fields['id']][4], $format_general); // Staff Column 7 $worksheet_open_status->write($row, 7, $custom_fields[$rs->fields['id']][8], $format_general); // New Hire Column 8 $worksheet_open_status->write($row, 8, $custom_fields[$rs->fields['id']][6], $format_general); // Email Body Column 9 $message_content = $rs->fields['content']; $worksheet_open_status->write($row, 9, trim($message_content), $format_general_nowrap); // Ticket Mask Column 10 $mask = $rs->fields['mask']; $worksheet_open_status->write($row, 10, $mask, $format_general); $row++; $rs->MoveNext(); } } if ($RunFromCron) { $logger->info("[Answernet.com] " . $translate->_('answernet.er.metlife.metlife.done')); $logger->info("[Answernet.com] " . $translate->_('answernet.er.metlife.generating.dr.transaction.report')); } else { print $translate->_('answernet.er.metlife.metlife.done'); print '<br>'; print $translate->_('answernet.er.metlife.generating.dr.transaction.report'); } //SELECT t.mask, t.created_date ticket_created_date, //m.created_date message_created_date, mc.content, //m.is_outgoing //FROM message m //INNER JOIN ticket t ON m.ticket_id = t.id //INNER JOIN address a ON m.address_id = a.id //INNER JOIN message_content mc on m.id = mc.message_id //WHERE t.team_id = 1721 //ORDER BY m.id; $sql = "SELECT t.id, t.mask, t.created_date ticket_created_date, "; $sql .= "m.created_date message_created_date, mc.content, m.is_outgoing "; $sql .= "FROM message m "; $sql .= "INNER JOIN ticket t ON m.ticket_id = t.id "; $sql .= "INNER JOIN address a ON m.address_id = a.id "; $sql .= "INNER JOIN message_content mc on m.id = mc.message_id "; $sql .= sprintf("WHERE m.created_date > %d AND m.created_date <= %d ", $start_ofday, $end_ofday); $sql .= "and t.team_id = 1721 "; $sql .= "ORDER BY t.id "; $rs = $db->Execute($sql); $row = 1; if (is_a($rs, 'ADORecordSet')) { while (!$rs->EOF) { $worksheet_transaction->setRow($row, 12); $custom_fields = DAO_CustomFieldValue::getValuesBySourceIds(ChCustomFieldSource_Ticket::ID, $rs->fields['id']); // Status, Due Date, SLA, SLA Age, Date Recived, RM Name, RM Employee ID, Topic, Staff, New Hire, Notes/Email Body if (intval($rs->fields['is_outgoing'])) { $worksheet_transaction->write($row, 0, "Recieved", $format_general); } else { $worksheet_transaction->write($row, 0, "Sent", $format_general); } // Due Date Column 1 $due_date_int = intval($custom_fields[$rs->fields['id']][1]); if ($due_date_int) { $ticket_due_date = date("n/j/y", $due_date_int); } else { $ticket_due_date = ""; } $worksheet_transaction->writeString($row, 1, $ticket_due_date, $format_general); // SLA Column 2 $worksheet_transaction->write($row, 2, $custom_fields[$rs->fields['id']][5], $format_general); // Date Recieved Column 3 $ticket_created_date = date("n/j/y g:i:s A", intval($rs->fields['ticket_created_date'])); $worksheet_transaction->writeString($row, 3, $ticket_created_date, $format_general); // RM Name Column 4 $worksheet_transaction->write($row, 4, $custom_fields[$rs->fields['id']][3], $format_general); // RM Employee ID Column 5 $worksheet_transaction->write($row, 5, $custom_fields[$rs->fields['id']][2], $format_general); // Topic / Request Type Column 6 $worksheet_transaction->write($row, 6, $custom_fields[$rs->fields['id']][4], $format_general); // Staff Column 7 $worksheet_transaction->write($row, 7, $custom_fields[$rs->fields['id']][8], $format_general); // New Hire Column 8 $worksheet_transaction->write($row, 8, $custom_fields[$rs->fields['id']][6], $format_general); // Email Body Column 9 $message_content = $rs->fields['content']; $worksheet_transaction->write($row, 9, trim($message_content), $format_general_nowrap); // Ticket Mask Column 10 $mask = $rs->fields['mask']; $worksheet_transaction->write($row, 10, $mask, $format_general); $row++; $rs->MoveNext(); } } if ($RunFromCron) { $logger->info("[Answernet.com] " . $translate->_('answernet.er.metlife.metlife.done')); $logger->info("[Answernet.com] " . $translate->_('answernet.er.metlife.generating.dr.monthly.report')); } else { print $translate->_('answernet.er.metlife.metlife.done'); print '<br>'; print $translate->_('answernet.er.metlife.generating.dr.monthly.report'); } /* print $translate->_('answernet.er.metlife.metlife.done'); print '<br>'; print $translate->_('answernet.er.metlife.generating.email.count'); $worksheet_in_count->setRow(1, 24); $row_count = 2; foreach ($in_count_admin as $record) { $worksheet_in_count->write($row_count, 0, $record['email'], $format_general); $worksheet_in_count->write($row_count, 1, $record['count'], $format_general); $row_count++; } $worksheet_in_count->write(1, 0, 'Total Admin Email', $format_in_count_total); $worksheet_in_count->writeFormula(1, 1, "=SUM(B3:B".$row_count.")", $format_general); $row_count = 2; foreach ($in_count_other as $record) { $worksheet_in_count->write($row_count, 2, $record['email'], $format_general); $worksheet_in_count->write($row_count, 3, '', $format_general); $worksheet_in_count->write($row_count, 4, $record['count'], $format_general); $row_count++; } $worksheet_in_count->write(1, 2, 'Total Field Email', $format_in_count_total); $worksheet_in_count->write(1, 3, '', $format_in_count_total); $worksheet_in_count->writeFormula(1, 4, "=SUM(E3:E".$row_count.")", $format_general); // Grand Total $worksheet_in_count->write(1, 5, 'Grand Total Email', $format_general); $worksheet_in_count->writeFormula(1, 6, "=SUM(B2,E2)", $format_general); $worksheet_out_count->setRow(1, 24); $row_count = 2; foreach ($out_count_admin as $record) { $worksheet_out_count->write($row_count, 0, $record['email'], $format_general); $worksheet_out_count->write($row_count, 1, $record['count'], $format_general); $row_count++; } $worksheet_out_count->write(1, 0, 'Total Admin Email', $format_general); $worksheet_out_count->writeFormula(1, 1, "=SUM(B3:B".$row_count.")", $format_general); $row_count = 2; foreach ($out_count_other as $record) { $worksheet_out_count->write($row_count, 2, $record['email'], $format_general); $worksheet_out_count->write($row_count, 3, '', $format_general); $worksheet_out_count->write($row_count, 4, $record['count'], $format_general); $row_count++; } $worksheet_out_count->write(1, 2, 'Total Field Email', $format_general); $worksheet_out_count->write(1, 3, '', $format_out_count_total); $worksheet_out_count->writeFormula(1, 4, "=SUM(E3:E".$row_count.")", $format_general); // Grand Total $worksheet_out_count->write(1, 5, 'Grand Total Email', $format_general); $worksheet_out_count->writeFormula(1, 6, "=SUM(B2,E2)", $format_general); */ $workbook->close(); return $filename; }
function showTab() { $tpl = DevblocksPlatform::getTemplateService(); $response = DevblocksPlatform::getHttpResponse(); // are we displaying the main home page? $path = $response->path; array_shift($path); // iphone // array_shift($path); // activity array_shift($path); // opportunities $action = array_shift($path); // current action $id = array_shift($path); // opp id $custom_fields = DAO_CustomField::getBySource(CrmCustomFieldSource_Opportunity::ID); $tpl->assign('custom_fields', $custom_fields); $custom_field_values = DAO_CustomFieldValue::getValuesBySourceIds(CrmCustomFieldSource_Opportunity::ID, $id); if (isset($custom_field_values[$id])) { $tpl->assign('custom_field_values', $custom_field_values[$id]); } $tpl->display('file:' . $this->_TPL_PATH . 'display/properties.tpl'); }
/** * @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; }
function showTasksPropertiesTabAction() { @($task_id = DevblocksPlatform::importGPC($_REQUEST['id'], 'integer')); $tpl = DevblocksPlatform::getTemplateService(); $tpl_path = dirname(dirname(dirname(__FILE__))) . '/templates/'; $tpl->assign('path', $tpl_path); $task = DAO_Task::get($task_id); $tpl->assign('task', $task); $active_workers = DAO_Worker::getAllActive(); $tpl->assign('active_workers', $active_workers); $workers = DAO_Worker::getAllWithDisabled(); $tpl->assign('workers', $workers); // Custom fields $custom_fields = DAO_CustomField::getBySource(ChCustomFieldSource_Task::ID); $tpl->assign('custom_fields', $custom_fields); $custom_field_values = DAO_CustomFieldValue::getValuesBySourceIds(ChCustomFieldSource_Task::ID, $task_id); if (isset($custom_field_values[$task_id])) { $tpl->assign('custom_field_values', $custom_field_values[$task_id]); } $tpl->display('file:' . $tpl_path . 'tasks/display/tabs/properties.tpl'); }
function run($message_id, $template) { if (!empty($message_id)) { $message = DAO_Ticket::getMessage($message_id); $fields = DAO_CustomField::getBySource(ChCustomFieldSource_Ticket::ID); $custom_fields = DAO_CustomFieldValue::getValuesBySourceIds(ChCustomFieldSource_Ticket::ID, $message->ticket_id); foreach ($fields as $field_id => $field) { if ($field->group_id == 0) { $template = str_replace(array('#cf_ticket_' . $field->name . '#'), array($custom_fields[$message->ticket_id][$field->id]), $template); } } } return; }
function getTimeSpentPlus1ReportAction() { $db = DevblocksPlatform::getDatabaseService(); DevblocksPlatform::getExtensions('timetracking.source', true); // Security if (null == ($active_worker = CerberusApplication::getActiveWorker())) { die($translate->_('common.access_denied')); } $tpl = DevblocksPlatform::getTemplateService(); $tpl->cache_lifetime = "0"; $tpl->assign('path', $this->tpl_path); // import dates from form @($start = DevblocksPlatform::importGPC($_REQUEST['start'], 'string', '')); @($end = DevblocksPlatform::importGPC($_REQUEST['end'], 'string', '')); $start_time = 0; $end_time = 0; if (empty($start) && empty($end)) { $start = "-30 days"; $end = "now"; $start_time = strtotime($start); $end_time = strtotime($end); } else { $start_time = strtotime($start); $end_time = strtotime($end); } if ($start_time === false || $end_time === false) { $start = "-30 days"; $end = "now"; $start_time = strtotime($start); $end_time = strtotime($end); $tpl->assign('invalidDate', true); } $groups = DAO_Group::getAll(); $buckets = DAO_Bucket::getAll(); // reload variables in template $tpl->assign('start', $start); $tpl->assign('end', $end); $sources = DAO_TimeTrackingEntry::getSources(); $tpl->assign('sources', $sources); $sql = "SELECT t.mask, t.id, sum(tte.time_actual_mins) mins, a.email, "; $sql .= "t.subject, t.created_date, t.updated_date, t.is_closed, "; $sql .= "t.is_waiting, t.team_id, t.category_id "; $sql .= "FROM timetracking_entry tte "; $sql .= "INNER JOIN ticket t ON tte.source_id = t.id "; $sql .= "INNER JOIN address a ON t.first_wrote_address_id = a.id "; $sql .= sprintf("WHERE log_date > %d AND log_date <= %d ", $start_time, $end_time); $sql .= "GROUP BY t.id "; $sql .= "ORDER BY t.id, tte.log_date "; // echo $sql; $rs = $db->Execute($sql); $time_entries = array(); $filename = "report-plus1-" . $active_worker->id . ".csv"; $full_filename = getcwd() . '/storage/answernet/' . $filename; if (file_exists($full_filename)) { if (!is_writable($full_filename)) { die("The file: {$full_filename} is not writable"); } } elseif (!is_writable(getcwd() . '/storage/answernet/')) { die("you cannot create files in this directory. Check the permissions"); } //open the file for Writing $fh = fopen($full_filename, "w"); //Lock the file for the write operation flock($fh, LOCK_EX); $label = array("Ticket Mask", "Ticket Number", "Client Name", "Asset Name", "Site Name", "Requestor", "Subject", "Created Date", "Last Updated", "Group", "Bucket", "Status", "Total Min"); fputcsv($fh, $label, ",", "\""); if (is_a($rs, 'ADORecordSet')) { while (!$rs->EOF) { $csv = array(); $custom_fields = array(); $mask = $rs->fields['mask']; $id = intval($rs->fields['id']); $email = $rs->fields['email']; $subject = $rs->fields['subject']; $team_id = intval($rs->fields['team_id']); $category_id = intval($rs->fields['category_id']); $created_date = intval($rs->fields['created_date']); $updated_date = intval($rs->fields['updated_date']); $status = "Open"; if (intval($rs->fields['is_waiting'])) { $status = "Waiting for Reply"; } if (intval($rs->fields['is_closed'])) { $status = "Completed"; } $mins = intval($rs->fields['mins']); if (!isset($time_entries[$id])) { $time_entries[$id] = array(); } $csv['mask'] = $mask; $csv['id'] = $id; unset($time_entry); $time_entry['mask'] = $mask; $custom_fields = DAO_CustomFieldValue::getValuesBySourceIds(ChCustomFieldSource_Ticket::ID, $id); if (isset($custom_fields[$id][10])) { $csv['client'] = $custom_fields[$id][10]; $time_entry['client'] = $custom_fields[$id][10]; } else { $csv['client'] = ""; $time_entry['client'] = ""; } if (isset($custom_fields[$id][11])) { $csv['asset'] = $custom_fields[$id][11]; $time_entry['asset'] = $custom_fields[$id][11]; } else { $csv['asset'] = ""; $time_entry['asset'] = ""; } if (isset($custom_fields[$id][1])) { $csv['sitename'] = $custom_fields[$id][1]; $time_entry['sitename'] = $custom_fields[$id][1]; } else { $csv['sitename'] = ""; $time_entry['sitename'] = ""; } $csv['email'] = $email; $time_entry['email'] = $email; $csv['subject'] = $subject; $time_entry['subject'] = $subject; $csv['created_date'] = date("Y-m-d h:i A", $created_date); $time_entry['created_date'] = $created_date; $csv['updated_date'] = date("Y-m-d h:i A", $updated_date); $time_entry['updated_date'] = $updated_date; $csv['group'] = $groups[$team_id]->name; $time_entry['group'] = $groups[$team_id]->name; if ($category_id) { $csv['bucket'] = $buckets[$category_id]->name; $time_entry['bucket'] = $buckets[$category_id]->name; } else { $csv['bucket'] = 'Inbox'; $time_entry['bucket'] = 'Inbox'; } $csv['status'] = $status; $time_entry['status'] = $status; $csv['mins'] = $mins; $time_entry['mins'] = $mins; $time_entries[$id] = $time_entry; fputcsv($fh, $csv, ",", "\""); $rs->MoveNext(); } } fclose($fh); $tpl->assign('time_entries', $time_entries); $tpl->display('file:' . $this->tpl_path . '/report_plus1_time_html.tpl'); }
function getTimeSpentWorkerReportAction() { $db = DevblocksPlatform::getDatabaseService(); $subtotal = array(); $total_cm = array(); DevblocksPlatform::getExtensions('timetracking.source', true); @($sel_worker_id = DevblocksPlatform::importGPC($_REQUEST['worker_id'], 'integer', 0)); @($report_type = DevblocksPlatform::importGPC($_REQUEST['report_type'], 'integer', 0)); // Security if (null == ($active_worker = CerberusApplication::getActiveWorker())) { die($translate->_('common.access_denied')); } $tpl = DevblocksPlatform::getTemplateService(); $tpl->cache_lifetime = "0"; $tpl->assign('path', $this->tpl_path); // import dates from form @($start = DevblocksPlatform::importGPC($_REQUEST['start'], 'string', '')); @($end = DevblocksPlatform::importGPC($_REQUEST['end'], 'string', '')); // use date rang@$sel_worker_id = DevblocksPlatform::importGPC($_REQUEST['worker_id'],'integer',0);e if specified, else use duration prior to now $start_time = 0; $end_time = 0; if (empty($start) && empty($end)) { $start = "Last Monday"; $end = "now"; $start_time = strtotime($start); $end_time = strtotime($end); } else { $start_time = strtotime($start); $end_time = strtotime($end); } if ($start_time === false || $end_time === false) { $start = "Last Monday"; $end = "now"; $start_time = strtotime($start); $end_time = strtotime($end); $tpl->assign('invalidDate', true); } // reload variables in template $tpl->assign('start', $start); $tpl->assign('end', $end); $workers = DAO_Worker::getAll(); $tpl->assign('workers', $workers); $sources = DAO_TimeTrackingEntry::getSources(); $tpl->assign('sources', $sources); $sql = "SELECT tte.log_date, tte.time_actual_mins, tte.worker_id, tte.notes, "; $sql .= "tte.source_extension_id, tte.source_id, "; $sql .= "tta.name activity_name "; $sql .= "FROM timetracking_entry tte "; $sql .= "INNER JOIN timetracking_activity tta ON tte.activity_id = tta.id "; $sql .= "INNER JOIN worker w ON tte.worker_id = w.id "; $sql .= sprintf("WHERE log_date > %d AND log_date <= %d ", $start_time, $end_time); if ($sel_worker_id) { $sql .= sprintf("AND tte.worker_id = %d ", $sel_worker_id); } // Do Not use Group By it breaks things. // $sql .= "GROUP BY activity_name "; $sql .= "ORDER BY w.last_name, w.first_name, activity_name, w.id, tte.log_date "; // echo $sql; $rs = $db->Execute($sql); $time_entries = array(); $filename = "worker-" . $active_worker->id . ".csv"; $full_filename = getcwd() . '/storage/answernet/' . $filename; if (file_exists($full_filename)) { if (!is_writable($full_filename)) { die("The file: {$full_filename} is not writable"); } } elseif (!is_writable(getcwd() . '/storage/answernet/')) { die("you cannot create files in this directory. Check the permissions"); } //open the file for Writing $fh = fopen($full_filename, "w"); //Lock the file for the write operation flock($fh, LOCK_EX); $label = array("Worker Name", "Ticket No", "Client", "Asset", "Site Name", "Billing Group", "Billing Min", "Sub-Total", "Total", "Date Recorded", "Notes"); fputcsv($fh, $label, ",", "\""); if (is_a($rs, 'ADORecordSet')) { while (!$rs->EOF) { $csv = array(); $custom_fields = array(); $mins = intval($rs->fields['time_actual_mins']); $worker_id = intval($rs->fields['worker_id']); $org_id = intval($rs->fields['org_id']); $activity = $rs->fields['activity_name']; $log_date = intval($rs->fields['log_date']); $notes = $rs->fields['notes']; if (!isset($time_entries[$worker_id])) { $time_entries[$worker_id] = array(); $time_entries[$worker_id]['mins'] = array(); } if (!isset($subtotal)) { $subtotal = array(); $subtotal_activity = $activity; $subtotal['name'] = $workers[$worker_id]->getName(false); $subtotal['source_id'] = ""; $subtotal['client'] = ""; $subtotal['asset'] = ""; $subtotal['sitename'] = ""; $subtotal['activity_name'] = $activity; $subtotal['mins'] = ""; } else { if ($subtotal_activity != $activity) { //Dump Sub Total fputcsv($fh, $subtotal, ",", "\""); $subtotal = array(); $subtotal_activity = $activity; $subtotal['name'] = $workers[$worker_id]->getName(false); $subtotal['source_id'] = ""; $subtotal['client'] = ""; $subtotal['asset'] = ""; $subtotal['sitename'] = ""; $subtotal['activity_name'] = $activity; $subtotal['mins'] = ""; } } if (!isset($total_cm)) { $total_cm = array(); $total_worker_id = $worker_id; $total_cm['name'] = $workers[$worker_id]->getName(false); $total_cm['source_id'] = ""; $total_cm['client'] = ""; $total_cm['asset'] = ""; $total_cm['sitename'] = ""; $total_cm['activity_name'] = ""; $total_cm['mins'] = ""; } else { if ($total_worker_id != $worker_id) { //Dump Total fputcsv($fh, $total_cm, ",", "\""); $total_cm = array(); $total_worker_id = $worker_id; $total_cm['name'] = $workers[$worker_id]->getName(false); $total_cm['source_id'] = ""; $total_cm['client'] = ""; $total_cm['asset'] = ""; $total_cm['sitename'] = ""; $total_cm['activity_name'] = ""; $total_cm['mins'] = ""; } } $csv['name'] = $workers[$worker_id]->getName(false); unset($time_entry); $time_entry['activity_name'] = $activity; $time_entry['mins'] = $mins; $time_entry['log_date'] = $log_date; $time_entry['notes'] = $notes; $time_entry['source_extension_id'] = $rs->fields['source_extension_id']; $time_entry['source_id'] = intval($rs->fields['source_id']); $csv['source_id'] = intval($rs->fields['source_id']); $custom_fields = DAO_CustomFieldValue::getValuesBySourceIds(ChCustomFieldSource_Ticket::ID, $csv['source_id']); if (isset($custom_fields[$csv['source_id']][10])) { $csv['client'] = $custom_fields[$csv['source_id']][10]; } else { $csv['client'] = ""; } if (isset($custom_fields[$csv['source_id']][11])) { $csv['asset'] = $custom_fields[$csv['source_id']][11]; } else { $csv['asset'] = ""; } if (isset($custom_fields[$csv['source_id']][1])) { $csv['sitename'] = $custom_fields[$csv['source_id']][1]; } else { $csv['sitename'] = ""; } $csv['activity_name'] = $activity; $csv['mins'] = $mins; $csv['subtotal'] = ""; $csv['total'] = ""; $csv['log_date'] = date("Y-m-d h:i A", $log_date); $csv['notes'] = $notes; $time_entries[$worker_id]['entries'][] = $time_entry; @($time_entries[$worker_id]['mins'][$activity] = intval($time_entries[$worker_id]['mins'][$activity]) + $mins); @($time_entries[$worker_id]['mins']['total'] = intval($time_entries[$worker_id]['mins']['total']) + $mins); $subtotal['subtotal'] = $time_entries[$worker_id]['mins'][$activity]; $total_cm['subtotal'] = ""; $subtotal['total'] = ""; $total_cm['total'] = $time_entries[$worker_id]['mins']['total']; fputcsv($fh, $csv, ",", "\""); $rs->MoveNext(); } } // print_r($time_entries); $tpl->assign('time_entries', $time_entries); $tpl->assign('report_type', $report_type); $tpl->assign('href_filename', $href_filename); fputcsv($fh, $subtotal, ",", "\""); fputcsv($fh, $total_cm, ",", "\""); fclose($fh); $tpl->display('file:' . $this->tpl_path . '/report_worker_time_html.tpl'); }
/** * @return Model_Sensor[]|false */ public function getMatches($sensors) { $matches = array(); // Check the sensor if (empty($sensors)) { return false; } $custom_fields = DAO_CustomField::getAll(); // Lazy load when needed on criteria basis $sensor_field_values = null; // Criteria extensions $alert_criteria_exts = DevblocksPlatform::getExtensions('portsensor.alert.criteria', false); if (is_array($sensors)) { foreach ($sensors as $sensor) { // Check filters $passed = 0; // Skip alerts with no criteria if (!is_array($this->criteria) || empty($this->criteria)) { continue; } // check criteria if (is_array($this->criteria)) { foreach ($this->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': switch ($sensor->status) { case 0: // OK if (isset($rule['ok'])) { $passed++; } break; case 1: // WARNING if (isset($rule['warning'])) { $passed++; } break; case 2: // CRITICAL if (isset($rule['critical'])) { $passed++; } break; } break; case 'alert_last_ran': @($from = DevblocksPlatform::importGPC($rule['from'], 'string', '')); @($to = DevblocksPlatform::importGPC($rule['to'], 'string', '')); if (intval(@strtotime($from)) <= $this->last_alert_date && intval(@strtotime($to)) >= $this->last_alert_date) { $passed++; } break; case 'sensor_name': $regexp_sensor_name = DevblocksPlatform::strToRegExp($value); if (@preg_match($regexp_sensor_name, $sensor->name)) { $passed++; } break; case 'sensor_type': if (isset($rule[$sensor->extension_id])) { $passed++; } break; case 'sensor_fail_count': $oper = $rule['oper']; switch ($oper) { default: if ($sensor->fail_count == $value) { $passed++; } break; case '!=': if ($sensor->fail_count != $value) { $passed++; } break; case '>': if ($sensor->fail_count > $value) { $passed++; } break; case '<': if ($sensor->fail_count < $value) { $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 PsCustomFieldSource_Sensor::ID: if (null == $sensor_field_values) { $sensor_field_values = array_shift(DAO_CustomFieldValue::getValuesBySourceIds(PsCustomFieldSource_Sensor::ID, $sensor->id)); } $field_values =& $sensor_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 // 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 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 // 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; } } elseif (isset($alert_criteria_exts[$rule_key])) { // criteria extensions try { $crit_ext = $alert_criteria_exts[$rule_key]->createInstance(); if ($crit_ext->matches($this, $sensor)) { $passed++; break; } } catch (Exception $e) { // Oops! //print_r($e); } } break; } } } // If our alert matched every criteria, stop and return the alert if ($passed == count($this->criteria)) { DAO_Alert::update($this->id, array(DAO_Alert::LAST_ALERT_DATE => time())); DAO_Alert::increment($this->id); // ++ the times we've matched $matches[$sensor->id] = $sensor; } } } // If last alert was still stackable... if (!empty($matches)) { return $matches; } // No matches return false; }
function showEntryAction($model = null) { $tpl = DevblocksPlatform::getTemplateService(); $tpl_path = dirname(dirname(__FILE__)) . '/templates/'; $tpl->assign('path', $tpl_path); $tpl->cache_lifetime = "0"; @($id = DevblocksPlatform::importGPC($_REQUEST['id'], 'integer', 0)); /* * [IMPORTANT -- Yes, this is simply a line in the sand.] * You're welcome to modify the code to meet your needs, but please respect * our licensing. Buy a legitimate copy to help support the project! * http://www.cerberusweb.com/ */ $license = CerberusLicense::getInstance(); if (empty($id) && (empty($license['serial']) || !empty($license['serial']) && isset($license['a'])) && 10 <= DAO_TimeTrackingEntry::getItemCount()) { $tpl->display('file:' . $tpl_path . 'timetracking/rpc/trial.tpl'); return; } /* * This treats procedurally created model objects * the same as existing objects */ if (!empty($id)) { // Were we given a model ID to load? if (null != ($model = DAO_TimeTrackingEntry::get($id))) { $tpl->assign('model', $model); } } elseif (!empty($model)) { // Were we passed a model object without an ID? $tpl->assign('model', $model); } /* @var $model Model_TimeTrackingEntry */ // Source extension if (!empty($model->source_extension_id)) { if (null != ($source = DevblocksPlatform::getExtension($model->source_extension_id, true))) { $tpl->assign('source', $source); } } // Org Name if (!empty($model->debit_org_id)) { if (null != ($org = DAO_ContactOrg::get($model->debit_org_id))) { $tpl->assign('org', $org); } } // Activities // [TODO] Cache $billable_activities = DAO_TimeTrackingActivity::getWhere(sprintf("%s!=0", DAO_TimeTrackingActivity::RATE)); $tpl->assign('billable_activities', $billable_activities); $nonbillable_activities = DAO_TimeTrackingActivity::getWhere(sprintf("%s=0", DAO_TimeTrackingActivity::RATE)); $tpl->assign('nonbillable_activities', $nonbillable_activities); // Custom fields $custom_fields = DAO_CustomField::getBySource(ChCustomFieldSource_TimeEntry::ID); $tpl->assign('custom_fields', $custom_fields); $custom_field_values = DAO_CustomFieldValue::getValuesBySourceIds(ChCustomFieldSource_TimeEntry::ID, $id); if (isset($custom_field_values[$id])) { $tpl->assign('custom_field_values', $custom_field_values[$id]); } $types = Model_CustomField::getTypes(); $tpl->assign('types', $types); $tpl->display('file:' . $tpl_path . 'timetracking/rpc/time_entry_panel.tpl'); }
function showRecipientPeekAction() { @($id = DevblocksPlatform::importGPC($_REQUEST['id'], 'integer', 0)); @($customer_id = DevblocksPlatform::importGPC($_REQUEST['customer_id'], 'integer', 0)); @($view_id = DevblocksPlatform::importGPC($_REQUEST['view_id'], 'string', '')); $display_view = 0; $tpl = DevblocksPlatform::getTemplateService(); $tpl->assign('path', $this->_TPL_PATH); $tpl->assign('id', $id); $tpl->assign('customer_id', $customer_id); $tpl->assign('view_id', $view_id); $customer_recipient = DAO_CustomerRecipient::get($id); $tpl->assign('customer_recipient', $customer_recipient); // Custom Fields $custom_fields = DAO_CustomField::getBySource(FegCustomFieldSource_CustomerRecipient::ID); $tpl->assign('custom_fields', $custom_fields); $custom_field_values = DAO_CustomFieldValue::getValuesBySourceIds(FegCustomFieldSource_CustomerRecipient::ID, $id); if (isset($custom_field_values[$id])) { $tpl->assign('custom_field_values', $custom_field_values[$id]); } // Below is the Audit log view only avaible is the audit log plugin is enabled. if (class_exists('View_MessageAuditLog', true)) { $display_view = 1; $defaults = new Feg_AbstractViewModel(); $defaults->class_name = 'View_MessageAuditLog'; $defaults->id = '_recipient_audit_log'; $defaults->renderLimit = 10; $defaults->renderSortBy = SearchFields_MessageAuditLog::CHANGE_DATE; $defaults->renderSortAsc = false; $defaults->params = array(); $view = Feg_AbstractViewLoader::getView($defaults->id, $defaults); $view->name = 'Recipient Audit Log'; $view->renderTemplate = 'peek_tab'; $view->params = array(SearchFields_MessageAuditLog::RECIPIENT_ID => new DevblocksSearchCriteria(SearchFields_MessageAuditLog::RECIPIENT_ID, DevblocksSearchCriteria::OPER_EQ, $id)); $view->renderPage = 0; $view->renderLimit = 10; $view->renderSortBy = SearchFields_MessageAuditLog::CHANGE_DATE; $view->renderSortAsc = false; $view->view_columns = array(SearchFields_MessageAuditLog::CHANGE_DATE, SearchFields_MessageAuditLog::MESSAGE_ID, SearchFields_MessageAuditLog::WORKER_ID, SearchFields_MessageAuditLog::CHANGE_FIELD, SearchFields_MessageAuditLog::CHANGE_VALUE); Feg_AbstractViewLoader::setView($view->id, $view); $tpl->assign('view', $view); } $tpl->assign('display_view', $display_view); $tpl->display('file:' . $this->_TPL_PATH . 'customer/tabs/recipient/peek.tpl'); }
function showOppPropertiesTabAction() { @($opp_id = DevblocksPlatform::importGPC($_REQUEST['id'], 'integer')); $tpl = DevblocksPlatform::getTemplateService(); $tpl_path = dirname(dirname(__FILE__)) . '/templates/'; $tpl->assign('path', $tpl_path); $opp = DAO_CrmOpportunity::get($opp_id); $tpl->assign('opp', $opp); $workers = DAO_Worker::getAllActive(); $tpl->assign('workers', $workers); $custom_fields = DAO_CustomField::getBySource(CrmCustomFieldSource_Opportunity::ID); $tpl->assign('custom_fields', $custom_fields); $custom_field_values = DAO_CustomFieldValue::getValuesBySourceIds(CrmCustomFieldSource_Opportunity::ID, $opp->id); if (isset($custom_field_values[$opp->id])) { $tpl->assign('custom_field_values', $custom_field_values[$opp->id]); } $tpl->display('file:' . $tpl_path . 'crm/opps/display/tabs/properties.tpl'); }
function showPropertiesAction() { @($ticket_id = DevblocksPlatform::importGPC($_REQUEST['ticket_id'], 'integer')); $tpl = DevblocksPlatform::getTemplateService(); $tpl->assign('path', $this->_TPL_PATH); $tpl->assign('ticket_id', $ticket_id); $ticket = DAO_Ticket::getTicket($ticket_id); $tpl->assign('ticket', $ticket); $requesters = DAO_Ticket::getRequestersByTicket($ticket_id); $tpl->assign('requesters', $requesters); $workers = DAO_Worker::getAllActive(); $tpl->assign('workers', $workers); // Groups (for custom fields) $groups = DAO_Group::getAll(); $tpl->assign('groups', $groups); // Custom fields $fields = DAO_CustomField::getBySource(ChCustomFieldSource_Ticket::ID); $tpl->assign('ticket_fields', $fields); $field_values = DAO_CustomFieldValue::getValuesBySourceIds(ChCustomFieldSource_Ticket::ID, $ticket_id); if (isset($field_values[$ticket->id])) { $tpl->assign('ticket_field_values', $field_values[$ticket->id]); } $tpl->display('file:' . $this->_TPL_PATH . 'display/modules/properties/index.tpl'); }
function showPreviewAction() { @($tid = DevblocksPlatform::importGPC($_REQUEST['tid'], 'integer', 0)); @($view_id = DevblocksPlatform::importGPC($_REQUEST['view_id'], 'string', '')); $tpl = DevblocksPlatform::getTemplateService(); $tpl_path = $this->_TPL_PATH; $tpl->assign('path', $tpl_path); $tpl->assign('view_id', $view_id); if (null != ($ticket = DAO_Ticket::getTicket($tid))) { /* @var $ticket CerberusTicket */ $tpl->assign('ticket', $ticket); } if (null != ($messages = DAO_Ticket::getMessagesByTicket($tid))) { if (!empty($messages)) { @($last = array_pop($messages)); @($content = DAO_MessageContent::get($last->id)); $tpl->assign('message', $last); $tpl->assign('content', $content); } } $teams = DAO_Group::getAll(); $tpl->assign('teams', $teams); $team_categories = DAO_Bucket::getTeams(); $tpl->assign('team_categories', $team_categories); $workers = DAO_Worker::getAllActive(); $tpl->assign('workers', $workers); // Custom fields $custom_fields = DAO_CustomField::getBySource(ChCustomFieldSource_Ticket::ID); $tpl->assign('custom_fields', $custom_fields); $custom_field_values = DAO_CustomFieldValue::getValuesBySourceIds(ChCustomFieldSource_Ticket::ID, $ticket->id); if (isset($custom_field_values[$ticket->id])) { $tpl->assign('custom_field_values', $custom_field_values[$ticket->id]); } // Display $tpl->display('file:' . $this->_TPL_PATH . 'tickets/rpc/preview_panel.tpl'); }
function showWorkerPeekAction() { @($id = DevblocksPlatform::importGPC($_REQUEST['id'], 'integer', 0)); @($view_id = DevblocksPlatform::importGPC($_REQUEST['view_id'], 'string', '')); $tpl = DevblocksPlatform::getTemplateService(); $tpl->assign('path', $this->_TPL_PATH); $tpl->assign('view_id', $view_id); $worker = DAO_Worker::getAgent($id); $tpl->assign('worker', $worker); $teams = DAO_Group::getAll(); $tpl->assign('teams', $teams); // Custom Fields $custom_fields = DAO_CustomField::getBySource(ChCustomFieldSource_Worker::ID); $tpl->assign('custom_fields', $custom_fields); $custom_field_values = DAO_CustomFieldValue::getValuesBySourceIds(ChCustomFieldSource_Worker::ID, $id); if (isset($custom_field_values[$id])) { $tpl->assign('custom_field_values', $custom_field_values[$id]); } $tpl->display('file:' . $this->_TPL_PATH . 'configuration/tabs/workers/peek.tpl'); }
/** * @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); if (empty($messages)) { return false; } if (null == @($message = array_pop($messages))) { /* @var $message CerberusMessage */ return false; } $message_headers = $message->getHeaders(); $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; // check criteria foreach ($filter->criteria as $rule_key => $rule) { @($value = $rule['value']); switch ($rule_key) { case 'tocc': $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 '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 // string case 'T': // clob $field_val = isset($field_values[$field_id]) ? $field_values[$field_id] : ''; $oper = isset($rule['oper']) ? $rule['oper'] : "="; if ($oper == "=" && @preg_match(DevblocksPlatform::strToRegExp($value), $field_val)) { $passed++; } elseif ($oper == "!=" && @(!preg_match(DevblocksPlatform::strToRegExp($value), $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 $field_val = isset($field_values[$field_id]) ? $field_values[$field_id] : array(); if (!is_array($value)) { $value = array($value); } foreach ($value as $v) { if (isset($field_val[$v])) { $passed++; } } 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; }