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

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

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

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

function disableMainCategory($id=null){
	$this->WhatWeThinkMainCategory->updateAll(array('status'=>'0'),array('id'=>$id));
	$this->paginate['limit'] = 50;
   	$this->paginate['order'] = array('date' => 'desc');
	$this->set('main_categories', $this->paginate('WhatWeThinkMainCategory'));
	$this->redirect('/what_we_think/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('WhatWeThinkCategory'));
		$this->render('viewCategories');
		
	}
function viewCategoryDetails($id=null){
	$data=$this->WhatWeThinkCategory->find('all',array('conditions'=>array('WhatWeThinkCategory.id'=>$id)));
	
	$this->set(compact('data'));	
	$main_cats=$this->WhatWeThinkMainCategory->find('list', array('fields'=>'title'));
	$this->set(compact('main_cats'));
}

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

	function editCategories($id=null){
		$main_cats=$this->WhatWeThinkMainCategory->find('list', array('fields'=>'title'));
			$this->set(compact('main_cats'));
		
	if(empty($this->data)){
		$current_image=$this->WhatWeThinkCategory->find('all',array('conditions'=>array('id'=>$id)));		
		$current_image=$current_image[0]['WhatWeThinkCategory']['image'];		
		$this->set(compact('current_image'));
		$data=$this->WhatWeThinkCategory->find('all',array('conditions'=>array('id'=>$id)));
		$this->data=$data[0];
	}	
	elseif(!empty($this->data)){
		$data=$this->data;
		$current_image=$this->WhatWeThinkCategory->find('all',array('conditions'=>array('id'=>$data['WhatWeThinkCategory']['id'])));		
		$current_image=$current_image[0]['WhatWeThinkCategory']['image'];
		$this->set(compact('current_image'));
			
		if(array_key_exists('remove',$data['WhatWeThinkCategory'])){
		
				if($data['WhatWeThinkCategory']['remove']==0){
				$data['WhatWeThinkCategory']['image']=$current_image;}
				
				elseif($data['WhatWeThinkCategory']['remove']!=0){
				$data['WhatWeThinkCategory']['image']='';}
		}
			if(($this->data['WhatWeThinkCategory']['image']['size']!=0) &&($this->data['WhatWeThinkCategory']['image']['size']<=2103361)) 
		  {			 
		  	$data=$this->data;  
			$image_path = $this->ImageHandler->upload_image_and_thumbnail($data['WhatWeThinkCategory']['image']);
			$image = $image_path['dir'].$image_path['img_folder'].$image_path['img_file'].".". $image_path['type'];
			$data['WhatWeThinkCategory']['image'] = $image;
			}
		   else if($this->data['WhatWeThinkCategory']['image']['size']>2103361) {
		    $this->Session->setFlash('Maximum file size exceeded.');
			$this->redirect('/what_we_think/editCategories/'.$this->data['WhatWeThinkCategory']['id']);
		}
		
			
										
			if($this->WhatWeThinkCategory->save($data)){				
			$this->Session->setFlash('Updated Successfully.');
			$this->redirect('/what_we_think/viewCategoryDetails/'.$this->data['WhatWeThinkCategory']['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('WhatWeThinkCategory'));
		$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('WhatWeThinkCategory'));
		$this->render('viewCategories');
		
	}
	
	
function enableCategories($id=null){
	$this->WhatWeThinkCategory->updateAll(array('status'=>'1'),array('id'=>$id));
	$this->paginate['limit'] = 50;
   	$this->paginate['order'] = array('date' => 'desc');
	$this->set('categories', $this->paginate('WhatWeThinkCategory'));
	$this->redirect('/what_we_think/viewDisabledCategories');
}

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

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


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('what_we_thinkSubCategory'));
		$this->render('viewAllSubCategories');		
	}
	
function viewSubCategoryDetails($id=null){
	$data=$this->what_we_thinkSubCategory->find('all',array('conditions'=>array('what_we_thinkSubCategory.id'=>$id)));
	
	$this->set(compact('data'));	
	$cats=$this->WhatWeThinkCategory->find('list', array('fields'=>'title'));
	$this->set(compact('cats'));
}
 ////////////
 function addSubCategory(){	
	$cats=$this->WhatWeThinkCategory->find('list', array('fields'=>'title'));
	$this->set(compact('cats'));	
		if((isset($this->data['what_we_thinkSubCategory']['image']))&&($this->data['what_we_thinkSubCategory']['image']['size']!=0) &&($this->data['what_we_thinkSubCategory']['image'				        ]['size']>2103361)){
		 		$this->data['what_we_thinkSubCategory']['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['what_we_thinkSubCategory']['image']);
			$image = $image_path['dir'].$image_path['img_folder'].$image_path['img_file'].".". $image_path['type'];
			$data['what_we_thinkSubCategory']['image'] = $image;
			if ($this->what_we_thinkSubCategory->save($data)) {
			$this->Session->setFlash('Saved Successfully');
				$this->redirect('/what_we_think/viewSubCategories');
		  }
		else if($this->data['what_we_thinkSubCategory']['image']['size']>2103361)		
				{
				 $this->data['what_we_thinkSubCategory']['image']='';
				 $this->Session->setFlash('Maximum file size exceeded.');
				$this->redirect(array('action' => 'addSubCategory'));
				}		
		      }
	    }
 ///////////
///*****************************///
function editSubCategories($id=null){
		$cats=$this->WhatWeThinkCategory->find('list', array('fields'=>'title'));
			$this->set(compact('cats'));
		
	if(empty($this->data)){
		$current_image=$this->what_we_thinkSubCategory->find('all',array('conditions'=>array('id'=>$id)));		
		$current_image=$current_image[0]['what_we_thinkSubCategory']['image'];		
		$this->set(compact('current_image'));
		$data=$this->what_we_thinkSubCategory->find('all',array('conditions'=>array('id'=>$id)));
		$this->data=$data[0];
	}	
	elseif(!empty($this->data)){
		$data=$this->data;
		$current_image=$this->what_we_thinkSubCategory->find('all',array('conditions'=>array('id'=>$data['what_we_thinkSubCategory']['id'])));		
		$current_image=$current_image[0]['what_we_thinkSubCategory']['image'];
		$this->set(compact('current_image'));
			
		if(array_key_exists('remove',$data['what_we_thinkSubCategory'])){
		
				if($data['what_we_thinkSubCategory']['remove']==0){
				$data['what_we_thinkSubCategory']['image']=$current_image;}
				
				elseif($data['what_we_thinkSubCategory']['remove']!=0){
				$data['what_we_thinkSubCategory']['image']='';}
		}
			if(($this->data['what_we_thinkSubCategory']['image']['size']!=0) &&($this->data['what_we_thinkSubCategory']['image']['size']<=2103361)) 
		  {			 
		  	$data=$this->data;  
			$image_path = $this->ImageHandler->upload_image_and_thumbnail($data['what_we_thinkSubCategory']['image']);
			$image = $image_path['dir'].$image_path['img_folder'].$image_path['img_file'].".". $image_path['type'];
			$data['what_we_thinkSubCategory']['image'] = $image;
			}
		   else if($this->data['what_we_thinkSubCategory']['image']['size']>2103361) {
		    $this->Session->setFlash('Maximum file size exceeded.');
			$this->redirect('/what_we_think/editSubCategories/'.$this->data['what_we_thinkSubCategory']['id']);
		}
		
			
										
			if($this->what_we_thinkSubCategory->save($data)){				
			$this->Session->setFlash('Updated Successfully.');
			$this->redirect('/what_we_think/viewSubCategoryDetails/'.$this->data['what_we_thinkSubCategory']['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('what_we_thinkSubCategory'));
		$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('what_we_thinkSubCategory'));
		$this->render('viewSubCategories');
		
	}
	
	
function enableSubCategories($id=null){
	$this->what_we_thinkSubCategory->updateAll(array('status'=>'1'),array('id'=>$id));
	$this->paginate['limit'] = 50;
   	$this->paginate['order'] = array('date' => 'desc');
	$this->set('sub_categories', $this->paginate('what_we_thinkSubCategory'));
	$this->redirect('/what_we_think/viewDisabledSubCategories');
}

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

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


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

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