\!/ KyuuKazami \!/

Path : /home/kohli/public_html/application/controllers/
Upload :
Current File : /home/kohli/public_html/application/controllers/products.php

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

class Products extends CI_Controller {
    public function __construct()
    {
        parent::__construct();        
        $this->load->library("common_lib");
        $this->load->model("productm");
        $this->load->model("commonm");
    }	
    
    public function get_product_data(){
        $data = array();
        $cid = $this->common_lib->fSafeNum($this->uri->segment(2));
        
        
        $per_page_limit = $this->config->item('product_list_limit');
        $column = "product_name";
        $sort = "asc";
        if($this->input->get("sort") != ""){                
            $sort_pair = explode(":",urldecode($this->input->get("sort")));                
            if(count($sort_pair) == 2){                    
                if($sort_pair[0] == "price"){
                    $column = "price";                        
                }else{
                    $column = "product_name";                        
                }                    
                if($sort_pair[1] == "asc"){
                    $sort = "asc";
                }else{
                    $sort = "desc";   
                }
                        
            }
        }
        
        $sort_data['sort_column'] = $this->input->get("sort");
        $sort_data['limit'] = $this->input->get("limit");
        
        if($this->common_lib->get_n_get("limit") > 0 && $this->common_lib->get_n_get("limit") <= 150){
            $per_page_limit = $this->common_lib->get_n_get("limit");
        }
        
        $cname = $this->uri->segment(3);
        $offset = $this->common_lib->fSafeNum($this->uri->segment(4));
        
        $search_criteria = array();
        
        
        
        if($cid > 0){            
            $product_list_count = $this->productm->get_category_products($cid);        
            $product_list = $this->productm->get_category_products($cid,$offset,$per_page_limit,$column,$sort);
            $collection_id = $this->commonm->get_all("categories",array("category_id" => $cid));
            $collection_id = $collection_id[0]->collection_id;                                    
            $data['current_category'] = $cid;
            $data['collection_id'] = $collection_id;
            $category_name = $this->commonm->get_all("categories",array("category_id" => $cid));
            $data['breadcrumb'] = $category_name[0]->category_name;
            $data['mode'] = "category"; 
        }else{
            $data['current_category'] = 0;
            $data['collection_id'] = 0;
            $search_keyword = $this->common_lib->get_get("q");
            $data['breadcrumb'] = $search_keyword;
            
            if($search_keyword != ""){
                $search_criteria['search_string'] = "(product_name like '%$search_keyword%' or sku like '%$search_keyword%' or item_number like '%$search_keyword%')"; 
            }
            $data['mode'] = "search";
            
            $product_list_count = $this->productm->get_category_products($search_criteria);
            $product_list = $this->productm->get_category_products($search_criteria,$offset,$per_page_limit,$column,$sort);
        }  
        
        $data['pagination'] = $this->common_lib->render_pagination(site_url("category-products")."/$cid/$cname",count($product_list_count),4,$per_page_limit);
        $data['offset'] = $offset;
        $data['total_items'] = count($product_list_count);
        $data['sort_data'] = $sort_data;
                      
        $data['product_list'] = $product_list;
        return $data;
    }
     
    public function index(){
        $data = $this->get_product_data();
        $data['inner_template'] = "products/products_list";
        $this->load->view('layout/layout_main.php',$data);		
    }
    
    public function product_list(){
        
    }
    
    public function detail($pid=0,$ptitle=''){
        $data = array();
        if($pid > 0){            
            $product_detail = $this->productm->get_product_detail($pid);
            if(count($product_detail) > 0){
                $product_variant = $this->productm->get_product_variant($pid,$product_detail[0]->item_number);
                $product_images = $this->commonm->get_all("product_images",array("product_id"=>$pid));
                $product_list = $this->productm->get_latest_products();       
                $product_reviews = $this->productm->get_product_reviews($pid);
                
                $data['product_variant'] = $product_variant;       
                $data['product_reviews'] = $product_reviews;
                $data['product_list'] = $product_list;
                $data['product_detail'] = $product_detail;
                $data['product_images'] = $product_images;
                $data['inner_template'] = "products/detail";
            }else{
                $data['inner_template'] = "layout/page-404";
            }
        }else{
            $data['inner_template'] = "layout/page-404";
        }        
        $this->load->view('layout/layout_main.php',$data);		
    }
    
