Ejemplo n.º 1
0
Archivo: App.php Proyecto: Hildy/cerb5
 private function _sendNotifications($filters, $url, $msg)
 {
     if (is_array($filters)) {
         foreach ($filters as $idx => $filter) {
             /* @var $filter Model_WatcherMailFilter */
             if (isset($filter->actions['notify'])) {
                 $fields = array(DAO_WorkerEvent::CREATED_DATE => time(), DAO_WorkerEvent::WORKER_ID => $filter->worker_id, DAO_WorkerEvent::URL => $url, DAO_WorkerEvent::TITLE => 'Watcher: ' . $filter->name, DAO_WorkerEvent::CONTENT => $msg, DAO_WorkerEvent::IS_READ => 0);
                 DAO_WorkerEvent::create($fields);
             }
         }
     }
 }
Ejemplo n.º 2
0
 private function _deleteIdAction($path)
 {
     $in_id = array_shift($path);
     if (empty($in_id)) {
         $this->_error("ID was not provided.");
     }
     if (null == ($event = DAO_WorkerEvent::get($in_id))) {
         $this->_error("ID is not valid.");
     }
     DAO_WorkerEvent::delete($event->id);
     $out_xml = new SimpleXMLElement('<success></success>');
     $this->_render($out_xml->asXML());
 }
Ejemplo n.º 3
0
 public function writeResponse(DevblocksHttpResponse $response)
 {
     $path = $response->path;
     // [JAS]: Ajax? // [TODO] Explore outputting whitespace here for Safari
     //	    if(empty($path))
     //			return;
     $tpl = DevblocksPlatform::getTemplateService();
     $session = DevblocksPlatform::getSessionService();
     $settings = CerberusSettings::getInstance();
     $translate = DevblocksPlatform::getTranslationService();
     $active_worker = CerberusApplication::getActiveWorker();
     $visit = $session->getVisit();
     $page_manifests = $this->_getAllowedPages();
     $controller = array_shift($path);
     // Default page [TODO] This is supposed to come from framework.config.php
     if (empty($controller)) {
         $controller = 'home';
     }
     // [JAS]: Require us to always be logged in for Cerberus pages
     if (empty($visit) && 0 != strcasecmp($controller, 'login')) {
         $query = array();
         if (!empty($response->path)) {
             $query = array('url' => urlencode(implode('/', $response->path)));
         }
         DevblocksPlatform::redirect(new DevblocksHttpRequest(array('login'), $query));
     }
     $page_id = $this->_getPageIdByUri($controller);
     @($page = DevblocksPlatform::getExtension($page_id, true));
     /* @var $page CerberusPageExtension */
     if (empty($page)) {
         header("Status: 404");
         return;
         // [TODO] 404
     }
     // [JAS]: Listeners (Step-by-step guided tour, etc.)
     $listenerManifests = DevblocksPlatform::getExtensions('devblocks.listener.http');
     foreach ($listenerManifests as $listenerManifest) {
         /* @var $listenerManifest DevblocksExtensionManifest */
         $inst = $listenerManifest->createInstance();
         /* @var $inst DevblocksHttpRequestListenerExtension */
         $inst->run($response, $tpl);
     }
     $tpl->assign('active_worker', $active_worker);
     $tour_enabled = false;
     if (!empty($visit) && !is_null($active_worker)) {
         $tour_enabled = intval(DAO_WorkerPref::get($active_worker->id, 'assist_mode', 1));
         if (DEMO_MODE) {
             $tour_enabled = 1;
         }
         // override for DEMO
         $keyboard_shortcuts = intval(DAO_WorkerPref::get($active_worker->id, 'keyboard_shortcuts', 1));
         $tpl->assign('pref_keyboard_shortcuts', $keyboard_shortcuts);
         $active_worker_memberships = $active_worker->getMemberships();
         $tpl->assign('active_worker_memberships', $active_worker_memberships);
         $unread_notifications = DAO_WorkerEvent::getUnreadCountByWorker($active_worker->id);
         $tpl->assign('active_worker_notify_count', $unread_notifications);
         DAO_Worker::logActivity($active_worker->id, $page->getActivity());
     }
     $tpl->assign('tour_enabled', $tour_enabled);
     // [JAS]: Variables provided to all page templates
     $tpl->assign('settings', $settings);
     $tpl->assign('session', $_SESSION);
     $tpl->assign('translate', $translate);
     $tpl->assign('visit', $visit);
     $tpl->assign('license', CerberusLicense::getInstance());
     $tpl->assign('page_manifests', $page_manifests);
     $tpl->assign('page', $page);
     $tpl->assign('response_uri', implode('/', $response->path));
     $core_tpl = DEVBLOCKS_PLUGIN_PATH . 'cerberusweb.core/templates/';
     $tpl->assign('core_tpl', $core_tpl);
     // Prebody Renderers
     $preBodyRenderers = DevblocksPlatform::getExtensions('cerberusweb.renderer.prebody', true);
     if (!empty($preBodyRenderers)) {
         $tpl->assign('prebody_renderers', $preBodyRenderers);
     }
     // Postbody Renderers
     $postBodyRenderers = DevblocksPlatform::getExtensions('cerberusweb.renderer.postbody', true);
     if (!empty($postBodyRenderers)) {
         $tpl->assign('postbody_renderers', $postBodyRenderers);
     }
     // Timings
     $tpl->assign('render_time', microtime(true) - DevblocksPlatform::getStartTime());
     if (function_exists('memory_get_usage') && function_exists('memory_get_peak_usage')) {
         $tpl->assign('render_memory', memory_get_usage() - DevblocksPlatform::getStartMemory());
         $tpl->assign('render_peak_memory', memory_get_peak_usage() - DevblocksPlatform::getStartPeakMemory());
     }
     $tpl->display($core_tpl . 'border.tpl');
     //		$cache = DevblocksPlatform::getCacheService();
     //		$cache->printStatistics();
 }
