Changeset 488 for trunk/app/controllers/messages_controller.php
- Timestamp:
- 05/14/08 14:52:22 (8 months ago)
- Files:
-
- 1 modified
-
trunk/app/controllers/messages_controller.php (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/app/controllers/messages_controller.php
r487 r488 12 12 public $helpers = array('Javascript', 'Ajax', 'Fck', 'Time', 'Gags'); 13 13 14 public $components = array('Portal', ' Security', 'Email', 'Session', 'Edublog', 'Autocomplete');14 public $components = array('Portal', 'Email', 'Session', 'Edublog'); 15 15 16 16 public function beforeFilter() 17 17 { 18 $this->Auth->allow(array('message', 'deliver', 'listing', 'compose', 'display', 'add', 'send', 'autocomplete')); 19 parent::beforeFilter(); 18 if ( $this->Auth->user() ): 19 $this->Auth->allow(array('message','deliver','listing','compose','display','add','send','autocomplete','sentmessages')); 20 else: 21 $this->redirect('/users/login'); 22 return false; 23 endif; 24 parent::beforeFilter(); 20 25 } 21 26 … … 36 41 $this->pageTitle = 'Contact'; 37 42 38 $user_id = $this->Message->User->field('id', array('username'=>$username));43 $user_id = $this->Message->User->field('id', array('username'=>$username)); 39 44 40 45 $this->layout = $this->Edublog->layout($user_id); … … 72 77 public function deliver() 73 78 { 74 $this->layout = 'ajax'; 75 76 if (!empty($this->data["Message"])) 77 { 79 80 if (!empty($this->data['Message'])): 81 78 82 $this->Sanitize = new Sanitize; 79 83 80 $this->Sanitize->html($this->data["Message"]["title"]); 81 82 $this->Sanitize->html($this->data["Message"]["body"]); 83 84 $this->Sanitize->html($this->data['Message']['title']); 85 86 $this->Sanitize->html($this->data['Message']['body']); 87 88 $this->data['Message']['sender'] = $this->Auth->user('id'); 89 $this->data['Message']['username'] = $this->Auth->user('username'); 90 91 $user_id = $this->Message->User->field('User.id', array('User.username'=>trim($this->data['Message']['sendern']))); 92 93 $this->data['Message']['user_id'] = $user_id; 94 95 //die(debug($this->data['Message'])); 96 84 97 $this->Message->create(); 85 98 86 if ($this->Message->save($this->data["Message"])): 87 88 $this->__sendMail($this->data["Message"]["user_id"], $this->data["Message"]["username"], $this->data["Message"]["title"]); 89 90 if ( isset($this->data["Message"]["admin"])): 91 $this->render('sentadmin','ajax'); 92 else: 93 $this->render('sent', 'ajax'); 94 endif; 95 endif; 96 } 99 if ( $this->Message->save($this->data['Message']) ): 100 $this->__sendMail($user_id); 101 $this->msgFlash('Message sent', '/messages/listing'); 102 endif; 103 endif; 97 104 } 98 105 99 106 public function listing() 100 107 { 101 if ( !$this->Auth->user() ):102 $this->redirect('/users/login');103 return false;104 endif;105 106 108 $this->layout = 'portal'; 107 109 … … 112 114 $this->Portal->statics(); // Charge Portal components aka Sidebars 113 115 } 116 117 public function sentmessages() 118 { 119 $this->layout = 'portal'; 120 121 $this->pageTitle = 'Messages'; 122 123 $this->set('data', $this->Message->sentmessages($this->Auth->user('id'))); 124 125 $this->Portal->statics(); // Charge Portal components aka Sidebars 126 } 114 127 115 128 public function autocomplete() … … 117 130 //Partial strings will come from the autocomplete field as 118 131 //$this->data['Post']['subject'] 119 132 $fields = array('id', 'username'); 133 $this->Message->User->unbindAll(); 134 $data = $this->Message->User->findAll("username LIKE 'aa%'", $fields); 135 //die(debug($data)); 120 136 $this->set('users', $this->Message->User->findAll("username LIKE '{$this->data['Message']['sendern']}%'")); 121 137 … … 152 168 public function display($message_id) 153 169 { 154 155 if ( !$this->Auth->user() ):156 $this->redirect('/users/login');157 return false;158 endif;159 160 170 $this->layout = 'portal'; 161 171 … … 165 175 166 176 $this->Portal->statics(); // Charge Portal components aka Sidebars 167 }177 } 168 178 169 179 /* == PRIVATE == **/ … … 336 346 $this->set('admin_reply', 'ajax'); 337 347 } 348 349 public function admin_deliver() 350 { 351 $this->layout = 'ajax'; 352 353 if (!empty($this->data["Message"])): 354 355 $this->Sanitize = new Sanitize; 356 357 $this->Sanitize->html($this->data["Message"]["title"]); 358 359 $this->Sanitize->html($this->data["Message"]["body"]); 360 361 $this->Message->create(); 362 363 if ($this->Message->save($this->data["Message"])): 364 $this->__sendMail($this->data["Message"]["user_id"]); 365 endif; 366 endif; 367 } 338 368 339 369 public function admin_add() … … 416 446 } 417 447 418 public function admin_deliver() 419 { 420 if (!empty($this->data['Message'])) 421 { 422 $this->Sanitize = new Sanitize; 423 424 $this->Sanitize->html($this->data['Message']['title']); 425 426 $this->Sanitize->html($this->data['Message']['body']); 427 428 $this->data['Message']['sender'] = $this->Auth->user('id'); 429 //die(debug($this->data)); 430 $this->Message->create(); 431 432 if ($this->Message->save($this->data['Message'])) 433 { 434 $email = $this->Message->User->field('email', array('id'=>$this->data['Message']['user_id'])); 435 if ( $this->__sendMail($email) ) 436 { 437 $this->msgFlash('Message sent','/admin/messages/listing'); 438 } 439 } 440 } 441 } 442 443 private function _sendMessage($email, $vclassroom_id) 448 private function __sendMessage($email, $vclassroom_id) 444 449 { 445 450 $this->layout = 'message_class'; … … 468 473 } 469 474 475 /* 476 * Delete one or several messages 477 * 478 */ 470 479 public function admin_delete($id=null) 471 480 { 472 if ( isset($this->data['Message']['several']) ) 473 { 474 //exit(print_r($this->data['Message']["id"])); 475 foreach ($this->data['Message']['id'] as $v) 476 { 477 if ( $v != 0) 478 { 481 if ( isset($this->data['Message']['several']) ): 482 //exit(debug($this->data['Message']["id"])); 483 foreach ($this->data['Message']['id'] as $v): 484 if ( $v != 0): 479 485 $this->Message->del($v); 480 }481 }486 endif; 487 endforeach; 482 488 483 $this->msgFlash('The message has been deleted.','/admin/messages/listing'); 484 } 485 else 486 { 489 $this->msgFlash('The message has been deleted.','/admin/messages/listing'); 490 491 else: 487 492 if ( isset( $this->data['Message']['id'] ) ): 488 493 $id = $this->data['Message']['id']; … … 490 495 491 496 $this->Message->del($id); 492 } 493 $this->msgFlash('Message has been deleted.','/admin/messages/listing'); 494 } 497 498 $this->msgFlash('Message has been deleted.','/admin/messages/listing'); 499 endif; 500 } 495 501 } 496 502 ?>
