<?php
/*SE HEREDA DE apt_get_files_fullv3.php 2023-07-13*/
include_once("utiles.php");

date_default_timezone_set("America/Panama");
error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);

if (!$connection = connectDb()) {
    die("err db");
} else {
    $connection->query("SET NAMES 'utf8';");
}
session_start();

$_SESSION['database'] = $_GET['database'];
$_SESSION['op_id']    = $_GET['op_id'];
$_SESSION['op_fecha'] = $_GET['op_fecha'];
$_SESSION['sw_debug'] = $_GET['sw_debug'];

$cDb_Nam = $_SESSION['database'];
$cOp__Id = $_SESSION['op_id'];
$cOp_Fch = $_SESSION['op_fecha'];
$DebugOn = $_SESSION['sw_debug'];

if ($DebugOn == 1)
    var_dump($_SESSION);

$Sql_Cmd = "SELECT `cupon_codigo` FROM `$cDb_Nam`.`cupon_tombola_digital` WHERE (TRIM(IFNULL(`cupon_codigo`,''))<>'') AND (TRIM(IFNULL(`op_id`,''))='') LIMIT 1;";
if ($DebugOn == 1) {
    print($Sql_Cmd . chr(13));
}

$records = 0;
$oRow = getRow($connection, $Sql_Cmd, $records, false);
if ($DebugOn == 1) {
    echo 'Resp: ';
    print_r($oRow) . chr(13);
}

if (($oRow['cupon_codigo'] != '') && ($oRow['cupon_codigo'] != 'null') && ($oRow['cupon_codigo'] != 'NULL')) {
    $Cod_Cupon = $oRow['cupon_codigo'];

    $Sql_Cmd = "UPDATE `$cDb_Nam`.`cupon_tombola_digital` SET op_id='$cOp__Id', op_fecha='$cOp_Fch' WHERE (cupon_codigo='$Cod_Cupon');";
    if ($DebugOn == 1)
        echo $Sql_Cmd;
    mysqli_query($connection, $Sql_Cmd);
} else {
    $Cod_Cupon = '';
}
header('content-type: application/json');
echo $Cod_Cupon;

@mysqli_close($connection);
session_destroy();
session_unset();

/*
Johnn Gutierrez A.
Fecha de Creación	 : 2024-12-06
*/
