From 935e13d44bd6c4ae5bf94d7336a85cfa69edde78 Mon Sep 17 00:00:00 2001 From: James Pattinson Date: Sun, 16 Mar 2025 17:17:42 +0000 Subject: [PATCH] CSV Download and Notes highlight --- action.php | 4 +- admin.php | 6 ++ download.php | 47 +++++++++++++ input.html | 2 +- pilotppr.php | 3 - testhook.json | 4 +- tower.php | 190 ++++++++++++++++++++++---------------------------- 7 files changed, 141 insertions(+), 115 deletions(-) create mode 100644 download.php diff --git a/action.php b/action.php index a5504f9..a9cba90 100644 --- a/action.php +++ b/action.php @@ -287,11 +287,11 @@ function opDetail() { echo 'Captain' . $row['captain'] . ''; echo 'Arriving From:' . $row['in_from'] . ''; echo 'POB IN'; - echo 'ETA'; + echo 'ETA'; echo 'Fuel' . $row['fuel'] . ''; echo 'POB OUT'; echo 'Outbound To' . $row['out_to'] . ''; - echo 'ETD'; + echo 'ETD'; echo 'Email Address' . $row['email'] . ''; echo 'Phone' . $row['phone'] . ''; echo 'Notes' . $row['notes'] . ''; diff --git a/admin.php b/admin.php index b1f4a3c..190adb9 100644 --- a/admin.php +++ b/admin.php @@ -148,6 +148,7 @@ require_db_auth(); +

@@ -186,6 +187,11 @@ require_db_auth(); selectMonth(); populateYearDropdown(); + function downloadCSV() { + let year = document.getElementById("yearSelect").value; + let month = document.getElementById("monthSelect").value; + window.location.href = `download.php?year=${year}&month=${month}`; + } connect_error) { + die("Connection failed: " . $conn->connect_error); +} + +$year = $_GET['year'] ?? date('Y'); +$month = $_GET['month'] ?? date('n'); + +$datetime = DateTime::createFromFormat('!m', $month); +$monthName = $datetime->format('F'); +$filename = $monthName . $year . '.csv'; + +header('Content-Type: text/csv'); +header('Content-Disposition: attachment;filename=' . $filename); + +$output = fopen('php://output', 'w'); + +$escape = '\\'; // Define the escape character + +// Fetch data +$sql = "SELECT * FROM submitted WHERE status != 'DELETED' and MONTH(eta) = $month and YEAR(eta) = $year ORDER BY eta ASC;"; +$result = $conn->query($sql); + +// Output column headers +$fields = $result->fetch_fields(); +$headers = []; +foreach ($fields as $field) { + $headers[] = $field->name; +} +fputcsv($output, $headers, ',', '"', $escape); + +// Output rows +while ($row = $result->fetch_assoc()) { + fputcsv($output, $row, ',', '"', $escape); +} + +// Close the database connection +$conn->close(); +fclose($output); +?> diff --git a/input.html b/input.html index f9dafad..6b6aef7 100644 --- a/input.html +++ b/input.html @@ -8,7 +8,7 @@ let now = new Date(); let localDatetime = now.toISOString().slice(0, 16); // Format for datetime-local input document.getElementById("eta").value = localDatetime; - document.getElementById("etd").value = localDatetime; + // document.getElementById("etd").value = localDatetime; }); function fetchResults() { diff --git a/pilotppr.php b/pilotppr.php index 9161297..d96229f 100644 --- a/pilotppr.php +++ b/pilotppr.php @@ -146,9 +146,6 @@ function opView($entryId) { echo "

Notes: " . $row['notes'] . "

"; echo ''; - echo '

Dear Pilot,

This is to confirm we have received your PPR information, and we look forward to welcoming you at Swansea Airport.

Please review our arrival procedures prior to your arrival.

To view or cancel your PPR please click the button:

'; - echo 'View PPR'; - echo '

Swansea Airport'; } else { echo ""; diff --git a/testhook.json b/testhook.json index 83e0ff7..4a07c8e 100644 --- a/testhook.json +++ b/testhook.json @@ -18,7 +18,7 @@ }, "data": { "617dd0cd-2d17-4d7f-826b-5348afdb30b3": { - "value": "G-LORD", + "value": "G-YSIR", "name": "Aircraft Registration" }, "148a55d8-5357-49a3-b9aa-2a5d4dc64173": { @@ -34,7 +34,7 @@ "name": "Arriving From" }, "ca4ac44f-0388-4a70-a072-38276ed2ac13": { - "value": "15\/03\/2025 17:22", + "value": "16\/03\/2025 17:22", "name": "ETA" }, "6fc47c54-7383-48fd-93fc-d8080f5ed8f5": { diff --git a/tower.php b/tower.php index fc8dae5..07884d9 100644 --- a/tower.php +++ b/tower.php @@ -140,35 +140,62 @@ require_db_auth(); cursor: pointer; } + /* Add this CSS for the red triangle */ + .red-triangle { + position: relative; + } + + .red-triangle::before { + content: ""; + position: absolute; + top: 0; + left: 0; + width: 0; + height: 0; + border-left: 10px solid red; + border-bottom: 10px solid transparent; + } + + .red-triangle:hover::after { + content: attr(data-notes); + position: absolute; + top: 20px; + left: 0; + background: #fff; + border: 1px solid #ddd; + padding: 5px; + border-radius: 5px; + white-space: nowrap; + z-index: 10; + } + +

