Subversion Repositories SmartDukaan

Rev

Rev 18192 | Rev 19257 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 18192 Rev 18208
Line 11... Line 11...
11
/**
11
/**
12
 * Components
12
 * Components
13
 *
13
 *
14
 * @var array
14
 * @var array
15
 */
15
 */
-
 
16
	
16
	public $components = array('Paginator');
17
	public $components = array('Paginator');
-
 
18
		    public function beforeFilter() {
-
 
19
		    	parent::beforeFilter();
-
 
20
		    	$this->Auth->allow('index','mobile','error');
-
 
21
		    }
17
 
22
 
18
		public function index() {
23
		public function index() {
19
		$encryptUrl = 'http://shop2020.in:8057/message/encrypt?type=encrypt&data=';
24
		$encryptUrl = 'http://104.200.25.40:8057/message/encrypt?type=encrypt&data=';
20
		$expiryFlag=false;
25
		$expiryFlag=false;
21
		$redirectFlag=false;
26
		$redirectFlag=false;
22
		$this->layout = 'ajax';
27
		$this->layout = 'ajax';
23
		$serverHost= $_SERVER['HTTP_HOST'];
28
		$serverHost= $_SERVER['HTTP_HOST'];
24
		$serverURI = $_SERVER['REQUEST_URI'];
29
		$serverURI = $_SERVER['REQUEST_URI'];
25
		$requestURL ="http://".$serverHost.$serverURI;
30
		$requestURL ="http://".$serverHost.$serverURI;
26
		$intentToSend = '';
31
		$intentToSend = '';
27
		$params = explode($serverHost.'/a', $requestURL);
32
		$params = explode($serverHost.'/A', $requestURL);
28
		$ua = $_SERVER['HTTP_USER_AGENT'];
33
		$ua = $_SERVER['HTTP_USER_AGENT'];
29
				
34
				
30
		if($this->isMobileDevice($ua)){	
35
		if($this->isMobileDevice($ua)){	
31
			if(empty($params[1])){
36
			if(empty($params[1])){
32
				//debug('Redirect to the 404 page condition 1');
-
 
33
				//echo('Redirect to the 404 page condition 1');
-
 
34
				$redirectFlag=true;
37
				$redirectFlag=true;
35
			}else{
38
			}else{
36
				$fetchParams = 	 explode('/', $params[1]);
39
				$fetchParams = 	 explode('/', $params[1]);
37
				if(empty($fetchParams[0]) && empty($fetchParams[1])){
40
				if(empty($fetchParams[0]) && empty($fetchParams[1])){
38
					//debug('Redirect to the 404 page condition 2');
-
 
39
					//echo('Redirect to the 404 page condition 2');
-
 
40
					$redirectFlag=true;
41
					$redirectFlag=true;
41
				}else{
42
				}else{
42
					if(sizeof($fetchParams) == 2 || empty($fetchParams[2])){
43
					if(sizeof($fetchParams) == 2 || empty($fetchParams[2])){
43
						//debug('Redirect to the 404 page condition 3');
-
 
44
						//echo('Redirect to the 404 page condition 3');
-
 
45
						$redirectFlag=true;
44
						$redirectFlag=true;
46
					}else if(sizeof($fetchParams)>4){
45
					}else if(sizeof($fetchParams)>4){
47
						//debug('Redirect to the 404 page condition 4');
-
 
48
						//echo('Redirect to the 404 page condition 4');
-
 
49
						$redirectFlag=true;
46
						$redirectFlag=true;
50
					}else{
47
					}else{
51
						$campaignId = $fetchParams[1];
48
						$campaignId = $fetchParams[1];
52
						$userId = $fetchParams[2];;
49
						$userId = $fetchParams[2];;
53
						
50
						
Line 58... Line 55...
58
						$conn=$this->getDatabaseConnection();
55
						$conn=$this->getDatabaseConnection();
59
						if($conn){
56
						if($conn){
60
							$sql    = 'SELECT * FROM notification_campaigns WHERE id ='.$campaignId;
57
							$sql    = 'SELECT * FROM notification_campaigns WHERE id ='.$campaignId;
61
							$result = mysql_query($sql, $conn);
58
							$result = mysql_query($sql, $conn);
62
							if (mysql_num_rows($result)==0) { 
59
							if (mysql_num_rows($result)==0) { 
63
								debug('Zero rows');
-
 
64
								echo('Zero rows');
-
 
65
								$redirectFlag=true;
60
								$redirectFlag=true;
66
							}else{
61
							}else{
67
								while ($row = mysql_fetch_assoc($result)) {
62
								while ($row = mysql_fetch_assoc($result)) {
68
						    		$notificationUrl = $row['url'];
63
						    		$notificationUrl = $row['url'];
69
						    		$notificationType = $row['type'];
64
						    		$notificationType = $row['type'];
Line 76... Line 71...
76
						    		if(strtotime($notificationExpires) < $currentTime || $notificationStatus=='inactive'){
71
						    		if(strtotime($notificationExpires) < $currentTime || $notificationStatus=='inactive'){
77
						    			$expiryFlag=true;
72
						    			$expiryFlag=true;
78
						    		}
73
						    		}
79
									if($notificationType=='native'){
74
									if($notificationType=='native'){
80
										if(strtolower($notificationUrl)=='contact' || strtolower($notificationUrl)=='profile' ||strtolower($notificationUrl)=='tutorial'){
75
										if(strtolower($notificationUrl)=='contact' || strtolower($notificationUrl)=='profile' ||strtolower($notificationUrl)=='tutorial'){
81
											//debug('V,W,Ir,aH,-y');
-
 
82
											$encryptUrl = $encryptUrl.base64_encode(strtolower($notificationUrl));
76
											$encryptUrl = $encryptUrl.base64_encode(strtolower($notificationUrl));
83
										    $encryptedData = $this->make_request($encryptUrl,null);
77
										    $encryptedData = $this->make_request($encryptUrl,null);
84
										}else{
78
										}else{
85
											$encryptedData = $this->defaultEncryptedMessage($userId);
79
											$encryptedData = $this->defaultEncryptedMessage($userId);
86
										}
80
										}
87
									}else if ($notificationType=='update'){
81
									}else if ($notificationType=='update'){
88
											//debug('K3');
-
 
89
											$encryptUrl = $encryptUrl.base64_encode('https://play.google.com/store/apps/details?id=com.saholic.profittill');
82
											$encryptUrl = $encryptUrl.base64_encode('https://play.google.com/store/apps/details?id=com.saholic.profittill');
90
										    $encryptedData = $this->make_request($encryptUrl,null);
83
										    $encryptedData = $this->make_request($encryptUrl,null);
91
									}else{
84
									}else{
92
										if(empty($notificationUrl)){
85
										if(empty($notificationUrl)){
93
						    				debug('B');
-
 
94
						    				$encryptedData = $this->defaultEncryptedMessage($userId);
86
						    				$encryptedData = $this->defaultEncryptedMessage($userId);
95
							    		}else if(strpos($notificationUrl,'?user_id=') !== false){
87
							    		}else if(strpos($notificationUrl,'?user_id=') !== false){
96
										    $encryptUrl = $encryptUrl.base64_encode($notificationUrl);
88
										    $encryptUrl = $encryptUrl.base64_encode($notificationUrl);
97
										    $encryptedData = $this->make_request($encryptUrl,null);
89
										    $encryptedData = $this->make_request($encryptUrl,null);
98
							    		}else{
90
							    		}else{
Line 112... Line 104...
112
			}
104
			}
113
 
105
 
114
			if($redirectFlag){
106
			if($redirectFlag){
115
				$this->redirect(array('action'=>'error'));
107
				$this->redirect(array('action'=>'error'));
116
			}else{
108
			}else{
117
				//debug($expiryFlag);
-
 
118
				$intentToSend = 'intent://pmapp.com?key='.urlencode($encryptedData['result']['value']).'&campaign='.$campaignId.'&intent_type='.$notificationType.'#Intent;scheme=profitmandiapp;package=com.saholic.profittill;end';							
109
				$intentToSend = 'intent://pm1.in?key='.urlencode($encryptedData['result']['value']).'&campaign='.$campaignId.'&intent_type='.$notificationType.'#Intent;scheme=profitmandiapp;package=com.saholic.profittill;end';							
119
				if($expiryFlag){
110
				if($expiryFlag){
120
					$this->set(compact('intentToSend','expiryFlag'));
111
					$this->set(compact('intentToSend','expiryFlag'));
121
				}else{
112
				}else{
122
					header('Location: '.$intentToSend);
113
					header('Location: '.$intentToSend);
123
					exit;	
114
					exit;	
Line 128... Line 119...
128
			$this->redirect(array('action'=>'mobile'));
119
			$this->redirect(array('action'=>'mobile'));
129
		}
120
		}
130
	}
121
	}
131
 
122
 
132
	function defaultEncryptedMessage($userId){
123
	function defaultEncryptedMessage($userId){
133
		$encryptUrl = 'http://shop2020.in:8057/message/encrypt?type=encrypt&data=';
124
		$encryptUrl = 'http://104.200.25.40:8057/message/encrypt?type=encrypt&data=';
134
		$defaultEncryptedData =array();
125
		$defaultEncryptedData =array();
135
		$defaultUrl = 'http://api.profittill.com/deals';
126
		$defaultUrl = 'http://api.profittill.com/deals';
136
		$notificationUrl = $defaultUrl.'?user_id='.$userId;
127
		$notificationUrl = $defaultUrl.'?user_id='.$userId;
137
	    $encryptUrl = $encryptUrl.base64_encode($notificationUrl);
128
	    $encryptUrl = $encryptUrl.base64_encode($notificationUrl);
138
	    $defaultEncryptedData = $this->make_request($encryptUrl,null);
129
	    $defaultEncryptedData = $this->make_request($encryptUrl,null);
139
	    return $defaultEncryptedData;
130
	    return $defaultEncryptedData;
140
	}
131
	}
141
	function decrypt($encryptData){
132
	function decrypt($encryptData){
142
		$encryptUrl = 'http://shop2020.in:8057/message/encrypt?type=decrypt&data=';
133
		$encryptUrl = 'http://104.200.25.40:8057/message/encrypt?type=decrypt&data=';
143
		$encryptUrl = $encryptUrl.$encryptData;
134
		$encryptUrl = $encryptUrl.$encryptData;
144
		$encryptedData = $this->make_request($encryptUrl,null);
135
		$encryptedData = $this->make_request($encryptUrl,null);
145
		return($encryptedData);
136
		return($encryptedData);
146
	}
137
	}
147
	function num_decode($value){
138
	function num_decode($value){
Line 163... Line 154...
163
    	}
154
    	}
164
    	return $shortenedId;
155
    	return $shortenedId;
165
	}
156
	}
166
 
157
 
167
	function getDatabaseConnection(){
158
	function getDatabaseConnection(){
168
		$servername = "104.200.25.40";
159
		$servername = "localhost";
169
		$username = "root";
160
		$username = "root";
170
		$password = "shop2020";
161
		$password = "shop2020";
171
		$databaseName="dtr";
162
		$databaseName="dtr";
172
		$conn = mysql_connect($servername,$username,$password);
163
		$conn = mysql_connect($servername,$username,$password);
173
		if(!$conn){
164
		if(!$conn){
Line 205... Line 196...
205
	            return true;
196
	            return true;
206
	        }
197
	        }
207
	    }
198
	    }
208
	    return false;
199
	    return false;
209
	}
200
	}
210
}
201
}
211
202