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

class Home extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see https://codeigniter.com/user_guide/general/urls.html
	 */
	 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->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;
		}
		
	}
	 
	 
	 
	 
	public function index()
	{
		
		$this->home() ;
	}
	
	public function home()
	{
		$data['result'] = array() ;
		$data['cart_qty'] = $this->cart_qty;
		$data['email'] = $this->user;
		$data['logged'] = $this->logged;
		
		$data['result'] = $this->Db_model->get_where_by_order('shop_pages',array('type'=>'about','active'=>'Y'),'order','desc') ;
		$data['welcome'] = $this->Db_model->get_where_by_order('shop_pages',array('type'=>'welcome','active'=>'Y'),'order','desc') ;
		
		$data['banneresult'] = $this->Db_model->get_where_by_order('shop_banner',array('status'=>'1'),'id','desc') ;
		
		$offer_products = $this->Db_model->get_all_by_order('shop_category','order','asc') ;
		
		$featured = $this->Db_model->get_where_by_order('shop_product',array('featured'=>'1','active'=>'Y'),'order','asc') ;
		
		$data['contactus'] = $this->Db_model->get_where_by_order('shop_contact',array('status'=>'1'),'id','desc') ;
		
		$data['category'] = $this->Db_model->get_all_by_order('shop_category','order','asc') ;
		
		if($featured!==FALSE)
		{
			$data['featured'] = $featured;
		}
		else
		{
			$data['featured'] = array() ;
		}
		
		
		$this->load->view('website/header',$data);
		$this->load->view('website/topbar',$data);
		$this->load->view('website/banner',$data);
		$this->load->view('website/menu',$data);
		$this->load->view('website/content',$data);
		//$this->load->view('website/prducts');
		$this->load->view('website/footer');
	}
	
}
