Subversion Repositories SmartDukaan

Rev

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