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
document.addEventListener("DOMContentLoaded", function () {
let now = new Date();
let localDatetime = now.toISOString().slice(0, 16); // Format for datetime-local input
const currentIsoDateString = new Date(Date.now() - new Date().getTimezoneOffset() * 60000).toISOString()
let localDatetime = currentIsoDateString.slice(0, 16); // Format for datetime-local input
document.getElementById("eta").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>";
foreach ($_POST as $key => $value) {
$escaped_key = "`" . $conn->real_escape_string($key) . "`";
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;
$values[] = $escaped_value;
echo "<li><strong>" . htmlspecialchars($key) . ":</strong> " . htmlspecialchars($value) . "</li>";

View File

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

View File

@@ -244,64 +244,69 @@ function openDetail(id) {
<?php
// Create connection
$conn = new mysqli($host, $username, $password, $database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
function renderTableCell($key, $value, $row) {
if ($key == 'ac_reg' && $row['ac_call'] != NULL) {
$notes = htmlspecialchars($row['notes'] ?? '');
$acCall = htmlspecialchars($row['ac_call'] ?? '');
$acReg = htmlspecialchars($value ?? '');
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
$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
function renderTableRow($row) {
$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
$result = $conn->query($sql);
function renderActionsCell($id) {
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
if ($result->num_rows > 0) {
// Start HTML table
echo '<table border="1" id="arrivals">
function renderTable($result) {
$tableHtml = "<table border='1' id='arrivals'>
<thead>
<tr>';
// Output table headers (assuming column names are known)
<tr>";
$fields = $result->fetch_fields();
foreach ($fields as $field) {
if ($field->name != 'notes' && $field->name != 'status' && $field->name != 'id' && $field->name != 'ac_call') {
echo '<th>' . htmlspecialchars($field->name ?? '') . '</th>';
if (!in_array($field->name, ['notes', 'status', 'id', 'ac_call'])) {
$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()) {
echo '<tr class="state-' . $row['status'] . '" data-id=' . $row['id'] . '>';
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>';
$tableHtml .= renderTableRow($row);
}
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 {
echo "No results found.";
}

View File

@@ -47,9 +47,10 @@ foreach ($payload['data'] as $key => $field) {
$columns[] = $columnMapping[$name];
$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") {
$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');
}