Rev 10815 | Rev 10853 | Go to most recent revision | 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 constructorparent::__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(){$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);}}//standard array$data = array();//get cache$configdata =array();$configdata = $this->config->item('home');$cachemodule = array('header','footer','response');$configdata = getCache($configdata,$cachemodule);//end of get cache$this->lessphp->object()->ccompile('assets/css/common.less','assets/css/common.css');$data['stylesheet'] = 'common.css';$data['response']=$this->home_model->getHome($this->input->get(),$this->input->post(),$configdata['module']);$tmp = $data['response'];//set cache to output or renew cacheif(isset($cachemodule) and !empty($cachemodule)){foreach($cachemodule as $cm){if(isset($configdata[$cm]) and !empty($configdata[$cm])){$data['response'][$cm]=$configdata[$cm];}}}//print_r($data['response']['response']);if(isset($data['response']['response']) && !empty($data['response']['response'])){foreach($data['response']['response'] as $rs){if(!isset($rs) || empty($rs)){$cache = 0;break;}}}if(!isset($cache) || $cache != 0){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_featured_product','recharge_icons',$tmp['response']['recharge_icons']);}else{$data['response']['response'] = $this->InsertBeforeKey($data['response']['response'],'home_menu','recharge_icons',$tmp['response']['recharge_icons']);}$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 */