Subversion Repositories SmartDukaan

Rev

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

Rev 18999 Rev 19084
Line 25... Line 25...
25
 * admin_index method
25
 * admin_index method
26
 *
26
 *
27
 * @return void
27
 * @return void
28
 */
28
 */
29
	public function admin_index() {
29
	public function admin_index() {
-
 
30
		
30
		$this->NotificationCampaign->recursive = 0;
31
		$page = $this->request->query('page');
-
 
32
		if(!isset($page)){
-
 
33
			$page = 1;
-
 
34
		}
-
 
35
		$limit = 20;
-
 
36
		$offset = ($page - 1)*$limit;
31
		// $this->Paginator->settings = array('order' => array('id'=>'desc'),'fields'=>('NotificationCampaign.id'));
37
		$url = Configure::read('nodeurl')."/getLatestNotificationCampaigns/?notification_type=GENERAL_NOTIFICATION&offset=".$offset."&limit=".$limit;
-
 
38
// 		echo $url;
32
		$this->Paginator->settings = array('order' => array('id'=>'desc'));
39
		$response = $this->make_request($url,null);
33
		$vari = $this->Paginator->paginate();
40
		$NotificationCampaign = array();
34
		// debug($vari);
41
		$newNotification = array();
35
		$checkArray=array();
42
		$checkArray=array();
36
		$id_set = '';
43
		$id_set = '';
37
		foreach ($vari as $key => $row) {
-
 
-
 
44
 
38
			foreach ($row as $key => $value) {
45
			foreach ($response['result'] as $key => $value) {
39
				if($id_set == '')
46
				if($id_set == '')
40
				{
47
				{
41
					$id_set = $value['id'];
48
					$id_set = $value['_id'];
42
				}
49
				}
43
				else
50
				else
44
				{
51
				{
45
					$id_set = $id_set.','.$value['id'];
52
					$id_set = $id_set.','.$value['_id'];
46
				}
53
				}
-
 
54
				$newNotification[$key]["NotificationCampaign"] = $value;
-
 
55
				$newNotification[$key]["NotificationCampaign"]["id"] = $value["_id"];
-
 
56
				$newNotification[$key]["NotificationCampaign"]["expiresat"] = date('Y-m-d H:i:s', $value["expiresat"]/1000);
-
 
57
				$newNotification[$key]["NotificationCampaign"]["created"] = date('Y-m-d H:i:s', $value["created"]/1000);
-
 
58
// 				unset($value["_id"]);
47
			}
59
			}
48
			
-
 
49
		}
-
 
50
 
-
 
51
		$url = Configure::read('nodeurl')."/getPushNotificationsStats/?campaigns=".$id_set;
60
		$url = Configure::read('nodeurl')."/getPushNotificationsStats/?campaigns=".$id_set;
52
		// echo $url;
61
// 		echo $url;
53
		$result = $this->make_request($url,null);
62
		$result = $this->make_request($url,null);
-
 
63
// 		echo "Before Modification";
-
 
64
// 		debug($result);
-
 
65
		
-
 
66
// 		Logic for new result start
-
 
67
		
-
 
68
		foreach ($result as $notkey =>$notval){
-
 
69
			
-
 
70
				$total = 0;
-
 
71
				$total_open = 0;
-
 
72
				$total_rec = 0;
-
 
73
				$success = 0;
-
 
74
				if(isset($notval["recieved"]))
-
 
75
				{
-
 
76
					$total = $notval["recieved"] + $total;
-
 
77
					$total_rec = $notval["recieved"];
-
 
78
				}
-
 
79
					
-
 
80
				if(isset($notval["expired"]))
-
 
81
				{
-
 
82
					$total = $notval["expired"] + $total;
-
 
83
				}
-
 
84
					
-
 
85
				if(isset($notval["opened"]))
-
 
86
				{
-
 
87
					$total = $notval["opened"] + $total;
-
 
88
					$total_rec = $total_rec + $notval["opened"];
-
 
89
					$total_open = $notval["opened"];
-
 
90
				}
-
 
91
				
-
 
92
				if(isset($notval["failed"]))
-
 
93
				{
-
 
94
					$total = $notval["failed"] + $total;
-
 
95
				}
-
 
96
				
-
 
97
				if(isset($notval["sent"]))
-
 
98
				{
-
 
99
					$total = $notval["sent"] + $total;
-
 
100
				}
-
 
101
				
-
 
102
				$success = $total;
-
 
103
				
-
 
104
				if(isset($notval["failed"]))
-
 
105
				{
-
 
106
					$success = $total - $notval["failed"] ;
-
 
107
				}
-
 
108
				
-
 
109
				if(isset($notval["referrer"]))
-
 
110
				{
-
 
111
					$total_open = $notval["referrer"] + $total_open;
-
 
112
				}
-
 
113
				
-
 
114
				if(isset($notval["login"]))
-
 
115
				{
-
 
116
					$total_open = $notval["login"] + $total_open;
-
 
117
				}
-
 
118
				
-
 
119
				$result[$notkey]["opened"] = $total_open;
-
 
120
				$result[$notkey]["recieved"] = $total_rec;
-
 
121
				$result[$notkey]["total"] = $total;
-
 
122
				$result[$notkey]["success"] = $success;
-
 
123
				
-
 
124
			
-
 
125
// 			if(isset($notval["recieved"])&& isset($notval["opened"])){
-
 
126
// 				$result[$notkey]["recieved"] = $notval["opened"] + $notval["recieved"];
-
 
127
 
-
 
128
// 			}
-
 
129
			
-
 
130
// 			if(isset($notval["opened"]))
-
 
131
// 			{
-
 
132
// 				$total_open = $notval["opened"];
-
 
133
// 				if(isset($notval["referrer"]))
-
 
134
// 				{
-
 
135
// 					$total_open = $notval["referrer"] + $total_open;
-
 
136
// 				}
-
 
137
				
-
 
138
// 				if(isset($notval["login"]))
-
 
139
// 				{
-
 
140
// 					$total_open = $notval["login"] + $total_open;
-
 
141
// 				}
-
 
142
// 				$result[$notkey]["opened"] = $total_open;
-
 
143
// 			}
-
 
144
			
-
 
145
// 			$result[$notkey]["opened"] = $notval["login"] + $notval["expired"] + $notval["opened"] +$notval['recieved'];
-
 
146
			
-
 
147
		}
-
 
148
// 		echo "After Modification";
-
 
149
// 		debug($result);
-
 
150
			
-
 
151
// 		Logic end
-
 
152
		
54
		// echo "Idset", $id_set;
153
		// echo "Idset", $id_set;
55
		// debug($result);
154
		// debug($result);
56
		// $campaign_array = array();
155
		// $campaign_array = array();
57
		// foreach ($vari as $key => $value) {
156
		// foreach ($vari as $key => $value) {
58
		// 	echo $value['NotificationCampaign']['id'];
157
		// 	echo $value['NotificationCampaign']['id'];
Line 76... Line 175...
76
			//$finalResult[$value['pushnotifications']['notification_campaign_id']][$value['pushnotifications']['type']]=$value[0]['status'];			
175
			//$finalResult[$value['pushnotifications']['notification_campaign_id']][$value['pushnotifications']['type']]=$value[0]['status'];			
77
		}
176
		}
78
		// debug($finalResult);
177
		// debug($finalResult);
79
		*/
178
		*/
80
		// $this->set('notificationWithVersionCode', $checkArray);
179
		// $this->set('notificationWithVersionCode', $checkArray);
81
		$this->set('notificationCampaigns', $vari);
180
		$this->set('notificationCampaigns', $newNotification);
82
		//$this->set('notificationCampaignsCount', $finalResult);
181
		//$this->set('notificationCampaignsCount', $finalResult);
83
		$this->set(compact('result'));
182
		$this->set(compact('result','page'));
84
	}
183
	}
85
 
184
 
-
 
185
	public function admin_batchcredit() {
-
 
186
 
-
 
187
		$page = $this->request->query('page');
-
 
188
		if(!isset($page)){
-
 
189
			$page = 1;
-
 
190
		}
-
 
191
		$limit = 20;
-
 
192
		$offset = ($page - 1)*$limit;
-
 
193
		$url = Configure::read('nodeurl')."/getLatestNotificationCampaigns/?notification_type=BATCH_CREDIT&offset=".$offset."&limit=".$limit;
-
 
194
		$response = $this->make_request($url,null);
-
 
195
		$NotificationCampaign = array();
-
 
196
		$newNotification = array();
-
 
197
		$checkArray=array();
-
 
198
		$id_set = '';
-
 
199
	
-
 
200
				foreach ($response['result'] as $key => $value) {
-
 
201
					if($id_set == '')
-
 
202
					{
-
 
203
						$id_set = $value['_id'];
-
 
204
					}
-
 
205
					else
-
 
206
					{
-
 
207
						$id_set = $id_set.','.$value['_id'];
-
 
208
					}
-
 
209
					$newNotification[$key]["NotificationCampaign"] = $value;
-
 
210
					$newNotification[$key]["NotificationCampaign"]["id"] = $value["_id"];
-
 
211
					$newNotification[$key]["NotificationCampaign"]["expiresat"] = date('Y-m-d H:i:s', $value["expiresat"]/1000);
-
 
212
					$newNotification[$key]["NotificationCampaign"]["created"] = date('Y-m-d H:i:s', $value["created"]/1000);
-
 
213
				}
-
 
214
			
-
 
215
				$url = Configure::read('nodeurl')."/getPushNotificationsStats/?campaigns=".$id_set;
-
 
216
				$result = $this->make_request($url,null);
-
 
217
		
-
 
218
				// 		Logic for new result start
-
 
219
		
-
 
220
				foreach ($result as $notkey =>$notval){
-
 
221
						
-
 
222
					$total = 0;
-
 
223
					$total_open = 0;
-
 
224
					$total_rec = 0;
-
 
225
					$success = 0;
-
 
226
					if(isset($notval["recieved"]))
-
 
227
					{
-
 
228
						$total = $notval["recieved"] + $total;
-
 
229
						$total_rec = $notval["recieved"];
-
 
230
					}
-
 
231
						
-
 
232
					if(isset($notval["expired"]))
-
 
233
					{
-
 
234
						$total = $notval["expired"] + $total;
-
 
235
					}
-
 
236
						
-
 
237
					if(isset($notval["opened"]))
-
 
238
					{
-
 
239
						$total = $notval["opened"] + $total;
-
 
240
						$total_rec = $total_rec + $notval["opened"];
-
 
241
						$total_open = $notval["opened"];
-
 
242
					}
-
 
243
		
-
 
244
					if(isset($notval["failed"]))
-
 
245
					{
-
 
246
						$total = $notval["failed"] + $total;
-
 
247
					}
-
 
248
		
-
 
249
					if(isset($notval["sent"]))
-
 
250
					{
-
 
251
						$total = $notval["sent"] + $total;
-
 
252
					}
-
 
253
		
-
 
254
					$success = $total;
-
 
255
		
-
 
256
					if(isset($notval["failed"]))
-
 
257
					{
-
 
258
						$success = $total - $notval["failed"] ;
-
 
259
					}
-
 
260
		
-
 
261
					if(isset($notval["referrer"]))
-
 
262
					{
-
 
263
						$total_open = $notval["referrer"] + $total_open;
-
 
264
					}
-
 
265
		
-
 
266
					if(isset($notval["login"]))
-
 
267
					{
-
 
268
						$total_open = $notval["login"] + $total_open;
-
 
269
					}
-
 
270
		
-
 
271
					$result[$notkey]["opened"] = $total_open;
-
 
272
					$result[$notkey]["recieved"] = $total_rec;
-
 
273
					$result[$notkey]["total"] = $total;
-
 
274
					$result[$notkey]["success"] = $success;					
-
 
275
				}					
-
 
276
				// 		Logic end
-
 
277
		
-
 
278
				$this->set('notificationCampaigns', $newNotification);
-
 
279
				//$this->set('notificationCampaignsCount', $finalResult);
-
 
280
				$this->set(compact('result','page'));
-
 
281
		}
