Advertisement
akbardwi

Ajax

Jul 6th, 2017
544
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.39 KB | None | 0 0
  1. if ($handler == 'newlicense') {
  2.         if(!$TOTP->validateCode($token))
  3.         {
  4.             $json['status'] = 401;
  5.             $json['message']['header'] = 'Oops!';
  6.             $json['message']['text'] = 'Invalid Token. Refresh the page and try again.';
  7.             $json['message']['type'] = 'error';
  8.             die(json_encode($json));
  9.         }
  10.         $addeddate = strtotime($_REQUEST['addeddate']);
  11.         $productid = $Gauntlet->filter($_REQUEST['productid']);
  12.         $categoryid = $Gauntlet->filter($_REQUEST['categoryid']);
  13.         $status = $Gauntlet->filter($_REQUEST['status']);      
  14.         $serialkey = $Gauntlet->filter($_REQUEST['serialkey']);
  15.         $type = $Gauntlet->filter($_REQUEST['type']);
  16.         if ($type == '' || $serialkey == '' || $addeddate == '' || $status == '') {
  17.             $json['status'] = 500;
  18.             $json['message']['header'] = 'Oops!';
  19.             $json['message']['text'] = 'You need to input all values.';
  20.             $json['message']['type'] = 'error';
  21.             die(json_encode($json));
  22.         }
  23.         $userid = $_SESSION['id'];
  24.         $sql = "SELECT * FROM licenses";
  25.         //die(var_dump($sql));
  26.         $query = $DatabaseHandler->query($sql);
  27.         $data = $query->fetch_array();
  28.         if ($type = $data['type'] && $serialkey = $data['licensekey'] && $productid = $data['productid']) {
  29.             $json['status'] = 300;
  30.             $json['message']['header'] = 'Oops!';
  31.             $json['message']['text'] = 'Data sudah ada.';
  32.             $json['message']['type'] = 'error';
  33.             die(json_encode($json));
  34.         }
  35.  
  36.         $sql = "INSERT INTO `licenses` (`addeddate`, `productid`, `categoryid`, `status`, `licensekey`, `type`, `issued-by`) VALUES ('$addeddate', '$productid', '$categoryid', '$status', '$serialkey', '$type', '$userid');";
  37.         //die(var_dump($sql));
  38.         $query = $DatabaseHandler->query($sql);
  39.         if ($query) {
  40.             $json['status'] = 200;
  41.             $json['message']['header'] = 'Success!';
  42.             $json['message']['text'] = 'License inserted successfully!';
  43.             $json['message']['type'] = 'success';
  44.             die(json_encode($json));
  45.         } else {
  46.             $json['status'] = 500;
  47.             $json['message']['header'] = 'Oops!';
  48.             $json['message']['text'] = 'Error in Database.';
  49.             $json['message']['type'] = 'error';
  50.             die(json_encode($json));
  51.         }
  52.  
  53.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement