<?php
error_reporting(E_ALL & ~ E_NOTICE & ~ E_WARNING);
include_once ("utiles.php");
include_once ("apt_funciones.php");

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

$_SESSION['dbname'] = $_POST['database'];
$_SESSION['op__id'] = $_POST['op__id'];
$_SESSION['status'] = $_POST['status'];
$_SESSION['swsavelog'] = $_POST['swsavelog'];

$cDb_Nam = $_SESSION['dbname'];
$cOp__id = $_SESSION['op__id'];
$cStatus = $_SESSION['status'];
$SaveLog = $_SESSION['swsavelog'];

$hoynow = getdate();
$timeStamp = $hoynow["year"] . "-" . $hoynow["mon"] . "-" . $hoynow["mday"];
$timeStamp = date("Y-m-d H:i:s");

if ($SaveLog == '1') {
    logs2('++++++++++++++++++++++++++++++++++++apt_actualiza_estatus.php+++++++++++++++++++++++++++++++++++++++++++++++++');
    logs2('database : ' . $cDb_Nam);
    logs2('status   : ' . $cOp__id);
    logs2('Op__id   : ' . $SaveLog);
    logs2('++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++');
}

$SQL_Update = 'UPDATE ' . $cDb_Nam . '.operacion SET
        '. ($status==''?'':'op_aptdo_status     = "' . $cStatus . '",'). '
        op_aptdo_factu      ="' . $timeStamp . '",
        usermodify          ="0",
        useroption          ="2"
        WHERE op_id  ="' . $cOp__id . '"';

$result = update_Sql($connection, $SQL_Update);

if ($SaveLog == '1') {
    logs2('++++++++++++++++++++++++++++++++++++apt_actualiza_estatus.php+++++++++++++++++++++++++++++++++++++++++++++++++');
}

if ($result == true) {
    $msg = array(
        "success" => 'true',
        "mensaje" => 'Procesado correctamente'
    );
} else {
    $msg = array(
        "success" => 'false',
        "mensaje" => 'Error de procesamiento'
    );
}
;

$jsonData[] = $msg;

header('content-type: application/json');
echo json_encode($jsonData);
@mysqli_close($connection);
?>