Пример #1
0
 function addmsg()
 {
     $idu = isset($_SESSION['idu']) ? $_SESSION['idu'] : 0;
     $iduser = isset($_POST['iduser']) ? $_POST['iduser'] : 0;
     $message = isset($_POST['message']) ? $_POST['message'] : 0;
     if ($idu > 0 && $iduser > 0 && !empty($message)) {
         $model = new Model_Message();
         $model->createMessage($idu, $iduser, $message);
     }
 }
Пример #2
0
 /**
  * Add message to an existent conversation
  */
 public function replyAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender();
     $request = $this->getRequest();
     $id = $data['thread_id'] = $request->getParam('id');
     $to = $data['user_to'] = $request->getParam('to');
     $lang = $this->lang;
     //first we check if user is logged, if not redir to login
     $auth = Zend_Auth::getInstance();
     if (!$auth->hasIdentity()) {
         //keep this url in zend session to redir after login
         $aNamespace = new Zend_Session_Namespace('Nolotiro');
         $aNamespace->redir = $lang . '/message/reply/' . $id . '/to/' . $to;
         $this->_redirect($lang . '/auth/login');
     }
     if ($request->isPost()) {
         $f_message_reply = new Form_MessageReply();
         if ($f_message_reply->isValid($request->getPost())) {
             // collect data
             $f = new Zend_Filter_StripTags();
             $data['body'] = $f->filter($request->getPost('body'));
             $data['user_from'] = $auth->getIdentity()->id;
             if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
                 $data['ip'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
             } elseif (isset($_SERVER['REMOTE_ADDR'])) {
                 $data['ip'] = $_SERVER['REMOTE_ADDR'];
             }
             // Insert new message in database
             $m_message = new Model_Message();
             $m_message->createMessage($data);
             // Send notification e-mail
             $mail = new Zend_Mail('utf-8');
             $hostname = 'http://' . $this->getRequest()->getHttpHost();
             $username_from = $auth->getIdentity()->username;
             $data['body'] = $data['subject'] . '<br/>' . $data['body'] . '<br/>';
             $data['body'] .= $this->view->translate('Go to this url to reply this message:') . '<br/>
                 <a href="' . $hostname . '/' . $this->lang . '/message/received">' . $hostname . '/' . $this->lang . '/message/received</a>
                 <br>---------<br/>';
             $data['body'] .= $this->view->translate('This is an automated notification. Please, don\'t reply  at this email address.');
             $mail->setBodyHtml($data['body']);
             $mail->setFrom('*****@*****.**', 'nolotiro.org');
             $m_user = new Model_User();
             $object_user = $m_user->fetchUser($data['user_to']);
             $mail->addTo($object_user->email);
             $mail->setSubject('[nolotiro.org] - ' . $this->view->translate('You have a new message from user') . ' ' . $username_from);
             $mail->send();
             // Show flash success notification
             $this->_helper->_flashMessenger->addMessage($this->view->translate('Message sent successfully!'));
         } else {
             // Show flash failure notification
             $this->_helper->_flashMessenger->addMessage($this->view->translate('There was an error sending your message'));
         }
         /* Redirect back to message list.
          * XXX: Do this in a way validation errors are kept. Javascript I
          *      guess */
         $this->_redirect('/' . $this->lang . '/message/show/' . $id);
     }
 }