<?php
include 'conn.php';
//Select data from database

include 'funciones.php';

session_start();
$_SESSION['database'] = $_GET['database'];
$_SESSION['numero'] = $_GET['numero'];
$_SESSION['monto'] = $_GET['monto'];
$_SESSION['nombre'] = $_GET['nombre'];
$_SESSION['ruc'] = $_GET['ruc'];
$_SESSION['gift_monto'] = "";
$_SESSION['gift_number'] = "";

$hoynow = getdate();

if ($_SESSION['monto'] == "") {
    $_SESSION['monto'] = "0";

}

$timeStamp = $hoynow["year"] . "-" . $hoynow["mon"] . "-" . $hoynow["mday"];

logs($timeStamp);

$montoesql = "select gift_certificate.gift_number FROM " . $_SESSION['database'] . ".gift_certificate where gift_certificate.gift_number='" . $_SESSION['numero'] . "' ";

logs($montoesql);

$qur = $connection->query($montoesql);

while ($r = mysqli_fetch_assoc($qur)) {

    $_SESSION['gift_number'] = $r['gift_number'];
}

if ($_SESSION['gift_number'] == "") {
    echo "NE";

} else {

    $SQLupdate = "update " . $_SESSION['database'] . ".gift_certificate set gift_fechae='" . $timeStamp . "',gift_monto=" . $_SESSION['monto'] . ",a_nombre='" . $_SESSION['nombre'] . "',a_nip='" . $_SESSION['ruc'] . "' where gift_certificate.gift_number='" . $_SESSION['numero'] . "' limit 1 ";

    logs($SQLupdate);

    if ($connection->query($SQLupdate) === true) {
        echo "true";
    } else {
        echo "false";
    }

}

@mysqli_close($connection);
?>