@@ -1,4 +1,3 @@
|
||||
<?php if($view->user->getAccessLevel() == 1): ?>
|
||||
<!-- Create Facility Modal -->
|
||||
<div class="modal fade" id="createModal" tabindex="-1" aria-labelledby="createModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
@@ -10,136 +9,115 @@
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body p-4">
|
||||
<form id="createForm">
|
||||
<input type="hidden" name="action" value="create">
|
||||
|
||||
<!-- Create facility form -->
|
||||
<form id="createFacilityForm">
|
||||
<!-- Form fields -->
|
||||
<div class="mb-3">
|
||||
<label for="titlCreate" class="form-label">Title</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text bg-light border-end-0">
|
||||
<i class="bi bi-tag text-success"></i>
|
||||
</span>
|
||||
<input type="text" class="form-control border-start-0" id="titlCreate" name="titlCreate" placeholder="Enter facility title" required>
|
||||
</div>
|
||||
<label for="createTitle" class="form-label">Facility Name</label>
|
||||
<input type="text" class="form-control" id="createTitle" name="title" required>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="cateCreate" class="form-label">Category</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text bg-light border-end-0">
|
||||
<i class="bi bi-bookmark text-success"></i>
|
||||
</span>
|
||||
<input type="text" class="form-control border-start-0" id="cateCreate" name="cateCreate" placeholder="Enter facility category" required>
|
||||
</div>
|
||||
<label for="createCategory" class="form-label">Category</label>
|
||||
<select class="form-select" id="createCategory" name="category" required>
|
||||
<option value="" selected disabled>Select a category</option>
|
||||
<option value="recycling">Recycling Center</option>
|
||||
<option value="compost">Composting Facility</option>
|
||||
<option value="ewaste">E-Waste Collection</option>
|
||||
<option value="donation">Donation Center</option>
|
||||
<option value="refill">Refill Station</option>
|
||||
<option value="repair">Repair Shop</option>
|
||||
<option value="garden">Community Garden</option>
|
||||
<option value="market">Farmers Market</option>
|
||||
<option value="other">Other</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="descCreate" class="form-label">Description</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text bg-light border-end-0">
|
||||
<i class="bi bi-card-text text-success"></i>
|
||||
</span>
|
||||
<textarea class="form-control border-start-0" id="descCreate" name="descCreate" placeholder="Enter facility description" rows="3" required></textarea>
|
||||
</div>
|
||||
<label for="createDescription" class="form-label">Description</label>
|
||||
<textarea class="form-control" id="createDescription" name="description" rows="3" required></textarea>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-3">
|
||||
<label for="hnumCreate" class="form-label">House/Building Number</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text bg-light border-end-0">
|
||||
<i class="bi bi-house text-success"></i>
|
||||
</span>
|
||||
<input type="text" class="form-control border-start-0" id="hnumCreate" name="hnumCreate" placeholder="Enter number" required>
|
||||
</div>
|
||||
<label for="createLatitude" class="form-label">Latitude</label>
|
||||
<input type="number" step="any" class="form-control" id="createLatitude" name="latitude" required>
|
||||
</div>
|
||||
|
||||
<div class="col-md-6 mb-3">
|
||||
<label for="strtCreate" class="form-label">Street Name</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text bg-light border-end-0">
|
||||
<i class="bi bi-signpost text-success"></i>
|
||||
</span>
|
||||
<input type="text" class="form-control border-start-0" id="strtCreate" name="strtCreate" placeholder="Enter street name" required>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-3">
|
||||
<label for="townCreate" class="form-label">Town/City</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text bg-light border-end-0">
|
||||
<i class="bi bi-building text-success"></i>
|
||||
</span>
|
||||
<input type="text" class="form-control border-start-0" id="townCreate" name="townCreate" placeholder="Enter town/city" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-6 mb-3">
|
||||
<label for="cntyCreate" class="form-label">County</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text bg-light border-end-0">
|
||||
<i class="bi bi-map text-success"></i>
|
||||
</span>
|
||||
<input type="text" class="form-control border-start-0" id="cntyCreate" name="cntyCreate" placeholder="Enter county" required>
|
||||
</div>
|
||||
<label for="createLongitude" class="form-label">Longitude</label>
|
||||
<input type="number" step="any" class="form-control" id="createLongitude" name="longitude" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="postCreate" class="form-label">Postcode</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text bg-light border-end-0">
|
||||
<i class="bi bi-mailbox text-success"></i>
|
||||
</span>
|
||||
<input type="text" class="form-control border-start-0" id="postCreate" name="postCreate" placeholder="Enter postcode" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-3">
|
||||
<label for="latCreate" class="form-label">Latitude</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text bg-light border-end-0">
|
||||
<i class="bi bi-geo-alt text-success"></i>
|
||||
</span>
|
||||
<input type="text" class="form-control border-start-0" id="latCreate" name="latCreate" placeholder="Enter latitude" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-6 mb-3">
|
||||
<label for="lngCreate" class="form-label">Longitude</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text bg-light border-end-0">
|
||||
<i class="bi bi-geo-alt text-success"></i>
|
||||
</span>
|
||||
<input type="text" class="form-control border-start-0" id="lngCreate" name="lngCreate" placeholder="Enter longitude" required>
|
||||
</div>
|
||||
</div>
|
||||
<label for="createAddress" class="form-label">Address</label>
|
||||
<input type="text" class="form-control" id="createAddress" name="address" required>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="contCreate" class="form-label">Contributor</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 bg-light" id="contCreate" name="contCreate" placeholder="Auto-filled with your username" disabled required>
|
||||
</div>
|
||||
<small class="text-muted">This will be automatically filled with your username</small>
|
||||
<label for="createContact" class="form-label">Contact Information</label>
|
||||
<input type="text" class="form-control" id="createContact" name="contact">
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="createWebsite" class="form-label">Website</label>
|
||||
<input type="url" class="form-control" id="createWebsite" name="website" placeholder="https://">
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="createHours" class="form-label">Operating Hours</label>
|
||||
<input type="text" class="form-control" id="createHours" name="hours" placeholder="e.g., Mon-Fri: 9am-5pm">
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="createStatus" class="form-label">Status</label>
|
||||
<select class="form-select" id="createStatus" name="status" required>
|
||||
<option value="operational">Operational</option>
|
||||
<option value="limited">Limited Service</option>
|
||||
<option value="closed">Temporarily Closed</option>
|
||||
<option value="planned">Planned</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div id="createError" class="alert alert-danger" style="display: none;"></div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer bg-light">
|
||||
<div class="w-100 d-flex justify-content-between">
|
||||
<button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal">Cancel</button>
|
||||
<button type="submit" form="createForm" class="btn btn-success">
|
||||
<i class="bi bi-plus-circle me-1"></i>Create Facility
|
||||
</button>
|
||||
</div>
|
||||
<button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal">Cancel</button>
|
||||
<button type="button" class="btn btn-success" id="createFacilityButton">
|
||||
<i class="bi bi-plus-circle me-1"></i>Create Facility
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<script>
|
||||
// Only allow admin users to access this modal
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const createModal = document.getElementById('createModal');
|
||||
if (createModal) {
|
||||
createModal.addEventListener('show.bs.modal', async function(event) {
|
||||
// Validate authentication with server first
|
||||
let isAdmin = false;
|
||||
if (simpleAuth.isAuthenticated()) {
|
||||
try {
|
||||
// This will validate the token with the server and handle refresh if needed
|
||||
const isValid = await simpleAuth.validateOnLoad();
|
||||
if (isValid) {
|
||||
isAdmin = simpleAuth.isAdmin();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error validating authentication:', error);
|
||||
isAdmin = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isAdmin) {
|
||||
event.preventDefault();
|
||||
alert('You need administrator privileges to add new facilities.');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
Reference in New Issue
Block a user