CSV Download and Notes highlight

This commit is contained in:
2025-03-16 17:17:42 +00:00
parent 82f2c5c16c
commit 935e13d44b
7 changed files with 141 additions and 115 deletions

47
download.php Normal file
View File

@@ -0,0 +1,47 @@
<?php
include("functions.php");
require_db_auth();
// 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');
$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);
?>