Subversion Repositories SmartDukaan

Rev

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