From c3873744beed1fa0bbb31830b5fb2c813cf6d8c3 Mon Sep 17 00:00:00 2001 From: Grisu Date: Thu, 22 Sep 2022 11:22:25 +0200 Subject: [PATCH 1/4] you can now set if a station needs points or get the results of the excersice and the website should calculate the points --- app/public/add_station.php | 10 +++++++++- app/public/edit_station.php | 13 +++++++++++++ app/public/stationen.php | 1 + app/scripts/database_queries.php | 16 ++++++++++++++-- app/scripts/functions.php | 10 ++++++++-- 5 files changed, 45 insertions(+), 5 deletions(-) diff --git a/app/public/add_station.php b/app/public/add_station.php index 7ca9f53..7913a2c 100644 --- a/app/public/add_station.php +++ b/app/public/add_station.php @@ -8,7 +8,8 @@ if(isset($_POST['save'])){ $station_name = sanitize_input($_POST['station_name']); $station_pos = sanitize_input($_POST['station_pos']); - write_station($con, $station_name, $station_pos); + $station_direct_points = sanitize_input($_POST['direkte_punkte']); + write_station($con, $station_name, $station_pos, $station_direct_points); } header("Location: stationen.php"); die; @@ -34,6 +35,13 @@ + Schließen diff --git a/app/public/edit_station.php b/app/public/edit_station.php index a53cac5..38eab12 100644 --- a/app/public/edit_station.php +++ b/app/public/edit_station.php @@ -16,11 +16,13 @@ $station_name = sanitize_input($_POST['station_name']); $station_pos = sanitize_input($_POST['station_pos']); $station_gewertet = sanitize_input($_POST['gewertet']); + $station_direct_points = sanitize_input($_POST['direkte_punkte']); $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']); + $direct_points = intval($station['direkte_punkte']); if($name != $station_name) { update_station_name($con, $s_id, $station_name); } @@ -32,6 +34,10 @@ if($gewertet != $station_gewertet) { update_station_gewertet($con, $s_id, $station_gewertet); } + + if($direct_points != $station_direct_points) { + update_station_direct_points($con, $s_id, $station_direct_points); + } } header("Location: stationen.php"); die; @@ -62,6 +68,13 @@ + />
diff --git a/app/public/stationen.php b/app/public/stationen.php index ad826d7..a1288c0 100644 --- a/app/public/stationen.php +++ b/app/public/stationen.php @@ -43,6 +43,7 @@ Name Standort Gewertet + Direkt Punkte eintragen diff --git a/app/scripts/database_queries.php b/app/scripts/database_queries.php index c9bfbc8..6149d38 100644 --- a/app/scripts/database_queries.php +++ b/app/scripts/database_queries.php @@ -167,11 +167,12 @@ function write_points($con, $s_id, $m_id, $points, $time) { } } -function write_station($con, $station_name, $station_pos) { +function write_station($con, $station_name, $station_pos, $station_direct_points) { try { - $stmt = $con->prepare("INSERT INTO Station (name, standort) VALUES (?, ?)"); + $stmt = $con->prepare("INSERT INTO Station (name, standort, direkte_punkte) VALUES (?, ?, ?)"); $stmt->bindParam(1, $station_name, PDO::PARAM_STR); $stmt->bindParam(2, $station_pos, PDO::PARAM_STR); + $stmt->bindParam(3, $station_direct_points, PDO::PARAM_INT); $stmt->execute(); } catch(PDOException $e) { handle_pdo_exceptio($e); @@ -426,6 +427,17 @@ function update_station_gewertet($con, $s_id, $gewertet) { } } +function update_station_direct_points($con, $s_id, $direct_points) { + try { + $stmt = $con->prepare("UPDATE Station SET direkte_punkte = ? WHERE s_id = ?"); + $stmt->bindParam(1, $direct_points, 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 34e90bf..9bc2dff 100644 --- a/app/scripts/functions.php +++ b/app/scripts/functions.php @@ -38,14 +38,20 @@ function load_stations_table($con) { $stmt = get_stations_all($con); foreach($stmt->fetchAll() as $row) { if ($row['gewertet'] == '1') { - $checked = "ja"; + $checked = "Ja"; } else { - $checked = "nein"; + $checked = "Nein"; + } + if ($row['direkte_punkte'] == '1') { + $direkte_punkte = "Ja"; + } else { + $direkte_punkte = "Nein"; } echo ""; echo "" . $row['name'] . ""; echo "" . $row['standort'] . ""; echo "". $checked . ""; + echo "" . $direkte_punkte . ""; echo ""; } } From e62be84d359d74bd6954f724298182b89ca78e70 Mon Sep 17 00:00:00 2001 From: Grisu Date: Thu, 22 Sep 2022 14:17:29 +0200 Subject: [PATCH 2/4] you can now edit, add and delete results --- app/public/add_entry.php | 49 +++++++++++++------- app/public/delete_statistics.php | 7 +++ app/public/edit_statistics.php | 78 ++++++++++++++++++++++---------- app/scripts/database_queries.php | 60 ++++++++++++++++++++++++ app/scripts/functions.php | 20 ++++++++ 5 files changed, 174 insertions(+), 40 deletions(-) diff --git a/app/public/add_entry.php b/app/public/add_entry.php index 179d714..a6bd9ea 100644 --- a/app/public/add_entry.php +++ b/app/public/add_entry.php @@ -4,13 +4,17 @@ include("../scripts/functions.php"); $user_data = check_login($con); + if($_SERVER['REQUEST_METHOD'] == "GET") { + $s_id = sanitize_input($_GET['station']); + } + if($_SERVER['REQUEST_METHOD'] == "POST") { - if(isset($_POST['save'])){ + $s_id = sanitize_input($_GET['station']); + if(isset($_POST['save']) && get_direct_points($con, $s_id)->fetch()['direkte_punkte'] == 1){ $points = sanitize_input($_POST['points']); $minutes = sanitize_input($_POST['minutes']); $seconds = sanitize_input($_POST['seconds']); $miliseconds = sanitize_input($_POST['miliseconds']); - $s_id = sanitize_input($_GET['station']); $m_id = sanitize_input($_POST['team']); if($minutes == 0 && $seconds == 0 && $miliseconds == 0){ @@ -30,6 +34,10 @@ $time = "00:" . $minutes . ":" . $seconds . "." . $miliseconds; } write_points($con, $s_id, $m_id, $points, $time); + } elseif (isset($_POST['save'])) { + $result = sanitize_input($_POST['result']); + $m_id = sanitize_input($_POST['team']); + write_result($con, $s_id, $m_id, $result); } header("Location: statistik.php"); die; @@ -51,27 +59,34 @@
-
- - + fetch()['direkte_punkte'] == 1) { + echo "
+ +
-
+

Zeit

-
-
- - +
+
+ +
-
- - +
+ +
-
- - +
+ +
-
+
";} else { + echo "
+ + +
"; + }?>
diff --git a/app/public/delete_statistics.php b/app/public/delete_statistics.php index 0fb7a7c..c41dcbf 100644 --- a/app/public/delete_statistics.php +++ b/app/public/delete_statistics.php @@ -10,6 +10,13 @@ $stmt->bindParam(1, $_POST["m_id"], PDO::PARAM_INT); $stmt->bindParam(2, $_POST["s_id"], PDO::PARAM_INT); $stmt->execute(); + if(get_direct_points($con, $_POST['s_id'])->fetch()['direkte_punkte'] == 0) { + $stmt = $con->prepare("DELETE FROM Ergebnisse WHERE m_id = ? AND s_id =?"); + $stmt->bindParam(1, $_POST["m_id"], PDO::PARAM_INT); + $stmt->bindParam(2, $_POST["s_id"], PDO::PARAM_INT); + $stmt->execute(); + update_points($con, $_POST["s_id"]); + } } catch(PDOException $e) { handle_pdo_exception($e); } diff --git a/app/public/edit_statistics.php b/app/public/edit_statistics.php index 870c74f..00705bb 100644 --- a/app/public/edit_statistics.php +++ b/app/public/edit_statistics.php @@ -5,14 +5,16 @@ $user_data=check_login($con); if($_SERVER['REQUEST_METHOD'] == "GET") { - $row = get_result($con, $_GET["m_id"], $_GET['s_id'])->fetch(); + $m_id = intval(sanitize_input($_GET['m_id'])); + $s_id = intval(sanitize_input($_GET['s_id'])); + $row = get_result($con, $m_id, $s_id)->fetch(); include("header_footer/header.php"); } if($_SERVER['REQUEST_METHOD'] == 'POST') { - if(isset($_POST['button'])) { - $m_id = intval(sanitize_input($_POST['m_id'])); - $s_id = intval(sanitize_input($_POST['s_id'])); + $s_id = intval(sanitize_input($_POST['s_id'])); + $m_id = intval(sanitize_input($_POST['m_id'])); + if(isset($_POST['save']) && get_direct_points($con, $s_id)->fetch()['direkte_punkte'] == 1) { $points = intval(sanitize_input($_POST['points'])); $minutes = intval(sanitize_input($_POST['minutes'])); $seconds = intval(sanitize_input($_POST['seconds'])); @@ -36,6 +38,9 @@ $time = "00:" . $minutes . ":" . $seconds . "." . $millis; change_time($con, $m_id, $s_id, $time); } + } elseif(isset($_POST['save'])) { + $result = intval(sanitize_input($_POST['result'])); + update_result($con, $s_id, $m_id, $result); } header("Location: statistik.php"); die; @@ -50,31 +55,58 @@


-
- - + fetch()['direkte_punkte'] == 1){ + echo "
+ +
-
+

Zeit

-
- -
- - fetch()['minutes'] . "\""; }?>/> +
"; + $time_set = check_time($con, $m_id, $s_id); + echo "
+ + fetch()['minutes'] . "\""; + } + echo "/>
-
- - fetch()['seconds'] . "\""; }?>/> +
+ + fetch()['seconds'] . "\""; } + echo"/>
-
- - fetch()['millis'] / 1e4 . "\""; }?>/> +
+ + fetch()['millis'] / 1e4; + echo "\"" . $millis . "\""; + } + echo"/>
-
- /> - /> - +
"; + } else { + echo "
+ + "; + }?> + /> + /> +
diff --git a/app/scripts/database_queries.php b/app/scripts/database_queries.php index 6149d38..74092e5 100644 --- a/app/scripts/database_queries.php +++ b/app/scripts/database_queries.php @@ -469,4 +469,64 @@ function update_team_fire_department($con, $m_id, $dep) { } catch(PDOException $e) { handle_pdo_exception($e); } +} + +function get_direct_points($con, $s_id) { + try { + $stmt = $con->prepare("SELECT direkte_punkte FROM Station WHERE s_id = :s_id"); + $stmt->execute(['s_id' => $s_id]); + $stmt->setFetchMode(PDO::FETCH_ASSOC); + return $stmt; + } catch(PDOException $e) { + handle_pdo_exception($e); + } +} + +function write_result_db($con, $s_id, $m_id, $result) { + try { + $stmt = $con->prepare("INSERT INTO Ergebnisse (s_id, m_id, erg) VALUES (?, ?, ?)"); + $stmt->bindParam(1, $s_id, PDO::PARAM_INT); + $stmt->bindParam(2, $m_id, PDO::PARAM_INT); + $stmt->bindParam(3, $result, PDO::PARAM_INT); + $stmt->execute(); + } catch(PDOException $e) { + handle_pdo_exception($e); + } +} + +function get_results($con, $s_id) { + try { + $stmt = $con->prepare("SELECT * FROM Ergebnisse WHERE s_id = :s_id ORDER BY erg DESC"); + $stmt->execute(['s_id' => $s_id]); + $stmt->setFetchMode(PDO::FETCH_ASSOC); + return $stmt; + } catch(PDOException $e) { + handle_pdo_exception($e); + } +} + +function update_result_db($con, $s_id, $m_id, $result) { + try { + $stmt = $con->prepare("UPDATE Ergebnisse SET erg = ? WHERE s_id = ? AND m_id = ?"); + $stmt->bindParam(1, $result, PDO::PARAM_INT); + $stmt->bindParam(2, $s_id, PDO::PARAM_INT); + $stmt->bindParam(3, $m_id, PDO::PARAM_INT); + $stmt->execute(); + } catch(PDOException $e) { + handle_pdo_exception($e); + } +} + +function get_result_team_station($con, $s_id, $m_id) { + try { + $stmt = $con->prepare("SELECT * FROM Ergebnisse WHERE s_id = ? AND m_id = ?"); + $stmt->bindParam(1, $s_id, PDO::PARAM_INT); + $stmt->bindParam(2, $m_id, PDO::PARAM_INT); + $stmt->execute(); + $stmt->setFetchMode(PDO::FETCH_ASSOC); + $result = $stmt->fetch()['erg']; + return $result; + } catch( PDOException $e) { + handle_pdo_exception($e); + } } \ No newline at end of file diff --git a/app/scripts/functions.php b/app/scripts/functions.php index 9bc2dff..4283191 100644 --- a/app/scripts/functions.php +++ b/app/scripts/functions.php @@ -228,4 +228,24 @@ function get_time_str($con, $m_id, $s_id) { function sanitize_input ($input) { $return = strip_tags($input); return htmlspecialchars($return, ENT_QUOTES); +} + +function update_points($con, $s_id) { + $results = get_results($con, $s_id)->fetchAll(); + $factor = $results[0]['erg']/ 15.0; + foreach($results as $row) { + $points = round($row['erg']/$factor); + change_points($con, $row['m_id'], $s_id, $points); + } +} + +function write_result($con, $s_id, $m_id, $result) { + write_result_db($con, $s_id, $m_id, $result); + write_points($con, $s_id, $m_id, 0, null); + update_points($con, $s_id); +} + +function update_result($con, $s_id, $m_id, $result) { + update_result_db($con, $s_id, $m_id, $result); + update_points($con, $s_id); } \ No newline at end of file From cfc9c96a17022f6f684723f5afa3833d53e7c31e Mon Sep 17 00:00:00 2001 From: Grisu Date: Thu, 22 Sep 2022 14:19:38 +0200 Subject: [PATCH 3/4] updated database schema --- mysql-schema/schema.sql | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/mysql-schema/schema.sql b/mysql-schema/schema.sql index 50d36fd..8179bbe 100644 --- a/mysql-schema/schema.sql +++ b/mysql-schema/schema.sql @@ -1,8 +1,8 @@ --- MariaDB dump 10.19 Distrib 10.8.3-MariaDB, for Linux (x86_64) +-- MariaDB dump 10.19 Distrib 10.9.2-MariaDB, for Linux (x86_64) -- -- Host: localhost Database: ksp -- ------------------------------------------------------ --- Server version 10.7.3-MariaDB-1:10.7.3+maria~focal +-- Server version 10.9.2-MariaDB-1:10.9.2+maria~ubu2204 /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; @@ -15,6 +15,26 @@ /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; +-- +-- Table structure for table `Ergebnisse` +-- + +DROP TABLE IF EXISTS `Ergebnisse`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `Ergebnisse` ( + `erg_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT, + `s_id` tinyint(3) unsigned DEFAULT NULL, + `m_id` tinyint(3) unsigned DEFAULT NULL, + `erg` smallint(5) unsigned DEFAULT NULL, + PRIMARY KEY (`erg_id`), + KEY `s_id` (`s_id`), + KEY `m_id` (`m_id`), + CONSTRAINT `Ergebnisse_ibfk_1` FOREIGN KEY (`s_id`) REFERENCES `Station` (`s_id`), + CONSTRAINT `Ergebnisse_ibfk_2` FOREIGN KEY (`m_id`) REFERENCES `Mannschaft` (`m_id`) +) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `Mannschaft` -- @@ -27,7 +47,7 @@ CREATE TABLE `Mannschaft` ( `name` tinytext DEFAULT NULL, `feuerwehr` tinytext DEFAULT NULL, PRIMARY KEY (`m_id`) -) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8mb4; +) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8mb4; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -60,8 +80,10 @@ CREATE TABLE `Station` ( `s_id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT, `name` tinytext DEFAULT NULL, `standort` text DEFAULT NULL, + `gewertet` tinyint(1) DEFAULT 1, + `direkte_punkte` tinyint(1) DEFAULT 1, PRIMARY KEY (`s_id`) -) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4; +) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -85,7 +107,7 @@ CREATE TABLE `users` ( UNIQUE KEY `user_name` (`user_name`), KEY `s_id` (`s_id`), CONSTRAINT `users_ibfk_1` FOREIGN KEY (`s_id`) REFERENCES `Station` (`s_id`) -) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4; +) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8mb4; /*!40101 SET character_set_client = @saved_cs_client */; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; @@ -97,4 +119,4 @@ CREATE TABLE `users` ( /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2022-06-19 22:58:36 +-- Dump completed on 2022-09-22 14:19:05 From 3598769c04152671111eed8378f6de634ebbaa12 Mon Sep 17 00:00:00 2001 From: Grisu Date: Thu, 22 Sep 2022 17:38:02 +0200 Subject: [PATCH 4/4] added warning when wrong password is entered --- app/public/css/login.css | 9 +++++++++ app/public/login.php | 23 ++++++++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/app/public/css/login.css b/app/public/css/login.css index 1298c77..6ceefbf 100644 --- a/app/public/css/login.css +++ b/app/public/css/login.css @@ -101,3 +101,12 @@ input[type="submit"]:hover{ border-color: #2691d9; transition: .5s; } + +.warnings { + outline: none; + margin-top: 0px; + margin-bottom: 10px; + background-color: #ff8080; + border-radius: 4px; + padding: 4px; +} \ No newline at end of file diff --git a/app/public/login.php b/app/public/login.php index b2fc870..d63036b 100644 --- a/app/public/login.php +++ b/app/public/login.php @@ -2,6 +2,8 @@ session_start(); include("../scripts/connection.php"); include("../scripts/functions.php"); + $password_wrong = false; + $wrong_data = false; if($_SERVER['REQUEST_METHOD'] == "POST"){ $user_name = sanitize_input($_POST['user_name']); @@ -21,14 +23,14 @@ } die; } else { - echo "Benutzername oder Passwort stimmen nicht"; + $password_wrong = true; } } else { - echo "Benutzername oder Passwort stimmen nicht"; + $password_wrong = true; } } else { - echo "Gib bitte gültige Daten ein!"; + $wrong_data = true; } } $con = null; @@ -57,6 +59,21 @@
+ + +
"; + } + + if ($wrong_data == true) { + echo " +
+ +
"; + } + ?>