<?php 
class AwardsController extends AppController{
	var $name="Awards";
	var $uses=array('AwardMainCategory','AwardCategory','AwardSubCategory');
	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 viewMainCategories(){
		$this->paginate['limit'] = 50;
   		$this->paginate['order'] = array('date' => 'desc');
   		$this->paginate['fields'] = array('title','date','status','id');
		$this->set('main_categories', $this->paginate('AwardMainCategory'));
		$this->render('viewAllMainCategories');
		
	}
function viewMainCategoryDetails($id=null){
	$data=$this->AwardMainCategory->find('all',array('conditions'=>array('AwardMainCategory.id'=>$id)));
	
	$this->set(compact('data'));	
	
}

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

function viewEnabledMainCategories(){
		$this->paginate['limit'] = 50;
   		$this->paginate['order'] = array('date' => 'desc');
   		$this->paginate['fields'] = array('title','status','date','id');
		$this->paginate['conditions']= array('status'=>'1');
		$this->set('status','1');
   		$this->set('main_categories', $this->paginate('AwardMainCategory'));
		$this->render('viewMainCategories');
		
	}
	
function viewDisabledMainCategories(){
		$this->paginate['limit'] = 50;
   		$this->paginate['order'] = array('date' => 'desc');
   		$this->paginate['fields'] = array('title','date','status','id');
		$this->paginate['conditions']= array('status'=>'0');
		$this->set('status','0');
   		$this->set('main_categories', $this->paginate('AwardMainCategory'));
		$this->render('viewMainCategories');
		
	}
	
		
function enableMainCategories($id=null){
	$this->AwardMainCategory->updateAll(array('status'=>'1'),array('id'=>$id));
	$this->paginate['limit'] = 50;
   	$this->paginate['order'] = array('date' => 'desc');
	$this->set('main_categories', $this->paginate('AwardMainCategory'));
   	//$this->render('viewMainCategories');
	$this->redirect('/Awards/viewDisabledMainCategories');
}

function enableMainCategory($id=null){
	$this->AwardMainCategory->updateAll(array('status'=>'1'),array('id'=>$id));
	$this->paginate['limit'] = 50;
   	$this->paginate['order'] = array('date' => 'desc');
	$this->set('main_categories', $this->paginate('AwardMainCategory'));
	$this->redirect('/Awards/viewMainCategories');
}

function disableMainCategories($id=null){
	$this->AwardMainCategory->updateAll(array('status'=>'0'),array('id'=>$id));
	$this->paginate['limit'] = 50;
   	$this->paginate['order'] = array('date' => 'desc');
	$this->set('main_categories', $this->paginate('AwardMainCategory'));
	$this->redirect('/Awards/viewEnabledMainCategories');
}

function disableMainCategory($id=null){
	$this->AwardMainCategory->updateAll(array('status'=>'0'),array('id'=>$id));
	$this->paginate['limit'] = 50;
   	$this->paginate['order'] = array('date' => 'desc');
	$this->set('main_categories', $this->paginate('AwardMainCategory'));
	$this->redirect('/Awards/viewMainCategories');

}



//MAIN CATEGORY SECTION ENDS HERE
//CATEGORIES SECTION STARTS HERE

function viewCategories(){
		$this->paginate['limit'] = 50;
   		$this->paginate['order'] = array('date' => 'desc');
   		$this->paginate['fields'] = array('title','date','status','id');
		$this->set('categories', $this->paginate('AwardCategory'));
		$this->render('viewAllCategories');
		
	}
function viewCategoryDetails($id=null){
	$data=$this->AwardCategory->find('all',array('conditions'=>array('AwardCategory.id'=>$id)));
	
	$this->set(compact('data'));	
	$main_cats=$this->AwardMainCategory->find('list', array('fields'=>'title'));
	$this->set(compact('main_cats'));
}

///////////////////////////////////////////
	function addCategory(){	
	$main_cats=$this->AwardMainCategory->find('list', array('fields'=>'title'));
	$this->set(compact('main_cats'));	
		if((isset($this->data['AwardCategory']['image']))&&($this->data['AwardCategory']['image']['size']!=0) &&($this->data['AwardCategory']['image'				        ]['size']>2103361)){
		 		$this->data['AwardCategory']['image']='';
				$this->Session->setFlash('Maximum file size of 2MB exceeded.');
				$this->redirect(array('action' => 'addCategory'));
		}		
		if (!empty($this->data)) {				
		  	$data=$this->data;  
			$image_path = $this->ImageHandler->upload_image_and_thumbnail($data['AwardCategory']['image']);
			$image = $image_path['dir'].$image_path['img_folder'].$image_path['img_file'].".". $image_path['type'];
			$data['AwardCategory']['image'] = $image;
			if ($this->AwardCategory->save($data)) {
			$this->Session->setFlash('Saved Successfully');
				$this->redirect('/Awards/viewCategories');
		  }
		else if($this->data['AwardCategory']['image']['size']>2103361)		
				{
				 $this->data['AwardCategory']['image']='';
				 $this->Session->setFlash('Maximum file size exceeded.');
				$this->redirect(array('action' => 'addCategory'));
				}		
		      }
	    }
///////////////////////////////////////////

