Subversion Repositories SmartDukaan

Rev

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

Rev 18148 Rev 18192
Line 23... Line 23...
23
		$serverHost= $_SERVER['HTTP_HOST'];
23
		$serverHost= $_SERVER['HTTP_HOST'];
24
		$serverURI = $_SERVER['REQUEST_URI'];
24
		$serverURI = $_SERVER['REQUEST_URI'];
25
		$requestURL ="http://".$serverHost.$serverURI;
25
		$requestURL ="http://".$serverHost.$serverURI;
26
		$intentToSend = '';
26
		$intentToSend = '';
27
		$params = explode($serverHost.'/a', $requestURL);
27
		$params = explode($serverHost.'/a', $requestURL);
28
			
-
 
29
		if(empty($params[1])){
-
 
30
			debug('Redirect to the 404 page condition 1');
-
 
31
			echo('Redirect to the 404 page condition 1');
-
 
32
			$redirectFlag=true;
-
 
33
			//Redirect to the 404 page
28
		$ua = $_SERVER['HTTP_USER_AGENT'];
34
		}else{
29
				
35
			$fetchParams = 	 explode('/', $params[1]);
30
		if($this->isMobileDevice($ua)){	
36
			//debug($fetchParams);
31
			if(empty($params[1])){
37
			if(empty($fetchParams[0]) && empty($fetchParams[1])){
-
 
38
				debug('Redirect to the 404 page condition 2');
32
				//debug('Redirect to the 404 page condition 1');
39
				echo('Redirect to the 404 page condition 2');
33
				//echo('Redirect to the 404 page condition 1');
40
				$redirectFlag=true;
34
				$redirectFlag=true;
41
				//Redirect to the 404 page	
-
 
42
			}else{
35
			}else{
43
				if(sizeof($fetchParams) == 2 || empty($fetchParams[2])){
36
				$fetchParams = 	 explode('/', $params[1]);
44
					debug('Redirect to the 404 page condition 3');
-
 
45
					echo('Redirect to the 404 page condition 3');
-
 
46
					$redirectFlag=true;
-
 
47
					//Redirect to the 404 page		
-
 
48
				}else if(sizeof($fetchParams)>4){
37
				if(empty($fetchParams[0]) && empty($fetchParams[1])){
49
					debug('Redirect to the 404 page condition 4');
38
					//debug('Redirect to the 404 page condition 2');
50
					echo('Redirect to the 404 page condition 4');
39
					//echo('Redirect to the 404 page condition 2');
51
					$redirectFlag=true;
40
					$redirectFlag=true;
52
					//Redirect to the 404 page		
-
 
53
				}else{
41
				}else{
54
					$campaignId = $fetchParams[1];
42
					if(sizeof($fetchParams) == 2 || empty($fetchParams[2])){
55
					$userId = $fetchParams[2];;
-
 
56
					
-
 
57
					$campaignId = $this->num_decode($campaignId);
43
						//debug('Redirect to the 404 page condition 3');
58
					$userId = $this->num_decode($userId);
-
 
59
					/*debug($campaignId);
-
 
60
					debug($userId);*/
-
 
61
					$notificationUrl='';
-
 
62
					$encryptedData=array();
-
 
63
					$conn=$this->getDatabaseConnection();
44
						//echo('Redirect to the 404 page condition 3');
64
					if($conn){
-
 
65
						$sql    = 'SELECT * FROM notification_campaigns WHERE id ='.$campaignId;
-
 
66
						$result = mysql_query($sql, $conn);
-
 
67
						if (mysql_num_rows($result)==0) { 
-
 
68
							debug('Zero rows');
-
 
69
							echo('Zero rows');
-
 
70
							$redirectFlag=true;
45
						$redirectFlag=true;
71
						}else{
-
 
72
							while ($row = mysql_fetch_assoc($result)) {
-
 
73
								//debug($row);
-
 
74
					    		$notificationUrl = $row['url'];
-
 
75
					    		$notificationType = $row['type'];
-
 
76
					    		$notificationExpires = $row['expiresat'];
-
 
77
					    		$notificationStatus = $row['status'];
-
 
78
					    		$currentTime = time();
-
 
79
					    		if(!strtotime($notificationExpires)){
46
					}else if(sizeof($fetchParams)>4){
80
					    			$notificationExpires='2038-01-19 03:14:07';
-
 
81
					    		}
-
 
82
					    		//debug($currentTime);
-
 
83
					    		//debug($notificationExpires);
47
						//debug('Redirect to the 404 page condition 4');
84
					    		if(strtotime($notificationExpires) < $currentTime || $notificationStatus=='inactive'){
-
 
85
					    			//debug('Notification has expired');
48
						//echo('Redirect to the 404 page condition 4');
86
					    			$expiryFlag=true;
49
						$redirectFlag=true;
87
					    		}
-
 
88
								if($notificationType=='native'){
-
 
89
									if(strtolower($notificationUrl)=='contact' || strtolower($notificationUrl)=='profile' ||strtolower($notificationUrl)=='tutorial'){
-
 
90
										//debug('V,W,Ir,aH,-y');
-
 
91
										$encryptUrl = $encryptUrl.base64_encode(strtolower($notificationUrl));
-
 
92
									    $encryptedData = $this->make_request($encryptUrl,null);
-
 
93
									}else{
-
 
94
										$encryptedData = $this->defaultEncryptedMessage($userId);
-
 
95
									}
-
 
96
								}else if ($notificationType=='update'){
-
 
97
										//debug('K3');
-
 
98
										$encryptUrl = $encryptUrl.base64_encode('https://play.google.com/store/apps/details?id=com.saholic.profittill');
-
 
99
									    $encryptedData = $this->make_request($encryptUrl,null);
-
 
100
								}else{
-
 
101
						    		//debug($notificationUrl);
-
 
102
									if(empty($notificationUrl)){
-
 
103
					    				debug('B');
-
 
104
					    				$encryptedData = $this->defaultEncryptedMessage($userId);
-
 
105
						    		}else if(strpos($notificationUrl,'?user_id=') !== false){
-
 
106
									    $encryptUrl = $encryptUrl.base64_encode($notificationUrl);
-
 
107
									    $encryptedData = $this->make_request($encryptUrl,null);
-
 
108
						    		}else{
-
 
109
						    			$notificationUrl = $notificationUrl.'?user_id='.$userId;
-
 
110
						    			$encryptUrl = $encryptUrl.base64_encode($notificationUrl);
-
 
111
									    $encryptedData = $this->make_request($encryptUrl,null);
-
 
112
						    		}
-
 
113
						    	}		
-
 
114
					    
-
 
115
							}
-
 
116
					    }
-
 
117
					}else{
50
					}else{
-
 
51
						$campaignId = $fetchParams[1];
-
 
52
						$userId = $fetchParams[2];;
-
 
53
						
-
 
54
						$campaignId = $this->num_decode($campaignId);
-
 
55
						$userId = $this->num_decode($userId);
-
 
56
						$notificationUrl='';
-
 
57
						$encryptedData=array();
-
 
58
						$conn=$this->getDatabaseConnection();
-
 
59
						if($conn){
-
 
60
							$sql    = 'SELECT * FROM notification_campaigns WHERE id ='.$campaignId;
-
 
61
							$result = mysql_query($sql, $conn);
-
 
62
							if (mysql_num_rows($result)==0) { 
-
 
63
								debug('Zero rows');
-
 
64
								echo('Zero rows');
-
 
65
								$redirectFlag=true;
-
 
66
							}else{
-
 
67
								while ($row = mysql_fetch_assoc($result)) {
-
 
68
						    		$notificationUrl = $row['url'];
-
 
69
						    		$notificationType = $row['type'];
-
 
70
						    		$notificationExpires = $row['expiresat'];
-
 
71
						    		$notificationStatus = $row['status'];
-
 
72
						    		$currentTime = time();
-
 
73
						    		if(!strtotime($notificationExpires)){
-
 
74
						    			$notificationExpires='2038-01-19 03:14:07';
-
 
75
						    		}
-
 
76
						    		if(strtotime($notificationExpires) < $currentTime || $notificationStatus=='inactive'){
-
 
77
						    			$expiryFlag=true;
-
 
78
						    		}
-
 
79
									if($notificationType=='native'){
-
 
80
										if(strtolower($notificationUrl)=='contact' || strtolower($notificationUrl)=='profile' ||strtolower($notificationUrl)=='tutorial'){
-
 
81
											//debug('V,W,Ir,aH,-y');
-
 
82
											$encryptUrl = $encryptUrl.base64_encode(strtolower($notificationUrl));
-
 
83
										    $encryptedData = $this->make_request($encryptUrl,null);
-
 
84
										}else{
-
 
85
											$encryptedData = $this->defaultEncryptedMessage($userId);
-
 
86
										}
-
 
87
									}else if ($notificationType=='update'){
-
 
88
											//debug('K3');
-
 
89
											$encryptUrl = $encryptUrl.base64_encode('https://play.google.com/store/apps/details?id=com.saholic.profittill');
-
 
90
										    $encryptedData = $this->make_request($encryptUrl,null);
-
 
91
									}else{
-
 
92
										if(empty($notificationUrl)){
-
 
93
						    				debug('B');
-
 
94
						    				$encryptedData = $this->defaultEncryptedMessage($userId);
-
 
95
							    		}else if(strpos($notificationUrl,'?user_id=') !== false){
-
 
96
										    $encryptUrl = $encryptUrl.base64_encode($notificationUrl);
-
 
97
										    $encryptedData = $this->make_request($encryptUrl,null);
-
 
98
							    		}else{
-
 
99
							    			$notificationUrl = $notificationUrl.'?user_id='.$userId;
-
 
100
							    			$encryptUrl = $encryptUrl.base64_encode($notificationUrl);
-
 
101
										    $encryptedData = $this->make_request($encryptUrl,null);
-
 
102
							    		}
-
 
103
							    	}		
-
 
104
						    
-
 
105
								}
-
 
106
						    }
-
 
107
						}else{
118
						$encryptedData = $this->defaultEncryptedMessage($userId);
108
							$encryptedData = $this->defaultEncryptedMessage($userId);
119
					}		
109
						}		
120
				}	
110
					}	
-
 
111
				}
121
			}
112
			}
122
		}
113
 
123
		if($redirectFlag){
114
			if($redirectFlag){
124
			$this->redirect(array('action'=>'error'));
115
				$this->redirect(array('action'=>'error'));
125
		}else{
-
 
126
			//debug($expiryFlag);
-
 
127
			$intentToSend = 'intent://pmapp.com?key='.urlencode($encryptedData['result']['value']).'&campaign='.$campaignId.'&intent_type='.$notificationType.'#Intent;scheme=profitmandiapp;package=com.saholic.profittill;end';							
-
 
128
			if($expiryFlag){
-
 
129
				$this->set(compact('intentToSend','expiryFlag'));
-
 
130
			}else{
116
			}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';							
-
 
119
				if($expiryFlag){
-
 
120
					$this->set(compact('intentToSend','expiryFlag'));
-
 
121
				}else{
131
				header('Location: '.$intentToSend);
122
					header('Location: '.$intentToSend);
132
				exit;	
123
					exit;	
-
 
124
					}
133
			}
125
				}
-
 
126
		}
