<?php
require_once("../functions.php");
if (comprobar_override(str_replace($_SERVER['DOCUMENT_ROOT'], '', __FILE__)))
    exit;
$pag = basename($_SERVER['PHP_SELF']);
comprobar_postget("post", ["id"], $pag, true, "/views/tables/registros_inspector");
gen_plantilla(true, $pag, false, false, '', false, false);

/*******************************************************************************
 *                                [Parámetros]                                  *
 *******************************************************************************/

$id = filter_input(INPUT_POST, "id", FILTER_SANITIZE_NUMBER_INT);

$hora1 = filter_input(INPUT_POST, "hora1", FILTER_SANITIZE_SPECIAL_CHARS);
$hora1 = ($hora1 == "" || $hora1 == "00:00") ? null : $hora1;
$hora2 = filter_input(INPUT_POST, "hora2", FILTER_SANITIZE_SPECIAL_CHARS);
$hora2 = ($hora2 == "" || $hora2 == "00:00") ? null : $hora2;
$hora3 = filter_input(INPUT_POST, "hora3", FILTER_SANITIZE_SPECIAL_CHARS);
$hora3 = ($hora3 == "" || $hora3 == "00:00") ? null : $hora3;
$hora4 = filter_input(INPUT_POST, "hora4", FILTER_SANITIZE_SPECIAL_CHARS);
$hora4 = ($hora4 == "" || $hora4 == "00:00") ? null : $hora4;
$hora5 = filter_input(INPUT_POST, "hora5", FILTER_SANITIZE_SPECIAL_CHARS);
$hora5 = ($hora5 == "" || $hora5 == "00:00") ? null : $hora5;
$hora6 = filter_input(INPUT_POST, "hora6", FILTER_SANITIZE_SPECIAL_CHARS);
$hora6 = ($hora6 == "" || $hora6 == "00:00") ? null : $hora6;
$hora7 = filter_input(INPUT_POST, "hora7", FILTER_SANITIZE_SPECIAL_CHARS);
$hora7 = ($hora7 == "" || $hora7 == "00:00") ? null : $hora7;
$hora8 = filter_input(INPUT_POST, "hora8", FILTER_SANITIZE_SPECIAL_CHARS);
$hora8 = ($hora8 == "" || $hora8 == "00:00") ? null : $hora8;
$hora9 = filter_input(INPUT_POST, "hora9", FILTER_SANITIZE_SPECIAL_CHARS);
$hora9 = ($hora9 == "" || $hora9 == "00:00") ? null : $hora9;
$hora10 = filter_input(INPUT_POST, "hora10", FILTER_SANITIZE_SPECIAL_CHARS);
$hora10 = ($hora10 == "" || $hora10 == "00:00") ? null : $hora10;


/*******************************************************************************
 *                                 [Consulta]                                  *
 *******************************************************************************/

if (
    !consulta(
        "UPDATE registros_inspector SET `hora1`=?,`hora2`=?,`hora3`=?,`hora4`=?,`hora5`=?,`hora6`=?,`hora7`=?,`hora8`=?,`hora9`=?,`hora10`=? WHERE id=?;",
        [$hora1, $hora2, $hora3, $hora4, $hora5, $hora6, $hora7, $hora8, $hora9, $hora10, $id],
        false
    )
) {
    crear_log(
        "error",
        "Error en la consulta",
        $pag,
        "No se ha podido actualizar el registro, porque ha ocurrido un error en la consulta."
    );
    header("Location: " . SITIO_CARPETA . "/views/forms/registro_inspector?id=$id&tipo=error&mensaje=No se ha podido actualizar, ha ocurrido un error en la consulta");
} else {
    crear_log(
        "info",
        "Registro actualizado",
        $pag,
        "Se ha actualizado el registro con id <b>[$id]</b>."
    );
    header("Location: " . SITIO_CARPETA . "/views/tables/registros_inspector?id_seleccionado=$id&tipo=correcto&mensaje=Registro actualizado correctamente");
}
