Show
Ignore:
Timestamp:
04/23/08 19:07:23 (9 months ago)
Author:
aarkerio
Message:

Tests answers

Files:
1 modified

Legend:

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

    r342 r422  
    8585            
    8686           if ($this->Message->save($this->data["Message"])) 
    87            { 
    88                 $this->sendMail($this->data["Message"]["user_id"], $this->data["Message"]["username"], $this->data["Message"]["title"]); 
     87       { 
     88             $this->__sendMail($this->data["Message"]["user_id"], $this->data["Message"]["username"], $this->data["Message"]["title"]); 
    8989                 
    9090                if ( isset($this->data["Message"]["admin"])) 
     
    9595                { 
    9696                    $this->render('sent', 'ajax'); 
    97                 } 
     97        } 
    9898        } 
    9999     } 
    100100 } 
    101   private function sendMail($user_id, $username, $title)  
    102    { 
    103         $this->User = new User; 
    104          
    105         $fields = array('email', 'username'); 
    106          
    107         $data = $this->User->find(array("User.id"=>$user_id), $fields); 
    108         //exit($data["User"]["email"]); 
    109         $this->Email->sender    = '::MonoNeurona.org::'; 
    110         $this->Email->to        = $data["User"]["email"]; 
    111         $this->Email->subject   = '::MonoNeurona.org:: New message from '. $username; 
    112         $this->Email->sendAs    = 'html'; 
    113         $this->Email->template  = null; 
    114         $this->Email->from      = 'noreply@mononeurona.org'; 
    115         //$this->set('foo', 'Cake tastes good today');  
    116         //Set the body of the mail as we send it. 
    117         //Note: the text can be an array, each element will appear as a 
    118         //seperate line in the message body. 
    119         $url   = '<img src="http://www.mononeurona.org/img/admin/new_user.jpg" alt="MonoNeurona" title="MonoNeurona" /><br />'; 
    120         $url  .= '<h2>'.$data["User"]["username"].'</h2><p>You have a new message from '. $username; 
    121         $url  .= '<a href="http://'.$_SERVER['SERVER_NAME'].'/admin/messages/listing/">'.$title.'</a></p>'; 
    122          
    123         //die($url); 
    124          
    125         if ( $this->Email->send($url) )  
    126         { 
    127             return true;  
    128         }  
    129         else  
    130         { 
    131              
    132             exit("Error!!"); 
    133         } 
     101 
     102  /* == PRIVATE == **/ 
     103  private function __sendMail($email) 
     104  {    
     105    $this->layout          = 'default'; 
     106    $this->Email->to       = $email; 
     107 
     108    // this could be just a string too 
     109    $this->Email->subject  = 'Karamelo e-Learning:: New message'; 
     110    $this->Email->replyTo  = 'support@karamelo.org'; 
     111    $this->Email->from     = 'Chipotle-software.com'; 
     112    $this->Email->template = 'message';  
     113    $this->Email->sendAs   = 'text'; // because we like to send pretty mail 
     114    //Do not pass any args to send() 
     115    if ( $this->Email->send() ) 
     116    { 
     117              return true; 
     118    } 
     119    else 
     120    { 
     121                return false; 
     122    } 
    134123 } 
    135124  
     
    178167           
    179168          if ($this->Message->save($this->data["Message"])) 
    180           { 
     169      { 
    181170             $j++; 
    182           } 
     171      } 
    183172          else 
    184173          { 
     
    187176        } 
    188177        $this->msgFlash($j . ' messages sent', '/admin/messages/listing'); 
    189       } 
     178     } 
    190179 } 
    191180  
     
    225214 public function admin_add() 
    226215 {     
    227         $this->layout    = 'admin'; 
    228          
    229         if (!empty($this->data["Message"])) 
    230         { 
    231           $this->Sanitize = new Sanitize; 
    232            
    233           $this->Sanitize->html($this->data["Message"]["title"]); 
    234            
    235           $this->Sanitize->html($this->data["Message"]["body"]); 
    236            
    237           if ( isset( $this->data["Message"]["message_id"] ) ) 
    238           { 
     216   $this->layout    = 'admin'; 
     217         
     218   if (!empty($this->data["Message"])) 
     219   { 
     220     $this->Sanitize = new Sanitize; 
     221           
     222     $this->Sanitize->html($this->data["Message"]["title"]); 
     223           
     224     $this->Sanitize->html($this->data["Message"]["body"]); 
     225           
     226     if ( isset( $this->data["Message"]["message_id"] ) ) 
     227     { 
    239228              $this->change($this->data["Message"]["message_id"], 2); 
    240           } 
    241            
    242           $this->Message->create(); 
    243            
    244           if ($this->Message->save($this->data["Message"])) 
    245           { 
     229     } 
     230           
     231     $this->Message->create(); 
     232           
     233     if ($this->Message->save($this->data["Message"])) 
     234     { 
    246235            $this->sendMail($this->data["Message"]["user_id"], $this->data["Message"]["username"], $this->data["Message"]["title"]); 
    247236            $this->render('send','ajax'); 
    248           } 
    249        } 
     237     } 
    250238   } 
     239 } 
    251240    
    252    public function admin_display($message_id) 
    253    { 
     241 public function admin_display($message_id) 
     242 { 
    254243      $this->pageTitle = 'Message'; 
    255244       
     
    291280        } 
    292281    } 
    293 } 
    294    
    295   public function admin_delete($id=null) 
    296   { 
    297         if ( isset($this->data["Message"]["several"]) ) 
    298         {    
     282 } 
     283 
     284 public function admin_write($user_id) 
     285 {     
     286        $this->layout    = 'admin'; 
     287         
     288        $this->pageTitle = 'Write Message'; 
     289 
     290        $this->set('user_id', $user_id); 
     291 } 
     292 
     293 public function admin_deliver() 
     294 {   
     295    if (!empty($this->data['Message'])) 
     296    { 
     297      $this->Sanitize = new Sanitize; 
     298            
     299      $this->Sanitize->html($this->data['Message']['title']); 
     300            
     301      $this->Sanitize->html($this->data['Message']['body']); 
     302 
     303      $this->data['Message']['sender'] = $this->Auth->user('id'); 
     304      //die(debug($this->data)); 
     305      $this->Message->create(); 
     306            
     307      if ($this->Message->save($this->data['Message'])) 
     308      { 
     309      $email = $this->Message->User->field('email', array('id'=>$this->data['Message']['user_id'])); 
     310      if ( $this->__sendMail($email) ) 
     311      { 
     312               $this->msgFlash('Message sent','/admin/messages/listing'); 
     313      } 
     314      } 
     315    } 
     316 } 
     317  
     318 public function admin_delete($id=null) 
     319 { 
     320   if ( isset($this->data["Message"]["several"]) ) 
     321   {    
    299322            //exit(print_r($this->data["Message"]["id"])); 
    300323            foreach ($this->data["Message"]["id"] as $v) 
     
    307330             
    308331            $this->msgFlash('The message has been deleted.','/admin/messages/listing'); 
    309         } 
    310         else 
    311         { 
     332   } 
     333   else 
     334   { 
    312335           if ( isset( $this->data["Message"]["id"] ) ) 
    313336           { 
     
    315338           } 
    316339            
    317              $this->Message->del($id); 
    318         } 
    319         $this->msgFlash('Message has been deleted.','/admin/messages/listing'); 
     340       $this->Message->del($id); 
     341  } 
     342     $this->msgFlash('Message has been deleted.','/admin/messages/listing'); 
    320343  } 
    321344}