    public function clearance(){
        $data = array();
        $cid = $this->uri->segment(2);                
        
        $per_page_limit = $this->config->item('product_list_limit');
        $column = "product_name";
        $sort = "asc";
        if($this->input->get("sort") != ""){                
            $sort_pair = explode(":",urldecode($this->input->get("sort")));                
            if(count($sort_pair) == 2){                    
                if($sort_pair[0] == "price"){
                    $column = "price";                        
                }else{
                    $column = "product_name";
                }                    
                if($sort_pair[1] == "asc"){
                    $sort = "asc";
                }else{
                    $sort = "desc";   
                }
                        
            }
        }
        
        $sort_data['sort_column'] = $this->input->get("sort");
        $sort_data['limit'] = $this->input->get("limit");
        
        if($this->common_lib->get_n_get("limit") > 0 && $this->common_lib->get_n_get("limit") <= 150){
            $per_page_limit = $this->common_lib->get_n_get("limit");
        }
        
        $cname = $this->uri->segment(3);
        $offset = $this->common_lib->fSafeNum($this->uri->segment(4));
        $product_list_count = $this->productm->get_clearance_products();
    
        $product_list = $this->productm->get_clearance_products($offset,$per_page_limit,$column,$sort);
        
        $data['sort_data'] = $sort_data;
        
        $data['current_category'] = $cid;
        $data['pagination'] = $this->common_lib->render_pagination(site_url("products/clearance"),count($product_list_count),4,$per_page_limit);
        $data['offset'] = $offset;
        $data['total_items'] = count($product_list_count);
                                          
        
        $data['product_list'] = $product_list;
        $data['inner_template'] = "products/products_list";
        $this->load->view('layout/layout_main.php',$data);
    }
    public function dealsproduct(){
        $data = array();
        $cid = $this->uri->segment(2);                
        
        $per_page_limit = $this->config->item('product_list_limit');
        $column = "product_name";
        $sort = "asc";
        if($this->input->get("sort") != ""){                
            $sort_pair = explode(":",urldecode($this->input->get("sort")));                
            if(count($sort_pair) == 2){                    
                if($sort_pair[0] == "price"){
                    $column = "price";                        
                }else{
                    $column = "product_name";
                }                    
                if($sort_pair[1] == "asc"){
                    $sort = "asc";
                }else{
                    $sort = "desc";   
                }
                        
            }
        }
        
        $sort_data['sort_column'] = $this->input->get("sort");
        $sort_data['limit'] = $this->input->get("limit");
        
        if($this->common_lib->get_n_get("limit") > 0 && $this->common_lib->get_n_get("limit") <= 150){
            $per_page_limit = $this->common_lib->get_n_get("limit");
        }
        $global_setting = $this->commonm->get_all("product_settings");
        $cname = $this->uri->segment(3);
        $offset = $this->common_lib->fSafeNum($this->uri->segment(4));
        $product_list_count = $this->productm->get_deal_products();
    
        $product_list = $this->productm->get_deal_products($offset,$per_page_limit,$column,$sort);
        
        $data['sort_data'] = $sort_data;
        $data['breadcrumb'] = " Deal Products";
        $data['current_category'] = $cid;
        $data['pagination'] = $this->common_lib->render_pagination(site_url("products/dealsproduct"),count($product_list_count),4,$per_page_limit);
        $data['offset'] = $offset;
        $data['total_items'] = count($product_list_count);
                                          
        
        $data['product_list'] = $product_list;
        $data['inner_template'] = "products/products_list";
        $this->load->view('layout/layout_main.php',$data);
    }
    
    public function ourdesign(){
        $data = array();
        $cid = $this->uri->segment(2);                
        
        $per_page_limit = $this->config->item('product_list_limit');
        $column = "product_name";
        $sort = "asc";
        if($this->input->get("sort") != ""){                
            $sort_pair = explode(":",urldecode($this->input->get("sort")));                
            if(count($sort_pair) == 2){                    
                if($sort_pair[0] == "price"){
                    $column = "price";                        
                }else{
                    $column = "product_name";
                }                    
                if($sort_pair[1] == "asc"){
                    $sort = "asc";
                }else{
                    $sort = "desc";   
                }
                        
            }
        }
        
        $sort_data['sort_column'] = $this->input->get("sort");
        $sort_data['limit'] = $this->input->get("limit");
        
        if($this->common_lib->get_n_get("limit") > 0 && $this->common_lib->get_n_get("limit") <= 150){
            $per_page_limit = $this->common_lib->get_n_get("limit");
        }
        $global_setting = $this->commonm->get_all("product_settings");
        $cname = $this->uri->segment(3);
        $offset = $this->common_lib->fSafeNum($this->uri->segment(4));
        $product_list_count = $this->productm->get_hot_products();
    
        $product_list = $this->productm->get_hot_products($offset,$per_page_limit,$column,$sort);
        
        $data['sort_data'] = $sort_data;
        $data['breadcrumb'] = " Our Design";
        $data['current_category'] = $cid;
        $data['pagination'] = $this->common_lib->render_pagination(site_url("products/ourdesign"),count($product_list_count),4,$per_page_limit);
        $data['offset'] = $offset;
        $data['total_items'] = count($product_list_count);
                                          
        
        $data['product_list'] = $product_list;
        $data['inner_template'] = "products/products_list";
        $this->load->view('layout/layout_main.php',$data);
    }
    
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

@KyuuKazami