<?php 
class AboutUsController extends AppController{
	var $name="AboutUs";
	var $uses=array('AboutUsMainCategory','AboutUsCategory','AboutUsSubCategory');
	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('AboutUsMainCategory'));
		$this->render('viewMainCategories');
		
	}
function viewMainCategoryDetails($id=null){
	$data=$this->AboutUsMainCategory->find('all',array('conditions'=>array('AboutUsMainCategory.id'=>$id)));
	
	$this->set(compact('data'));	
	
}

		
		function addMainCategory() {		
		if((isset($this->data['AboutUsMainCategory']['image']))&&($this->data['AboutUsMainCategory']['image']['size']!=0) &&($this->data['AboutUsMainCategory']['image'				        ]['size']>2103361)){
		 		$this->data['AboutUsMainCategory']['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['AboutUsMainCategory']['image']);
			$image = $image_path['dir'].$image_path['img_folder'].$image_path['img_file'].".". $image_path['type'];
			$data['AboutUsMainCategory']['image'] = $image;
			if ($this->AboutUsMainCategory->save($data)) {
				$this->Session->setFlash('Saved Successfully.');
				$this->redirect('/AboutUs/viewDisabledMainCategories');
		  }
		else if($this->data['AboutUsMainCategory']['image']['size']>2103361)		
				{
				 $this->data['AboutUsMainCategory']['image']='';
				 $this->Session->setFlash('Maximum file size exceeded.');
				$this->redirect(array('action' => 'addMainCategory'));
				}		
		      }
	    }
	
	
function editMainCategories($id=null){		
	if(empty($this->data)){
		$current_image=$this->AboutUsMainCategory->find('all',array('conditions'=>array('id'=>$id)));		
		$current_image=$current_image[0]['AboutUsMainCategory']['image'];		
		$this->set(compact('current_image'));
		$data=$this->AboutUsMainCategory->find('all',array('conditions'=>array('id'=>$id)));
		$this->data=$data[0];
	}	
	elseif(!empty($this->data)){
		$data=$this->data;
		$current_image=$this->AboutUsMainCategory->find('all',array('conditions'=>array('id'=>$data['AboutUsMainCategory']['id'])));		
		$current_image=$current_image[0]['AboutUsMainCategory']['image'];
		$this->set(compact('current_image'));
			
		if(array_key_exists('remove',$data['AboutUsMainCategory'])){
		
				if($data['AboutUsMainCategory']['remove']==0){
				$data['AboutUsMainCategory']['image']=$current_image;}
				
				elseif($data['AboutUsMainCategory']['remove']!=0){
				$data['AboutUsMainCategory']['image']='';}
		}
			if(($this->data['AboutUsMainCategory']['image']['size']!=0) &&($this->data['AboutUsMainCategory']['image']['size']<=2103361)) 
		  {			 
		  	$data=$this->data;  
			$image_path = $this->ImageHandler->upload_image_and_thumbnail($data['AboutUsMainCategory']['image']);
			$image = $image_path['dir'].$image_path['img_folder'].$image_path['img_file'].".". $image_path['type'];
			$data['AboutUsMainCategory']['image'] = $image;
			}
		   else if($this->data['AboutUsMainCategory']['image']['size']>2103361) {
		    $this->Session->setFlash('Maximum file size exceeded.');		
			$this->redirect('/AboutUs/editMainCategories/'.$this->data['AboutUsMainCategory']['id']);
		}
		
			
										
			if($this->AboutUsMainCategory->save($data)){	
			$this->Session->setFlash('Updated Successfully.');				
			$this->redirect('/AboutUs/viewMainCategoryDetails/'.$this->data['AboutUsMainCategory']['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('AboutUsMainCategory'));
		$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('AboutUsMainCategory'));
		$this->render('viewMainCategories');
		
	}
	
		
/*function enableMainCategories($id=null){
	$this->AboutUsMainCategory->updateAll(array('status'=>'1'),array('id'=>$id));
	$this->paginate['limit'] = 50;
   	$this->paginate['order'] = array('date' => 'desc');
	$this->set('main_categories', $this->paginate('AboutUsMainCategory'));
   	//$this->render('viewMainCategories');
	$this->redirect('/AboutUs/viewDisabledMainCategories');
}

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

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

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

}*/


function addMainCategoryResponse(){
	
	
	
}










//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('AboutUsCategory'));
		$this->render('viewCategories');
		
	}
function viewCategoryDetails($id=null){
	$data=$this->AboutUsCategory->find('all',array('conditions'=>array('AboutUsCategory.id'=>$id)));
	
	$this->set(compact('data'));	
	$main_cats=$this->AboutUsMainCategory->find('list', array('fields'=>'title'));
	$this->set(compact('main_cats'));
}

///////////////////////////////////////////
	function addCategory(){	
	$main_cats=$this->AboutUsMainCategory->find('list', array('fields'=>'title'));
	$this->set(compact('main_cats'));	
		if((isset($this->data['AboutUsCategory']['image']))&&($this->data['AboutUsCategory']['image']['size']!=0) &&($this->data['AboutUsCategory']['image'				        ]['size']>2103361)){
		 		$this->data['AboutUsCategory']['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['AboutUsCategory']['image']);
			$image = $image_path['dir'].$image_path['img_folder'].$image_path['img_file'].".". $image_path['type'];
			$data['AboutUsCategory']['image'] = $image;
			if ($this->AboutUsCategory->save($data)) {
			$this->Session->setFlash('Saved Successfully');
				$this->redirect('/AboutUs/viewDisabledCategories');
		  }
		else if($this->data['AboutUsCategory']['image']['size']>2103361)		
				{
				 $this->data['AboutUsCategory']['image']='';
				 $this->Session->setFlash('Maximum file size exceeded.');
				$this->redirect(array('action' => 'addCategory'));
				}		
		      }
	    }
///////////////////////////////////////////

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

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('AboutUsCategory'));
		$main_cats=$this->AboutUsMainCategory->find('list', array('fields'=>'title'));
			$this->set(compact('main_cats'));
		$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('AboutUsCategory'));
		$main_cats=$this->AboutUsMainCategory->find('list', array('fields'=>'title'));
			$this->set(compact('main_cats'));
		$this->render('viewCategories');
		
		
	}
	
	
/*function enableCategories($id=null){
	$this->AboutUsCategory->updateAll(array('status'=>'1'),array('id'=>$id));
	$this->paginate['limit'] = 50;
   	$this->paginate['order'] = array('date' => 'desc');
	$this->set('categories', $this->paginate('AboutUsCategory'));
	$this->redirect('/AboutUs/viewDisabledCategories');
	$main_cats=$this->AboutUsMainCategory->find('list', array('fields'=>'title'));
			$this->set(compact('main_cats'));
}

function enableCategory($id=null){
	$this->AboutUsCategory->updateAll(array('status'=>'1'),array('id'=>$id));
	$this->paginate['limit'] = 50;
   	$this->paginate['order'] = array('date' => 'desc');
	$this->set('categories', $this->paginate('AboutUsCategory'));
   	//$this->render('viewCategories');
	$this->redirect('/AboutUs/viewCategories');
	$main_cats=$this->AboutUsMainCategory->find('list', array('fields'=>'title'));
			$this->set(compact('main_cats'));
}

function disableCategory($id=null){
	$this->AboutUsCategory->updateAll(array('status'=>'0'),array('id'=>$id));
	$this->paginate['limit'] = 50;
   	$this->paginate['order'] = array('date' => 'desc');
	$this->set('categories', $this->paginate('AboutUsCategory'));
   	//$this->render('viewCategories');
	$this->redirect('/AboutUs/viewCategories');
	$main_cats=$this->AboutUsMainCategory->find('list', array('fields'=>'title'));
			$this->set(compact('main_cats'));
}
function disableCategories($id=null){
	$this->AboutUsCategory->updateAll(array('status'=>'0'),array('id'=>$id));
	$this->paginate['limit'] = 50;
   	$this->paginate['order'] = array('date' => 'desc');
	$this->set('categories', $this->paginate('AboutUsCategory'));
   	//$this->render('viewCategories');
	$this->redirect('/AboutUs/viewEnabledCategories');
	$main_cats=$this->AboutUsMainCategory->find('list', array('fields'=>'title'));
			$this->set(compact('main_cats'));
}*/


function addCategoryResponse(){
	
	
	
}
	
	
	
//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('AboutUsSubCategory'));
		$this->render('viewAllSubCategories');		
	}
	
