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

class Home extends CI_Controller {
	
	public function __construct()
    {
	    parent::__construct();
		 
	}
	  
	public function index(){
      
		$prod_query=$this->Data_access_model->select_data('*','hs_products',array( 'prod_status' =>1,));
		   
		if($prod_query->num_rows() > 0){
			$data['all_products']  = $prod_query->result();
		}
		else
		{ 
			$data['all_products'] = "";
		}
		 
	    $cate_query=$this->Data_access_model->select_data('*','hs_category',array( 'category_status' =>1,));
		   
		if($cate_query->num_rows() > 0){
			$data['all_category']  = $cate_query->result();
		}
		else{ 
			$data['all_category'] = "";
		}
	    
		$testi_query=$this->Data_access_model->select_data('*','hs_testimonial',array( 'testi_status' =>1,));
		if($testi_query->num_rows() > 0){
			   
		    $data['all_testimonial'] =$testi_query->result();
			 
		}else{ 
			$data['all_testimonial'] ="";
			  
		}
		 
		$chef_query=$this->Data_access_model->select_data('*','hs_chef_team',array( 'chef_status' =>1,));
		if($chef_query->num_rows() > 0){
			   
		    $data['all_chefteam'] =$chef_query->result();
			 
		}else{ 
			$data['all_chefteam'] = "";
			  
		}
		
		$blog_query = $this->Data_access_model->count_items('*','comment_id','countcomment','hs_comment','hs_blogs','blog_id = comment_blog_id','blog_id');
		if($blog_query->num_rows() > 0){
			 $data['all_blogs'] =$blog_query->result();
		}else{ 
			$data['all_blogs'] = "";
		}
		
		$pages_query=$this->Data_access_model->select_data('*','hs_pages',array('page_status' =>1,));
		if($pages_query->num_rows() > 0){
			   
		    $data['all_pages'] =$pages_query->result();
			 
		}else{ 
			$data['all_pages'] = "";
		}
		
		$portfolio_query=$this->Data_access_model->select_data_withlimit('*','hs_portfolio',array( 'portfolio_status' =>1),9,0);
		if($portfolio_query->num_rows() > 0){
			   
		    $data['all_portfolio'] =$portfolio_query->result();
			 
		}else{ 
			$data['all_portfolio'] = "";
			  
		}
		
		$partner_query=$this->Data_access_model->select_data('*','hs_partners',array('partner_status' =>1));
		if($partner_query->num_rows() > 0){
			   
		    $setting_data['all_partners'] =$partner_query->result();
			 
		}else{ 
			$setting_data['all_partners'] = "";
			  
		}
		
		$occasion_query=$this->Data_access_model->select_data('*','hs_occasions',array( 'occasion_status' =>1,));
		if($occasion_query->num_rows() > 0){
			   
		    $data['all_occasion'] =$occasion_query->result();
			 
		}else{ 
			$data['all_occasion'] = "";
		}
		
		$offer_query=$this->Data_access_model->select_data('*','hs_offers',array( 'offer_status' =>1,));
		if($offer_query->num_rows() > 0){
			   
		    $data['all_offer'] =$offer_query->result();
			 
		}else{ 
			$data['all_offer'] = "";
		}
		
		$slider_query=$this->Data_access_model->select_data('*','hs_banner_slider',array('slider_status' =>1,));
		if($slider_query->num_rows() > 0){
			   
		    $data['all_slider'] =$slider_query->result();
			 
		}else{ 
			$data['all_slider'] = "";
			  
		}
		
		$opening_time_query =$this->Data_access_model->select_all('hs_opening_schedule');
		
		if($opening_time_query->num_rows() > 0){
			   
		    $setting_data['opening_time'] =$opening_time_query->result();
			 
		}else{ 
			$setting_data['opening_time'] = "";
			  
		} 
		
		$data['add_active'] = 1;
		$this->load->view('theme/common/header',$data);
		$this->load->view('theme/index',$data);
		$this->load->view('theme/common/footer',$setting_data);
	}
   
