<?php 
class SportsprogramsController extends AppController{
	var $name="Sportsprograms";
	var $uses=array('SportsprogramMainCategory','SportsprogramCategory','SportsprogramSubCategory');
	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('SportsprogramMainCategory'));
		$this->render('viewAllMainCategories');
		
	}
function viewMainCategoryDetails($id=null){
	$data=$this->SportsprogramMainCategory->find('all',array('conditions'=>array('SportsprogramMainCategory.id'=>$id)));
	
	$this->set(compact('data'));	
	
}

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

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

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

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

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

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

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

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

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

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

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

}
?>