<?php
class MailsController extends AppController{
var $name = 'Mails';
var $uses = array('Mail','Member');
var $helpers = array('Form', 'Html', 'Text','Javascript', 'Time', 'Number','Paginator','Cache','Ajax', 'Session');
var $components=array('RequestHandler');

function viewMails(){
	
		$this->paginate['limit'] = 50;
   		$this->paginate['order'] = array('date' => 'desc');
   		//$this->paginate['fields'] = array('branch_name','status','id','date');
		$this->set('locations', $this->paginate('Mail'));
}
function viewMailDetails($id){
	$data=$this->Mail->find('all',array('conditions'=>array('id'=>$id)));
	$this->set('locations',$data);
}

function compose(){
		
		if(!empty($this->data)){
			
			if($this->Mail->validates()){
				if($this->Mail->save($this->data)){
				$contacts = $this->Member->find('all');
				foreach($contacts as $contacts){
				$from = 'info@swesconiansgh.com';
    		$to = $contacts['Member']['email'];
    		$message = $this->data['Mail']['message'];
			$this->Email->from    = $from;
			$this->Email->to      = $to;
			$this->Email->subject = $this->data['Mail']['subject'];
			$this->Email->send($message);
				}
					
					$this->redirect('/Mails/viewMails');
					
				}
				
				
			}

		}
		
		
	}


}
?>