-
 
282
	
-
 
283
	
-
 
284
	
86
/**
285
/**
87
 * admin_view method
286
 * admin_view method
88
 *
287
 *
89
 * @throws NotFoundException
288
 * @throws NotFoundException
90
 * @param string $id
289
 * @param string $id
91
 * @return void
290
 * @return void
92
 */
291
 */
93
	public function admin_view($id = null) {
292
	public function admin_view($id = null) {
-
 
293
		$url = Configure::read('nodeurl')."/getNotificationCampaignById?id=".$id;
-
 
294
		$result = $this->make_request($url,null);
-
 
295
		$getdata = array();
-
 
296
		$getdata["NotificationCampaign"] = $result;
-
 
297
		$getdata["NotificationCampaign"]["expiresat"] = date('Y-m-d H:i:s', $result["expiresat"]/1000);
-
 
298
		$getdata["NotificationCampaign"]["id"] =  $result["_id"];
-
 
299
		unset($getdata["NotificationCampaign"]["_id"]);
-
 
300
//		debug($getdata);
-
 
301
		
94
		if (!$this->NotificationCampaign->exists($id)) {
302
// 		if (!$this->NotificationCampaign->exists($id)) {
95
			throw new NotFoundException(__('Invalid notification campaign'));
303
// 			throw new NotFoundException(__('Invalid notification campaign'));
96
		}
304
// 		}
97
		$sort = $this->request->query('type');
305
// 		$sort = $this->request->query('type');
98
		$direction = $this->request->query('order');
306
// 		$direction = $this->request->query('order');
99
		$options = array('conditions' => array('NotificationCampaign.' . $this->NotificationCampaign->primaryKey => $id));
307
// 		$options = array('conditions' => array('NotificationCampaign.' . $this->NotificationCampaign->primaryKey => $id));
100
		$userData=$this->NotificationCampaign->find('first', $options);
308
// 		$userData=$this->NotificationCampaign->find('first', $options);
-
 
309
// 		debug($userData);
101
		// $userActions = array();
310
		// $userActions = array();
102
		// foreach ($userData['Pushnotification'] as $key => $value) {
311
		// foreach ($userData['Pushnotification'] as $key => $value) {
103
		// 	if($value['type']=='sent'){
312
		// 	if($value['type']=='sent'){
104
		// 	$userActions[$value['user_id']][$value['type']] = $value['created'];
313
		// 	$userActions[$value['user_id']][$value['type']] = $value['created'];
105
		// 	$userActions[$value['user_id']]['status'] =$value['status'];
314
		// 	$userActions[$value['user_id']]['status'] =$value['status'];
Line 128... Line 337...
128
				if(isset($value['user_id'])){
337
				if(isset($value['user_id'])){
129
					$userActions[$value['user_id']][$value['type']] = $dt;//$value['response_time'];
338
					$userActions[$value['user_id']][$value['type']] = $dt;//$value['response_time'];
130
				}
339
				}
131
			}else{
340
			}else{
132
				$epoch = $value['created']/1000;
341
				$epoch = $value['created']/1000;
133
				// date_default_timezone_set('GMT');
-
 
134
				$dt = date('Y-m-d H:i:s', $epoch);
342
				$dt = date('Y-m-d H:i:s', $epoch);
135
				if(isset($value['user_id'])){
343
				if(isset($value['user_id'])){
136
					$userActions[$value['user_id']][$value['type']] = $dt;//$value['response_time'];
344
					$userActions[$value['user_id']][$value['type']] = $dt;//$value['response_time'];
137
				}
345
				}
138
			}
346
			}
