Subversion Repositories SmartDukaan

Rev

Rev 18999 | Rev 19116 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
14954 manas 1
<?php
2
App::uses('AppController', 'Controller');
3
/**
4
 * NotificationCampaigns Controller
5
 *
6
 * @property NotificationCampaign $NotificationCampaign
7
 * @property PaginatorComponent $Paginator
8
 */
9
class NotificationCampaignsController extends AppController {
10
 
11
/**
12
 * Components
13
 *
14
 * @var array
15
 */
16
	public $components = array('Paginator');
17
 
14964 manas 18
	public function beforeFilter() {		
19
		parent::beforeFilter();
20
		$this->Auth->allow('notificationactive');
21
		$this->apihost = Configure::read('pythonapihost');
22
	}
14954 manas 23
 
24
/**
25
 * admin_index method
26
 *
27
 * @return void
28
 */
29
	public function admin_index() {
19084 naman 30
 
31
		$page = $this->request->query('page');
32
		if(!isset($page)){
33
			$page = 1;
34
		}
35
		$limit = 20;
36
		$offset = ($page - 1)*$limit;
37
		$url = Configure::read('nodeurl')."/getLatestNotificationCampaigns/?notification_type=GENERAL_NOTIFICATION&offset=".$offset."&limit=".$limit;
38
// 		echo $url;
39
		$response = $this->make_request($url,null);
40
		$NotificationCampaign = array();
41
		$newNotification = array();
15581 manas 42
		$checkArray=array();
17212 naman 43
		$id_set = '';
19084 naman 44
 
45
			foreach ($response['result'] as $key => $value) {
17212 naman 46
				if($id_set == '')
47
				{
19084 naman 48
					$id_set = $value['_id'];
17212 naman 49
				}
50
				else
51
				{
19084 naman 52
					$id_set = $id_set.','.$value['_id'];
17212 naman 53
				}
19084 naman 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"]);
17212 naman 59
			}
19084 naman 60
		$url = Configure::read('nodeurl')."/getPushNotificationsStats/?campaigns=".$id_set;
61
// 		echo $url;
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){
17212 naman 69
 
19084 naman 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
 
17212 naman 147
		}
19084 naman 148
// 		echo "After Modification";
149
// 		debug($result);
150
 
151
// 		Logic end
152
 
17212 naman 153
		// echo "Idset", $id_set;
154
		// debug($result);
155
		// $campaign_array = array();
156
		// foreach ($vari as $key => $value) {
157
		// 	echo $value['NotificationCampaign']['id'];
158
 
159
		// }
160
		/*
14954 manas 161
		foreach ($vari as $key => $value) {
162
			$cid=$value['NotificationCampaign']['id'];
163
			$sqlQuery = "SELECT status as status,notification_campaign_id,type,count(*) as count FROM pushnotifications group by notification_campaign_id, type,status";
15581 manas 164
			#$successQuery="SELECT count(*) as count from pushnotifications where status=1 and type='sent' and notification_campaign_id=$cid";
165
			$successQuery="SELECT count(distinct p.user_id) as count from pushnotifications p join devices d on p.user_id=d.user_id where status=1 and type='sent' and notification_campaign_id='$cid'  and d.versioncode>=14";
14954 manas 166
			$resul=$this->NotificationCampaign->query($sqlQuery);	
15581 manas 167
			$success_result=$this->NotificationCampaign->query($successQuery);	
168
			array_push($checkArray, $success_result[0][0]['count']);
14954 manas 169
		}
17212 naman 170
		// debug($checkArray);
14954 manas 171
		$finalResult = array();
172
		foreach ($resul as $key => $value) {
173
			$finalResult[$value['pushnotifications']['notification_campaign_id']][$value['pushnotifications']['type']]=$value[0]['count'];
174
			$finalResult[$value['pushnotifications']['notification_campaign_id']][$value['pushnotifications']['status']]=$value[0]['count'];
175
			//$finalResult[$value['pushnotifications']['notification_campaign_id']][$value['pushnotifications']['type']]=$value[0]['status'];			
176
		}
17212 naman 177
		// debug($finalResult);
178
		*/
179
		// $this->set('notificationWithVersionCode', $checkArray);
19084 naman 180
		$this->set('notificationCampaigns', $newNotification);
17212 naman 181
		//$this->set('notificationCampaignsCount', $finalResult);
19084 naman 182
		$this->set(compact('result','page'));
14954 manas 183
	}
184
 
