public function registerPushNotif()
 {
     IMBAuth::checkOAuth();
     $app_id = addslashes($_POST['app_id']);
     $app_token = addslashes($_POST['app_token']);
     $app = new AppAccount();
     $app->getByID($app_id);
     if ($app->app_token != $app_token) {
         $json['status_code'] = 0;
         $json['status_message'] = "Token Mismatched";
         echo json_encode($json);
         die;
     }
     $acc_id = addslashes($_POST['acc_id']);
     $now = addslashes($_POST['now']);
     $ios = addslashes($_POST['ios']);
     $_GET['ios'] = $ios;
     $push_title = addslashes($_POST['push_title']);
     $push_msg = addslashes($_POST['push_msg']);
     $push_url = addslashes($_POST['push_url']);
     $push_img = addslashes($_POST['push_img']);
     $push_date = date("Y-m-d", strtotime(addslashes($_POST['push_date'])));
     $push_time = (int) addslashes($_POST['push_time']);
     $img = '';
     if ($push_img != '') {
         $img = Crud::savePic($push_img);
     }
     $push = new PushNotCamp();
     $push->camp_client_id = $app->app_client_id;
     $push->camp_img = $img;
     $push->camp_name = $push_title;
     $push->camp_title = $push_title;
     $push->camp_active = 1;
     $push->camp_start = $push_date;
     $push->camp_hour = $push_time;
     $push->camp_msg = $push_msg;
     $push->camp_url = $push_url;
     $push->camp_create_by = $acc_id;
     $push->camp_app_id = $app->app_id;
     $camp_id = $push->save();
     if ($camp_id) {
         $json['status_code'] = 1;
         if ($now) {
             //langsung do push
             $succ = Pusher::pushbyID($camp_id);
             $json['status_message'] = "Push Notifications Pushed";
             echo json_encode($json);
             die;
         } else {
             $json['status_message'] = "Push Notifications Registration Success";
             echo json_encode($json);
             die;
         }
     } else {
         $json['status_code'] = 0;
         $json['status_message'] = "Push Notifications Registration Failed";
         echo json_encode($json);
         die;
     }
 }
 public static function parseToLLAccount($VRO)
 {
     $ll = new LL_Account();
     $ll->macc_ll_customer_id = (string) $VRO->CustomerBody->CustomerID;
     $ll->macc_id = (string) $VRO->CustomerBody->CustomerID;
     if (!$ll->macc_id) {
         return 0;
     }
     /*
      * cek apa di database sudah ada
      */
     $ll->getByID($ll->macc_id);
     if ($ll->macc_id != "" || $ll->macc_id != 0) {
         $ll->load = 0;
     }
     /*
      * cek if ada fb_id atau foto
      */
     $macc_foto = addslashes($_POST['macc_foto']);
     $macc_fb_id = addslashes($_POST['macc_fb_id']);
     if ($macc_foto != "") {
         $ll->macc_foto = Crud::savePic($macc_foto);
     }
     if ($macc_fb_id != "") {
         $ll->macc_fb_id = $macc_fb_id;
     }
     //insert name
     $arrName = $VRO->CustomerBody->EntityInformation->Individual->Name;
     foreach ($arrName->Name as $obj) {
         $var = self::xml_attribute($obj, 'TypeCode');
         //pr($obj);
         //echo "var : ".$var;
         if ($var == "FamilyName") {
             $ll->macc_last_name = (string) $obj;
         }
         if ($var == "GivenName") {
             $ll->macc_first_name = (string) $obj;
         }
         if ($var == "PreferredName") {
             $ll->macc_prefered_name = (string) $obj;
         }
     }
     if ($_GET['test']) {
         echo "names : ";
         pr($ll);
     }
     //insert dob
     $arrTelp = $VRO->CustomerBody->EntityInformation->Individual->ContactInformation->Telephone;
     foreach ($arrTelp as $obj) {
         $var = self::xml_attribute($obj, 'TypeCode');
         if ($var == "Home") {
             $ll->macc_phone_home = (string) $obj->LocalNumber;
         }
         if ($var == "Mobile") {
             $ll->macc_phone = (string) $obj->LocalNumber;
         }
         if ($var == "Work") {
             $ll->macc_phone_work = (string) $obj->LocalNumber;
         }
     }
     if ($_GET['test']) {
         echo "telp : ";
         pr($ll);
     }
     //Address
     $arrAddress = $VRO->CustomerBody->EntityInformation->Individual->ContactInformation->Address;
     $ll->macc_address = (string) $arrAddress->AddressLine;
     $ll->macc_address_city = (string) $arrAddress->City;
     $ll->macc_address_territory = (string) $arrAddress->Territory;
     $ll->macc_address_postalcode = (string) $arrAddress->PostalCode;
     $ll->macc_address_country = (string) $arrAddress->Country;
     //email
     $arrEmail = $VRO->CustomerBody->EntityInformation->Individual->ContactInformation->EMail;
     foreach ($arrEmail as $obj) {
         $var = self::xml_attribute($obj, 'TypeCode');
         if ($var == "Home") {
             $ll->macc_email = (string) $obj->EMailAddress;
         }
     }
     if ($_GET['test']) {
         echo "email : ";
         pr($ll);
     }
     //PersonalSummary
     $personalSum = $VRO->CustomerBody->EntityInformation->Individual->PersonalSummary;
     foreach ($personalSum->attributes() as $a => $b) {
         //echo $a,'="',$b,"\"";
         //echo "IN $a $b";
         //echo "haloo ".$arrName->Name[$b];
         if ($a == "GenderType") {
             $ll->macc_gender = (string) $b;
         }
     }
     if ($_GET['test']) {
         echo "gender : ";
         pr($ll);
     }
     //insert dob
     $dob = (string) $VRO->CustomerBody->EntityInformation->Individual->PersonalSummary->BirthDate;
     $exp = explode("+", $dob);
     $ll->macc_dob = date("Y-m-d", strtotime($exp[0]));
     $ll->macc_card_nr = (string) $VRO->CustomerBody->EntityInformation->Individual->PersonalSummary->LoyaltyTokenID;
     $ll->macc_card_barcode = (string) $VRO->CustomerBody->EntityInformation->Individual->PersonalSummary->LoyaltyTokenBarcode;
     $ll->macc_member_type = (string) $VRO->CustomerBody->EntityInformation->Individual->PersonalSummary->MemberType;
     $ll->macc_member_tier = (string) $VRO->CustomerBody->EntityInformation->Individual->PersonalSummary->MemberTier;
     //real tier n type
     $ll->macc_real_member_type = (string) $VRO->CustomerBody->EntityInformation->Individual->PersonalSummary->MemberType;
     $ll->macc_real_tier = (string) $VRO->CustomerBody->EntityInformation->Individual->PersonalSummary->MemberTier;
     $tkdate = (string) $VRO->CustomerBody->EntityInformation->Individual->PersonalSummary->TokenIssueDate;
     $ll->macc_token_issue_date = date("Y-m-d h:i:s", strtotime($tkdate));
     $ll->macc_token_status = (string) $VRO->CustomerBody->EntityInformation->Individual->PersonalSummary->TokenStatus;
     if ($_GET['test']) {
         echo "members : ";
         pr($ll);
     }
     $ll->macc_member_mismatch = 0;
     //mismatch calculator
     if ($ll->macc_real_member_type == "STC" && $ll->macc_real_tier != "Stamp Card Member") {
         $ll->macc_member_mismatch = 1;
     }
     if ($ll->macc_real_member_type == "133") {
         if ($ll->macc_real_tier != "Fan" && $ll->macc_real_tier != "LYB Member") {
             $ll->macc_member_mismatch = 1;
         }
     }
     if ($ll->macc_real_member_type == "LYB") {
         if ($ll->macc_real_tier != "Fan" && $ll->macc_real_tier != "LYB Member") {
             $ll->macc_member_mismatch = 1;
         }
     }
     //converter member type Stamp card
     if ($ll->macc_member_tier == "Fan" || $ll->macc_member_tier == "LYB Member") {
         $ll->macc_member_type == "LYB";
     }
     //        if($ll->macc_member_tier == "Stamp Card Member") {
     //            $ll->macc_member_type == "STC";
     //        }
     //converter member type Stamp card
     if ($ll->macc_member_type == "STC") {
         //            $ll->macc_member_type = "STC";
         $ll->macc_member_tier = "Stamp Card Member";
     }
     //points
     $arrPoints = $VRO->CustomerBody->CustomerAccount->LoyaltyAccount->Points;
     //pr($arrPoints);
     $sem = array();
     $pointsDetails = array();
     foreach ($arrPoints as $obj) {
         $var = self::xml_attribute($obj, 'Type');
         $sem[$var] = (string) $obj;
         foreach ($obj->attributes() as $a => $b) {
             $pointsDetails[$var][$a] = (string) $b;
         }
     }
     if ($_GET['test']) {
         echo "points : ";
         pr($ll);
     }
     //sementara pakai balance
     $ll->macc_points = $sem['Balance'];
     //sementara saja
     $ll->macc_point_details = serialize(array("points" => $sem, "details" => $pointsDetails));
     //$this->points_details = $pointsDetails;
     return $ll;
 }
 public static function processAgent($mode = "web")
 {
     $json = array();
     $json['err'] = "";
     $json['bool'] = 0;
     $json['status_code'] = 0;
     $json['status_message'] = "Failed";
     if ($mode == "web") {
         $rand = $_SESSION['rand'];
         $token = $_POST['token'];
         if ($rand != $token) {
             $json['err'] .= "Wrong Token<br>";
         }
     }
     //check username
     $ktp = addslashes($_POST['ktp']);
     if ($ktp == "") {
         $json['err'] .= "Ktp cannot be empty<br>";
     }
     //check username
     $npwp = addslashes($_POST['npwp']);
     //        if($npwp==""){
     //            $json['err'] .= "Npwp cannot be empty<br>";
     //        }
     //check username
     $bank_name = addslashes($_POST['bank_name']);
     if ($bank_name == "") {
         $json['err'] .= "Bank Name cannot be empty<br>";
     }
     //check username
     $account_nr = addslashes($_POST['account_nr']);
     if ($account_nr == "") {
         $json['err'] .= "Bank Name cannot be empty<br>";
     }
     //check username
     $account_name = addslashes($_POST['account_name']);
     if ($account_name == "") {
         $json['err'] .= "Bank Name cannot be empty<br>";
     }
     //check username
     $branch_name = addslashes($_POST['branch_name']);
     if ($branch_name == "") {
         $json['err'] .= "Bank Name cannot be empty<br>";
     }
     if ($mode == "web") {
         //check username
         $tos = addslashes($_POST['tos']);
         if ($tos == "") {
             $json['err'] .= "Please accept Terms of Service<br>";
         }
     }
     if ($json['err'] == "") {
         //process npwp or ktp
         if ($mode == "web") {
             $npwp_dipakai = $npwp;
         } else {
             if ($npwp != "") {
                 $npwp_dipakai = Crud::savePic($npwp);
             }
         }
         if ($mode == "web") {
             $ktp_dipakai = $ktp;
         } else {
             if ($ktp != "") {
                 $ktp_dipakai = Crud::savePic($ktp);
             }
         }
         $acc = new Account();
         $acc->getByID(Account::getMyID());
         $acc->admin_bank = $bank_name;
         $acc->admin_bank_acc = $account_nr;
         $acc->admin_bank_acc_name = $account_name;
         $acc->admin_bank_kcu = $branch_name;
         $acc->admin_ktp = $ktp_dipakai;
         $acc->admin_npwp = $npwp_dipakai;
         $acc->admin_isAgent = -1;
         $succ = $acc->save();
         if ($succ) {
             $_SESSION['account'] = $acc;
         }
         $json['bool'] = $succ;
         if ($succ) {
             $json['status_code'] = 1;
             $json['status_message'] = "Submission Successful, Waiting for Approval";
         }
     }
     //        $json['post'] = $_POST;
     echo json_encode($json);
     die;
 }