141 lines
4.4 KiB
PHP
141 lines
4.4 KiB
PHP
<?php
|
|
// Comprobamos si existe la sesión de apodo
|
|
session_start();
|
|
if (!isset($_SESSION['usuario'])) {
|
|
// En caso contrario devolvemos a la página login.php
|
|
header('Location: login_usuarios.php');
|
|
die();
|
|
}
|
|
?>
|
|
|
|
<!Doctype html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
|
|
<title>Buscador de reservas</title>
|
|
<link rel="stylesheet" type="text/css" href="estilos.css" />
|
|
</head>
|
|
<body>
|
|
<div>
|
|
<!-- Saludamos -->
|
|
<h1>Bienvenido <?php echo $_SESSION['usuario']; ?></h1>
|
|
<!-- Botón para cerrar la sesión -->
|
|
<a href="logout.php">Cerrar sesión</a>
|
|
<form method="post">
|
|
<p>*Término a buscar: </p><p><input type="text" name="busqueda" id="busqueda" size="30" placeholder="Introduzca la palabra de busqueda" required></p>
|
|
<input type="submit" name="buscar" value="Buscar" >
|
|
</form></div>
|
|
|
|
<?php
|
|
|
|
//Suponiendo que el archivo caracteres.php está en la misma carpeta:
|
|
include('caracteres.php');
|
|
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['buscar'])) {
|
|
// Busca una palabra
|
|
$busqueda=isset($_REQUEST['busqueda'])? $_REQUEST['busqueda']: "" ;
|
|
|
|
|
|
//Abrir el archivo
|
|
$archivo = fopen('listado_reservas.txt', 'r');
|
|
|
|
//Leer el archivo
|
|
|
|
if (!$archivo) { echo("Error abriendo archivo"); }
|
|
|
|
// Abro la tabla
|
|
echo '<br>';
|
|
echo '<table border="2">';
|
|
echo "<tr><th>Id Reserva</th><th>Nombre</th><th>Correo</th><th>Teléfono</th><th>Entrada</th><th>Salida</th><th>Fecha reserva</th><th>Duración</th></tr>";
|
|
|
|
//Busco la coincidencia
|
|
|
|
while (($linea = fgets($archivo)) != false) {
|
|
if(strpos(eliminar_tildes(strtolower($linea)), eliminar_tildes(strtolower($busqueda))) !== false){
|
|
|
|
// Mostrar la tabla con array
|
|
$arrayLinea=explode('/_/', $linea);
|
|
//foreach ($arrayLinea as $dato) {
|
|
// echo "<td>$dato</td>";
|
|
//}
|
|
echo "<tr><td>$arrayLinea[0]</td><td>$arrayLinea[1]</td><td>$arrayLinea[2]</td><td>$arrayLinea[3]</td><td>$arrayLinea[4]</td><td>$arrayLinea[5]</td><td>$arrayLinea[6]</td><td>$arrayLinea[7]</td></tr>";
|
|
|
|
}
|
|
}
|
|
// Cierrro la tabla
|
|
echo "</table>";
|
|
//cerrar el archivo
|
|
fclose($archivo);
|
|
|
|
// Vacio los datos de POST
|
|
unset($_POST);
|
|
|
|
}
|
|
?>
|
|
<br>
|
|
<div><form method="post">
|
|
<p>*ID de alquiler para borrar: </p><input type="text" name="Id_borrar" value="" id="Id_borrar" size="15" minlength="15" maxlength="15" placeholder="Id Alquiler"/>
|
|
<input type="submit" name="borrar" value="Borrar reserva de alquiler" >
|
|
</form></div>
|
|
|
|
<?php
|
|
|
|
// Borrar reservas de alquiler
|
|
$listaReservas = "listado_reservas.txt";
|
|
$temporal = "temp.txt";
|
|
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['borrar']) && isset($_POST['Id_borrar'])) {
|
|
$borrado = $_POST['Id_borrar'];
|
|
|
|
$accesoLista = fopen($listaReservas, 'r');
|
|
$accesoTemporal = fopen($temporal, 'w');
|
|
|
|
// Buscar la reserva por ID
|
|
while (($linea = fgets($accesoLista)) !== false) {
|
|
// Obtener el ID de reserva de la línea actual
|
|
$arrayLinea = explode('/_/', $linea);
|
|
$id_reserva = $arrayLinea[0];
|
|
|
|
// Si el ID de reserva no coincide
|
|
if(trim($id_reserva) !== trim($borrado)) {
|
|
fwrite($accesoTemporal, $linea);
|
|
}
|
|
}
|
|
|
|
fclose($accesoLista);
|
|
fclose($accesoTemporal);
|
|
|
|
// Borrar listado y renombrar el temporal
|
|
unlink($listaReservas);
|
|
rename($temporal, $listaReservas);
|
|
|
|
// Borrar ficha de reserva individual
|
|
$ficha_individual = "reservas/reserva_" .$borrado.".txt";
|
|
if (file_exists($ficha_individual)) {
|
|
if (unlink("reservas/reserva_" .$borrado.".txt") !== false) {
|
|
echo "<div><p>La ficha de reserva se ha borrado</p></div>";
|
|
}
|
|
} else {
|
|
echo "<div><p>La ficha de reserva no se ha encontrado</p></div>";
|
|
}
|
|
|
|
// Borrar DNI con glob()
|
|
$dni_archivos = glob("dni_clientes/*_{$borrado}_*");
|
|
|
|
foreach ($dni_archivos as $dni_aborrar) {
|
|
if (unlink($dni_aborrar)) {
|
|
echo '<div><p>El archivo ' . $dni_aborrar . ' fue eliminado exitosamente.</p></div>';
|
|
} else {
|
|
echo '<div><p>Ocurrió un error al intentar eliminar el archivo ' . $dni_aborrar . '.</p></div>';
|
|
}
|
|
}
|
|
|
|
// Vacio los datos de POST
|
|
unset($_POST);
|
|
}
|
|
?>
|
|
|
|
</body>
|
|
</html>
|