Esempio n. 1
0
 function handleRequest(DevblocksHttpRequest $request)
 {
     $worker = CerberusApplication::getActiveWorker();
     if (empty($worker)) {
         return;
     }
     $stack = $request->path;
     array_shift($stack);
     // print
     @($object = strtolower(array_shift($stack)));
     // ticket|message|etc
     $tpl = DevblocksPlatform::getTemplateService();
     $tpl->assign('path', $this->_TPL_PATH);
     $settings = DevblocksPlatform::getPluginSettingsService();
     $tpl->assign('settings', $settings);
     $translate = DevblocksPlatform::getTranslationService();
     $tpl->assign('translate', $translate);
     $teams = DAO_Group::getAll();
     $tpl->assign('teams', $teams);
     $buckets = DAO_Bucket::getAll();
     $tpl->assign('buckets', $buckets);
     $workers = DAO_Worker::getAll();
     $tpl->assign('workers', $workers);
     // Security
     $active_worker = CerberusApplication::getActiveWorker();
     $active_worker_memberships = $active_worker->getMemberships();
     // [TODO] Make this pluggable
     // Subcontroller
     switch ($object) {
         case 'ticket':
             @($id = array_shift($stack));
             @($ticket = is_numeric($id) ? DAO_Ticket::getTicket($id) : DAO_Ticket::getTicketByMask($id));
             $convo_timeline = array();
             $messages = $ticket->getMessages();
             foreach ($messages as $message_id => $message) {
                 /* @var $message CerberusMessage */
                 $key = $message->created_date . '_m' . $message_id;
                 // build a chrono index of messages
                 $convo_timeline[$key] = array('m', $message_id);
             }
             @($mail_inline_comments = DAO_WorkerPref::get($active_worker->id, 'mail_inline_comments', 1));
             if ($mail_inline_comments) {
                 // if inline comments are enabled
                 $comments = DAO_TicketComment::getByTicketId($ticket->id);
                 arsort($comments);
                 $tpl->assign('comments', $comments);
                 // build a chrono index of comments
                 foreach ($comments as $comment_id => $comment) {
                     /* @var $comment Model_TicketComment */
                     $key = $comment->created . '_c' . $comment_id;
                     $convo_timeline[$key] = array('c', $comment_id);
                 }
             }
             ksort($convo_timeline);
             $tpl->assign('convo_timeline', $convo_timeline);
             // Comment parent addresses
             $comment_addresses = array();
             foreach ($comments as $comment) {
                 /* @var $comment Model_TicketComment */
                 $address_id = intval($comment->address_id);
                 if (!isset($comment_addresses[$address_id])) {
                     $address = DAO_Address::get($address_id);
                     $comment_addresses[$address_id] = $address;
                 }
             }
             $tpl->assign('comment_addresses', $comment_addresses);
             // Message Notes
             $notes = DAO_MessageNote::getByTicketId($ticket->id);
             $message_notes = array();
             // Index notes by message id
             if (is_array($notes)) {
                 foreach ($notes as $note) {
                     if (!isset($message_notes[$note->message_id])) {
                         $message_notes[$note->message_id] = array();
                     }
                     $message_notes[$note->message_id][$note->id] = $note;
                 }
             }
             $tpl->assign('message_notes', $message_notes);
             // Make sure we're allowed to view this ticket or message
             if (!isset($active_worker_memberships[$ticket->team_id])) {
                 echo "<H1>" . $translate->_('common.access_denied') . "</H1>";
                 return;
             }
             $tpl->assign('ticket', $ticket);
             $tpl->display('file:' . $this->_TPL_PATH . 'print/ticket.tpl');
             break;
         case 'message':
             @($id = array_shift($stack));
             @($message = DAO_Ticket::getMessage($id));
             @($ticket = DAO_Ticket::getTicket($message->ticket_id));
             // Make sure we're allowed to view this ticket or message
             if (!isset($active_worker_memberships[$ticket->team_id])) {
                 echo "<H1>" . $translate->_('common.access_denied') . "</H1>";
                 return;
             }
             // Message Notes
             $notes = DAO_MessageNote::getByTicketId($ticket->id);
             $message_notes = array();
             // Index notes by message id
             if (is_array($notes)) {
                 foreach ($notes as $note) {
                     if (!isset($message_notes[$note->message_id])) {
                         $message_notes[$note->message_id] = array();
                     }
                     $message_notes[$note->message_id][$note->id] = $note;
                 }
             }
             $tpl->assign('message_notes', $message_notes);
             $tpl->assign('message', $message);
             $tpl->assign('ticket', $ticket);
             $tpl->display('file:' . $this->_TPL_PATH . 'print/message.tpl');
             break;
     }
 }
Esempio n. 2
0
 function showCommentsAction()
 {
     @($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);
     $workers = DAO_Worker::getAll();
     $tpl->assign('workers', $workers);
     $active_workers = DAO_Worker::getAllActive();
     $tpl->assign('active_workers', $active_workers);
     $comments = DAO_TicketComment::getByTicketId($ticket_id);
     arsort($comments);
     $tpl->assign('comments', $comments);
     // Comment parent addresses
     $comment_addresses = array();
     foreach ($comments as $comment) {
         /* @var $comment Model_TicketComment */
         $address_id = intval($comment->address_id);
         if (!isset($comment_addresses[$address_id])) {
             $address = DAO_Address::get($address_id);
             $comment_addresses[$address_id] = $address;
         }
     }
     $tpl->assign('comment_addresses', $comment_addresses);
     $tpl->register_modifier('makehrefs', array('CerberusUtils', 'smarty_modifier_makehrefs'));
     $tpl->display('file:' . $this->_TPL_PATH . 'display/modules/comments/index.tpl');
 }
