Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

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