	//*******************about_us page start *******************//   
	public function aboutus(){
		$cate_query=$this->Data_access_model->select_data('*','hs_category',array( 'category_status' =>1,));
		   
		if($cate_query->num_rows() > 0){
			$data['all_category']  = $cate_query->result();
		}else{ 
			$data['all_category'] = "";
		}
		
		$chef_query=$this->Data_access_model->select_data('*','hs_chef_team',array( 'chef_status' =>1,));
		if($chef_query->num_rows() > 0){
			   
		    $data['all_chefteam'] =$chef_query->result();
			 
		}else{ 
			$data['all_chefteam'] = "";
			  
		}
		
		$testi_query=$this->Data_access_model->select_data('*','hs_testimonial',array( 'testi_status' =>1,));
		if($testi_query->num_rows() > 0){
			   
		    $data['all_testimonial'] =$testi_query->result();
			 
		}else{ 
			$data['all_testimonial'] ="";
			  
		}
		
		$opening_time_query =$this->Data_access_model->select_all('hs_opening_schedule');
		
		if($opening_time_query->num_rows() > 0){
			   
		    $setting_data['opening_time'] =$opening_time_query->result();
			 
		}else{ 
			$setting_data['opening_time'] = "";
			  
		}
		
		$partner_query=$this->Data_access_model->select_data('*','hs_partners',array( 'partner_status' =>1,));
		if($partner_query->num_rows() > 0){
			   
		    $setting_data['all_partners'] =$partner_query->result();
			 
		}else{ 
			$setting_data['all_partners'] = "";
			  
		}
		
		$occasion_query=$this->Data_access_model->select_data('*','hs_occasions',array( 'occasion_status' =>1,));
		if($occasion_query->num_rows() > 0){
			   
		    $data['all_occasion'] =$occasion_query->result();
			 
		}else{ 
			$data['all_occasion'] = "";
			  
		}
		
		$prod_query=$this->Data_access_model->select_data('*','hs_products',array( 'prod_status' =>1,));
		if($prod_query->num_rows() > 0){
			$data['all_products']  = $prod_query->result();
		}else{ 
			$data['all_products'] = "";
		}
		
		$offer_query=$this->Data_access_model->select_data('*','hs_offers',array( 'offer_status' =>1,));
		if($offer_query->num_rows() > 0){
			   
		    $data['all_offer'] =$offer_query->result();
			 
		}else{ 
			$data['all_offer'] = "";
			  
		}
		
		$pages_query=$this->Data_access_model->select_data('*','hs_pages',array( 'page_status' =>1,));
		if($pages_query->num_rows() > 0){
			   
		    $data['all_pages'] =$pages_query->result();
			 
		}else{ 
			$data['all_pages'] = "";
			  
		}
		$data['page_title']='About Us';
		$data['page_descri'] ='About Us';
		$data['add_active'] = 2;
		$this->load->view('theme/common/header',$data);
		$this->load->view('theme/about',$data);
		$this->load->view('theme/common/footer',$setting_data);
	} 
	//*******************about_as page end *******************// 


