Subversion Repositories SmartDukaan

Rev

Rev 10851 | Rev 10933 | 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');
61
		$cachemodule = array('header','footer','response');
62
		$configdata = getCache($configdata,$cachemodule);
63
		//end of get cache
64
		$this->lessphp->object()->ccompile('assets/css/common.less','assets/css/common.css');
65
		$data['stylesheet'] = 'common.css';
66
		$data['response']=$this->home_model->getHome($this->input->get(),$this->input->post(),$configdata['module']);
67
		$tmp = $data['response'];
68
		//set cache to output or renew cache
69
		if(isset($cachemodule) and !empty($cachemodule))
70
		{
71
			foreach($cachemodule as $cm)
72
			{
73
				if(isset($configdata[$cm]) and !empty($configdata[$cm]))
74
				{
75
					$data['response'][$cm]=$configdata[$cm];
76
				}
77
			}
78
		}
10751 lgm 79
		//print_r($data['response']['response']);
80
		if(isset($data['response']['response']) && !empty($data['response']['response'])){
81
			foreach($data['response']['response'] as $rs)
82
			{
83
				if(!isset($rs) || empty($rs)){
84
					$cache = 0;
85
					break;
86
				}
87
			}
88
		}
89
		if(!isset($cache) || $cache != 0){
90
			setCache($configdata['module'],$cachemodule,$data['response']);
91
		}
10851 lgm 92
		if(isset($data['response']['response']['home_featured_product']) && !empty($data['response']['response']['home_featured_product'])){
93
			$data['response']['response'] = $this->InsertBeforeKey($data['response']['response'],'home_featured_product','recharge_icons',$tmp['response']['recharge_icons']);
94
		}else{
95
			$data['response']['response'] = $this->InsertBeforeKey($data['response']['response'],'home_menu','recharge_icons',$tmp['response']['recharge_icons']);
96
		}
10582 lgm 97
		$data['response']['response'] = $this->InsertBeforeKey($data['response']['response'],'home_menu','recommended_accessories',$tmp['response']['recommended_accessories']);
98
		//end of set cache\
99
		$this->layout->view('home/home_view',$data);
100
	}
101
	public function InsertBeforeKey($originalArray,$originalKey,$insertKey,$insertValue){
102
 
103
	    $newArray = array();
104
	    $inserted = false;
105
 
106
	    foreach( $originalArray as $key => $value ) {
107
 
108
	        if( !$inserted && $key === $originalKey ) {
109
	            $newArray[ $insertKey ] = $insertValue;
110
	            $inserted = true;
111
	        }
112
 
113
	        $newArray[ $key ] = $value;
114
 
115
	    }
116
 
117
	    return $newArray;
118
 
119
	}
120
	public function autosuggest($qstr){
121
		$url = $this->config->item('auto_suggest');
122
	  	$url = $url['url'];
123
        $url = $this->config->item('curl_base_url').$url;
124
        $params['term'] = rawurldecode($qstr);	
125
        $this->mcurl->add_call('autosuggest','get',$url,$params);
126
        $response = $this->mcurl->execute($url);
127
        $data = $response['autosuggest']['response'];
128
        $data = str_replace('[', '', $data);
129
        $data = str_replace(']', '', $data);
130
        $data = str_replace('"', '', $data);
131
        echo json_encode(explode(',', $data));
132
	}
133
}
134
 
135
/* End of file welcome.php */
136
/* Location: ./application/controllers/welcome.php */