<?php 
	App::uses('AppController','Controller');
	App::uses('CakeEmail','Network/Email');
	class ContactsController extends AppController{
		public $name = 'Contacts';
		public $components = array('RequestHandler','Session','Email');
		public $uses = array('Contact','News');
		
		
		public function index(){
			$new = $this->News->find('all', array('conditions'=>array('status'=>'1'), 'limit'=>'3', 'order'=>'id desc'));
			$this->set(compact('new'));
			//debug($new);exit;
			
		}
		
		
		
		public function send_message(){
			if($this->request->is('post')){
				if(!empty($this->request->data)){
					$name = $this->request->data['Contact']['name'];
					$email = $this->request->data['Contact']['email_address'];
					$tel = $this->request->data['Contact']['phone_number'];
					$msg = $this->request->data['Contact']['message'];
					$body = "";
					$body .= "Name: ";
					$body .= $name;
					$body .= "\n\n";

					$body .= "email: ";
					$body .= $email;
					$body .= "\n\n";

					$body .= "Phone Number: ";
					$body .= $tel;
					$body .= "\n\n";

					$body .= "Message: ";
					$body .= $msg;
					$body .= "\n";
					
					$Email = new CakeEmail();
					$Email->to('studentsupport@aobs.org.uk');
					$Email->from($email);
					$Email->subject('AOBS Student Enquiry');
					$Email->send($body);
					
					if($this->Contact->save($this->request->data)){
						$this->Session->setFlash('<span id="valid"><i class="icon icon-check"></i>Your Email was sent!</span>');
						$this->redirect($this->referer());
						
					}else{
						$this->Session->setFlash('<span id="invalid">Invalid Email, please provide a correct email.</span>');
						$this->redirect($this->referer());
						
					}
				}
				
				
			}
			
			
		}
		
		
	}




?>