	//*******************reservation page start *******************// 	
	public function reservation(){
		
		$prod_query=$this->Data_access_model->select_data('*','hs_products',array( 'prod_status' =>1,));
		   
		if($prod_query->num_rows() > 0){
			$data['all_products']  = $prod_query->result();
		}else{ 
			$data['all_products'] = "";
		}
		
		$opening_time_query =$this->Data_access_model->select_all('hs_opening_schedule');
		
		if($opening_time_query->num_rows() > 0){
			$setting_data['opening_time'] =$opening_time_query->result();
		}else{ 
			$setting_data['opening_time'] = "";
		}
		
		$partner_query=$this->Data_access_model->select_data('*','hs_partners',array( 'partner_status' =>1,));
		if($partner_query->num_rows() > 0){
			$setting_data['all_partners'] =$partner_query->result();
		}else{ 
			$setting_data['all_partners'] = "";
		}
		
		$occasion_query = $this->Data_access_model->select_data('*','hs_occasions',array( 'occasion_status' =>1,));
		if($occasion_query->num_rows() > 0){
			   
			$data['all_occasion'] =$occasion_query->result();
			 
		}else{ 
			$data['all_occasion'] = "";
			  
		}
		
		$offer_query = $this->Data_access_model->select_data('*','hs_offers',array( 'offer_status' =>1,));
		if($offer_query->num_rows() > 0){
			   
			$data['all_offer'] =$offer_query->result();
			 
		}else{ 
			$data['all_offer'] = "";
		}
		
		$table_query = $this->Data_access_model->select_data('*','hs_table_details',array( 'table_status' =>1,));
		if($table_query->num_rows() > 0){
			   
			$data['all_tables'] =$table_query->result();
			 
		}else{ 
			$data['all_table'] = "";
		}
		
		$reservation_query = $this->Data_access_model->select_all('hs_reservation_details');
		if($reservation_query->num_rows() > 0){
			   
		    $data['all_reservation'] =$reservation_query->result_array();
			 
		}else{ 
			$data['all_reservation'] = "";
		}
		$data['page_title']='Reservation';
		$data['page_descri'] ='Restaurant Reservation';
		$data['add_active'] = 4;
		$this->load->view('theme/common/header',$data);
		$this->load->view('theme/reservation_type1',$data);
		$this->load->view('theme/common/footer',$setting_data);
	}
	//*******************reservation page end *******************// 
	
	//*******************gallery page start *******************// 	
	
	public function gallery(){
		
		$portfolio_query=$this->Data_access_model->select_data_withlimit('*','hs_portfolio',array('portfolio_status' =>1),9,0);
		if($portfolio_query->num_rows() > 0){
			$data['all_portfolio']  = $portfolio_query->result();
		}
		else{ 
			$data['all_portfolio'] = "";
		}
		 
		$prod_query=$this->Data_access_model->select_data('*','hs_products',array( 'prod_status' =>1,));
		   
		if($prod_query->num_rows() > 0){
			$data['all_products']  = $prod_query->result();
		}else{ 
			$data['all_products'] = "";
		}
		
		$opening_time_query =$this->Data_access_model->select_all('hs_opening_schedule');
		
		if($opening_time_query->num_rows() > 0){
			$setting_data['opening_time'] =$opening_time_query->result();
		}else{ 
			$setting_data['opening_time'] = "";
		}
		
		$partner_query=$this->Data_access_model->select_data('*','hs_partners',array( 'partner_status' =>1,));
		if($partner_query->num_rows() > 0){
			   
		    $setting_data['all_partners'] =$partner_query->result();
			 
		}else{ 
			$setting_data['all_partners'] = "";
			  
		}
		
		$offer_query=$this->Data_access_model->select_data('*','hs_offers',array( 'offer_status' =>1,));
		if($offer_query->num_rows() > 0){
			$data['all_offer'] =$offer_query->result();
		}else{ 
			$data['all_offer'] = "";
		}
		
		$data['page_title']='Gallery';
		$data['page_descri'] ='Our Portfolios';
		$data['add_active'] = 5;
		$this->load->view('theme/common/header',$data);
		$this->load->view('theme/gallery',$data);
		$this->load->view('theme/common/footer',$setting_data);
	}

	
 	public function loadmore_portfolio(){
		
		$port_limit = 3;
	    $port_offset = $this->input->post('portfolio_offset');
		$total_portfolio = $this->Data_access_model->select_data('*,count(portfolio_id) as count_portfolio','hs_portfolio',array('portfolio_status' =>1));
		if($total_portfolio->num_rows() > 0){
			$total_port =$total_portfolio->row();
			$tport = $total_port->count_portfolio;  
		}
		$output ='';
		if($tport > $port_limit){
			if(isset($port_limit)){
				$portfolio_query=$this->Data_access_model->select_data_withlimit('*','hs_portfolio',array('portfolio_status' =>1),$port_limit,$port_offset);
				if($portfolio_query->num_rows() > 0){
					$port_data = $portfolio_query->result();
					$count = 0;
					foreach($port_data as $portfo){ 
						$count++;					
						$output .='<div class="element-item">
									<div class="fd_gal_box">
									<div class="fd_gallery_img">
									<img src="'.base_url().$portfo->portfolio_image.'" alt="" class="img-fluid"/>
									<div class="fd_img_overlay">
									<a href="'.base_url().$portfo->portfolio_image.'"><span class="fd_gal_icon"><img src="'.base_url().'themeassets/images/svg/search.svg" alt=""></span></a>
									</div>										
									<div class="fd_galimg_overlay"></div>
									</div>
									</div>
									</div>';
						}
				}  
				$port_output = array('output'=>$output,
									'total_port' => $count,
									);
				echo json_encode($port_output);	
				 
			}
		}else{
			echo json_encode($output);
		}
	} 
	