function viewSubCategoryDetails($id=null){
	$data=$this->AboutUsSubCategory->find('all',array('conditions'=>array('AboutUsSubCategory.id'=>$id)));
	
	$this->set(compact('data'));	
	$cats=$this->AboutUsCategory->find('list', array('fields'=>'title'));
	$this->set(compact('cats'));
}
 ////////////
 function addSubCategory(){	
	$cats=$this->AboutUsCategory->find('list', array('fields'=>'title'));
	$this->set(compact('cats'));	
		if((isset($this->data['AboutUsSubCategory']['image']))&&($this->data['AboutUsSubCategory']['image']['size']!=0) &&($this->data['AboutUsSubCategory']['image'				        ]['size']>2103361)){
		 		$this->data['AboutUsSubCategory']['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['AboutUsSubCategory']['image']);
			$image = $image_path['dir'].$image_path['img_folder'].$image_path['img_file'].".". $image_path['type'];
			$data['AboutUsSubCategory']['image'] = $image;
			if ($this->AboutUsSubCategory->save($data)) {
			$this->Session->setFlash('Saved Successfully');
				$this->redirect('/AboutUs/viewSubCategories');
		  }
		else if($this->data['AboutUsSubCategory']['image']['size']>2103361)		
				{
				 $this->data['AboutUsSubCategory']['image']='';
				 $this->Session->setFlash('Maximum file size exceeded.');
				$this->redirect(array('action' => 'addSubCategory'));
				}		
		      }
	    }
 ///////////
///*****************************///
function editSubCategories($id=null){
		$cats=$this->AboutUsCategory->find('list', array('fields'=>'title'));
			$this->set(compact('cats'));
		
	if(empty($this->data)){
		$current_image=$this->AboutUsSubCategory->find('all',array('conditions'=>array('id'=>$id)));		
		$current_image=$current_image[0]['AboutUsSubCategory']['image'];		
		$this->set(compact('current_image'));
		$data=$this->AboutUsSubCategory->find('all',array('conditions'=>array('id'=>$id)));
		$this->data=$data[0];
	}	
	elseif(!empty($this->data)){
		$data=$this->data;
		$current_image=$this->AboutUsSubCategory->find('all',array('conditions'=>array('id'=>$data['AboutUsSubCategory']['id'])));		
		$current_image=$current_image[0]['AboutUsSubCategory']['image'];
		$this->set(compact('current_image'));
			
		if(array_key_exists('remove',$data['AboutUsSubCategory'])){
		
				if($data['AboutUsSubCategory']['remove']==0){
				$data['AboutUsSubCategory']['image']=$current_image;}
				
				elseif($data['AboutUsSubCategory']['remove']!=0){
				$data['AboutUsSubCategory']['image']='';}
		}
			if(($this->data['AboutUsSubCategory']['image']['size']!=0) &&($this->data['AboutUsSubCategory']['image']['size']<=2103361)) 
		  {			 
		  	$data=$this->data;  
			$image_path = $this->ImageHandler->upload_image_and_thumbnail($data['AboutUsSubCategory']['image']);
			$image = $image_path['dir'].$image_path['img_folder'].$image_path['img_file'].".". $image_path['type'];
			$data['AboutUsSubCategory']['image'] = $image;
			}
		   else if($this->data['AboutUsSubCategory']['image']['size']>2103361) {
		    $this->Session->setFlash('Maximum file size exceeded.');
			$this->redirect('/AboutUs/editSubCategories/'.$this->data['AboutUsSubCategory']['id']);
		}
		
			
										
			if($this->AboutUsSubCategory->save($data)){				
			$this->Session->setFlash('Updated Successfully.');
			$this->redirect('/AboutUs/viewSubCategoryDetails/'.$this->data['AboutUsSubCategory']['id']);
			}
	}
		}
		
///*****************************///
	
		
	function subCategoryEditResponse(){
		
		
	}

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('AboutUsSubCategory'));
		$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('AboutUsSubCategory'));
		$this->render('viewSubCategories');
		
	}
	
	
/*function enableSubCategories($id=null){
	$this->AboutUsSubCategory->updateAll(array('status'=>'1'),array('id'=>$id));
	$this->paginate['limit'] = 50;
   	$this->paginate['order'] = array('date' => 'desc');
	$this->set('sub_categories', $this->paginate('AboutUsSubCategory'));
	$this->redirect('/AboutUs/viewDisabledSubCategories');
}

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

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


function addSubCategoryResponse(){	
    }
	
function delete($id){
	$this->AboutUsMainCategory->delete($id);
	$this->redirect($this->referer());
}

function deleteCategoryDetails($id) {
	$this->AboutUsCategory->delete($id);
	$this->redirect($this->referer());
	}
}
?>