Skip to content
Permalink
361f1f2641
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
310 lines (292 sloc) 14.6 KB
<div class="row mt-4">
<div class="col-md-8 mx-auto">
<h3 class="float-start">Engineers</h3>
<button type="button" class="btn btn-primary float-end mb-2" data-bs-toggle="modal" data-bs-target="#addModal">
New engineer
</button>
<div style="clear: both"></div>
<?php
if (isset($_POST['addEngineer'])) {
engineer::add($_POST['name'], $_POST['category'], $_POST['email'], $_POST['password']);
}
if (isset($_POST['editEngineer'])) {
engineer::edit($_POST['id'], $_POST['name'], $_POST['category'], $_POST['email']);
}
if (isset($_POST['removeEngineer'])) {
engineer::remove($_POST['id']);
}
if (isset($_POST['addSchedule'])) {
if (isset($_POST['aircraft_id']) && isset($_POST['engineer_id'])) {
schedule::add($_POST['aircraft_id'], $_POST['engineer_id'], $_POST['task'], true);
}else {
respond::alert('warning', '', 'All fields are required');
}
}
if (isset($_POST['removeSchedule'])) {
engineer::removeSchedule($_POST['id']);
}
$engineers = engineer::all();
?>
<div class="card">
<?php
if ($engineers) {
?>
<table class="table table-hover table-striped card-body mb-0">
<thead>
<tr>
<th>Name</th>
<th>Email address</th>
<th>Category</th>
<th>Maintenance</th>
<th>Date added</th>
<th></th>
</tr>
</thead>
<tbody>
<?php
foreach ($engineers as $engineer) {
$date = new DateTime($engineer['createdAt']);
$engineer_id = $engineer['id'];
$name = $engineer['name'];
$email = $engineer['email'];
// h:i A
?>
<tr>
<td><?= $name; ?></td>
<td><?= $email; ?></td>
<td><?= $engineer['category']; ?></td>
<td>
<?php
$status = engineer::checkSchedule($engineer_id);
if ($status) {
echo '<span class="text-success">Assigned</span>';
}else {
echo '<span class="text-danger">Unassigned</span>';
}
?>
</td>
<td><?= $date->format("F d, Y"); ?></td>
<td>
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton1" data-bs-toggle="dropdown" aria-expanded="false">
Options
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuButton1">
<li>
<a class="dropdown-item" onclick="
$('.engineer_id').val('<?= $engineer_id ?>');
$('.name').val('<?= $name ?>');
$('.email').val('<?= $email ?>');
" href="javascript:;" data-bs-toggle="modal" data-bs-target="#updateModal">Edit</a>
</li>
<li>
<?php
if ($status) {
?>
<a class="dropdown-item" onclick="$('.engineer_id').val('<?= $engineer_id ?>')" href="javascript:;" data-bs-toggle="modal" data-bs-target="#removeTaskModal">Remove task</a>
<?php
}else {
?>
<a class="dropdown-item" onclick="$('.engineer_id').val('<?= $engineer_id ?>')" href="javascript:;" data-bs-toggle="modal" data-bs-target="#assignTaskModal">Assign task</a>
<?php
}
?>
</li>
<li><a href="javascript:;" onclick="$('.engineer_id').val('<?= $engineer_id ?>')" class="dropdown-item text-danger" data-bs-toggle="modal" data-bs-target="#removeModal">Remove engineer</a></li>
</ul>
</div>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
<?php
}else {
?>
<div class="alert alert-info alert-custom alert-dismissible" style="text-align: center; margin-bottom: 0; width: 100%;">
<p style="margin-bottom: 0;">No engineer has been added</p>
</div>
<?php
}
?>
</div>
</div>
</div>
<!-- Add Modal -->
<div class="modal fade" id="addModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">New engineer</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form action="" method="post">
<div class="modal-body">
<div class="mb-3">
<label for="exampleFormControlInput1" class="form-label">Name</label>
<input type="text" required name="name" class="form-control" id="exampleFormControlInput1" placeholder="Engineer name">
</div>
<div class="mb-3">
<label for="category" class="form-label">Category</label>
<select name="category" id="category" class="form-control">
<option value="Category B1 Mechanic">Category B1 Mechanic</option>
</select>
</div>
<hr>
<div class="row">
<div class="col-md-6">
<div class="mb-3">
<label for="email" class="form-label">Email address</label>
<input type="email" name="email" class="email form-control" id="editEmail" placeholder="Engineer email address">
</div>
</div>
<div class="col-md-6">
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" name="password" class="email form-control" id="password" placeholder="Account password">
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-primary" name="addEngineer">Add engineer</button>
</div>
</form>
</div>
</div>
</div>
<!-- edit Modal -->
<div class="modal fade" id="updateModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Update engineer</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form action="" method="post">
<div class="modal-body">
<input type="hidden" name="id" class="engineer_id">
<div class="mb-3">
<label for="exampleFormControlInput1" class="form-label">Name</label>
<input type="text" name="name" required class="name form-control" id="exampleFormControlInput1" placeholder="Engineer name">
</div>
<div class="row">
<div class="col-md-6">
<div class="mb-3">
<label for="editEmail" class="form-label">Email address</label>
<input type="email" required name="email" class="email form-control" id="editEmail" placeholder="Engineer email address">
</div>
</div>
<div class="col-md-6">
<div class="mb-3">
<label for="category" class="form-label">Category</label>
<select name="category" id="category" class="form-control">
<option value="Category B1 Mechanic">Category B1 Mechanic</option>
</select>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-primary" name="editEngineer">Save changes</button>
</div>
</form>
</div>
</div>
</div>
<!-- remove Modal -->
<div class="modal fade" id="removeModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Remove engineer</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form action="" method="post">
<div class="modal-body">
<div class="mb-3">
<input type="hidden" name="id" class="engineer_id">
<p align="center">Are you sure you want to remove this engineer?</p>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-danger" name="removeEngineer">Yes, remove</button>
</div>
</form>
</div>
</div>
</div>
<!-- Assign Task Modal -->
<div class="modal fade" id="assignTaskModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Assign task</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form action="" method="post">
<input type="hidden" name="engineer_id" class="engineer_id">
<div class="modal-body">
<?php
$aircraft = aircraft::unscheduledAircraft();
if (!$aircraft) {
respond::alert('info', '', 'All aircraft has been scheduled for maintenance');
}else {
?>
<div class="mb-3">
<label for="aircraft" class="form-label">Aircraft</label>
<select name="aircraft_id" required class="form-control" id="aircraft">
<option value="">Select aircraft</option>
<?php
foreach ($aircraft as $aircraft_) {
?>
<option value="<?= $aircraft_['id'] ?>"><?= $aircraft_['company'].' - '.$aircraft_['number'] ?></option>
<?php
}
?>
</select>
</div>
<?php
}
?>
<div class="mb-3">
<label for="task" class="form-label">Task</label>
<textarea name="task" required class="form-control" id="task" rows="3"></textarea>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-primary" name="addSchedule">Assign</button>
</div>
</form>
</div>
</div>
</div>
<!-- Remove Task Modal -->
<div class="modal fade" id="removeTaskModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Remove task</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form action="" method="post">
<div class="modal-body">
<div class="mb-3">
<input type="hidden" name="id" class="engineer_id">
<p align="center">Are you sure you want to remove task from this engineer?</p>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-danger" name="removeSchedule">Yes, remove</button>
</div>
</form>
</div>
</div>
</div>