From 83c62d00153e20cda1dab454306315417947efaa Mon Sep 17 00:00:00 2001 From: Grisu Date: Sun, 4 Sep 2022 16:51:47 +0200 Subject: [PATCH] Points are now only counted if it is selected --- app/public/edit_station.php | 13 +++++++++++++ app/public/stationen.php | 1 + app/scripts/database_queries.php | 13 ++++++++++++- app/scripts/functions.php | 6 ++++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/app/public/edit_station.php b/app/public/edit_station.php index f14cd47..3f0641c 100644 --- a/app/public/edit_station.php +++ b/app/public/edit_station.php @@ -14,10 +14,12 @@ $station_id = sanitize_input($_POST['station_id']); $station_name = sanitize_input($_POST['station_name']); $station_pos = sanitize_input($_POST['station_pos']); + $station_gewertet = sanitize_input($_POST['gewertet']); $station = get_station_all($con, $station_id)->fetch(); $s_id = intval($station['s_id']); $name = strval($station['name']); $standort = strval($station['standort']); + $gewertet = intval($station['gewertet']); if($name != $station_name) { update_station_name($con, $s_id, $station_name); } @@ -25,6 +27,10 @@ if($standort != $station_pos) { update_station_pos($con, $s_id, $station_pos); } + + if($gewertet != $station_gewertet) { + update_station_gewertet($con, $s_id, $station_gewertet); + } header("Location: stationen.php"); die; } @@ -47,6 +53,13 @@ + /> diff --git a/app/public/stationen.php b/app/public/stationen.php index 88fe7af..ad826d7 100644 --- a/app/public/stationen.php +++ b/app/public/stationen.php @@ -42,6 +42,7 @@ Name Standort + Gewertet diff --git a/app/scripts/database_queries.php b/app/scripts/database_queries.php index 5e93da8..7ebfcf3 100644 --- a/app/scripts/database_queries.php +++ b/app/scripts/database_queries.php @@ -87,7 +87,7 @@ function get_teams($con) { function get_total_score($con) { try { - $stmt = $con->prepare("SELECT M.name as Mannschaftsname, M.feuerwehr as Feuerwehr, SUM(P.punkte) as Gesamtpunkte FROM Punkte as P, Mannschaft as M WHERE P.m_id = M.m_id GROUP BY M.m_id ORDER BY Gesamtpunkte DESC"); + $stmt = $con->prepare("SELECT M.name as Mannschaftsname, M.feuerwehr as Feuerwehr, SUM(P.punkte) as Gesamtpunkte FROM Punkte as P, Mannschaft as M, Station as S WHERE P.m_id = M.m_id AND P.s_id = S.s_id AND S.gewertet = \"1\" GROUP BY M.m_id ORDER BY Gesamtpunkte DESC"); $stmt->execute(); $stmt->setFetchMode(PDO::FETCH_ASSOC); return $stmt; @@ -393,6 +393,17 @@ function update_station_pos($con, $s_id, $pos) { } } +function update_station_gewertet($con, $s_id, $gewertet) { + try { + $stmt = $con->prepare("UPDATE Station SET gewertet = ? WHERE s_id = ?"); + $stmt->bindParam(1, $gewertet, PDO::PARAM_INT); + $stmt->bindParam(2, $s_id, PDO::PARAM_INT); + $stmt->execute(); + } catch(PDOExeption $e) { + handle_pdo_exception($e); + } +} + function get_team($con, $m_id) { try { $stmt = $con->prepare("SELECT * FROM Mannschaft WHERE m_id = :m_id"); diff --git a/app/scripts/functions.php b/app/scripts/functions.php index 839e775..d4ccdfe 100644 --- a/app/scripts/functions.php +++ b/app/scripts/functions.php @@ -37,9 +37,15 @@ function generate_password_hash($password, $salt) { function load_stations_table($con) { $stmt = get_stations_all($con); foreach($stmt->fetchAll() as $row) { + if ($row['gewertet'] == '1') { + $checked = "ja"; + } else { + $checked = "nein"; + } echo ""; echo "" . $row['name'] . ""; echo "" . $row['standort'] . ""; + echo "". $checked . ""; echo ""; } }