<?php
session_start();
$usuarioSession = $_SESSION['USUARIO'];
$grupo = $_SESSION['GRUPO'];
$contacto = $_SESSION['CONTACTO'];
$awa_session_id = $_SESSION['AWA_SESION_ID'];
include('../lg/config_vo.php');
include('../includes/conex.php');
include('../includes/eat.php');
include('../includes/historial.php');
include('../class/Static.php');
include('../class/Schema.php');
include('../class/MotherCar.php');
include('../class/PuzzleHTML.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);
$MotherCar = new MotherCar($con);
$color = ["primary", "secondary", "success", "danger", "warning", "info", "light", "dark"];
$random = rand(0, 7);
$codigo_vehiculo = Statics::SafeInput($con, $_POST['codigo_vehiculo']);
$codigo_origen = Statics::SafeInput($con, $_POST['codigo_origen']);
$row = $MotherCar->getCarData($codigo_vehiculo);
$s3Link = $Schema->executeQuery('SELECT LINK FROM VEHICULOS_MULTIMEDIA_LINKS WHERE VEHICULO = ? AND ORIGEN = ? AND ORDEN = ?', 'isi', [$codigo_vehiculo, $codigo_origen, 1])->fetch_array();
$html = '<div class="row">';
    $html .= '<div class="col-sm-12 col-md-8 overflow-hidden">';
        if(!empty($s3Link['LINK'])) {
            if(file_get_contents($s3Link['LINK'])) {
                $imageData = base64_encode(file_get_contents($s3Link['LINK']));
                $html .= '<img src="data:image/jpeg;base64,' . $imageData . '" class="img-fit" width="100%">';
            } else {
                $html .= '<div class="d-flex align-items-center justify-content-center text-center bg-' . $color[$random] . ' h-100"><i class="far fa-image text-white fa-5x"></i></div>';
            }
        } else {
            $html .= '<div class="d-flex align-items-center justify-content-center text-center bg-' . $color[$random] . ' h-100"><i class="far fa-image text-white fa-5x"></i></div>';
        }
    $html .= '</div>';
    $html .= '<div class="col-sm-12 col-md-4 list-group">';
        $html .= '<a class="list-group-item list-group-item-action"><div class="d-flex w-100 justify-content-between"><h6 class="mb-1">' . $descripcion_idcar_lg . '</h6></div>' . $row['MOSTRAR'] . '</a>';
        $html .= '<a class="list-group-item list-group-item-action"><div class="d-flex w-100 justify-content-between"><h6 class="mb-1">' . $version_lg . '</h6></div>' . $row['VERSION'] . '</a>';
        $html .= '<a class="list-group-item list-group-item-action"><div class="d-flex w-100 justify-content-between"><h6 class="mb-1">' . $combustible_lg . '</h6></div>' . $row['DESCRIPCION_LG1'] . '</a>';
        $html .= '<a class="list-group-item list-group-item-action"><div class="d-flex w-100 justify-content-between"><h6 class="mb-1">' . $cambio_lg . '</h6></div>' . $row['DESCRIPCION_LG2'] . '</a>';
        $html .= '<a class="list-group-item list-group-item-action"><div class="d-flex w-100 justify-content-between"><h6 class="mb-1">' . $km_lg . '</h6></div>' . $row['KM'] . '</a>';
        $html .= '<a class="list-group-item list-group-item-action"><div class="d-flex w-100 justify-content-between"><h6 class="mb-1">' . $precio_venta_lg . '</h6></div>' . $row['VENTA_TOTAL'] . $moneda_vo .'</a>';
    $html .= '</div>';
$html .= '</div>';


echo $html;

?>
