321 lines
17 KiB
PHTML
Executable File
321 lines
17 KiB
PHTML
Executable File
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<meta name="description" content="EcoBuddy - Sustainable facilities management platform">
|
|
<meta name="author" content="">
|
|
<link rel="icon" type="image/x-icon" href="/images/ecoBuddy_x32.png">
|
|
|
|
<!-- Bootstrap core CSS from CDN for faster loading -->
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
|
|
|
|
<!-- CSS theme -->
|
|
<link href="/public/css/my-style.css" rel="stylesheet">
|
|
|
|
<!-- Bootstrap Icons -->
|
|
<link href="/public/css/bootstrap-icons.css" rel="stylesheet">
|
|
|
|
<!-- Leaflet -->
|
|
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=" crossorigin="" />
|
|
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js" integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo=" crossorigin=""></script>
|
|
|
|
<!-- Dynamic page title based on the current page -->
|
|
<title>Ecobuddy - <?php echo $view->pageTitle; ?></title>
|
|
|
|
<!-- Load simplified authentication helper -->
|
|
<script src="/public/js/simpleAuth.js"></script>
|
|
|
|
<!-- Load API client -->
|
|
<script src="/public/js/apiClient.js"></script>
|
|
|
|
<!-- Load facility data script -->
|
|
<script src="/public/js/facilityData.js"></script>
|
|
|
|
<!-- Initialise facility data from PHP server-side data -->
|
|
<script>
|
|
<?php if (isset($view->facilityDataSet) && is_array($view->facilityDataSet)): ?>
|
|
try {
|
|
// Convert PHP data to JavaScript object with proper encoding
|
|
// Using JSON_UNESCAPED_SLASHES and JSON_UNESCAPED_UNICODE for proper character handling
|
|
const initialData = <?php echo json_encode($view->facilityDataSet,
|
|
JSON_UNESCAPED_SLASHES |
|
|
JSON_UNESCAPED_UNICODE |
|
|
JSON_PARTIAL_OUTPUT_ON_ERROR
|
|
); ?>;
|
|
|
|
// Validate and store data in sessionStorage for use across the application
|
|
if (Array.isArray(initialData) && initialData.length > 0) {
|
|
sessionStorage.setItem('facilityData', JSON.stringify(initialData));
|
|
|
|
// Initialize based on DOM state to ensure scripts run at the right time
|
|
if (document.readyState === 'complete' || document.readyState === 'interactive') {
|
|
if (typeof initialiseFacilityData === 'function') {
|
|
initialiseFacilityData(initialData);
|
|
}
|
|
} else {
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
if (typeof initialiseFacilityData === 'function') {
|
|
initialiseFacilityData(initialData);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
// Add client-side authentication check to update UI
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
// Check if user is authenticated on the client side
|
|
if (window.auth && window.auth.isAuthenticated()) {
|
|
console.log('User is authenticated on client side');
|
|
|
|
// Get user data
|
|
const user = window.auth.getUser();
|
|
if (user) {
|
|
console.log('User data:', user);
|
|
|
|
// Hide login button if it exists
|
|
const loginButton = document.getElementById('loginButton');
|
|
if (loginButton) {
|
|
loginButton.style.display = 'none';
|
|
}
|
|
|
|
// Hide login modal if it exists
|
|
const loginModal = document.getElementById('loginModal');
|
|
if (loginModal) {
|
|
loginModal.style.display = 'none';
|
|
}
|
|
|
|
// Show user menu
|
|
const userMenuContainer = document.createElement('div');
|
|
userMenuContainer.className = 'user-menu';
|
|
userMenuContainer.innerHTML = `
|
|
<div class="user-avatar">
|
|
<i class="bi bi-person-fill text-success"></i>
|
|
</div>
|
|
<div class="dropdown">
|
|
<button class="btn btn-light dropdown-toggle" type="button" id="userMenuButton" data-bs-toggle="dropdown" aria-expanded="false">
|
|
${user.username}
|
|
</button>
|
|
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="userMenuButton">
|
|
<li><a class="dropdown-item" href="#"><i class="bi bi-person me-2"></i>Profile</a></li>
|
|
<li><a class="dropdown-item" href="#"><i class="bi bi-gear me-2"></i>Settings</a></li>
|
|
<li><hr class="dropdown-divider"></li>
|
|
<li><button class="dropdown-item text-danger" id="logoutButton"><i class="bi bi-box-arrow-right me-2"></i>Logout</button></li>
|
|
</ul>
|
|
</div>
|
|
`;
|
|
|
|
// Replace login button with user menu
|
|
if (loginButton) {
|
|
loginButton.parentNode.replaceChild(userMenuContainer, loginButton);
|
|
}
|
|
|
|
// Add logout button handler
|
|
const logoutButton = document.getElementById('logoutButton');
|
|
if (logoutButton) {
|
|
logoutButton.addEventListener('click', async function() {
|
|
await window.auth.logout();
|
|
window.location.reload();
|
|
});
|
|
}
|
|
}
|
|
}
|
|
});
|
|
} catch (error) {
|
|
console.error('Error processing facility data:', error);
|
|
}
|
|
<?php endif; ?>
|
|
</script>
|
|
</head>
|
|
|
|
<body role="document">
|
|
<!-- Navigation bar -->
|
|
<nav class="navbar navbar-expand-lg navbar-light bg-white shadow-sm sticky-top">
|
|
<div class="container-fluid px-3">
|
|
<!-- Brand logo and name -->
|
|
<a class="navbar-brand d-flex align-items-center" href="/index.php">
|
|
<img src="/images/ecoBuddy_x64.png" alt="EcoBuddy Logo" width="48" height="48" class="me-2">
|
|
<span class="fw-bold text-success">EcoBuddy</span>
|
|
</a>
|
|
|
|
<!-- Mobile menu toggle -->
|
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarContent"
|
|
aria-controls="navbarContent" aria-expanded="false" aria-label="Toggle navigation">
|
|
<span class="navbar-toggler-icon"></span>
|
|
</button>
|
|
|
|
<!-- Navigation content -->
|
|
<div class="collapse navbar-collapse" id="navbarContent">
|
|
<!-- Main navigation links -->
|
|
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
|
<li class="nav-item">
|
|
<a class="nav-link active" aria-current="page" href="/index.php">
|
|
<i class="bi bi-house-fill me-1"></i>Home
|
|
</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="/map.php">
|
|
<i class="bi bi-map-fill me-1"></i>Map
|
|
</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="/about.php">
|
|
<i class="bi bi-info-circle-fill me-1"></i>About
|
|
</a>
|
|
</li>
|
|
</ul>
|
|
|
|
<!-- Search and filter controls -->
|
|
<div class="d-flex flex-column flex-lg-row search-controls mx-auto">
|
|
<form class="d-flex flex-column flex-lg-row gap-2 w-100" role="search" action="" method="POST">
|
|
<div class="input-group">
|
|
<span class="input-group-text bg-light border-end-0">
|
|
<i class="bi bi-sort-alpha-down text-success"></i>
|
|
</span>
|
|
<select name="sort" class="form-select border-start-0 filter-control" id="sort">
|
|
<option value="title">Title</option>
|
|
<option value="category">Category</option>
|
|
<option value="status">Status</option>
|
|
<option value="description">Description</option>
|
|
<option value="streetName">Street</option>
|
|
<option value="county">County</option>
|
|
<option value="town">Town</option>
|
|
<option value="postcode">Postcode</option>
|
|
<option value="contributor">Contributor</option>
|
|
</select>
|
|
<select class="form-select sort-control" name="dir" id="dir" data-order="asc">
|
|
<option value="asc">Asc</option>
|
|
<option value="desc">Desc</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="input-group">
|
|
<span class="input-group-text bg-light border-end-0">
|
|
<i class="bi bi-filter-circle-fill text-success"></i>
|
|
</span>
|
|
<select name="filterCat" class="form-select border-start-0 filter-control" id="filterCat">
|
|
<option value="">All</option>
|
|
<option value="title">Title</option>
|
|
<option value="category">Category</option>
|
|
<option value="status">Status</option>
|
|
<option value="description">Description</option>
|
|
<option value="streetName">Street</option>
|
|
<option value="county">County</option>
|
|
<option value="town">Town</option>
|
|
<option value="postcode">Postcode</option>
|
|
<option value="contributor">Contributor</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="input-group">
|
|
<span class="input-group-text bg-light border-end-0">
|
|
<i class="bi bi-search text-success"></i>
|
|
</span>
|
|
<input class="form-control border-start-0" id="searchInput" type="search" name="filter" placeholder="Search..." aria-label="Search">
|
|
</div>
|
|
</form>
|
|
</div>
|
|
|
|
<!-- User account section -->
|
|
<div class="ms-lg-3 mt-3 mt-lg-0">
|
|
<?php if(!$view->user->isLoggedIn()): ?>
|
|
<button type="button" class="btn btn-success" id="loginButton" data-bs-toggle="modal" data-bs-target="#loginModal">
|
|
<i class="bi bi-box-arrow-in-right me-1"></i>Login
|
|
</button>
|
|
<?php else: ?>
|
|
<div class="user-menu">
|
|
<div class="user-avatar">
|
|
<i class="bi bi-person-fill text-success"></i>
|
|
</div>
|
|
<div class="dropdown">
|
|
<button class="btn btn-light dropdown-toggle" type="button" id="userMenuButton" data-bs-toggle="dropdown" aria-expanded="false">
|
|
<?php echo $view->user->getUsername(); ?>
|
|
</button>
|
|
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="userMenuButton">
|
|
<li><a class="dropdown-item" href="#"><i class="bi bi-person me-2"></i>Profile</a></li>
|
|
<li><a class="dropdown-item" href="#"><i class="bi bi-gear me-2"></i>Settings</a></li>
|
|
<li><hr class="dropdown-divider"></li>
|
|
<li><button class="dropdown-item text-danger" id="logoutButton"><i class="bi bi-box-arrow-right me-2"></i>Logout</button></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<!-- Login Modal -->
|
|
<?php if(!$view->user->isLoggedIn()): ?>
|
|
<div class="modal fade" id="loginModal" tabindex="-1" aria-labelledby="loginModalLabel" aria-hidden="true">
|
|
<div class="modal-dialog modal-dialog-centered">
|
|
<div class="modal-content border-0 shadow">
|
|
<div class="modal-header bg-light">
|
|
<h5 class="modal-title" id="loginModalLabel">
|
|
<i class="bi bi-box-arrow-in-right text-success me-2"></i>Login to EcoBuddy
|
|
</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
</div>
|
|
<div class="modal-body p-4">
|
|
<form id="loginForm">
|
|
<div class="mb-3">
|
|
<label for="username" class="form-label">Username</label>
|
|
<div class="input-group">
|
|
<span class="input-group-text bg-light border-end-0">
|
|
<i class="bi bi-person text-success"></i>
|
|
</span>
|
|
<input type="text" class="form-control border-start-0" id="username" name="username" placeholder="Enter your username" required>
|
|
</div>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="password" class="form-label">Password</label>
|
|
<div class="input-group">
|
|
<span class="input-group-text bg-light border-end-0">
|
|
<i class="bi bi-lock text-success"></i>
|
|
</span>
|
|
<input type="password" class="form-control border-start-0" id="password" name="password" placeholder="Enter your password" required>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="loginError" class="alert alert-danger" style="display: none;"></div>
|
|
|
|
<div class="row captcha-container" style="display: none;">
|
|
<!-- CAPTCHA Display -->
|
|
<div class="col-md-6 mb-3">
|
|
<label for="captchaCode" class="form-label">CAPTCHA Code</label>
|
|
<input type="text" class="form-control bg-light" id="captchaCode" name="generatedCaptcha" value="" readonly>
|
|
</div>
|
|
|
|
<!-- CAPTCHA Input -->
|
|
<div class="col-md-6 mb-3">
|
|
<label for="captchaInput" class="form-label">Enter CAPTCHA</label>
|
|
<input type="text" class="form-control" id="captchaInput" name="captchaInput" placeholder="Enter code">
|
|
</div>
|
|
</div>
|
|
|
|
<div class="d-grid gap-2 mt-4">
|
|
<button type="submit" class="btn btn-success">
|
|
<i class="bi bi-box-arrow-in-right me-2"></i>Login
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
<div class="modal-footer bg-light">
|
|
<div class="w-100 d-flex justify-content-between align-items-center">
|
|
<small class="text-muted">Don't have an account? <a href="" onclick="alert('Please contact the administrator to create an account.');" class="text-success">Register</a></small>
|
|
<button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal">Close</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<!-- Main content container -->
|
|
<div class="container-fluid py-4 px-3">
|
|
<div class="row" id="content">
|
|
|
|
|
|
|