
<?php
/*
JOHNN GUTIERREZ, 
FECHA DE CREACION   2021-01-01
ULTIMA MODIFICASION 2021-01-28
*/
include '../conn_obj/utiles_pdo.php';
include '../conn_obj/conn_param.php';
date_default_timezone_set("America/Panama");
error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
#error_reporting(E_ALL);
session_start();
if ($_POST) {
    $_SESSION['db_che'] = $_POST['db_che'];
    $_SESSION['suc_id'] = $_POST['suc_id'];
    $_SESSION['usr_id'] = $_POST['usr_id'];
    $_SESSION['pw_str'] = $_POST['pw_str'];
    $_SESSION['fecnew'] = $_POST['fecnew'];

    $pDb_Nam = $_SESSION['db_che'];
    $pSuc_Id = $_SESSION['suc_id'];
    $pUsr_Id = $_SESSION['usr_id'];
    $pPw_Str = $_SESSION['pw_str'];
    $pfecnew = $_SESSION['fecnew'];

    #$pDb_Nam = '74529_melo3';

    $oCnn = new Utiles($pDb_Nam, $Srv_Info['hostname'], $Srv_Info['username'], $Srv_Info['password'], $Srv_Info['charset']);

    if ($oCnn->FieldExists('usuarios', 'u_clave_old') == 0) {
        $Sql_Cmd = "ALTER TABLE `$pDb_Nam`.`usuarios` ADD COLUMN `u_clave_old` VARCHAR(30) NULL DEFAULT '' COLLATE 'utf8_general_ci' AFTER `u_usuario`";
        echo $Sql_Cmd;
        $execQry = $oCnn->query($Sql_Cmd);
    }

    $Sql_Cmd = '';
    $Sql_Cmd = $Sql_Cmd . 'UPDATE `' . $pDb_Nam . '`.`usuarios` SET ';
    $Sql_Cmd = $Sql_Cmd . ' u_clave_old = u_clave, ';
    $Sql_Cmd = $Sql_Cmd . ' u_clave     =' . $pPw_Str . ', ';
    $Sql_Cmd = $Sql_Cmd . ' fecha_cambio = DATE_ADD(fecha_cambio, INTERVAL dias_de_caducidad DAY) ';
    $Sql_Cmd = $Sql_Cmd . 'WHERE (u_id="' . $pUsr_Id . '") ';
    try {
        $execQry = $oCnn->query($Sql_Cmd);
        $aResp = array(
            "success" => 'true',
            "mensaje" => 'REGISTROS AFECTADOS: ' . $oCnn->affectedRows() . ' ',
            "jsonres" => ''
        );
    } catch (Exception $e) {
        $aResp = array(
            "success" => 'false',
            "mensaje" => 'ERROR AL EJECUTAR EL COMANDO.',
            "jsonres" => ''
        );
    }
    $oCnn->close;
} else {
    $aResp = array(
        "success" => 'false',
        "mensaje" => 'SOLO SE ADMITEN LLAMADOS POR METODO POST.',
        "jsonres" => ''
    );

    header('Temporary-Header: True', true, 403);
    header_remove('Temporary-Header');
}
header('content-type: application/json');
echo json_encode($aResp);
?>