19084 naman 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
 
14954 manas 285
/**
286
 * admin_view method
287
 *
288
 * @throws NotFoundException
289
 * @param string $id
290
 * @return void
291
 */
292
	public function admin_view($id = null) {
19084 naman 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
 
302
// 		if (!$this->NotificationCampaign->exists($id)) {
303
// 			throw new NotFoundException(__('Invalid notification campaign'));
304
// 		}
305
// 		$sort = $this->request->query('type');
306
// 		$direction = $this->request->query('order');
307
// 		$options = array('conditions' => array('NotificationCampaign.' . $this->NotificationCampaign->primaryKey => $id));
308
// 		$userData=$this->NotificationCampaign->find('first', $options);
309
// 		debug($userData);
17212 naman 310
		// $userActions = array();
311
		// foreach ($userData['Pushnotification'] as $key => $value) {
312
		// 	if($value['type']=='sent'){
313
		// 	$userActions[$value['user_id']][$value['type']] = $value['created'];
314
		// 	$userActions[$value['user_id']]['status'] =$value['status'];
315
		// 	}else{
316
		// 		$userActions[$value['user_id']][$value['type']] = $value['response_time'];
317
		// 	}
318
		// 	 //debug($value);
319
		// }
320
 
14954 manas 321
		$userActions = array();
17212 naman 322
		$url = Configure::read('nodeurl')."/getPushNotificationByCampaignId/?notification_campaign_id=".$id;
323
		// echo $url;
324
		$result = $this->make_request($url,null);
325
		foreach ($result as $key => $value) {
14954 manas 326
			if($value['type']=='sent'){
17224 naman 327
				// date_default_timezone_set('GMT');
17222 naman 328
				$epoch = $value['created']/1000;
17212 naman 329
				$dt = date('Y-m-d H:i:s', $epoch);
330
				// echo $dt->format('Y-m-d H:i:s');
331
				$userActions[$value['user_id']][$value['type']] = $dt;//$value['created'];
332
				$userActions[$value['user_id']]['status'] =$value['status'];
17349 manish.sha 333
			}else if(isset($value['response_time'])){
17222 naman 334
				$epoch = $value['response_time']/1000;
17224 naman 335
				// date_default_timezone_set('GMT');
17212 naman 336
				$dt = date('Y-m-d H:i:s', $epoch);
18174 manish.sha 337
				if(isset($value['user_id'])){
338
					$userActions[$value['user_id']][$value['type']] = $dt;//$value['response_time'];
339
				}
17349 manish.sha 340
			}else{
341
				$epoch = $value['created']/1000;
342
				$dt = date('Y-m-d H:i:s', $epoch);
18174 manish.sha 343
				if(isset($value['user_id'])){
344
					$userActions[$value['user_id']][$value['type']] = $dt;//$value['response_time'];
345
				}
14954 manas 346
			}
347
			 //debug($value);
348
		}
17212 naman 349
 
19084 naman 350
// 		$cid=$userData['NotificationCampaign']['id'];
351
// 		$sqlQuery = "SELECT status as status,notification_campaign_id,type,count(*) as count FROM pushnotifications where notification_campaign_id=4120 group by type,status";
352
// 		$resul=$this->NotificationCampaign->query($sqlQuery);	
353
// 		debug($resul);
354
// 		$finalResult = array();	
355
// 		foreach ($resul as $key => $value) {
356
// 			$finalResult[$value['pushnotifications']['notification_campaign_id']][$value['pushnotifications']['type']]=$value[0]['count'];
357
// 			$finalResult[$value['pushnotifications']['notification_campaign_id']][$value['pushnotifications']['status']]=$value[0]['count'];
358
// 			//$finalResult[$value['pushnotifications']['notification_campaign_id']][$value['pushnotifications']['type']]=$value[0]['status'];			
359
// 		}
17212 naman 360
 
19084 naman 361
		$this->set('notificationData', $getdata);
14954 manas 362
		$this->set('notificationCampaign', $userActions);
19084 naman 363
// 		$this->set('notificationCount', $finalResult);
14954 manas 364
	}
365
 
366
/**
367
 * admin_add method
368
 *
369
 * @return void
370
 */
371
	public function admin_add() {
372
		if ($this->request->is('post')) {
373
			$this->NotificationCampaign->create();
374
			if ($this->NotificationCampaign->save($this->request->data)) {
375
				$this->Session->setFlash(__('The notification campaign has been saved.'));
376
				return $this->redirect(array('action' => 'index'));
377
			} else {
378
				$this->Session->setFlash(__('The notification campaign could not be saved. Please, try again.'));
379
			}
380
		}
381
	}
382
 
383
/**
384
 * admin_edit method
385
 *
386
 * @throws NotFoundException
387
 * @param string $id
388
 * @return void
389
 */
390
	public function admin_edit($id = null) {
19084 naman 391
// 		if (!$this->NotificationCampaign->exists($id)) {
392
// 			throw new NotFoundException(__('Invalid notification campaign'));
393
// 		}
14954 manas 394
		if ($this->request->is(array('post', 'put'))) {
19084 naman 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
 
407
// 			if ($this->NotificationCampaign->save($this->request->data)) {
408
			if($debres['message'] == 'Success'){
14954 manas 409
				$this->Session->setFlash(__('The notification campaign has been saved.'));
410
				return $this->redirect(array('action' => 'index'));
411
			} else {
412
				$this->Session->setFlash(__('The notification campaign could not be saved. Please, try again.'));
413
			}
414
		} else {
19084 naman 415
// 			$options = array('conditions' => array('NotificationCampaign.' . $this->NotificationCampaign->primaryKey => $id));
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;
14954 manas 425
		}
426
	}
427
 
428
/**
429
 * admin_delete method
430
 *
431
 * @throws NotFoundException
432
 * @param string $id
433
 * @return void
434
 */
435
	public function admin_delete($id = null) {
436
		$this->NotificationCampaign->id = $id;
437
		if (!$this->NotificationCampaign->exists()) {
438
			throw new NotFoundException(__('Invalid notification campaign'));
439
		}
440
		$this->request->onlyAllow('post', 'delete');
441
		if ($this->NotificationCampaign->delete()) {
442
			$this->Session->setFlash(__('The notification campaign has been deleted.'));
443
		} else {
444
			$this->Session->setFlash(__('The notification campaign could not be deleted. Please, try again.'));
445
		}
446
		return $this->redirect(array('action' => 'index'));
447
	}
17212 naman 448
	// $this->set(compact('result'));
449
	// 
14954 manas 450
	public function admin_show($id = null,$type=null,$status=null) {
17212 naman 451
		// $sqlQuery = "SELECT * FROM pushnotifications where notification_campaign_id=$id and type='$type' and status=$status" ;
14954 manas 452
 
17212 naman 453
		// $resul=$this->NotificationCampaign->query($sqlQuery1ry);
17220 naman 454
		// if($type == 0 || $type == 1)
455
		// {
456
		// 	$type = "sent";
457
		// }
458
		// echo "type", $type;
19084 naman 459
 		$url = Configure::read('nodeurl')."/getPushNotificationDetailsByType/?type=".$type."&notification_campaign_id=".$id."&status=".$status;//remove hardcoded value
460
 
461
 		$result = $this->make_request($url,null);
17220 naman 462
		// debug($result);
19084 naman 463
// 		$sqlQuery1 = "SELECT * FROM notification_campaigns where id=$id" ;
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
 
17212 naman 479
 
480
		$this->set(compact('result'));
481
		// $this->set('data', $result);
19084 naman 482
		$this->set('notificationData', $getdata);
14954 manas 483
	}
484
 
485
	public function admin_user($id = null) {
17225 naman 486
		$url = Configure::read('nodeurl')."/getPushNotificationByUserId/?user_id=".$id;
487
		$userdata = $this->make_request($url,null);
488
		// debug($userdata);
489
		$this->set(compact('userdata'));
490
		// $sqlQuery = "SELECT * FROM pushnotifications where user_id=$id order by id desc" ;
491
		// $resul=$this->NotificationCampaign->query($sqlQuery);
492
		// $this->set('userdata', $resul);
14954 manas 493
	}
15261 anikendra 494
 
