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
363 lines (339 sloc) 17.6 KB
<div class="row mt-4">
<div class="col-md-8 mx-auto">
<h3 class="float-start">Aircraft</h3>
<button type="button" class="btn btn-primary float-end mb-2" data-bs-toggle="modal" data-bs-target="#addModal">
New aircraft
</button>
<div style="clear: both"></div>
<?php
if (isset($_POST['addAircraft'])) {
aircraft::add($_POST['company'], $_POST['number'], $_POST['type'], $_POST['age'], $_POST['year'], $_POST['running_hours']);
}
if (isset($_POST['editAircraft'])) {
aircraft::edit($_POST['id'], $_POST['company'], $_POST['number'], $_POST['type'], $_POST['age'], $_POST['year'], $_POST['running_hours']);
}
if (isset($_POST['removeAircraft'])) {
aircraft::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']);
}else {
respond::alert('warning', '', 'All fields are required');
}
}
if (isset($_POST['removeSchedule'])) {
aircraft::removeSchedule($_POST['id']);
}
$aircrafts = aircraft::all();
?>
<div class="card">
<?php
if ($aircrafts) {
?>
<table class="table table-hover table-striped card-body mb-0">
<thead>
<tr>
<th>Company</th>
<th>Number</th>
<th>Age</th>
<th>Type</th>
<th>Running hours</th>
<th>Status</th>
<th>Date added</th>
<th></th>
</tr>
</thead>
<tbody>
<?php
foreach ($aircrafts as $aircraft) {
$id = $aircraft['id'];
$company = $aircraft['company'];
$age = $aircraft['age'];
$number = $aircraft['number'];
$year = $aircraft['year'];
$aircraft_type = $aircraft['aircraft_type'];
$hours = $aircraft['running_hours'];
$date = new DateTime($aircraft['createdAt']);
$status = aircraft::checkSchedule($id);
?>
<tr>
<td><?= $company ?></td>
<td><?= $number; ?></td>
<td><?= $age ?></td>
<td><?= $aircraft_type ?></td>
<td><?= $hours ?></td>
<td>
<?php
if ($status) {
echo '<span class="text-success">Scheduled</span>';
}else {
echo '<span class="text-danger">Unscheduled</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="
$('.id').val('<?= $id ?>');
$('.company').val('<?= $company ?>');
$('.number').val('<?= $number ?>');
$('.age').val('<?= $age ?>');
$('.year').val('<?= $year ?>');
$('.running_hours').val('<?= $hours ?>');
" href="javascript:;" data-bs-toggle="modal" data-bs-target="#editModal">Edit</a></li>
<li>
<?php
if ($status) {
?>
<a class="dropdown-item" href="javascript:;" onclick="$('.id').val('<?= $id ?>')" data-bs-toggle="modal" data-bs-target="#removeScheduleModal">Remove schedule</a>
<?php
}else {
?>
<a class="dropdown-item" onclick="$('.id').val('<?= $id ?>')" href="javascript:;" data-bs-toggle="modal" data-bs-target="#scheduleModal">Schedule maintenance</a>
<?php
}
?>
</li>
<li><a href="javascript:;" onclick="$('.id').val('<?= $id ?>')" class="dropdown-item text-danger" data-bs-toggle="modal" data-bs-target="#removeModal">Remove aircraft</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: 0px;">No aircraft 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 modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">New aircraft</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="company" class="form-label">Aircraft company</label>
<input type="text" required class="form-control" id="company" name="company" placeholder="Aircraft company">
</div>
<div class="row">
<div class="col-md-6">
<div class="mb-3">
<label for="number" class="form-label">Number</label>
<input type="text" required placeholder="Aircraft number" class="form-control" id="number" name="number">
</div>
</div>
<div class="col-md-6">
<div class="mb-3">
<label for="type" class="form-label">Aircraft type</label>
<select name="type" required id="type" class="form-control">
<option value="">Select aircraft type</option>
<option value="Helicopter">Helicopter</option>
<option value="Turbine">Turbine</option>
</select>
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="mb-3">
<label for="year" class="form-label">Aircraft year</label>
<input type="number" required placeholder="Year of manufacturing" class="form-control" id="year" name="year">
</div>
</div>
<div class="col-md-4">
<div class="mb-3">
<label for="age" class="form-label">Aircraft age</label>
<input type="number" required placeholder="Age of aircraft" class="form-control" id="age" name="age">
</div>
</div>
<div class="col-md-4">
<div class="mb-3">
<label for="running_hours" class="form-label">Running hours</label>
<input type="number" required placeholder="Age of aircraft" class="form-control" id="running_hours" name="running_hours">
</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="addAircraft">Add aircraft</button>
</div>
</form>
</div>
</div>
</div>
<!-- Edit Modal -->
<div class="modal fade" id="editModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Update aircraft</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form action="" method="post">
<input type="hidden" name="id" class="id">
<div class="modal-body">
<div class="mb-3">
<label for="company" class="form-label">Aircraft company</label>
<input type="text" required class="form-control company" id="company" name="company" placeholder="Aircraft company">
</div>
<div class="row">
<div class="col-md-6">
<div class="mb-3">
<label for="number" class="form-label">Number</label>
<input type="text" required placeholder="Aircraft number" class="form-control number" id="number" name="number">
</div>
</div>
<div class="col-md-6">
<div class="mb-3">
<label for="type" class="form-label">Aircraft type</label>
<select name="type" required id="type" class="form-control">
<option value="">Select aircraft type</option>
<option value="Helicopter">Helicopter</option>
<option value="Turbine">Turbine</option>
</select>
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="mb-3">
<label for="year" class="form-label">Aircraft year</label>
<input type="number" required placeholder="Year of manufacturing" class="form-control year" id="year" name="year">
</div>
</div>
<div class="col-md-4">
<div class="mb-3">
<label for="age" class="form-label">Aircraft age</label>
<input type="number" required placeholder="Age of aircraft" class="form-control age" id="age" name="age">
</div>
</div>
<div class="col-md-4">
<div class="mb-3">
<label for="running_hours" class="form-label">Running hours</label>
<input type="number" required placeholder="Age of aircraft" class="form-control running_hours" id="running_hours" name="running_hours">
</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="editAircraft">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 aircraft</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="id">
<p align="center">Are you sure you want to remove this aircraft?</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="removeAircraft">Yes, remove</button>
</div>
</form>
</div>
</div>
</div>
<!-- Assign Task Modal -->
<div class="modal fade" id="scheduleModal" 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">Schedule maintenance</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form action="" method="post">
<input type="hidden" name="aircraft_id" class="id">
<div class="modal-body">
<?php
$engineers = engineer::unscheduledEngineers();
if (!$engineers) {
respond::alert('info', '', 'All engineers has been scheduled for maintenance');
}else {
?>
<div class="mb-3">
<label for="engineers" class="form-label">Engineer</label>
<select name="engineer_id" required class="form-control" id="engineers">
<option value="">Select engineer</option>
<?php
foreach ($engineers as $engineer) {
?>
<option value="<?= $engineer['id'] ?>"><?= $engineer['name'].' - '.$engineer['category'] ?></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="removeScheduleModal" 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 schedule</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="id">
<p align="center">Are you sure you want to remove schedule from this aircraft?</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>