public static function getTemplateHandler() { $tpl = DevblocksPlatform::getTemplateService(); $tpl_path = dirname(__FILE__) . '/templates/'; $tpl->assign('path', $tpl_path); $tpl->cache_lifetime = "0"; $total_new_count = 0; foreach (DAO_WorkflowView::getGroupTotals() as $data) { $total_new_count += $data["total"]; } $tpl->assign('total_new_count', $total_new_count); $newest = isset($_SESSION["fluid_latest_seen"]) ? $_SESSION["fluid_latest_seen"] : time() - 3600; $worker = CerberusApplication::getActiveWorker(); $memberships = $worker->getMemberships(); $params = array(SearchFields_Ticket::TICKET_TEAM_ID => new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_TEAM_ID, 'in', array_keys($memberships)), SearchFields_Ticket::TICKET_DELETED => new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_DELETED, 'eq', 0), SearchFields_Ticket::TICKET_WAITING => new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_WAITING, 'eq', 0), SearchFields_Ticket::TICKET_CLOSED => new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_CLOSED, 'eq', 0), SearchFields_Ticket::TICKET_UPDATED_DATE => new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_UPDATED_DATE, '>', $newest)); list($results, $total) = DAO_Ticket::search(array(SearchFields_Ticket::TICKET_ID, SearchFields_Ticket::TICKET_MASK, SearchFields_Ticket::TICKET_SUBJECT, SearchFields_Ticket::TICKET_LAST_WROTE), $params, 5, 0, SearchFields_Ticket::TICKET_UPDATED_DATE, false, true); $tickets = array(); foreach ($results as $ticket) { if ($ticket[SearchFields_Ticket::TICKET_UPDATED_DATE] > $newest) { $newest = $ticket[SearchFields_Ticket::TICKET_UPDATED_DATE]; } $tickets[] = $ticket; } $_SESSION["fluid_latest_seen"] = $newest; $tpl->assign("recent_tickets_json", json_encode($tickets)); $tpl->assign("recent_ticket_count", json_encode($total)); return $tpl; }
function browseAction() { $translate = DevblocksPlatform::getTranslationService(); $visit = CerberusApplication::getVisit(); /* @var $visit CerberusVisit */ $request = DevblocksPlatform::getHttpRequest(); $stack = $request->path; array_shift($stack); // display array_shift($stack); // browse @($id = array_shift($stack)); // [JAS]: Mask if (!is_numeric($id)) { $id = DAO_Ticket::getTicketIdByMask($id); } $ticket = DAO_Ticket::getTicket($id); if (empty($ticket)) { echo "<H1>" . $translate->_('display.invalid_ticket') . "</H1>"; return; } // Display series support (inherited paging from Display) @($view_id = array_shift($stack)); if (!empty($view_id)) { $view = C4_AbstractViewLoader::getView('', $view_id); // Restrict to the active worker's groups $active_worker = CerberusApplication::getActiveWorker(); $memberships = $active_worker->getMemberships(); $view->params['tmp'] = new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_TEAM_ID, 'in', array_keys($memberships)); $range = 250; // how far to jump ahead of the current page $block_size = 250; $page = floor($view->renderPage * $view->renderLimit / $block_size); $index = array(); $found = false; $full = false; do { list($series, $null) = DAO_Ticket::search(array(SearchFields_Ticket::TICKET_MASK), $view->params, $block_size, $page, $view->renderSortBy, $view->renderSortAsc, false); // Index by mask foreach ($series as $idx => $val) { // Find our match before we index anything if (!$found && $idx == $id) { $found = true; } elseif (!$found) { // Only keep a max of X things behind our match, reserve the most room ahead if (count($index) == 20) { array_shift($index); } } $index[] = $val[SearchFields_Ticket::TICKET_MASK]; // Stop if we fill up our desired rows if (count($index) == $range) { $full = true; break; } } $page++; } while (!empty($series) && !$full); $series_info = array('title' => $view->name, 'total' => count($index), 'series' => $index); $visit->set('ch_display_series', $series_info); } DevblocksPlatform::redirect(new DevblocksHttpResponse(array('display', $ticket->mask))); }
function writeResponse(DevblocksHttpResponse $response) { $tpl = DevblocksPlatform::getTemplateService(); $tpl_path = dirname(dirname(__FILE__)) . '/templates/'; $theme = DAO_CommunityToolProperty::get($this->getPortal(), UmScApp::PARAM_THEME, UmScApp::DEFAULT_THEME); if (!is_dir($tpl_path . 'portal/sc/themes/' . $theme)) { $theme = UmScApp::DEFAULT_THEME; } $umsession = $this->getSession(); $active_user = $umsession->getProperty('sc_login', null); $stack = $response->path; @($module = array_shift($stack)); switch ($module) { default: case 'home': $sHomeRss = DAO_CommunityToolProperty::get($this->getPortal(), UmScApp::PARAM_HOME_RSS, ''); $aHomeRss = !empty($sHomeRss) ? unserialize($sHomeRss) : array(); $feeds = array(); // [TODO] Implement a feed cache so we aren't bombing out foreach ($aHomeRss as $title => $url) { $feed = null; try { $feed = Zend_Feed::import($url); } catch (Exception $e) { } if (!empty($feed) && $feed->count()) { $feeds[] = array('name' => $title, 'feed' => $feed); } } $tpl->assign('feeds', $feeds); $tpl->display("file:{$tpl_path}portal/sc/internal/home/index.tpl"); break; case 'account': if (!$this->allow_logins || empty($active_user)) { break; } $address = DAO_Address::get($active_user->id); $tpl->assign('address', $address); $tpl->display("file:{$tpl_path}portal/sc/internal/account/index.tpl"); break; case 'kb': // KB Roots $sKbRoots = DAO_CommunityToolProperty::get($this->getPortal(), UmScApp::PARAM_KB_ROOTS, ''); $kb_roots = !empty($sKbRoots) ? unserialize($sKbRoots) : array(); $kb_roots_str = '0'; if (!empty($kb_roots)) { $kb_roots_str = implode(',', array_keys($kb_roots)); } switch (array_shift($stack)) { case 'article': if (empty($kb_roots)) { return; } $id = intval(array_shift($stack)); list($articles, $count) = DAO_KbArticle::search(array(new DevblocksSearchCriteria(SearchFields_KbArticle::ID, '=', $id), new DevblocksSearchCriteria(SearchFields_KbArticle::TOP_CATEGORY_ID, 'in', array_keys($kb_roots))), -1, 0, null, null, false); if (!isset($articles[$id])) { break; } $article = DAO_KbArticle::get($id); $tpl->assign('article', $article); @($article_list = $umsession->getProperty(UmScApp::SESSION_ARTICLE_LIST, array())); if (!empty($article) && !isset($article_list[$id])) { DAO_KbArticle::update($article->id, array(DAO_KbArticle::VIEWS => ++$article->views)); $article_list[$id] = $id; $umsession->setProperty(UmScApp::SESSION_ARTICLE_LIST, $article_list); } $categories = DAO_KbCategory::getWhere(); $tpl->assign('categories', $categories); $cats = DAO_KbArticle::getCategoriesByArticleId($id); $breadcrumbs = array(); foreach ($cats as $cat_id) { if (!isset($breadcrumbs[$cat_id])) { $breadcrumbs[$cat_id] = array(); } $pid = $cat_id; while ($pid) { $breadcrumbs[$cat_id][] = $pid; $pid = $categories[$pid]->parent_id; } $breadcrumbs[$cat_id] = array_reverse($breadcrumbs[$cat_id]); // Remove any breadcrumbs not in this SC profile $pid = reset($breadcrumbs[$cat_id]); if (!isset($kb_roots[$pid])) { unset($breadcrumbs[$cat_id]); } } $tpl->assign('breadcrumbs', $breadcrumbs); $tpl->display("file:{$tpl_path}portal/sc/internal/kb/article.tpl"); break; default: case 'browse': @($root = intval(array_shift($stack))); $tpl->assign('root_id', $root); $categories = DAO_KbCategory::getWhere(); $tpl->assign('categories', $categories); $tree_map = DAO_KbCategory::getTreeMap(0); // Remove other top-level categories if (is_array($tree_map[0])) { foreach ($tree_map[0] as $child_id => $count) { if (!isset($kb_roots[$child_id])) { unset($tree_map[0][$child_id]); } } } // Remove empty categories if (is_array($tree_map[0])) { foreach ($tree_map as $node_id => $children) { foreach ($children as $child_id => $count) { if (empty($count)) { @($pid = $categories[$child_id]->parent_id); unset($tree_map[$pid][$child_id]); unset($tree_map[$child_id]); } } } } $tpl->assign('tree', $tree_map); // Breadcrumb // [TODO] API-ize inside Model_KbTree ? $breadcrumb = array(); $pid = $root; while (0 != $pid) { $breadcrumb[] = $pid; $pid = $categories[$pid]->parent_id; } $tpl->assign('breadcrumb', array_reverse($breadcrumb)); $tpl->assign('mid', @intval(ceil(count($tree_map[$root]) / 2))); // Articles if (!empty($root)) { list($articles, $count) = DAO_KbArticle::search(array(new DevblocksSearchCriteria(SearchFields_KbArticle::CATEGORY_ID, '=', $root), new DevblocksSearchCriteria(SearchFields_KbArticle::TOP_CATEGORY_ID, 'in', array_keys($kb_roots))), -1, 0, null, null, false); } $tpl->assign('articles', $articles); $tpl->display("file:{$tpl_path}portal/sc/internal/kb/index.tpl"); break; } break; case 'answers': $query = rawurldecode(array_shift($stack)); $tpl->assign('query', $query); $sFnrSources = DAO_CommunityToolProperty::get($this->getPortal(), UmScApp::PARAM_FNR_SOURCES, ''); $aFnrSources = !empty($sFnrSources) ? unserialize($sFnrSources) : array(); if (!empty($query)) { // [JAS]: If we've been customized with specific sources, use them $where = !empty($aFnrSources) ? sprintf("%s IN (%s)", DAO_FnrExternalResource::ID, implode(',', array_keys($aFnrSources))) : sprintf("%s IN (-1)", DAO_FnrExternalResource::ID); $resources = DAO_FnrExternalResource::getWhere($where); $feeds = Model_FnrExternalResource::searchResources($resources, $query); $tpl->assign('feeds', $feeds); $fields = array(DAO_FnrQuery::QUERY => $query, DAO_FnrQuery::CREATED => time(), DAO_FnrQuery::SOURCE => $this->getPortal(), DAO_FnrQuery::NO_MATCH => empty($feeds) ? 1 : 0); DAO_FnrQuery::create($fields); } // KB $sKbRoots = DAO_CommunityToolProperty::get($this->getPortal(), UmScApp::PARAM_KB_ROOTS, ''); $kb_roots = !empty($sKbRoots) ? unserialize($sKbRoots) : array(); list($articles, $count) = DAO_KbArticle::search(array(array(DevblocksSearchCriteria::GROUP_OR, new DevblocksSearchCriteria(SearchFields_KbArticle::TITLE, 'fulltext', $query), new DevblocksSearchCriteria(SearchFields_KbArticle::CONTENT, 'fulltext', $query)), new DevblocksSearchCriteria(SearchFields_KbArticle::TOP_CATEGORY_ID, 'in', array_keys($kb_roots))), 100, 0, null, null, true); $tpl->assign('articles', $articles); $tpl->display("file:{$tpl_path}portal/sc/internal/answers/index.tpl"); break; case 'contact': $response = array_shift($stack); $settings = CerberusSettings::getInstance(); $default_from = $settings->get(CerberusSettings::DEFAULT_REPLY_FROM); $tpl->assign('default_from', $default_from); switch ($response) { case 'confirm': $tpl->assign('last_opened', $umsession->getProperty('support.write.last_opened', '')); $tpl->display("file:{$tpl_path}portal/sc/internal/contact/confirm.tpl"); break; default: case 'step1': $umsession->setProperty('support.write.last_error', null); case 'step2': $sFrom = $umsession->getProperty('support.write.last_from', ''); $sSubject = $umsession->getProperty('support.write.last_subject', ''); $sNature = $umsession->getProperty('support.write.last_nature', ''); $sContent = $umsession->getProperty('support.write.last_content', ''); // $aLastFollowupQ = $umsession->getProperty('support.write.last_followup_q',''); $aLastFollowupA = $umsession->getProperty('support.write.last_followup_a', ''); $sError = $umsession->getProperty('support.write.last_error', ''); $tpl->assign('last_from', $sFrom); $tpl->assign('last_subject', $sSubject); $tpl->assign('last_nature', $sNature); $tpl->assign('last_content', $sContent); // $tpl->assign('last_followup_q', $aLastFollowupQ); $tpl->assign('last_followup_a', $aLastFollowupA); $tpl->assign('last_error', $sError); $sDispatch = DAO_CommunityToolProperty::get($this->getPortal(), UmScApp::PARAM_DISPATCH, ''); // $dispatch = !empty($sDispatch) ? (is_array($sDispatch) ? unserialize($sDispatch): array($sDispatch)) : array(); $dispatch = !empty($sDispatch) ? unserialize($sDispatch) : array(); $tpl->assign('dispatch', $dispatch); switch ($response) { default: // If there's only one situation, skip to step2 if (1 == count($dispatch)) { @($sNature = md5(key($dispatch))); $umsession->setProperty('support.write.last_nature', $sNature); reset($dispatch); } else { $tpl->display("file:{$tpl_path}portal/sc/internal/contact/step1.tpl"); break; } case 'step2': // Cache along with answers? if (is_array($dispatch)) { foreach ($dispatch as $k => $v) { if (md5($k) == $sNature) { $umsession->setProperty('support.write.last_nature_string', $k); $tpl->assign('situation', $k); $tpl->assign('situation_params', $v); break; } } } $ticket_fields = DAO_CustomField::getBySource('cerberusweb.fields.source.ticket'); $tpl->assign('ticket_fields', $ticket_fields); $tpl->display("file:{$tpl_path}portal/sc/internal/contact/step2.tpl"); break; } break; } break; // $tpl->display("file:${tpl_path}portal/sc/internal/contact/index.tpl"); // break; // $tpl->display("file:${tpl_path}portal/sc/internal/contact/index.tpl"); // break; case 'history': if (!$this->allow_logins || empty($active_user)) { break; } $mask = array_shift($stack); if (empty($mask)) { list($open_tickets) = DAO_Ticket::search(array(), array(new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_FIRST_WROTE_ID, '=', $active_user->id), new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_CLOSED, '=', 0)), -1, 0, SearchFields_Ticket::TICKET_UPDATED_DATE, false, false); $tpl->assign('open_tickets', $open_tickets); list($closed_tickets) = DAO_Ticket::search(array(), array(new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_FIRST_WROTE_ID, '=', $active_user->id), new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_CLOSED, '=', 1)), -1, 0, SearchFields_Ticket::TICKET_UPDATED_DATE, false, false); $tpl->assign('closed_tickets', $closed_tickets); $tpl->display("file:{$tpl_path}portal/sc/internal/history/index.tpl"); } else { // Secure retrieval (address + mask) list($tickets) = DAO_Ticket::search(array(), array(new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_MASK, '=', $mask), new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_FIRST_WROTE_ID, '=', $active_user->id)), 1, 0, null, null, false); $ticket = array_shift($tickets); // Security check (mask compare) if (0 == strcasecmp($ticket[SearchFields_Ticket::TICKET_MASK], $mask)) { $messages = DAO_Ticket::getMessagesByTicket($ticket[SearchFields_Ticket::TICKET_ID]); $messages = array_reverse($messages, true); $tpl->assign('ticket', $ticket); $tpl->assign('messages', $messages); $tpl->display("file:{$tpl_path}portal/sc/internal/history/display.tpl"); } } break; case 'register': if (!$this->allow_logins) { break; } @($step = array_shift($stack)); switch ($step) { case 'forgot': $tpl->display("file:{$tpl_path}portal/sc/internal/register/forgot.tpl"); break; case 'forgot2': $tpl->display("file:{$tpl_path}portal/sc/internal/register/forgot_confirm.tpl"); break; case 'confirm': $tpl->display("file:{$tpl_path}portal/sc/internal/register/confirm.tpl"); break; default: $tpl->display("file:{$tpl_path}portal/sc/internal/register/index.tpl"); break; } break; } // print_r($response); }
function saveTabInboxAddAction() { $translate = DevblocksPlatform::getTranslationService(); @($id = DevblocksPlatform::importGPC($_REQUEST['id'], 'integer', 0)); @($group_id = DevblocksPlatform::importGPC($_REQUEST['group_id'], 'integer')); @($view_id = DevblocksPlatform::importGPC($_REQUEST['view_id'], 'string', '')); @($active_worker = CerberusApplication::getActiveWorker()); if (!$active_worker->isTeamManager($group_id) && !$active_worker->is_superuser) { return; } /*****************************/ @($name = DevblocksPlatform::importGPC($_POST['name'], 'string', '')); @($is_sticky = DevblocksPlatform::importGPC($_POST['is_sticky'], 'integer', 0)); @($is_stackable = DevblocksPlatform::importGPC($_POST['is_stackable'], 'integer', 0)); @($rules = DevblocksPlatform::importGPC($_POST['rules'], 'array', array())); @($do = DevblocksPlatform::importGPC($_POST['do'], 'array', array())); if (empty($name)) { $name = $translate->_('mail.inbox_filter'); } $criterion = array(); $actions = array(); // Custom fields $custom_fields = DAO_CustomField::getAll(); // Criteria if (is_array($rules)) { foreach ($rules as $rule) { $rule = DevblocksPlatform::strAlphaNumDash($rule); @($value = DevblocksPlatform::importGPC($_POST['value_' . $rule], 'string', '')); // [JAS]: Allow empty $value (null/blank checking) $criteria = array('value' => $value); // Any special rule handling switch ($rule) { case 'dayofweek': // days $days = DevblocksPlatform::importGPC($_REQUEST['value_dayofweek'], 'array', array()); if (in_array(0, $days)) { $criteria['sun'] = 'Sunday'; } if (in_array(1, $days)) { $criteria['mon'] = 'Monday'; } if (in_array(2, $days)) { $criteria['tue'] = 'Tuesday'; } if (in_array(3, $days)) { $criteria['wed'] = 'Wednesday'; } if (in_array(4, $days)) { $criteria['thu'] = 'Thursday'; } if (in_array(5, $days)) { $criteria['fri'] = 'Friday'; } if (in_array(6, $days)) { $criteria['sat'] = 'Saturday'; } unset($criteria['value']); break; case 'timeofday': $from = DevblocksPlatform::importGPC($_REQUEST['timeofday_from'], 'string', ''); $to = DevblocksPlatform::importGPC($_REQUEST['timeofday_to'], 'string', ''); $criteria['from'] = $from; $criteria['to'] = $to; unset($criteria['value']); break; case 'subject': break; case 'from': break; case 'tocc': break; case 'header1': case 'header2': case 'header3': case 'header4': case 'header5': if (null != @($header = DevblocksPlatform::importGPC($_POST[$rule], 'string', null))) { $criteria['header'] = strtolower($header); } break; case 'body': break; case 'attachment': break; default: // ignore invalids // Custom fields if ("cf_" == substr($rule, 0, 3)) { $field_id = intval(substr($rule, 3)); if (!isset($custom_fields[$field_id])) { continue; } // [TODO] Operators switch ($custom_fields[$field_id]->type) { case 'S': // string // string case 'T': // clob // clob case 'U': // URL $oper = DevblocksPlatform::importGPC($_REQUEST['value_cf_' . $field_id . '_oper'], 'string', 'regexp'); $criteria['oper'] = $oper; break; case 'D': // dropdown // dropdown case 'M': // multi-dropdown // multi-dropdown case 'X': // multi-checkbox // multi-checkbox case 'W': // worker $in_array = DevblocksPlatform::importGPC($_REQUEST['value_cf_' . $field_id], 'array', array()); $out_array = array(); // Hash key on the option for quick lookup later if (is_array($in_array)) { foreach ($in_array as $k => $v) { $out_array[$v] = $v; } } $criteria['value'] = $out_array; break; case 'E': // date $from = DevblocksPlatform::importGPC($_REQUEST['value_cf_' . $field_id . '_from'], 'string', '0'); $to = DevblocksPlatform::importGPC($_REQUEST['value_cf_' . $field_id . '_to'], 'string', 'now'); $criteria['from'] = $from; $criteria['to'] = $to; unset($criteria['value']); break; case 'N': // number $oper = DevblocksPlatform::importGPC($_REQUEST['value_cf_' . $field_id . '_oper'], 'string', '='); $criteria['oper'] = $oper; $criteria['value'] = intval($value); break; case 'C': // checkbox $criteria['value'] = intval($value); break; } } else { continue; } break; } $criterion[$rule] = $criteria; } } // Actions if (is_array($do)) { foreach ($do as $act) { $action = array(); switch ($act) { // Move group/bucket case 'move': @($move_code = DevblocksPlatform::importGPC($_REQUEST['do_move'], 'string', null)); if (0 != strlen($move_code)) { list($g_id, $b_id) = CerberusApplication::translateTeamCategoryCode($move_code); $action = array('group_id' => intval($g_id), 'bucket_id' => intval($b_id)); } break; // Assign to worker // Assign to worker case 'assign': @($worker_id = DevblocksPlatform::importGPC($_REQUEST['do_assign'], 'string', null)); if (0 != strlen($worker_id)) { $action = array('worker_id' => intval($worker_id)); } break; // Spam training // Spam training case 'spam': @($is_spam = DevblocksPlatform::importGPC($_REQUEST['do_spam'], 'string', null)); if (0 != strlen($is_spam)) { $action = array('is_spam' => !$is_spam ? 0 : 1); } break; // Set status // Set status case 'status': @($status = DevblocksPlatform::importGPC($_REQUEST['do_status'], 'string', null)); if (0 != strlen($status)) { $action = array('is_waiting' => 3 == $status ? 1 : 0, 'is_closed' => 0 == $status || 3 == $status ? 0 : 1, 'is_deleted' => 2 == $status ? 1 : 0); } break; default: // ignore invalids // Custom fields if ("cf_" == substr($act, 0, 3)) { $field_id = intval(substr($act, 3)); if (!isset($custom_fields[$field_id])) { continue; } $action = array(); // [TODO] Operators switch ($custom_fields[$field_id]->type) { case 'S': // string // string case 'T': // clob // clob case 'D': // dropdown // dropdown case 'U': // URL // URL case 'W': // worker $value = DevblocksPlatform::importGPC($_REQUEST['do_cf_' . $field_id], 'string', ''); $action['value'] = $value; break; case 'M': // multi-dropdown // multi-dropdown case 'X': // multi-checkbox $in_array = DevblocksPlatform::importGPC($_REQUEST['do_cf_' . $field_id], 'array', array()); $out_array = array(); // Hash key on the option for quick lookup later if (is_array($in_array)) { foreach ($in_array as $k => $v) { $out_array[$v] = $v; } } $action['value'] = $out_array; break; case 'E': // date $value = DevblocksPlatform::importGPC($_REQUEST['do_cf_' . $field_id], 'string', ''); $action['value'] = $value; break; case 'N': // number // number case 'C': // checkbox $value = DevblocksPlatform::importGPC($_REQUEST['do_cf_' . $field_id], 'string', ''); $action['value'] = intval($value); break; } } else { continue; } break; } $actions[$act] = $action; } } $fields = array(DAO_GroupInboxFilter::NAME => $name, DAO_GroupInboxFilter::IS_STICKY => $is_sticky, DAO_GroupInboxFilter::CRITERIA_SER => serialize($criterion), DAO_GroupInboxFilter::ACTIONS_SER => serialize($actions)); // Only sticky filters can manual order and be stackable if (!$is_sticky) { $fields[DAO_GroupInboxFilter::STICKY_ORDER] = 0; $fields[DAO_GroupInboxFilter::IS_STACKABLE] = 0; } else { // is sticky $fields[DAO_GroupInboxFilter::IS_STACKABLE] = $is_stackable; } // Create if (empty($id)) { $fields[DAO_GroupInboxFilter::GROUP_ID] = $group_id; $fields[DAO_GroupInboxFilter::POS] = 0; $id = DAO_GroupInboxFilter::create($fields); // Update } else { DAO_GroupInboxFilter::update($id, $fields); } $defaults = new C4_AbstractViewModel(); $defaults->class_name = 'C4_TicketView'; $defaults->id = $view_id; $view = C4_AbstractViewLoader::getView($view_id, $defaults); if (!empty($view_id) && null != $view) { /* @var $view C4_TicketView */ // Loop through all the tickets in this inbox list($inbox_tickets, $null) = DAO_Ticket::search(null, array(new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_TEAM_ID, '=', $group_id), new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_CATEGORY_ID, '=', '0')), -1, 0, null, null, false); if (is_array($inbox_tickets)) { foreach ($inbox_tickets as $inbox_ticket) { /* @var $inbox_ticket CerberusTicket */ // Run only this new rule against all tickets in the group inbox CerberusApplication::runGroupRouting($group_id, intval($inbox_ticket[SearchFields_Ticket::TICKET_ID]), $id); } } $view->render(); return; } DevblocksPlatform::redirect(new DevblocksHttpResponse(array('groups', $group_id, 'inbox'))); }
function showAddressPeekAction() { @($id = DevblocksPlatform::importGPC($_REQUEST['id'], 'integer', '')); @($address_id = DevblocksPlatform::importGPC($_REQUEST['address_id'], 'integer', 0)); @($email = DevblocksPlatform::importGPC($_REQUEST['email'], 'string', '')); @($view_id = DevblocksPlatform::importGPC($_REQUEST['view_id'], 'string', '')); @($org_id = DevblocksPlatform::importGPC($_REQUEST['org_id'], 'string', '')); $tpl = DevblocksPlatform::getTemplateService(); $tpl->assign('path', $this->_TPL_PATH); if (!empty($address_id)) { $email = ''; if (null != ($addy = DAO_Address::get($address_id))) { @($email = $addy->email); } } $tpl->assign('email', $email); if (!empty($email)) { list($addresses, $null) = DAO_Address::search(array(), array(new DevblocksSearchCriteria(SearchFields_Address::EMAIL, DevblocksSearchCriteria::OPER_EQ, $email)), 1, 0, null, null, false); $address = array_shift($addresses); $tpl->assign('address', $address); $id = $address[SearchFields_Address::ID]; list($open_tickets, $open_count) = DAO_Ticket::search(array(), array(new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_CLOSED, '=', 0), new DevblocksSearchCriteria(SearchFields_Ticket::REQUESTER_ID, '=', $address[SearchFields_Address::ID])), 1); $tpl->assign('open_count', $open_count); list($closed_tickets, $closed_count) = DAO_Ticket::search(array(), array(new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_CLOSED, '=', 1), new DevblocksSearchCriteria(SearchFields_Ticket::REQUESTER_ID, '=', $address[SearchFields_Address::ID])), 1); $tpl->assign('closed_count', $closed_count); } if (!empty($org_id)) { $org = DAO_ContactOrg::get($org_id); $tpl->assign('org_name', $org->name); $tpl->assign('org_id', $org->id); } // Custom fields $custom_fields = DAO_CustomField::getBySource(ChCustomFieldSource_Address::ID); $tpl->assign('custom_fields', $custom_fields); $custom_field_values = DAO_CustomFieldValue::getValuesBySourceIds(ChCustomFieldSource_Address::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); // Display $tpl->assign('id', $id); $tpl->assign('view_id', $view_id); $tpl->display('file:' . $this->_TPL_PATH . 'contacts/addresses/address_peek.tpl'); }
private function _getListAction($path, $params = array()) { @($p_page = DevblocksPlatform::importGPC($_REQUEST['p'], 'integer', 0)); @($p_group_id = DevblocksPlatform::importGPC($_REQUEST['group_id'], 'string', '')); @($p_bucket_id = DevblocksPlatform::importGPC($_REQUEST['bucket_id'], 'string', '')); @($p_is_closed = DevblocksPlatform::importGPC($_REQUEST['is_closed'], 'string', '')); @($p_is_deleted = DevblocksPlatform::importGPC($_REQUEST['is_deleted'], 'string', '')); // Group if (0 != strlen($p_group_id)) { // cannot allow override by Worker search to invalid team if (isset($params[SearchFields_Ticket::TEAM_ID])) { // this is a Worker search if (false !== array_search($p_group_id, $params[SearchFields_Ticket::TEAM_ID]->value)) { } // worker is member of group_id $params[SearchFields_Ticket::TEAM_ID] = new DevblocksSearchCriteria(SearchFields_Ticket::TEAM_ID, 'eq', intval($p_group_id)); } else { // app-level key search $params[SearchFields_Ticket::TEAM_ID] = new DevblocksSearchCriteria(SearchFields_Ticket::TEAM_ID, 'eq', intval($p_group_id)); } } // Bucket if (0 != strlen($p_bucket_id)) { $params[SearchFields_Ticket::TICKET_CATEGORY_ID] = new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_CATEGORY_ID, 'eq', intval($p_bucket_id)); } // Closed if (0 != strlen($p_is_closed)) { $params[SearchFields_Ticket::TICKET_CLOSED] = new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_CLOSED, 'eq', intval($p_is_closed)); } // Deleted if (0 != strlen($p_is_deleted)) { $params[SearchFields_Ticket::TICKET_DELETED] = new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_DELETED, 'eq', intval($p_is_deleted)); } list($results, $null) = DAO_Ticket::search(array(), $params, 50, $p_page, SearchFields_Ticket::TICKET_UPDATED_DATE, true, false); $this->_renderResults($results, SearchFields_Ticket::getFields(), 'ticket', 'tickets'); }
/** * @param array * @param array * @return boolean * [TODO] Find a better home for this? */ function doBulkUpdate($filter, $filter_param, $data, $do, $ticket_ids = array()) { @set_time_limit(600); // Make sure we have checked items if we want a checked list if (0 == strcasecmp($filter, "checks") && empty($ticket_ids)) { return; } $rule = new Model_GroupInboxFilter(); $rule->actions = $do; $params = $this->params; if (empty($filter)) { $data[] = '*'; // All, just to permit a loop in foreach($data ...) } switch ($filter) { default: case 'subject': case 'sender': case 'header': if (is_array($data)) { foreach ($data as $v) { $new_params = array(); $do_header = null; switch ($filter) { case 'subject': $new_params = array(new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_SUBJECT, DevblocksSearchCriteria::OPER_LIKE, $v)); $do_header = 'subject'; $ticket_ids = array(); break; case 'sender': $new_params = array(new DevblocksSearchCriteria(SearchFields_Ticket::SENDER_ADDRESS, DevblocksSearchCriteria::OPER_LIKE, $v)); $do_header = 'from'; $ticket_ids = array(); break; case 'header': $new_params = array(new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_MESSAGE_HEADER, DevblocksSearchCriteria::OPER_EQ, $filter_param), new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_MESSAGE_HEADER_VALUE, DevblocksSearchCriteria::OPER_EQ, $v)); $ticket_ids = array(); break; } $new_params = array_merge($new_params, $params); $pg = 0; if (empty($ticket_ids)) { do { list($tickets, $null) = DAO_Ticket::search(array(), $new_params, 100, $pg++, SearchFields_Ticket::TICKET_ID, true, false); $ticket_ids = array_merge($ticket_ids, array_keys($tickets)); } while (!empty($tickets)); } $batch_total = count($ticket_ids); for ($x = 0; $x <= $batch_total; $x += 200) { $batch_ids = array_slice($ticket_ids, $x, 200); $rule->run($batch_ids); unset($batch_ids); } } } break; } unset($ticket_ids); }
function getData() { $objects = DAO_Ticket::search(array(), $this->params, $this->renderLimit, $this->renderPage, $this->renderSortBy, $this->renderSortAsc); return $objects; }
function saveAddInboxRulePanelAction() { $translate = DevblocksPlatform::getTranslationService(); @($view_id = DevblocksPlatform::importGPC($_REQUEST['view_id'], 'string', '')); @($group_id = DevblocksPlatform::importGPC($_REQUEST['group_id'], 'integer')); $view = C4_AbstractViewLoader::getView('C4_TicketView', $view_id); /* @var $view C4_TicketView */ if (empty($group_id)) { $view->render(); exit; } @($name = DevblocksPlatform::importGPC($_POST['name'], 'string', '')); @($rules = DevblocksPlatform::importGPC($_POST['rules'], 'array', array())); @($do = DevblocksPlatform::importGPC($_POST['do'], 'array', array())); if (empty($name)) { $name = $translate->_('mail.inbox_filter'); } $criterion = array(); $actions = array(); // Criteria if (is_array($rules)) { foreach ($rules as $rule) { $rule = DevblocksPlatform::strAlphaNumDash($rule); @($value = DevblocksPlatform::importGPC($_POST['value_' . $rule], 'string', '')); // [JAS]: Allow empty $value (null/blank checking) $criteria = array('value' => $value); // Any special rule handling switch ($rule) { case 'subject': break; case 'from': break; case 'tocc': break; case 'header1': case 'header2': case 'header3': case 'header4': case 'header5': if (null != @($header = DevblocksPlatform::importGPC($_POST[$rule], 'string', null))) { $criteria['header'] = strtolower($header); } break; case 'body': break; case 'attachment': break; default: // ignore invalids continue; break; } $criterion[$rule] = $criteria; } } // Actions if (is_array($do)) { foreach ($do as $act) { $action = array(); switch ($act) { // Move group/bucket case 'move': @($move_code = DevblocksPlatform::importGPC($_REQUEST['do_move'], 'string', null)); if (0 != strlen($move_code)) { list($g_id, $b_id) = CerberusApplication::translateTeamCategoryCode($move_code); $action = array('group_id' => intval($g_id), 'bucket_id' => intval($b_id)); } break; // Assign to worker // Assign to worker case 'assign': @($worker_id = DevblocksPlatform::importGPC($_REQUEST['do_assign'], 'string', null)); if (0 != strlen($worker_id)) { $action = array('worker_id' => intval($worker_id)); } break; // Spam training // Spam training case 'spam': @($is_spam = DevblocksPlatform::importGPC($_REQUEST['do_spam'], 'string', null)); if (0 != strlen($is_spam)) { $action = array('is_spam' => !$is_spam ? 0 : 1); } break; // Set status // Set status case 'status': @($status = DevblocksPlatform::importGPC($_REQUEST['do_status'], 'string', null)); if (0 != strlen($status)) { $action = array('is_closed' => 0 == $status ? 0 : 1, 'is_deleted' => 2 == $status ? 1 : 0); } break; default: // ignore invalids continue; break; } $actions[$act] = $action; } } $fields = array(DAO_GroupInboxFilter::NAME => $name, DAO_GroupInboxFilter::GROUP_ID => $group_id, DAO_GroupInboxFilter::CRITERIA_SER => serialize($criterion), DAO_GroupInboxFilter::ACTIONS_SER => serialize($actions), DAO_GroupInboxFilter::POS => 0); $routing_id = DAO_GroupInboxFilter::create($fields); // Loop through all the tickets in this inbox list($inbox_tickets, $null) = DAO_Ticket::search(null, array(new DevblocksSearchCriteria(SearchFields_Ticket::TEAM_ID, '=', $group_id), new DevblocksSearchCriteria(SearchFields_Ticket::TICKET_CATEGORY_ID, '=', '0')), -1, 0, null, null, false); if (is_array($inbox_tickets)) { foreach ($inbox_tickets as $inbox_ticket) { /* @var $inbox_ticket CerberusTicket */ // Run only this new rule against all tickets in the group inbox CerberusApplication::runGroupRouting($group_id, intval($inbox_ticket[SearchFields_Ticket::TICKET_ID]), $routing_id); } } $view->render(); exit; }