<?php
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'] = $_POST['database'];
$_SESSION['suc_id'] = $_POST['suc_id'];
$_SESSION['per_id'] = $_POST['per_id'];
$_SESSION['ced_id'] = $_POST['ced_id'];
$_SESSION['tip_id'] = $_POST['tip_id'];
$_SESSION['datos'] = $_POST['datos'];
$_SESSION['swsavelog'] = $_POST['swsavelog'];

$cDb_Nam = $_SESSION['database'];
$cSuc_id = $_SESSION['suc_id'];
$cPer_id = $_SESSION['per_id'];
$cCed_id = $_SESSION['ced_id'];
$tip_id = $_SESSION['tip_id'];
$cfprint = $_SESSION['datos'];
$SaveLog = $_SESSION['save_log_fle'];

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

if ($SaveLog == 1) {
    logs2('', false);
    logs2('++++++++++++++++++++++++++++++++++++++++++++++GEN_FINGERP_UPD.PHP+++++++++++++++++++++++++++++++++++++++++++++++');
    logs2('DB ORIGEN : ' . $cDb_Nam);
    logs2('SUCURSAL  : ' . $cSuc_id);
    logs2('PERSPNAL  : ' . $cPer_id);
    logs2('CEDULA    : ' . $cCed_id);
    logs2('DATOS     : ' . $cfprint);
    logs2('SAVE LOGIN: ' . $SaveLog);
    logs2('++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++');
    logs2('', false);
}

$cWhere = (($cCed_id <> '') ? 'WHERE pers_cedula="' . $cCed_id . '"' : 'WHERE pers_id="' . $cPer_id . '"');
$cField = (($tip_id == 1) ? 'pers_fing_type=1, pers_fing_zk="' . $cfprint . '", pers_fing_dp=null ' : 'pers_fing_type=2, pers_fing_dp="' . $cfprint . '", pers_fing_zk=null ');

$str_result = 'null';
$cmd = 'UPDATE ' . $cDb_Nam . '.personal SET usermodify=1, ' . $cField . ' ' . $cWhere;
#echo $cmd; 
$resp1 = update_Sql($connection, $cmd);

#$cmd = 'UPDATE ' . $cDb_Nam . '.usuarios SET u_fing="' . $cfprint . '" '.$cWhere;
#$resp2 = update_Sql($connection, $cmd);

#if (($resp1 == true) and ($resp2 == true)) {
if ($resp1 == true) {
    $str_result = 'ok';
}

header('content-type: application/json; charset=UTF-8');
echo $str_result;

@mysqli_close($connection);
?>