示例#1
0
 public function replyAction()
 {
     $ticket = $this->getDi()->helpdeskTicketTable->load($this->getParam('ticket'));
     if (!$this->strategy->canEditTicket($ticket)) {
         throw new Am_Exception_AccessDenied(___('Access Denied'));
     }
     $message = null;
     $type = $this->getParam('type', 'message');
     if ($message_id = $this->getDi()->app->reveal($this->getParam('message_id'))) {
         $message = $this->getDi()->helpdeskMessageTable->load($message_id);
         switch ($type) {
             case 'message':
                 if (!$this->strategy->canViewMessage($message)) {
                     throw new Am_Exception_AccessDenied(___('Access Denied'));
                 }
                 break;
             case 'comment':
                 if (!$this->strategy->canEditMessage($message)) {
                     throw new Am_Exception_AccessDenied(___('Access Denied'));
                 }
                 break;
             default:
                 throw new Am_Exception_InputError('Unknown message type : ' . $type);
         }
     }
     /* @var $replyForm Am_Form */
     $replyForm = $this->getReplyForm($this->getParam('ticket'), $message, $type);
     if ($this->isPost()) {
         $replyForm->setDataSources(array($this->getRequest()));
         $values = $replyForm->getValue();
         $message_id = $this->getParam('message_id', null);
         $message_id = $message_id ? $this->getDi()->app->reveal($message_id) : $message_id;
         $this->reply($ticket, $message_id, $values);
         $this->getRequest()->set('ticket', $ticket->ticket_mask);
         return $this->redirectTicket($ticket);
     }
     $content = (string) $replyForm;
     if ($this->isAjax()) {
         header('Content-type: text/html; charset=UTF-8');
         echo $content;
     } else {
         $this->view->assign('content', $content);
         $this->view->display($this->strategy->getTemplatePath() . '/index.phtml');
     }
 }
示例#2
0
 private function getReplyForm($ticket_id, $message = null, $type = 'message')
 {
     $content = '';
     $hiddens = '';
     if (!is_null($message) && $type == 'message') {
         $content = explode("\n", $message->content);
         $content = array_map(create_function('$v', 'return \'>\'.$v;'), $content);
         $content = "\n\n" . implode("\n", $content);
     } elseif (!is_null($message) && $type == 'comment') {
         $content = $message->content;
         $hiddens .= sprintf('<input type="hidden" name="message_id" value="%d" />', $message->message_id);
     }
     $t = new Am_View();
     $t->assign('content', $content);
     $t->assign('type', $type);
     $t->assign('hiddens', $hiddens);
     $t->assign('ticket_id', $ticket_id);
     return $t->display($this->strategy->getTemplatePath() . '/_reply-form.phtml');
 }