cleaner index.php code

This commit is contained in:
Joel Garcia 2021-11-09 12:31:30 -06:00
parent bd9b1c8732
commit 6c755857a5
2 changed files with 16 additions and 9 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 859 B

View File

@ -14,16 +14,16 @@ input[type="time"]::-webkit-calendar-picker-indicator{
</style>
</head>
<body>
<header>
<h1>Pagina de usuarios frecuentes</h1>
</header>
<main>
<?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";
@ -31,6 +31,7 @@ $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());
@ -73,7 +74,9 @@ if(sizeOf($fila_exists['place'])==0 ){
echo "This is something else";
$time = $_POST['starttime'];
$num = $_POST['spacenum'];
$reserve = $conn->query("update spaces set startTime = '$time', reserved = True where spaceID = $num");
$currentDate = new DateTime();
$day = $currentDate->format('Y-m-d');
$reserve = $conn->query("update spaces set date = '$day', startTime = '$time', reserved = True where spaceID = $num");
$reserve = $conn->query("update users set time = '$time', place = $num where id = $id");
header("Location:/parking/vip/");
}
@ -88,20 +91,24 @@ if (sizeOf($fila['spaceID']) != 0){
<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);
exec('sudo qrencode -s 20 -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'");
$free_place = $conn->query("update spaces set reserved = 0, startTime = NULL, endTime = NULL where spaceID = $cancelled");
$free_place = $conn->query("update users set place = NULL, time = NULL where id = '$id'");
mysqli_close($conn);
header("Location:/parking/vip/");
//}
}
}
mysqli_close($conn);
?>
</main>
<footer>
<p>Todos los derechos reservados (©).</p>
</footer>
</body>
</html>