-
 
127
		else{
-
 
128
			$this->redirect(array('action'=>'mobile'));
134
		}
129
		}
135
	}
130
	}
136
 
131
 
137
	function defaultEncryptedMessage($userId){
132
	function defaultEncryptedMessage($userId){
138
		$encryptUrl = 'http://shop2020.in:8057/message/encrypt?type=encrypt&data=';
133
		$encryptUrl = 'http://shop2020.in:8057/message/encrypt?type=encrypt&data=';
Line 189... Line 184...
189
	function error(){
184
	function error(){
190
			$this->layout='ajax';
185
			$this->layout='ajax';
191
			$name='Sorry';
186
			$name='Sorry';
192
			$this->set(compact('name'));
187
			$this->set(compact('name'));
193
	}
188
	}
-
 
189
 
-
 
190
	public function mobile() {
-
 
191
		$this->layout='ajax';
-
 
192
	}
-
 
193
	function isMobileDevice($userAgent){
-
 
194
	    $aMobileUA = array(
-
 
195
	        // '/iphone/i' => 'iPhone', 
-
 
196
	        // '/ipod/i' => 'iPod', 
-
 
197
	        // '/ipad/i' => 'iPad', 
-
 
198
	        '/android/i' => 'Android', 
-
 
199
	        // '/blackberry/i' => 'BlackBerry', 
-
 
200
	        // '/webos/i' => 'Mobile'
-
 
201
	    );
-
 
202
 
-
 
203
	    foreach($aMobileUA as $sMobileKey => $sMobileOS){
-
 
204
	        if(preg_match($sMobileKey,$userAgent)){
-
 
205
	            return true;
-
 
206
	        }
-
 
207
	    }
-
 
208
	    return false;
-
 
209
	}
194
}
210
}