Subversion Repositories SmartDukaan

Rev

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