	//*******************gallery page end*******************//

	
	//*******************contact_us page start *******************//	

	public function contact(){
	
		$opening_time_query =$this->Data_access_model->select_all('hs_opening_schedule');
		
		if($opening_time_query->num_rows() > 0){
			   
		    $setting_data['opening_time'] =$opening_time_query->result();
			 
		}else{ 
			$setting_data['opening_time'] = "";
			  
		}
		
		$partner_query=$this->Data_access_model->select_data('*','hs_partners',array( 'partner_status' =>1,));
		if($partner_query->num_rows() > 0){
			   
		    $setting_data['all_partners'] =$partner_query->result();
			 
		}else{ 
			$setting_data['all_partners'] = "";
			  
		}
		
		$offer_query=$this->Data_access_model->select_data('*','hs_offers',array( 'offer_status' =>1,));
		if($offer_query->num_rows() > 0){
			   
		    $data['all_offer'] =$offer_query->result();
			 
		}else{ 
			$data['all_offer'] = "";
			  
		} 
		
		$data['page_title']='Contact Us';
		$data['page_descri'] ='Contact Us';
		$data['add_active'] = 7;
	    $this->load->view('theme/common/header',$data);
		$this->load->view('theme/contact_us',$setting_data);
		$this->load->view('theme/common/footer',$setting_data);
	}
	//*******************contact_us page end *******************//	

	//************display product by category section start ***********//	
	
     public function display_products(){
	 
		 $cate_id = $this->input->post('cate_id');
		 if(isset($cate_id) && ($cate_id !=='')){
			 if($cate_id == 0){
				$prod_query=$this->Data_access_model->select_data('*','hs_products',array(  'prod_status' =>1,)); 
			}else{
				$prod_query=$this->Data_access_model->select_data('*','hs_products',array('prod_cateid'=>$cate_id, 'prod_status' =>1));
			}  
			if($prod_query->num_rows() > 0){
				$data = $prod_query->result();  
				$response ="";
				foreach($data as $products){   
					$response .='<div class="swiper-slide"><div class="fd_food_box"><div class="fd_food_img"><img src="'.base_url().$products->prod_image.'" alt="">
					</div><div class="fd_food_name"><h3><a href="'.base_url().'product/'.$products->prod_slug.'/'.$products->prod_code.'">'.$products->prod_name.'</a></h3>
					<span class="food_price">'.$this->hs->getwebsettings('currency_symbol').''.$products->prod_price.'</span><span class="food_name_arrow"><img src=" '.base_url().'themeassets/images/svg/up_arrow1.svg" alt=""></span>
					</div><div class="fd_food_detail"><h3><a href="'.base_url().'product/'.$products->prod_slug.'/'.$products->prod_code.'">'.$products->prod_name.'</a></h3><span class="food_price">'.$this->hs->getwebsettings('currency_symbol').''.$products->prod_price.'</span>
					<div class="add_to_cart"><a href="javascript:;" onclick="add_to_cart('.$products->prod_id.',1)">add to cart <span class="add_crt_icon"><img src="'.base_url().'themeassets/images/svg/basket1.svg" alt=""></span></a></div></div><div class="fd_food_overlay"></div></div></div>';
				} 
					echo json_encode($response);   
			}else{ 
				$response = 0;
				echo json_encode($response); 
			} 
		} 
	} 
	//*******************display product by category end ************//

 
	//********************search product start***************//
 