139
			 //debug($value);
347
			 //debug($value);
140
		}
348
		}
141
		// debug($userData);
-
 
142
		// debug($result);
-
 
143
		// debug($userActions);
-
 
144
		// debug($userAct);
-
 
145
		
-
 
146
		// $this->set(compact('result'));
-
 
147
 
349
 
148
		$cid=$userData['NotificationCampaign']['id'];
350
// 		$cid=$userData['NotificationCampaign']['id'];
149
		$sqlQuery = "SELECT status as status,notification_campaign_id,type,count(*) as count FROM pushnotifications where notification_campaign_id=$cid group by type,status";
351
// 		$sqlQuery = "SELECT status as status,notification_campaign_id,type,count(*) as count FROM pushnotifications where notification_campaign_id=4120 group by type,status";
150
		$resul=$this->NotificationCampaign->query($sqlQuery);	
352
// 		$resul=$this->NotificationCampaign->query($sqlQuery);	
-
 
353
// 		debug($resul);
151
		$finalResult = array();	
354
// 		$finalResult = array();	
152
		foreach ($resul as $key => $value) {
355
// 		foreach ($resul as $key => $value) {
153
			$finalResult[$value['pushnotifications']['notification_campaign_id']][$value['pushnotifications']['type']]=$value[0]['count'];
356
// 			$finalResult[$value['pushnotifications']['notification_campaign_id']][$value['pushnotifications']['type']]=$value[0]['count'];
154
			$finalResult[$value['pushnotifications']['notification_campaign_id']][$value['pushnotifications']['status']]=$value[0]['count'];
357
// 			$finalResult[$value['pushnotifications']['notification_campaign_id']][$value['pushnotifications']['status']]=$value[0]['count'];
155
			//$finalResult[$value['pushnotifications']['notification_campaign_id']][$value['pushnotifications']['type']]=$value[0]['status'];			
358
// 			//$finalResult[$value['pushnotifications']['notification_campaign_id']][$value['pushnotifications']['type']]=$value[0]['status'];			
156
		}
359
// 		}
157
		
360
		
158
		$this->set('notificationData', $userData);
361
		$this->set('notificationData', $getdata);
159
		$this->set('notificationCampaign', $userActions);
362
		$this->set('notificationCampaign', $userActions);
160
		$this->set('notificationCount', $finalResult);
363
// 		$this->set('notificationCount', $finalResult);
161
	}
364
	}
162
 
365
 
163
/**
366
/**
164
 * admin_add method
367
 * admin_add method
165
 *
368
 *
Line 183... Line 386...
183
 * @throws NotFoundException
386
 * @throws NotFoundException
184
 * @param string $id
387
 * @param string $id
185
 * @return void
388
 * @return void
186
 */
389
 */
187
	public function admin_edit($id = null) {
390
	public function admin_edit($id = null) {
188
		if (!$this->NotificationCampaign->exists($id)) {
391
// 		if (!$this->NotificationCampaign->exists($id)) {
189
			throw new NotFoundException(__('Invalid notification campaign'));
392
// 			throw new NotFoundException(__('Invalid notification campaign'));
190
		}
393
// 		}
191
		if ($this->request->is(array('post', 'put'))) {
394
		if ($this->request->is(array('post', 'put'))) {
-
 
395
			$message= $this->request->data['NotificationCampaign'];
-
 
396
			if($message['expiresat']['meridian']=='pm'){
-
 
397
				$message['expiresat'] = 1000*mktime(($message['expiresat']['hour'])+12,$message['expiresat']['min'],0,$message['expiresat']['month'],$message['expiresat']['day'],$message['expiresat']['year']);
-
 
398
			}else{
-
 
399
				$message['expiresat'] = 1000*mktime($message['expiresat']['hour'],$message['expiresat']['min'],0,$message['expiresat']['month'],$message['expiresat']['day'],$message['expiresat']['year']);
-
 
400
			}
-
 
401
// 			$senddata = '{"id":"56d80b7514fb6c4a5183a74a","name":"Naman","title":"Naman","message":"Naman","type":"url","url":"http:\/\/api.profittill.com","expiresat":1344988800000,"status":"active","sendsms":0,"messagetext":"","smsprocessed":0}';
-
 
402
//			debug($message);
-
 
403
			$url = Configure::read('nodeurl')."/updatedNotificationCampaign";//remove hardcoded value
-
 
404
			$debres = $this->make_request($url,json_encode($message,JSON_NUMERIC_CHECK));
-
 
405
// 			debug($debres);
-
 
406
			
192
			if ($this->NotificationCampaign->save($this->request->data)) {
407
// 			if ($this->NotificationCampaign->save($this->request->data)) {
-
 
408
			if($debres['message'] == 'Success'){
193
				$this->Session->setFlash(__('The notification campaign has been saved.'));
409
				$this->Session->setFlash(__('The notification campaign has been saved.'));
194
				return $this->redirect(array('action' => 'index'));
410
				return $this->redirect(array('action' => 'index'));
195
			} else {
411
			} else {
196
				$this->Session->setFlash(__('The notification campaign could not be saved. Please, try again.'));
412
				$this->Session->setFlash(__('The notification campaign could not be saved. Please, try again.'));
197
			}
413
			}
198
		} else {
414
		} else {
199
			$options = array('conditions' => array('NotificationCampaign.' . $this->NotificationCampaign->primaryKey => $id));
415
// 			$options = array('conditions' => array('NotificationCampaign.' . $this->NotificationCampaign->primaryKey => $id));
200
			$this->request->data = $this->NotificationCampaign->find('first', $options);
416
// 			$this->request->data = $this->NotificationCampaign->find('first', $options);
-
 
417
			$url = Configure::read('nodeurl')."/getNotificationCampaignById?id=".$id;
-
 
418
			$result = $this->make_request($url,null);			
-
 
419
			$getdata = array();
-
 
420
			$getdata["NotificationCampaign"] = $result;
-
 
421
			$getdata["NotificationCampaign"]["expiresat"] = date('Y-m-d H:i:s', $result["expiresat"]/1000);
-
 
422
			$getdata["NotificationCampaign"]["id"] =  $result["_id"];
-
 
423
			unset($getdata["NotificationCampaign"]["_id"]);
-
 
424
			$this->request->data = $getdata;
201
		}
425
		}
202
	}
426
	}
203
 
427
 
204
/**
428
/**
205
 * admin_delete method
429
 * admin_delete method
Line 230... Line 454...
230
		// if($type == 0 || $type == 1)
454
		// if($type == 0 || $type == 1)
231
		// {
455
		// {
232
		// 	$type = "sent";
456
		// 	$type = "sent";
233
		// }
457
		// }
234
		// echo "type", $type;
458
		// echo "type", $type;
235
		$url = Configure::read('nodeurl')."/getPushNotificationDetailsByType/?type=".$type."&notification_campaign_id=".$id."&status=".$status;//remove hardcoded value
459
 		$url = Configure::read('nodeurl')."/getPushNotificationDetailsByType/?type=".$type."&notification_campaign_id=".$id."&status=".$status;//remove hardcoded value
236
		// echo $url;
460
		
237
		$result = $this->make_request($url,null);
461
 		$result = $this->make_request($url,null);
238
		// debug($result);
462
		// debug($result);
239
		$sqlQuery1 = "SELECT * FROM notification_campaigns where id=$id" ;
463
// 		$sqlQuery1 = "SELECT * FROM notification_campaigns where id=$id" ;
240
		$resultData=$this->NotificationCampaign->query($sqlQuery1);
464
// 		$resultData=$this->NotificationCampaign->query($sqlQuery1);
-
 
465
// 		debug($resultData);
-
 
466
		$url = Configure::read('nodeurl')."/getNotificationCampaignById?id=".$id;
-
 
467
		$res = $this->make_request($url,null);
-
 
468
		debug($res);
-
 
469
		$getdata = array();
-
 
470
		if(!empty($res)){
-
 
471
			$getdata["NotificationCampaign"] = $res;
-
 
472
			$getdata["NotificationCampaign"]["expiresat"] = date('Y-m-d H:i:s', $res["expiresat"]/1000);
-
 
473
			$getdata["NotificationCampaign"]["id"] =  $res["_id"];
-
 
474
			unset($getdata["NotificationCampaign"]["_id"]);
-
 
475
		}
-
 
476
		
-
 
477
		
-
 
478
		
241
 
479
 
242
		$this->set(compact('result'));
480
		$this->set(compact('result'));
243
		// $this->set('data', $result);
481
		// $this->set('data', $result);
244
		$this->set('notificationData', $resultData);
482
		$this->set('notificationData', $getdata);
245
	}
483
	}
246
 
484
 
247
	public function admin_user($id = null) {
485
	public function admin_user($id = null) {
248
		$url = Configure::read('nodeurl')."/getPushNotificationByUserId/?user_id=".$id;
486
		$url = Configure::read('nodeurl')."/getPushNotificationByUserId/?user_id=".$id;
249
		$userdata = $this->make_request($url,null);
487
		$userdata = $this->make_request($url,null);
Line 301... Line 539...
301
		));
539
		));
302
		$this->render('/Elements/json');
540
		$this->render('/Elements/json');
303
	}
541
	}
304
 
542
 
305
	public function admin_send(){
543
	public function admin_send(){
306
		if ($this->request->is('post')) {			
544
		if ($this->request->is('post')) {
307
			$sql = $this->request->data['NotificationCampaign']['sql'];
545
			$sql = $this->request->data['NotificationCampaign']['sql'];
308
			if(!empty($sql)){
546
			if(!empty($sql)){
309
				$users = $this->NotificationCampaign->query($sql);
547
				$users = $this->NotificationCampaign->query($sql);
310
				$message = $this->request->data['NotificationCampaign'];
548
				$message = $this->request->data['NotificationCampaign'];
311
				if($message['expiresat']['meridian']=='pm'){
549
				if($message['expiresat']['meridian']=='pm'){
Line 313... Line 551...
313
				}else{
551
				}else{
314
					$message['expiresat'] = 1000*mktime($message['expiresat']['hour'],$message['expiresat']['min'],0,$message['expiresat']['month'],$message['expiresat']['day'],$message['expiresat']['year']);					
552
					$message['expiresat'] = 1000*mktime($message['expiresat']['hour'],$message['expiresat']['min'],0,$message['expiresat']['month'],$message['expiresat']['day'],$message['expiresat']['year']);					
315
				}
553
				}
316
				$message['status']='active';
554
				$message['status']='active';
317
				$message['smsprocessed']=0;
555
				$message['smsprocessed']=0;
-
 
556
				$message['notification_processed']=0;
318
				$urlPush = Configure::read('nodeurl')."/addNotificationCampaign";
557
				$urlPush = Configure::read('nodeurl')."/addNotificationCampaign";
319
				$result = $this->make_request($urlPush,json_encode($message,JSON_NUMERIC_CHECK));
558
				$result = $this->make_request($urlPush,json_encode($message,JSON_NUMERIC_CHECK));
320
				if ($result['msg']=='Success'){
559
				if ($result['msg']=='Success'){
321
					$this->loadModel('Pushnotification');
560
// 					$this->loadModel('Pushnotification');
322
					$sentUsers = array();
561
// 					$sentUsers = array();
323
					$payload = array();
562
// 					$payload = array();
324
					foreach ($users as $key => $value) {	
563
// 					foreach ($users as $key => $value) {	
325
						if(!in_array($value['User']['id'], $sentUsers)) {
564
// 						if(!in_array($value['User']['id'], $sentUsers)) {
326
							$sentUsers[] = $value['User']['id'];								
565
// 							$sentUsers[] = $value['User']['id'];								
327
							$data = array('notification_campaign_id'=>$message['cid'],'user_id'=>$value['User']['id'],'type'=>'pending','status'=>0);
566
// 							$data = array('notification_campaign_id'=>$message['cid'],'user_id'=>$value['User']['id'],'type'=>'pending','status'=>0);
328
							// $this->Pushnotification->create();
567
// 							// $this->Pushnotification->create();
329
							// $this->Pushnotification->save($data);
568
// 							// $this->Pushnotification->save($data);
330
							$payload[] = $data;
569
// 							$payload[] = $data;
331
						}
570
// 						}
332
					}
571
// 					}
333
					$url = Configure::read('nodeurl')."/addPushNotification";//remove hardcoded value
572
// 					$url = Configure::read('nodeurl')."/addPushNotification";//remove hardcoded value
334
					$this->make_request($url,json_encode($payload,JSON_NUMERIC_CHECK));
573
// 					$this->make_request($url,json_encode($payload,JSON_NUMERIC_CHECK));
335
					$this->Session->setFlash(__('Push notification scheduled for '.sizeof($users).' users'));
574
					$this->Session->setFlash(__('Push notification scheduled for users'));
336
					return $this->redirect(array('controller' => 'administration', 'action' => 'dashboard', 'admin' => false));
575
					return $this->redirect(array('controller' => 'administration', 'action' => 'dashboard', 'admin' => false));
337
				}else{
576
				}else{
338
					$this->Session->setFlash(__('Notification Campaign Insertion Failed. '));
577
					$this->Session->setFlash(__('Notification Campaign Insertion Failed. '));
339
					return $this->redirect(array('controller' => 'administration', 'action' => 'dashboard', 'admin' => false));
578
					return $this->redirect(array('controller' => 'administration', 'action' => 'dashboard', 'admin' => false));
340
				}									
579
				}