feat(home) displaying cached stations
This commit is contained in:
@@ -16,34 +16,6 @@ function getUsers() {
|
||||
}
|
||||
}
|
||||
|
||||
function updateUserDetails($userId, $email, $firstName, $lastName, $is_admin, $password = null) {
|
||||
global $conn;
|
||||
try {
|
||||
if ($password) {
|
||||
$query = $conn->prepare("UPDATE users SET email = ?, firstName = ?, lastName = ?, password = ?, is_admin = ? WHERE id = ?");
|
||||
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
|
||||
$query->execute([$email, $firstName, $lastName, $hashedPassword, $is_admin, $userId]);
|
||||
} else {
|
||||
$query = $conn->prepare("UPDATE users SET email = ?, firstName = ?, lastName = ?, is_admin = ? WHERE id = ?");
|
||||
$query->execute([$email, $firstName, $lastName, $is_admin, $userId]);
|
||||
}
|
||||
return true;
|
||||
} catch(PDOException $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function deleteUser($userId) {
|
||||
global $conn;
|
||||
try {
|
||||
$query = $conn->prepare("DELETE FROM users WHERE id = ?");
|
||||
$query->execute([$userId]);
|
||||
return true;
|
||||
} catch(PDOException $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$users = getUsers();
|
||||
|
||||
include 'post.php';
|
||||
@@ -56,6 +28,9 @@ include 'post.php';
|
||||
unset($_SESSION['message']);
|
||||
?>
|
||||
<h2 class="mb-4">Administration</h2>
|
||||
<form method="POST">
|
||||
<button type="submit" name="refreshData" class="btn btn-primary">Refresh Data</button>
|
||||
</form>
|
||||
<?php include 'users_list.php'; ?>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1,9 +1,84 @@
|
||||
<?php
|
||||
|
||||
|
||||
function updateUserDetails($userId, $email, $firstName, $lastName, $is_admin, $password = null) {
|
||||
global $conn;
|
||||
try {
|
||||
if ($password) {
|
||||
$query = $conn->prepare("UPDATE users SET email = ?, firstName = ?, lastName = ?, password = ?, is_admin = ? WHERE id = ?");
|
||||
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
|
||||
$query->execute([$email, $firstName, $lastName, $hashedPassword, $is_admin, $userId]);
|
||||
} else {
|
||||
$query = $conn->prepare("UPDATE users SET email = ?, firstName = ?, lastName = ?, is_admin = ? WHERE id = ?");
|
||||
$query->execute([$email, $firstName, $lastName, $is_admin, $userId]);
|
||||
}
|
||||
return true;
|
||||
} catch(PDOException $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function deleteUser($userId) {
|
||||
global $conn;
|
||||
try {
|
||||
$query = $conn->prepare("DELETE FROM users WHERE id = ?");
|
||||
$query->execute([$userId]);
|
||||
return true;
|
||||
} catch(PDOException $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function refreshData() {
|
||||
global $conn;
|
||||
try {
|
||||
|
||||
$conn->exec("TRUNCATE TABLE stops");
|
||||
|
||||
$json = @file_get_contents(__DIR__ .'/../../data/stops.json');
|
||||
$data = json_decode($json, true);
|
||||
|
||||
$filteredData = array_filter($data, function($item) {
|
||||
return isset($item['fields']['mode']) && $item['fields']['mode'] === 'METRO';
|
||||
});
|
||||
|
||||
$query = $conn->prepare("INSERT INTO stops (stopId, name, lineId) VALUES (?, ?, ?)");
|
||||
$conn->beginTransaction();
|
||||
foreach ($filteredData as $item) {
|
||||
$fields = $item['fields'];
|
||||
if (isset($fields['id_ref_zda'], $fields['nom_zda'], $fields['indice_lig'])) {
|
||||
try {
|
||||
$query->execute([$fields['id_ref_zda'], $fields['nom_zda'], $fields['indice_lig']]);
|
||||
} catch (PDOException $e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$conn->commit();
|
||||
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['refreshData'])) {
|
||||
$success = refreshData();
|
||||
if ($success) {
|
||||
$_SESSION['message'] = '<div class="alert alert-success text-center" role="alert">Data refreshed successfully.</div>';
|
||||
} else {
|
||||
$_SESSION['message'] = '<div class="alert alert-danger text-center" role="alert">Failed to refresh data.</div>';
|
||||
}
|
||||
header("Location: " . $_SERVER['REQUEST_URI']);
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['userId'])) {
|
||||
|
||||
|
||||
if (isset($_POST['delete'])) {
|
||||
if ($_POST['userId'] == $_SESSION['user_id']) {
|
||||
echo 222;
|
||||
$_SESSION['message'] = '<div class="alert alert-danger text-center" role="alert">You cannot delete yourself.</div>';
|
||||
header("Location: " . $_SERVER['REQUEST_URI']);
|
||||
exit();
|
||||
@@ -17,6 +92,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['userId'])) {
|
||||
header("Location: " . $_SERVER['REQUEST_URI']);
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
$password = !empty($_POST['password']) ? $_POST['password'] : null;
|
||||
$_POST['is_admin'] = isset($_POST['is_admin']) ? 1 : 0;
|
||||
|
||||
@@ -13,7 +13,7 @@ $directions = [];
|
||||
if (isset($data['Siri']['ServiceDelivery']['StopMonitoringDelivery'][0]['MonitoredStopVisit'])) {
|
||||
foreach ($data['Siri']['ServiceDelivery']['StopMonitoringDelivery'][0]['MonitoredStopVisit'] as $visit) {
|
||||
$vehicleJourney = $visit['MonitoredVehicleJourney'];
|
||||
if (strpos($vehicleJourney['OperatorRef']['value'], '.' . $lineId . '.' . $lineId) !== false) {
|
||||
if (isset($vehicleJourney['MonitoredCall']['ExpectedArrivalTime'])) {
|
||||
$direction = $vehicleJourney['DirectionName'][0]['value'];
|
||||
$expectedArrival = $vehicleJourney['MonitoredCall']['ExpectedArrivalTime'];
|
||||
$expectedDeparture = $vehicleJourney['MonitoredCall']['ExpectedDepartureTime'];
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($station['name']); ?></td>
|
||||
<td class="text-end">
|
||||
<?php if (isFavorite($_SESSION['user_id'], $station['id'], $i)): ?>
|
||||
<button class="btn btn-danger remove-stop" data-station-id="<?= $station['id'] ?>" data-line-id="<?= $i ?>">Revoke</button>
|
||||
<?php if (isFavorite($_SESSION['user_id'], $station['stopId'], $i)): ?>
|
||||
<button class="btn btn-danger remove-stop" data-station-id="<?= $station['stopId'] ?>" data-line-id="<?= $i ?>">Revoke</button>
|
||||
<?php else: ?>
|
||||
<button class="btn btn-success add-stop" data-station-id="<?= $station['id'] ?>" data-line-id="<?= $i ?>">Add</button>
|
||||
<button class="btn btn-success add-stop" data-station-id="<?= $station['stopId'] ?>" data-line-id="<?= $i ?>">Add</button>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -11,4 +11,4 @@
|
||||
}
|
||||
?>
|
||||
</head>
|
||||
<body style="display:block;">
|
||||
<body style="display:none;">
|
||||
Reference in New Issue
Block a user