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