Subversion Repositories SmartDukaan

Rev

Rev 11108 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
10582 lgm 1
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2
 
3
class Home extends MY_Controller {
4
 
5
public $layoutName ='';
6
 
7
	function __construct() {
8
 
9
		// Call the CI_controller constructor
10
		parent::__construct();
11108 lgm 11
		// $admin = $this->session->userdata('admin');
12
		// if(!isset($admin) || empty($admin)) {
13
		// 	redirect(base_url().'authorize');
14
		// }
10582 lgm 15
		$this->layout->setlayout('layout/layout_main');
16
		$this->load->model('home_model');
17
		$this->layoutName= $this->layout->getLayout();
18
		$this->layoutName =substr($this->layoutName , 0, strrpos($this->layoutName , "/")).'/';
11169 lgm 19
		//print_r($this->session->all_userdata());
10582 lgm 20
 
21
 
22
	}
23
	public function index()
24
	{
11169 lgm 25
 
11056 lgm 26
		$configdata =array();
27
		$configdata = $this->config->item('home');
28
		$checkConfig = $this->config->item('home');
29
		$cachemodule = array('header','footer','response');
30
		$configdata = getCache($configdata,$cachemodule);
10582 lgm 31
		$detect = new Mobile_Detect;
32
		$deviceType = ($detect->isMobile() ? ($detect->isTablet() ? 'tablet' : 'phone') : 'computer');
33
		$scriptVersion = $detect->getScriptVersion();
34
		//echo $detect->getUserAgent();
35
		if($detect->isAndroidOS() == 1){
36
			$str=explode('Build', $detect->getUserAgent());
37
			$str=explode(';', $str[0]);
38
			$str = end($str);
39
			$str = ltrim($str);
40
			$str = rtrim($str);
41
			$this->session->set_userdata('mobileBuild',$str);
42
			//print_r($detect->getUaHttpHeaders());
43
		}else if($detect->isIphone() ==1){
44
			$this->session->set_userdata('mobileBuild','iPhone');
45
		}elseif($detect->isWindowsPhoneOS() == 1){
46
			if(strpos($detect->getUserAgent(), 'NOKIA') !== false){
47
				$str=explode('NOKIA', $detect->getUserAgent());
48
				$str=explode(';', $str[1]);
49
				$str=str_replace(')','', $str);
50
				$str = ltrim($str[1]);
51
				$str=rtrim($str);
52
				$this->session->set_userdata('mobileBuild',$str);
53
			}
10853 lgm 54
		}elseif($detect->isBlackBerry() == 1){
55
			$str=explode('Touch', $detect->getUserAgent());
56
			$str=explode(';', $str[0]);
57
			$str=explode('(', $str[0]);
58
			$str=ltrim($str[1]);
59
			$str=rtrim($str);
60
			$this->session->set_userdata('mobileBuild',$str);
11056 lgm 61
		}else{
11169 lgm 62
			unset($checkConfig['response'][2]);
63
			unset($configdata['module']['response'][2]);
11056 lgm 64
			$recommended_accessories = false;
10582 lgm 65
		}
66
		//standard array
67
		$data = array();
68
		//get cache 
10933 lgm 69
		$newData = array();
70
		foreach ($checkConfig['response'] as $key => $value) {
71
			if($value != 'recommended_accessories' && $value != 'recharge_icons'){
72
				$newData[] = $value;
73
			}
74
		}
75
		$newparams = array();
76
		if(isset($configdata['response'])){
77
			foreach($newData as $key => $value){
78
	 			if(!array_key_exists($value,$configdata['response'])){
79
					$api = 1;
80
				}
81
	 		}
82
		}
10582 lgm 83
		//end of get cache
84
		$this->lessphp->object()->ccompile('assets/css/common.less','assets/css/common.css');
85
		$data['stylesheet'] = 'common.css';
10933 lgm 86
		if(isset($api) && $api == 1){
11169 lgm 87
			//echo '1';
11056 lgm 88
			$data['response']=$this->home_model->getHome($this->input->get(),$this->input->post(),$checkConfig);
10933 lgm 89
		}elseif(!isset($api)){
11169 lgm 90
			//print_r($configdata['module']);
10933 lgm 91
			$data['response']=$this->home_model->getHome($this->input->get(),$this->input->post(),$configdata['module']);
92
		}
93
		//print_r($data['response']);
10582 lgm 94
		$tmp = $data['response'];
95
		//set cache to output or renew cache
10933 lgm 96
		if(isset($cachemodule) and !empty($cachemodule) && !isset($api))
10582 lgm 97
		{
98
			foreach($cachemodule as $cm)
99
			{
100
				if(isset($configdata[$cm]) and !empty($configdata[$cm]))
101
				{
102
					$data['response'][$cm]=$configdata[$cm];
103
				}
104
			}
105
		}
10933 lgm 106
		if(isset($data['response']['response'])){
107
			foreach($newData as $key => $value){
108
	 			if(!array_key_exists($value,$data['response']['response'])){
109
					$noCache = 1;
10751 lgm 110
				}
10933 lgm 111
	 		}
10751 lgm 112
		}
10933 lgm 113
		//print_r($newparams);
114
		if(!isset($noCache)){
10751 lgm 115
			setCache($configdata['module'],$cachemodule,$data['response']);
116
		}
11169 lgm 117
		// if(!isset($data['response']['response']['home_featured_product']) && empty($data['response']['response']['home_featured_product'])){
118
		// 	$data['response']['response'] = $this->InsertBeforeKey($data['response']['response'],'home_menu','recharge_icons',$tmp['response']['recharge_icons']);
119
		// }else{
120
		// 	$data['response']['response'] = $this->InsertBeforeKey($data['response']['response'],'home_featured_product','recharge_icons',$tmp['response']['recharge_icons']);
121
		// }
11056 lgm 122
		if(!isset($recommended_accessories)){
123
			$data['response']['response'] = $this->InsertBeforeKey($data['response']['response'],'home_menu','recommended_accessories',$tmp['response']['recommended_accessories']);
124
		}
10582 lgm 125
		//end of set cache\
126
		$this->layout->view('home/home_view',$data);
127
	}
128
	public function InsertBeforeKey($originalArray,$originalKey,$insertKey,$insertValue){
129
 
130
	    $newArray = array();
131
	    $inserted = false;
132
 
133
	    foreach( $originalArray as $key => $value ) {
134
 
135
	        if( !$inserted && $key === $originalKey ) {
136
	            $newArray[ $insertKey ] = $insertValue;
137
	            $inserted = true;
138
	        }
139
 
140
	        $newArray[ $key ] = $value;
141
 
142
	    }
143
 
144
	    return $newArray;
145
 
146
	}
147
	public function autosuggest($qstr){
148
		$url = $this->config->item('auto_suggest');
149
	  	$url = $url['url'];
150
        $url = $this->config->item('curl_base_url').$url;
151
        $params['term'] = rawurldecode($qstr);	
152
        $this->mcurl->add_call('autosuggest','get',$url,$params);
153
        $response = $this->mcurl->execute($url);
154
        $data = $response['autosuggest']['response'];
155
        $data = str_replace('[', '', $data);
156
        $data = str_replace(']', '', $data);
157
        $data = str_replace('"', '', $data);
158
        echo json_encode(explode(',', $data));
159
	}
160
}
161
 
162
/* End of file welcome.php */
163
/* Location: ./application/controllers/welcome.php */