add entries to statistics
This commit is contained in:
55
app/public/add_entry.php
Normal file
55
app/public/add_entry.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
session_start();
|
||||
include("../scripts/connection.php");
|
||||
include("../scripts/functions.php");
|
||||
if($_SERVER['REQUEST_METHOD'] == "POST") {
|
||||
$points = $_POST['points'];
|
||||
$minutes = $_POST['minutes'];
|
||||
$seconds = $_POST['seconds'];
|
||||
$miliseconds = $_POST['miliseconds'];
|
||||
|
||||
if($minutes == 0 && $seconds == 0 && $miliseconds == 0){
|
||||
$time = null;
|
||||
} else {
|
||||
$time = $minutes . ":" . $seconds . "." . $miliseconds;
|
||||
}
|
||||
write_points($con, $_GET['station'], $_POST['team'], $points, $time);
|
||||
header("Location: statistik.php");
|
||||
die;
|
||||
}
|
||||
?>
|
||||
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Eintrag eintragen</title>
|
||||
</head>
|
||||
<body>
|
||||
<div <?php if(!station_exists($con, $_GET['station'])) { echo "hidden=\"true\"";}?>>
|
||||
<form action="" method="post">
|
||||
<div id="team-div">
|
||||
<label for="team">Mannschaft</label>
|
||||
<select name="team" id="team">
|
||||
<?php load_teams_no_points($con, $_GET['station'])?>
|
||||
</select>
|
||||
</div>
|
||||
<label for="points">Punkte: </label>
|
||||
<input name="points" id="points" type="number" max="15" min="0" value="0"/><br>
|
||||
<label for="zeit">Zeit: </label>
|
||||
<div id="zeit">
|
||||
<label for="minutes">Minuten</label>
|
||||
<input name="minutes" id="minutes" type="number" max="60" min="0" value="0"/><br>
|
||||
<label for="seconds">Sekunden</label>
|
||||
<input name="seconds" id="seconds" type="number" max="60" min="0" value="0"/><br>
|
||||
<label for="miliseconds">Millisekunden</label>
|
||||
<input name="miliseconds" id="miliseconds" type="number" max="99" min="0" value="0"/>
|
||||
</div>
|
||||
<div>
|
||||
<input id="button" type="submit" value="Eintragen"/>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -5,8 +5,8 @@
|
||||
include("../scripts/functions.php");
|
||||
$user_data = check_login($con);
|
||||
|
||||
if(isset($_POST['stationen'])) {
|
||||
$_SESSION['select-statistics'] = $_POST['stationen'];
|
||||
if(isset($_GET['stationen'])) {
|
||||
$_SESSION['select-statistics'] = $_GET['stationen'];
|
||||
}
|
||||
|
||||
echo file_get_contents("html/header.html");
|
||||
@@ -14,20 +14,27 @@
|
||||
|
||||
<body>
|
||||
<div>
|
||||
<form name="switch-statistics" method="post">
|
||||
<label for="station">Welche Station soll angezeigt werden?</label>
|
||||
<form name="switch-statistics" method="get">
|
||||
<select name="stationen" id="station" onchange="this.form.submit()">
|
||||
<?php
|
||||
if(!isset($_SESSION['select-statistics']) || $_SESSION['select-statistics'] == "total-score") {
|
||||
$session = "total-score";
|
||||
} else {
|
||||
$session = $_SESSION['select-statistics'];
|
||||
echo $session;
|
||||
}
|
||||
load_options_stations($con, $session);
|
||||
?>
|
||||
</select>
|
||||
</form>
|
||||
<?php
|
||||
if($session != "total-score" && get_teams_no_points($con, $session)->rowCount() > 0) {
|
||||
echo "<form action=\"add_entry.php\" method=\"get\">
|
||||
<input type=\"hidden\" name=\"station\" value=\"$session\"/>
|
||||
<input type=\"submit\" value=\"Ergebniss eintragen\"/>
|
||||
</form>";
|
||||
}
|
||||
|
||||
?>
|
||||
</div>
|
||||
<div class="headline">
|
||||
<?php
|
||||
|
||||
@@ -117,3 +117,41 @@ function get_station($con, $s_id) {
|
||||
handle_pdo_exception($e);
|
||||
}
|
||||
}
|
||||
|
||||
function get_teams_no_points($con, $s_id) {
|
||||
try {
|
||||
$stmt = $con->prepare("SELECT M.* FROM Mannschaft M WHERE M.m_id NOT IN (SELECT P.m_id FROM Punkte P WHERE P.s_id = :s_id)");
|
||||
$stmt->execute(['s_id' => $s_id]);
|
||||
$stmt->setFetchMode(PDO::FETCH_ASSOC);
|
||||
return $stmt;
|
||||
} catch(PDOException $e) {
|
||||
handle_pdo_excepiton($e);
|
||||
}
|
||||
}
|
||||
|
||||
function station_exists($con, $s_id) {
|
||||
try {
|
||||
$stmt = $con->prepare("SELECT s_id FROM Station WHERE s_id = :s_id");
|
||||
$stmt->execute(['s_id' => $s_id]);
|
||||
if($stmt->rowCount() > 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch(PDOException $e) {
|
||||
handle_pdo_exception($e);
|
||||
}
|
||||
}
|
||||
|
||||
function write_points($con, $s_id, $m_id, $points, $time) {
|
||||
try {
|
||||
$stmt = $con->prepare("INSERT INTO Punkte (m_id, s_id, punkte, zeit) VALUES (?, ?, ?, ?)");
|
||||
$stmt->bindParam(1, $m_id, PDO::PARAM_INT);
|
||||
$stmt->bindParam(2, $s_id, PDO::PARAM_INT);
|
||||
$stmt->bindParam(3, $points, PDO::PARAM_INT);
|
||||
$stmt->bindParam(4, $time, PDO::PARAM_STR);
|
||||
$stmt->execute();
|
||||
} catch(PDOException $e) {
|
||||
handle_pdo_exception($e);
|
||||
}
|
||||
}
|
||||
@@ -109,3 +109,12 @@ function load_station_table($con, $s_id) {
|
||||
}
|
||||
echo "</tbody>\n";
|
||||
}
|
||||
|
||||
function load_teams_no_points($con, $s_id) {
|
||||
if (station_exists($con, $s_id)) {
|
||||
$stmt = get_teams_no_points($con, $s_id);
|
||||
foreach($stmt->fetchAll() as $option) {
|
||||
echo "<option value=\"" . $option['m_id'] . "\">" . $option['name'] . " " . $option['feuerwehr'] . "</option>";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user