You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

98 lines
3.1 KiB

<?php
/**
* Delete a user
*/
require "../config.php";
require "../common.php";
$success = null;
if (isset($_POST["submit"])) {
if (!hash_equals($_SESSION['csrf'], $_POST['csrf'])) die();
try {
$connection = new PDO($dsn, $username, $password, $options);
$identificador = $_POST["submit"];
$sql = "DELETE FROM carburante WHERE identificador = :identificador";
$statement = $connection->prepare($sql);
$statement->bindValue(':identificador', $identificador);
$statement->execute();
$success = "Repostaje borrado con éxito";
$log_msg='BORRA REPOSTAJE-> ID: '.$identificador;
escribe_log($log_msg);
} catch(PDOException $error) {
echo $sql . "<br>" . $error->getMessage();
}
}
try {
$connection = new PDO($dsn, $username, $password, $options);
$sql = "SELECT * FROM carburante ORDER BY fecha DESC";
$statement = $connection->prepare($sql);
$statement->execute();
$result = $statement->fetchAll();
} catch(PDOException $error) {
echo $sql . "<br>" . $error->getMessage();
}
?>
<?php require "../templates/header.php"; ?>
<section class="principal">
<div class="container">
<section>
<h2>Borrar repostajes</h2>
<?php if ($success) echo $success; ?>
<form method="post">
<input name="csrf" type="hidden" value="<?php echo escape($_SESSION['csrf']); ?>">
<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>
<th>Borrar</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>
<td><button type="submit" name="submit"
value="<?php echo escape($row["identificador"]); ?>">Borrar</button></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</form>
</section>
</div>
</section>
<?php require "../templates/footer.php"; ?>