better queries, can update time of existing reservation, can remove reservations
This commit is contained in:
parent
67c3a97ef4
commit
d6e7521891
|
@ -35,70 +35,77 @@ if (!isset($_SESSION['user_id'])){
|
|||
|
||||
|
||||
<?php
|
||||
$id = $_SESSION['user_id'];
|
||||
$servername = "localhost";
|
||||
$username = "pi2";
|
||||
$password = "emb20";
|
||||
$database = "parking_lot";
|
||||
$conn = mysqli_connect($servername,$username,$password,$database);
|
||||
if(!$conn){
|
||||
echo "Connection failed";
|
||||
die("Connection failed: ". mysqli_connect_error());
|
||||
}
|
||||
|
||||
if($_POST['spacenum'] and $_SERVER['REQUEST_METHOD'] == "POST"){
|
||||
$id = $_SESSION['user_id'];
|
||||
$time = $_POST['starttime'];
|
||||
$num = $_POST['spacenum'];
|
||||
$servername = "localhost";
|
||||
$username = "pi2";
|
||||
$password = "emb20";
|
||||
$database = "parking_lot";
|
||||
$conn = mysqli_connect($servername,$username,$password,$database);
|
||||
if(!$conn){
|
||||
echo "Connection failed";
|
||||
die("Conection failed: ". mysqli_connect_error());
|
||||
}
|
||||
$time = $_POST['starttime'];
|
||||
|
||||
// Buscar espacios ya reservados por el usuario
|
||||
$existing = $conn->query("select spaceID from spaces where spaceID = (select place from users where place is not NULL and id = $id)");
|
||||
$existing -> data_seek(0);
|
||||
$fila_exist = $existing->fetch_assoc();
|
||||
|
||||
echo "Hola a todos", $fila_exist['spaceID'], "tamaño", sizeOf($fila_exist['spaceID']);
|
||||
|
||||
$results = $conn->query("select spaceID from spaces where usedID = 0 and spaceID = $num");
|
||||
$results -> data_seek(0);
|
||||
$fila = $results->fetch_assoc();
|
||||
if (sizeOf($fila['spaceID']) != 0){
|
||||
//echo "Lugar disponible";
|
||||
$request = $conn->query("update spaces set reserved = True, startTime = '$time', endTime = NULL where spaceID = '$num' and usedID = False");
|
||||
$actual = $fila_exist['spaceID'];
|
||||
|
||||
if (sizeOf($fila_exist['spaceID']) != 0){
|
||||
$request = $conn->query("update spaces set startTime = '$time' where spaceID = $actual");
|
||||
$request = $conn->query("update users set time = '$time' where id = $actual");
|
||||
echo "<p><b>Ya has apartado el lugar ",$fila_exist['spaceID'], "</b> (liberalo si quieres cambiarlo). Puedes actualizar la hora de un espacio que ya reservaste.</p>";
|
||||
}
|
||||
else if (sizeOf($fila['spaceID']) != 0){
|
||||
// Configuramos el espacio deseado en la base de usuarios para que solo
|
||||
// se pueda reservar un lugar por usuario
|
||||
$request = $conn->query("update users set place = $num, time = '$time' where id = '$id' and place is NULL");
|
||||
//header("Location:/web/vip/");
|
||||
// Configuramos el espacio deseado en la base de espacios si es que esta vacio
|
||||
$request = $conn->query("update spaces set reserved = True, startTime = '$time', endTime = NULL where spaceID = '$num' and usedID = 0");
|
||||
|
||||
}
|
||||
else{
|
||||
echo "Lugar no disponible";
|
||||
}
|
||||
mysqli_close($conn);
|
||||
}
|
||||
?>
|
||||
<h2>Liberar un lugar</h2>
|
||||
<p>Libera un espacio apartado que deseas cancelar.</p>
|
||||
<form method="POST" action="/web/vip/index.php" name="reg-form">
|
||||
<label>Espacio</label><br>
|
||||
<input type="number" max="15" name="freenum" required/><br>
|
||||
<button type="submit" name="register" value="registro">Apartar espacio</button>
|
||||
<button type="submit" name="freenum" value="registro">Cancelar apartado actual</button>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
$reserved = $conn->query("select spaceID from spaces where spaceID = (select place from users where place is not NULL and id = $id)");
|
||||
$reserved -> data_seek(0);
|
||||
$fila = $reserved->fetch_assoc();
|
||||
if (sizeOf($fila['spaceID']) != 0){
|
||||
echo "Tienes apartado el lugar: ", $fila['spaceID'];
|
||||
}
|
||||
if($_POST['freenum'] and $_SERVER['REQUEST_METHOD'] == "POST"){
|
||||
$id = $_SESSION['user_id'];
|
||||
$num = $_POST['freenum'];
|
||||
$servername = "localhost";
|
||||
$username = "pi2";
|
||||
$password = "emb20";
|
||||
$database = "parking_lot";
|
||||
$conn = mysqli_connect($servername,$username,$password,$database);
|
||||
if(!$conn){
|
||||
echo "Connection failed";
|
||||
die("Conection failed: ". mysqli_connect_error());
|
||||
}
|
||||
$results = $conn->query("select spaceID from spaces where usedID = 0 and spaceID = $num");
|
||||
$results -> data_seek(0);
|
||||
$fila = $results->fetch_assoc();
|
||||
//$num = $_POST['spacenum'];
|
||||
$time = $_POST['starttime'];
|
||||
if (sizeOf($fila['spaceID']) != 0){
|
||||
$request = $conn->query("update spaces set reserved = False, startTime = NULL, endTime = NULL where spaceID = '$num'");
|
||||
$request = $conn->query("update spaces set reserved = 0, startTime = NULL, endTime = NULL where spaceID = (select place from users where id = $id)");
|
||||
$request = $conn->query("update users set place = NULL, time = NULL where id = '$id'");
|
||||
//header("Location:/web/vip/");
|
||||
|
||||
}
|
||||
else{
|
||||
echo "Lugar no disponible";
|
||||
echo "No tienes lugares apartados.";
|
||||
}
|
||||
mysqli_close($conn);
|
||||
}
|
||||
mysqli_close($conn);
|
||||
?>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in New Issue