Ejemplo n.º 4
0
 function doNotificationsMarkReadAction()
 {
     $worker = PortSensorApplication::getActiveWorker();
     @($view_id = DevblocksPlatform::importGPC($_REQUEST['view_id'], 'string', ''));
     @($row_ids = DevblocksPlatform::importGPC($_REQUEST['row_id'], 'array', array()));
     if (is_array($row_ids) && !empty($row_ids)) {
         DAO_WorkerEvent::updateWhere(array(DAO_WorkerEvent::IS_READ => 1), sprintf("%s = %d AND %s IN (%s)", DAO_WorkerEvent::WORKER_ID, $worker->id, DAO_WorkerEvent::ID, implode(',', $row_ids)));
         DAO_WorkerEvent::clearCountCache($worker->id);
     }
     $myEventsView = Ps_AbstractViewLoader::getView($view_id);
     $myEventsView->render();
 }
Ejemplo n.º 5
0
 function saveCommentAction()
 {
     @($ticket_id = DevblocksPlatform::importGPC($_REQUEST['ticket_id'], 'integer'));
     @($comment = DevblocksPlatform::importGPC($_REQUEST['comment'], 'string', ''));
     // Worker is logged in
     if (null === ($active_worker = CerberusApplication::getActiveWorker())) {
         DevblocksPlatform::redirect(new DevblocksHttpResponse(array('display', $ticket_id)));
     }
     $worker_email = $active_worker->email;
     // Worker address exists
     if (null === ($address = CerberusApplication::hashLookupAddress($active_worker->email, true))) {
         DevblocksPlatform::redirect(new DevblocksHttpResponse(array('display', $ticket_id)));
     }
     // Form was filled in
     if (empty($ticket_id) || empty($comment)) {
         DevblocksPlatform::redirect(new DevblocksHttpResponse(array('display', $ticket_id)));
     }
     $fields = array(DAO_TicketComment::CREATED => time(), DAO_TicketComment::TICKET_ID => $ticket_id, DAO_TicketComment::ADDRESS_ID => $address->id, DAO_TicketComment::COMMENT => $comment);
     $comment_id = DAO_TicketComment::create($fields);
     @($ticket = DAO_Ticket::getTicket($ticket_id));
     // 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=display&id=' . $ticket->mask, true), DAO_WorkerEvent::TITLE => 'New Ticket Comment', DAO_WorkerEvent::CONTENT => sprintf("#%s: %s\n%s comments: %s", $ticket->mask, $ticket->subject, $active_worker->getName(), $comment), DAO_WorkerEvent::IS_READ => 0);
             DAO_WorkerEvent::create($fields);
         }
     }
     DevblocksPlatform::redirect(new DevblocksHttpResponse(array('display', $ticket->mask, 'comments')));
 }
Ejemplo n.º 6
0
 function doNotificationsMarkReadAction()
 {
     @($view_id = DevblocksPlatform::importGPC($_REQUEST['view_id'], 'string', ''));
     @($row_ids = DevblocksPlatform::importGPC($_REQUEST['row_id'], 'array', array()));
     if (is_array($row_ids) && !empty($row_ids)) {
         DAO_WorkerEvent::updateWhere(array(DAO_WorkerEvent::IS_READ => 1), sprintf("%s IN (%s)", DAO_WorkerEvent::ID, implode(',', $row_ids)));
     }
     $myEventsView = C4_AbstractViewLoader::getView('', $view_id);
     $myEventsView->render();
 }
