TZ changes

This commit is contained in:
2025-03-31 08:29:59 +00:00
parent 07cb5d1419
commit ca28f490eb
5 changed files with 65 additions and 52 deletions

View File

@@ -5,8 +5,8 @@
// Set default value to current date & time // Set default value to current date & time
document.addEventListener("DOMContentLoaded", function () { document.addEventListener("DOMContentLoaded", function () {
let now = new Date(); const currentIsoDateString = new Date(Date.now() - new Date().getTimezoneOffset() * 60000).toISOString()
let localDatetime = now.toISOString().slice(0, 16); // Format for datetime-local input let localDatetime = currentIsoDateString.slice(0, 16); // Format for datetime-local input
document.getElementById("eta").value = localDatetime; document.getElementById("eta").value = localDatetime;
// document.getElementById("etd").value = localDatetime; // document.getElementById("etd").value = localDatetime;
}); });

View File

@@ -11,7 +11,14 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
echo "<h2>Received POST Data:</h2><ul>"; echo "<h2>Received POST Data:</h2><ul>";
foreach ($_POST as $key => $value) { foreach ($_POST as $key => $value) {
$escaped_key = "`" . $conn->real_escape_string($key) . "`"; $escaped_key = "`" . $conn->real_escape_string($key) . "`";
$escaped_value = ($value === '' || $value === null) ? "NULL" : (is_numeric($value) ? $value : "'" . $conn->real_escape_string($value) . "'"); if ($key === 'eta' || $key === 'etd') {
// Convert London time to UTC
$datetime = new DateTime($value, new DateTimeZone('Europe/London'));
$datetime->setTimezone(new DateTimeZone('UTC'));
$escaped_value = "'" . $datetime->format('Y-m-d H:i:s') . "'";
} else {
$escaped_value = ($value === '' || $value === null) ? "NULL" : (is_numeric($value) ? $value : "'" . $conn->real_escape_string($value) . "'");
}
$columns[] = $escaped_key; $columns[] = $escaped_key;
$values[] = $escaped_value; $values[] = $escaped_value;
echo "<li><strong>" . htmlspecialchars($key) . ":</strong> " . htmlspecialchars($value) . "</li>"; echo "<li><strong>" . htmlspecialchars($key) . ":</strong> " . htmlspecialchars($value) . "</li>";

View File

@@ -34,7 +34,7 @@
"name": "Arriving From" "name": "Arriving From"
}, },
"ca4ac44f-0388-4a70-a072-38276ed2ac13": { "ca4ac44f-0388-4a70-a072-38276ed2ac13": {
"value": "31\/03\/2025 17:22", "value": "31\/03\/2025 13:00",
"name": "ETA" "name": "ETA"
}, },
"6fc47c54-7383-48fd-93fc-d8080f5ed8f5": { "6fc47c54-7383-48fd-93fc-d8080f5ed8f5": {

View File

@@ -244,64 +244,69 @@ function openDetail(id) {
<?php <?php
// Create connection function renderTableCell($key, $value, $row) {
$conn = new mysqli($host, $username, $password, $database); if ($key == 'ac_reg' && $row['ac_call'] != NULL) {
$notes = htmlspecialchars($row['notes'] ?? '');
// Check connection $acCall = htmlspecialchars($row['ac_call'] ?? '');
if ($conn->connect_error) { $acReg = htmlspecialchars($value ?? '');
die("Connection failed: " . $conn->connect_error); if (!empty($row['notes'])) {
return "<td class='red-triangle' data-notes='$notes'>$acCall<br><span class='acreg'>$acReg</span></td>";
}
return "<td>$acCall<br><span class='acreg'>$acReg</span></td>";
} elseif ($key == 'ac_reg' && !empty($row['notes'])) {
$notes = htmlspecialchars($row['notes'] ?? '');
$acReg = htmlspecialchars($value ?? '');
return "<td class='red-triangle' data-notes='$notes'>$acReg</td>";
} else {
return "<td>" . htmlspecialchars($value ?? '') . "</td>";
}
} }
// Define your SQL query function renderTableRow($row) {
$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 $rowHtml = "<tr class='state-" . htmlspecialchars($row['status']) . "' data-id='" . htmlspecialchars($row['id']) . "'>";
foreach ($row as $key => $value) {
if (!in_array($key, ['notes', 'status', 'id', 'ac_call'])) {
$rowHtml .= renderTableCell($key, $value, $row);
}
}
$rowHtml .= renderActionsCell($row['id']);
$rowHtml .= "</tr>";
return $rowHtml;
}
// Execute the query function renderActionsCell($id) {
$result = $conn->query($sql); return "<td>
<img src='assets/cancel-icon.webp' title='Cancel PPR' style='width: 25px; height: auto;' onclick='markCancel($id)'>
<img src='assets/arrive.png' title='Land' style='width: 30px; height: auto;' onclick='markLanded($id)'>
</td>";
}
// Check if there are results function renderTable($result) {
if ($result->num_rows > 0) { $tableHtml = "<table border='1' id='arrivals'>
// Start HTML table <thead>
echo '<table border="1" id="arrivals"> <tr>";
<thead>
<tr>';
// Output table headers (assuming column names are known)
$fields = $result->fetch_fields(); $fields = $result->fetch_fields();
foreach ($fields as $field) { foreach ($fields as $field) {
if ($field->name != 'notes' && $field->name != 'status' && $field->name != 'id' && $field->name != 'ac_call') { if (!in_array($field->name, ['notes', 'status', 'id', 'ac_call'])) {
echo '<th>' . htmlspecialchars($field->name ?? '') . '</th>'; $tableHtml .= "<th>" . htmlspecialchars($field->name ?? '') . "</th>";
} }
} }
echo '<th>actions</th>'; $tableHtml .= "<th>actions</th></tr></thead><tbody>";
echo ' </tr>
</thead>
<tbody>';
// Output table rows
while ($row = $result->fetch_assoc()) { while ($row = $result->fetch_assoc()) {
echo '<tr class="state-' . $row['status'] . '" data-id=' . $row['id'] . '>'; $tableHtml .= renderTableRow($row);
foreach ($row as $key => $value) {
if ($key != 'notes' && $key != 'status' && $key != 'id' && $key != 'ac_call') {
if ($key == 'ac_reg' && $row['ac_call'] != NULL) {
if (!empty($row['notes'])) {
echo '<td class="red-triangle" data-notes="' . htmlspecialchars($row['notes'] ?? '') . '">' . htmlspecialchars($row['ac_call'] ?? '') . "<br><span class=acreg>" . $value . '</span></td>';
} else {
echo '<td>' . htmlspecialchars($row['ac_call'] ?? '') . "<br><span class=acreg>" . $value . '</span></td>';
}
} else if ($key == 'ac_reg' && !empty($row['notes'])) {
echo '<td class="red-triangle" data-notes="' . htmlspecialchars($row['notes'] ?? '') . '">' . htmlspecialchars($value ?? '') . '</td>';
} else {
echo '<td>' . htmlspecialchars($value ?? '') . '</td>';
}
}
}
echo '<td><img src="assets/cancel-icon.webp" title="Cancel PPR" style="width: 25px; height: auto;" onclick="markCancel(' . $row['id'] . ')"><img src="assets/arrive.png" title="Land" style="width: 30px; height: auto;" onclick="markLanded(' . $row['id'] . ')"></td>';
echo '</tr>';
} }
echo ' </tbody></table>'; $tableHtml .= "</tbody></table>";
return $tableHtml;
}
$conn = connectDb();
$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
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo renderTable($result);
} else { } else {
echo "No results found."; echo "No results found.";
} }

View File

@@ -47,9 +47,10 @@ foreach ($payload['data'] as $key => $field) {
$columns[] = $columnMapping[$name]; $columns[] = $columnMapping[$name];
$value = $field['value']; $value = $field['value'];
// Transform ETA and ETD to MySQL datetime format // Transform ETA and ETD to MySQL datetime format in UTC
if ($name == "ETA" || $name == "ETD") { if ($name == "ETA" || $name == "ETD") {
$date = DateTime::createFromFormat('d/m/Y H:i', $value); $date = DateTime::createFromFormat('d/m/Y H:i', $value, new DateTimeZone('Europe/London'));
$date->setTimezone(new DateTimeZone('UTC')); // Convert to UTC
$value = $date->format('Y-m-d H:i:s'); $value = $date->format('Y-m-d H:i:s');
} }