Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once 'config-api.php';
- //Get Parameter Data
- $checkindate = str_replace('/', '-', $_GET['cidate']);
- $checkoutdate = str_replace('/', '-', $_GET['codate']);
- $checkin = date('Y-m-d', strtotime($checkindate));
- $checkout = date('Y-m-d', strtotime($checkoutdate));
- $username = $_GET['room'];
- $password = $_GET['pass'];
- $time = $_GET['cotime'];
- $status = $_GET['gtype'];
- $firstname = 'frii';
- $lastname = $_GET['pass'];
- $note = '';
- $datetime = "";
- $fullname = $firstname." ".$lastname;
- $reservation_id = intval(preg_replace('/[^0-9]+/', '', $_GET['resid']), 10);
- //Declare Data Radius
- $username_radius = $customer_sid."@".$username."@".$password;
- /*Customer Checkin Method*/
- if ($_GET['mode'] == 'checkin' && $status == '0') {
- //Check Validation Data
- $query_pms = $db_pms->query("SELECT * FROM pms WHERE username = '".$username."' AND password = '".$password."' AND checkin = '".$checkin."' AND checkout = '".$checkout."' AND groupname = '".$customer_profile."' AND reservation_id='".$reservation_id."'");
- $result_pms = $query_pms->num_rows;
- //Validation True
- if (empty($result_pms)) {
- //Save to table pms
- $insert_pms = $db_pms->query("INSERT INTO pms (username,password,fullname,firstname,lastname,checkin,checkout,note,datetime,groupname,reservation_id) VALUES ('".$username."','".$password."','".$fullname."','".$firstname."','".$lastname."','".$checkin."','".$checkout."','".$note."','".$datetime."','".$customer_profile."','".$reservation_id."')");
- if ($insert_pms) {
- //Check Validation Data
- $query_radius = $db_radius->query("SELECT * FROM radcheck WHERE username='".$username_radius."' AND username_only='".$username."' AND value='".$password."' AND customer='".$customer_sid."' AND reservation_id='".$reservation_id."'");
- $result_radius = $query_radius->num_rows;
- if (empty($result_radius)) {
- //Save to table radcheck
- $insert_radius = $db_radius->query("INSERT INTO radcheck (username,attribute,op,value,username_only,firstname,lastname,type,customer,reservation_id) VALUES ('".$username_radius."','Cleartext-Password',':=','".$password."','".$username."','".$firstname."','".$lastname."','PMS','".$customer_sid."','".$reservation_id."')");
- if ($insert_radius) {
- //Check Validation Data
- $query_radusergroup = $db_radius->query("SELECT * FROM radusergroup WHERE username = '".$username_radius."' AND groupname='".$customer_profile."' AND customer='".$customer_sid."'");
- $result_radusergroup = $query_radusergroup->num_rows;
- if (empty($result_radusergroup)) {
- //Save to rable radusergroup
- $insert_radusergroup = $db_radius->query("INSERT INTO radusergroup(username,groupname,customer,priority) VALUES('".$username_radius."','".$customer_profile."','".$customer_sid."','1')");
- }
- }
- }
- }
- }else{
- echo "Cannot save same customer data .Data is available (Mode Checkin)";
- echo "<br>Mysql Error :<br><b>".mysql_error()."</b>";
- }
- }elseif($_GET['mode'] == 'checkout' && $status == '0'){
- //Get Customer Data
- $query_checkout = $db_pms->query("SELECT * FROM pms WHERE username= '".$username."' AND password='".$password."' AND groupname = '".$customer_profile."' AND reservation_id='".$reservation_id."'");
- $result_checkout = $query_checkout->num_rows;
- if (!empty($result_checkout)) {
- //if data available do delete
- $delete_pms = $db_pms->query("DELETE FROM pms WHERE username= '".$username."' AND password='".$password."' AND groupname = '".$customer_profile."' AND reservation_id='".$reservation_id."'");
- $delete_radius = $db_radius->query("DELETE FROM radcheck WHERE username='".$username_radius."' AND customer='".$customer_sid."' AND type='PMS' AND reservation_id='".$reservation_id."'");
- $delete_radusergroup = $db_radius->query("DELETE FROM radusergroup WHERE username= '".$username_radius."' AND groupname='".$customer_profile."' AND customer='".$customer_sid."'");
- }else{
- echo "Data not available to delete. Customer is already checkout (Mode Checkout)<br>";
- echo mysql_error();
- }
- }elseif($_GET['mode'] == 'update' && $status == '0'){
- $checkroom = $db_pms->query("SELECT username FROM pms WHERE groupname='".$customer_profile."' AND username='".$username."'");
- $count = $checkroom->num_rows;
- if (!empty($count)) {
- echo("Room Not Empty");
- }elseif(empty($count)){
- $query_update_pms = $db_pms->query("UPDATE pms SET username='".$username."',password='".$password."',checkin='".$checkin."',checkout='".$checkout."' WHERE groupname = '".$customer_profile."' AND reservation_id='".$reservation_id."'");
- if ($query_update_pms) {
- $query_update_radius = $db_radius->query("UPDATE radcheck SET username='".$username_radius."', username_only='".$username."',value='".$password."' WHERE customer='".$customer_sid."' AND reservation_id='".$reservation_id."'");
- $query_update_radusergroup = $db_radius->query("UPDATE radusergroup SET username='".$username_radius."' WHERE customer='".$customer_sid."'");
- }else{
- echo "Data cannot save to table PMS";
- echo "<br>Mysql Error : <br><b>".mysql_error()."</b>";
- }
- }
- }else{
- echo "Data cannot process , please check your parameter (Mode Update)";
- echo "<br>Mysql Error : <br><b>".mysql_error()."</b>";
- }
- $db_radius->close();
- $db_pms->close();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement