Subversion Repositories SmartDukaan

Rev

Rev 10751 | Go to most recent revision | Details | 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
		}
72
		setCache($configdata['module'],$cachemodule,$data['response']);
73
		$data['response']['response'] = $this->InsertBeforeKey($data['response']['response'],'home_menu','recommended_accessories',$tmp['response']['recommended_accessories']);
74
		//end of set cache\
75
		$this->layout->view('home/home_view',$data);
76
	}
77
	public function InsertBeforeKey($originalArray,$originalKey,$insertKey,$insertValue){
78
 
79
	    $newArray = array();
80
	    $inserted = false;
81
 
82
	    foreach( $originalArray as $key => $value ) {
83
 
84
	        if( !$inserted && $key === $originalKey ) {
85
	            $newArray[ $insertKey ] = $insertValue;
86
	            $inserted = true;
87
	        }
88
 
89
	        $newArray[ $key ] = $value;
90
 
91
	    }
92
 
93
	    return $newArray;
94
 
95
	}
96
	public function autosuggest($qstr){
97
		$url = $this->config->item('auto_suggest');
98
	  	$url = $url['url'];
99
        $url = $this->config->item('curl_base_url').$url;
100
        $params['term'] = rawurldecode($qstr);	
101
        $this->mcurl->add_call('autosuggest','get',$url,$params);
102
        $response = $this->mcurl->execute($url);
103
        $data = $response['autosuggest']['response'];
104
        $data = str_replace('[', '', $data);
105
        $data = str_replace(']', '', $data);
106
        $data = str_replace('"', '', $data);
107
        echo json_encode(explode(',', $data));
108
	}
109
}
110
 
111
/* End of file welcome.php */
112
/* Location: ./application/controllers/welcome.php */