<?php
|
|
|
|
/**
|
|
* Function to query information based on
|
|
* a parameter: in this case, marca.
|
|
*
|
|
*/
|
|
|
|
require "../../config.php";
|
|
require "../../common.php";
|
|
|
|
/**
|
|
* Esto es para obtener los vehículos dados de alta
|
|
*/
|
|
$conexion = new PDO($dsn, $username, $password, $options);
|
|
$smt = $conexion->prepare('SELECT matricula FROM vehiculos');
|
|
$smt->execute();
|
|
$vehiculos = $smt->fetchAll();
|
|
|
|
if (isset($_POST['submit'])) {
|
|
if (!hash_equals($_SESSION['csrf'], $_POST['csrf'])) die();
|
|
|
|
try {
|
|
$connection = new PDO($dsn, $username, $password, $options);
|
|
|
|
$sql = "SELECT *
|
|
FROM carburante
|
|
WHERE vehiculo = :vehiculo ORDER BY fecha DESC" ;
|
|
|
|
$marca = $_POST['vehiculo'];
|
|
$statement = $connection->prepare($sql);
|
|
$statement->bindParam(':vehiculo', $marca, PDO::PARAM_STR);
|
|
$statement->execute();
|
|
|
|
$result = $statement->fetchAll();
|
|
} catch(PDOException $error) {
|
|
echo $sql . "<br>" . $error->getMessage();
|
|
}
|
|
}
|
|
?>
|
|
<?php require "../templates/header.php"; ?>
|
|
|
|
<?php
|
|
if (isset($_POST['submit'])) {
|
|
if ($result && $statement->rowCount() > 0) { ?>
|
|
<section id="five" class="main style1">
|
|
<div class="container">
|
|
<section>
|
|
<a href="menu.php" class="button small">Volver</a>
|
|
|
|
<h2>Resultados para vehículo <?php echo escape($_POST['vehiculo']); ?></h2>
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>#</th>
|
|
<th>Fecha</th>
|
|
<th>Vehículo</th>
|
|
<th>Kilómetros</th>
|
|
<th>Litros</th>
|
|
<th>Descuento</th>
|
|
<th>Precio/litro</th>
|
|
<th>Importe</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($result as $row) : ?>
|
|
<tr>
|
|
<td><?php echo escape($row["identificador"]); ?></td>
|
|
<td><?php echo escape($row["fecha"]); ?></td>
|
|
<td><?php echo escape($row["vehiculo"]); ?></td>
|
|
<td><?php echo escape($row["kms"]); ?></td>
|
|
<td><?php echo escape(str_replace('.', ',',$row["litros"])); ?></td>
|
|
<td><?php echo escape(str_replace('.', ',',$row["descuento"])); ?></td>
|
|
<td><?php echo escape(str_replace('.', ',',$row["precioxlitro"])); ?></td>
|
|
<td><?php echo escape(str_replace('.', ',',$row["importe"])); ?></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
|
|
</section>
|
|
</div>
|
|
</section>
|
|
<?php } else { ?>
|
|
<blockquote>No results found for <?php echo escape($_POST['vehiculo']); ?>.</blockquote>
|
|
<?php }
|
|
} ?>
|
|
|
|
<section id="five" class="main style1">
|
|
<div class="container">
|
|
<section>
|
|
<h2>Busca repostajes por vehículo</h2>
|
|
|
|
<form method="post">
|
|
<div class="row gtr-uniform gtr-50">
|
|
<input name="csrf" type="hidden" value="<?php echo escape($_SESSION['csrf']); ?>">
|
|
<div class="col-12">
|
|
<label for="vehiculo">Vehículo</label>
|
|
<select name="vehiculo" id="vehiculo">
|
|
<?php foreach ($vehiculos as $row) { ?>
|
|
<option><?=$row["matricula"]?></option>
|
|
<?php } ?>
|
|
</select>
|
|
</div>
|
|
<div class="col-12">
|
|
|
|
<!-- <input type="text" id="vehiculo" name="vehiculo"> -->
|
|
<input type="submit" name="submit" value="Ver resultados" class="primary">
|
|
</div>
|
|
</div>
|
|
</form>
|
|
<a href="menu.php" class="button small">Volver</a>
|
|
</section>
|
|
</div>
|
|
</section>
|
|
<?php require "../templates/footer.php"; ?>
|