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

class List_property extends CI_Controller {


	private $cart_qty   = '' ;
	private $logged 	= 0  ;	
	private $user 		= '' ;
	
	public function __construct()
	{
		parent::__construct();
		
		$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.'';
		
		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()
	{	
		
		$data['product'] = array();
		$data['preproduct'] = array();
		$data['result']= array();
		$data['categoryes']=array();
		$data['cart_qty'] = $this->cart_qty ;
		$data['brand_id'] = $this->brand_id ;
		$data['email'] = $this->user;
		$data['logged'] = $this->logged;
		
		
		if($data['email']=='') { redirect('User/register'); }
		
		$data['allproduct']= $this->Db_model->get_where_by_order('shop_product',array('reg_user_mail'=>''.$this->user.''),'order','asc') ;
        $data['brand'] = $this->Db_model->get_where_by_order('shop_brand',array(),'order','asc') ;
		$data['contactus'] = $this->Db_model->get_where_by_order('shop_contact',array('status'=>'1'),'id','desc') ;
		$data['site'] = $this->Db_model->get_all('site',array()) ;
		$data['service'] = $this->Db_model->get_where_by_order('shop_pages',array('active'=>'Y','type'=>'service'),'order','asc') ;
		$data['category']=$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['category']=$data['result'] = $this->Db_model->get_all_by_order('shop_category','order','asc') ;
		//$product = $this->Db_model->get_where_by_order('shop_product',array('active'=>'Y'),'order','asc') ;
		



			
//echo '<pre>'; print_r($previous); echo '</pre>';


//foreach ($previous as $value) {
//  echo "$value <br>";
//  
//}
//	$product = $this->Db_model->where_in('shop_productr',array('aid'=>4,'aid'=>7),'order','asc') ;
//$ids = array(33, 34, 45);
//$dbStations->where_in('id', $ids);
// Produces: WHERE id IN (33, 34, 45)
		
		if($this->input->post('submit'))
		{
			
	        $categories5=$this->input->post('categories');
		    $sub_categories5=$this->input->post('sub_categories');
		   $brand5=$this->input->post('brand');
		   
		  
		   redirect('Search_product?cid='.$categories5.'&&sid='.$sub_categories5.'&&bid='.$brand5.'/');
			
		}
		else
		{
$email_id=$data['email'];
$sql ="SELECT * FROM shop_checkoutusers where email='$email_id' ";
$query = $this->db->query($sql);
if ($query->num_rows() > 0) {
foreach($query->result() as $row) {
$user_id=$row->id;
}
}
		
$sql2 ="SELECT * FROM shop_order where user_id='$user_id' ";
$query2 = $this->db->query($sql2);
if ($query2->num_rows() > 0) {
foreach($query2->result() as $row2) {
$prod_id[]=$row2->prod_id;		
}
}


if($prod_id!=''){
$previous=array_unique($prod_id);
$preproduct=$product=$this->Db_model->information('shop_product',$previous) ;
}
}
		
if($_GET["cid"]) {  $cid=$_GET["cid"]; } 
if($_GET["sid"]) {  $sid=$_GET["sid"]; } 
if($_GET["bid"]) {  $bid=$_GET["bid"]; }  
if($cid!='') { $product = $this->Db_model->get_where_by_order('shop_product',array('category_id'=>$cid,'active'=>'Y'),'order','asc') ;}  
if($sid!='') { $product = $this->Db_model->get_where_by_order('shop_product',array('subcategory_id'=>$sid,'active'=>'Y'),'order','asc') ;}		
if($bid!='') { $product = $this->Db_model->get_where_by_order('shop_product',array('brand_id'=>$bid,'active'=>'Y'),'order','asc') ;}	


if($cid!='' && $sid!='' ) { $product = $this->Db_model->get_where_by_order('shop_product',array('category_id'=>$cid,'subcategory_id'=>$sid,'active'=>'Y'),'order','asc') ;}
if($cid!='' && $sid!='' &&  $bid!='' ) { $product = $this->Db_model->get_where_by_order('shop_product',array('category_id'=>$cid,'subcategory_id'=>$sid,'brand_id'=>$bid,'active'=>'Y'),'order','asc') ;}

	   
		
		
		if($product!==FALSE)
		{
		$data['product'] = $product;
	
		}
		
		
		
		
		if($this->input->post('addtocart'))
		{
			
			
			 $pro_id=$this->input->post('pro_id');
			 $price=$this->input->post('price');
			 $unit_id=$this->input->post('unit_id');
			 $url=$this->input->post('url');
			 $title=$this->input->post('title');
			 $qty=$this->input->post($pro_id);
			
			redirect('Cart/quckinsert/'.$pro_id.'/'.$qty.'/'.$price.'/'.$unit_id.'/'.$url.'/'.$cid.'/'.$sid.'/'.$bid);
			//'Cart/insert/'.$row_off['aid'].'/1/'.$row_off['price'].'/'.$row_off['unit_id'].'/'.$url.'/'.url_title($row_off->title,'-',true)
		}
		
		
		
		
		$this->load->view('website/header');
        $this->load->view('website/menu',$data);
		$this->load->view('website/list_property',$data);
        $this->load->view('website/footer');
	}
	
}
