<?php

require_once('config.php');
authenticate();


$old_key = $_GET['key'];

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

if($license){
  $key = license_generate();
  $db->exec("UPDATE licenses SET deleted_at=NOW() WHERE license_key='$old_key'");
  $db->exec("INSERT INTO licenses (license_key,venue_id,old_license_key,expires_at) VALUES ('$key', '$license[venue_id]','$license[license_key]','$license[expires_at]')");

  $response = "Yeni Lisans Anahtarı: $key";
} else {
  $response = "Geçersiz lisans anahtarı.";
}


?>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
  </head>
  <body>
    <?php
    include('menu.php');
    ?>
    <?=$response;?>
  </body>
</html>
