318 lines
10 KiB
PHP
318 lines
10 KiB
PHP
<?php
|
|
include("functions.php");
|
|
require_db_auth();
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta http-equiv="refresh" content="300">
|
|
<script>
|
|
document.addEventListener("DOMContentLoaded", function() {
|
|
let rows = document.querySelectorAll("table tbody tr");
|
|
|
|
rows.forEach(row => {
|
|
let fuelCell = row.cells[3]; // Get the "Fuel" cell (index 3)
|
|
|
|
if (fuelCell.textContent == "100LL") {
|
|
row.classList.add("highlight100LL"); // Add the class
|
|
} else if (fuelCell.textContent == "JET A1") {
|
|
row.classList.add("highlightJET"); // Add the class
|
|
}
|
|
});
|
|
|
|
// Sorting functionality
|
|
let table = document.querySelector("table");
|
|
let headers = table.querySelectorAll("th");
|
|
let sortDirection = {}; // Track sort direction for each column
|
|
|
|
headers.forEach((header, index) => {
|
|
header.addEventListener("click", function() {
|
|
let direction = sortDirection[index] === "asc" ? "desc" : "asc";
|
|
sortDirection[index] = direction;
|
|
sortTable(table, index, direction);
|
|
|
|
// Update visual indication
|
|
headers.forEach(h => h.classList.remove("sorted-asc", "sorted-desc"));
|
|
header.classList.add(direction === "asc" ? "sorted-asc" : "sorted-desc");
|
|
});
|
|
});
|
|
|
|
function sortTable(table, columnIndex, direction) {
|
|
let rows = Array.from(table.querySelectorAll("tbody tr"));
|
|
let isDate = !isNaN(Date.parse(rows[0].cells[columnIndex]?.textContent.trim() || ""));
|
|
let isNumeric = !isNaN(rows[0].cells[columnIndex]?.textContent.trim() || "");
|
|
let sortedRows = rows.sort((a, b) => {
|
|
let aText = a.cells[columnIndex]?.textContent.trim() || null;
|
|
let bText = b.cells[columnIndex]?.textContent.trim() || null;
|
|
|
|
if (aText === null || bText === null) {
|
|
return aText === null ? 1 : -1; // Place null/empty values at the bottom
|
|
}
|
|
|
|
if (isDate) {
|
|
let aDate = new Date(aText);
|
|
let bDate = new Date(bText);
|
|
return direction === "asc" ? aDate - bDate : bDate - aDate;
|
|
} else if (isNumeric) {
|
|
return direction === "asc" ? aText - bText : bText - aText;
|
|
} else {
|
|
return direction === "asc" ? aText.localeCompare(bText) : bText.localeCompare(aText);
|
|
}
|
|
});
|
|
|
|
let tbody = table.querySelector("tbody");
|
|
tbody.innerHTML = "";
|
|
sortedRows.forEach(row => tbody.appendChild(row));
|
|
}
|
|
});
|
|
</script>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Swansea Daily PPR</title>
|
|
<style>
|
|
|
|
/* Styling for the table */
|
|
table {
|
|
width: 90%;
|
|
border-collapse: collapse;
|
|
margin: 20px 0;
|
|
margin-left: auto; /* Automatically adjusts left margin */
|
|
margin-right: auto; /* Automatically adjusts right margin */
|
|
|
|
}
|
|
table, th, td {
|
|
border: 1px solid #ddd;
|
|
}
|
|
th {
|
|
padding: 2px;
|
|
text-align: center;
|
|
}
|
|
td {
|
|
padding: 2px;
|
|
text-align: center;
|
|
font-family: Arial, sans-serif;
|
|
font-size: 8pt;
|
|
}
|
|
th {
|
|
background-color: #f2f2f2;
|
|
}
|
|
tr:nth-child(even) {
|
|
background-color: #f9f9f9;
|
|
}
|
|
tr:hover {
|
|
background-color: #f1f1f1;
|
|
}
|
|
|
|
.highlight100LL {
|
|
background-color: #ADD8E6 !important;
|
|
#font-weight: bold;
|
|
}
|
|
|
|
.highlightJET {
|
|
background-color: yellow !important; /* Allow it to override the odd/even shading */
|
|
#font-weight: bold;
|
|
}
|
|
|
|
button {
|
|
padding: 10px 20px;
|
|
font-size: 1rem;
|
|
background-color: #007bff;
|
|
color: white;
|
|
border: none;
|
|
border-radius: 5px;
|
|
cursor: pointer;
|
|
transition: 0.3s;
|
|
}
|
|
|
|
button:hover {
|
|
background-color: #0056b3;
|
|
}
|
|
|
|
select {
|
|
padding: 10px;
|
|
font-size: 16px;
|
|
border: 1px solid #ccc;
|
|
border-radius: 5px;
|
|
}
|
|
|
|
/* Add styles for sorted columns */
|
|
th.sorted-asc::after {
|
|
content: " ▲";
|
|
font-size: 0.8em;
|
|
}
|
|
th.sorted-desc::after {
|
|
content: " ▼";
|
|
font-size: 0.8em;
|
|
}
|
|
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<script>
|
|
function markLanded(id) {
|
|
page="action.php?op=landed&id=" + id;
|
|
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 deletePpr(id) {
|
|
page="action.php?op=delete&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
|
|
};
|
|
|
|
}
|
|
</script>
|
|
<center><h2>Swansea Inbound PPR ADMIN</h2></center>
|
|
|
|
<div class="container">
|
|
<h2>Select a Month</h2>
|
|
<select id="monthSelect">
|
|
<option value="1">January</option>
|
|
<option value="2">February</option>
|
|
<option value="3">March</option>
|
|
<option value="4">April</option>
|
|
<option value="5">May</option>
|
|
<option value="6">June</option>
|
|
<option value="7">July</option>
|
|
<option value="8">August</option>
|
|
<option value="9">September</option>
|
|
<option value="10">October</option>
|
|
<option value="11">November</option>
|
|
<option value="12">December</option>
|
|
</select>
|
|
<select id="yearSelect"></select>
|
|
<button onclick="selectMonthYear()">Submit</button>
|
|
<button onclick="downloadCSV()">Download CSV</button>
|
|
<p id="output"></p>
|
|
</div>
|
|
|
|
<script>
|
|
function populateYearDropdown() {
|
|
let yearSelect = document.getElementById("yearSelect");
|
|
let currentYear = new Date().getFullYear();
|
|
let startYear = currentYear;
|
|
let endYear = currentYear - 10; // Last 10 years
|
|
|
|
for (let year = startYear; year >= endYear; year--) { // Descending order
|
|
let option = document.createElement("option");
|
|
option.value = year;
|
|
option.textContent = year;
|
|
if (year === currentYear) {
|
|
option.selected = true; // Set default to current year
|
|
}
|
|
yearSelect.appendChild(option);
|
|
}
|
|
}
|
|
|
|
function selectMonthYear() {
|
|
let month = document.getElementById("monthSelect").value;
|
|
let year = document.getElementById("yearSelect").value;
|
|
window.location.href = `admin.php?year=${year}&month=${month}`;
|
|
}
|
|
|
|
function selectMonth() {
|
|
let month = new URLSearchParams(window.location.search).get('month') ?? new Date().getMonth() + 1;
|
|
document.getElementById("monthSelect").value = month;
|
|
}
|
|
|
|
const year = new URLSearchParams(window.location.search).get('year') ?? new Date().getFullYear();
|
|
const month = new URLSearchParams(window.location.search).get('month') ?? new Date().getMonth() + 1;
|
|
|
|
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}`;
|
|
}
|
|
</script>
|
|
|
|
<?php
|
|
|
|
|
|
|
|
// Create connection
|
|
$conn = new mysqli($host, $username, $password, $database);
|
|
|
|
// Check connection
|
|
if ($conn->connect_error) {
|
|
die("Connection failed: " . $conn->connect_error);
|
|
}
|
|
|
|
$year = $_GET['year'] ?? date('Y');
|
|
$month = $_GET['month'] ?? date('n');
|
|
|
|
$sql = "SELECT * FROM submitted WHERE status != 'DELETED' and MONTH(eta) = $month and YEAR(eta) = $year ORDER BY eta ASC;"; // Replace with your table name
|
|
$result = $conn->query($sql);
|
|
|
|
// Check if there are results
|
|
if ($result->num_rows > 0) {
|
|
// Start HTML table
|
|
echo '<table border="1">
|
|
<thead>
|
|
<tr>';
|
|
|
|
// Output table headers (assuming column names are known)
|
|
$fields = $result->fetch_fields();
|
|
foreach ($fields as $field) {
|
|
if ($field->name != 'id') {
|
|
echo '<th>' . htmlspecialchars($field->name ?? '') . '</th>';
|
|
}
|
|
|
|
}
|
|
// echo '<th>actions</th>';
|
|
|
|
echo ' </tr>
|
|
</thead>
|
|
<tbody>';
|
|
|
|
// Output table rows
|
|
while ($row = $result->fetch_assoc()) {
|
|
echo '<tr onclick="openDetail(' . $row['id'] . ')">';
|
|
foreach ($row as $key => $value) {
|
|
if ($key != 'id') {
|
|
echo '<td>' . htmlspecialchars($value ?? '') . '</td>';
|
|
}
|
|
}
|
|
echo '</tr>';
|
|
}
|
|
|
|
echo ' </tbody></table>';
|
|
} else {
|
|
echo "No results found.";
|
|
}
|
|
|
|
// Close the database connection
|
|
$conn->close();
|
|
|
|
?>
|
|
|
|
<center><button onclick="openPopup()">Log New PPR</button></center>
|
|
|
|
<script>
|
|
function openPopup() {
|
|
window.open("input.html", "PopupWindow", "toolbar=no, location=no, directories=no,status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=yes, width=600, height=1100");
|
|
}
|
|
</script>
|