Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
- class Api_New extends CI_Controller {
- function Api_New()
- {
- parent::__construct();
- $this->load->model('commonmodel');
- $this->load->model('api_model');
- $this->load->library('email');
- $this->load->helper('email');
- $this->form_validation->set_message('valid_email', 'please insert a valid email address');
- $this->form_validation->set_message('matches', 'please check you have entered the correct password');
- $this->form_validation->set_message('is_unique', 'it seems you have already registered with us. Can you please login');
- $this->data['giftcard_url'] = $this->config->item('site_url').'uploads/giftcard/original/';
- $this->data['country_url'] = $this->config->item('site_url').'uploads/country/original/';
- $this->data['social_url'] = $this->config->item('site_url').'uploads/social/original/';
- }
- function index()
- {
- echo "Not authorized";
- }
- /* Start Function for register user */
- function register(){
- if($_POST){
- //// Start Check fields validation
- if($this->input->post('type') == 'email'){$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|is_unique[users.email]');}
- $this->form_validation->set_rules('first_name', 'First Name', 'trim|required');
- $this->form_validation->set_rules('last_name', 'Last Name', 'trim|required');
- $this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[5]');
- $this->form_validation->set_rules('cnfpassword', 'Confirm Password', 'trim|required|matches[password]');
- $this->form_validation->set_rules('gcm_id', 'Gcm id', 'trim|required');
- $this->form_validation->set_rules('device_id', 'Device id', 'trim|required');
- $this->form_validation->set_rules('type', 'Type', 'trim|required');
- $this->form_validation->set_error_delimiters('', ''); //Changing error delimiter to empty
- //// End Check fields validation
- if($this->form_validation->run()) {
- $insertdata = array();
- if($this->input->post('type') != 'email'){$insertdata['is_active'] = 'Y';}
- $insertdata['type'] = $this->input->post('type');
- $insertdata['first_name'] = $this->input->post('first_name');
- $insertdata['last_name'] = $this->input->post('last_name');
- $insertdata['password'] = md5($this->input->post('password'));
- $insertdata['email'] = $this->input->post('email');
- $insertdata['encrypt'] = base64_encode($_POST['password']);
- $insertdata['gcm_id'] = $this->input->post('gcm_id');
- $insertdata['device_id'] = $this->input->post('device_id');
- $insertdata['registration_date'] = date('Y-m-d H:i:s');
- $insertdata['wallet_id'] = str_replace('0','5',md5(uniqid()));
- $insertdata['invation_code'] = substr(md5(uniqid()) ,5, 5);
- $insertdata['activation_code'] = md5(date("Y-m-d H:i:s").$_POST['email']);
- $insertdata['last_login_date'] = date("Y-m-d H:i:s");
- if($this->input->post('type') == 'email'){
- //// insert user register data
- $id = $this->api_model->insertData("users", $insertdata);
- }
- else{
- $checkDataa = array();
- $tableNamea ="users AS usr";
- $fieldNamea = array('usr.* , usr.id AS user_id , usr.is_active');
- $checkDataa['usr.email'] = $this->input->post('email');
- $rowDataa = $this->api_model->selectData($tableNamea, $fieldNamea, $checkDataa);
- if($rowDataa->num_rows() > 0){
- $userDataa = $rowDataa->result_array();
- if($userDataa[0]['is_active'] == 'Y'){$id = $userDataa[0]['user_id'];}
- else{echo json_encode(array("RESULT" => "NO", "Message" => "Admin Blocked this account"));exit;}
- }
- else{$id = $this->api_model->insertData("users", $insertdata);}
- }
- if($id){
- $checkData['usr.Id'] = $id;
- $tableName = "users AS usr";
- $fieldName = array('usr.* , usr.id AS user_id');
- $rowData = $this->api_model->selectData($tableName, $fieldName, $checkData);
- $userData = $rowData->result_array();
- $userData[0]['password'] = base64_decode($userData[0]['encrypt']);
- //Add other things to register
- //Menu Text Details
- $checkData2 = "(menu.id='1')";
- $tableCon2 ="menu_pages AS menu";
- $fields2 = array("menu.faq_text AS faq_content , menu.term_text AS term_content, menu.assistance AS assistance_content");
- $groupBy2 = "menu.id";
- $rowData2 = $this->api_model->selectData($tableCon2, $fields2, $checkData2,NULL,NULL,0,10,FALSE,$groupBy2);
- $menuData = $rowData2->row_array();
- /* Earn points details */
- $checkData3['ern.id'] = 1;
- $tableName3 ="earn_points AS ern";
- $fieldName3 = array('ern.daily_reward_points , ern.daily_reward_limit , ern.invite_user_reward , ern.invite_friend_reward ,ern.invite_code_disable_points , ern.share_text , ern.invite_text');
- $rowData3 = $this->api_model->selectData($tableName3, $fieldName3, $checkData3);
- $earnData = $rowData3->row_array();
- //version Details
- $checkData4 = "(ver.id='1')";
- $tableCon4 ="app_version AS ver";
- $fields4 = array("ver.version AS app_version");
- $groupBy4 = "ver.id";
- $rowData4 = $this->api_model->selectData($tableCon4, $fields4, $checkData4,NULL,NULL,0,10,FALSE,$groupBy4);
- $versionData = $rowData4->row_array();
- $resultArray = array_merge($userData[0],$menuData , $earnData , $versionData);
- ///send activation account
- if($this->input->post('type') == 'email'){ $this->sendmail($insertdata);
- echo json_encode(array("RESULT" => "YES", "Message" => "Thanks, Please Check Your Email to Activate Your Account.", "Data" => $resultArray));} else{ echo json_encode(array("RESULT" => "YES", "Message" => "Login Successfully", "Data" => $resultArray)); exit; }
- }else{
- echo json_encode(array("RESULT" => "NO", "Message" => "Registration not completed. Please contact with application administrator"));
- }
- exit();
- }else{
- $this->load->view('api/noresult'); //load noresult and error view
- exit();
- }
- }else{
- //$this->load->view('api/register'); // load default testing view
- }
- }
- /* End Function for register user */
- /* Start Function for register user */
- function update_profile(){
- if($_POST){
- $updatedata = array();
- $where['id'] = $this->input->post('user_id');
- if($this->input->post('paypal_account')!='') {$updatedata['paypal_account'] = $this->input->post('paypal_account');}
- if($this->input->post('first_name')!='') {$updatedata['first_name'] = $this->input->post('first_name');}
- if($this->input->post('last_name')!='') {$updatedata['last_name'] = $this->input->post('last_name');}
- if($this->input->post('password')!='') {$updatedata['password'] = $this->input->post('password');$updatedata['encrypt'] = base64_encode($_POST['password']);}
- //// insert user register data
- $id = $this->api_model->updateData("users", $updatedata , $where);
- if($id){
- $checkData['usr.Id'] = $this->input->post('user_id');
- $tableName = "users AS usr";
- $fieldName = array('usr.* , usr.id AS user_id');
- $rowData = $this->api_model->selectData($tableName, $fieldName, $checkData);
- $userData = $rowData->result_array();
- $userData[0]['password'] = base64_decode($userData[0]['encrypt']);
- //Add other things to register
- //Menu Text Details
- $checkData2 = "(menu.id='1')";
- $tableCon2 ="menu_pages AS menu";
- $fields2 = array("menu.faq_text AS faq_content , menu.term_text AS term_content, menu.assistance AS assistance_content");
- $groupBy2 = "menu.id";
- $rowData2 = $this->api_model->selectData($tableCon2, $fields2, $checkData2,NULL,NULL,0,10,FALSE,$groupBy2);
- $menuData = $rowData2->row_array();
- /* Earn points details */
- $checkData3['ern.id'] = 1;
- $tableName3 ="earn_points AS ern";
- $fieldName3 = array('ern.daily_reward_points , ern.daily_reward_limit , ern.invite_user_reward , ern.invite_friend_reward ,ern.invite_code_disable_points , ern.share_text , ern.invite_text');
- $rowData3 = $this->api_model->selectData($tableName3, $fieldName3, $checkData3);
- $earnData = $rowData3->row_array();
- $resultArray = array_merge($userData[0],$menuData , $earnData);
- echo json_encode(array("RESULT" => "YES", "Message" => "success", "Data" => $resultArray));
- }else{
- echo json_encode(array("RESULT" => "NO", "Message" => "Please try again"));
- }
- }else{
- //$this->load->view('api/update_profile'); // load default testing view
- }
- }
- /* End Function for register user */
- /* Start Function for login authentication */
- function login_authentication(){
- if($_POST){
- //// Start Check fields validation
- $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
- $this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[5]');
- $this->form_validation->set_rules('gcm_id', 'Gcm id', 'trim|required');
- $this->form_validation->set_rules('device_id', 'Device id', 'trim|required');
- $this->form_validation->set_error_delimiters('', ''); //Changing error delimiter to empty
- //// End Check fields validation
- if($this->form_validation->run()) {
- $checkData = array();
- $checkData['usr.password'] = md5($this->input->post('password'));
- $checkData['usr.email'] = $this->input->post('email');
- $checkData['usr.is_active'] = 'Y';
- $insertData['device_id'] = $this->input->post('device_id');
- $insertData['gcm_id'] = $this->input->post('gcm_id');
- $insertData['last_login_date'] = date("Y-m-d H:i:s");
- $tableName ="users AS usr";
- $fieldName = array('usr.* , usr.id AS user_id');
- $rowData = $this->api_model->selectData($tableName, $fieldName, $checkData);
- if($rowData->num_rows() > 0){
- $userData = $rowData->result_array();
- $whereData['id'] = $userData[0]['user_id'];
- $this->api_model->updateData("users",$insertData , $whereData );
- //Add other things to login
- //Menu Text Details
- $checkData2 = "(menu.id='1')";
- $tableCon2 ="menu_pages AS menu";
- $fields2 = array("menu.faq_text AS faq_content , menu.term_text AS term_content, menu.assistance AS assistance_content");
- $groupBy2 = "menu.id";
- $rowData2 = $this->api_model->selectData($tableCon2, $fields2, $checkData2,NULL,NULL,0,10,FALSE,$groupBy2);
- $menuData = $rowData2->row_array();
- /* Earn points details */
- $checkData3['ern.id'] = 1;
- $tableName3 ="earn_points AS ern";
- $fieldName3 = array('ern.daily_reward_points , ern.daily_reward_limit , ern.invite_user_reward , ern.invite_friend_reward ,ern.invite_code_disable_points , ern.share_text , ern.invite_text');
- $rowData3 = $this->api_model->selectData($tableName3, $fieldName3, $checkData3);
- $earnData = $rowData3->row_array();
- //version Details
- $checkData4 = "(ver.id='1')";
- $tableCon4 ="app_version AS ver";
- $fields4 = array("ver.version AS app_version");
- $groupBy4 = "ver.id";
- $rowData4 = $this->api_model->selectData($tableCon4, $fields4, $checkData4,NULL,NULL,0,10,FALSE,$groupBy4);
- $versionData = $rowData4->row_array();
- $resultArray = array_merge($userData[0],$menuData , $earnData ,$versionData);
- echo json_encode(array("RESULT" => "YES", "Message" => "Success", "Data" => $resultArray));
- }else{ echo json_encode(array("RESULT" => "NO", "Message" => "Inavalid Email and Password")); }
- }
- else{
- $this->load->view('api/noresult'); //load noresult and error view
- exit();
- }
- }else{
- //$this->load->view('api/checklogin'); // load default testing view
- }
- }
- /* End Function for login authentication */
- /* Start Function for forgot password */
- function forgot_pass(){
- if($_POST){
- //// Start Check fields validation
- $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
- $this->form_validation->set_error_delimiters('', ''); //Changing error delimiter to empty
- //// End Check fields validation
- if($this->form_validation->run()) {
- $checkData = array();
- $checkData['usr.email'] = $this->input->post('email');
- $checkData['usr.is_active'] = 'Y';
- $tableName ="users AS usr";
- $fieldName = array('usr.* , usr.id AS user_id');
- $rowData = $this->api_model->selectData($tableName, $fieldName, $checkData);
- if($rowData->num_rows() > 0){
- $userData = $rowData->result_array();
- $password = uniqid();
- $insertData['password'] = md5($password);
- $insertData['encrypt'] = base64_encode($password);
- $this->sendmailForgotPassword($userData[0],$password);
- $whereData['id'] = $userData[0]['user_id'];
- $this->api_model->updateData("users",$insertData , $whereData );
- echo json_encode(array("RESULT" => "YES", "Message" => "Your updated password sent on your email address,Please check", "Data" => $userData[0]));
- }else{
- echo json_encode(array("RESULT" => "NO", "Message" => "Inavalid Email Address")); }
- }
- else{
- $this->load->view('api/noresult'); //load noresult and error view
- exit();
- }
- }else{
- //$this->load->view('api/checklogin'); // load default testing view
- }
- }
- /* End Function for forgot password */
- /* Start Function for country list */
- function country_list(){
- $checkData = "(cty.is_active='Y')";
- $tableCon ="country AS cty";
- $fields = array("cty.id AS country_id , cty.name AS country_name, cty.price_sign AS country_price_sign , CONCAT('".$this->data['country_url']."',cty.logo) AS country_logo , cty.is_active AS country_status ");
- $groupBy = "cty.id";
- $rowData = $this->api_model->selectData($tableCon, $fields, $checkData,NULL,NULL,0,50,FALSE,$groupBy);
- if($rowData->num_rows() > 0){
- $query_tables_result = array();
- $query_tables_result = $rowData->result_array();
- echo json_encode(array("RESULT" => "YES", "Message" => "Success", "Data" => array_values($query_tables_result)));exit();
- }else{
- echo json_encode(array("RESULT" => "NO", "Message" => "Sorry, No Data!."));exit();
- }
- }
- /* End Function for country list */
- /* Start Function for redeem complete list */
- function redeem_complete_list(){
- if($_POST){
- $checkData = "(red.user_id = '".$_POST['user_id']."')";
- $tableCon ="redeem_offers AS red LEFT JOIN offers AS off ON red.offer_id = off.id LEFT JOIN gifts_card AS gift ON gift.id = off.giftcard_id LEFT JOIN country ON country.id =gift.country_id";
- $fields = array("red.* , off.*,gift.title AS giftcard_title , red.is_active AS redeem_status ,country.price_sign AS country_price_sign, country.name AS country_name");
- $groupBy = "red.id";
- $rowData = $this->api_model->selectData($tableCon, $fields, $checkData,NULL,NULL,0,50,FALSE,$groupBy);
- if($rowData->num_rows() > 0){
- $query_tables_result = array();
- $query_tables_result = $rowData->result_array();
- echo json_encode(array("RESULT" => "YES", "Message" => "Success", "Data" => array_values($query_tables_result)));exit();
- }else{
- echo json_encode(array("RESULT" => "NO", "Message" => "Sorry, No Data!."));exit();
- }
- }
- //$this->load->view('api/redeem_complete_list');// load default testing view
- }
- /* End Function for for redeem complete list */
- /* Start Function for redeem complete list */
- function credits_complete_list(){
- if($_POST){
- $checkData = "(red.user_wallet = '".$_POST['user_id']."') AND (red.sdk_name!='admin')";
- $tableCon ="offers_credits AS red LEFT JOIN users AS usr ON red.user_wallet = usr.wallet_id";
- $fields = array("red.* , usr.first_name , usr.last_name , usr.email");
- $groupBy = "red.id";
- $rowData = $this->api_model->selectData($tableCon, $fields, $checkData,NULL,NULL,0,50,FALSE,$groupBy);
- if($rowData->num_rows() > 0){
- $query_tables_result = array();
- $query_tables_result = $rowData->result_array();
- echo json_encode(array("RESULT" => "YES", "Message" => "Success", "Data" => array_values($query_tables_result)));exit();
- }else{
- echo json_encode(array("RESULT" => "NO", "Message" => "Sorry, No Data!."));exit();
- }
- }
- // $this->load->view('api/redeem_complete_list');// load default testing view
- }
- /* End Function for for redeem complete list */
- /* Start Function for invite friend list */
- function invite_friend_list(){
- if($_POST){
- $checkData = "(usr.parent_id = '".$_POST['user_id']."')";
- $tableCon ="users AS usr";
- $fields = array("usr.*");
- $groupBy = "usr.id";
- $rowData = $this->api_model->selectData($tableCon, $fields, $checkData,NULL,NULL,0,50,FALSE,$groupBy);
- if($rowData->num_rows() > 0){
- $query_tables_result = array();
- $query_tables_result = $rowData->result_array();
- echo json_encode(array("RESULT" => "YES", "Message" => "Success", "Data" => array_values($query_tables_result)));exit();
- }else{
- echo json_encode(array("RESULT" => "NO", "Message" => "Sorry, No Data!."));exit();
- }
- }
- //$this->load->view('api/redeem_complete_list');// load default testing view
- }
- /* End Function for invite friend list */
- /* Start Function for social list */
- function social_list(){
- $checkData = "(social.is_active='Y')";
- $tableCon ="social_networks AS social";
- $fields = array("social.id AS social_id , social.title AS social_title, social.link AS social_link , CONCAT('".$this->data['social_url']."',social.logo) AS social_logo , social.is_active AS social_status ");
- $groupBy = "social.id";
- $orderby = "social.weight";
- $rowData = $this->api_model->selectData($tableCon, $fields, $checkData,NULL,$orderby,0,10,FALSE,$groupBy);
- if($rowData->num_rows() > 0){
- $query_tables_result = array();
- $query_tables_result = $rowData->result_array();
- echo json_encode(array("RESULT" => "YES", "Message" => "Success", "Data" => array_values($query_tables_result)));exit();
- }else{
- echo json_encode(array("RESULT" => "NO", "Message" => "Sorry, No Data!."));exit();
- }
- }
- /* End Function for country list */
- /* Start Function for country Details */
- function country_details(){
- if($_POST){
- //// Start Check fields validation
- $this->form_validation->set_rules('country_id', 'Country Id', 'required');
- $this->form_validation->set_error_delimiters('', ''); //Changing error delimiter to empty
- //// End Check fields validation
- if($this->form_validation->run()) {
- /* Post values */
- $country_id = $this->input->post('country_id');
- $checkData = "(gift.country_id= '".$country_id."') AND (gift.is_active='Y')";
- $tableCon ="gifts_card gift LEFT JOIN offers ON (offers.giftcard_id = gift.id AND offers.is_active='Y')";
- $fields = array("gift.country_id AS country_id , gift.description AS giftcard_description, gift.id AS giftcard_id , gift.title AS giftcard_title , CONCAT('".$this->data['giftcard_url']."',gift.logo) AS giftcard_logo ,CONCAT('[' , GROUP_CONCAT(DISTINCT '{\"offer_id\":\"' , offers.id, '\",\"offers_redeem_amount\":\"' , offers.title , '\",\"offer_price\":\"' , offers.price , '\"}') , ']') AS offers_details");
- $groupBy = "gift.id";
- $orderBy = 'gift.weight';
- $rowData = $this->api_model->selectData($tableCon, $fields, $checkData,NULL,$orderBy,0,10,FALSE,$groupBy);
- if($rowData->num_rows() > 0){
- $query_tables_result = array();
- $query_tables_result = $rowData->result_array();
- $count =sizeof($query_tables_result);
- for($a= 0; $a<$count; $a++){
- /* Start Convert json to Array */
- $query_tables_result[$a]['offers_details'] = json_decode($query_tables_result[$a]['offers_details']);
- if($query_tables_result[$a]['offers_details'] == null || $query_tables_result[$a]['offers_details'] == '') {$query_tables_result[$a]['offers_details'] = array();}
- /* End Convert json to Array */
- }
- echo json_encode(array("RESULT" => "YES", "Message" => "Success", "Data" => array_values($query_tables_result)));exit();
- }else{
- echo json_encode(array("RESULT" => "NO", "Message" => "Sorry, No Data!"));exit();
- }
- }else{
- $this->load->view('api/noresult'); //load noresult and error view
- exit();
- }}
- else{
- //$this->load->view('api/country_details');// load default testing view
- }
- }
- /* End Function for country Details */
- /* Start Function for Checkin */
- function checkin(){
- if($_POST){
- //// Start Check fields validation
- $this->form_validation->set_rules('user_id', 'User id', 'required');
- $this->form_validation->set_error_delimiters('', ''); //Changing error delimiter to empty
- //// End Check fields validation
- if($this->form_validation->run()) {
- $checkData = array();
- /* Post values */
- $checkData['usr.id'] = $this->input->post('user_id');
- $tableName ="users AS usr";
- $fieldName = array('usr.rewards_checkin AS rewards_checkin , usr.points AS points');
- $rowData = $this->api_model->selectData($tableName, $fieldName, $checkData);
- if($rowData->num_rows() > 0){
- $userData = $rowData->row_array();
- $rewards_checkin = $userData['rewards_checkin'];
- $datetime = date('Y-m-d H:i:s');
- /* Earn points details */
- $checkData2['ern.id'] = 1;
- $tableName2 ="earn_points AS ern";
- $fieldName2 = array('ern.*');
- $rowData2 = $this->api_model->selectData($tableName2, $fieldName2, $checkData2);
- $earnData = $rowData2->row_array();
- if($rewards_checkin == '0000-00-00 00:00:00'){
- $insertData['points'] = $userData['points'] + $earnData['daily_reward_points'];
- $insertData['rewards_checkin'] = date('Y-m-d H:i:s');
- }
- else{
- $day1 = strtotime($rewards_checkin);
- $day2 = strtotime($datetime);
- $diffHours = round(($day2 - $day1) / 3600);
- if($diffHours >= 24 ){ $insertData['points'] = $userData['points'] + $earnData['daily_reward_points']; $insertData['rewards_checkin'] = date('Y-m-d H:i:s');}
- else{ echo json_encode(array("RESULT" => "NO", "Message" => "Sorry, Unable to Check-In!"));exit(); }
- }
- $whereData['id'] = $this->input->post('user_id');
- $this->api_model->updateData("users",$insertData , $whereData );
- $points['user_points'] = $insertData['points'];
- $points['rewards_checkin'] = $insertData['rewards_checkin'];
- echo json_encode(array("RESULT" => "YES", "Message" => "Check-In Successful", "Data" => $points));
- }
- else{
- echo json_encode(array("RESULT" => "NO", "Message" => "Sorry, Unable to checkin!"));exit();
- }
- }else{
- $this->load->view('api/noresult'); //load noresult and error view
- exit();
- }}
- else{
- //$this->load->view('api/checkin');// load default testing view
- }
- }
- /* End Function for Checkin */
- /* Start Function For menu_content*/
- function menu_content(){
- $checkData = "(menu.id='1')";
- $tableCon ="menu_pages AS menu";
- $fields = array("menu.faq_text AS faq_content , menu.term_text AS term_content, menu.assistance AS assistance_content");
- $groupBy = "menu.id";
- $rowData = $this->api_model->selectData($tableCon, $fields, $checkData,NULL,NULL,0,10,FALSE,$groupBy);
- if($rowData->num_rows() > 0){
- $query_tables_result = $rowData->row_array();
- echo json_encode(array("RESULT" => "YES", "Message" => "Success", "Data" => $query_tables_result));exit();
- }else{
- echo json_encode(array("RESULT" => "NO", "Message" => "Sorry, No Data!."));exit();
- }
- }
- /* End Function For menu_content*/
- /* Start Function For invitaion_code */
- function invitaion_code(){
- if($_POST){
- //// Start Check fields validation
- $this->form_validation->set_rules('user_id', 'User id', 'required');
- $this->form_validation->set_rules('invite_wallet_id', 'Invite wallet id', 'required');
- $this->form_validation->set_error_delimiters('', ''); //Changing error delimiter to empty
- //// End Check fields validation
- if($this->form_validation->run()) {
- $checkData = array();
- /* Post values */
- $checkData['usr.id'] = $this->input->post('user_id');
- $tableName ="users AS usr";
- $fieldName = array('usr.*');
- $rowData = $this->api_model->selectData($tableName, $fieldName, $checkData);
- $checkData2['usr.wallet_id'] = $this->input->post('invite_wallet_id');
- $tableName2 ="users AS usr";
- $fieldName2 = array('usr.*');
- $rowData2 = $this->api_model->selectData($tableName2, $fieldName2, $checkData2);
- if($rowData->num_rows() > 0 && $rowData2->num_rows() > 0){
- $userData = $rowData->row_array();
- $fuserData = $rowData2->row_array();
- if($userData['is_usecode'] == 'N'){
- /// Get Reward points details
- $checkEarnData['earn.id'] = '1';
- $tableEarnName ="earn_points AS earn";
- $fieldEarnName = array('earn.*');
- $rowEarnData = $this->api_model->selectData($tableEarnName, $fieldEarnName, $checkEarnData);
- $earnData = $rowEarnData->row_array();
- //update user points who use invation code
- $udateUserData = $this->db->query("UPDATE users set points = points + '".$earnData['invite_user_reward']."' , parent_id = '".$fuserData['id']."' , is_usecode = 'Y' WHERE id ='".$this->input->post('user_id')."'");
- //update user friends points who send invation code
- $udateFriendData = $this->db->query("UPDATE users set points = points + '".$earnData['invite_friend_reward']."' WHERE wallet_id ='".$this->input->post('invite_wallet_id')."'");
- $checkData = array();
- /* Post values */
- $checkData['usr.id'] = $this->input->post('user_id');
- $tableName ="users AS usr";
- $fieldName = array('usr.rewards_checkin AS rewards_checkin , usr.points AS user_points');
- $rowData = $this->api_model->selectData($tableName, $fieldName, $checkData);
- $userData = $rowData->row_array();
- echo json_encode(array("RESULT" => "YES", "Message" => "Successfully Use Invitaion code ", "Data" => $userData));
- }
- else{
- echo json_encode(array("RESULT" => "NO", "Message" => "Sorry, Unable to Use Invitaion code!"));exit();
- }
- }
- else{
- echo json_encode(array("RESULT" => "NO", "Message" => "Sorry, Unable to Use Invitaion code!"));exit();
- }
- }else{
- $this->load->view('api/noresult'); //load noresult and error view
- exit();
- }}
- else{
- //$this->load->view('api/invitaion_code');// load default testing view
- }
- }
- /* End Function For invitaion_code */
- /* Start Function For credit apk */
- function super_rewards(){
- if($_REQUEST){
- $SECRET_KEY = "36f0b3b4cd28302a41ecb52a7f08dc3d"; // secret for my app
- $transaction_id = $_REQUEST['id'];
- $walletId = $_REQUEST['uid'];
- $offer_id = $_REQUEST['oid']; // completed offer or payment method
- $points = $_REQUEST['new'];
- $hash_signature = $_REQUEST['sig'];
- $hash = md5($transaction_id.':'.$points.':'.$walletId.':'.$SECRET_KEY);
- if ($hash != $hash_signature) {
- // signature doesn't match, respond with a failure
- /*$to = "mca.abhinav.saxena@gmail.com";
- $subject = "Testing Email ";
- $msg = "Info Mail User Failure";
- $headers = "From: Test info@archiveinfotechdevelopers.com" . "\r\n";
- $headers .= "MIME-Version: 1.0" . "\r\n";
- $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
- mail($to,$subject,$msg,$headers);*/
- echo "0\n";
- exit;
- }
- //update user friends points who send invation code
- $udatepoints = $this->db->query("UPDATE users set points = points + '".$points."' WHERE wallet_id ='".$walletId."'");
- $credits = $this->db->query("INSERT INTO offers_credits set credits = '".$points."' , sdk_name = 'Super Rewards' , user_wallet = '".$walletId."' , created = now()");
- //GET user Details
- $checkData['usr.wallet_id'] = $walletId;
- $tableName ="users AS usr";
- $fieldName = array('usr.gcm_id AS registatoin_ids' ,'points');
- $rowData = $this->api_model->selectData($tableName, $fieldName, $checkData);
- $userData = $rowData->row_array();
- $registatoin_ids = $userData['registatoin_ids'];
- $earn = $userData['points'];
- //$message = array("message" => 'Congrats!!! You got '.$points.' points.');
- $message = array("message" => 'Congrats!!! You got '.$points.' credits from super rewards.' , 'type' => 'confirm' , 'userpoints' =>$earn);
- $this->send_notification($registatoin_ids, $message); // sending push notification
- // all good!
- //log("User $user_id purchased $new_currency coins using $offer_id (txn: $transaction_id)\n");
- $to = "mca.abhinav.saxena@gmail.com";
- $subject = "Testing Email ";
- $msg = "Info Mail User Id".$walletId."=======REwards".$points."";
- $headers = "From: Test info@archiveinfotechdevelopers.com" . "\r\n";
- $headers .= "MIME-Version: 1.0" . "/r/n";
- $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
- //mail($to,$subject,$msg,$headers);
- echo "1";
- }
- }
- function adscend_media(){
- if($_REQUEST){
- $transaction_id = $_REQUEST['offerid'];
- $walletId = $_REQUEST['sub1'];
- $points = $_REQUEST['rate']; // completed offer or payment method
- //update user friends points who send invation code
- $udatepoints = $this->db->query("UPDATE users set points = points + '".$points."' WHERE wallet_id ='".$walletId."'");
- $credits = $this->db->query("INSERT INTO offers_credits set credits = '".$points."' , sdk_name = 'AdscendMedia' , user_wallet = '".$walletId."' , created = now()");
- //GET user Details
- $checkData['usr.wallet_id'] = $walletId;
- $tableName ="users AS usr";
- $fieldName = array('usr.gcm_id AS registatoin_ids' ,'points');
- $rowData = $this->api_model->selectData($tableName, $fieldName, $checkData);
- $userData = $rowData->row_array();
- $registatoin_ids = $userData['registatoin_ids'];
- $earn = $userData['points'];
- //$message = array("message" => 'Congrats!!! You got '.$points.' points.');
- $message = array("message" => 'Congrats!!! You got '.$points.' credits from adscend media.' , 'type' => 'confirm' , 'userpoints' =>$earn);
- $this->send_notification($registatoin_ids, $message); // sending push notification
- $to = "mca.abhinav.saxena@gmail.com";
- $subject = "Testing Email ";
- $msg = "Info Mail User Id".$walletId."=======REwards".$points."";
- $headers = "From: Test info@archiveinfotechdevelopers.com" . "\r\n";
- $headers .= "MIME-Version: 1.0" . "\r\n";
- $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
- //mail($to,$subject,$msg,$headers);
- echo "1";
- }
- }
- function adxmi(){
- if($_GET){
- $transaction_id = $_REQUEST['order'];
- $walletId = $_REQUEST['user'];
- $points = $_REQUEST['points']; // completed offer or payment method
- //update user friends points who send invation code
- $udatepoints = $this->db->query("UPDATE users set points = points + '".$points."' WHERE wallet_id ='".$walletId."'");
- $credits = $this->db->query("INSERT INTO offers_credits set credits = '".$points."' , sdk_name = 'ADXMI' , user_wallet = '".$walletId."' , created = now()");
- //GET user Details
- $checkData['usr.wallet_id'] = $walletId;
- $tableName ="users AS usr";
- $fieldName = array('usr.gcm_id AS registatoin_ids' ,'points');
- $rowData = $this->api_model->selectData($tableName, $fieldName, $checkData);
- $userData = $rowData->row_array();
- $registatoin_ids = $userData['registatoin_ids'];
- $earn = $userData['points'];
- //$message = array("message" => 'Congrats!!! You got '.$points.' points.');
- $message = array("message" => 'Congratulations! You got '.$points.' credits from ADXMI.' , 'type' => 'confirm' , 'userpoints' =>$earn);
- $this->send_notification($registatoin_ids, $message); // sending push notification
- $to = "mca.abhinav.saxena@gmail.com";
- $subject = "Testing Email ";
- $msg = "Info Mail User Id".$walletId."=======REwards".$points."";
- $headers = "From: Test info@archiveinfotechdevelopers.com" . "\r\n";
- $headers .= "MIME-Version: 1.0" . "\r\n";
- $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
- //mail($to,$subject,$msg,$headers);
- echo "1";
- }
- }
- function cpa_lead(){
- if($_REQUEST){
- /*
- * Postback Example Script. This script is meant to only be a rough outline of
- * how a postback should operate, and not necessarily used out of the box.
- *
- * Copyright 2015. CPAlead, LLC. All Rights Reserved
- */
- // Define your password, set to blank "" for no password. (optional).
- $your_postback_password = "";
- // Setup postback variables. For a complete list of variables visit https://cpalead.com/documentation/postback/index.php
- $password = $_REQUEST['password'];
- $walletId = $_REQUEST['subid'];
- $campaign_name = $_REQUEST['campaign_name'];
- $payout = $_REQUEST['payout'];
- $points = $_REQUEST['virtual_currency'];
- // If (optional) password is set, deny access.
- if (!empty($your_postback_password) && isset($password) && !empty($password) && ($your_postback_password != $password))
- {
- // exit;
- }
- //update user friends points who send invation code
- $udatepoints = $this->db->query("UPDATE users set points = points + '".$points."' WHERE wallet_id ='".$walletId."'");
- $credits = $this->db->query("INSERT INTO offers_credits set credits = '".$points."' , sdk_name = 'CPALead' , user_wallet = '".$walletId."' , created = now()");
- //GET user Details
- $checkData['usr.wallet_id'] = $walletId;
- $tableName ="users AS usr";
- $fieldName = array('usr.gcm_id AS registatoin_ids' ,'points');
- $rowData = $this->api_model->selectData($tableName, $fieldName, $checkData);
- $userData = $rowData->row_array();
- $registatoin_ids = $userData['registatoin_ids'];
- $earn = $userData['points'];
- //$message = array("message" => 'Congrats!!! You got '.$points.' points.');
- $message = array("message" => 'Congrats!!! You got '.$points.' credits from cpa lead.' , 'type' => 'confirm' , 'userpoints' =>$earn);
- $this->send_notification($registatoin_ids, $message); // sending push notification
- $to = "mca.abhinav.saxena@gmail.com";
- $subject = "Testing Email ";
- $msg = "Info Mail User Id".$walletId."=======REwards".$points."";
- $headers = "From: Test info@archiveinfotechdevelopers.com" . "\r\n";
- $headers .= "MIME-Version: 1.0" . "/r/n";
- $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
- //mail($to,$subject,$msg,$headers);
- echo "success";
- }
- }
- function personaly(){
- if($_REQUEST){
- $secret_key = '1819ba4924947870f0666e3bd15c466c';
- $app_hash = '84bd29a809d93f7d2f4e0e1a01a6517b';
- // Get params
- $walletId = $_REQUEST['user_id'];
- $points = $_REQUEST['amount'];
- $offer_id = $_REQUEST['offer_id'];
- $app_id = $_REQUEST['app_id'];
- $signature = $_REQUEST['signature'];
- $offer_name = $_REQUEST['offer_name'];
- // Create validation signature
- $validation_signature = md5($walletId . ':' . $app_hash . ':' . $secret_key); // the app_hash can be found in your app settings
- if ($signature != $validation_signature) {
- // Signatures not equal - send error code
- echo 0;
- //die();
- }
- //update user friends points who send invation code
- $udatepoints = $this->db->query("UPDATE users set points = points + '".$points."' WHERE wallet_id ='".$walletId."'");
- $credits = $this->db->query("INSERT INTO offers_credits set credits = '".$points."' , sdk_name = 'Persona.ly' , user_wallet = '".$walletId."' , created = now()");
- //GET user Details
- $checkData['usr.wallet_id'] = $walletId;
- $tableName ="users AS usr";
- $fieldName = array('usr.gcm_id AS registatoin_ids' ,'points');
- $rowData = $this->api_model->selectData($tableName, $fieldName, $checkData);
- $userData = $rowData->row_array();
- $registatoin_ids = $userData['registatoin_ids'];
- // $message = array("message" => 'Congrats!!! You got '.$points.' points.');
- $earn = $userData['points'];
- //$message = array("message" => 'Congrats!!! You got '.$points.' points.');
- $message = array("message" => 'Congrats!!! You got '.$points.' credits from personaly.' , 'type' => 'confirm' , 'userpoints' =>$earn);
- $this->send_notification($registatoin_ids, $message); // sending push notification
- // Validation was successful. Credit user process.
- $to = "mca.abhinav.saxena@gmail.com";
- $subject = "Testing Email ";
- $msg = "Info Mail User Id".$walletId."=======REwards".$points."";
- $headers = "From: Test info@archiveinfotechdevelopers.com" . "\r\n";
- $headers .= "MIME-Version: 1.0" . "\r\n";
- $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
- //mail($to,$subject,$msg,$headers);
- echo 1;
- die();
- }
- }
- function super_sonic(){
- if($_GET){
- // get the variables
- $userId = $_GET['appUserId'];
- $eventId = $_GET['eventId'];
- $rewards = $_GET['rewards'];
- $signature = $_GET['signature'];
- $timestamp = $_GET['timestamp'];
- $privateKey = '9d4a37';
- // validate the call using the signature
- if (md5($timestamp.$eventId.$userId.$rewards.$privateKey) != $signature)
- {
- echo "Signature doesnÕt match parameters";
- return;
- }
- //update user friends points who send invation code
- $udatepoints = $this->db->query("UPDATE users set points = points + '".$rewards."' WHERE wallet_id ='".$userId."'");
- $credits = $this->db->query("INSERT INTO offers_credits set credits = '".$rewards."' , sdk_name = 'Super Sonic' , user_wallet = '".$userId."' , created = now()");
- //GET user Details
- $checkData['usr.wallet_id'] = $userId;
- $tableName ="users AS usr";
- $fieldName = array('usr.gcm_id AS registatoin_ids' ,'points');
- $rowData = $this->api_model->selectData($tableName, $fieldName, $checkData);
- $userData = $rowData->row_array();
- $registatoin_ids = $userData['registatoin_ids'];
- $earn = $userData['points'];
- //$message = array("message" => 'Congrats!!! You got '.$points.' points.');
- $message = array("message" => 'Congrats!!! You got '.$rewards.' credits from super sonic.' , 'type' => 'confirm' , 'userpoints' =>$earn);
- //$message = array("message" => 'Congrats!!! You got '.$rewards.' points.');
- $to = "mca.abhinav.saxena@gmail.com";
- $subject = "Testing Email ";
- $msg = "Info Mail User Id".$userId."===Event Id".$eventId."====REwards".$message."";
- $headers = "From: Test info@archiveinfotechdevelopers.com" . "\r\n";
- $headers .= "MIME-Version: 1.0" . "\r\n";
- $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
- //mail($to,$subject,$msg,$headers);
- $this->send_notification($registatoin_ids, $message); // sending push notification
- // check that we haven't processed the same event before
- /*if (!alreadyProcessed($eventId)){
- // grant the rewards
- // doProcessEvent($eventId, $userId, $rewards);
- }*/
- // return ok
- echo $eventId.":OK";
- }
- }
- function trial_rewards(){
- if($_REQUEST){
- // TrialPay provides this signature for the message
- // Note: The actual HTTP header is "TrialPay-HMAC-MD5",
- // but PHP renames all HTTP headers so we end up with:
- $message_signature = $_SERVER['HTTP_TRIALPAY_HMAC_MD5'];
- // Recalculate the signature locally
- $key = '9f93738c9f';
- if ($_SERVER['REQUEST_METHOD'] == 'POST') {
- // the following is for POST notification
- if (empty($HTTP_RAW_POST_DATA)) {
- $recalculated_message_signature = hash_hmac('md5', file_get_contents('php://input'), $key);
- } else {
- $recalculated_message_signature = hash_hmac('md5', $HTTP_RAW_POST_DATA, $key);
- }
- } else {
- // the following is for GET notification
- $recalculated_message_signature = hash_hmac('md5', $_SERVER['QUERY_STRING'], $key);
- }
- if ($message_signature == $recalculated_message_signature) {
- // the message is authentic
- $walletId = $_REQUEST['sid'];
- $points = $_REQUEST['reward_amount'];// Revenue In dollor
- //update user friends points who send invation code
- $udatepoints = $this->db->query("UPDATE users set points = points + '".$points."' WHERE wallet_id ='".$walletId."'");
- $credits = $this->db->query("INSERT INTO offers_credits set credits = '".$points."' , sdk_name = 'Trial Pay' , user_wallet = '".$walletId."' , created = now()");
- //GET user Details
- $checkData['usr.wallet_id'] = $walletId;
- $tableName ="users AS usr";
- $fieldName = array('usr.gcm_id AS registatoin_ids' ,'points');
- $rowData = $this->api_model->selectData($tableName, $fieldName, $checkData);
- $userData = $rowData->row_array();
- $registatoin_ids = $userData['registatoin_ids'];
- $message = array("message" => 'Congrats!!! You got '.$points.' points.');
- $earn = $userData['points'];
- //$message = array("message" => 'Congrats!!! You got '.$points.' points.');
- $message = array("message" => 'Congrats!!! You got '.$points.' credits from Trialpay.' , 'type' => 'confirm' , 'userpoints' =>$earn);
- $this->send_notification($registatoin_ids, $message); // sending push notification
- $to = "mca.abhinav.saxena@gmail.com";
- $subject = "Testing Email ";
- $msg = "Info Mail User Id".$walletId."=======REwards".$points."";
- $headers = "From: Test info@archiveinfotechdevelopers.com" . "\r\n";
- $headers .= "MIME-Version: 1.0" . "\r\n";
- $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
- // mail($to,$subject,$msg,$headers);
- http_response_code(200);
- echo "1";
- } else {
- // the message is not authentic
- http_response_code(400);
- echo "Duplicate Transaction";
- }
- }
- }
- function test(){
- $url = 'http://sensiblewallet.com/sensible_wallet/admin/index.php/api_new/test1';
- //print_r(get_headers($url));
- //print_r(get_headers($url, 1));
- $homepage = file_get_contents($url);
- //echo $homepage;
- $message_signature = $_SERVER['HTTP_TRIALPAY_HMAC_MD5'];
- echo $message_signature;}
- function test1(){
- http_response_code(200);
- echo "2";
- //http_response_code(400);
- }
- function adgate_media(){
- // Validation was successful. Credit user process.
- $to = "mca.abhinav.saxena@gmail.com";
- $subject = "Testing Email ";
- $msg = "Info Mail adgatemedia";
- $headers = "From: Test info@archiveinfotechdevelopers.com" . "\r\n";
- $headers .= "MIME-Version: 1.0" . "/r/n";
- $headers .= "Content-type:text/html;charset=UTF-8" . "/r/n";
- //mail($to,$subject,$msg,$headers);
- echo 1;
- //die;
- if($_REQUEST){
- // Get params
- $walletId = $_REQUEST['aff_sub'];
- $points = $_REQUEST['points'];
- //update user friends points who send invation code
- $udatepoints = $this->db->query("UPDATE users set points = points + '".$points."' WHERE wallet_id ='".$walletId."'");
- $credits = $this->db->query("INSERT INTO offers_credits set credits = '".$points."' , sdk_name = 'AdgateMedia' , user_wallet = '".$walletId."' , created = now()");
- //GET user Details
- $checkData['usr.wallet_id'] = $walletId;
- $tableName ="users AS usr";
- $fieldName = array('usr.gcm_id AS registatoin_ids' ,'points');
- $rowData = $this->api_model->selectData($tableName, $fieldName, $checkData);
- $userData = $rowData->row_array();
- $registatoin_ids = $userData['registatoin_ids'];
- // $message = array("message" => 'Congrats!!! You got '.$points.' points.');
- $earn = $userData['points'];
- //$message = array("message" => 'Congrats!!! You got '.$points.' points.');
- $message = array("message" => 'Congrats!!! You got '.$points.' credits from adgate media.' , 'type' => 'confirm' , 'userpoints' =>$earn);
- $this->send_notification($registatoin_ids, $message); // sending push notification
- // Validation was successful. Credit user process.
- $to = "mca.abhinav.saxena@gmail.com";
- $subject = "Testing Email ";
- $msg = "Info Mail User Id".$walletId."=======REwards".$points."";
- $headers = "From: Test info@archiveinfotechdevelopers.com" . "\r\n";
- $headers .= "MIME-Version: 1.0" . "\r\n";
- $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
- //mail($to,$subject,$msg,$headers);
- echo 1;
- die();
- }
- }
- function tapjoy(){
- if($_REQUEST){
- // Get params
- $walletId = $_REQUEST['snuid'];
- $points = $_REQUEST['currency'];
- //update user friends points who send invation code
- $udatepoints = $this->db->query("UPDATE users set points = points + '".$points."' WHERE wallet_id ='".$walletId."'");
- $credits = $this->db->query("INSERT INTO offers_credits set credits = '".$points."' , sdk_name = 'TapJoy' , user_wallet = '".$walletId."' , created = now()");
- //GET user Details
- $checkData['usr.wallet_id'] = $walletId;
- $tableName ="users AS usr";
- $fieldName = array('usr.gcm_id AS registatoin_ids' ,'points');
- $rowData = $this->api_model->selectData($tableName, $fieldName, $checkData);
- $userData = $rowData->row_array();
- $registatoin_ids = $userData['registatoin_ids'];
- // $message = array("message" => 'Congrats!!! You got '.$points.' points.');
- $earn = $userData['points'];
- //$message = array("message" => 'Congrats!!! You got '.$points.' points.');
- $message = array("message" => 'Congrats!!! You got '.$points.' credits from Tapjoy.' , 'type' => 'confirm' , 'userpoints' =>$earn);
- $this->send_notification($registatoin_ids, $message); // sending push notification
- // Validation was successful. Credit user process.
- $to = "mca.abhinav.saxena@gmail.com";
- $subject = "Testing Email ";
- $msg = "Info Mail User Id".$walletId."=======REwards".$points."";
- $headers = "From: Test info@archiveinfotechdevelopers.com" . "\r\n";
- $headers .= "MIME-Version: 1.0" . "\r\n";
- $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
- //mail($to,$subject,$msg,$headers);
- echo 1;
- die();
- }
- }
- /* End Function For credit apk */
- /* Start Function For redeem */
- function redeem(){
- if($_POST){
- //// Start Check fields validation
- $this->form_validation->set_rules('user_id', 'User Id', 'trim|required');
- $this->form_validation->set_rules('first_name', 'First Name', 'trim|required');
- $this->form_validation->set_rules('last_name', 'Last Name', 'trim|required');
- $this->form_validation->set_rules('offer_id', 'Offer id', 'trim|required');
- $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
- $this->form_validation->set_error_delimiters('', ''); //Changing error delimiter to empty
- //// End Check fields validation
- if($this->form_validation->run()) {
- $insertdata = array();
- $insertdata['user_id'] = $this->input->post('user_id');
- $insertdata['first_name'] = $this->input->post('first_name');
- $insertdata['last_name'] = $this->input->post('last_name');
- $insertdata['offer_id'] = $this->input->post('offer_id');
- $insertdata['email'] = $this->input->post('email');
- $insertdata['created'] = date('Y-m-d H:i:s');
- ///check points of user
- $offerQuery2 = $this->db->query("SELECT price AS offer_price FROM offers WHERE id = '".$this->input->post('offer_id')."'");
- $offerData2 = $offerQuery2->row_array();
- $offer_price2 = $offerData2['offer_price'];
- $checkpoints = $this->db->query("SELECT points AS offer_points FROM users WHERE id ='".$this->input->post('user_id')."'");
- $checkpointsData = $checkpoints->row_array();
- $chkpoints = $checkpointsData['offer_points'];
- if($offer_price2 > $chkpoints){echo json_encode(array("RESULT" => "NO", "Message" => "Try Again")); exit;}
- //// insert user register data
- $id = $this->api_model->insertData("redeem_offers", $insertdata);
- if($id){
- $offerQuery = $this->db->query("SELECT price AS offer_price FROM offers WHERE id = '".$this->input->post('offer_id')."'");
- $offerData = $offerQuery->row_array();
- $offer_price = $offerData['offer_price'];
- $udatepoints = $this->db->query("UPDATE users set points = points - '".$offer_price."' WHERE id ='".$this->input->post('user_id')."'");
- //updated points
- $userQuery = $this->db->query("SELECT points FROM users WHERE id = '".$this->input->post('user_id')."'");
- $userData = $userQuery ->row_array();
- $points_user = $userData['points'];
- $points['user_points'] = $points_user;
- $points['charged_offer_points'] = $offer_price;
- $query = $this->db->query("SELECT t1.*,t3.title , t3.price AS offer_price ,t4.title AS gift_title , t5.name AS country_name , t5.price_sign FROM redeem_offers t1 LEFT JOIN users t2 ON t1.user_id = t2.id LEFT JOIN offers t3 ON t1.offer_id = t3.id LEFT JOIN gifts_card t4 ON t3.giftcard_id = t4.id LEFT JOIN country t5 ON t4.country_id = t5.id WHERE t1.id = '".$id."' ");
- $redeemData = $query->row_array();
- $this->sendredeemmail($redeemData);
- echo json_encode(array("RESULT" => "YES", "Message" => "Success", "Data" => $points));
- }else{
- echo json_encode(array("RESULT" => "NO", "Message" => "Try Again"));
- }
- exit();
- }else{
- $this->load->view('api/noresult'); //load noresult and error view
- exit();
- }
- }else{
- //$this->load->view('api/redeem'); // load default testing view
- }
- }
- /* End Function For redeem */
- /**
- * This function is to send varification mail
- */
- function sendmail($userData)
- {
- // send mail
- $to = $userData['email'];
- $to_name = $userData['first_name'].' '.$userData['last_name'];
- $from = 'support@sensiblewallet.com';
- $from_name = 'Sensible Wallet Support Team';
- $subject = "Regarding Activation on Sensible Wallet App";
- $message = "Hello,<br><br>
- Welcome to Sensible Wallet! <br><br>
- You are almost Ready to Start Recharging Your Wallet!<br><br>
- You, or someone using your email address, has completed registration at Wallet.<br><br>
- You can complete registration by clicking the following link:<br><br>";
- $message .='<a href="'."http://".$_SERVER['HTTP_HOST'].base_url().'users/activation/'.$userData['activation_code'].'">Click here</a><br><br><br><br>Best Regards,<br/>
- Sensible Wallet Support Team';
- $this->email->clear();
- $this->email->from($from, $from_name);
- $this->email->to($to,$to_name);
- $this->email->reply_to('no@noreply.com','noreplay');
- $this->email->subject($subject);
- $this->email->message($message);
- $this->email->set_mailtype('html');
- $this->email->send();
- return true;
- }
- function updatePoints(){
- if($_POST){
- $this->form_validation->set_rules('wallet_id', 'Wallet id', 'required');
- $this->form_validation->set_rules('points', 'Points', 'required');
- $this->form_validation->set_error_delimiters('', '');
- if($this->form_validation->run()) {
- $checkData = array();
- $checkData['wallet_id'] = $this->input->post('wallet_id');
- $tableName ="users AS usr";
- $fieldName = array('usr.*');
- $rowData = $this->api_model->selectData($tableName, $fieldName, $checkData);
- if($rowData->num_rows() > 0){
- $data = $rowData->row_array();
- $insertData['points'] = $this->input->post('points') + $data['points'] ;
- $whereData['wallet_id'] = $this->input->post('wallet_id');
- $this->api_model->updateData("users",$insertData , $whereData );
- //GET user Details
- $checkData2['usr.wallet_id'] = $this->input->post('wallet_id');
- $tableName2 ="users AS usr";
- $fieldName2 = array('usr.gcm_id AS registatoin_ids' ,'usr.points');
- $rowData2 = $this->api_model->selectData($tableName2, $fieldName2, $checkData2);
- $userData2 = $rowData2->row_array();
- $registatoin_ids = $userData2['registatoin_ids'];
- $earn = $userData2['points'];
- $credits = $this->db->query("INSERT INTO offers_credits set credits = '".$this->input->post('points')."' , sdk_name = '".$this->input->post('sdkName')."', user_wallet = '".$this->input->post('wallet_id')."' , created = now()");
- $message = array("message" => 'Congrats!!! You got '.$this->input->post('points').' credits from '.$this->input->post('sdkName').'.' , 'type' => 'points' , 'userpoints' =>$earn);
- $this->send_notification($registatoin_ids, $message); // sending push notification
- $points['user_points'] = $insertData['points'];
- echo json_encode(array("RESULT" => "YES", "Message" => "Credits updated successfully!", "Data" => $points));
- }else{
- echo json_encode(array("RESULT" => "NO", "Message" => "Oops! Invalid wallet id"));exit();
- }
- }else{
- $this->load->view('api/noresult'); //load noresult and error view
- exit();
- }
- }else{
- //$this->load->view('api/updatePoints');// load default testing view
- }
- }
- /* End Function for updatePoints */
- function sendmailForgotPassword($userData,$password)
- {
- // send mail
- $to = $userData['email'];
- $to_name = $userData['first_name'].' '.$userData['last_name'];
- $from = 'support@sensiblewallet.com';
- $from_name = 'Wallet Support Team';
- $subject = "Forgot Password on Wallet App";
- $message = "Your password is ".$password ."<br/>";
- $message .='Best Regards,<br/>
- Wallet Support Team';
- $this->email->clear();
- $this->email->from($from, $from_name);
- $this->email->to($to,$to_name);
- $this->email->reply_to('no@noreply.com','noreplay');
- $this->email->subject($subject);
- $this->email->message($message);
- $this->email->set_mailtype('html');
- $this->email->send();
- return true;
- }
- /**
- * Sending Push Notification
- */
- function send_notification($registatoin_ids, $message) {
- // Set POST variables
- $url = 'https://android.googleapis.com/gcm/send';
- $fields = array(
- 'registration_ids' => array($registatoin_ids),
- 'data' => $message,
- );
- $headers = array(
- 'Authorization: key=' .$this->config->item('GOOGLE_API_KEY'),
- 'Content-Type: application/json'
- );
- // Open connection
- $ch = curl_init();
- // Set the url, number of POST vars, POST data
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- // Disabling SSL Certificate support temporarly
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
- // Execute post
- $result = curl_exec($ch);
- if ($result === FALSE) {
- die('Curl failed: ' . curl_error($ch));
- }
- // Close connection
- curl_close($ch);
- // echo $result;
- }
- /**
- * Sending Push Notification
- */
- function test_notification($walletId) {
- //GET user Details
- $checkData['usr.wallet_id'] = $walletId;
- $tableName ="users AS usr";
- $fieldName = array('usr.gcm_id AS registatoin_ids');
- $rowData = $this->api_model->selectData($tableName, $fieldName, $checkData);
- $userData = $rowData->row_array();
- // $registatoin_ids = array($gcm_regid);
- // json message
- $arr_message = array('testing notification');
- //$message = array("message" => json_encode($arr_message));
- $message = array("message" => 'Congrats!!! You got 5 points.' , 'type' => 'confirm' , 'userpoints' =>'5');
- $registatoin_ids = $userData['registatoin_ids'];
- // Set POST variables
- $url = 'https://android.googleapis.com/gcm/send';
- $fields = array(
- 'registration_ids' =>array($registatoin_ids),
- 'data' =>$message,
- );
- $headers = array(
- 'Authorization: key=' .$this->config->item('GOOGLE_API_KEY'),
- 'Content-Type: application/json'
- );
- // Open connection
- $ch = curl_init();
- // Set the url, number of POST vars, POST data
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- // Disabling SSL Certificate support temporarly
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
- // Execute post
- $result = curl_exec($ch);
- if ($result === FALSE) {
- die('Curl failed: ' . curl_error($ch));
- }
- // Close connection
- curl_close($ch);
- echo $result;
- }
- /**
- * This function is to send reddem mail
- */
- function sendredeemmail($data)
- {
- // send mail
- $to = 'rewards@sensiblewallet.com';
- $to_name = 'sensiblewallet';
- $from = $data['email'];
- $from_name = $data['first_name'].' '.$data['last_name'];
- $subject = "User is Requesting Award";
- $message = "Hi,<br><br>
- Country : ".$data['country_name']." <br><br>
- GiftCard : ".$data['gift_title']." <br><br>
- UserName : ".$data['first_name'].' '.$data['last_name']." <br><br>
- Email : ".$data['email']." <br><br>
- Offer Redeem Amount : ".$data['price_sign'].' '.$data['title']." <br><br>";
- $message .='<br><br>Best Regards,<br/>
- '.$from_name.'';
- $this->email->clear();
- $this->email->from($from, $from_name);
- $this->email->to($to,$to_name);
- $this->email->reply_to('no@noreply.com','noreplay');
- $this->email->subject($subject);
- $this->email->message($message);
- $this->email->set_mailtype('html');
- $this->email->send();
- return true;
- }
- function arrayresult($value){
- echo "<pre>";
- print_r($value);die;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement