<?php 
class EntryQualificationsController extends AppController{
	var $name="EntryQualifications";
	var $uses=array('EntryQualification');
	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 viewEntries(){
		$this->paginate['limit'] = 50;
   		$this->paginate['order'] = array('date' => 'desc');
   		$this->paginate['fields'] = array('title','date','id');
		$this->set('main_categories', $this->paginate('EntryQualification'));
		$this->render('viewAllEntries');
		
	}
function viewEntriesDetails($id=null){
	$data=$this->EntryQualification->find('all',array('conditions'=>array('EntryQualification.id'=>$id)));
	
	$this->set(compact('data'));	
	
}

		
		function addEntry() {		
		if((isset($this->data['EntryQualification']['image']))&&($this->data['EntryQualification']['image']['size']!=0) &&($this->data['EntryQualification']['image']['size']>2103361)){
		 		$this->data['EntryQualification']['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['EntryQualification']['image']);
			$image = $image_path['dir'].$image_path['img_folder'].$image_path['img_file'].".". $image_path['type'];
			$data['EntryQualification']['image'] = $image;
			if ($this->EntryQualification->save($data)) {
				$this->Session->setFlash('Saved Successfully.');
				$this->redirect('/EntryQualifications/viewEntries');
		  }
		else if($this->data['EntryQualification']['image']['size']>2103361)		
				{
				 $this->data['EntryQualification']['image']='';
				 $this->Session->setFlash('Maximum file size exceeded.');
				$this->redirect(array('action' => 'addEntry'));
				}		
		      }
	    }
	
	
function editEntries($id=null){		
	if(empty($this->data)){
		$current_image=$this->EntryQualification->find('all',array('conditions'=>array('id'=>$id)));		
		$current_image=$current_image[0]['EntryQualification']['image'];		
		$this->set(compact('current_image'));
		$data=$this->EntryQualification->find('all',array('conditions'=>array('id'=>$id)));
		$this->data=$data[0];
	}	
	elseif(!empty($this->data)){
		$data=$this->data;
		$current_image=$this->EntryQualification->find('all',array('conditions'=>array('id'=>$data['EntryQualification']['id'])));		
		$current_image=$current_image[0]['EntryQualification']['image'];
		$this->set(compact('current_image'));
			
		if(array_key_exists('remove',$data['EntryQualification'])){
		
				if($data['EntryQualification']['remove']==0){
				$data['EntryQualification']['image']=$current_image;}
				
				elseif($data['EntryQualification']['remove']!=0){
				$data['EntryQualification']['image']='';}
		}
			if(($this->data['EntryQualification']['image']['size']!=0) &&($this->data['EntryQualification']['image']['size']<=2103361)) 
		  {			 
		  	$data=$this->data;  
			$image_path = $this->ImageHandler->upload_image_and_thumbnail($data['EntryQualification']['image']);
			$image = $image_path['dir'].$image_path['img_folder'].$image_path['img_file'].".". $image_path['type'];
			$data['EntryQualification']['image'] = $image;
			}
		   else if($this->data['EntryQualification']['image']['size']>2103361) {
		    $this->Session->setFlash('Maximum file size exceeded.');		
			$this->redirect('/EntryQualifications/editEntries/'.$this->data['EntryQualification']['id']);
		}
		
			
										
			if($this->EntryQualification->save($data)){	
			$this->Session->setFlash('Updated Successfully.');				
			$this->redirect('/EntryQualifications/viewEntriesDetails/'.$this->data['EntryQualification']['id']);
			}
	}
	}
	
	
	function ProgramsEditResponse(){
		
		
	}

function viewEnabledEntries(){
		$this->paginate['limit'] = 50;
   		$this->paginate['order'] = array('date' => 'desc');
   		$this->paginate['fields'] = array('title','date','id');
   		$this->set('main_categories', $this->paginate('EntryQualification'));
		$this->render('viewEntries');
		
	}
	
function viewDisabledEntries(){
		$this->paginate['limit'] = 50;
   		$this->paginate['order'] = array('date' => 'desc');
   		$this->paginate['fields'] = array('title','date','id');
   		$this->set('main_categories', $this->paginate('EntryQualification'));
		$this->render('viewEntries');
		
	}
	
		
function enableEntry($id=null){
	$this->EntryQualification->updateAll(array('status'=>'1'),array('id'=>$id));
	$this->paginate['limit'] = 50;
   	$this->paginate['order'] = array('date' => 'desc');
	$this->set('main_categories', $this->paginate('EntryQualification'));
   	//$this->render('viewPrograms');
	$this->redirect('/EntryQualifications/viewDisabledEntries');
}

function enableEntries($id=null){
	$this->EntryQualification->updateAll(array('status'=>'1'),array('id'=>$id));
	$this->paginate['limit'] = 50;
   	$this->paginate['order'] = array('date' => 'desc');
	$this->set('main_categories', $this->paginate('EntryQualification'));
	$this->redirect('/EntryQualifications/viewEntries');
}

function disableEntry($id=null){
	$this->EntryQualification->updateAll(array('status'=>'0'),array('id'=>$id));
	$this->paginate['limit'] = 50;
   	$this->paginate['order'] = array('date' => 'desc');
	$this->set('main_categories', $this->paginate('EntryQualification'));
	$this->redirect('/EntryQualifications/viewEnabledEntries');
}

function disableEntries($id=null){
	$this->EntryQualification->updateAll(array('status'=>'0'),array('id'=>$id));
	$this->paginate['limit'] = 50;
   	$this->paginate['order'] = array('date' => 'desc');
	$this->set('main_categories', $this->paginate('EntryQualification'));
	$this->redirect('/EntryQualifications/viewEntries');

}



//MAIN CATEGORY SECTION ENDS HERE


}
?>