public function action_message()
 {
     Controller::$full_width = TRUE;
     if ($this->request->param('id') !== NULL and is_numeric($id_msg_thread = $this->request->param('id'))) {
         $messages = Model_Message::get_thread($id_msg_thread, $this->user->id_user);
         if ($messages !== FALSE) {
             $msg_thread = new Model_Message();
             $msg_thread = $msg_thread->where('id_message', '=', $this->request->param('id'))->find();
             // send reply message
             if ($this->request->post() and Form::token('reply_message', TRUE)) {
                 $validation = Validation::factory($this->request->post())->rule('message', 'not_empty');
                 if ($validation->check()) {
                     $ret = Model_Message::reply(core::post('message'), $this->user->id_user, $id_msg_thread, NULL);
                     if ($ret !== FALSE) {
                         //who is who? if from is the same then send to TO, else to from
                         if ($msg_thread->id_user_from == $this->user->id_user) {
                             $user_to = $msg_thread->to;
                             $user_from = $msg_thread->from;
                         } else {
                             $user_to = $msg_thread->from;
                             $user_from = $msg_thread->to;
                         }
                         //email title
                         if ($msg_thread->id_ad !== NULL) {
                             $email_title = $msg_thread->ad->title;
                         } else {
                             $email_title = sprintf(__('Direct message from %s'), $user_from->name);
                         }
                         $user_to->email('messaging-reply', array('[TITLE]' => $email_title, '[DESCRIPTION]' => core::post('message'), '[URL.QL]' => $user_to->ql('oc-panel', array('controller' => 'messages', 'action' => 'message', 'id' => $this->request->param('id')))));
                         Alert::set(Alert::SUCCESS, __('Reply created.'));
                         $this->redirect(Route::url('oc-panel', array('controller' => 'messages', 'action' => 'message', 'id' => Request::current()->param('id'))));
                     } else {
                         Alert::set(Alert::ERROR, __('Message not sent'));
                     }
                 } else {
                     $errors = $validation->errors('message');
                 }
             }
             Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Messaging'))->set_url(Route::url('oc-panel', array('controller' => 'messages', 'action' => 'index'))));
             if ($msg_thread->id_ad !== NULL) {
                 Breadcrumbs::add(Breadcrumb::factory()->set_title($msg_thread->ad->title));
             } else {
                 Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Direct Message')));
             }
             $this->template->styles = array('css/jquery.sceditor.default.theme.min.css' => 'screen');
             $this->template->scripts['footer'] = array('js/jquery.sceditor.bbcode.min.js', 'js/messages.js');
             $this->template->content = View::factory('oc-panel/pages/messages/message', array('msg_thread' => $msg_thread, 'messages' => $messages, 'user' => $this->user));
         } else {
             Alert::set(Alert::ERROR, __('Message not found'));
             $this->redirect(Route::url('oc-panel', array('controller' => 'messages', 'action' => 'index')));
         }
     } else {
         Alert::set(Alert::ERROR, __('Message not found'));
         $this->redirect(Route::url('oc-panel', array('controller' => 'messages', 'action' => 'index')));
     }
 }
Beispiel #2
0
 public function action_message()
 {
     Controller::$full_width = TRUE;
     if ($this->request->param('id') !== NULL and is_numeric($id_msg_thread = $this->request->param('id'))) {
         $messages = Model_Message::get_thread($id_msg_thread, $this->user);
         if ($messages !== FALSE) {
             $msg_thread = new Model_Message();
             $msg_thread = $msg_thread->where('id_message', '=', $id_msg_thread)->where('id_message_parent', '=', $id_msg_thread)->find();
             // send reply message
             if ($this->request->post() and Form::token('reply_message', TRUE)) {
                 $validation = Validation::factory($this->request->post())->rule('message', 'not_empty');
                 if ($validation->check()) {
                     $ret = Model_Message::reply(core::post('message'), $this->user, $id_msg_thread, NULL);
                     if ($ret !== FALSE) {
                         Alert::set(Alert::SUCCESS, __('Reply created.'));
                         $this->redirect(Route::url('oc-panel', array('controller' => 'messages', 'action' => 'message', 'id' => Request::current()->param('id'))));
                     } else {
                         Alert::set(Alert::ERROR, __('Message not sent'));
                     }
                 } else {
                     $errors = $validation->errors('message');
                 }
             }
             Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Messaging'))->set_url(Route::url('oc-panel', array('controller' => 'messages', 'action' => 'index'))));
             if ($msg_thread->id_ad !== NULL) {
                 Breadcrumbs::add(Breadcrumb::factory()->set_title($msg_thread->ad->title));
             } else {
                 Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Direct Message')));
             }
             $this->template->styles = array('css/jquery.sceditor.default.theme.min.css' => 'screen', '//cdn.jsdelivr.net/sweetalert/0.1.2/sweet-alert.min.css' => 'screen');
             $this->template->scripts['footer'] = array('js/jquery.sceditor.bbcode.min.js', '//cdn.jsdelivr.net/sweetalert/0.1.2/sweet-alert.min.js', 'js/messages.js');
             $this->template->content = View::factory('oc-panel/pages/messages/message', array('msg_thread' => $msg_thread, 'messages' => $messages, 'user' => $this->user));
         } else {
             Alert::set(Alert::ERROR, __('Message not found'));
             $this->redirect(Route::url('oc-panel', array('controller' => 'messages', 'action' => 'index')));
         }
     } else {
         Alert::set(Alert::ERROR, __('Message not found'));
         $this->redirect(Route::url('oc-panel', array('controller' => 'messages', 'action' => 'index')));
     }
 }
 /**
  * Handle POST requests for messages
  */
 public function action_create()
 {
     try {
         $user = $this->user;
         //get message
         if (isset($this->_post_params['message'])) {
             $message = $this->_post_params['message'];
         } else {
             $this->_error(__('Message not sent'));
         }
         //price?
         $price = (isset($this->_post_params['price']) and is_numeric($this->_post_params['price'])) ? $this->_post_params['price'] : NULL;
         //message to the user
         if (isset($this->_post_params['id_user']) and is_numeric($id_user_to = $this->_post_params['id_user'])) {
             $ret = Model_Message::send_user($message, $user->id_user, $id_user_to);
         } elseif (isset($this->_post_params['id_ad']) and is_numeric($id_ad = $this->_post_params['id_ad'])) {
             $ret = Model_Message::send_ad($message, $user->id_user, $id_ad, $price);
         } elseif (isset($this->_post_params['id_message_parent']) and is_numeric($id_message_parent = $this->_post_params['id_message_parent'])) {
             $ret = Model_Message::reply($message, $user->id_user, $id_message_parent, $price);
         }
         //good response!
         if ($ret !== FALSE) {
             $this->rest_output(array('message' => $ret->as_array()));
         } else {
             $this->_error(__('Message not sent'));
         }
     } catch (Kohana_HTTP_Exception $khe) {
         $this->_error($khe);
     }
 }