Show
Ignore:
Timestamp:
05/14/08 14:52:22 (8 months ago)
Author:
aarkerio
Message:

Message interfase

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/app/controllers/messages_controller.php

    r487 r488  
    1212 public $helpers       = array('Javascript', 'Ajax', 'Fck', 'Time', 'Gags'); 
    1313  
    14  public $components    = array('Portal', 'Security', 'Email', 'Session', 'Edublog', 'Autocomplete'); 
     14 public $components    = array('Portal', 'Email', 'Session', 'Edublog'); 
    1515  
    1616 public function beforeFilter()  
    1717 { 
    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(); 
    2025 } 
    2126 
     
    3641        $this->pageTitle = 'Contact'; 
    3742         
    38         $user_id = $this->Message->User->field('id', array('username'=>$username)); 
     43    $user_id = $this->Message->User->field('id', array('username'=>$username)); 
    3944         
    4045        $this->layout    = $this->Edublog->layout($user_id); 
     
    7277 public function deliver() 
    7378 { 
    74     $this->layout = 'ajax'; 
    75      
    76     if (!empty($this->data["Message"])) 
    77     { 
     79     
     80    if (!empty($this->data['Message'])): 
     81       
    7882           $this->Sanitize = new Sanitize; 
    7983            
    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 
    8497           $this->Message->create(); 
    8598            
    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; 
    97104 } 
    98105 
    99106 public function listing() 
    100107 { 
    101    if ( !$this->Auth->user() ): 
    102          $this->redirect('/users/login'); 
    103          return false;         
    104    endif; 
    105  
    106108   $this->layout    = 'portal'; 
    107109       
     
    112114   $this->Portal->statics(); // Charge Portal components aka Sidebars 
    113115 } 
     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 } 
    114127 
    115128 public function autocomplete() 
     
    117130    //Partial strings will come from the autocomplete field as 
    118131    //$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)); 
    120136    $this->set('users',  $this->Message->User->findAll("username LIKE '{$this->data['Message']['sendern']}%'")); 
    121137      
     
    152168 public function display($message_id) 
    153169 { 
    154  
    155    if ( !$this->Auth->user() ): 
    156          $this->redirect('/users/login'); 
    157          return false;         
    158    endif; 
    159  
    160170   $this->layout    = 'portal'; 
    161171 
     
    165175 
    166176   $this->Portal->statics(); // Charge Portal components aka Sidebars 
    167   } 
     177 } 
    168178 
    169179  /* == PRIVATE == **/ 
     
    336346    $this->set('admin_reply', 'ajax'); 
    337347 } 
     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 } 
    338368  
    339369 public function admin_add() 
     
    416446 } 
    417447 
    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) 
    444449 {    
    445450  $this->layout          = 'message_class'; 
     
    468473 } 
    469474 
     475/*   
     476 *  Delete one or several messages 
     477 *   
     478 */ 
    470479 public function admin_delete($id=null) 
    471480 { 
    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): 
    479485                    $this->Message->del($v); 
    480                } 
    481             } 
     486         endif; 
     487     endforeach; 
    482488             
    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: 
    487492          if ( isset( $this->data['Message']['id'] ) ): 
    488493               $id = $this->data['Message']['id']; 
     
    490495            
    491496       $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 } 
    495501} 
    496502?>