<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Admin extends CI_Controller {
     
	public function __construct()
	{
	    parent::__construct();
		 if(!isset($_SESSION['admin_uid']))
		 {
			redirect(base_url('adminlogin'));
	     }
	} 
	
//*********************** html view start **************************//	 
    public function dashboard()
	{      
		$query_user = $this->Data_access_model->select_data('*',' hs_user',array('user_type'=>2));
		$query_product =$this->Data_access_model->select_all('hs_products');
		$query_tables =$this->Data_access_model->select_all('hs_table_details');
		$query_reservation =$this->Data_access_model->select_all('hs_reservation_details');
		$query_orders =$this->Data_access_model->select_all('hs_user_orders');
		$query_chefmember =$this->Data_access_model->select_all('hs_chef_team');
		
		if(!empty($query_user)){
			$data['total_user'] = $query_user->num_rows();
		}else{ 
			$data['total_user'] = 0;   
		}

		if($query_product->num_rows() > 0){
			$data['total_product'] =$query_product->num_rows();
		}else{ 
			$data['total_product'] = 0;   
		}

		if($query_tables->num_rows() > 0){
			$data['total_tables'] =$query_tables->num_rows();
		}else{ 
			$data['total_tables'] = 0;   
		}

		if($query_reservation->num_rows() > 0){
			$data['total_reservation'] =$query_reservation->num_rows();
		}else{ 
			$data['total_reservation'] = 0;   
		}

		if($query_orders->num_rows() > 0){

		$data['total_orders'] = $query_orders->num_rows();
		}else{ 
		$data['total_orders'] = 0;   
		}

		if($query_chefmember->num_rows() > 0){

		$data['total_chef'] = $query_chefmember->num_rows();
		}else{ 
		$data['total_chef'] = 0;   
		}
	   
		$data['pagetitle'] ='dashboard';
		$data['active_class']= 1; 
		$this->load->view('common/header',$data);
		$this->load->view('dashboard',$data);
		$this->load->view('common/footer');
	}
    
	
	public function reservation_list()
	{
		$query_reservation =$this->Data_access_model->select_all('hs_reservation_details','reservation_id');
	   
		if($query_reservation->num_rows() > 0){
	   
			$data['all_reservation'] =$query_reservation->result(); 
		
		}else{ 
		
			$data['all_reservation'] = '';
		}
	   
		$query_product = $this->Data_access_model->select_all('hs_products');
	 
		if($query_product->num_rows() >0){
			
			$data['prod_details'] =$query_product->result(); 
			  
		}else{
			
			$data['prod_details'] = '';
		}
		
		$query_occasions = $this->Data_access_model->select_all('hs_occasions');
	 
		if($query_occasions->num_rows() > 0){
			
			$data['all_occasions'] =$query_occasions->result(); 
			  
		}else{
			
			$data['all_occasions'] = '';
		}
	    $data['pagetitle'] ='Reservations';
		$data['active_class']= 2; 
	    $this->load->view('common/header',$data);
		$this->load->view('reservation_list',$data);
		$this->load->view('common/footer');
	}
	
	public function add_new_table()
	{	$data['pagetitle'] ='New Table';
	    $data['active_class']= 3;
		$this->load->view('common/header',$data);
		$this->load->view('tablemanagement/add_table');
		$this->load->view('common/footer');
	}
    
	public function tablelist()
	{
		$query =$this->Data_access_model->select_all('hs_table_details');
		if($query->num_rows() > 0){
			   
			$data['all_tables'] =$query->result();
			 
		}else{ 
			 $data['all_tables'] = '';
			  
		}
		
		$data['active_class']= 3;
		$data['pagetitle'] ='Manage Tables';
		$this->load->view('common/header',$data);
		$this->load->view('tablemanagement/table_list',$data);
		$this->load->view('common/footer');
	}

    public function update_table_data()
	{
		if($this->uri->segment(3)){
			$old_table_id = $this->uri->segment(3);
			$where_data =array('table_id' =>$old_table_id,);
			$query=$this->Data_access_model->select_data('*','hs_table_details',$where_data);
		
			if($query->num_rows() > 0){
				$data['tabledetails']  = $query->result();
			}else{
			  
				$data['tabledetails']  = ''; 
			}
		}
		$data['pagetitle'] ='Update Table';
		$data['active_class']= 3;
		$this->load->view('common/header',$data);
		$this->load->view('tablemanagement/update_table', $data);
		$this->load->view('common/footer');
	}
	
	public function add_new_products()
	{
	    $cate_data =array( 'category_status' =>1);
	    $cate_query=$this->Data_access_model->select_data('category_id,category_name',' hs_category',$cate_data);
		   
		if($cate_query->num_rows() > 0){
			$data['category']  = $cate_query->result();
		}else{ 
			$data['category'] = '';
		} 
	    
		$data['pagetitle'] ='Add Products';
		$data['active_class']= 4;
		$this->load->view('common/header',$data);
		$this->load->view('productmanagment/addproducts',$data);
		$this->load->view('common/footer');
	}
	
	public function productlist()
	{
		$prod_query =$this->Data_access_model->select_all('hs_products');
		if($prod_query->num_rows() > 0){
			   
			$data['all_products'] =$prod_query->result();
			 
		}else{ 
		
			$data['all_product'] = '';
		}
		 
	    $cate_query =$this->Data_access_model->select_all('hs_category');
		
		if($cate_query->num_rows() > 0){
			   
			$data['all_category'] =$cate_query->result();
			 
		}else{ 
		
			$data['all_category'] = '';
		}
	
		$data['pagetitle'] ='Manage Products';
		$data['active_class']= 4;
	    $this->load->view('common/header',$data);
		$this->load->view('productmanagment/productlist',$data);
		$this->load->view('common/footer');
	}
	
	public function product_review()
	{
		 
		if($this->uri->segment(3)){
			$reviewprod_id = $this->uri->segment(3);
			$review_query =$this->Data_access_model->select_data('*',' hs_rating',array('rating_prod_id'=>$reviewprod_id));
		
			if($review_query->num_rows() > 0){
			   
				$data['all_review'] =$review_query->result();
			 
			}else{ 
		
				$data['all_review'] = '';
			}
		}
		$data['pagetitle'] ='Product Review';
		$data['active_class']= 4;
	    $this->load->view('common/header',$data);
		$this->load->view('productmanagment/product_review',$data);
		$this->load->view('common/footer');
	}
	
	
	public function update_product()
	{
		$data =array( 'category_status' =>1, );
	    $query=$this->Data_access_model->select_data('category_id,category_name',' hs_category',$data);
		   
		if($query->num_rows() > 0){
			$data['category']  = $query->result();
		}
	
	    if($this->uri->segment(3)){
			$old_prod_id = $this->uri->segment(3);
			$where_data =array( 'prod_id' =>$old_prod_id);
	        $query=$this->Data_access_model->select_data('*','hs_products',$where_data);
		    if($query->num_rows() > 0){
				$data['productdeatils']  = $query->result();
		    }
		}
		$data['pagetitle'] ='Update Product';
		$data['active_class']= 4;
		$this->load->view('common/header',$data);
		$this->load->view('productmanagment/update_product',$data);
		$this->load->view('common/footer');
	}
	
	public function manage_orders()
	{
		$order_query = $this->Data_access_model->select_all('hs_user_orders','order_id');
		if($order_query->num_rows() > 0){
			$data['all_uorders'] =$order_query->result();
		}else{ 
			$data['all_uorders'] = "";
		} 
		$data['pagetitle'] ='Orders';
		$data['active_class']= 18;
		$this->load->view('common/header',$data);
		$this->load->view('productmanagment/orders',$data);
		$this->load->view('common/footer');
	}
	
	
	public function categorylist()
	{
		$query = $this->Data_access_model->select_all('hs_category');
		
		if($query->num_rows() > 0){
		   
			$data['all_categories'] =$query->result(); 
			 
		}else{ 
			
			$data['all_categories'] = '';
		}
        $data['pagetitle'] ='Categories';
		$data['active_class']= 4;
		$this->load->view('common/header',$data);
		$this->load->view('categorymanagement/categorylist',$data);
		$this->load->view('common/footer');
	}
	
	public function edit_category()
	{
		$cate_query=$this->Data_access_model->select_data('*','hs_category',array( 'category_id' =>$this->input->post('cate_id'),));
		   
	    if($cate_query->num_rows() > 0){
			$data['all_category']= $cate_query->result();
		}
		else{ 
			 $data['all_category'] = "";
		}  
		echo json_encode($data);
	}
	
	public function add_new_user()
	{
		$data['pagetitle'] ='Add User';
		$data['active_class']= 5;
		$this->load->view('common/header',$data);
		$this->load->view('usermanegement/adduser');
		$this->load->view('common/footer');
	}
	
	public function userslist()
	{
		$query = $this->Data_access_model->select_data('*','hs_user',array('user_type' =>2));
		if($query->num_rows() > 0){
			   
			$data['all_users'] =$query->result();
		}else{ 
			$data['all_users'] = '';
		}
			
		$data['pagetitle'] ='Manage Users';
		$data['active_class']=5;
	    $this->load->view('common/header',$data);
		$this->load->view('usermanegement/userslist',$data);
		$this->load->view('common/footer');
	}
	
	public function update_user_data()
	{
		if($this->uri->segment(3)){
	      
			$old_user_id = $this->uri->segment(3);
			$where_data =array( 'user_id' =>$old_user_id, );
			$query=$this->Data_access_model->select_data('*','hs_user',$where_data);
		
			if($query->num_rows() > 0){
				$data['userdeatils']  = $query->result();
		    }
        
			$data['pagetitle'] ='Update User';
			$data['active_class']= 5;
			$this->load->view('common/header',$data);
			$this->load->view('usermanegement/update_user',$data);
			$this->load->view('common/footer');
	    }
    }

	public function blog_catelist()
	{
		$query =$this->Data_access_model->select_all('hs_blog_category');
		
		if($query->num_rows() > 0){
		   
			$data['all_blogcate'] =$query->result(); 
			 
		}else{ 
			
			$data['all_blogcate'] = '';
		}
		$data['pagetitle'] ='Blog Categories';
		$data['active_class']= 6;
		$this->load->view('common/header',$data);
		$this->load->view('blogs/blog_catelist',$data);
		$this->load->view('common/footer');
	}
	
	public function update_blogcate()
	{
		if($this->uri->segment(3)){
	      
			$old_blogcate_id = $this->uri->segment(3);
			$where_data =array( 'blog_id' =>$old_blogcate_id, );
			$query=$this->Data_access_model->select_data('*','hs_blogs',$where_data);
		
			if($query->num_rows() > 0){
				$data['blogdeatils']  = $query->result();
			}
		  
		    $data['pagetitle'] ='Update Blog Category';
			$data['active_class']= 6;
			$this->load->view('common/header',$data);
			$this->load->view('blogs/update_blogcate');
			$this->load->view('common/footer');	 
		}
	}
	
	public function add_blog()
	{
		$cate_data =array('cate_status' =>1,);
	    $blog_cate_query=$this->Data_access_model->select_data('cate_id,cate_name',' hs_blog_category',$cate_data);
		   
		if($blog_cate_query->num_rows() > 0){
			$data['blog_category']  = $blog_cate_query->result();
		} 
		$data['pagetitle'] ='Add Blog';
		$data['active_class']= 6;
		$this->load->view('common/header',$data);
		$this->load->view('blogs/addblog',$data);
		$this->load->view('common/footer');
	}
	
	public function bloglist()
	{
		$blogs_query =$this->Data_access_model->select_all('hs_blogs');
		
		if($blogs_query->num_rows() > 0){
		   
			$data['all_blogs'] =$blogs_query->result(); 
			 
		}else{ 
			
			$data['all_blogs'] = '';
		}
			
		$blogcate_query =$this->Data_access_model->select_all('hs_blog_category');
	
		if($blogcate_query->num_rows() > 0){
	   
			$data['all_blogcate'] =$blogcate_query->result(); 
		 
		}else{ 
		
			$data['all_blogcate'] = '';
		}
		$data['pagetitle'] ='Blogs';
		$data['active_class']= 6;
		$this->load->view('common/header',$data);
		$this->load->view('blogs/manage_blogs',$data);
		$this->load->view('common/footer');
	}
	
	public function update_blogs()
	{
		$cate_data =array('cate_status' =>1,);
	    $blog_cate_query=$this->Data_access_model->select_data('cate_id,cate_name',' hs_blog_category',$cate_data);
		   
		if($blog_cate_query->num_rows() > 0){
			$data['blog_category']  = $blog_cate_query->result();
		}
	
	    if($this->uri->segment(3)){
	      
			$old_blog_id = $this->uri->segment(3);
			$where_data =array( 'blog_id' =>$old_blog_id, );
			$query=$this->Data_access_model->select_data('*','hs_blogs',$where_data);
		
			if($query->num_rows() > 0){
				$data['blogdeatils']  = $query->result();
			}
		  
			$data['pagetitle'] ='Update Blog';
			$data['active_class']= 6;
			$this->load->view('common/header',$data);
			$this->load->view('blogs/update_blog',$data);
			$this->load->view('common/footer');
	    }
    }
	
	public function testimonial()
	{
		$data['pagetitle'] ='Add Testimonial';
		$data['active_class']= 7;
		$this->load->view('common/header',$data);
		$this->load->view('testimonial/add_testimonial');
		$this->load->view('common/footer');
	}
	
	public function testimoniallist()
	{	
		$query =$this->Data_access_model->select_all('hs_testimonial');
		
		if($query->num_rows() > 0){
		   
			$data['all_testimonial'] =$query->result(); 
			 
		}else{ 
			
			$data['all_testimonial'] = '';
		}
		$data['pagetitle'] ='Manage Testimonials';
		$data['active_class']= 7;
		$this->load->view('common/header',$data);
		$this->load->view('testimonial/manage_testimonial',$data);
		$this->load->view('common/footer');
	}
	
	public function update_testimonial()
	{
		if($this->uri->segment(3)){
	      
			$old_testi_id = $this->uri->segment(3);
			$where_data =array( 'testi_id' =>$old_testi_id, );
			$query=$this->Data_access_model->select_data('*','hs_testimonial',$where_data);
		
			if($query->num_rows() > 0){
				$data['testideatils']  = $query->result();
			}
		  
			$data['pagetitle'] ='Update Testimonial';
			$data['active_class']= 7;
			$this->load->view('common/header',$data);
			$this->load->view('testimonial/update_testimonial',$data);
			$this->load->view('common/footer');
	    }
    }
	
	public function addchefteam()
	{
		$data['pagetitle'] ='Add Chef';
		$data['active_class']= 8;
		$this->load->view('common/header',$data);
		$this->load->view('chef_team/addchef_team');
		$this->load->view('common/footer');
	}
	
	public function chefteamlist()
	{
		$query =$this->Data_access_model->select_all('hs_chef_team');
		if($query->num_rows() > 0){
		   
			$data['all_chefteam'] =$query->result(); 
			 
		}else{ 
			
			$data['all_chefteam'] = '';
		}
		$data['pagetitle'] ='Chef Team Members';
		$data['active_class']= 8;
		$this->load->view('common/header',$data);
		$this->load->view('chef_team/manage_chefteam',$data);
		$this->load->view('common/footer');
	}
	
	public function update_chefteam()
	{
		if($this->uri->segment(3)){
	      
			$old_chef_id = $this->uri->segment(3);
			$where_data =array('chef_id' =>$old_chef_id,);
			$query=$this->Data_access_model->select_data('*','hs_chef_team',$where_data);
		
			if($query->num_rows() > 0){
				$data['chefmember']  = $query->result();
			}
        
			$data['pagetitle'] ='Update Chef';
			$data['active_class']= 8;
			$this->load->view('common/header',$data);
			$this->load->view('chef_team/update_chefteam',$data);
			$this->load->view('common/footer');
	    }
    }
    
	public function occasion()
	{
		$query =$this->Data_access_model->select_all('hs_occasions');
		
		if($query->num_rows() > 0){
		   
			$data['all_occasions'] =$query->result(); 
			 
		}else{ 
			
			$data['all_occasions'] = '';
		}
			
		$data['pagetitle'] ='Occasions';
		$data['active_class']= 9;
		$this->load->view('common/header',$data);
		$this->load->view('productmanagment/manage_occasion',$data);
		$this->load->view('common/footer');
	}
	
	public function partners_list()
	{
		$query =$this->Data_access_model->select_all('hs_partners');
		
		if($query->num_rows() > 0){
	   
			$data['all_partners'] =$query->result(); 
		 
		}else{ 
		
			$data['all_partners'] = "";
		}
		$data['pagetitle'] ='Partners';
		$data['active_class']= 10;
		$this->load->view('common/header',$data);
		$this->load->view('manage_partners/manage_partners',$data);
		$this->load->view('common/footer');	
    }
	
	 
	public function gallery_image_list(){
		
		$query =$this->Data_access_model->select_all('hs_portfolio');
		
		if($query->num_rows() > 0){
			$data['all_portfolio'] =$query->result(); 
		}else{ 
			$data['all_portfolio'] = "";
		}
		$data['pagetitle'] ='Manage Portfolios';
		$data['active_class']= 11;		   
		$this->load->view('common/header',$data);
		$this->load->view('portfolio/manage_gallery',$data);
		$this->load->view('common/footer');
	}
	
	public function pages_list(){
		
		$query =$this->Data_access_model->select_all('hs_pages');
		
		if($query->num_rows() > 0){
	   
			$data['all_pages'] =$query->result(); 
		 
		}else{ 
		
			$data['all_pages'] = "";
		}
		$data['pagetitle'] ='Pages';
		$data['active_class']= 12;
		$this->load->view('common/header',$data);
		$this->load->view('pages/manage_pages',$data);
		$this->load->view('common/footer');
	}
	
	public function edit_pages(){
		
		if($this->uri->segment(3)){
	      
		  $old_page_id = $this->uri->segment(3);
		  $where_data =array('page_id' =>$old_page_id,);
	      $query=$this->Data_access_model->select_data('*','hs_pages',$where_data);
		
			if($query->num_rows() > 0){
				$data['pagedetails']  = $query->result();
			}
		}
		$data['pagetitle'] ='Update Pages';
		$data['active_class']= 12;
		$this->load->view('common/header',$data);
		$this->load->view('pages/update_page',$data);
		$this->load->view('common/footer');
	}
	
	public function comments()
	{
		$comment_query =$this->Data_access_model->select_all('hs_comment');
		
		if($comment_query->num_rows() > 0){
	   
			$data['all_comments'] =$comment_query->result(); 
		 
		}else{ 
		
			$data['all_comments'] = "";
		}
		$data['pagetitle'] ='Comments';
		$data['active_class']= 13;
		$this->load->view('common/header',$data);
		$this->load->view('comments/manage_comments',$data);
		$this->load->view('common/footer');
	}
	
	public function contact_us()
	{
		$query =$this->Data_access_model->select_all('hs_contact');
		
		if($query->num_rows() > 0){
	   
			$data['all_contacts'] =$query->result(); 
		 
		}else{ 
		
			$data['all_contacts'] = '';
		}
		$data['pagetitle'] ='Contact Us';
		$data['active_class']= 14;
		$this->load->view('common/header',$data);
		$this->load->view('comments/contactus_list',$data);
		$this->load->view('common/footer');
	}
	
	public function offers_list(){
	
	    $query =$this->Data_access_model->select_all('hs_offers');
		
		if($query->num_rows() > 0){
	   
			$data['all_offers'] =$query->result(); 
		 
		}else{ 
			$data['all_offers'] = '';
		}
			
		$query_prod =$this->Data_access_model->select_all('hs_products');
		
		if($query_prod->num_rows() > 0){
	   
			$data['all_products'] =$query_prod->result_array(); 
		 
		}else{ 
			$data['all_products'] = '';
		}	
		$data['pagetitle'] ='Offers';
		$data['active_class']= 15;
		$this->load->view('common/header',$data);
		$this->load->view('manage_offer/manage_offer',$data);
		$this->load->view('common/footer');
	}
	
	public function edit_offer()
	{
		if(isset($_POST['offer_id']) && $_POST['offer_id'] !='' )
		{
			$where_data =array('offer_id' =>$_POST['offer_id'],);
			$query=$this->Data_access_model->select_data('*','hs_offers',$where_data);
			if($query->num_rows() > 0){
				$edit_offer= $query->result_array();
				$resp = array('status'=>1, 'edit_offer'=>$edit_offer) ; 
			}else{
				$resp = array('status'=>0, 'error'=>'something went wroung. please try again!') ;
			}
		}else{
			$resp = array('status'=>0, 'error'=>'something went wroung. please try again!') ;
		}
		echo json_encode($resp);
	}
	
//**************** html view end *******************************//
	
	
//****************data add/update section start****************//
	   
	public function add_user(){

		$this->form_validation->set_rules('u_name','Name', 'trim|required');
        $this->form_validation->set_rules('u_email','Email', 'trim|required');	
        $this->form_validation->set_rules('u_mobile','Mobile', 'trim|required');
		$this->form_validation->set_rules('u_password','Password', 'trim|required');
        $this->form_validation->set_rules('u_address','Address','trim|required'); 
		if ($this->form_validation->run() == FALSE)
		{
			echo 0; 
		}else{
			$useremail = $this->input->post('u_email');
			$query = $this->Data_access_model->select_data('user_email','hs_user',array('user_email'=>$useremail));
			if($query->num_rows() > 0){ 
				$check_useremail = $query->row();
			if($check_useremail->user_email == $useremail){
				echo 2;
			}
			}else{
				$data = array(
							  'user_name' =>ucwords($this->input->post('u_name')),
							  'user_email' =>$this->input->post('u_email'),
							  'user_mobile' =>$this->input->post('u_mobile'),
							  'user_password' =>md5($this->input->post('u_password')),
							  'user_address'=>$this->input->post('u_address'),
							  'user_status'=>1,
							  'registration_date' =>date('d M Y H:i:s'),
							  'user_type' =>2,
							  );
								  
				$this->Data_access_model->insert_data('hs_user',$data); 
				if($this->db->affected_rows() > 0){	
					$send_mail = $this->input->post('u_emailsend');
					if($send_mail ==1){
						$user_name = ucwords($this->input->post('u_name'));
						$userpwd = $this->input->post('u_password');
						$to_useremail = $this->input->post('u_email');	
						$email_content = $this->hs->getwebsettings('register_template');  
						$email_content = str_replace("[username]",$user_name, $email_content);
						$email_content = str_replace("[Email]",$to_useremail, $email_content);
						$email_content = str_replace("[password]",$userpwd,$email_content);
						$email_content = str_replace("[break]", "<br>", $email_content);
						$data['emcontent'] = $email_content;
						$email_template = $this->load->view('theme/email_template',$data,true);
						$subject = $this->hs->getwebsettings('register_subject');
						//sending mail
						$this->hs->send_mail($to_useremail,$subject,$email_template);
					}
					echo 1;
				}else{
					echo 0;
				}
				}
			}
       }

	public function update_user()
	{
		$user_id =$this->input->post('u_id');
		if(!empty($user_id)){
			$data = array(
						'user_mobile' =>$this->input->post('u_mobile'),
						'user_address'=>$this->input->post('u_address'),
						);
				 
			$this->Data_access_model->update_data('hs_user',array('user_id' => $this->input->post('u_id')),$data); 
			echo 1;
		}else{
			echo 0;
		}
	}
	
	public function add_products(){
		$this->form_validation->set_rules('p_name','Name', 'trim|required');
		$this->form_validation->set_rules('p_category','Category', 'required');
        $this->form_validation->set_rules('p_description','Description', 'required');
		$this->form_validation->set_rules('p_longdescription','Long Description', 'required');
	    $this->form_validation->set_rules('p_price','Price', 'required');
 
		if ($this->form_validation->run() == FALSE)
		{
			echo 0; 
			
		}else{  
		    
			$product_name = $this->input->post('p_name');
			$product_slug = str_replace(' ','-',strtolower($product_name));
			if(isset($_FILES['file_uploade']))
		    {
			    $config['upload_path']      = './uploads/productimage';
                $config['allowed_types']    = 'gif|jpg|png|jpeg';
                $this->load->library('upload');
                $this->upload->initialize($config);
                if (!$this->upload->do_upload('file_uploade'))
                {
					echo 0;
			    }
                else
                { 
                    $imgdata = array('upload_data' => $this->upload->data());
					foreach($imgdata as  $path){
					$imagename = $path['file_name'];
					}
					$imagedata ='uploads/productimage/'.$imagename;
				    //***image resize for menu***//
                    $config['image_library'] = 'gd2';
                    $config['source_image']	='./uploads/productimage/'.$imagename;
                    $config['create_thumb'] = FALSE;
                    $config['maintain_ratio'] = FALSE;
                    $config['height']	= "260";
                    $config['width'] = "270";
                    $config['new_image'] ='./uploads/productimage/'.$imagename;//you should have write permission here..
					 
                    $this->image_lib->initialize($config);
                    if(!$this->image_lib->resize()){
						$error['resize'] = $this->image_lib->display_errors();
					 
					} 
					//***image resize for special menu***//
					$config['image_library'] = 'gd2';
                    $config['source_image']	='./uploads/productimage/'.$imagename;
                    $config['create_thumb'] = FALSE;
                    $config['maintain_ratio'] = FALSE;
                    $config['height']	= "65";
                    $config['width'] = "65";
                    $config['new_image'] ='./uploads/specialmenu_image/'.$imagename;//you should have write permission here..
					$this->image_lib->initialize($config);
                    if(!$this->image_lib->resize()){
						$error['resize'] = $this->image_lib->display_errors();
					}
					$specialmenu_image ='uploads/specialmenu_image/'.$imagename;
					
					//***image resize for special menu***//
					$config['image_library'] = 'gd2';
                    $config['source_image']	='./uploads/productimage/'.$imagename;
                    $config['create_thumb'] = FALSE;
                    $config['maintain_ratio'] = FALSE;
                    $config['height']	= "430";
                    $config['width'] = "570";
                    $config['new_image'] ='./uploads/singleprod_image/'.$imagename;//you should have write permission here..
					$this->image_lib->initialize($config);
                    if(!$this->image_lib->resize()){
						$error['resize'] = $this->image_lib->display_errors();
					}
					$singleprod_image ='uploads/singleprod_image/'.$imagename;
				}  
			}
	 
		        $data = array(
				           'prod_name' =>ucwords($this->input->post('p_name')),
						   'prod_cateid' =>$this->input->post('p_category'),
					       'prod_description'=>$this->input->post('p_description'),
						   'prod_price'=>$this->input->post('p_price'),
						   'prod_quantity' =>$this->input->post('p_quantity'),
						   'prod_image' =>  $imagedata,
						   'prod_specialmenu_img' =>$specialmenu_image,
						   'prod_date' =>date('d M Y H:i:s'),
						   'prod_longdescription' =>$this->input->post('p_longdescription'),
						   'prod_slug' => $product_slug,
						   'prod_code' =>rand(100000,999999),
						   'prod_singleimg' =>$singleprod_image
				        ); 
			   $this->Data_access_model->insert_data('hs_products',$data);  
			    echo 1;  
		    } 
	}
	
	public function update_products(){
		   	
		$this->form_validation->set_rules('p_name','Name', 'trim|required');
		$this->form_validation->set_rules('p_category','Category', 'required');
        $this->form_validation->set_rules('p_description','Description', 'required');
		$this->form_validation->set_rules('p_longdescription','Long Description', 'required');
	    $this->form_validation->set_rules('p_price','Price', 'required');
		
		if ($this->form_validation->run() == FALSE)
		{
			echo 0; 
			
		}else{  
			$product_name = $this->input->post('p_name');
			$product_slug = str_replace(' ','-',strtolower($product_name));
		
		    if(isset($_FILES['prod_image']) && $_FILES['prod_image']['name'] !=="")
		    {
			    $config['upload_path']      = './uploads/productimage';
                $config['allowed_types']    = 'gif|jpg|png|jpeg';
                $this->load->library('upload');
                $this->upload->initialize($config);
                if (!$this->upload->do_upload('prod_image'))
                {
					echo 0;
			    }
                else
                {             
			
                    $imgdata = array('upload_data' => $this->upload->data());
					foreach($imgdata as  $path){
					$imagename = $path['file_name'];
					}
					$imagedata ='uploads/productimage/'.$imagename;
					
					   //***image resize for menu***// 
                    $config['image_library'] = 'gd2';
                    $config['source_image']	='./uploads/productimage/'.$imagename;
                    $config['create_thumb'] = FALSE;
                    $config['maintain_ratio'] = FALSE;
                    $config['height']	= "260";
                    $config['width'] = "270";
                    $config['new_image'] ='./uploads/productimage/'.$imagename;
					//you should have write permission here..
					 
                    $this->image_lib->initialize($config);
                    if(!$this->image_lib->resize()){
						$error['resize'] = $this->image_lib->display_errors();
					 
					} 
					
                    //***image resize for special menu***//
					$config['image_library'] = 'gd2';
                    $config['source_image']	='./uploads/productimage/'.$imagename;
                    $config['create_thumb'] = FALSE;
                    $config['maintain_ratio'] = FALSE;
                    $config['height']	= "65";
                    $config['width'] = "65";
                    $config['new_image'] ='./uploads/specialmenu_image/'.$imagename;
					//you should have write permission here..
					 
                    $this->image_lib->initialize($config);
                    if(!$this->image_lib->resize()){
						$error['resize'] = $this->image_lib->display_errors();
					 
					}					
						$specialmenu_image ='uploads/specialmenu_image/'.$imagename;
						
					//***image resize for special menu***//
					$config['image_library'] = 'gd2';
                    $config['source_image']	='./uploads/productimage/'.$imagename;
                    $config['create_thumb'] = FALSE;
                    $config['maintain_ratio'] = FALSE;
                    $config['height']	= "430";
                    $config['width'] = "570";
                    $config['new_image'] ='./uploads/singleprod_image/'.$imagename;//you should have write permission here..
					$this->image_lib->initialize($config);
                    if(!$this->image_lib->resize()){
						$error['resize'] = $this->image_lib->display_errors();
					}
					$singleprod_image ='uploads/singleprod_image/'.$imagename;	
				} 
                     $data = array(
				           'prod_name' =>ucwords($this->input->post('p_name')),
						   'prod_cateid' =>$this->input->post('p_category'),
					       'prod_description'=>$this->input->post('p_description'),
						   'prod_price'=>$this->input->post('p_price'),
						   'prod_quantity' =>$this->input->post('p_quantity'),
						   'prod_image' =>  $imagedata,
						   'prod_specialmenu_img' =>$specialmenu_image,
						   'prod_longdescription' =>$this->input->post('p_longdescription'),
						   'prod_slug' => $product_slug,
						   'prod_singleimg' =>$singleprod_image
				        ); 
            }
			else{
	                $data = array(
				           'prod_name' =>ucwords($this->input->post('p_name')),
						   'prod_cateid' =>$this->input->post('p_category'),
					       'prod_description'=>$this->input->post('p_description'),
						   'prod_price'=>$this->input->post('p_price'),
						   'prod_quantity' =>$this->input->post('p_quantity'),
						   'prod_longdescription' =>$this->input->post('p_longdescription'),
						   'prod_slug' => $product_slug,
						  ); 
			    }						
				$this->Data_access_model->update_data('hs_products',array('prod_id' => $this->input->post('old_prod_id')),$data);  
				echo 1;  
	    } 
	}
	
	public function addtable(){
		  
		$this->form_validation->set_rules('t_name','name', 'required');	
		$this->form_validation->set_rules('t_number','number', 'required');
		$this->form_validation->set_rules('t_capacity','capacity', 'required');
		  
		if ($this->form_validation->run() == FALSE)
		{
			echo 0; 
			
		}else{
			
			if(isset($_FILES['t_image']) && $_FILES['t_image']['name'] !=="")
		    {
			    $config['upload_path']      = './uploads/bookingtable_image';
                $config['allowed_types']    = 'gif|jpg|png|jpeg';
                $this->load->library('upload');
                $this->upload->initialize($config);
                if (!$this->upload->do_upload('t_image'))
                {
                    $error = array('error' => $this->upload->display_errors());
		            echo 0;
			    }
                else
                {  
                    $imgdata = array('upload_data' => $this->upload->data());
					foreach($imgdata as  $path){
					$imagename = $path['file_name'];
					}
					$imagedata ='uploads/bookingtable_image/'.$imagename;
					  //***image resize for menu***// 
					list($width, $height) = getimagesize($imagedata);
                    $config['image_library'] = 'gd2';
                    $config['source_image']	='./uploads/bookingtable_image/'.$imagename;
                    $config['create_thumb'] = FALSE;
                    $config['maintain_ratio'] = FALSE;
                    $config['height']	= "108";
                    if($width <= 110){
						$config['width'] = "108";
					}else{
						$config['width'] = "180";
					}
                    $config['new_image'] ='./uploads/bookingtable_image/'.$imagename;
					//you should have write permission here..
					$this->image_lib->initialize($config);
					if(!$this->image_lib->resize()){
						$error['resize'] = $this->image_lib->display_errors();
					}					
				}
				$data = array(
				                'table_name' =>$this->input->post('t_name'),
						        'table_no' => $this->input->post('t_number'),
						        'table_capacity' =>$this->input->post('t_capacity'),
								'table_image' =>$imagedata,
					        );
	            $this->Data_access_model->insert_data('hs_table_details',$data);
		        echo 1;
		    }
        }
	}
	
	public function update_table(){
		  
		$this->form_validation->set_rules('t_name','name', 'required');	
		$this->form_validation->set_rules('t_number','number', 'required');
		$this->form_validation->set_rules('t_capacity','capacity', 'required');
		if ($this->form_validation->run() == FALSE)
		{
			echo 0; 
			
		}else{
				if(isset($_FILES['t_image']) && $_FILES['t_image']['name'] !=="")
				{
					$config['upload_path']      = './uploads/bookingtable_image';
					$config['allowed_types']    = 'gif|jpg|png|jpeg';
					$this->load->library('upload');
					$this->upload->initialize($config);
					if (!$this->upload->do_upload('t_image'))
					{
						$error = array('error' => $this->upload->display_errors());
					    echo 0;
					}
					else
					{  
						$imgdata = array('upload_data' => $this->upload->data());
						foreach($imgdata as  $path){
							$imagename = $path['file_name'];
						}
						$imagedata ='uploads/bookingtable_image/'.$imagename;
							  //***image resize for menu***// 
						list($width, $height) = getimagesize($imagedata);
						 
						$config['image_library'] = 'gd2';
						$config['source_image']	='./uploads/bookingtable_image/'.$imagename;
						$config['create_thumb'] = FALSE;
						$config['maintain_ratio'] = FALSE;
						$config['height']	= "108";
						if($width <= 110){
							$config['width'] = "108";
						}else{
							$config['width'] = "180";
						}
						
						$config['new_image'] ='./uploads/bookingtable_image/'.$imagename; 
						//you should have write permission here..
						 $this->image_lib->initialize($config);
						if(!$this->image_lib->resize()){
							$error['resize'] = $this->image_lib->display_errors();
						} 	
							 
						$data = array(
				                'table_name' => $this->input->post('t_name'),
						        'table_no' =>  $this->input->post('t_number'),
						        'table_capacity' =>$this->input->post('t_capacity'),
								'table_image' =>$imagedata,
					        );	
					}
			}else{
						$data = array(
				                'table_name' => $this->input->post('t_name'),
						        'table_no' =>  $this->input->post('t_number'),
						        'table_capacity' =>$this->input->post('t_capacity'),
					          );
				}
				$this->Data_access_model->update_data('hs_table_details',array('table_id' => $this->input->post('t_id')),$data); 			
				echo 1;
			}
	}
	
    public function add_category(){
		
		$this->form_validation->set_rules('catename','Name', 'required');	
	    $this->form_validation->set_rules('cate_descri','Description', 'required');
	     if ($this->form_validation->run() == FALSE)
		{
	        echo 0; 
			
		}else{
			$cate_name = $this->input->post('catename');
			$cate_slug = str_replace(' ','-',strtolower($cate_name));
			if(isset($_FILES['cateimage']))
		    {
			    $config['upload_path']      = './uploads/cateimage';
                $config['allowed_types']    = 'gif|jpg|png|jpeg';
                $this->load->library('upload');
                $this->upload->initialize($config);
                if (!$this->upload->do_upload('cateimage'))
                {
                    //$error = array('error' => $this->upload->display_errors());
		           echo 0;
			    }
                else
                { 
			 
                     $imgdata = array('upload_data' => $this->upload->data());
					foreach($imgdata as  $path){
						$imagename = $path['file_name']; 
					}
					$imagedata ='uploads/cateimage/'.$imagename;
                    
                    $config['image_library'] = 'gd2';
                    $config['source_image']	='./uploads/cateimage/'.$imagename;
                    $config['create_thumb'] = FALSE;
                    $config['maintain_ratio'] = FALSE;
                    $config['height']	= "350";
                    $config['width'] = "350";
                    $config['new_image'] ='./uploads/cateimage/'.$imagename;//you should have write permission here..
					  
                    $this->image_lib->initialize($config);
                    if(!$this->image_lib->resize()){
						$error['resize'] = $this->image_lib->display_errors();
					}					 
				}  
			}
                $data = array(
			                    'category_name' =>ucwords($this->input->post('catename')),
								'category_description' =>$this->input->post('cate_descri'),
								'category_image' =>$imagedata,
								'category_slug' => $cate_slug,
						    );
							
				$this->Data_access_model->insert_data('hs_category',$data);	  
				echo 1; 
		    } 
	}	 

	
	public function update_category(){
		 
		$this->form_validation->set_rules('up_catename','Name', 'required');	
	    $this->form_validation->set_rules('up_catedescri','Description', 'required');
	     if ($this->form_validation->run() == FALSE)
		{
	        echo 0; 
			
		}else{
				$upcate_name = $this->input->post('up_catename');
				$upcate_slug = str_replace(' ','-',strtolower($upcate_name));
			
			if(isset($_FILES['up_cateimage']) && $_FILES['up_cateimage']['name'] !=="")
		    {
			    $config['upload_path']      = './uploads/cateimage';
                $config['allowed_types']    = 'gif|jpg|png|jpeg';
                $this->load->library('upload');
                $this->upload->initialize($config);
                if (!$this->upload->do_upload('up_cateimage'))
                {
                    $error = array('error' => $this->upload->display_errors());
		           echo 0;
			    }
                else
                { 
			        $imgdata = array('upload_data' => $this->upload->data());
					foreach($imgdata as  $path){
					$imagename = $path['file_name']; 
					}
					$imagedata ='uploads/cateimage/'.$imagename; 
					
					 
                    $config['image_library'] = 'gd2';
                    $config['source_image']	='./uploads/cateimage/'.$imagename;
                    $config['create_thumb'] = FALSE;
                    $config['maintain_ratio'] = FALSE;
                    $config['height']	= "350";
                    $config['width'] = "350";
                    $config['new_image'] ='./uploads/cateimage/'.$imagename;//you should have write permission here..
					 
                    $this->image_lib->initialize($config);
                    if(!$this->image_lib->resize()){
						$error['resize'] = $this->image_lib->display_errors();
					} 
				}  
				 
				 $data = array(
			                    'category_name' =>ucwords($this->input->post('up_catename')),
								'category_description' =>$this->input->post('up_catedescri'),
								'category_image' =>$imagedata,
								'category_slug' =>$upcate_slug,
						      );
		}else{  
                  $data = array(
			                    'category_name' =>ucwords($this->input->post('up_catename')),
								'category_description' => $this->input->post('up_catedescri'),
								'category_slug' =>$upcate_slug, 
						    );
			}
			 	$this->Data_access_model->update_data('hs_category',array('category_id' => $this->input->post('old_cateid')),$data);	 
			    echo 1; 
		} 
	}
	
	public function add_blogcategory(){
		
		$this->form_validation->set_rules('cate_name','Name', 'required');	
	 
	    if ($this->form_validation->run() == FALSE)
		{
	        echo 0; 
			
		}else{
			    $data = array(
			                    'cate_name' =>ucwords($this->input->post('cate_name')),
						    );
				$this->Data_access_model->insert_data('hs_blog_category',$data);	  
				echo 1;
		    }
	}
	
	public function update_blogcategory(){
		
		$this->form_validation->set_rules('cate_name','Name', 'required');	
	 
	    if ($this->form_validation->run() == FALSE)
		{
	        echo 0; 
			
		}else{
			    $data = array(
			                   'cate_name' =>ucwords($this->input->post('cate_name')),
						    );
				$this->Data_access_model->update_data('hs_blog_category',array('cate_id' => $this->input->post('bcate_id')),$data); 			  
			    echo 1;
		    }
	}
	
	public function add_blog_data(){
		
		$this->form_validation->set_rules('blog_title','Title', 'trim|required');	
		$this->form_validation->set_rules('blog_cate','Category', 'required');
		$this->form_validation->set_rules('blog_content','Content', 'required');
        if ($this->form_validation->run() == FALSE)
		{
			echo 0; 
			
		}else{  
					$blog_title = $this->input->post('blog_title');
			        $blogslug = str_replace(' ','-',strtolower($blog_title));
		    if(isset($_FILES['blog_image']))
		    {
			    $config['upload_path']      = './uploads/blogimage';
                $config['allowed_types']    = 'gif|jpg|png|jpeg';
                $this->load->library('upload');
                $this->upload->initialize($config);
                if (!$this->upload->do_upload('blog_image'))
                {
                    //$error = array('error' => $this->upload->display_errors());
		           echo 0;
			    }
                else
                { 
                    $imgdata = array('upload_data' => $this->upload->data());
					foreach($imgdata as  $path){
					$imagename = $path['file_name'];
					}
					$imagedata ='uploads/blogimage/'.$imagename;
					 
                    $config['image_library'] = 'gd2';
                    $config['source_image']	='./uploads/blogimage/'.$imagename;
                    $config['create_thumb'] = FALSE;
                    $config['maintain_ratio'] = FALSE;
                    $config['height']	= "380";
                    $config['width'] = "570";
                    $config['new_image'] ='./uploads/blogimage/'.$imagename;
					//you should have write permission here..
					 
                    $this->image_lib->initialize($config);
                    if(!$this->image_lib->resize()){
						$error['resize'] = $this->image_lib->display_errors();
					 
					}
					//***************image resize for blog single page ***********// 
					$config['image_library'] = 'gd2';
                    $config['source_image']	='./uploads/blogimage/'.$imagename;
                    $config['create_thumb'] = FALSE;
                    $config['maintain_ratio'] = FALSE;
                    $config['height']	= "459";
                    $config['width'] = "840";
                    $config['new_image'] ='./uploads/blogsingleimage/'.$imagename;
					//you should have write permission here..
					 
                    $this->image_lib->initialize($config);
                    if(!$this->image_lib->resize()){
						$error['resize'] = $this->image_lib->display_errors();
					 
					}
					
					$blogsingle_img ='uploads/blogsingleimage/'.$imagename;
					
				}  
			}
	 
		        $data = array(
				           'blog_title' =>ucwords($this->input->post('blog_title')),
						   'blog_userid' =>$this->input->post('blog_userid'),
						   'blog_category' =>$this->input->post('blog_cate'),
					       'blog_content'=>$this->input->post('blog_content'),
						   'blog_longcontent'=>$this->input->post('longblog_content'),
						   'blog_image' =>$imagedata,
						   'blogsingle_image' =>$blogsingle_img,
						   'blog_date' =>date('d M Y H:i:s'),
						   'blog_slug' =>$blogslug,
						   ); 
			    $this->Data_access_model->insert_data('hs_blogs',$data);  
			    echo 1;  
		    }
	}
	
	public function update_blog_data(){
		
	    $this->form_validation->set_rules('blog_title','Title', 'trim|required');	
		$this->form_validation->set_rules('blog_cate','Category', 'required');
		$this->form_validation->set_rules('blog_content','Content', 'required');
		if ($this->form_validation->run() == FALSE)
		{
			echo 0; 
			
		}else{
			    $blog_title = $this->input->post('blog_title');
			    $blogslug = str_replace(' ','-',strtolower($blog_title));
			if(isset($_FILES['blog_image']) && $_FILES['blog_image']['name'] !=="")
		    {
			    $config['upload_path']      = './uploads/blogimage';
                $config['allowed_types']    = 'gif|jpg|png|jpeg';
                $this->load->library('upload');
                $this->upload->initialize($config);
                if (!$this->upload->do_upload('blog_image'))
                {
                    //$error = array('error' => $this->upload->display_errors());
		           echo 0;
			    }
                else
                { 
                    $imgdata = array('upload_data' => $this->upload->data());
					foreach($imgdata as  $path){
					$imagename = $path['file_name'];
					}
					$imagedata ='uploads/blogimage/'.$imagename;
				 
                    $config['image_library'] = 'gd2';
                    $config['source_image']	='./uploads/blogimage/'.$imagename;
                    $config['create_thumb'] = FALSE;
                    $config['maintain_ratio'] = FALSE;
                    $config['height']	= "380";
                    $config['width'] = "570";
                    $config['new_image'] ='./uploads/blogimage/'.$imagename;//you should have write permission here..
					 
                    $this->image_lib->initialize($config);
                    if(!$this->image_lib->resize()){
						$error['resize'] = $this->image_lib->display_errors();
					 
					}
					
					//***************image resize for blog single page ***********// 
					$config['image_library'] = 'gd2';
                    $config['source_image']	='./uploads/blogimage/'.$imagename;
                    $config['create_thumb'] = FALSE;
                    $config['maintain_ratio'] = FALSE;
                    $config['height']	= "459";
                    $config['width'] = "840";
                    $config['new_image'] ='./uploads/blogsingleimage/'.$imagename;
					 
					$this->image_lib->initialize($config);
                    if(!$this->image_lib->resize()){
						$error['resize'] = $this->image_lib->display_errors();
					}
					
					$blogsingle_img ='uploads/blogsingleimage/'.$imagename;
				}  
				   $data = array(
				           'blog_title' =>ucwords($this->input->post('blog_title')),
						   'blog_category' =>$this->input->post('blog_cate'),
					       'blog_content'=>$this->input->post('blog_content'),
						   'blog_longcontent'=>$this->input->post('longblog_content'),
						   'blog_image' =>$imagedata,
						   'blogsingle_image' =>$blogsingle_img,
						   'blog_slug' =>$blogslug,
						   ); 
			}else{
			        $data = array(
				           'blog_title' =>ucwords($this->input->post('blog_title')),
						   'blog_category' =>$this->input->post('blog_cate'),
					       'blog_content'=>$this->input->post('blog_content'),
						   'blog_longcontent'=>$this->input->post('longblog_content'),
						   'blog_slug' =>$blogslug,
						); 
			    }
				   $this->Data_access_model->update_data('hs_blogs',array('blog_id' => $this->input->post('blog_id')),$data); 
					echo 1;
		    }
	}
	
	public function add_testimonial(){
		
		$this->form_validation->set_rules('testi_name','Name', 'required');	
		$this->form_validation->set_rules('testi_desig','Designation', 'required');
		$this->form_validation->set_rules('testi_msg','Massage', 'required');
         
		if ($this->form_validation->run() == FALSE)
		{
			echo 0; 
			
		}else{  
		
		
		    if(isset($_FILES['testi_image']))
		    {
			    $config['upload_path']      = './uploads/testimoimage';
                $config['allowed_types']    = 'gif|jpg|png|jpeg';
                $this->load->library('upload');
                $this->upload->initialize($config);
                if (!$this->upload->do_upload('testi_image'))
                {
                    //$error = array('error' => $this->upload->display_errors());
		         echo 0;  
			    }
                else
                { 
                    $imgdata = array('upload_data' => $this->upload->data());
					foreach($imgdata as  $path){
					$imagename = $path['file_name'];
					}
					$imagedata ='uploads/testimoimage/'.$imagename;
					 
                    $config['image_library'] = 'gd2';
                    $config['source_image']	='./uploads/testimoimage/'.$imagename;
                    $config['create_thumb'] = FALSE;
                    $config['maintain_ratio'] = FALSE;
                    $config['height']	= "240";
                    $config['width'] = "240";
                    $config['new_image'] ='./uploads/testimoimage/'.$imagename;//you should have write permission here..
					 
                    $this->image_lib->initialize($config);
                    if(!$this->image_lib->resize()){
						$error['resize'] = $this->image_lib->display_errors();
					} 
				}  
			}
	 
		        $data = array(
				           'testi_name' =>ucwords($this->input->post('testi_name')),
						   'testi_desig' =>ucwords($this->input->post('testi_desig')),
					       'testi_msg'=>$this->input->post('testi_msg'),
						   'testi_image' =>$imagedata,
						   'testi_facebook_link' =>$this->input->post('testi_facebook_link'),
						   'testi_youtube_link' =>$this->input->post('testi_youtube_link'),
						   'testi_twitter_link' =>$this->input->post('testi_twitter_link'),
						   'testi_linkedin_link' =>$this->input->post('testi_linkedin_link'),
						   ); 
			    $this->Data_access_model->insert_data('hs_testimonial',$data);  
			    echo 1;  
		    }
	}
	
	public function updatetestimo(){
		
		$this->form_validation->set_rules('testi_name','Name', 'required');	
		$this->form_validation->set_rules('testi_desig','Designation', 'required');
		$this->form_validation->set_rules('testi_msg','Massage', 'required');
        
		if ($this->form_validation->run() == FALSE)
		{
			echo 0; 
			
		}else{  
		
			if(isset($_FILES['testi_image']) && $_FILES['testi_image']['name'] !=="")
		    {
			    $config['upload_path']      = './uploads/testimoimage';
                $config['allowed_types']    = 'gif|jpg|png|jpeg';
                $this->load->library('upload');
                $this->upload->initialize($config);
                if (!$this->upload->do_upload('testi_image'))
                {
                    //$error = array('error' => $this->upload->display_errors());
		           echo 0;
			    }
                else
                { 
                    $imgdata = array('upload_data' => $this->upload->data());
					foreach($imgdata as  $path){
					$imagename = $path['file_name'];
					}
					$imagedata ='uploads/testimoimage/'.$imagename;
					 
                    $config['image_library'] = 'gd2';
                    $config['source_image']	='./uploads/testimoimage/'.$imagename;
                    $config['create_thumb'] = FALSE;
                    $config['maintain_ratio'] = FALSE;
                    $config['height']	= "240";
                    $config['width'] = "240";
                    $config['new_image'] ='./uploads/testimoimage/'.$imagename;
					
					//you should have write permission here..
					 
                    $this->image_lib->initialize($config);
                    if(!$this->image_lib->resize()){
						$error['resize'] = $this->image_lib->display_errors();
					 
					}
				}  
				$data = array(
				           'testi_name' =>ucwords($this->input->post('testi_name')),
						   'testi_desig' =>ucwords($this->input->post('testi_desig')),
					       'testi_msg'=>$this->input->post('testi_msg'),
						   'testi_image' =>$imagedata,
						   'testi_facebook_link' =>$this->input->post('testi_facebook_link'),
						   'testi_youtube_link' =>$this->input->post('testi_youtube_link'),
						   'testi_twitter_link' =>$this->input->post('testi_twitter_link'),
						   'testi_linkedin_link' =>$this->input->post('testi_linkedin_link'),
						   ); 
			}else{
	 
		            $data = array(
				           'testi_name' =>ucwords($this->input->post('testi_name')),
						   'testi_desig' =>ucwords($this->input->post('testi_desig')),
					       'testi_msg'=>$this->input->post('testi_msg'),
						   'testi_facebook_link' =>$this->input->post('testi_facebook_link'),
						   'testi_youtube_link' =>$this->input->post('testi_youtube_link'),
						   'testi_twitter_link' =>$this->input->post('testi_twitter_link'),
						   'testi_linkedin_link' =>$this->input->post('testi_linkedin_link'),
						); 
			    }   
                $this->Data_access_model->update_data('hs_testimonial',array('testi_id' => $this->input->post('old_testi_id')),$data);
				echo 1;  
			}
	}
	
	public function add_chefmember(){
		
		$this->form_validation->set_rules('chef_name','Name', 'required');	
		$this->form_validation->set_rules('chef_desig','Designation', 'required');
	    if ($this->form_validation->run() == FALSE)
		{
			echo 0; 
			
		}else{  
		
			if(isset($_FILES['chef_image']))
		    {
			    $config['upload_path']      = './uploads/chefimage';
                $config['allowed_types']    = 'gif|jpg|png|jpeg';
                $this->load->library('upload');
                $this->upload->initialize($config);
                if (!$this->upload->do_upload('chef_image'))
                {
                    //$error = array('error' => $this->upload->display_errors());
		           echo 0;
			    }
                else
                { 
                    $imgdata = array('upload_data' => $this->upload->data());
					foreach($imgdata as  $path){
					    $imagename = $path['file_name'];
					}
					$imagedata ='uploads/chefimage/'.$imagename;
					
					 
                    $config['image_library'] = 'gd2';
                    $config['source_image']	='./uploads/chefimage/'.$imagename;
                    $config['create_thumb'] = FALSE;
                    $config['maintain_ratio'] = FALSE;
                    $config['height']	= "370";
                    $config['width'] = "270";
                    $config['new_image'] ='./uploads/chefimage/'.$imagename;//you should have write permission here..
					 
                    $this->image_lib->initialize($config);
                    if(!$this->image_lib->resize()){
						$error['resize'] = $this->image_lib->display_errors();
					 
					} 
				}  
			}
	 
		        $data = array(
				           'chef_name' =>ucwords($this->input->post('chef_name')),
						   'chef_desig' =>ucwords($this->input->post('chef_desig')),
						   'chef_facebook' =>$this->input->post('chef_facebook_link'),
						   'chef_youtube' =>$this->input->post('chef_youtube_link'),
						   'chef_twitter' =>$this->input->post('chef_twitter_link'),
						   'chef_linkedin' =>$this->input->post('chef_linkedin_link'),
					       'chef_image' =>$imagedata,
						   ); 
			    $this->Data_access_model->insert_data('hs_chef_team',$data);  
			    echo 1;  
		    }
	}
	
	public function update_chefmember(){
		
		$this->form_validation->set_rules('chef_name','Name', 'required');	
		$this->form_validation->set_rules('chef_desig','Designation', 'required');
	   
		if ($this->form_validation->run() == FALSE)
		{
			echo 0; 
			
		}else{  
		
			if(isset($_FILES['chef_image']) && $_FILES['chef_image']['name'] !=="")
		    {
			    $config['upload_path']      = './uploads/chefimage';
                $config['allowed_types']    = 'gif|jpg|png|jpeg';
                $this->load->library('upload');
                $this->upload->initialize($config);
                if (!$this->upload->do_upload('chef_image'))
                {
                    //$error = array('error' => $this->upload->display_errors());
		           echo 0;
			    }
                else
                { 
                    $imgdata = array('upload_data' => $this->upload->data());
					foreach($imgdata as  $path){
					$imagename = $path['file_name'];
					}
					$imagedata ='uploads/chefimage/'.$imagename;
					
				 
                    $config['image_library'] = 'gd2';
                    $config['source_image']	='./uploads/chefimage/'.$imagename;
                    $config['create_thumb'] = FALSE;
                    $config['maintain_ratio'] = FALSE;
                    $config['height']	= "370";
                    $config['width'] = "270";
                    $config['new_image'] ='./uploads/chefimage/'.$imagename; 
					 
                    $this->image_lib->initialize($config);
                    if(!$this->image_lib->resize()){
						$error['resize'] = $this->image_lib->display_errors();
					 } 
				}  
				$data = array(
				           'chef_name' =>ucwords($this->input->post('chef_name')),
						   'chef_desig' =>ucwords($this->input->post('chef_desig')),
						   'chef_facebook' =>$this->input->post('chef_facebook_link'),
						   'chef_youtube' =>$this->input->post('chef_youtube_link'),
						   'chef_twitter' =>$this->input->post('chef_twitter_link'),
						   'chef_linkedin' =>$this->input->post('chef_linkedin_link'),
					       'chef_image' =>$imagedata,
						   );
			}else{
	 
		        $data = array(
				           'chef_name' =>ucwords($this->input->post('chef_name')),
						   'chef_desig' =>ucwords($this->input->post('chef_desig')),
						   'chef_facebook' =>$this->input->post('chef_facebook_link'),
						   'chef_youtube' =>$this->input->post('chef_youtube_link'),
						   'chef_twitter' =>$this->input->post('chef_twitter_link'),
						   'chef_linkedin' =>$this->input->post('chef_linkedin_link'),
					    );
			}						   
				$this->Data_access_model->update_data('hs_chef_team',array('chef_id' => $this->input->post('old_chef_id')),$data);
				echo 1;  
		    }
	}
	
	public function add_portfolio(){
		
			if(isset($_FILES['portfolio_image']))
		    {
			    $config['upload_path']      = './uploads/portfolioimage';
                $config['allowed_types']    = 'gif|jpg|png|jpeg';
                $this->load->library('upload');
                $this->upload->initialize($config);
                if (!$this->upload->do_upload('portfolio_image'))
                {
                    //$error = array('error' => $this->upload->display_errors());
		           echo 0;
			    }
                else
                { 
					 
                    $imgdata = array('upload_data' => $this->upload->data());
					foreach($imgdata as  $path){
					$imagename = $path['file_name'];
					}
					$imagedata ='uploads/portfolioimage/'.$imagename;
					$config['image_library'] = 'gd2';
                    $config['source_image']	='./uploads/portfolioimage/'.$imagename;
                    $config['create_thumb'] = FALSE;
                    $config['maintain_ratio'] = FALSE;
					$config['width'] = "370";
					$config['height'] = "300";
                    $config['new_image'] ='./uploads/portfolioimage/'.$imagename;//you should have write permission here..
					
					
					$data = array('portfolio_image' =>$imagedata); 
					$this->Data_access_model->insert_data('hs_portfolio',$data);  
					if($this->db->affected_rows() > 0){
						echo 1; 
					}
			    }  
			}
		}
	
	public function update_portfolio(){
		
			if(isset($_FILES['update_portfolio_img']))
		    {
			    $config['upload_path']  = './uploads/portfolioimage';
                $config['allowed_types'] = 'gif|jpg|png|jpeg';
                $this->load->library('upload');
                $this->upload->initialize($config);
                if (!$this->upload->do_upload('update_portfolio_img'))
                {
                    //$error = array('error' => $this->upload->display_errors());
		           echo 123;
			    }
                else
                {  
					 
					$imgdata = array('upload_data' => $this->upload->data());
					foreach($imgdata as  $path){
					$imagename = $path['file_name'];
					}
					$imagedata ='uploads/portfolioimage/'.$imagename;
					
					$config['image_library'] = 'gd2';
                    $config['source_image']	='./uploads/portfolioimage/'.$imagename;
                    $config['create_thumb'] = FALSE;
                    $config['maintain_ratio'] = FALSE;
					$config['width'] = "370";
					$config['height']	= "300";
                    $config['new_image'] ='./uploads/portfolioimage/'.$imagename;//you should have write permission here..
					 
                    $this->image_lib->initialize($config);
                    if(!$this->image_lib->resize()){
						$error['resize'] = $this->image_lib->display_errors();
					 
					} 
					
					$data = array('portfolio_image' =>$imagedata); 
					 
					$this->Data_access_model->update_data('hs_portfolio',array('portfolio_id' => $this->input->post('old_portfolio_id')),$data);
					if($this->db->affected_rows() >0){
						echo 1; 
					}
				}  
			}
		}
	
	public function add_partners(){
		
		
			if(isset($_FILES['partners_image']))
		    {
			    $config['upload_path']      = './uploads/partnerimage';
                $config['allowed_types']    = 'gif|jpg|png|jpeg';
                $this->load->library('upload');
                $this->upload->initialize($config);
                if (!$this->upload->do_upload('partners_image'))
                {
                    //$error = array('error' => $this->upload->display_errors());
		           echo 0;
			    }
                else
                { 
                    $imgdata = array('upload_data' => $this->upload->data());
					foreach($imgdata as  $path){
					$imagename = $path['file_name'];
					}
					$imagedata ='uploads/partnerimage/'.$imagename;
					
					$config['image_library'] = 'gd2';
                    $config['source_image']	='./uploads/partnerimage/'.$imagename;
                    $config['create_thumb'] = FALSE;
                    $config['maintain_ratio'] = FALSE;
                    $config['height']	= "100";
                    $config['width'] = "88";
                    $config['new_image'] ='./uploads/partnerimage/'.$imagename;//you should have write permission here..
					 
                    $this->image_lib->initialize($config);
                    if(!$this->image_lib->resize()){
						$error['resize'] = $this->image_lib->display_errors();
					 
					}
					$data = array(
				                 'partner_image' =>$imagedata,
								 ); 
					$this->Data_access_model->insert_data('hs_partners',$data);
                    echo 1;					
				}  
			}
    }
	
	public function update_partners(){
		
		    if(isset($_FILES['update_partner_image']))
		    {
			    $config['upload_path']      = './uploads/partnerimage';
                $config['allowed_types']    = 'gif|jpg|png|jpeg';
                $this->load->library('upload');
                $this->upload->initialize($config);
                if (!$this->upload->do_upload('update_partner_image'))
                {
                    //$error = array('error' => $this->upload->display_errors());
		           echo 0;
			    }
                else
                { 
                    $imgdata = array('upload_data' => $this->upload->data());
					foreach($imgdata as  $path){
					$imagename = $path['file_name'];
					}
					$imagedata ='uploads/partnerimage/'.$imagename;
					
					$config['image_library'] = 'gd2';
                    $config['source_image']	='./uploads/partnerimage/'.$imagename;
                    $config['create_thumb'] = FALSE;
                    $config['maintain_ratio'] = FALSE;
                    $config['height']	= "100";
                    $config['width'] = "88";
                    $config['new_image'] ='./uploads/partnerimage/'.$imagename;//you should have write permission here..
					 
                    $this->image_lib->initialize($config);
                    if(!$this->image_lib->resize()){
						$error['resize'] = $this->image_lib->display_errors();
					}
					$data = array( 'partner_image' =>$imagedata); 
					$this->Data_access_model->update_data('hs_partners',array('partner_id' => $this->input->post('old_partnerid')),$data);
					if($this->db->affected_rows() >0){
						echo 1; 
					}
				}  
			}
	}
	
	public function add_pages(){
		
		$this->form_validation->set_rules('page_heading','Heading', 'required');	
		$this->form_validation->set_rules('page_title','Title', 'required');
		$this->form_validation->set_rules('page_msg','Massage', 'required');
        
		if ($this->form_validation->run() == FALSE)
		{
			echo 0; 
			
		}else{  
		
		
		    if(isset($_FILES['page_image']))
		    {
			    $config['upload_path']      = './uploads/pagesimage';
                $config['allowed_types']    = 'gif|jpg|png|jpeg';
                $this->load->library('upload');
                $this->upload->initialize($config);
                if (!$this->upload->do_upload('page_image'))
                {
                    //$error = array('error' => $this->upload->display_errors());
		           echo 0;
			    }
                else
                { 
                    $imgdata = array('upload_data' => $this->upload->data());
					foreach($imgdata as  $path){
					$imagename = $path['file_name'];
					}
					$imagedata ='uploads/pagesimage/'.$imagename;
					 
                    $config['image_library'] = 'gd2';
                    $config['source_image']	='./uploads/pagesimage/'.$imagename;
                    $config['create_thumb'] = FALSE;
                    $config['maintain_ratio'] = FALSE;
                    $config['height']	= "400";
                    $config['width'] = "511";
                    $config['new_image'] ='./uploads/pagesimage/'.$imagename;//you should have write permission here..
					 
                    $this->image_lib->initialize($config);
                    if(!$this->image_lib->resize()){
						$error['resize'] = $this->image_lib->display_errors();
					} 
				}  
			}
	 
		        $data = array(
				           'page_heading' =>$this->input->post('page_heading'),
						   'page_title' =>$this->input->post('page_title'),
					       'page_image' =>$imagedata,
						   'page_massage'=>$this->input->post('page_msg'),
						   ); 
						   
			    $this->Data_access_model->insert_data('hs_pages',$data);  
			    echo 1;  
		    }
	}
	
	public function update_comments(){
		  
		$this->form_validation->set_rules('up_cooment_name','Name', 'required');	
		$this->form_validation->set_rules('up_cooment_email','Email', 'required');
		$this->form_validation->set_rules('up_comment_content','Content', 'required');
		//$this->form_validation->set_rules('up_cooment_date','Date', 'required');
		 
		if ($this->form_validation->run() == FALSE)
		{
			echo 0; 
			
		}else{
		        $data = array(
				                'comment_name' => $this->input->post('up_cooment_name'),
						        'comment_email' =>  $this->input->post('up_cooment_email'),
						        'comment_content' =>$this->input->post('up_comment_content'),
						        //'comment_date'  =>date('d M Y H:i:s'),
					        );
				$this->Data_access_model->update_data('hs_comment',array('comment_id' => $this->input->post('old_commentid')),$data); 			
				echo 1;
		    }
	}

	public function update_pages(){
		
		$this->form_validation->set_rules('page_heading','Heading', 'required');	
		$this->form_validation->set_rules('page_title','Title', 'required');
		$this->form_validation->set_rules('page_shortcontn','Short Content', 'required');
		$this->form_validation->set_rules('page_msg','Long Content', 'required');
         
	    if ($this->form_validation->run() == FALSE)
		{
			echo 0; 
			
		}else{  
		
		
		    if(isset($_FILES['page_image']) && $_FILES['page_image']['name'] !== "")
		    {
			    $config['upload_path'] = './uploads/pagesimage';
                $config['allowed_types'] = 'gif|jpg|png|jpeg';
                $this->load->library('upload');
                $this->upload->initialize($config);
                if (!$this->upload->do_upload('page_image'))
                {
                    //$error = array('error' => $this->upload->display_errors());
		           echo 0;
			    }
                else
                { 
                    $imgdata = array('upload_data' => $this->upload->data());
					foreach($imgdata as  $path){
					$imagename = $path['file_name'];
					}
					$imagedata ='uploads/pagesimage/'.$imagename;
					 
                    $config['image_library'] = 'gd2';
                    $config['source_image']	='./uploads/pagesimage/'.$imagename;
                    $config['create_thumb'] = FALSE;
                    $config['maintain_ratio'] = FALSE;
                    $config['height']	= "400";
                    $config['width'] = "511";
                    $config['new_image'] ='./uploads/pagesimage/'.$imagename;//you should have write permission here..
					 
                    $this->image_lib->initialize($config);
                    if(!$this->image_lib->resize()){
						$error['resize'] = $this->image_lib->display_errors();
					} 
				}	
					$data = array(
				           'page_heading' => $this->input->post('page_heading'),
						   'page_title' =>$this->input->post('page_title'),
					       'page_image' =>$imagedata,
						   'page_shortcontent'=>$this->input->post('page_shortcontn'),
						   'page_massage'=>$this->input->post('page_msg'),
						   ); 
			}else{
	 
		            $data = array(
						   'page_heading' => $this->input->post('page_heading'),
						   'page_title' =>$this->input->post('page_title'),
					       'page_shortcontent'=>$this->input->post('page_shortcontn'),
						   'page_massage'=>$this->input->post('page_msg'),
						   ); 
				}
			 
			 $this->Data_access_model->update_data('hs_pages',array('page_id' => $this->input->post('old_page_id')),$data);	 	echo 1;  
		    }
		
	}
	
	public function add_offer(){
		 
		$this->form_validation->set_rules('offer_heading','Heading', 'required');	
		$this->form_validation->set_rules('offer_descr','Description', 'required');
		$this->form_validation->set_rules('coupen_code','Coupen Code', 'required'); 
		$this->form_validation->set_rules('coupen_uses_limit','Uses Limit', 'required');
		$this->form_validation->set_rules('discount_type','Discount Type', 'required');
		$this->form_validation->set_rules('discount_amount','Discount Amount', 'required');
		$this->form_validation->set_rules('apply_discount_to','Apply Discount To', 'required');
		$this->form_validation->set_rules('coupen_expire_date','Expire Date', 'required');
		if($this->form_validation->run() == FALSE)
		{
			echo 0; 
			
		}else{
			$check_coupencode = 0;
			$where_data =array('coupen_code'=>$this->input->post('coupen_code'));
			$query=$this->Data_access_model->select_data('*','hs_offers',$where_data);
			if($query->num_rows() > 0){
				$check_code= $query->result_array();
				if($check_code[0]['coupen_code'] == $this->input->post('coupen_code')){
					$check_coupencode++;	
				}
			} 
			
			if($check_coupencode == 0)
			{
				$discounted_product=$this->input->post('discounted_product');
				if(!isset($discounted_product)){
					$discounted_prod = 0;
				}else{
					$discounted_prod = $discounted_product;
				}
				if(isset($_FILES['offer_image']) && $_FILES['offer_image']['name'] !== "")
				{
					$config['upload_path'] = './uploads/offer_images';
					$config['allowed_types'] = 'gif|jpg|png|jpeg';
					$this->load->library('upload');
					$this->upload->initialize($config);
					if (!$this->upload->do_upload('offer_image'))
					{
						 
						echo 0;
					}
					else
					{ 
						$imgdata = array('upload_data' => $this->upload->data());
						foreach($imgdata as  $path){
							$imagename = $path['file_name'];
						}
							$imagedata ='uploads/offer_images/'.$imagename;
					 
						$config['image_library'] = 'gd2';
						$config['source_image']	='./uploads/offer_images/'.$imagename;
						$config['create_thumb'] = FALSE;
						$config['maintain_ratio'] = FALSE;
						$config['height']	= "183";
						$config['width'] = "270";
						$config['new_image'] ='./uploads/offer_images/'.$imagename;//you should have write permission here..
					 
						$this->image_lib->initialize($config);
							if(!$this->image_lib->resize()){
								$error['resize'] = $this->image_lib->display_errors();
							} 
					}	
						$data = array(
									'offer_heading' => $this->input->post('offer_heading'),
									'offer_description' =>$this->input->post('offer_descr'),
									'create_at' => date('d M Y h:i:s'),
									'offer_image'=> $imagedata,
									'coupen_code'=>$this->input->post('coupen_code'),
									'coupen_uses_limt'=>$this->input->post('coupen_uses_limit'),
									'discount_type'=>$this->input->post('discount_type'),
									'discount_amount'=>$this->input->post('discount_amount'),
									'apply_discount_to'=>$this->input->post('apply_discount_to'),
									'discounted_product'=>$this->$discounted_prod,
									'coupen_expire_date'=>$this->input->post('coupen_expire_date'),
								); 
				}else{
					 
						$data = array(
									'offer_heading' => $this->input->post('offer_heading'),
									'offer_description' =>$this->input->post('offer_descr'),
									'create_at' => date('d M Y h:i:s'), 
									'coupen_code'=>$this->input->post('coupen_code'),
									'coupen_uses_limt'=>$this->input->post('coupen_uses_limit'),
									'discount_type'=>$this->input->post('discount_type'),
									'discount_amount'=>$this->input->post('discount_amount'),
									'apply_discount_to'=>$this->input->post('apply_discount_to'),
									'discounted_product'=>$discounted_prod,
									'coupen_expire_date'=>$this->input->post('coupen_expire_date'),
								);
								 
				} 
				$this->Data_access_model->insert_data('hs_offers',$data); 
				if($this->db->affected_rows() > 0){
					echo 1;
				}else{
					echo 0;
				}
		    }else{
				echo 2;
			}
		
		}		
	}
	
	public function update_offer(){
		  
		$this->form_validation->set_rules('up_offer_heading','Heading', 'required');	
		$this->form_validation->set_rules('up_offer_descr','Description', 'required');
		$this->form_validation->set_rules('up_coupen_code','Coupen Code', 'required'); 
		$this->form_validation->set_rules('up_coupen_uses_limit','Uses Limit', 'required');
		$this->form_validation->set_rules('up_discount_type','Discount Type', 'required');
		$this->form_validation->set_rules('up_discount_amount','Discount Amount', 'required');
		$this->form_validation->set_rules('up_apply_discount_to','Apply Discount To', 'required');
		$this->form_validation->set_rules('up_coupen_expire_date','Expire Date', 'required'); 
		if ($this->form_validation->run() == FALSE)
		{
			echo 0; 
			
		}else{
			$discounted_product=$this->input->post('up_discounted_product');
			 if(!isset($discounted_product)){
				$discounted_prod = 0;
			 }else{
				$discounted_prod = $discounted_product;
			 }	
			
			if(isset($_FILES['up_offer_image']) && $_FILES['up_offer_image']['name'] !== "")
		    {
			    $config['upload_path'] = './uploads/offer_images';
                $config['allowed_types'] = 'gif|jpg|png|jpeg';
                $this->load->library('upload');
                $this->upload->initialize($config);
                if (!$this->upload->do_upload('up_offer_image'))
                {
                    //$error = array('error' => $this->upload->display_errors());
		           echo 0;
			    }
                else
                { 
                    $imgdata = array('upload_data' => $this->upload->data());
					foreach($imgdata as  $path){
					$imagename = $path['file_name'];
					}
					$imagedata ='uploads/offer_images/'.$imagename;
					 
                    $config['image_library'] = 'gd2';
                    $config['source_image']	='./uploads/offer_images/'.$imagename;
                    $config['create_thumb'] = FALSE;
                    $config['maintain_ratio'] = FALSE;
                    $config['height']	= "183";
                    $config['width'] = "270";
                    $config['new_image'] ='./uploads/offer_images/'.$imagename;//you should have write permission here..
					 
                    $this->image_lib->initialize($config);
                    if(!$this->image_lib->resize()){
						$error['resize'] = $this->image_lib->display_errors();
					 
					} 
				}	
					$data = array(
				                'offer_heading' => $this->input->post('up_offer_heading'),
						        'offer_description' =>$this->input->post('up_offer_descr'),
								'offer_image'=> $imagedata,
								'coupen_code'=>$this->input->post('up_coupen_code'),
								'coupen_uses_limt'=>$this->input->post('up_coupen_uses_limit'),
								'discount_type'=>$this->input->post('up_discount_type'),
								'discount_amount'=>$this->input->post('up_discount_amount'),
								'apply_discount_to'=>$this->input->post('up_apply_discount_to'),
								'discounted_product'=>$discounted_prod,
								'coupen_expire_date'=>$this->input->post('up_coupen_expire_date'),
					        ); 
			}else{
			
					$data = array(
				                'offer_heading' => $this->input->post('up_offer_heading'),
						        'offer_description' =>$this->input->post('up_offer_descr'),
								'coupen_code'=>$this->input->post('up_coupen_code'),
								'coupen_uses_limt'=>$this->input->post('up_coupen_uses_limit'),
								'discount_type'=>$this->input->post('up_discount_type'),
								'discount_amount'=>$this->input->post('up_discount_amount'),
								'apply_discount_to'=>$this->input->post('up_apply_discount_to'),
								'discounted_product'=>$discounted_prod,
								'coupen_expire_date'=>$this->input->post('up_coupen_expire_date'),
							);
			}
				$this->Data_access_model->update_data('hs_offers',array('offer_id' => $this->input->post('old_offer_id')),$data); 			
				echo 1;
		    }
	}
	
	public function add_occasion(){
		$this->form_validation->set_rules('occasion_name','Name', 'required');
			if ($this->form_validation->run() == FALSE)
			{
				echo 0; 
			
			}else{
					$data = array('occasion_name' =>$this->input->post('occasion_name'));
					$this->Data_access_model->insert_data('hs_occasions',$data);
						if($this->db->affected_rows() > 0){ 
							echo 1;
						}
				}
	}
	
	public function update_occasion(){
		$this->form_validation->set_rules('update_occaname','Name', 'required');
			if ($this->form_validation->run() == FALSE)
			{
				echo 0; 
			
			}else{
					$data = array('occasion_name' =>$this->input->post('update_occaname'));
					$this->Data_access_model->update_data('hs_occasions',array('occasion_id' =>$this->input->post('old_occasid')),$data); 
				     echo 1;
				}
	}
	
	public function change_admin_password(){
		$old_userid = $this->input->post('old_userid');
		$uemail = $this->input->post('user_email');
		$unew_pwd =$this->input->post('user_newpwd') ;
			if(!empty($uemail)){
		
				if(!empty($uemail) && !empty($unew_pwd)){
				$data = array('user_email' =>$uemail,
							'user_password' =>md5($unew_pwd),
							);
				}else if(!empty($uemail)){
					$data = array('user_email' =>$uemail,
						  );
				}else if(!empty($unew_pwd)){
					$data = array('user_password' =>md5($unew_pwd),
						  );
				}
				$this->Data_access_model->update_data('hs_user',array('user_id' =>$old_userid),$data);
				echo 1;
			}else{
				echo 0;
			}
	}
		
	public function wallet_credit(){
		$this->form_validation->set_rules('old_wallet_uid','User Id', 'required');
		$this->form_validation->set_rules('cd_wallet_amount','Amount', 'trim|required');	
		if ($this->form_validation->run() == FALSE)
		{
			echo 0; 
			
		}else{
			
			$old_wallet_userid = $this->input->post('old_wallet_uid');
			$addwallet_amount = $this->input->post('cd_wallet_amount');
			$wallet_note = $this->input->post('cd_wallet_note');
			$check_amount = $this->Data_access_model->select_data('wallet_uid,wallet_amount','hs_user_wallet',array('wallet_uid' =>$old_wallet_userid));
			
			if($check_amount->num_rows() > 0){
				
				$old_udetail = $check_amount->row();
				$old_uamount = $old_udetail->wallet_amount;
				$total_amount = $old_uamount + $addwallet_amount;
				
				$data = array('wallet_amount' =>$total_amount);
					$this->Data_access_model->update_data('hs_user_wallet',array('wallet_uid' =>$old_wallet_userid),$data);
					if($this->db->affected_rows() > 0){
						$data = array(
										'wcredit_uid' =>$old_wallet_userid,
										'wcredit_amount' =>$addwallet_amount,
										'wcredit_note' =>$wallet_note,
										'wcredit_date' =>date('d M Y h:i:s'),
						            );
						
						$this->Data_access_model->insert_data('hs_uwallet_credit',$data);
						echo 1;
					}
			}else{
                    $data = array(
									'wallet_uid'=>$old_wallet_userid,
									'wallet_amount' =>$addwallet_amount,
							    );
			
						    $this->Data_access_model->insert_data('hs_user_wallet',$data);
							if($this->db->affected_rows() > 0){ 
								$data = array(
										'wcredit_uid' =>$old_wallet_userid,
										'wcredit_amount' =>$addwallet_amount,
										'wcredit_note' =>$wallet_note,
										'wcredit_date' =>date('d M Y h:i:s'),
								);
							    $this->Data_access_model->insert_data('hs_uwallet_credit',$data);
							    echo 1;
						    }
				}			
		    }
	}
	
//*************************data add/update section end***************************//

	
//*************************data delete section start**********************//	

	public function delete_product(){
		if($this->uri->segment(3)){
			$old_prod_id = $this->uri->segment(3);
			$check_image = $this->Data_access_model->select_data('*','hs_products',array('prod_id' =>$old_prod_id));
			    if($check_image->num_rows() > 0){
				     $image_path = $check_image->row();
					if(file_exists($image_path->prod_image) && file_exists($image_path->prod_specialmenu_img) && file_exists($image_path->prod_singleimg)){
						unlink($image_path->prod_image);
						unlink($image_path->prod_specialmenu_img);
						unlink($image_path->prod_singleimg);
					}
				}
			$query = $this->Data_access_model->delete_data('hs_products',array('prod_id' =>$old_prod_id)); 
		    redirect(base_url("admin/productlist"));
		}
	}
	  
	public function delete_user(){
		  
		if($this->uri->segment(3)){
			$old_user_id = $this->uri->segment(3);
			$query = $this->Data_access_model->delete_data('hs_user',array('user_id' =>$old_user_id)); 
		    redirect(base_url("admin/userslist"));
		}
	} 
	  
	public function delete_blogs(){
		  
		if($this->uri->segment(3)){
			$old_blog_id = $this->uri->segment(3);
			$check_image = $this->Data_access_model->select_data('blog_image, blogsingle_image','hs_blogs',array('blog_id' =>$old_blog_id));
			if($check_image->num_rows() > 0){
				$image_path = $check_image->row();
				if(file_exists($image_path->blog_image) && file_exists($image_path->blogsingle_image)){
					unlink($image_path->blog_image);
					unlink($image_path->blogsingle_image);
				}
			}
			$query = $this->Data_access_model->delete_data('hs_blogs',array('blog_id' =>$old_blog_id)); 
		    redirect(base_url("admin/bloglist"));
		}
	}

    public function delete_tables(){
		  
		 if($this->uri->segment(3)){
			 $old_table_id = $this->uri->segment(3);
			 $check_image = $this->Data_access_model->select_data('table_image','hs_table_details',array('table_id' =>$old_table_id));
			    if($check_image->num_rows() > 0){
				     $image_path = $check_image->row();
					if(file_exists($image_path->table_image)){
						unlink($image_path->table_image);
					}
				}
			 $query = $this->Data_access_model->delete_data('hs_table_details',array('table_id' =>$old_table_id)); 
		     redirect(base_url("admin/tablelist"));
		 }
	 }
	 
	 public function delete_chefteam(){
		  
		 if($this->uri->segment(3)){
			 $old_chef_id = $this->uri->segment(3);
			 $check_image = $this->Data_access_model->select_data('chef_image','hs_chef_team',array('chef_id' =>$old_chef_id));
			    if($check_image->num_rows() > 0){
				     $image_path = $check_image->row();
					if(file_exists($image_path->chef_image)){
						unlink($image_path->chef_image);
					}
				}
			  $query = $this->Data_access_model->delete_data('hs_chef_team',array('chef_id' =>$old_chef_id)); 
			  redirect(base_url("admin/chefteamlist"));
		 }
	 }
	 
	 public function delete_testimonial(){
		  
		 if($this->uri->segment(3)){
			 $old_testimo_id = $this->uri->segment(3);
			 $check_image = $this->Data_access_model->select_data('testi_image','hs_testimonial',array('testi_id' =>$old_testimo_id));
			    if($check_image->num_rows() > 0){
				     $image_path = $check_image->row();
					if(file_exists($image_path->testi_image)){
						unlink($image_path->testi_image);
					}
				}
			  $query = $this->Data_access_model->delete_data('hs_testimonial',array('testi_id' =>$old_testimo_id)); 
			  redirect(base_url("admin/testimoniallist"));
		 }
	 }
	 
	public function delete_partners_image(){
		  
		 if($this->uri->segment(3)){
				$old_partner_id =$this->uri->segment(3);
				
				$check_image = $this->Data_access_model->select_data('partner_image',' hs_partners',array('partner_id' =>$old_partner_id));
			    if($check_image->num_rows() > 0){
				     $image_path = $check_image->row();
					if(file_exists($image_path->partner_image)){
						unlink($image_path->partner_image);
					}
				}
				$query = $this->Data_access_model->delete_data('hs_partners',array('partner_id' =>$old_partner_id));
				redirect(base_url("admin/partners_list"));
		    }
	 }
	 
	public function delete_portfolio_image(){
		  
		 if($this->uri->segment(3)){
			 $old_portfolio_id =$this->uri->segment(3);
			 $check_image = $this->Data_access_model->select_data('portfolio_image','hs_portfolio',array('portfolio_id' =>$old_portfolio_id));
			    if($check_image->num_rows() > 0){
				     $image_path = $check_image->row();
					if(file_exists($image_path->portfolio_image)){
						unlink($image_path->portfolio_image);
					}
				}
			 $query = $this->Data_access_model->delete_data('hs_portfolio',array('portfolio_id' =>$old_portfolio_id));
		     redirect(base_url("admin/gallery_image_list"));
		 }
	 }
	 
	public function delete_reservation(){
		  
		if($this->uri->segment(3)){
			 $old_reservation_id =$this->uri->segment(3);
			 $this->Data_access_model->delete_data('hs_reservation_details',array('reservation_id' =>$old_reservation_id));
		     redirect(base_url("admin/reservation_list"));
		}
	 }
	 
	public function delete_comment(){
		  
		 if($this->uri->segment(3)){
			 $old_comment_id =$this->uri->segment(3);
			  $this->Data_access_model->delete_data('hs_comment',array('comment_id' =>$old_comment_id));
		     redirect(base_url("admin/comments"));
		  }
	}
	
	 public function delete_review(){
		  
		 if($this->uri->segment(3)){
			 $old_review_id =$this->uri->segment(3);
			  $this->Data_access_model->delete_data('hs_rating',array('rating_id' =>$old_review_id));
		     redirect(base_url("admin/product_review"));
		  }
	}
	
	
	public function delete_offer(){
		  
		if($this->uri->segment(3)){
			  $old_offer_id =$this->uri->segment(3);
			  $check_image = $this->Data_access_model->select_data('offer_image','hs_offers',array('offer_id' =>$old_offer_id));
			    if($check_image->num_rows() > 0){
				     $image_path = $check_image->row();
				if(file_exists($image_path->offer_image)){
					unlink($image_path->offer_image);
				}
			}
			 $this->Data_access_model->delete_data('hs_offers',array('offer_id' =>$old_offer_id));
			  redirect(base_url("admin/offers_list"));
		}
	}	
	
	public function delete_contact(){
		  
		 if($this->uri->segment(3)){
			 $old_contact_id =$this->uri->segment(3);
			  $this->Data_access_model->delete_data('hs_contact',array('contact_id' =>$old_contact_id));
			   redirect(base_url("admin/contact_us"));
		}
	}
	
	public function delete_order(){
		  
		 if($this->uri->segment(3)){
			 $old_order_id =$this->uri->segment(3);
			  $this->Data_access_model->delete_data('hs_user_orders',array('order_id' =>$old_order_id));
			   redirect(base_url("admin/manage_orders"));
		}
	}	
	
 
	public function delete_occasion(){
		  
		 if($this->uri->segment(3)){
			 $old_occasion_id =$this->uri->segment(3);
			  $this->Data_access_model->delete_data('hs_occasions',array('occasion_id' =>$old_occasion_id));
			   redirect(base_url("admin/occasion"));
		}
	}
			
//*************************data delete section end************************//	
	
	
//**************************status update section start***********************// 	
   
    public function update_cate_status(){
		
		$data=array(
		            'category_status' =>$this->input->post('val'),
					);
		
		 $this->Data_access_model->update_data('hs_category',array('category_id' => $this->input->post('cate_id')),$data);    
			if($this->db->affected_rows() > 0){
			    echo 1; 
	        }else{
			  echo 0;
		    }
	} 
	
	public function update_cate_featured(){
		$data=array(
		            'category_featured' =>$this->input->post('val'),
					);
		
		 $this->Data_access_model->update_data('hs_category',array('category_id' => $this->input->post('cate_id')),$data);    
		    if($this->db->affected_rows() > 0){
			    echo 1; 
	        }else{
			  echo 0;
		    }
	}
	 
	public function update_table_status(){
		
		$data=array(
		            'table_status' =>$this->input->post('val'),
					);
		
		 $this->Data_access_model->update_data('hs_table_details',array('table_id' => $this->input->post('table_id')),$data);    
			if($this->db->affected_rows() > 0){
			    echo 1; 
	        }else{
			  echo 0;
		    }
	}
 
	public function update_product_status(){
		$data=array(
		            'prod_status' =>$this->input->post('val'),
					);
		
		$this->Data_access_model->update_data('hs_products',array('prod_id' => $this->input->post('prod_id')),$data);    
			if($this->db->affected_rows() > 0){
			    echo 1; 
	        }else{
			  echo 0;
		    }
		} 
	 
	public function update_product_featured(){
		$data=array(
		            'prod_featured' =>$this->input->post('val'),
					);
		
		 $this->Data_access_model->update_data('hs_products',array('prod_id' => $this->input->post('prod_id')),$data);    
			if($this->db->affected_rows() > 0){
			    echo 1; 
	        }else{
			  echo 0;
		    } 
	}
	 
	public function update_user_status(){
		$data=array(
		            'user_status' =>$this->input->post('val'),
					);
		
		$this->Data_access_model->update_data('hs_user',array('user_id' => $this->input->post('user_id')),$data);
 		if($this->db->affected_rows() > 0){
			    echo 1; 
	    }else{
			  echo 0;
		} 

	 }
	 
	public function update_blogcate_status(){
		$data=array('cate_status' =>$this->input->post('val'));
		$this->Data_access_model->update_data('hs_blog_category',array('cate_id' => $this->input->post('blogcate_id')),$data);
		if($this->db->affected_rows() > 0){
			echo 1; 
		}else{
			echo 0;
		} 
	}
	  
    public function update_blogs_status(){
		$data=array('blog_status' =>$this->input->post('val'));
		$this->Data_access_model->update_data('hs_blogs',array('blog_id' => $this->input->post('blog_id')),$data);
		if($this->db->affected_rows() > 0){
			echo 1; 
		}else{
			echo 0;
		}
	}
	 
	public function update_chefmember_status(){
		$data=array('chef_status' =>$this->input->post('val'));
		$this->Data_access_model->update_data('hs_chef_team',array('chef_id' => $this->input->post('chef_id')),$data);
		if($this->db->affected_rows() > 0){
			echo 1; 
		}else{
			echo 0;
		}
	}
	 
	public function update_testimonial_status(){
		$data=array('testi_status' =>$this->input->post('val'));
		$this->Data_access_model->update_data('hs_testimonial',array('testi_id' => $this->input->post('testi_id')),$data);
		if($this->db->affected_rows() > 0){
			echo 1; 
		}else{
			echo 0;
		}
	 }
	 
	public function update_portfolio_status(){
		$data=array('portfolio_status' =>$this->input->post('val'));
		$this->Data_access_model->update_data('hs_portfolio',array('portfolio_id' => $this->input->post('portfolio_id')),$data);
		if($this->db->affected_rows() > 0){
			echo 1; 
		}else{
			echo 0;
		}
	 }
	 
	public function update_partner_status(){
		$data=array('partner_status' =>$this->input->post('val'));
		$this->Data_access_model->update_data('hs_partners',array('partner_id' => $this->input->post('partner_id')),$data);
		if($this->db->affected_rows() > 0){
			echo 1; 
		}else{
			echo 0;
		}
	 }
	 
	public function update_comment_status(){
		$data=array('comment_status' =>$this->input->post('val'));
		$this->Data_access_model->update_data('hs_comment',array('comment_id' => $this->input->post('comment_id')),$data);
		if($this->db->affected_rows() > 0){
			echo 1; 
		}else{
			echo 0;
		}
	 }
	 
	public function update_offer_status(){
		$data=array('offer_status' =>$this->input->post('offer_value'));
		$this->Data_access_model->update_data('hs_offers',array('offer_id' => $this->input->post('offer_id')),$data);
		if($this->db->affected_rows() > 0){
			echo 1; 
		}else{
			echo 0;
		}
	}
	 
	
	 
	public function update_occasion_status(){
		$data=array('occasion_status' =>$this->input->post('occasion_value'));
		$this->Data_access_model->update_data('hs_occasions',array('occasion_id' => $this->input->post('occasion_id')),$data);
		if($this->db->affected_rows() > 0){
			echo 1; 
		}else{
			echo 0;
		}
	}
	
	
	public function update_review_status()
	{
		$data=array('rating_status' =>$this->input->post('review_value'));
		$this->Data_access_model->update_data('hs_rating',array('rating_id' => $this->input->post('review_id')),$data);
		if($this->db->affected_rows() > 0){
			echo 1; 
		}else{
			echo 0;
		}
	}
	 
	public function update_reservation_status(){
		
		$reserv_status = $this->input->post('reserv_value');
		$reserv_id = $this->input->post('reserv_id');
		if(!empty($reserv_id)){
			$data=array('reservation_status' =>$reserv_status);
			$this->Data_access_model->update_data('hs_reservation_details',array('reservation_id' =>$reserv_id),$data);
			if($this->db->affected_rows() > 0){
				if($reserv_status != 0){
					$reserv_details = $this->Data_access_model->select_data('*','hs_reservation_details',array('reservation_id' =>$reserv_id));
					if($reserv_details->num_rows() > 0){
						$reserv_info = $reserv_details->row();
						$booking_number = $reserv_info->reservation_uniqid;
						$user_email = $reserv_info->email;
						$booking_uname = $reserv_info->name;
						$booking_table = $reserv_info->reservation_uniqid;
						
						if($reserv_status == 1){
					
							$email_content = $this->hs->getwebsettings('tbconfirm_tamplate');  
							$subject = $this->hs->getwebsettings('tbconfirm_subject');
					
						}else if($reserv_status == 2){
							$email_content = $this->hs->getwebsettings('tbcancel_template');  
							$subject = $this->hs->getwebsettings('tbcancel_subject');
						}

						$email_content = str_replace("[username]",$booking_uname, $email_content);
						$email_content = str_replace("[booking_number]",$booking_number,$email_content);
						$email_content = str_replace("[break]", "<br>", $email_content);
						$data['emcontent'] = $email_content;
					
						$email_template = $this->load->view('theme/email_template',$data,true);
						//sending mail
						$this->hs->send_mail($user_email,$subject,$email_template);
					}
				}	
					echo 1; 
			}else{
				echo 0;
			}
	   }
	}
//**********************status update section end ******************//	 
}

 