Rev 18135 | Rev 18142 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?phpApp::uses('AppController', 'Controller');/*** A Controller** @property A $A* @property PaginatorComponent $Paginator*/class AController extends AppController {/*** Components** @var array*/public $components = array('Paginator');public function index() {$encryptUrl = 'http://shop2020.in:8057/message/encrypt?type=encrypt&data=';$expiryFlag=false;$redirectFlag=false;$this->layout = 'innerpages';$serverHost= $_SERVER['HTTP_HOST'];$serverURI = $_SERVER['REQUEST_URI'];$requestURL ="http://".$serverHost.$serverURI;$intentToSend = '';$params = explode($serverHost.'/a', $requestURL);if(empty($params[1])){debug('Redirect to the 404 page condition 1');echo('Redirect to the 404 page condition 1');$redirectFlag=true;//Redirect to the 404 page}else{$fetchParams = explode('/', $params[1]);//debug($fetchParams);if(empty($fetchParams[0]) && empty($fetchParams[1])){debug('Redirect to the 404 page condition 2');echo('Redirect to the 404 page condition 2');$redirectFlag=true;//Redirect to the 404 page}else{if(sizeof($fetchParams) == 2 || empty($fetchParams[2])){debug('Redirect to the 404 page condition 3');echo('Redirect to the 404 page condition 3');$redirectFlag=true;//Redirect to the 404 page}else if(sizeof($fetchParams)>4){debug('Redirect to the 404 page condition 4');echo('Redirect to the 404 page condition 4');$redirectFlag=true;//Redirect to the 404 page}else{$campaignId = $fetchParams[1];$userId = $fetchParams[2];;$campaignId = $this->num_decode($campaignId);$userId = $this->num_decode($userId);/*debug($campaignId);debug($userId);*/$notificationUrl='';$encryptedData=array();$conn=$this->getDatabaseConnection();if($conn){$sql = 'SELECT * FROM notification_campaigns WHERE id ='.$campaignId;$result = mysql_query($sql, $conn);if (mysql_num_rows($result)==0) {debug('Zero rows');echo('Zero rows');$redirectFlag=true;}else{while ($row = mysql_fetch_assoc($result)) {//debug($row);$notificationUrl = $row['url'];$notificationType = $row['type'];$notificationExpires = $row['expiresat'];$notificationStatus = $row['status'];$currentTime = time();if(strtotime($notificationExpires) < $currentTime || $notificationStatus=='inactive'){//debug('Notification has expired');$expiryFlag=true;}if($notificationType=='native'){if(strtolower($notificationUrl)=='contact' || strtolower($notificationUrl)=='profile' ||strtolower($notificationUrl)=='tutorial'){//debug('V,W,Ir,aH,-y');$encryptUrl = $encryptUrl.base64_encode(strtolower($notificationUrl));$encryptedData = $this->make_request($encryptUrl,null);}else{$encryptedData = $this->defaultEncryptedMessage($userId);}}else if ($notificationType=='update'){//debug('K3');$encryptUrl = $encryptUrl.base64_encode('https://play.google.com/store/apps/details?id=com.saholic.profittill');$encryptedData = $this->make_request($encryptUrl,null);}else{//debug($notificationUrl);if(empty($notificationUrl)){debug('B');$encryptedData = $this->defaultEncryptedMessage($userId);}else if(strpos($notificationUrl,'?user_id=') !== false){$encryptUrl = $encryptUrl.base64_encode($notificationUrl);$encryptedData = $this->make_request($encryptUrl,null);}else{$notificationUrl = $notificationUrl.'?user_id='.$userId;$encryptUrl = $encryptUrl.base64_encode($notificationUrl);$encryptedData = $this->make_request($encryptUrl,null);}}}}}else{$encryptedData = $this->defaultEncryptedMessage($userId);}//debug($encryptedData);//debug($this->decrypt(urlencode($encryptedData['result']['value'])));}}}if($redirectFlag){debug('The user needs to be redirected');echo('The user needs to be redirected');}else{$intentToSend = 'intent://pmapp.com?key='.urlencode($encryptedData['result']['value']).'&campaign='.$campaignId.'&intent_type='.$notificationType.'#Intent;scheme=profitmandiapp;package=com.saholic.profittill;end';//if()$this->set(compact('intentToSend','expiryFlag'));header('Location: '.$intentToSend);return;//debug($intentToSend);//debug($expiryFlag);}}function defaultEncryptedMessage($userId){$encryptUrl = 'http://shop2020.in:8057/message/encrypt?type=encrypt&data=';$defaultEncryptedData =array();$defaultUrl = 'http://api.profittill.com/deals';// if(empty($userId)){// $notificationUrl = $defaultUrl;// }else{// $notificationUrl = $defaultUrl.'?user_id='.$userId;// }$notificationUrl = $defaultUrl.'?user_id='.$userId;$encryptUrl = $encryptUrl.base64_encode($notificationUrl);$defaultEncryptedData = $this->make_request($encryptUrl,null);return $defaultEncryptedData;}function decrypt($encryptData){$encryptUrl = 'http://shop2020.in:8057/message/encrypt?type=decrypt&data=';$encryptUrl = $encryptUrl.$encryptData;$encryptedData = $this->make_request($encryptUrl,null);return($encryptedData);}function num_decode($value){$alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';$number=0;foreach(str_split($value) as $letter) {$number=($number*64) + strpos($alphabet,$letter);}return $number;}function num_encode($id){$alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';$shortenedId = '';while($id>0) {$remainder = $id % 64;$id = ($id-$remainder) / 64;$shortenedId = $alphabet{$remainder} . $shortenedId;}return $shortenedId;}function getDatabaseConnection(){$servername = "104.200.25.40";$username = "root";$password = "shop2020";$databaseName="dtr";$conn = mysql_connect($servername,$username,$password);if(!$conn){return false;}else{$databaseConnection = mysql_select_db($databaseName, $conn);if(!$databaseConnection){return false;}else{return $conn;}}}}