108 lines
4.1 KiB
PHP
108 lines
4.1 KiB
PHP
<!doctype html>
|
|
<html>
|
|
<head>
|
|
<title>Usuarios frecuentes</title>
|
|
<meta name="description" content="Our first page">
|
|
<meta name="keywords" content="html tutorial template">
|
|
<link rel="stylesheet" href="https://cdn.simplecss.org/simple.min.css">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<style>
|
|
input[type="time"]::-webkit-calendar-picker-indicator{
|
|
filter: invert(90%) sepia(13%) saturate(3207%) hue-rotate(130deg) brightness(95%) contrast(80%);
|
|
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h1>Pagina de usuarios frecuentes</h1>
|
|
<?php
|
|
session_start();
|
|
if (!isset($_SESSION['user_id'])){
|
|
echo '<p><a href="/parking/login/">Inicie sesión</a> para acceder a esta pagina</p>';
|
|
exit;
|
|
}
|
|
else{
|
|
echo "Sesion actual: ", $_SESSION['user_id'];
|
|
}
|
|
|
|
$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());
|
|
}
|
|
// Buscar espacios ya reservados por el usuario
|
|
$existing = $conn->query("select place from users where place is not NULL and id = $id");
|
|
$existing -> data_seek(0);
|
|
$fila_exists = $existing->fetch_assoc();
|
|
|
|
// Si no ha reservado nada, dar la opcion de reservar
|
|
if(sizeOf($fila_exists['place'])==0 ){
|
|
$query_available = "select spaceID from spaces where usedID = 0 and reserved = 0";
|
|
$available = $conn->query($query_available);
|
|
$available_spaces = $available->fetch_all();
|
|
echo '<h2>Apartar un lugar</h2>
|
|
<p>Adquiere derecho a un espacio de estacionamiento en una hora deseada.</p>
|
|
<form method="POST" action="/parking/vip/" name="reg-form">
|
|
<label for="spaces">Espacio</label><br>
|
|
<select id="spaces" name="spacenum" required>';
|
|
for ($i = 0; $i < sizeOf($available_spaces); $i++){
|
|
echo "<option value='",$available_spaces[$i][0],"'>", $available_spaces[$i][0], "</option>";
|
|
}
|
|
echo '</select> <br>
|
|
<label>Hora de inicio</label><br>
|
|
<input type="time" name="starttime" value="00:00:00" required/><br>
|
|
<button type="submit" name="register" value="registro">Apartar espacio</button>
|
|
</form>';
|
|
|
|
if($_POST['spacenum'] and $_SERVER['REQUEST_METHOD'] == "POST"){
|
|
echo "This is something else";
|
|
$time = $_POST['starttime'];
|
|
$num = $_POST['spacenum'];
|
|
$reserve = $conn->query("update spaces set startTime = '$time', reserved = True where spaceID = $num");
|
|
$reserve = $conn->query("update users set time = '$time', place = $num where id = $id");
|
|
header("Location:/parking/vip/");
|
|
}
|
|
}
|
|
|
|
$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();
|
|
$selected = $fila['spaceID'];
|
|
|
|
$secret = $conn->query("select password from users where id = $id");
|
|
$secret -> data_seek(0);
|
|
$secret = $secret->fetch_assoc();
|
|
$code = $secret['password'];
|
|
|
|
if (sizeOf($fila['spaceID']) != 0){
|
|
echo "<h2>Liberar un lugar</h2>";
|
|
echo "Tienes apartado el lugar: ", $fila['spaceID'];
|
|
echo '<p>Libera un espacio apartado que deseas cancelar.</p>
|
|
<form method="POST" action="/parking/vip/" name="reg-form">
|
|
<button type="submit" name="freenum" value="registro">Cancelar apartado actual</button> </form>
|
|
<p>Utiliza este codigo QR para validar tu reservación al entrar al estacionamiento</p>';
|
|
|
|
$url = "'http://192.168.1.130/parking/vip/validate.php?number=$selected&userid=$id&secret=$code'";
|
|
exec('sudo qrencode -s 30 -o file.png '. $url);
|
|
echo '<img src="file.png">';
|
|
}
|
|
if($_POST['freenum'] and $_SERVER['REQUEST_METHOD'] == "POST"){
|
|
$cancelled = $_POST['freenum'];
|
|
if (sizeOf($fila['spaceID']) != 0){
|
|
$request = $conn->query("update spaces set reserved = 0, startTime = NULL, endTime = NULL where spaceID = $cancelled");
|
|
$request = $conn->query("update users set place = NULL, time = NULL where id = '$id'");
|
|
mysqli_close($conn);
|
|
header("Location:/parking/vip/");
|
|
}
|
|
}
|
|
mysqli_close($conn);
|
|
?>
|
|
|
|
</body>
|
|
</html>
|