private function _workerAssignedTask($event) { $translate = DevblocksPlatform::getTranslationService(); $events = DevblocksPlatform::getEventService(); $worker_id = $event->params['worker_id']; $context = $event->params['context']; $task_id = $event->params['context_id']; $mail_service = DevblocksPlatform::getMailService(); $mailer = null; // lazy load $settings = DevblocksPlatform::getPluginSettingsService(); $reply_to = $settings->get('cerberusweb.core', CerberusSettings::DEFAULT_REPLY_FROM, CerberusSettingsDefaults::DEFAULT_REPLY_FROM); $reply_personal = $settings->get('cerberusweb.core', CerberusSettings::DEFAULT_REPLY_PERSONAL, CerberusSettingsDefaults::DEFAULT_REPLY_PERSONAL); $task = DAO_Task::get($task_id); // Sanitize and combine all the destination addresses $next_worker = DAO_Worker::get($worker_id); $notify_emails = $next_worker->email; if (empty($notify_emails)) { return; } try { if (null == $mailer) { $mailer = $mail_service->getMailer(CerberusMail::getMailerDefaults()); } // Create the message $mail = $mail_service->createMessage(); $mail->setTo(array($notify_emails)); $mail->setFrom(array($reply_to => $reply_personal)); $mail->setReplyTo($reply_to); $mail->setSubject(sprintf("[Task Assignment #%d]: %s", $task->id, $task->title)); $headers = $mail->getHeaders(); $headers->addTextHeader('X-Mailer', 'Cerberus Helpdesk (Build ' . APP_BUILD . ')'); $headers->addTextHeader('Precedence', 'List'); $headers->addTextHeader('Auto-Submitted', 'auto-generated'); $body = sprintf("[Task Assignment #%d]: %s", $task->id, $task->title); $mft = DevblocksPlatform::getExtension($context, false, true); $ext = $mft->createInstance(); $url = $ext->getPermalink($task_id); $body .= "\r\n" . $url; // Comments $comments = DAO_Comment::getByContext(CerberusContexts::CONTEXT_TASK, $task_id); foreach ($comments as $comment_id => $comment) { $address = DAO_Address::get($comment->address_id); $body .= "\r\nCommented By: " . $address->first_name . " " . $address->last_name; $body .= "\r\n" . $comment->comment; } unset($comments); $body .= "\r\n"; $mail->setBody($body); $result = $mailer->send($mail); } catch (Exception $e) { echo "Task Email Notification failed to send<br>"; } }
function render() { $tpl = DevblocksPlatform::getTemplateService(); $tpl->cache_lifetime = "0"; $tpl_path = $this->plugin_path . '/templates/'; $tpl->assign('path', $tpl_path); $visit = CerberusApplication::getVisit(); $translate = DevblocksPlatform::getTranslationService(); $response = DevblocksPlatform::getHttpResponse(); $stack = $response->path; array_shift($stack); // crm $module = array_shift($stack); // opps switch ($module) { default: case 'opps': @($opp_id = intval(array_shift($stack))); if (null == ($opp = DAO_CrmOpportunity::get($opp_id))) { break; // [TODO] Not found } $tpl->assign('opp', $opp); $address = DAO_Address::get($opp->primary_email_id); $tpl->assign('address', $address); $workers = DAO_Worker::getAll(); $tpl->assign('workers', $workers); $task_count = DAO_Task::getCountBySourceObjectId('cerberusweb.tasks.opp', $opp_id); $tpl->assign('tasks_total', $task_count); $visit = CerberusApplication::getVisit(); // Does a series exist? if (null != ($series_info = $visit->get('ch_opp_series', null))) { @($series = $series_info['series']); // Is this ID part of the series? If not, invalidate if (!isset($series[$opp_id])) { $visit->set('ch_opp_series', null); } else { $series_stats = array('title' => $series_info['title'], 'total' => $series_info['total'], 'count' => count($series)); reset($series); $cur = 1; while (current($series)) { $pos = key($series); if (intval($pos) == intval($opp_id)) { $series_stats['cur'] = $cur; if (false !== prev($series)) { @($series_stats['prev'] = $series[key($series)][SearchFields_CrmOpportunity::ID]); next($series); // skip to current } else { reset($series); } next($series); // next @($series_stats['next'] = $series[key($series)][SearchFields_CrmOpportunity::ID]); break; } next($series); $cur++; } $tpl->assign('series_stats', $series_stats); } } $tpl->display($tpl_path . 'crm/opps/display/index.tpl'); break; } }
function render() { $tpl = DevblocksPlatform::getTemplateService(); $tpl->cache_lifetime = "0"; $tpl->assign('path', $this->_TPL_PATH); $visit = CerberusApplication::getVisit(); /* @var $visit CerberusVisit */ $response = DevblocksPlatform::getHttpResponse(); $active_worker = CerberusApplication::getActiveWorker(); $translate = DevblocksPlatform::getTranslationService(); $url = DevblocksPlatform::getUrlService(); $stack = $response->path; @array_shift($stack); // display @($id = array_shift($stack)); // Tabs $tab_manifests = DevblocksPlatform::getExtensions('cerberusweb.ticket.tab', false); $tpl->assign('tab_manifests', $tab_manifests); @($tab_selected = array_shift($stack)); if (empty($tab_selected)) { $tab_selected = 'conversation'; } $tpl->assign('tab_selected', $tab_selected); switch ($tab_selected) { case 'conversation': @($mail_always_show_all = DAO_WorkerPref::get($active_worker->id, 'mail_always_show_all', 0)); @($tab_option = array_shift($stack)); if ($mail_always_show_all || 0 == strcasecmp("read_all", $tab_option)) { $tpl->assign('expand_all', true); } break; } // [JAS]: Translate Masks 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; } // Permissions $active_worker_memberships = $active_worker->getMemberships(); // Check group membership ACL if (!isset($active_worker_memberships[$ticket->team_id])) { echo "<H1>" . $translate->_('common.access_denied') . "</H1>"; return; } $tpl->assign('ticket', $ticket); // TicketToolbarItem Extensions $ticketToolbarItems = DevblocksPlatform::getExtensions('cerberusweb.ticket.toolbaritem', true); if (!empty($ticketToolbarItems)) { $tpl->assign('ticket_toolbaritems', $ticketToolbarItems); } // Next+Prev: Does a series exist? if (null != ($series_info = $visit->get('ch_display_series', null))) { @($series = $series_info['series']); $cur = 1; $found = false; // Is this ID part of the series? If not, invalidate if (is_array($series)) { while ($mask = current($series)) { // Stop if we find it. if ($mask == $ticket->mask) { $found = true; break; } next($series); $cur++; } } if (!$found) { // not found $visit->set('ch_display_series', null); } else { // found $series_stats = array('title' => $series_info['title'], 'total' => $series_info['total'], 'count' => count($series)); $series_stats['cur'] = $cur; if (false !== prev($series)) { @($series_stats['prev'] = current($series)); next($series); // skip to current } else { reset($series); } next($series); // next @($series_stats['next'] = current($series)); $tpl->assign('series_stats', $series_stats); } } $quick_search_type = $visit->get('quick_search_type'); $tpl->assign('quick_search_type', $quick_search_type); // Comments [TODO] Eventually this can be cached on ticket.num_comments $comments_total = DAO_TicketComment::getCountByTicketId($id); $tpl->assign('comments_total', $comments_total); // Tasks Total [TODO] Eventually this can be ticket.num_tasks $tasks_total = DAO_Task::getCountBySourceObjectId('cerberusweb.tasks.ticket', $id); $tpl->assign('tasks_total', $tasks_total); $workers = DAO_Worker::getAll(); $tpl->assign('workers', $workers); $teams = DAO_Group::getAll(); $tpl->assign('teams', $teams); $team_categories = DAO_Bucket::getTeams(); $tpl->assign('team_categories', $team_categories); // Log Activity DAO_Worker::logActivity($active_worker->id, new Model_Activity('activity.display_ticket', array(sprintf("<a href='%s' title='[%s] %s'>#%s</a>", $url->write("c=display&id=" . $ticket->mask), htmlspecialchars(@$teams[$ticket->team_id]->name, ENT_QUOTES, LANG_CHARSET_CODE), htmlspecialchars($ticket->subject, ENT_QUOTES, LANG_CHARSET_CODE), $ticket->mask)))); $tpl->display('file:' . $this->_TPL_PATH . 'display/index.tpl'); }
function render() { $tpl = DevblocksPlatform::getTemplateService(); $tpl->assign('path', $this->_TPL_PATH); $visit = CerberusApplication::getVisit(); $response = DevblocksPlatform::getHttpResponse(); $stack = $response->path; @array_shift($stack); // contacts @($selected_tab = array_shift($stack)); // orgs|addresses|* $tpl->assign('selected_tab', $selected_tab); // Allow a non-tab renderer switch ($selected_tab) { case 'import': switch (@array_shift($stack)) { case 'step2': $type = $visit->get('import.last.type', ''); switch ($type) { case 'orgs': $fields = DAO_ContactOrg::getFields(); $tpl->assign('fields', $fields); $custom_fields = DAO_CustomField::getBySource(ChCustomFieldSource_Org::ID); $tpl->assign('custom_fields', $custom_fields); break; case 'addys': $fields = DAO_Address::getFields(); $tpl->assign('fields', $fields); $custom_fields = DAO_CustomField::getBySource(ChCustomFieldSource_Address::ID); $tpl->assign('custom_fields', $custom_fields); break; } $tpl->display('file:' . $this->_TPL_PATH . 'contacts/import/mapping.tpl'); return; break; } break; // [TODO] The org display page should probably move to its own controller // [TODO] The org display page should probably move to its own controller case 'orgs': switch (@array_shift($stack)) { case 'display': $tab_manifests = DevblocksPlatform::getExtensions('cerberusweb.org.tab', false); $tpl->assign('tab_manifests', $tab_manifests); $id = array_shift($stack); $contact = DAO_ContactOrg::get($id); $tpl->assign('contact', $contact); $task_count = DAO_Task::getCountBySourceObjectId('cerberusweb.tasks.org', $contact->id); $tpl->assign('tasks_total', $task_count); $people_count = DAO_Address::getCountByOrgId($contact->id); $tpl->assign('people_total', $people_count); // Does a series exist? // [TODO] This is highly redundant if (null != ($series_info = $visit->get('ch_org_series', null))) { @($series = $series_info['series']); // Is this ID part of the series? If not, invalidate if (!isset($series[$contact->id])) { $visit->set('ch_org_series', null); } else { $series_stats = array('title' => $series_info['title'], 'total' => $series_info['total'], 'count' => count($series)); reset($series); $cur = 1; while ($pos = key($series)) { if (intval($pos) == intval($contact->id)) { $series_stats['cur'] = $cur; if (false !== prev($series)) { @($series_stats['prev'] = key($series)); next($series); // skip to current } else { reset($series); } next($series); // next @($series_stats['next'] = key($series)); break; } next($series); $cur++; } $tpl->assign('series_stats', $series_stats); } } $tpl->display('file:' . $this->_TPL_PATH . 'contacts/orgs/display.tpl'); return; break; // case 'orgs/display' } // switch (action) break; } // switch (tab) $tpl->display('file:' . $this->_TPL_PATH . 'contacts/index.tpl'); return; // case 'people': // $view = C4_AbstractViewLoader::getView('addybook_people'); // C4_AddressView::DEFAULT_ID // // if(null == $view) { // $view = new C4_AddressView(); // $view->id = 'addybook_people'; // $view->name = 'People'; // $view->params = array( // new DevblocksSearchCriteria(SearchFields_Address::CONTACT_ORG_ID,'!=',0), // ); // // C4_AbstractViewLoader::setView('addybook_people', $view); // } // // $tpl->assign('view', $view); // $tpl->assign('contacts_page', 'people'); // $tpl->assign('view_fields', C4_AddressView::getFields()); // $tpl->assign('view_searchable_fields', C4_AddressView::getSearchFields()); // $tpl->display('file:' . $this->_TPL_PATH . 'contacts/people/index.tpl'); // break; }
function saveTaskPeekAction() { @($id = DevblocksPlatform::importGPC($_REQUEST['id'], 'integer', '')); @($view_id = DevblocksPlatform::importGPC($_REQUEST['view_id'], 'string', '')); @($link_namespace = DevblocksPlatform::importGPC($_REQUEST['link_namespace'], 'string', '')); @($link_object_id = DevblocksPlatform::importGPC($_REQUEST['link_object_id'], 'integer', 0)); @($do_delete = DevblocksPlatform::importGPC($_REQUEST['do_delete'], 'integer', 0)); $active_worker = CerberusApplication::getActiveWorker(); if (!empty($id) && !empty($do_delete)) { // delete $task = DAO_Task::get($id); // Check privs if ($active_worker->hasPriv('core.tasks.actions.create') && $active_worker->id == $task->worker_id || $active_worker->hasPriv('core.tasks.actions.update_nobody') && empty($task->worker_id) || $active_worker->hasPriv('core.tasks.actions.update_all')) { DAO_Task::delete($id); } } else { // create|update $fields = array(); // Title @($title = DevblocksPlatform::importGPC($_REQUEST['title'], 'string', '')); if (!empty($title)) { $fields[DAO_Task::TITLE] = $title; } // Completed @($completed = DevblocksPlatform::importGPC($_REQUEST['completed'], 'integer', 0)); $fields[DAO_Task::IS_COMPLETED] = intval($completed); // [TODO] This shouldn't constantly update the completed date (it should compare) if ($completed) { $fields[DAO_Task::COMPLETED_DATE] = time(); } else { $fields[DAO_Task::COMPLETED_DATE] = 0; } // Due Date @($due_date = DevblocksPlatform::importGPC($_REQUEST['due_date'], 'string', '')); @($fields[DAO_Task::DUE_DATE] = empty($due_date) ? 0 : intval(strtotime($due_date))); // Worker @($worker_id = DevblocksPlatform::importGPC($_REQUEST['worker_id'], 'integer', 0)); @($fields[DAO_Task::WORKER_ID] = intval($worker_id)); // Content @($content = DevblocksPlatform::importGPC($_REQUEST['content'], 'string', '')); @($fields[DAO_Task::CONTENT] = $content); // Link to object (optional) if (!empty($link_namespace) && !empty($link_object_id)) { @($fields[DAO_Task::SOURCE_EXTENSION] = $link_namespace); @($fields[DAO_Task::SOURCE_ID] = $link_object_id); } // Save if (!empty($id)) { DAO_Task::update($id, $fields); } else { $id = DAO_Task::create($fields); // Write a notification (if not assigned to ourselves) // $url_writer = DevblocksPlatform::getUrlService(); $source_extensions = DevblocksPlatform::getExtensions('cerberusweb.task.source', true); if (!empty($worker_id)) { // && $active_worker->id != $worker_id (Temporarily allow self notifications) if (null != @($source_renderer = $source_extensions[$link_namespace])) { /* @var $source_renderer Extension_TaskSource */ $source_info = $source_renderer->getSourceInfo($link_object_id); $source_name = $source_info['name']; $source_url = $source_info['url']; if (empty($source_name) || empty($source_url)) { break; } $fields = array(DAO_WorkerEvent::CREATED_DATE => time(), DAO_WorkerEvent::WORKER_ID => $worker_id, DAO_WorkerEvent::URL => $source_url, DAO_WorkerEvent::TITLE => 'New Task Assignment', DAO_WorkerEvent::CONTENT => sprintf("%s\n%s says: %s", $source_name, $active_worker->getName(), $title), DAO_WorkerEvent::IS_READ => 0); DAO_WorkerEvent::create($fields); } } } // Custom field saves @($field_ids = DevblocksPlatform::importGPC($_POST['field_ids'], 'array', array())); DAO_CustomFieldValue::handleFormPost(ChCustomFieldSource_Task::ID, $id, $field_ids); } if (!empty($view_id) && null != ($view = C4_AbstractViewLoader::getView('', $view_id))) { $view->render(); } exit; }
private function _deleteIdAction($path) { $in_id = array_shift($path); if (empty($in_id)) { $this->_error("ID was not provided."); } if (null == ($task = DAO_Task::get($in_id))) { $this->_error("ID is not valid."); } DAO_Task::delete($task->id); $out_xml = new SimpleXMLElement('<success></success>'); $this->_render($out_xml->asXML()); }
function doBulkUpdate($filter, $do, $ids = array()) { @set_time_limit(600); // [TODO] Temp! $change_fields = array(); $custom_fields = array(); // Make sure we have actions if (empty($do)) { return; } // Make sure we have checked items if we want a checked list if (0 == strcasecmp($filter, "checks") && empty($ids)) { return; } if (is_array($do)) { foreach ($do as $k => $v) { switch ($k) { case 'due': @($date = strtotime($v)); $change_fields[DAO_Task::DUE_DATE] = intval($date); break; case 'status': if (1 == intval($v)) { // completed $change_fields[DAO_Task::IS_COMPLETED] = 1; $change_fields[DAO_Task::COMPLETED_DATE] = time(); } else { // active $change_fields[DAO_Task::IS_COMPLETED] = 0; $change_fields[DAO_Task::COMPLETED_DATE] = 0; } break; case 'worker_id': $change_fields[DAO_Task::WORKER_ID] = intval($v); break; default: // Custom fields if (substr($k, 0, 3) == "cf_") { $custom_fields[substr($k, 3)] = $v; } } } } $pg = 0; if (empty($ids)) { do { list($objects, $null) = DAO_Task::search(array(), $this->params, 100, $pg++, SearchFields_Task::ID, true, false); $ids = array_merge($ids, array_keys($objects)); } while (!empty($objects)); } $batch_total = count($ids); for ($x = 0; $x <= $batch_total; $x += 100) { $batch_ids = array_slice($ids, $x, 100); DAO_Task::update($batch_ids, $change_fields); // Custom Fields self::_doBulkSetCustomFields(ChCustomFieldSource_Task::ID, $custom_fields, $batch_ids); unset($batch_ids); } unset($ids); }
/** * @param array $ids */ static function delete($ids) { if (!is_array($ids)) { $ids = array($ids); } $db = DevblocksPlatform::getDatabaseService(); $id_list = implode(',', $ids); // Orgs $sql = sprintf("DELETE QUICK FROM contact_org WHERE id IN (%s)", $id_list); $db->Execute($sql) or die(__CLASS__ . '(' . __LINE__ . ')' . ':' . $db->ErrorMsg()); /* @var $rs ADORecordSet */ // Clear any associated addresses $sql = sprintf("UPDATE address SET contact_org_id = 0 WHERE contact_org_id IN (%s)", $id_list); $db->Execute($sql) or die(__CLASS__ . '(' . __LINE__ . ')' . ':' . $db->ErrorMsg()); /* @var $rs ADORecordSet */ // Tasks DAO_Task::deleteBySourceIds('cerberusweb.tasks.org', $ids); // Custom fields DAO_CustomFieldValue::deleteBySourceIds(ChCustomFieldSource_Org::ID, $ids); // Notes DAO_Note::deleteBySourceIds(ChNotesSource_Org::ID, $ids); }
function saveTaskNoteAction() { @($task_id = DevblocksPlatform::importGPC($_REQUEST['task_id'], 'integer', 0)); @($content = DevblocksPlatform::importGPC($_REQUEST['content'], 'string', '')); $active_worker = CerberusApplication::getActiveWorker(); if (!empty($task_id) && 0 != strlen(trim($content))) { $fields = array(DAO_Note::SOURCE_EXTENSION_ID => ChNotesSource_Task::ID, DAO_Note::SOURCE_ID => $task_id, DAO_Note::WORKER_ID => $active_worker->id, DAO_Note::CREATED => time(), DAO_Note::CONTENT => $content); $note_id = DAO_Note::create($fields); } $task = DAO_Task::get($task_id); // Worker notifications $url_writer = DevblocksPlatform::getUrlService(); @($notify_worker_ids = DevblocksPlatform::importGPC($_REQUEST['notify_worker_ids'], 'array', array())); if (is_array($notify_worker_ids) && !empty($notify_worker_ids)) { foreach ($notify_worker_ids as $notify_worker_id) { $fields = array(DAO_WorkerEvent::CREATED_DATE => time(), DAO_WorkerEvent::WORKER_ID => $notify_worker_id, DAO_WorkerEvent::URL => $url_writer->write('c=tasks&a=display&id=' . $task_id, true), DAO_WorkerEvent::TITLE => 'New Task Note', DAO_WorkerEvent::CONTENT => sprintf("%s\n%s notes: %s", $task->title, $active_worker->getName(), $content), DAO_WorkerEvent::IS_READ => 0); DAO_WorkerEvent::create($fields); } } DevblocksPlatform::redirect(new DevblocksHttpResponse(array('tasks', 'display', $task_id))); }
function runMacroAction() { @($macro_id = DevblocksPlatform::importGPC($_REQUEST['macro_id'], 'integer')); @($ids = DevblocksPlatform::importGPC($_REQUEST['ids'])); @($view_id = DevblocksPlatform::importGPC($_REQUEST['view_id'], 'string')); $view = C4_AbstractViewLoader::getView($view_id); $ids = explode(',', $ids); if (null !== ($macro = DAO_Macro::get($macro_id))) { switch ($macro->source_extension_id) { case 'cerberusweb.macros.ticket': $fields = array(); // loop over the actions, saving the $params as $fields foreach ($macro->actions as $action => $params) { switch ($action) { case 'cerberusweb.macros.action.assign': $fields['next_worker_id'] = $params['worker_id']; break; case 'cerberusweb.macros.action.move': $fields['team_id'] = $params['group_id']; $fields['category_id'] = $params['bucket_id']; break; case 'cerberusweb.macros.action.status': $fields['is_waiting'] = $params['is_waiting']; $fields['is_closed'] = $params['is_closed']; $fields['is_deleted'] = $params['is_deleted']; break; default: // $fields[] = $params; break; } } // update the ticket DAO_Ticket::updateTicket($ids, $fields); break; case 'cerberusweb.macros.address': foreach ($macro->actions as $action => $params) { switch ($action) { default: DAO_Address::update($ids, $params); } } break; case 'cerberusweb.macros.opportunity': foreach ($macro->actions as $action => $params) { switch ($action) { default: DAO_CrmOpportunity::update($ids, $params); } } case 'cerberusweb.macros.task': foreach ($macro->actions as $action => $params) { switch ($action) { default: DAO_Task::update($ids, $params); } } case 'cerberusweb.macros.organization': foreach ($macro->actions as $action => $params) { switch ($action) { default: DAO_ContactOrg::update($ids, $params); } } default: break; } } $view = C4_AbstractViewLoader::getView($view_id); $view->render(); }