| 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 | } |
| 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 | { |
| 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 | { |