Ejemplo n.º 7
0
 function saveOppNoteAction()
 {
     @($opp_id = DevblocksPlatform::importGPC($_REQUEST['opp_id'], 'integer', 0));
     @($content = DevblocksPlatform::importGPC($_REQUEST['content'], 'string', ''));
     $active_worker = CerberusApplication::getActiveWorker();
     if (!empty($opp_id) && 0 != strlen(trim($content))) {
         $fields = array(DAO_Note::SOURCE_EXTENSION_ID => CrmNotesSource_Opportunity::ID, DAO_Note::SOURCE_ID => $opp_id, DAO_Note::WORKER_ID => $active_worker->id, DAO_Note::CREATED => time(), DAO_Note::CONTENT => $content);
         $note_id = DAO_Note::create($fields);
     }
     $opp = DAO_CrmOpportunity::get($opp_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=crm&a=opps&id=' . $opp_id, true), DAO_WorkerEvent::TITLE => 'New Opportunity Note', DAO_WorkerEvent::CONTENT => sprintf("%s\n%s notes: %s", $opp->name, $active_worker->getName(), $content), DAO_WorkerEvent::IS_READ => 0);
             DAO_WorkerEvent::create($fields);
         }
     }
     DevblocksPlatform::redirect(new DevblocksHttpResponse(array('crm', 'opp', $opp_id)));
 }
Ejemplo n.º 8
0
 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;
 }
Ejemplo n.º 9
0
 function getData()
 {
     $objects = DAO_WorkerEvent::search($this->params, $this->renderLimit, $this->renderPage, $this->renderSortBy, $this->renderSortAsc);
     return $objects;
 }
Ejemplo n.º 10
0
 function viewAssignThreadsAction()
 {
     @($row_ids = DevblocksPlatform::importGPC($_POST['row_id'], 'array', array()));
     @($worker_id = DevblocksPlatform::importGPC($_REQUEST['assign_worker_id'], 'integer', 0));
     @($view_id = DevblocksPlatform::importGPC($_REQUEST['view_id'], 'string', ''));
     $active_worker = CerberusApplication::getActiveWorker();
     if (is_array($row_ids) && !empty($row_ids)) {
         // Do assignments
         $fields = array(DAO_ForumsThread::WORKER_ID => $worker_id);
         DAO_ForumsThread::update($row_ids, $fields);
         // Only send notifications if not assigning to self (or unassigning)
         if (!empty($worker_id) && $active_worker->id != $worker_id) {
             $url_writer = DevblocksPlatform::getUrlService();
             // Load threads for notifications
             $forum_threads = DAO_ForumsThread::getWhere(sprintf("%s IN (%s)", DAO_ForumsThread::ID, implode(',', $row_ids)));
             // Send notifications about assigned forum threads
             if (is_array($forum_threads) && !empty($forum_threads)) {
                 foreach ($forum_threads as $forum_thread) {
                     /* @var $forum_thread Model_ForumsThread */
                     $fields = array(DAO_WorkerEvent::CREATED_DATE => time(), DAO_WorkerEvent::WORKER_ID => $worker_id, DAO_WorkerEvent::URL => $url_writer->write('c=forums&a=explorer', true) . '?start=' . $forum_thread->id, DAO_WorkerEvent::TITLE => 'New Forum Assignment', DAO_WorkerEvent::CONTENT => sprintf("%s assigned: %s", $active_worker->getName(), $forum_thread->title), DAO_WorkerEvent::IS_READ => 0);
                     DAO_WorkerEvent::create($fields);
                 }
             }
         }
     }
     if (!empty($view_id) && null != ($view = C4_AbstractViewLoader::getView($view_id))) {
         $view->render();
     }
 }
Ejemplo n.º 11
0
 private function _workerAssigned($event)
 {
     @($ticket_ids = $event->params['ticket_ids']);
     @($changed_fields = $event->params['changed_fields']);
     if (empty($ticket_ids) || empty($changed_fields)) {
         return;
     }
     @($next_worker_id = $changed_fields[DAO_Ticket::NEXT_WORKER_ID]);
     // Make sure a next worker was assigned
     if (empty($next_worker_id)) {
         return;
     }
     @($active_worker = CerberusApplication::getActiveWorker());
     // Make sure we're not assigning work to ourselves, if so then bail
     if (null != $active_worker && $active_worker->id == $next_worker_id) {
         return;
     }
     $tickets = DAO_Ticket::getTickets($ticket_ids);
     // Write a notification (if not assigned to ourselves)
     $url_writer = DevblocksPlatform::getUrlService();
     foreach ($ticket_ids as $ticket_id) {
         if (null == ($ticket = $tickets[$ticket_id])) {
             /* @var $ticket CerberusTicket */
             continue;
         }
         $fields = array(DAO_WorkerEvent::CREATED_DATE => time(), DAO_WorkerEvent::WORKER_ID => $next_worker_id, DAO_WorkerEvent::URL => $url_writer->write('c=display&id=' . $ticket->mask, true), DAO_WorkerEvent::TITLE => 'New Ticket Assignment', DAO_WorkerEvent::CONTENT => sprintf("#%s: %s", $ticket->mask, $ticket->subject), DAO_WorkerEvent::IS_READ => 0);
         DAO_WorkerEvent::create($fields);
     }
 }