<?php

require_once('config.php');

header('Access-Control-Allow-Origin: *');
header('Content-Type: application/json; charset=utf-8');

$license_key = isset($_POST['license']) ? $_POST['license']: '';
$uuid = isset($_POST['uuid']) ? $_POST['uuid']: '';

if($license_key && $uuid){

  $license = $db->query("SELECT * FROM licenses WHERE license_key='$license_key' AND deleted_at IS NULL")->fetch();

  if($license){

    if($license['uuid'] == $uuid){

      $db->exec("UPDATE licenses SET uuid=NULL, os=NULL, model=NULL WHERE id='$license[id]'");

      $response = array(
        "successful" => true,
      );

    } else {
      $response = array("successful" => false, "error_title" => "Hata", "error_message" => "Lisans anahtarı size ait değil.");
    }
  } else {
    $response = array("successful" => false, "error_title" => "Hata", "error_message" => "Lisans anahtarı yanlış. Lütfen kontrol edip tekrar deneyin.");
  }
} else {
  $response = array("successful" => false, "error_title" => "Hata", "error_message" => "Boş alanlar var.");
}

echo json_encode($response, JSON_UNESCAPED_UNICODE);

?>