14954 manas 495
	public function admin_sort($id = null) {
496
		$sort = $this->request->query('type');
497
		$direction = $this->request->query('order');
498
		//$cid = $this->request->query('cid');
499
		if($sort=='user_id'){
500
			$sqlQuery = "SELECT * FROM pushnotifications where notification_campaign_id =$id order by $sort $direction" ;			
501
		}
502
		else{
503
			$sqlQuery = "SELECT * FROM pushnotifications where notification_campaign_id =$id order by type='$sort' $direction" ;
504
		}
505
		$resul=$this->NotificationCampaign->query($sqlQuery);
506
		$userActions = array();
507
		foreach ($resul as $key => $value) {
508
			if($value['pushnotifications']['type']=='sent'){
509
			$userActions[$value['pushnotifications']['user_id']][$value['pushnotifications']['type']] = $value['pushnotifications']['created'];
510
			$userActions[$value['pushnotifications']['user_id']]['status'] =$value['pushnotifications']['status'];
511
			}else{
512
				$userActions[$value['pushnotifications']['user_id']][$value['pushnotifications']['type']] = $value['pushnotifications']['response_time'];
513
			}			
514
		}
515
		$this->set('notificationId',$id);
516
		$this->set('sortdata', $userActions);
517
	}
518
 
14964 manas 519
	public function notificationactive(){
15669 anikendra 520
		session_write_close();
14964 manas 521
		$cid = $this->request->query('cid');
18174 manish.sha 522
		$cidVals = explode("_", $cid);
523
		$cid = $cidVals[0];
15669 anikendra 524
		$this->log("cid $cid",'notificationactive');
15767 anikendra 525
		$options = array('conditions' => array('id'=> $cid,'status'=>'active','expiresat >'=>date('Y-m-d H:i:s',time())),'recursive'=>-1);
14964 manas 526
		$count = $this->NotificationCampaign->find('count',$options);
15669 anikendra 527
		$this->log("count ".print_r($count,1),'notificationactive');
14964 manas 528
		if(!$count){
529
			$result = array('success'=>false);
530
		}else{
531
			$result = array('success'=>true);
14954 manas 532
		}
14964 manas 533
 
534
		$this->response->type('json');
535
		$this->layout = 'ajax';
536
		$this->set(array(
537
		    'result' => $result,
538
		    '_serialize' => array('result')
539
		));
540
		$this->render('/Elements/json');
541
	}
15261 anikendra 542
 
543
	public function admin_send(){
19084 naman 544
		if ($this->request->is('post')) {
15261 anikendra 545
			$sql = $this->request->data['NotificationCampaign']['sql'];
546
			if(!empty($sql)){
547
				$users = $this->NotificationCampaign->query($sql);
548
				$message = $this->request->data['NotificationCampaign'];
18999 manas 549
				if($message['expiresat']['meridian']=='pm'){
550
					$message['expiresat'] = 1000*mktime(($message['expiresat']['hour'])+12,$message['expiresat']['min'],0,$message['expiresat']['month'],$message['expiresat']['day'],$message['expiresat']['year']);
551
				}else{
552
					$message['expiresat'] = 1000*mktime($message['expiresat']['hour'],$message['expiresat']['min'],0,$message['expiresat']['month'],$message['expiresat']['day'],$message['expiresat']['year']);					
553
				}
554
				$message['status']='active';
555
				$message['smsprocessed']=0;
19084 naman 556
				$message['notification_processed']=0;
18999 manas 557
				$urlPush = Configure::read('nodeurl')."/addNotificationCampaign";
558
				$result = $this->make_request($urlPush,json_encode($message,JSON_NUMERIC_CHECK));
559
				if ($result['msg']=='Success'){
19084 naman 560
// 					$this->loadModel('Pushnotification');
561
// 					$sentUsers = array();
562
// 					$payload = array();
563
// 					foreach ($users as $key => $value) {	
564
// 						if(!in_array($value['User']['id'], $sentUsers)) {
565
// 							$sentUsers[] = $value['User']['id'];								
566
// 							$data = array('notification_campaign_id'=>$message['cid'],'user_id'=>$value['User']['id'],'type'=>'pending','status'=>0);
567
// 							// $this->Pushnotification->create();
568
// 							// $this->Pushnotification->save($data);
569
// 							$payload[] = $data;
570
// 						}
571
// 					}
572
// 					$url = Configure::read('nodeurl')."/addPushNotification";//remove hardcoded value
573
// 					$this->make_request($url,json_encode($payload,JSON_NUMERIC_CHECK));
574
					$this->Session->setFlash(__('Push notification scheduled for users'));
18999 manas 575
					return $this->redirect(array('controller' => 'administration', 'action' => 'dashboard', 'admin' => false));
576
				}else{
577
					$this->Session->setFlash(__('Notification Campaign Insertion Failed. '));
578
					return $this->redirect(array('controller' => 'administration', 'action' => 'dashboard', 'admin' => false));
579
				}									
15261 anikendra 580
			}
581
		}
582
	}
17202 anikendra 583
}