Esempio n. 3
0
 function showTab()
 {
     $response = DevblocksPlatform::getHttpResponse();
     $path = $response->path;
     array_shift($path);
     // iphone
     array_shift($path);
     // tickets
     array_shift($path);
     // current ('display')
     $id = array_shift($path);
     // ticket id
     @($active_worker = CerberusApplication::getActiveWorker());
     $tpl = DevblocksPlatform::getTemplateService();
     $tpl->assign('path', $this->_TPL_PATH);
     $tpl->assign('expand_all', $expand_all);
     $ticket = DAO_Ticket::getTicket($id);
     $tpl->assign('requesters', $ticket->getRequesters());
     // Drafts
     $drafts = DAO_MailQueue::getWhere(sprintf("%s = %d AND %s = %s", DAO_MailQueue::TICKET_ID, $id, DAO_MailQueue::TYPE, C4_ORMHelper::qstr(Model_MailQueue::TYPE_TICKET_REPLY)));
     if (!empty($drafts)) {
         $tpl->assign('drafts', $drafts);
     }
     // Only unqueued drafts
     $pending_drafts = array();
     if (!empty($drafts) && is_array($drafts)) {
         foreach ($drafts as $draft_id => $draft) {
             if (!$draft->is_queued) {
                 $pending_drafts[$draft_id] = $draft;
             }
         }
     }
     if (!empty($pending_drafts)) {
         $tpl->assign('pending_drafts', $pending_drafts);
     }
     // Messages
     $messages = $ticket->getMessages();
     arsort($messages);
     $tpl->assign('latest_message_id', key($messages));
     $tpl->assign('messages', $messages);
     // Thread comments and messages on the same level
     $convo_timeline = array();
     // Track senders and their orgs
     $message_senders = array();
     $message_sender_orgs = array();
     // Loop messages
     foreach ($messages as $message_id => $message) {
         /* @var $message Model_Message */
         $key = $message->created_date . '_m' . $message_id;
         // build a chrono index of messages
         $convo_timeline[$key] = array('m', $message_id);
         // If we haven't cached this sender address yet
         if (!isset($message_senders[$message->address_id])) {
             if (null != ($sender_addy = DAO_Address::get($message->address_id))) {
                 $message_senders[$sender_addy->id] = $sender_addy;
                 // If we haven't cached this sender org yet
                 if (!isset($message_sender_orgs[$sender_addy->contact_org_id])) {
                     if (null != ($sender_org = DAO_ContactOrg::get($sender_addy->contact_org_id))) {
                         $message_sender_orgs[$sender_org->id] = $sender_org;
                     }
                 }
             }
         }
     }
     $tpl->assign('message_senders', $message_senders);
     $tpl->assign('message_sender_orgs', $message_sender_orgs);
     @($mail_inline_comments = DAO_WorkerPref::get($active_worker->id, 'mail_inline_comments', 1));
     if ($mail_inline_comments) {
         // if inline comments are enabled
         $comments = DAO_TicketComment::getByTicketId($id);
         arsort($comments);
         $tpl->assign('comments', $comments);
         // build a chrono index of comments
         foreach ($comments as $comment_id => $comment) {
             /* @var $comment Model_TicketComment */
             $key = $comment->created . '_c' . $comment_id;
             $convo_timeline[$key] = array('c', $comment_id);
         }
     }
     // Thread drafts into conversation
     if (!empty($drafts)) {
         foreach ($drafts as $draft_id => $draft) {
             /* @var $draft Model_MailQueue */
             $key = $draft->updated . '_d' . $draft_id;
             $convo_timeline[$key] = array('d', $draft_id);
         }
     }
     // sort the timeline
     if (!$expand_all) {
         krsort($convo_timeline);
     } else {
         ksort($convo_timeline);
     }
     $tpl->assign('convo_timeline', $convo_timeline);
     // Message Notes
     $notes = DAO_MessageNote::getByTicketId($id);
     $message_notes = array();
     // Index notes by message id
     if (is_array($notes)) {
         foreach ($notes as $note) {
             if (!isset($message_notes[$note->message_id])) {
                 $message_notes[$note->message_id] = array();
             }
             $message_notes[$note->message_id][$note->id] = $note;
         }
     }
     $tpl->assign('message_notes', $message_notes);
     // Message toolbar items
     $messageToolbarItems = DevblocksPlatform::getExtensions('cerberusweb.message.toolbaritem', true);
     if (!empty($messageToolbarItems)) {
         $tpl->assign('message_toolbaritems', $messageToolbarItems);
     }
     // Workers
     $workers = DAO_Worker::getAll();
     $tpl->assign('workers', $workers);
     $tpl->display('file:' . $this->_TPL_PATH . 'tickets/display/conversation.tpl');
 }