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

class Welcome extends CI_Controller {


	private $cart_qty   = '' ;
	private $logged 	= 0  ;	
	private $user 		= '' ;
	
	
	public function __construct()
	{
		parent::__construct();
		
		$this->load->library('loginfunctions');
		
		$this->load->library(array('form_validation'));
		
		$this->load->model('Db_model');
		
		$this->load->library('cart');
		
		$this->load->helper('basic_helper');
		
		$this->load->library('user_loginfunctions');
	    
		
		$ic=0;
		foreach ($this->cart->contents() as $items):
		$ic++;
		endforeach;
		$this->cart_qty = ''.$ic.'';
		//$this->cart_qty = ''.$this->cart->total_items().'';
		
		if($this->session->userdata('shop_user2'))
		{
			$this->load->library('encrypt') ;
			$this->user = $this->encrypt->decode($this->session->userdata('shop_user2'));
			$this->logged = 1;
		}
		
		
		if($_COOKIE['username_m'] !='' && $_COOKIE['password_m']!='' )
		{	
		if($this->user_loginfunctions->mobile_log($_COOKIE['username_m'],$_COOKIE['password_m']))
		{
			// echo $_COOKIE['username_m'];
			$this->load->library('encrypt') ;
			$this->user = $_COOKIE['username_m'];
			$this->logged = 1;
		}	
		}
		
		
		
		
		
	}
	
	public function index()
	{
	
	
	
	
	 if($this->input->post('submit'))
		{
		 $buy='';
		 $type='';
		 $district='';
		 $town='0';
		 $dcity='';
		
		 $buy = $this->input->post('buy'); 
		 $type = $this->input->post('type'); 
		 $district = $this->input->post('district'); 
		// $town = $this->input->post('town'); 


if($type!='') {
$sql1 ="SELECT * FROM shop_category where id=$type ";
$query1 = $this->db->query($sql1);
if ($query1->num_rows() > 0) {
foreach($query1->result() as $row1) {
$subcat=$row1->title;
}
}
}

		 	 	
if($district!='') {
$sql2 ="SELECT * FROM districts where id=$district ";
$query2 = $this->db->query($sql2);
if ($query2->num_rows() > 0) {
foreach($query2->result() as $row2) {
$dname=$row2->name;
}
}
}


if($town!='') {
$sql3 ="SELECT * FROM city where id=$town ";
$query3 = $this->db->query($sql3);
if ($query3->num_rows() > 0) {
foreach($query3->result() as $row3) {
$dcity=$row3->title;
}
}
}
if($subcat!='') { $subcat=''.url_title($subcat,'-', TRUE).'';}
if($dname!='' && $subcat!='') { $dname='-'.url_title($dname,'-', TRUE).'';}
if($dname!='' && $subcat=='') { $dname=''.url_title($dname,'-', TRUE).'';}
if($dcity!='') { $dcity='-'.url_title($dcity,'-', TRUE).'';}
		 

		redirect('Search/rn/1/'.$buy.'/'.$type.'/'.$district.'/'.$town.'/'.$subcat.''.$dname.''.$dcity.'');
		
		}
		
		
		
	setcookie('user_s','majo',time() + (86400 * 7)); // 86400 = 1 day
	
		
		$data['result'] = array() ;
		$data['cart_qty'] = $this->cart_qty;
		$data['email'] = $this->user;
		$data['logged'] = $this->logged;
		$data['page'] = 'about' ;

	    
		$data['district'] = $this->Db_model->get_where_by_order('districts',array('state_id'=>'18'),'name','asc') ;
		
		
		
		
		
		$data['about'] = $this->Db_model->get_where_by_order('shop_pages',array('type'=>'about','active'=>'Y'),'title','asc') ;
		$data['category'] = $this->Db_model->get_all_by_order('shop_category','order','asc') ;
		$data['result'] = $this->Db_model->get_where_by_order('shop_category',array(),'order','asc') ;	
		$data['gift'] = $this->Db_model->get_where_by_order('shop_category',array(),'order','asc') ;
        $data['subcat']= $this->Db_model->get_where_by_order('shop_subcategory',array(),'id','asc') ;
        $cart_product = $this->Db_model->get_where_by_order('shop_product',array(),'order','asc') ;
		$data['site'] = $this->Db_model->get_all('site',array()) ;
		$data['contactus'] = $this->Db_model->get_where_by_order('shop_contact',array('status'=>'1'),'id','desc') ;
		$data['banner'] = $this->Db_model->get_where_by_order('shop_banner',array('status'=>'1'),'id','desc') ;
        $data['details2'] = $this->Db_model->get_where_by_order('shop_pages',array('active'=>'Y','type'=>'Welcome'),'order','asc') ; 
		
        //$data['allproduct']= $this->Db_model->get_where_by_order('shop_product',array('active'=>'Y','featured'=>'1'),'La_modi_date','desc') ;
		
		$data['allproduct']= $this->Db_model->get_where_by_order_limit('shop_product',array('active'=>'Y'),'reg_date','desc',12) ;
		
		
		$data['todays'] = $this->Db_model->get_where_by_order('shop_product',array('code'=>1),'order','asc') ;
		$data['advertisement'] = $this->Db_model->get_where_by_order('advertisement',array('active'=>'Y'),'position','asc') ;
		
		$data['related2'] = $this->Db_model->get_where_by_order('shop_product',array('active'=>'Y','featured'=>1),'order','asc') ;
		
		
	/*	$product = $this->Db_model->get_where_by_order_limit('shop_product',array('active'=>'Y','featured'=>1),'order','asc') ;
		if($product!==FALSE)
		{
			$data['product'] = $product;
		}*/
		
		
		$details = $this->Db_model->get_where_by_order('shop_pages',array('active'=>'Y','type'=>'about'),'order','asc') ;
		$data['service'] = $this->Db_model->get_where_by_order('shop_pages',array('active'=>'Y','type'=>'service'),'order','asc') ;
		
		
		
		
		if($details!==FALSE){$data['details'] = $details ;}
		
	
		//$this->load->view('website/base_header');
		//$this->load->view('website/menu',$data);
		//$this->load->view('website/about',$data);
		//$this->load->view('website/right');
		//$this->load->view('website/footer');
		
			
		$testimonials = $this->Db_model->get_where_by_order('testimonials',array('active'=>'Y','type'=>'about'),'order','asc') ;
		
		
		
		
		if($testimonials!==FALSE)
		{
			$data['testimonials'] = $testimonials ;
		}
		

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		

	$this->load->view('website/header',$data);
	$this->load->view('website/menu',$data);
	$this->load->view('website/home',$data);
   $this->load->view('website/footer',$data);
		
	
	}
	
	

	

}
