Subversion Repositories SmartDukaan

Rev

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

Rev 14395 Rev 14408
Line 3... Line 3...
3
/**
3
/**
4
 * Users Controller
4
 * Users Controller
5
 *
5
 *
6
 * @property User $User
6
 * @property User $User
7
 */
7
 */
-
 
8
 
-
 
9
set_time_limit(0);
-
 
10
 
8
class UsersController extends AppController {
11
class UsersController extends AppController {
9
 
12
 
10
	public $components = array('SignMeUp.SignMeUp','RequestHandler','Cookie','Paginator');
13
	public $components = array('SignMeUp.SignMeUp','RequestHandler','Cookie','Paginator');
11
 
14
 
12
    public function beforeFilter() {
15
    public function beforeFilter() {
Line 289... Line 292...
289
/**
292
/**
290
 * admin_index method
293
 * admin_index method
291
 *
294
 *
292
 * @return void
295
 * @return void
293
 */
296
 */
-
 
297
 
-
 
298
	public function admin_pushnotifications(){
-
 
299
		if ($this->request->is('post')) {
-
 
300
			$sql = $this->request->data['User']['sql'];
-
 
301
			if(!empty($sql)){
-
 
302
				$users = $this->User->query($sql);
-
 
303
				$this->set(compact('users'));
-
 
304
			}
-
 
305
		}
-
 
306
	}
-
 
307
 
-
 
308
	public function admin_push(){
-
 
309
		if ($this->request->is('post')) {
-
 
310
			if(empty($this->request->data['userIds'])){
-
 
311
				$this->Session->setFlash(__('Please choose a few users'));
-
 
312
				$this->redirect(array('action' => 'admin_pushnotifications'));
-
 
313
			}else{
-
 
314
				$this->loadModel('GcmUser');
-
 
315
				foreach ($this->request->data['userIds'] as $key => $value) {					
-
 
316
					$options = array('conditions'=>array('user_id'=>$value),'fields'=>array('gcm_regid'),'order'=>array('id'=>'desc'));
-
 
317
					$gcmUser = $this->GcmUser->find('first',$options);
-
 
318
					$regIds = array($gcmUser['GcmUser']['gcm_regid']);
-
 
319
					$message = array('message'=>$this->request->data['User']['message']);
-
 
320
					$this->send_push_notification($regIds,$message);
-
 
321
				}
-
 
322
			}
-
 
323
		}
-
 
324
	}
-
 
325
 
-
 
326
	private function send_push_notification($registatoin_ids, $message) {
-
 
327
		debug(func_get_args());return;
-
 
328
        $msg = array(
-
 
329
            'message'       => $message['message'],
-
 
330
            'title'         => $message['message'],
-
 
331
            'subtitle'      => 'This is a subtitle',
-
 
332
            'tickerText'    => 'Ticker text here...Ticker text here...Ticker text here',
-
 
333
            'vibrate'       => 1,
-
 
334
            'sound'         => 1,
-
 
335
            'largeIcon'     => 'large_icon',
-
 
336
            'smallIcon'     => 'small_icon'
-
 
337
        );
-
 
338
 
-
 
339
        // Set POST variables
-
 
340
        $url = 'https://android.googleapis.com/gcm/send';
-
 
341
 
-
 
342
        $fields = array(
-
 
343
            'registration_ids' => $registatoin_ids,
-
 
344
            'data' => $msg,
-
 
345
        );
-
 
346
        $headers = array(
-
 
347
            'Authorization: key=' . Configure::read('googleapikey'),
-
 
348
            'Content-Type: application/json'
-
 
349
        );
-
 
350
        //print_r($headers);
-
 
351
        // Open connection
-
 
352
        $ch = curl_init();
-
 
353
 
-
 
354
        // Set the url, number of POST vars, POST data
-
 
355
        curl_setopt($ch, CURLOPT_URL, $url);
-
 
356
        curl_setopt($ch, CURLOPT_POST, true);
-
 
357
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
-
 
358
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
-
 
359
 
-
 
360
        // Disabling SSL Certificate support temporarly
-
 
361
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
-
 
362
 
-
 
363
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
-
 
364
 
-
 
365
        // Execute post
-
 
366
        $result = curl_exec($ch);
-
 
367
        if ($result === FALSE) {
-
 
368
            die('Curl failed: ' . curl_error($ch));
-
 
369
        }
-
 
370
 
-
 
371
        // Close connection
-
 
372
        curl_close($ch);
-
 
373
        // echo $result;die;
-
 
374
    }
-
 
375
 
294
	public function admin_index() {
376
	public function admin_index() {		
295
		$this->User->recursive = 0;
377
		$this->User->recursive = 0;
296
		$options = array('limit'=>100,'order'=>array('id'=>'desc'));
378
		$options = array('limit'=>100,'order'=>array('id'=>'desc'));
297
		$this->Paginator->settings = $options;
379
		$this->Paginator->settings = $options;
298
		$users = $this->Paginator->paginate();
380
		$users = $this->Paginator->paginate();
299
		$groups = $this->User->Group->find('list');
381
		$groups = $this->User->Group->find('list');