i finally committed i guess

Signed-off-by: boris <boris@borishub.co.uk>
This commit is contained in:
boris
2025-03-15 01:59:16 +00:00
parent 8de2b7f29e
commit 709596eea2
113 changed files with 25075 additions and 54344 deletions

152
Views/index.phtml Normal file → Executable file
View File

@@ -1,60 +1,104 @@
<?php require('template/header.phtml') ?>
<div class="row">
<div class="col-5 me-auto">
<p><?php echo $view->dbMessage; ?></p>
<?php
/**
* Main index view for the EcoBuddy application
*
* This file serves as the main view for the application, displaying
* a table of facilities with various actions depending on the user's
* access level. It includes modals for creating, updating, deleting,
* and viewing statuses of facilities.
*
* The table is populated dynamically using JavaScript, with the data
* stored in sessionStorage.
*/
require('template/header.phtml')
?>
<div class="row">
<div class="col-12 p-0" id="facilityContent">
<!-- Main content -->
<div class="card shadow-sm border-0 rounded-3">
<!-- Title and add button (admins only) -->
<div class="card-header bg-light py-3">
<div class="d-flex justify-content-between align-items-center">
<div class="d-flex align-items-center">
<h5 class="mb-0 fw-bold text-primary">
<i class="bi bi-geo-alt-fill me-2 text-success"></i>Facilities
</h5>
<!-- Badge showing the number of facilities -->
<span class="badge bg-success rounded-pill ms-2" id="facilityCount"></span>
</div>
<?php if($view->user->getAccessLevel() == 1): ?>
<!-- Add new facility button (admin only) -->
<button type="button" class="btn btn-success" data-bs-toggle="modal" data-bs-target="#createModal">
<i class="bi bi-plus-circle me-1"></i>Add New Facility
</button>
<?php endif; ?>
</div>
</div>
<!-- Pagination controls -->
<div class="card-footer bg-white py-2">
<?php require('template/pagination.phtml');?>
</div>
<!-- Facilities table -->
<div class="card-body p-0">
<div class="table-responsive">
<table class="table table-hover align-middle mb-0" id="facilityTable">
<thead class="table-light">
<tr>
<?php if($view->user->getAccessLevel() == 1): ?>
<th class="fw-semibold" style="width: 40px;">ID</th>
<?php else: ?>
<th class="d-none">ID</th>
<?php endif; ?>
<th class="fw-semibold" style="width: 15%;">Title</th>
<th class="fw-semibold text-center" style="width: 10%;">Category</th>
<th class="fw-semibold" style="width: 25%;">Description</th>
<th class="fw-semibold" style="width: 20%;">Address</th>
<th class="fw-semibold text-center" style="width: 8%;" hidden>Postcode</th>
<th class="fw-semibold text-center" style="width: 12%;">Coordinates</th>
<th class="fw-semibold text-center" style="width: 8%;">Contributor</th>
<th class="fw-semibold text-center" style="width: 10%;">Actions</th>
</tr>
</thead>
<tbody class="border-top-0">
<!-- Table content will be dynamically populated by JavaScript -->
</tbody>
</table>
</div>
</div>
</div>
<form class="col-auto">
<?php require_once('template/createModal.phtml') ?>
</form>
</div>
</div>
<div class="row">
<div class="container-fluid p-3" id="facilityContent">
<table class="table table-bordered">
<thead>
<tr>
<th>Facility ID</th>
<th>Title</th>
<th>Category</th>
<th>Status</th>
<th>Description</th>
<th>Address</th>
<th>Postcode</th>
<th>Lat/Long</th>
<th>Contributor</th>
<?php if($view->user->getAccessLevel() == 1): ?>
<th>Actions</th>
<?php endif; ?>
</tr>
</thead>
<tbody>
<?php foreach ($view->pageData as $facilityData): ?>
<tr>
<td><?= htmlspecialchars($facilityData->getId() ?? 'N/A') ?></td>
<td><?= htmlspecialchars($facilityData->getTitle() ?? 'N/A') ?></td>
<td><?= htmlspecialchars($facilityData->getCategory() ?? 'N/A') ?></td>
<td><?= htmlspecialchars($facilityData->getStatus() ?? 'N/A') ?></td>
<td><?= htmlspecialchars($facilityData->getDescription() ?? 'N/A') ?></td>
<td><?= htmlspecialchars(trim(($facilityData->getHouseNumber() ?? '') . ' ' .
($facilityData->getStreetName() ?? '') . ' ' .
($facilityData->getCounty() ?? '') . ' ' .
($facilityData->getTown() ?? ''))) ?></td>
<td><?= htmlspecialchars($facilityData->getPostcode() ?? 'N/A') ?></td>
<td><?= htmlspecialchars(($facilityData->getLat() ?? 'N/A') . ', ' .
($facilityData->getLng() ?? 'N/A')) ?></td>
<td><?= htmlspecialchars($facilityData->getContributor() ?? 'N/A') ?></td>
<?php if($view->user->getAccessLevel() == 1): ?>
<td class="btn-group">
<?php require("template/updateModal.phtml") ?>
<?php require("template/deleteModal.phtml") ?>
</td>
<?php endif; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<!-- Include modal templates -->
<?php require('template/createModal.phtml') ?>
<?php require('template/updateModal.phtml') ?>
<?php require('template/deleteModal.phtml') ?>
<?php require('template/statusModal.phtml') ?>
<!-- Script to update the facility count badge -->
<script>
document.addEventListener('DOMContentLoaded', function() {
// Update facility count badge based on data in sessionStorage
const updateFacilityCount = () => {
const facilityData = JSON.parse(sessionStorage.getItem('facilityData') || '[]');
const countBadge = document.getElementById('facilityCount');
if (countBadge) {
countBadge.textContent = `${facilityData.length} facilities`;
}
};
// Initial count update when the page loads
updateFacilityCount();
// Listen for changes in facility data to update the count
window.addEventListener('storage', function(e) {
if (e.key === 'facilityData') {
updateFacilityCount();
}
});
});
</script>
<?php require('template/footer.phtml') ?>
<?php require('template/footer.phtml');?>