| Line 305... |
Line 305... |
| 305 |
public function admin_send(){
|
305 |
public function admin_send(){
|
| 306 |
if ($this->request->is('post')) {
|
306 |
if ($this->request->is('post')) {
|
| 307 |
$sql = $this->request->data['NotificationCampaign']['sql'];
|
307 |
$sql = $this->request->data['NotificationCampaign']['sql'];
|
| 308 |
if(!empty($sql)){
|
308 |
if(!empty($sql)){
|
| 309 |
$users = $this->NotificationCampaign->query($sql);
|
309 |
$users = $this->NotificationCampaign->query($sql);
|
| 310 |
// debug($users);
|
- |
|
| 311 |
$message = $this->request->data['NotificationCampaign'];
|
310 |
$message = $this->request->data['NotificationCampaign'];
|
| 312 |
// $data = array('name'=>$message['name'],'title'=>$message['title'],'type'=>$message['type'],'message'=>$message['message'],'url'=>$message['url'],'expiresat'=>$message['expiresat'],'sql'=>$message['sql']);
|
- |
|
| 313 |
$this->NotificationCampaign->create();
|
- |
|
| 314 |
if($this->NotificationCampaign->save($message)){
|
311 |
if($message['expiresat']['meridian']=='pm'){
|
| 315 |
$message['cid'] = $this->NotificationCampaign->getLastInsertId();
|
312 |
$message['expiresat'] = 1000*mktime(($message['expiresat']['hour'])+12,$message['expiresat']['min'],0,$message['expiresat']['month'],$message['expiresat']['day'],$message['expiresat']['year']);
|
| 316 |
} else{
|
313 |
}else{
|
| 317 |
debug($this->NotificationCampaign->validationErrors);
|
- |
|
| 318 |
$message['cid'] = $message['name'];
|
- |
|
| 319 |
}
|
- |
|
| 320 |
$this->loadModel('Pushnotification');
|
- |
|
| 321 |
$sentUsers = array();
|
- |
|
| 322 |
$payload = array();
|
- |
|
| 323 |
foreach ($users as $key => $value) {
|
- |
|
| 324 |
if(!in_array($value['User']['id'], $sentUsers)) {
|
- |
|
| 325 |
$sentUsers[] = $value['User']['id'];
|
- |
|
| 326 |
$data = array('notification_campaign_id'=>$message['cid'],'user_id'=>$value['User']['id'],'type'=>'pending','status'=>0);
|
314 |
$message['expiresat'] = 1000*mktime($message['expiresat']['hour'],$message['expiresat']['min'],0,$message['expiresat']['month'],$message['expiresat']['day'],$message['expiresat']['year']);
|
| 327 |
// $this->Pushnotification->create();
|
- |
|
| 328 |
// $this->Pushnotification->save($data);
|
- |
|
| 329 |
$payload[] = $data;
|
- |
|
| 330 |
}
|
- |
|
| 331 |
}
|
315 |
}
|
| - |
|
316 |
$message['status']='active';
|
| - |
|
317 |
$message['smsprocessed']=0;
|
| - |
|
318 |
$urlPush = Configure::read('nodeurl')."/addNotificationCampaign";
|
| - |
|
319 |
$result = $this->make_request($urlPush,json_encode($message,JSON_NUMERIC_CHECK));
|
| - |
|
320 |
if ($result['msg']=='Success'){
|
| - |
|
321 |
$this->loadModel('Pushnotification');
|
| - |
|
322 |
$sentUsers = array();
|
| - |
|
323 |
$payload = array();
|
| - |
|
324 |
foreach ($users as $key => $value) {
|
| - |
|
325 |
if(!in_array($value['User']['id'], $sentUsers)) {
|
| - |
|
326 |
$sentUsers[] = $value['User']['id'];
|
| - |
|
327 |
$data = array('notification_campaign_id'=>$message['cid'],'user_id'=>$value['User']['id'],'type'=>'pending','status'=>0);
|
| - |
|
328 |
// $this->Pushnotification->create();
|
| - |
|
329 |
// $this->Pushnotification->save($data);
|
| - |
|
330 |
$payload[] = $data;
|
| - |
|
331 |
}
|
| - |
|
332 |
}
|
| 332 |
$url = Configure::read('nodeurl')."/addPushNotification";//remove hardcoded value
|
333 |
$url = Configure::read('nodeurl')."/addPushNotification";//remove hardcoded value
|
| 333 |
$this->make_request($url,json_encode($payload,JSON_NUMERIC_CHECK));
|
334 |
$this->make_request($url,json_encode($payload,JSON_NUMERIC_CHECK));
|
| 334 |
$this->Session->setFlash(__('Push notification scheduled for '.sizeof($users).' users'));
|
335 |
$this->Session->setFlash(__('Push notification scheduled for '.sizeof($users).' users'));
|
| - |
|
336 |
return $this->redirect(array('controller' => 'administration', 'action' => 'dashboard', 'admin' => false));
|
| - |
|
337 |
}else{
|
| - |
|
338 |
$this->Session->setFlash(__('Notification Campaign Insertion Failed. '));
|
| 335 |
return $this->redirect(array('controller' => 'administration', 'action' => 'dashboard', 'admin' => false));
|
339 |
return $this->redirect(array('controller' => 'administration', 'action' => 'dashboard', 'admin' => false));
|
| - |
|
340 |
}
|
| 336 |
}
|
341 |
}
|
| 337 |
}
|
342 |
}
|
| 338 |
}
|
343 |
}
|
| 339 |
}
|
344 |
}
|
| 340 |
|
345 |
|