Compare commits

...

2 Commits

Author SHA1 Message Date
42d3f01176 Merge pull request 'added csv download' (#9) from dev into main
Reviewed-on: #9
2022-12-04 21:49:55 +00:00
Grisu
c4d62ac658 added csv download 2022-12-04 22:34:01 +01:00
3 changed files with 53 additions and 0 deletions

View File

@@ -217,6 +217,14 @@ div.headline h2{
visibility: visible;
}
#icon-download {
position:absolute;
top: 6px;
left: 5px;
pointer-events: none;
visibility: visible;
}
.input-table{
padding-left: 2px;
padding-right: 2px;

View File

@@ -0,0 +1,35 @@
<?php
session_start();
include("../scripts/connection.php");
include("../scripts/functions.php");
$user_data = check_admin($con);
if(isset($_GET['table'])) {
$table = $_GET['table'];
}
header('Content-type: text/csv');
header('Content-Disposition: attachment; filename="table.csv" ');
function download_table($stmt) {
$output = fopen('php://output', 'w');
$header = true;
while ($row = $stmt->fetch()) {
if ($header) {
fputcsv($output, array_keys($row));
$header = false;
}
fputcsv($output, $row);
}
fclose($output);
}
if($table == "total-score") {
$total_score = get_total_score($con);
download_table($total_score);
} else {
$station = get_station($con, $table);
download_table($station);
}
?>

View File

@@ -74,6 +74,16 @@
</form>
</div>\n";
}
if($user_data['user_group'] == 'admin') {
echo "<div class=\"btn-div\">
<form action=\"download_table.php\" method=\"get\">
<span class=\"gg-software-download icon\" id=\"icon-download\"></span>
<input type=\"hidden\" name=\"table\" value=\"$session\">
<input type=\"submit\" value=\"\">
</form>
</div>";
}
?>
</div>
<div class="table-div">