Subversion Repositories SmartDukaan

Rev

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

Rev 15380 Rev 15414
Line 404... Line 404...
404
				}
404
				}
405
			}
405
			}
406
		}
406
		}
407
	}
407
	}
408
 
408
 
409
	private function send_push_notification($registatoin_ids, $message, $user_id) {
409
	/*private function send_push_notification($registatoin_ids, $message, $user_id) {
410
		$msg = array(
410
		$msg = array(
411
		    'message'       => $message['message'],
411
		    'message'       => $message['message'],
412
		    'cid'       	=> $message['cid'],
412
		    'cid'       	=> $message['cid'],
413
		    'title'         => $message['title'],
413
		    'title'         => $message['title'],
414
		    'type'      	=> $message['type'],
414
		    'type'      	=> $message['type'],
Line 456... Line 456...
456
		$this->Pushnotification->create();
456
		$this->Pushnotification->create();
457
		$this->Pushnotification->save($data);
457
		$this->Pushnotification->save($data);
458
		// Close connection
458
		// Close connection
459
		curl_close($ch);
459
		curl_close($ch);
460
		$this->log("For $user_id ".$registatoin_ids[0]." ".print_r($result,1),'pushnotifications');
460
		$this->log("For $user_id ".$registatoin_ids[0]." ".print_r($result,1),'pushnotifications');
461
	}
461
	}*/
-
 
462
	private function send_push_notification($registatoin_ids, $message, $user_id) {
-
 
463
                $msg = array(
-
 
464
                    'message'       => $message['message'],
-
 
465
                    'cid'               => $message['cid'],
-
 
466
                    'title'         => $message['title'],
-
 
467
                    'type'              => $message['type'],
-
 
468
                    'url'                   => $message['url'],
-
 
469
                    // 'expiresat'          => strtotime($message['expiresat']),
-
 
470
                    'vibrate'       => 1,
-
 
471
                    'sound'         => 1,
-
 
472
                    'largeIcon'     => 'large_icon',
-
 
473
                    'smallIcon'     => 'small_icon'
-
 
474
                );
-
 
475
                // Set POST variables
-
 
476
                $url = 'https://android.googleapis.com/gcm/send';
-
 
477
 
-
 
478
                $fields = array(
-
 
479
                    'registration_ids' => $registatoin_ids,
-
 
480
                    'data' => $msg,
-
 
481
                );
-
 
482
                $headers = array(
-
 
483
                    'Authorization: key=' . Configure::read('googleapikey'),
-
 
484
                    'Content-Type: application/json'
-
 
485
                );
-
 
486
                //print_r($headers);
-
 
487
                // Open connection
-
 
488
                $ch = curl_init();
-
 
489
 
-
 
490
                // Set the url, number of POST vars, POST data
-
 
491
                curl_setopt($ch, CURLOPT_URL, $url);
-
 
492
                curl_setopt($ch, CURLOPT_POST, true);
-
 
493
                curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
-
 
494
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
-
 
495
 
-
 
496
                // Disabling SSL Certificate support temporarly
-
 
497
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
-
 
498
 
-
 
499
                curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
-
 
500
 
-
 
501
                // Execute post
-
 
502
                $result = curl_exec($ch);
-
 
503
                if ($result === FALSE) {
-
 
504
                    die('Curl failed: ' . curl_error($ch));
-
 
505
                }
-
 
506
                $res = json_decode($result,1);
-
 
507
 
-
 
508
                $this->loadModel('Pushnotification');
-
 
509
                if($res['success']==1){
-
 
510
					$data = array('notification_campaign_id'=>$message['cid'],'user_id'=>$user_id,'type'=>'sent','status'=>$res['success'],'message'=>'success');
-
 
511
				}else if($res['success']==0){
-
 
512
					$error_message=$res['results'][0]['error'];
-
 
513
					$sqlQuery="update gcm_users set failurecount=failurecount+1 where gcm_regid='".$registatoin_ids[0]."'";
-
 
514
					$resultData=$this->GcmUser->query($sqlQuery);
-
 
515
					$data = array('notification_campaign_id'=>$message['cid'],'user_id'=>$user_id,'type'=>'sent','status'=>$res['success'],'message'=>$error_message);
-
 
516
				}
-
 
517
                #$data = array('notification_campaign_id'=>$message['cid'],'user_id'=>$user_id,'status'=>$res['success']);
-
 
518
                $this->Pushnotification->create();
-
 
519
                $this->Pushnotification->save($data);
-
 
520
                $this->log("For $user_id ".$registatoin_ids[0]." ".print_r($data,1),'pushnotifications');
-
 
521
                // Close connection
-
 
522
                curl_close($ch);
-
 
523
                $this->log("For $user_id ".$registatoin_ids[0]." ".print_r($result,1),'pushnotifications');
-
 
524
        }
462
 
525
 
463
	public function admin_index() {		
526
	public function admin_index() {		
464
		$this->User->recursive = 0;
527
		$this->User->recursive = 0;
465
		$options = array('limit'=>100,'order'=>array('id'=>'desc'));
528
		$options = array('limit'=>100,'order'=>array('id'=>'desc'));
466
		$this->Paginator->settings = $options;
529
		$this->Paginator->settings = $options;