Ejemplo n.º 1
0
 public function addReply()
 {
     $msgId = JRequest::getVar('msgid', '', 'POST');
     $reply = JRequest::getVar('reply', '', 'POST');
     $attachment = JRequest::getVar('attachment', array(), 'POST', 'array');
     $my = JXFactory::getUser();
     $messagingModel = MessagingFactory::getModel('inbox');
     $message = $messagingModel->getMessage($msgId);
     if ($my->id == 0) {
         return;
     }
     $now = new JDate();
     $obj = new stdClass();
     $obj->id = null;
     $obj->from = $my->id;
     $obj->posted_on = $now->toMySQL();
     $obj->from_name = $my->name;
     $obj->subject = 'RE:' . $message->subject;
     $obj->body = $reply;
     $obj->attachment = implode(', ', $attachment);
     $messagingModel->sendReply($obj, $msgId);
     $deleteLink = JRoute::_('index.php?option=com_community&view=inbox&task=remove&msgid=' . $obj->id);
     $authorLink = JRoute::_('index.php?option=com_community&view=profile&userid=' . $my->id);
     $this->_addAttachments($obj->id);
     $attachments = $messagingModel->getAttachments($obj);
     $tmpl = new MessagingTemplate();
     $tmpl->set('user', JXFactory::getUser($obj->from));
     $tmpl->set('msg', $obj);
     $tmpl->set('removeLink', $deleteLink);
     $tmpl->set('authorLink', $authorLink);
     $tmpl->set('attachments', $attachments);
     $html = $tmpl->fetch('inbox.message');
     $data = array();
     $data['html'] = $html;
     header('Content-Type: text/json');
     echo json_encode($data);
     exit;
 }