2024-06-28 06:30:49 +02:00
|
|
|
<?php
|
|
|
|
// Database configuration
|
|
|
|
$servername = "localhost";
|
|
|
|
$username = "mailstats";
|
|
|
|
$password = "mailstats";
|
|
|
|
$dbname = "mailstats";
|
|
|
|
|
|
|
|
// Default date to yesterday
|
|
|
|
$date = isset($_GET['date']) ? $_GET['date'] : date('Y-m-d', strtotime('-1 day'));
|
|
|
|
|
2024-06-30 10:10:57 +02:00
|
|
|
// Default hour to 99 (means all the hours)
|
|
|
|
$hour = isset($_GET['hour']) ? $_GET['hour'] : 99;
|
2024-06-28 06:30:49 +02:00
|
|
|
|
|
|
|
// Create connection
|
|
|
|
$conn = new mysqli($servername, $username, $password, $dbname);
|
|
|
|
|
|
|
|
// Check connection
|
|
|
|
if ($conn->connect_error) {
|
|
|
|
die("Connection failed: " . $conn->connect_error);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prepare and execute the query
|
2024-06-30 10:10:57 +02:00
|
|
|
if ($hour == 99){
|
|
|
|
$sql = "SELECT * FROM SummaryLogs WHERE Date = ?";
|
|
|
|
$stmt = $conn->prepare($sql);
|
|
|
|
$stmt->bind_param("s", $date);
|
|
|
|
} else {
|
|
|
|
$sql = "SELECT * FROM SummaryLogs WHERE Date = ? AND Hour = ?";
|
|
|
|
$stmt = $conn->prepare($sql);
|
|
|
|
$stmt->bind_param("si", $date, $hour);
|
|
|
|
}
|
2024-06-28 06:30:49 +02:00
|
|
|
$stmt->execute();
|
|
|
|
$result = $stmt->get_result();
|
2024-06-30 16:38:42 +02:00
|
|
|
$result_count = $result->num_rows;
|
2024-06-28 06:30:49 +02:00
|
|
|
|
|
|
|
function generateLogDataTable($logData) {
|
|
|
|
$data = json_decode($logData, true);
|
|
|
|
if (is_null($data)) {
|
|
|
|
return "Invalid JSON data";
|
|
|
|
}
|
|
|
|
|
2024-06-30 13:05:54 +02:00
|
|
|
//// Remove entries with the key "logterse"
|
|
|
|
//if (isset($data['logterse'])) {
|
|
|
|
//unset($data['logterse']);
|
|
|
|
//}
|
|
|
|
|
|
|
|
// Remove entries with the key "logterse" and remove entries with empty values
|
|
|
|
foreach ($data as $key => $value) {
|
|
|
|
if ($key === 'logterse' || empty($value)) {
|
|
|
|
unset($data[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle adjacent duplicates by merging keys
|
|
|
|
$mergedData = [];
|
|
|
|
$previousValue = null;
|
|
|
|
foreach ($data as $key => $value) {
|
|
|
|
if ($value === $previousValue) {
|
|
|
|
// Merge the current key with the previous key
|
|
|
|
end($mergedData);
|
|
|
|
$lastKey = key($mergedData);
|
|
|
|
$newKey = "$lastKey/$key";
|
|
|
|
$mergedData[$newKey] = $value;
|
|
|
|
// Remove the old entry
|
|
|
|
unset($mergedData[$lastKey]);
|
|
|
|
} else {
|
|
|
|
// Otherwise, add a new entry
|
|
|
|
$mergedData[$key] = $value;
|
|
|
|
}
|
|
|
|
$previousValue = $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$keys = array_keys($mergedData);
|
|
|
|
$values = array_values($mergedData);
|
2024-06-28 06:30:49 +02:00
|
|
|
|
2024-07-15 12:06:44 +02:00
|
|
|
$output = '<table class="stripes" style="border-collapse: collapse; width:95%;overflow-x:auto; margin: 0.6% auto 0.6% auto;"><tbody>';
|
2024-06-28 06:30:49 +02:00
|
|
|
|
|
|
|
// Divide keys and values into sets of 6
|
2024-06-30 13:05:54 +02:00
|
|
|
$chunks = array_chunk($keys, 6);
|
2024-06-28 06:30:49 +02:00
|
|
|
foreach ($chunks as $chunkIndex => $chunk) {
|
|
|
|
if ($chunkIndex > 0) {
|
|
|
|
// Add spacing between different sets
|
|
|
|
#$output .= '<tr><td colspan="6" style="height: 1em;"></td></tr>';
|
|
|
|
}
|
|
|
|
|
|
|
|
$output .= '<tr>';
|
|
|
|
foreach ($chunk as $key) {
|
|
|
|
$output .= '<th>' . htmlspecialchars($key) . '</th>';
|
|
|
|
}
|
|
|
|
$output .= '</tr><tr>';
|
|
|
|
foreach ($chunk as $i => $key) {
|
2024-06-30 13:05:54 +02:00
|
|
|
$output .= '<td>' . htmlspecialchars($values[$chunkIndex * 6+ $i]) . '</td>';
|
2024-06-28 06:30:49 +02:00
|
|
|
}
|
|
|
|
$output .= '</tr>';
|
|
|
|
}
|
|
|
|
|
|
|
|
$output .= '</tbody></table>';
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|
|
|
|
|
|
|
|
<!DOCTYPE html>
|
|
|
|
<html lang="en">
|
|
|
|
<head>
|
|
|
|
<meta charset="UTF-8">
|
2024-06-30 13:05:54 +02:00
|
|
|
<link rel='stylesheet' type='text/css' href='css/mailstats.css' />
|
2024-06-28 06:30:49 +02:00
|
|
|
<title>Summary Logs</title>
|
2024-06-30 13:05:54 +02:00
|
|
|
<!-- <style>
|
2024-06-28 06:30:49 +02:00
|
|
|
table {
|
2024-06-30 13:05:54 +02:00
|
|
|
xxwidth: 100%;
|
|
|
|
xxborder-collapse: collapse;
|
2024-06-28 06:30:49 +02:00
|
|
|
}
|
|
|
|
table, th, td {
|
2024-06-30 13:05:54 +02:00
|
|
|
xxborder: 1px solid black;
|
2024-06-28 06:30:49 +02:00
|
|
|
}
|
|
|
|
th, td {
|
2024-06-30 13:05:54 +02:00
|
|
|
xxpadding: 8px;
|
|
|
|
xxtext-align: left;
|
2024-06-28 06:30:49 +02:00
|
|
|
}
|
|
|
|
</style>
|
2024-06-30 13:05:54 +02:00
|
|
|
-->
|
2024-06-28 06:30:49 +02:00
|
|
|
</head>
|
|
|
|
<body>
|
2024-06-30 13:10:57 +02:00
|
|
|
<div style="width:100%;overflow-x:auto;font-size:0.726cqw">"
|
2024-06-30 10:10:57 +02:00
|
|
|
<h1>Summary Logs for Date: <?= htmlspecialchars($date) ?> <?= $hour == 99 ? 'for All Hours' : 'and Hour: ' . htmlspecialchars($hour) ?></h1>
|
2024-06-30 16:38:42 +02:00
|
|
|
<h3>Found <?= $result_count ?> records.</h3>
|
2024-06-30 13:05:54 +02:00
|
|
|
<table style="border-collapse:collapse;width:98%">
|
2024-06-28 06:30:49 +02:00
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>Id</th>
|
|
|
|
<!--<th>Date</th>-->
|
|
|
|
<!--<th>Hour</th>-->
|
|
|
|
<th>Log Data</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<?php if ($result->num_rows > 0): ?>
|
|
|
|
<?php while($row = $result->fetch_assoc()): ?>
|
|
|
|
<tr>
|
|
|
|
<td><?= htmlspecialchars($row['id']) ?></td>
|
|
|
|
<td><?= generateLogDataTable($row['logData']) ?></td>
|
|
|
|
</tr>
|
|
|
|
<?php endwhile; ?>
|
|
|
|
<?php else: ?>
|
|
|
|
<tr>
|
|
|
|
<td colspan="4">No records found for the specified date and hour.</td>
|
|
|
|
</tr>
|
|
|
|
<?php endif; ?>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
2024-06-30 13:05:54 +02:00
|
|
|
</div>
|
2024-06-28 06:30:49 +02:00
|
|
|
<?php
|
|
|
|
// Close the connection
|
|
|
|
$stmt->close();
|
|
|
|
$conn->close();
|
|
|
|
?>
|
|
|
|
</body>
|
|
|
|
</html>
|