<?php
include_once ("conn.php");
include_once ("funciones.php");

$_SESSION['database'] = $_POST['database'];
$_SESSION['json_data'] = $_POST['json_data'];
$_SESSION['tablename'] = $_POST['tablename'];
$_SESSION['swsavelog'] = $_POST['swsavelog'];

$database = $_SESSION['database'];
$json_data = $_SESSION['json_data'];
$tablenam = $_SESSION['tablename'];
$swsavelog = $_SESSION['swsavelog'];

if ($_SESSION['swsavelog'] == '1') {
    logs('->insert_json_op_gen.php--');
}
;

$data_arr = json_decode($json_data, TRUE);
$data_tab = $data_arr[$tablenam];
$regs_cnt = $data_arr['regs_cnt'];

$process_ok = jsonmysql($data_tab, $regs_cnt, $tablenam, $connection, $database, $swsavelog);

if ($process_ok === 'true') {
    $msg = array(
        "success" => 'true',
        "mensaje" => 'Procesado correctamente [' . $tablenam . ']'
    );
} else {
    $msg = array(
        "success" => 'false',
        "mensaje" => 'Error de procesamiento [' . $tablenam . ']'
    );
}
;
if ($_SESSION['swsavelog'] == '1') {
    logs('DATA: ' . $database);
    logs('JSON: ' . $json_data);
    logs('TABL: ' . $tablenam);
    logs('RESP: ' . $msg);
    logs('--insert_json_op_gen.php<-');
}
;

$jsonData[] = $msg;

header('content-type: application/json');
echo json_encode($jsonData);

@mysqli_close($connection);
?>