<?php
    session_start();
    $usuarioSession = $_SESSION['USUARIO'];
    $grupo = $_SESSION['GRUPO'];
    $contacto = $_SESSION['CONTACTO'];
    $awa_session_id = $_SESSION['AWA_SESION_ID'];
    include('../includes/conex.php');
    include('../includes/eat.php');
    include('../includes/historial.php');
    include('../includes/functions.php');
    include('../includes/esquemas.php');
    include('../class/Schema.php');
    include('../class/MotherCar.php');
    include('../class/Static.php');
    if(!isset($usuarioSession) OR $awa_session_id != $awa_id) {
        eatCookies();
        header('Location:../index.php');
    }
    if(isset($_COOKIE['usuario']) AND $_COOKIE['usuario'] != $staticUsu ) {
        eatCookies();
        header('Loction:../index.php');
    }
    if (isset($_COOKIE['idioma'])) {
        include('../lg/LG_' . $_COOKIE['idioma'] . '.php');
    } else {
        include('../lg/LG_SP.php');
    }
    $Schema = new Schema($con, $database);

    $key = 'KM = ?';
    $type = 'i';
    $array_value = [Statics::SafeInput($con, $_POST['km'])];
    if (!empty($_POST['itv_proxima'])) {
        $key .= ',ITV_PROXIMA = ?';
        $type .= 's';
        array_push($array_value, Statics::SafeInput($con, $_POST['itv_proxima']));
    }
    if (!empty($_POST['manual_usuarios'])) {
        $key .= ',MANUAL = ?';
        $type .= 'i';
        array_push($array_value, Statics::SafeInput($con, $_POST['manual_usuarios']));
    }
    if (!empty($_POST['libro_mantenimiento'])) {
        $key .= ',LIBRO_MANT = ?';
        $type .= 'i';
        array_push($array_value, Statics::SafeInput($con, $_POST['libro_mantenimiento']));
    }
    if (!empty($_POST['mantenimiento_sellado'])) {
        $key .= ',MANT_SELLADO = ?';
        $type .= 'i';
        array_push($array_value, Statics::SafeInput($con, $_POST['mantenimiento_sellado']));
    }
    if (!empty($_POST['ultimo_mantenimiento'])) {
        $key .= ',ULT_MANT = ?';
        $type .= 's';
        array_push($array_value, Statics::SafeInput($con, $_POST['ultimo_mantenimiento']));
    }
    if (!empty($_POST['llaves'])) {
        $key .= ',LLAVES = ?';
        $type .= 'i';
        array_push($array_value, Statics::SafeInput($con, $_POST['llaves']));
    }
    if (!empty($_POST['codigo_radio'])) {
        $key .= ',CODIGO_RAD = ?';
        $type .= 'i';
        array_push($array_value, Statics::SafeInput($con, $_POST['codigo_radio']));
    }
    if (!empty($_POST['codigo_navegador'])) {
        $key .= ',CODIGO_NAV = ?';
        $type .= 's';
        array_push($array_value, Statics::SafeInput($con, $_POST['codigo_navegador']));
    }
    if (!empty($_POST['tipo_seguro'])) {
        $key .= ',TIPO_SEGURO = ?';
        $type .= 'i';
        array_push($array_value, Statics::SafeInput($con, $_POST['tipo_seguro']));
    }
    if (!empty($_POST['franquicia'])) {
        $key .= ',FRANQUICIA = ?';
        $type .= 'i';
        array_push($array_value, Statics::SafeInput($con, $_POST['franquicia']));
    }
    if (!empty($_POST['aseguradora'])) {
        $key .= ',ASEGURADORA = ?';
        $type .= 'i';
        array_push($array_value, Statics::SafeInput($con, $_POST['aseguradora']));
    }
    if (!empty($_POST['numero_partes'])) {
        $key .= ',NUM_PARTES = ?';
        $type .= 'i';
        array_push($array_value, Statics::SafeInput($con, $_POST['numero_partes']));
    }
    if (!empty($_POST['fecha_finalizacion'])) {
        $key .= ',FECHA_FINALIZACION_SEGURO = ?';
        $type .= 's';
        array_push($array_value, Statics::SafeInput($con, $_POST['fecha_finalizacion']));
    }
    $key .= ' WHERE CODIGO = ?';
    $type .= 'i';
    array_push($array_value, $_SESSION['VEHICULO_RECIEN_CREADO']);

    $Schema->executeQuery("UPDATE VEHICULOS SET $key" , $type, $array_value);
    $_SESSION['MSG_INFO'] = 'DATOS_OTROS';
    $detalle = $actualizacion_lg . ': ' . $otros_datos_vehiculo_lg;
    Statics::add_trace_history($con, $usuarioSession, $_SESSION['VEHICULO_RECIEN_CREADO'], 2, $detalle);
    header("Location:../nuevo-vehiculo-datos.php");

?>