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
|
<?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"){
|
if($_POST['spacenum'] and $_SERVER['REQUEST_METHOD'] == "POST"){
|
||||||
$id = $_SESSION['user_id'];
|
|
||||||
$time = $_POST['starttime'];
|
|
||||||
$num = $_POST['spacenum'];
|
$num = $_POST['spacenum'];
|
||||||
$servername = "localhost";
|
$time = $_POST['starttime'];
|
||||||
$username = "pi2";
|
|
||||||
$password = "emb20";
|
// Buscar espacios ya reservados por el usuario
|
||||||
$database = "parking_lot";
|
$existing = $conn->query("select spaceID from spaces where spaceID = (select place from users where place is not NULL and id = $id)");
|
||||||
$conn = mysqli_connect($servername,$username,$password,$database);
|
$existing -> data_seek(0);
|
||||||
if(!$conn){
|
$fila_exist = $existing->fetch_assoc();
|
||||||
echo "Connection failed";
|
|
||||||
die("Conection failed: ". mysqli_connect_error());
|
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 = $conn->query("select spaceID from spaces where usedID = 0 and spaceID = $num");
|
||||||
$results -> data_seek(0);
|
$results -> data_seek(0);
|
||||||
$fila = $results->fetch_assoc();
|
$fila = $results->fetch_assoc();
|
||||||
if (sizeOf($fila['spaceID']) != 0){
|
$actual = $fila_exist['spaceID'];
|
||||||
//echo "Lugar disponible";
|
|
||||||
$request = $conn->query("update spaces set reserved = True, startTime = '$time', endTime = NULL where spaceID = '$num' and usedID = False");
|
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");
|
$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{
|
else{
|
||||||
echo "Lugar no disponible";
|
echo "Lugar no disponible";
|
||||||
}
|
}
|
||||||
mysqli_close($conn);
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
<h2>Liberar un lugar</h2>
|
<h2>Liberar un lugar</h2>
|
||||||
<p>Libera un espacio apartado que deseas cancelar.</p>
|
<p>Libera un espacio apartado que deseas cancelar.</p>
|
||||||
<form method="POST" action="/web/vip/index.php" name="reg-form">
|
<form method="POST" action="/web/vip/index.php" name="reg-form">
|
||||||
<label>Espacio</label><br>
|
<label>Espacio</label><br>
|
||||||
<input type="number" max="15" name="freenum" required/><br>
|
<button type="submit" name="freenum" value="registro">Cancelar apartado actual</button>
|
||||||
<button type="submit" name="register" value="registro">Apartar espacio</button>
|
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<?php
|
<?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"){
|
if($_POST['freenum'] and $_SERVER['REQUEST_METHOD'] == "POST"){
|
||||||
$id = $_SESSION['user_id'];
|
//$num = $_POST['spacenum'];
|
||||||
$num = $_POST['freenum'];
|
$time = $_POST['starttime'];
|
||||||
$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();
|
|
||||||
if (sizeOf($fila['spaceID']) != 0){
|
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'");
|
$request = $conn->query("update users set place = NULL, time = NULL where id = '$id'");
|
||||||
//header("Location:/web/vip/");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
echo "Lugar no disponible";
|
echo "No tienes lugares apartados.";
|
||||||
}
|
}
|
||||||
mysqli_close($conn);
|
|
||||||
}
|
}
|
||||||
|
mysqli_close($conn);
|
||||||
?>
|
?>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in New Issue