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

class Product 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');
		$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;
		}
		
	}
	
	public function index()
	{
		$this->category() ;
	}
	
	public function view($id='',$title='')
	{
	    $qty = 1;
		$data['qty'] = $qty;
	
		$id = $this->uri->segment(3,'') ;
  
		
		$data['product'] = array();
		$data['result']= array();
		$data['result']= array();
		$data['books']=array();
		$data['related']=array();
		$data['cart_qty'] = $this->cart_qty ;
		$data['email'] = $this->user;
		$data['logged'] = $this->logged;
		$data['contactus'] = $this->Db_model->get_where_by_order('shop_contact',array('status'=>'1'),'id','desc') ;
		$data['units'] = $this->Db_model->get_all('shop_unit') ;
		$data['category'] = $this->Db_model->get_all_by_order('shop_category','order','asc') ;
$books = $this->Db_model->get_where_by_order('shop_product',array('active'=>'Y'),'order','asc') ;

		
		if($books!==FALSE)
		{
			$data['books'] = $books;
		}
		
		
		//$data['result'] = $this->Db_model->get_where_by_order('shop_product',array('active'=>'Y'),'order','asc') ;
		$product = $this->Db_model->get_one('shop_product',array('aid'=>$id,'active'=>'Y')) ;
		$related = $this->Db_model->get_where_by_order('shop_relproduct',array('active'=>'Y','product_id'=>$id),'order','asc');
		
		if($related!==FALSE)
		{
			$data['related'] = $related;
		}
		
		
		//$subcategory_id=$product->subcategory_id;
		//$category_id=$product->category_id;
		
		//$data['categoryes'] = $this->Db_model->get_where_by_order('shop_product',array('category_id'=>$category_id,'active'=>'Y'),'order','asc') ;
		
		//$data['subcategory'] = $this->Db_model->get_one('shop_subcategory',array('id'=>$subcategory_id)) ;
		//$data['categoryname'] = $this->Db_model->get_one('shop_category',array('id'=>$category_id)) ;
		
		if($product!==FALSE)
		{
			$data['product'] = $product ;
		}
		
	
		$this->load->view('website/header',$data);
		$this->load->view('website/topbar',$data);
		$this->load->view('website/menu',$data);
		$this->load->view('website/prd_content1',$data);
		$this->load->view('website/footer');
	}
	
	
	public function category($limit_from='')
	{
		$categories = array() ;
		
		$total_rows = 0;
		$per_page = 12;
		
		
		$data['result'] = array() ;
		$data['categories'] = array() ;
		$data['cart_qty'] = $this->cart_qty ;
		$data['email'] = $this->user;
		$data['logged'] = $this->logged;
		
		
		
		$categories = $this->Db_model->get_all_by_order_limit('shop_category','order','asc',$limit_from,$per_page) ;
		
		if($categories!==FALSE)
		{
			$data['categories'] = $categories ;
		}
		
		
		
		/* pagination part */
		
		$total_rows = $this->Db_model->get_count('shop_category') ;
		
		$this->load->library('pagination');

		$config['base_url'] = base_url('product/category') ;
		$config['total_rows'] = $total_rows;
		$config['per_page'] = $per_page;
		$config['full_tag_open'] = '<div align="center" class="page_div">';
		$config['full_tag_close'] = '</div>';
		$config['first_link'] = 'First';
		$config['first_tag_open'] = '<span class="first">';
		$config['first_tag_close'] = '</span>';
		$config['last_link'] = 'Last';
		$config['last_tag_open'] = '<span class="last">';
		$config['last_tag_close'] = '</span>';
		$config['num_tag_open'] = '<span class="page_digit">';
		$config['num_tag_close'] = '</span>';
		$config['next_link'] = '&gt;';
		$config['next_tag_open'] = '<span class="next">';
		$config['next_tag_close'] = '</span>';
		$config['prev_link'] = '&lt;';
		$config['prev_tag_open'] = '<span class="prev">';
		$config['prev_tag_close'] = '</span>';
		
		$this->pagination->initialize($config);
		
		$data['pagination'] = $this->pagination->create_links();
		
		/* end pagination */
		
		
		
		$this->load->view('website/prd_header');
		$this->load->view('website/topbar',$data);
		$this->load->view('website/menu',$data);
		$this->load->view('website/category_list',$data);
		$this->load->view('website/right'); 
		$this->load->view('website/footer');
	}
	
	
	public function items($category_id='',$title='')
	{
		$data['result'] = array() ;
		$data['books'] = array() ;
		$data['category']=array() ;
		$data['cart_qty'] = $this->cart_qty ;
		$data['email'] = $this->user;
		$data['logged'] = $this->logged;
		$data['title']=$title;
	
		
		//$data['category'] = get_category_by_id($category_id) ;
		$data['contactus'] = $this->Db_model->get_where_by_order('shop_contact',array('status'=>'1'),'id','desc') ;
		$data['category']=$data['result'] = $this->Db_model->get_all_by_order('shop_category','order','asc') ;
		$data['subcate'] = $this->Db_model->get_all_by_order('shop_subcategory','id','desc') ;
		$data['categoryname'] = $this->Db_model->get_one('shop_category',array('id'=>$category_id)) ;
		//$data['result'] = $this->Db_model->get_where_by_order('shop_product',array('active'=>'Y'),'order','asc') ;
		$books = $this->Db_model->get_where_by_order('shop_product',array('category_id'=>$category_id,'active'=>'Y'),'order','asc') ;
		
		if($books!==FALSE)
		{
			$data['books'] = $books;
		}
				
		$this->load->view('website/item_header',$data);
			$this->load->view('website/topbar',$data);
		$this->load->view('website/menu',$data);
		$this->load->view('website/item_list',$data);
		
		$this->load->view('website/footer');
	}
	
	public function item()
	{

		$data['result'] = array() ;
		$data['books'] = array() ;
		$data['category']=array() ;
		$data['cart_qty'] = $this->cart_qty ;
		$data['email'] = $this->user;
		$data['logged'] = $this->logged;
		$data['title']='';
		//$data['categoryname']=array();
		
		//$subcatego = $this->Db_model->get_one('shop_subcategory',array('id'=>$sub_id)) ;
		//$data['categoryname'] = $this->Db_model->get_one('shop_category',array('id'=>$subcatego->category_id)) ;
		//$data['category'] = get_category_by_id($category_id) ;
		$data['contactus'] = $this->Db_model->get_where_by_order('shop_contact',array('status'=>'1'),'id','desc') ;
		$data['category']=$data['result'] = $this->Db_model->get_all_by_order('shop_category','order','asc') ;
		//$data['subcate'] = $this->Db_model->get_all_by_order('shop_subcategory','id','desc') ;
		//$data['result'] = $this->Db_model->get_where_by_order('shop_product',array('active'=>'Y'),'order','asc') ;
		$books = $this->Db_model->get_where_by_order('shop_product',array('active'=>'Y'),'order','asc') ;
		
		if($books!==FALSE)
		{
			$data['books'] = $books;
		}
				
		$this->load->view('website/item_header',$data);
		$this->load->view('website/header',$data);
		$this->load->view('website/topbar',$data);
		$this->load->view('website/menu',$data);
		$this->load->view('website/item_list',$data);
		
		$this->load->view('website/footer');
	}
	
	public function books($category_id='',$title='')
	{
		$data['result'] = array() ;
		$data['books'] = array() ;
		$data['category']=array() ;
		$data['cart_qty'] = $this->cart_qty ;
		$data['email'] = $this->user;
		$data['logged'] = $this->logged;
		$data['title']=$title;
		$data['categoryname']=array();
		//$data['category'] = get_category_by_id($category_id) ;
		
		$data['result'] = $this->Db_model->get_all_by_order('shop_category','order','asc') ;
		$data['subcate'] = $this->Db_model->get_all_by_order('shop_subcategory','id','desc') ;
		$books = $this->Db_model->get_where_by_order('shop_product',array('entrance'=>$category_id,'active'=>'Y'),'order','asc') ;
		
		if($books!==FALSE)
		{
			$data['books'] = $books;
		}
				
		$this->load->view('website/base_header');
		$this->load->view('website/topbar',$data);
		$this->load->view('website/menu',$data);
		$this->load->view('website/item_list',$data);
		
		$this->load->view('website/footer');
	}
	
	public function categorys()
	{
		
		
		$data['result'] = array() ;
		$data['cart_qty'] = $this->cart_qty;
		$data['email'] = $this->user;
		$data['logged'] = $this->logged;
		$data['page'] = 'about' ;
		$data['result'] = $this->Db_model->get_all_by_order('shop_category','order','asc') ;	
		$data['subcate'] = $this->Db_model->get_all_by_order('shop_subcategory','id','desc') ;
		$data['category'] = $this->Db_model->get_all_by_order('shop_category','order','asc') ;
		$data['contactus'] = $this->Db_model->get_where_by_order('shop_contact',array('status'=>'1'),'id','desc') ;
		$data['category1'] = $this->Db_model->get_all_by_order('shop_category','order','asc') ;
		
		
		
	
		$this->load->view('website/base_header',$data);
		$this->load->view('website/topbar',$data);
		$this->load->view('website/menu',$data);
		$this->load->view('website/category_content',$data);
		$this->load->view('website/footer');
	}
	
}
