<?php
header('Access-Control-Allow-Origin: *');
header("Content-type: application/json; charset=utf-8");

if (isset($_SERVER['HTTP_ORIGIN'])) {
    // Decide if the origin in $_SERVER['HTTP_ORIGIN'] is one
    // you want to allow, and if so:
    header('Access-Control-Allow-Origin: *');
    header('Access-Control-Allow-Credentials: true');
    header('Access-Control-Max-Age: 1000');
}
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
    if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD'])) {
        // may also be using PUT, PATCH, HEAD etc
        header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE");
    }

    if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'])) {
        header("Access-Control-Allow-Headers: Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization");
    }
    exit(0);
}

// error_reporting(0);

include '../../../utils/database.php';
include '../../../utils/helper.php';

$response1['success'] = 'false';
$response1['message'] = '500';

$isDiscount = true;

$conn = new mysqli($servername, $username, $password, $dbname_process);
// Check connection
mysqli_set_charset($conn, "utf8");
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error); 
}
$conn_mint = new mysqli($servername, $username, $password, $dbname_mint);
// Check connection
mysqli_set_charset($conn_mint, "utf8");
if ($conn_mint->connect_error) {
  die("Connection failed: " . $conn_mint->connect_error); 
}

$token = $_GET["userToken"];
$phone = $_GET["phoneNumber"];
$currentTime = time();

if($conn->query("UPDATE tamdid SET `phone`='$phone' WHERE `tamdidToken`='$token' OR `token`='$token'")){
    if($conn_mint->query("UPDATE transactions SET `phone`='$phone' WHERE `code`='$token'")){
        $response1['success'] = 'true';
        $response1['message'] = '200';
    }
}

$json_response = json_encode($response1);
echo $json_response;
die();