Subversion Repositories SmartDukaan

Rev

Rev 11169 | Blame | Compare with Previous | Last modification | View Log | RSS feed

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

class Home extends MY_Controller {

public $layoutName ='';
        
        function __construct() {

                // Call the CI_controller constructor
                parent::__construct();
                // $admin = $this->session->userdata('admin');
                // if(!isset($admin) || empty($admin)) {
                //      redirect(base_url().'authorize');
                // }
                $this->layout->setlayout('layout/layout_main');
                $this->load->model('home_model');
                $this->layoutName= $this->layout->getLayout();
                $this->layoutName =substr($this->layoutName , 0, strrpos($this->layoutName , "/")).'/';
                //print_r($this->session->all_userdata());
                

        }
        public function index()
        {

                $configdata =array();
                $configdata = $this->config->item('home');
                $checkConfig = $this->config->item('home');
                $cachemodule = array('header','footer','response');
                $configdata = getCache($configdata,$cachemodule);
                unset($checkConfig['response'][2]);
                unset($configdata['module']['response'][2]);
                $recommended_accessories = false;
                /*------------------------recomeended accessories-------------------------------- */
                // $detect = new Mobile_Detect;
                // $deviceType = ($detect->isMobile() ? ($detect->isTablet() ? 'tablet' : 'phone') : 'computer');
                // $scriptVersion = $detect->getScriptVersion();
                // //echo $detect->getUserAgent();
                // if($detect->isAndroidOS() == 1){
                //      $str=explode('Build', $detect->getUserAgent());
                //      $str=explode(';', $str[0]);
                //      $str = end($str);
                //      $str = ltrim($str);
                //      $str = rtrim($str);
                //      $this->session->set_userdata('mobileBuild',$str);
                //      //print_r($detect->getUaHttpHeaders());
                // }else if($detect->isIphone() ==1){
                //      $this->session->set_userdata('mobileBuild','iPhone');
                // }elseif($detect->isWindowsPhoneOS() == 1){
                //      if(strpos($detect->getUserAgent(), 'NOKIA') !== false){
                //              $str=explode('NOKIA', $detect->getUserAgent());
                //              $str=explode(';', $str[1]);
                //              $str=str_replace(')','', $str);
                //              $str = ltrim($str[1]);
                //              $str=rtrim($str);
                //              $this->session->set_userdata('mobileBuild',$str);
                //      }
                // }elseif($detect->isBlackBerry() == 1){
                //      $str=explode('Touch', $detect->getUserAgent());
                //      $str=explode(';', $str[0]);
                //      $str=explode('(', $str[0]);
                //      $str=ltrim($str[1]);
                //      $str=rtrim($str);
                //      $this->session->set_userdata('mobileBuild',$str);
                // }else{
                //      unset($checkConfig['response'][2]);
                //      unset($configdata['module']['response'][2]);
                //      $recommended_accessories = false;
                // }
                /*--------------------------------------------------------------------------------------*/
                //standard array
                $data = array();
                //get cache 
                $newData = array();
                foreach ($checkConfig['response'] as $key => $value) {
                        if($value != 'recommended_accessories' && $value != 'recharge_icons'){
                                $newData[] = $value;
                        }
                }
                $newparams = array();
                if(isset($configdata['response'])){
                        foreach($newData as $key => $value){
                                if(!array_key_exists($value,$configdata['response'])){
                                        $api = 1;
                                }
                        }
                }
                //end of get cache
                $this->lessphp->object()->ccompile('assets/css/common.less','assets/css/common.css');
                $data['stylesheet'] = 'common.css';
                if(isset($api) && $api == 1){
                        //echo '1';
                        $data['response']=$this->home_model->getHome($this->input->get(),$this->input->post(),$checkConfig);
                }elseif(!isset($api)){
                        //print_r($configdata['module']);
                        $data['response']=$this->home_model->getHome($this->input->get(),$this->input->post(),$configdata['module']);
                }
                //print_r($data['response']);
                $tmp = $data['response'];
                //set cache to output or renew cache
                if(isset($cachemodule) and !empty($cachemodule) && !isset($api))
                {
                        foreach($cachemodule as $cm)
                        {
                                if(isset($configdata[$cm]) and !empty($configdata[$cm]))
                                {
                                        $data['response'][$cm]=$configdata[$cm];
                                }
                        }
                }
                if(isset($data['response']['response'])){
                        foreach($newData as $key => $value){
                                if(!array_key_exists($value,$data['response']['response'])){
                                        $noCache = 1;
                                }
                        }
                }
                //print_r($newparams);
                if(!isset($noCache)){
                        setCache($configdata['module'],$cachemodule,$data['response']);
                }
                // if(!isset($data['response']['response']['home_featured_product']) && empty($data['response']['response']['home_featured_product'])){
                //      $data['response']['response'] = $this->InsertBeforeKey($data['response']['response'],'home_menu','recharge_icons',$tmp['response']['recharge_icons']);
                // }else{
                //      $data['response']['response'] = $this->InsertBeforeKey($data['response']['response'],'home_featured_product','recharge_icons',$tmp['response']['recharge_icons']);
                // }
                // if(!isset($recommended_accessories)){
                //      $data['response']['response'] = $this->InsertBeforeKey($data['response']['response'],'home_menu','recommended_accessories',$tmp['response']['recommended_accessories']);
                // }
                //end of set cache\
                $this->layout->view('home/home_view',$data);
        }
        public function InsertBeforeKey($originalArray,$originalKey,$insertKey,$insertValue){

            $newArray = array();
            $inserted = false;

            foreach( $originalArray as $key => $value ) {

                if( !$inserted && $key === $originalKey ) {
                    $newArray[ $insertKey ] = $insertValue;
                    $inserted = true;
                }

                $newArray[ $key ] = $value;

            }

            return $newArray;

        }
        public function autosuggest($qstr){
                $url = $this->config->item('auto_suggest');
                $url = $url['url'];
        $url = $this->config->item('curl_base_url').$url;
        $params['term'] = rawurldecode($qstr);  
        $this->mcurl->add_call('autosuggest','get',$url,$params);
        $response = $this->mcurl->execute($url);
        $data = $response['autosuggest']['response'];
        $data = str_replace('[', '', $data);
        $data = str_replace(']', '', $data);
        $data = str_replace('"', '', $data);
        echo json_encode(explode(',', $data));
        }
        
}

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