Subversion Repositories SmartDukaan

Rev

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

Rev 14409 Rev 14428
Line 303... Line 303...
303
				$this->set(compact('users'));
303
				$this->set(compact('users'));
304
			}
304
			}
305
		}
305
		}
306
	}
306
	}
307
 
307
 
-
 
308
	public function generateAffiliateUrl($url,$user_id){
-
 
309
		//Get StoreProduct Info
-
 
310
		$this->loadModel('Store');
-
 
311
		$store = $this->Store->getByUrl($url);	
-
 
312
		$storeId = $store['Store']['id'];
-
 
313
		$prefix = "SHA".$storeId;
-
 
314
		$tag = $prefix.time();
-
 
315
		if($storeId == 2){				
-
 
316
			$url = str_replace('www','m',$url);
-
 
317
		} elseif($storeId == 3) {
-
 
318
			$url_parts = parse_url($url);
-
 
319
			$url_parts['path'] = str_replace('viewAllSellers/','',$url_parts['path']);//quickfix for snapdeal
-
 
320
			if(isset($url_parts['query'])) {
-
 
321
				$url = "http://m.snapdeal.com".$url_parts['path'].'?'.$url_parts['query']."&utm_source=aff_prog&utm_campaign=afts&offer_id=17";
-
 
322
			}else{
-
 
323
				$url = "http://m.snapdeal.com".$url_parts['path'].'?utm_source=aff_prog&utm_campaign=afts&offer_id=17';
-
 
324
			}
-
 
325
		} elseif($storeId == 4){
-
 
326
			$next = "&next=".str_replace('www','m',$url);	
-
 
327
			$url = $this->getAutoLoginUrl($userId,$next);
-
 
328
			$url .= '?utm_source=profitmandi';
-
 
329
		}
-
 
330
		if( strpos($url, '?') === false ) {
-
 
331
			$firstChar = '?';
-
 
332
		} else {
-
 
333
			$firstChar = '&';
-
 
334
		}
-
 
335
		$url .= $firstChar.$store['Store']['affid_param'].'='.$store['Store']['affiliate_id'];
-
 
336
		if(!empty($store['Store']['sub_tag_param'])){
-
 
337
			$url .= '&'.$store['Store']['sub_tag_param'].'='.$tag;
-
 
338
		}
-
 
339
		$extras = array('store'=>$store['Store']['name'],'source'=>'notification');
-
 
340
		$data = array('user_id' => $user_id,'store_product_id'=>0,'tag'=>$tag,'url'=>$url,'price'=>0,'extras'=>json_encode($extras));
-
 
341
		$this->loadModel('Click');
-
 
342
		$this->Click->create();
-
 
343
		$this->Click->save($data);
-
 
344
		return $url;
-
 
345
	}
-
 
346
 
308
	public function admin_push(){
347
	public function admin_push(){
309
		if ($this->request->is('post')) {
348
		if ($this->request->is('post')) {
310
			if(empty($this->request->data['userIds'])){
349
			if(empty($this->request->data['userIds'])){
311
				$this->Session->setFlash(__('Please choose a few users'));
350
				$this->Session->setFlash(__('Please choose a few users'));
312
				$this->redirect(array('action' => 'admin_pushnotifications'));
351
				$this->redirect(array('action' => 'admin_pushnotifications'));
Line 314... Line 353...
314
				$this->loadModel('GcmUser');
353
				$this->loadModel('GcmUser');
315
				foreach ($this->request->data['userIds'] as $key => $value) {					
354
				foreach ($this->request->data['userIds'] as $key => $value) {					
316
					$options = array('conditions'=>array('user_id'=>$value),'fields'=>array('gcm_regid'),'order'=>array('id'=>'desc'));
355
					$options = array('conditions'=>array('user_id'=>$value),'fields'=>array('gcm_regid'),'order'=>array('id'=>'desc'));
317
					$gcmUser = $this->GcmUser->find('first',$options);
356
					$gcmUser = $this->GcmUser->find('first',$options);
318
					$regIds = array($gcmUser['GcmUser']['gcm_regid']);
357
					$regIds = array($gcmUser['GcmUser']['gcm_regid']);
319
					$message = array('message'=>$this->request->data['User']['message']);
358
					// $message = array('message'=>$this->request->data['User']['message']);
-
 
359
					$message = $this->request->data['User'];
-
 
360
					if($message['type'] == 'url'){
-
 
361
						$message['url'] = $this->generateAffiliateUrl($message['url'],$value);
-
 
362
					}					
320
					$this->send_push_notification($regIds,$message);
363
					$this->send_push_notification($regIds,$message,$value);
321
				}
364
				}
322
			}
365
			}
323
		}
366
		}
324
	}
367
	}
325
 
368
 
326
	private function send_push_notification($registatoin_ids, $message) {
369
	private function send_push_notification($registatoin_ids, $message, $user_id) {
327
		$msg = array(
370
		$msg = array(
328
		    'message'       => $message['message'],
371
		    'message'       => $message['message'],
329
		    'title'         => $message['message'],
372
		    'title'         => $message['title'],
330
		    'subtitle'      => 'This is a subtitle',
373
		    'type'      	=> $message['type'],
331
		    'tickerText'    => 'Ticker text here...Ticker text here...Ticker text here',
374
		    'url'		    => $message['url'],
332
		    'vibrate'       => 1,
375
		    'vibrate'       => 1,
333
		    'sound'         => 1,
376
		    'sound'         => 1,
334
		    'largeIcon'     => 'large_icon',
377
		    'largeIcon'     => 'large_icon',
335
		    'smallIcon'     => 'small_icon'
378
		    'smallIcon'     => 'small_icon'
336
		);
379
		);
337
 
-
 
338
		// Set POST variables
380
		// Set POST variables
339
		$url = 'https://android.googleapis.com/gcm/send';
381
		$url = 'https://android.googleapis.com/gcm/send';
340
 
382
 
341
		$fields = array(
383
		$fields = array(
342
		    'registration_ids' => $registatoin_ids,
384
		    'registration_ids' => $registatoin_ids,
Line 367... Line 409...
367
		    die('Curl failed: ' . curl_error($ch));
409
		    die('Curl failed: ' . curl_error($ch));
368
		}
410
		}
369
 
411
 
370
		// Close connection
412
		// Close connection
371
		curl_close($ch);
413
		curl_close($ch);
372
		$this->log(print_r($result,1),'notifiactions');
414
		$this->log("For $user_id ".print_r($result,1),'notifiactions');
373
	}
415
	}
374
 
416
 
375
	public function admin_index() {		
417
	public function admin_index() {		
376
		$this->User->recursive = 0;
418
		$this->User->recursive = 0;
377
		$options = array('limit'=>100,'order'=>array('id'=>'desc'));
419
		$options = array('limit'=>100,'order'=>array('id'=>'desc'));