<?php 
class TuitionsController extends AppController{
	var $name="Tuitions";
	var $uses=array('Tuition');
	var $helpers = array('Form', 'Html', 'Text','Javascript', 'Time', 'Number','Paginator','Cache','Ajax', 'Session');
	var $components=array('RequestHandler','ImageHandler','Session');
	
function index() {
		
	}
	
	
	
//MAIN CATEGORIES SECTION STARTS HERE	
function viewTuitions(){
		$this->paginate['limit'] = 50;
   		$this->paginate['order'] = array('date' => 'desc');
   		$this->paginate['fields'] = array('title','date','id');
		$this->set('main_categories', $this->paginate('Tuition'));
		$this->render('viewAllTuitions');
		
	}
function viewTuitionsDetails($id=null){
	$data=$this->Tuition->find('all',array('conditions'=>array('Tuition.id'=>$id)));
	
	$this->set(compact('data'));	
	
}

		
		function addTuition() {		
		if((isset($this->data['Tuition']['image']))&&($this->data['Tuition']['image']['size']!=0) &&($this->data['Tuition']['image']['size']>2103361)){
		 		$this->data['Tuition']['image']='';
				$this->Session->setFlash('Maximum file size exceeded.');
				$this->redirect(array('action' => 'addMainCategory'));
		}		
		if (!empty($this->data)) {				
		  	$data=$this->data;  
			$image_path = $this->ImageHandler->upload_image_and_thumbnail($data['Tuition']['image']);
			$image = $image_path['dir'].$image_path['img_folder'].$image_path['img_file'].".". $image_path['type'];
			$data['Tuition']['image'] = $image;
			if ($this->Tuition->save($data)) {
				$this->Session->setFlash('Saved Successfully.');
				$this->redirect('/Tuitions/viewTuitions');
		  }
		else if($this->data['Tuition']['image']['size']>2103361)		
				{
				 $this->data['Tuition']['image']='';
				 $this->Session->setFlash('Maximum file size exceeded.');
				$this->redirect(array('action' => 'addTuition'));
				}		
		      }
	    }
	
	
function editTuitions($id=null){		
	if(empty($this->data)){
		$current_image=$this->Tuition->find('all',array('conditions'=>array('id'=>$id)));		
		$current_image=$current_image[0]['Tuition']['image'];		
		$this->set(compact('current_image'));
		$data=$this->Tuition->find('all',array('conditions'=>array('id'=>$id)));
		$this->data=$data[0];
	}	
	elseif(!empty($this->data)){
		$data=$this->data;
		$current_image=$this->Tuition->find('all',array('conditions'=>array('id'=>$data['Tuition']['id'])));		
		$current_image=$current_image[0]['Tuition']['image'];
		$this->set(compact('current_image'));
			
		if(array_key_exists('remove',$data['Tuition'])){
		
				if($data['Tuition']['remove']==0){
				$data['Tuition']['image']=$current_image;}
				
				elseif($data['Tuition']['remove']!=0){
				$data['Tuition']['image']='';}
		}
			if(($this->data['Tuition']['image']['size']!=0) &&($this->data['Tuition']['image']['size']<=2103361)) 
		  {			 
		  	$data=$this->data;  
			$image_path = $this->ImageHandler->upload_image_and_thumbnail($data['Tuition']['image']);
			$image = $image_path['dir'].$image_path['img_folder'].$image_path['img_file'].".". $image_path['type'];
			$data['Tuition']['image'] = $image;
			}
		   else if($this->data['Tuition']['image']['size']>2103361) {
		    $this->Session->setFlash('Maximum file size exceeded.');		
			$this->redirect('/Tuitions/editTuitions/'.$this->data['Tuition']['id']);
		}
		
			
										
			if($this->Tuition->save($data)){	
			$this->Session->setFlash('Updated Successfully.');				
			$this->redirect('/Tuitions/viewTuitionsDetails/'.$this->data['Tuition']['id']);
			}
	}
	}
	
	
	function ProgramsEditResponse(){
		
		
	}

function viewEnabledTuitions(){
		$this->paginate['limit'] = 50;
   		$this->paginate['order'] = array('date' => 'desc');
   		$this->paginate['fields'] = array('title','date','id');
   		$this->set('main_categories', $this->paginate('Tuition'));
		$this->render('viewTuitions');
		
	}
	
function viewDisabledTuitions(){
		$this->paginate['limit'] = 50;
   		$this->paginate['order'] = array('date' => 'desc');
   		$this->paginate['fields'] = array('title','date','id');
   		$this->set('main_categories', $this->paginate('Tuition'));
		$this->render('viewTuitions');
		
	}
	
		
function enableTuition($id=null){
	$this->Tuition->updateAll(array('status'=>'1'),array('id'=>$id));
	$this->paginate['limit'] = 50;
   	$this->paginate['order'] = array('date' => 'desc');
	$this->set('main_categories', $this->paginate('Tuition'));
   	//$this->render('viewPrograms');
	$this->redirect('/Tuitions/viewDisabledTuitions');
}

function enableTuitions($id=null){
	$this->Tuition->updateAll(array('status'=>'1'),array('id'=>$id));
	$this->paginate['limit'] = 50;
   	$this->paginate['order'] = array('date' => 'desc');
	$this->set('main_categories', $this->paginate('Tuition'));
	$this->redirect('/Tuitions/viewTuitions');
}

function disableTuition($id=null){
	$this->Tuition->updateAll(array('status'=>'0'),array('id'=>$id));
	$this->paginate['limit'] = 50;
   	$this->paginate['order'] = array('date' => 'desc');
	$this->set('main_categories', $this->paginate('Tuition'));
	$this->redirect('/Tuitions/viewEnabledTutions');
}

function disableTuitions($id=null){
	$this->Tuition->updateAll(array('status'=>'0'),array('id'=>$id));
	$this->paginate['limit'] = 50;
   	$this->paginate['order'] = array('date' => 'desc');
	$this->set('main_categories', $this->paginate('Tuition'));
	$this->redirect('/Tuitions/viewTutions');

}



//MAIN CATEGORY SECTION ENDS HERE


}
?>