Ejemplo n.º 1
0
 public function action_to($id = null)
 {
     // redirect if no id
     if ($id == null) {
         Response::redirect('message');
     }
     // redirect if no right access
     if (!Sentry::user()->has_access('message_send')) {
         Session::set_flash('error', "You are not allowed to send message");
         Response::redirect('');
     }
     $data['user'] = Sentry::user(intval($id));
     $data['messages'] = Model_Message::messageWith($data['user'], $this->current_user);
     if (Input::method() == 'POST') {
         $message = Model_Message::forge(array('subject' => Input::post('subject'), 'content' => Input::post('content'), 'to' => $data['user']->id, 'from' => $this->current_user->id, 'parent_id' => '', 'read' => 0, 'from_delete' => 0, 'to_delete' => 0));
         if ($message and $message->save()) {
             Session::set_flash('success', 'Message successfuly sent to ' . $data['user']->username);
             Response::redirect('message');
         } else {
             Session::set_flash('error', 'Could not send the message.');
         }
     }
     $this->template->h2 = 'Send Message to ' . $data['user']->username;
     $this->template->title = 'Message » to';
     $this->template->content = View::forge('message/to', $data);
 }
Ejemplo n.º 2
0
 public function action_create()
 {
     if (Input::method() == 'POST') {
         $val = Model_Message::validate('create');
         if ($val->run()) {
             $message = Model_Message::forge(array('name' => Auth::instance()->get_screen_name(), 'message' => Input::post('message')));
             if ($message and $message->save()) {
                 Session::set_flash('success', 'Added message #' . $message->id . '.');
                 Response::redirect('messages');
             } else {
                 Session::set_flash('error', 'Could not save message.');
             }
         } else {
             Session::set_flash('error', $val->error());
         }
     }
     $this->template->title = "Messages";
     $this->template->content = View::forge('messages/create');
 }