	 function searching_products(){
		$search_prod = $this->input->post('search_item');
		$output ='';
		if($search_prod !=''){
			$get_prod = $this->Data_access_model->select_data_like('*','hs_products',array('prod_name' =>$search_prod,)); 
			if($get_prod->num_rows() > 0){
				$prod= $get_prod->result_array();
				$output = '<ul>';
				foreach($prod as $p){    
					$output .='<li><a  href="'.base_url().'product/'.$p['prod_slug'].'/'.$p['prod_code'].'" id="selected_prod">'.$p['prod_name'].'</a></li>';  
				}
				$output .='</ul>';
			}else{
				$output ='<ul><li>Item Not Found!</li></ul>';
			}
				echo $output; 
		}else{
			echo $output;
		}
	} 
	//********************search product end***************//	

//********************privacy policy page start*********//
	public function policy(){
	
		$opening_time_query =$this->Data_access_model->select_all('hs_opening_schedule');
		
		if($opening_time_query->num_rows() > 0){
			   
		     $setting_data['opening_time'] = $opening_time_query->result();
			 
		}else{ 
			 $setting_data['opening_time'] = "";
		}
		$partner_query=$this->Data_access_model->select_data('*','hs_partners',array( 'partner_status' =>1,));
		if($partner_query->num_rows() > 0){
			   
		    $setting_data['all_partners'] = $partner_query->result();
		}else{ 
			$setting_data['all_partners'] = "";
		}
		
		$offer_query=$this->Data_access_model->select_data('*','hs_offers',array( 'offer_status' =>1,));
		if($offer_query->num_rows() > 0){
			   
		    $data['all_offer'] =$offer_query->result();
			 
		}else{ 
			$data['all_offer'] = "";
			  
		}
		$data['page_title']='Privacy Policy';
		$data['page_descri'] ='Privacy Policy';
	    $this->load->view('theme/common/header',$data);
		$this->load->view('theme/policy',$setting_data);
		$this->load->view('theme/common/footer',$setting_data);
	}
	//**************privacy policy page end*********//

	//********************T&C page start*********//
	public function term_condition(){
	
		$opening_time_query =$this->Data_access_model->select_all('hs_opening_schedule');
		
		if($opening_time_query->num_rows() > 0){
			   
		    $setting_data['opening_time'] =$opening_time_query->result();
			 
		}else{ 
			$setting_data['opening_time'] = "";
			  
		}
		
		$partner_query=$this->Data_access_model->select_data('*','hs_partners',array( 'partner_status' =>1,));
		if($partner_query->num_rows() > 0){
			   
		    $setting_data['all_partners'] =$partner_query->result();
			 
		}else{ 
			$setting_data['all_partners'] = "";
			  
		}
		
		$offer_query=$this->Data_access_model->select_data('*','hs_offers',array( 'offer_status' =>1,));
		if($offer_query->num_rows() > 0){
			   
		    $data['all_offer'] =$offer_query->result();
			 
		}else{ 
			$data['all_offer'] = "";
			  
		}
		$data['page_title']='T&C';
		$data['page_descri'] ='Terms And Conditoins';
	    $this->load->view('theme/common/header',$data);
		$this->load->view('theme/terms',$setting_data);
		$this->load->view('theme/common/footer',$setting_data);
	}
	//********************T&C page end*********//

}	
	    
 	   