Tower Ops

- const now = new Date(); - const currentTime = now.toISOString().slice(11, 16); // Extract HH:MM - - Swal.fire({ - title: "Land Aircraft at time", - html: ``, - icon: "info", - showCancelButton: true, - confirmButtonColor: "#3085d6", - cancelButtonColor: "#d33", - confirmButtonText: "Landed", - preConfirm: () => { - const time = document.getElementById("timepicker").value; - if (!time) { - Swal.showValidationMessage("Please select a time"); - } - return time; - } - - }).then((result) => { - if (result.isConfirmed) { - page="action.php?op=landed&id=" + id + "&time=" + encodeURIComponent(result.value); - var xhr = new XMLHttpRequest(); - xhr.open("GET", page, false); // 'false' makes the request synchronous - xhr.send(); - window.location.reload(true); - } - }); - } - function markCancel(id) { - page="action.php?op=cancel&id=" + id; - var xhr = new XMLHttpRequest(); - xhr.open("GET", page, false); // 'false' makes the request synchronous - xhr.send(); - window.location.reload(true); - } - function openDetail(id) { - page="action.php?op=detail&id=" + id; - var popupWindow = window.open(page, "PopupWindow", "toolbar=no, location=no, directories=no,status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=yes, width=600, height=1100"); - popupWindow.onload = function () { - var contentHeight = popupWindow.document.body.scrollHeight; - var contentWidth = popupWindow.document.body.scrollWidth; - popupWindow.resizeTo(contentWidth + 20, contentHeight + 180); // Adding padding to prevent clipping - }; - - } - - -

Tower Ops

- - +--> -
Inbound PPR
+
Inbound Aircraft
connect_error) { } // Define your SQL query -$sql = "SELECT id, status, ac_reg, ac_type, ac_call, TIME_FORMAT(eta,'%H:%i') AS ETA, fuel, in_from, pob_in FROM submitted WHERE DATE(eta) = CURDATE() AND (status = 'NEW' OR status = 'CANCELED') ORDER BY eta ASC;"; // Replace with your table name +$sql = "SELECT id, status, ac_reg, ac_type, ac_call, TIME_FORMAT(eta,'%H:%i') AS ETA, fuel, in_from, pob_in, notes FROM submitted WHERE DATE(eta) = CURDATE() AND (status = 'NEW' OR status = 'CANCELED') ORDER BY eta ASC;"; // Replace with your table name // Execute the query $result = $conn->query($sql); @@ -296,7 +268,7 @@ if ($result->num_rows > 0) { // Output table headers (assuming column names are known) $fields = $result->fetch_fields(); foreach ($fields as $field) { - if ($field->name != 'status' && $field->name != 'id' && $field->name != 'ac_call') { + if ($field->name != 'notes' && $field->name != 'status' && $field->name != 'id' && $field->name != 'ac_call') { echo '' . htmlspecialchars($field->name ?? '') . ''; } @@ -311,12 +283,14 @@ if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { echo ''; foreach ($row as $key => $value) { - if ($key != 'status' && $key != 'id' && $key != 'ac_call') { + if ($key != 'notes' && $key != 'status' && $key != 'id' && $key != 'ac_call') { if ($key == 'ac_reg' && $row['ac_call'] != NULL) { echo '' . htmlspecialchars($row['ac_call'] ?? '') . "
" . $value . ''; + } else if ($key == 'ac_reg' && !empty($row['notes'])) { + echo '' . htmlspecialchars($value ?? '') . ''; } else { echo '' . htmlspecialchars($value ?? '') . ''; - } + } } } echo ''; @@ -330,14 +304,14 @@ if ($result->num_rows > 0) { ?> -
Booking Out
+
Visiting Aircraft
query($sql); @@ -352,7 +326,7 @@ if ($result->num_rows > 0) { // Output table headers (assuming column names are known) $fields = $result->fetch_fields(); foreach ($fields as $field) { - if ($field->name != 'status' && $field->name != 'id' && $field->name != 'ac_call') { + if ($field->name != 'notes' && $field->name != 'status' && $field->name != 'id' && $field->name != 'ac_call') { echo '' . htmlspecialchars($field->name ?? '') . ''; } @@ -367,12 +341,14 @@ if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { echo ''; foreach ($row as $key => $value) { - if ($key != 'status' && $key != 'id' && $key != 'ac_call') { + if ($key != 'notes' && $key != 'status' && $key != 'id' && $key != 'ac_call') { if ($key == 'ac_reg' && $row['ac_call'] != NULL) { echo '' . htmlspecialchars($row['ac_call'] ?? '') . "
" . $value . ''; + } else if ($key == 'ac_reg' && !empty($row['notes'])) { + echo '' . htmlspecialchars($value ?? '') . ''; } else { echo '' . htmlspecialchars($value ?? '') . ''; - } + } } } echo '';