	function editCategories($id=null){
		$main_cats=$this->AwardMainCategory->find('list', array('fields'=>'title'));
			$this->set(compact('main_cats'));
		
	if(empty($this->data)){
		$current_image=$this->AwardCategory->find('all',array('conditions'=>array('id'=>$id)));		
		$current_image=$current_image[0]['AwardCategory']['image'];		
		$this->set(compact('current_image'));
		$data=$this->AwardCategory->find('all',array('conditions'=>array('id'=>$id)));
		$this->data=$data[0];
	}	
	elseif(!empty($this->data)){
		$data=$this->data;
		$current_image=$this->AwardCategory->find('all',array('conditions'=>array('id'=>$data['AwardCategory']['id'])));		
		$current_image=$current_image[0]['AwardCategory']['image'];
		$this->set(compact('current_image'));
			
		if(array_key_exists('remove',$data['AwardCategory'])){
		
				if($data['AwardCategory']['remove']==0){
				$data['AwardCategory']['image']=$current_image;}
				
				elseif($data['AwardCategory']['remove']!=0){
				$data['AwardCategory']['image']='';}
		}
			if(($this->data['AwardCategory']['image']['size']!=0) &&($this->data['AwardCategory']['image']['size']<=2103361)) 
		  	{			 
		  	$data=$this->data;  
			$image_path = $this->ImageHandler->upload_image_and_thumbnail($data['AwardCategory']['image']);
			$image = $image_path['dir'].$image_path['img_folder'].$image_path['img_file'].".". $image_path['type'];
			$data['AwardCategory']['image'] = $image;
			}
		   else if($this->data['AwardCategory']['image']['size']>2103361) {
		    $this->Session->setFlash('Maximum file size exceeded.');
			$this->redirect('/Awards/editCategories/'.$this->data['AwardCategory']['id']);
			}									
			if($this->AwardCategory->save($data)){				
			$this->Session->setFlash('Updated Successfully.');
			$this->redirect('/Awards/viewCategoryDetails/'.$this->data['AwardCategory']['id']);
			}
	}
		}

function viewEnabledCategories(){
		$this->paginate['limit'] = 50;
   		$this->paginate['order'] = array('date' => 'desc');
   		$this->paginate['fields'] = array('title','status','date','id');
		$this->paginate['conditions']= array('status'=>'1');
		$this->set('status','1');
   		$this->set('categories', $this->paginate('AwardCategory'));
		$this->render('viewCategories');
		
	}
	
function viewDisabledCategories(){
		$this->paginate['limit'] = 50;
   		$this->paginate['order'] = array('date' => 'desc');
   		$this->paginate['fields'] = array('title','date','status','id');
		$this->paginate['conditions']= array('status'=>'0');
		$this->set('status','0');
   		$this->set('categories', $this->paginate('AwardCategory'));
		$this->render('viewCategories');
		
	}
	
	
function enableCategories($id=null){
	$this->AwardCategory->updateAll(array('status'=>'1'),array('id'=>$id));
	$this->paginate['limit'] = 50;
   	$this->paginate['order'] = array('date' => 'desc');
	$this->set('categories', $this->paginate('AwardCategory'));
	$this->redirect('/Awards/viewDisabledCategories');
}

function enableCategory($id=null){
	$this->AwardCategory->updateAll(array('status'=>'1'),array('id'=>$id));
	$this->paginate['limit'] = 50;
   	$this->paginate['order'] = array('date' => 'desc');
	$this->set('categories', $this->paginate('AwardCategory'));
	$this->redirect('/Awards/viewCategories');
}

function disableCategory($id=null){
	$this->AwardCategory->updateAll(array('status'=>'0'),array('id'=>$id));
	$this->paginate['limit'] = 50;
   	$this->paginate['order'] = array('date' => 'desc');
	$this->set('categories', $this->paginate('AwardCategory'));
	$this->redirect('/Awards/viewCategories');
}

function disableCategories($id=null){
	$this->AwardCategory->updateAll(array('status'=>'0'),array('id'=>$id));
	$this->paginate['limit'] = 50;
   	$this->paginate['order'] = array('date' => 'desc');
	$this->set('categories', $this->paginate('AwardCategory'));
	$this->redirect('/Awards/viewEnabledCategories');
}
	
	
//CATEGORIES SECTION ENDS HERE
//SUB CATEGORIES SECTION STARTS HERE	
	
function viewSubCategories(){
		$this->paginate['limit'] = 50;
   		$this->paginate['order'] = array('date' => 'desc');
   		$this->paginate['fields'] = array('title','date','status','id');
		$this->set('sub_categories', $this->paginate('AwardSubCategory'));
		$this->render('viewAllSubCategories');		
	}
	
function viewSubCategoryDetails($id=null){
	$data=$this->AwardSubCategory->find('all',array('conditions'=>array('AwardSubCategory.id'=>$id)));
	
	$this->set(compact('data'));	
	$cats=$this->AwardCategory->find('list', array('fields'=>'title'));
	$this->set(compact('cats'));
}
 ////////////
 function addSubCategory(){	
	$cats=$this->AwardCategory->find('list', array('fields'=>'title'));
	$this->set(compact('cats'));	
		if((isset($this->data['AwardSubCategory']['image']))&&($this->data['AwardSubCategory']['image']['size']!=0) &&($this->data['AwardSubCategory']['image'				        ]['size']>2103361)){
		 		$this->data['AwardSubCategory']['image']='';
				$this->Session->setFlash('Maximum file size of 2MB exceeded.');
				$this->redirect(array('action' => 'addSubCategory'));
		}		
		if (!empty($this->data)) {				
		  	$data=$this->data;  
			$image_path = $this->ImageHandler->upload_image_and_thumbnail($data['AwardSubCategory']['image']);
			$image = $image_path['dir'].$image_path['img_folder'].$image_path['img_file'].".". $image_path['type'];
			$data['AwardSubCategory']['image'] = $image;
			if ($this->AwardSubCategory->save($data)) {
			$this->Session->setFlash('Saved Successfully');
				$this->redirect('/Awards/viewSubCategories');
		  }
		else if($this->data['AwardSubCategory']['image']['size']>2103361)		
				{
				 $this->data['AwardSubCategory']['image']='';
				 $this->Session->setFlash('Maximum file size exceeded.');
				$this->redirect(array('action' => 'addSubCategory'));
				}		
		      }
	    }
 ///////////
///*****************************///
function editSubCategories($id=null){
		$cats=$this->AwardCategory->find('list', array('fields'=>'title'));
			$this->set(compact('cats'));
		
	if(empty($this->data)){
		$current_image=$this->AwardSubCategory->find('all',array('conditions'=>array('id'=>$id)));		
		$current_image=$current_image[0]['AwardSubCategory']['image'];		
		$this->set(compact('current_image'));
		$data=$this->AwardSubCategory->find('all',array('conditions'=>array('id'=>$id)));
		$this->data=$data[0];
	}	
	elseif(!empty($this->data)){
		$data=$this->data;
		$current_image=$this->AwardSubCategory->find('all',array('conditions'=>array('id'=>$data['AwardSubCategory']['id'])));		
		$current_image=$current_image[0]['AwardSubCategory']['image'];
		$this->set(compact('current_image'));
			
		if(array_key_exists('remove',$data['AwardSubCategory'])){
		
				if($data['AwardSubCategory']['remove']==0){
				$data['AwardSubCategory']['image']=$current_image;}
				
				elseif($data['AwardSubCategory']['remove']!=0){
				$data['AwardSubCategory']['image']='';}
		}
			if(($this->data['AwardSubCategory']['image']['size']!=0) &&($this->data['AwardSubCategory']['image']['size']<=2103361)) 
		  {			 
		  	$data=$this->data;  
			$image_path = $this->ImageHandler->upload_image_and_thumbnail($data['AwardSubCategory']['image']);
			$image = $image_path['dir'].$image_path['img_folder'].$image_path['img_file'].".". $image_path['type'];
			$data['AwardSubCategory']['image'] = $image;
			}
		   else if($this->data['AwardSubCategory']['image']['size']>2103361) {
		    $this->Session->setFlash('Maximum file size exceeded.');
			$this->redirect('/Awards/editSubCategories/'.$this->data['AwardSubCategory']['id']);
		}
		
			
										
			if($this->AwardSubCategory->save($data)){				
			$this->Session->setFlash('Updated Successfully.');
			$this->redirect('/Awards/viewSubCategoryDetails/'.$this->data['AwardSubCategory']['id']);
			}
	}
		}
		
///*****************************///
	
		


function viewEnabledSubCategories(){
		$this->paginate['limit'] = 50;
   		$this->paginate['order'] = array('date' => 'desc');
   		$this->paginate['fields'] = array('title','date','status','id');
		$this->paginate['conditions']= array('status'=>'1');
		$this->set('status','1');
   		$this->set('sub_categories', $this->paginate('AwardSubCategory'));
		$this->render('viewSubCategories');
		
	}
	
function viewDisabledSubCategories(){
		$this->paginate['limit'] = 50;
   		$this->paginate['order'] = array('date' => 'desc');
   		$this->paginate['fields'] = array('title','date','status','id');
		$this->paginate['conditions']= array('status'=>'0');
		$this->set('status','0');
   		$this->set('sub_categories', $this->paginate('AwardSubCategory'));
		$this->render('viewSubCategories');
		
	}
	
	
function enableSubCategories($id=null){
	$this->AwardSubCategory->updateAll(array('status'=>'1'),array('id'=>$id));
	$this->paginate['limit'] = 50;
   	$this->paginate['order'] = array('date' => 'desc');
	$this->set('sub_categories', $this->paginate('AwardSubCategory'));
	$this->redirect('/Awards/viewDisabledSubCategories');
}

function disableSubCategories($id=null){
	$this->AwardSubCategory->updateAll(array('status'=>'0'),array('id'=>$id));
	$this->paginate['limit'] = 50;
   	$this->paginate['order'] = array('date' => 'desc');
	$this->set('sub_categories', $this->paginate('AwardSubCategory'));
	$this->redirect('/Awards/viewEnabledSubCategories');
}

function disableSubCategory($id=null){
	$this->AwardSubCategory->updateAll(array('status'=>'0'),array('id'=>$id));
	$this->paginate['limit'] = 50;
   	$this->paginate['order'] = array('date' => 'desc');
	$this->set('categories', $this->paginate('AwardSubCategory'));
	$this->redirect('/Awards/viewSubCategories');	
	}
	
function enableSubCategory($id=null){
	$this->AwardSubCategory->updateAll(array('status'=>'1'),array('id'=>$id));
	$this->paginate['limit'] = 50;
   	$this->paginate['order'] = array('date' => 'desc');
	$this->set('categories', $this->paginate('AwardSubCategory'));
	$this->redirect('/Awards/viewSubCategories');
	}

}
?>