Compare commits

..

5 Commits

Author SHA1 Message Date
Grisu
484cf11c07 added pass mark 2022-12-05 12:44:39 +01:00
Grisu
2e77ac243b added compression for download and ensure utf-8 encoding 2022-12-04 23:04:29 +01:00
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
Grisu
c1ffddfdb2 as admin you now can't delete your own account 2022-09-22 18:09:50 +02:00
6 changed files with 74 additions and 2 deletions

View File

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

View File

@@ -6,8 +6,11 @@
if($_SERVER['REQUEST_METHOD'] == "POST") { if($_SERVER['REQUEST_METHOD'] == "POST") {
try { try {
$stmt = $con->prepare("DELETE FROM users WHERE id = :id"); $selected_user_id = get_id_user_by_user_id($con, $_SESSION['user_id']);
$stmt->execute(['id' => $_POST['id']]); if($selected_user_id != $_POST['id']) {
$stmt = $con->prepare("DELETE FROM users WHERE id = :id");
$stmt->execute(['id' => $_POST['id']]);
}
} catch(PDOException $e) { } catch(PDOException $e) {
handle_pdo_exception($e); handle_pdo_exception($e);
} }

View File

@@ -0,0 +1,36 @@
<?php
session_start();
include("../scripts/connection.php");
include("../scripts/functions.php");
$user_data = check_admin($con);
if(isset($_GET['table'])) {
$table = $_GET['table'];
}
ob_start('ob_gzhandler'); #compressing data which is sent to the browser, the browser will decompress the data automatically
header('Content-type: text/csv; charset="UTF-8" ');
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> </form>
</div>\n"; </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>
<div class="table-div"> <div class="table-div">

View File

@@ -530,3 +530,15 @@ function get_result_team_station($con, $s_id, $m_id) {
handle_pdo_exception($e); handle_pdo_exception($e);
} }
} }
function get_id_user_by_user_id($con, $user_id) {
try {
$stmt = $con->prepare("SELECT * FROM users WHERE user_id = ?");
$stmt->bindParam(1, $user_id, PDO::PARAM_STR);
$stmt->execute();
$stmt->setFetchMode(PDO::FETCH_ASSOC);
return $stmt->fetch()['id'];
} catch( PDOException $e) {
handle_pdo_exception($e);
}
}

View File

@@ -235,6 +235,9 @@ function update_points($con, $s_id) {
$factor = $results[0]['erg']/ 15.0; $factor = $results[0]['erg']/ 15.0;
foreach($results as $row) { foreach($results as $row) {
$points = round($row['erg']/$factor); $points = round($row['erg']/$factor);
if ($points == 0 && $row['erg'] != 0) {
$points = 1;
}
change_points($con, $row['m_id'], $s_id, $points); change_points($con, $row['m_id'], $s_id, $points);
} }
} }