show statistics of the stations is now possible
This commit is contained in:
@@ -67,3 +67,14 @@ div.table-div th,td {
|
|||||||
padding-right: 2.5vw;
|
padding-right: 2.5vw;
|
||||||
padding-bottom: 0.5vw;
|
padding-bottom: 0.5vw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
div.headline {
|
||||||
|
display: block;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.headline h2{
|
||||||
|
text-align: center;
|
||||||
|
color: #002e5b;
|
||||||
|
}
|
||||||
@@ -5,22 +5,48 @@
|
|||||||
include("../scripts/functions.php");
|
include("../scripts/functions.php");
|
||||||
$user_data = check_login($con);
|
$user_data = check_login($con);
|
||||||
|
|
||||||
|
if(isset($_POST['stationen'])) {
|
||||||
|
$_SESSION['select-statistics'] = $_POST['stationen'];
|
||||||
|
}
|
||||||
|
|
||||||
echo file_get_contents("html/header.html");
|
echo file_get_contents("html/header.html");
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
<div>
|
||||||
|
<form name="switch-statistics" method="post">
|
||||||
|
<label for="station">Welche Station soll angezeigt werden?</label>
|
||||||
|
<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>
|
||||||
|
</div>
|
||||||
|
<div class="headline">
|
||||||
|
<?php
|
||||||
|
if($session == "total-score") {
|
||||||
|
echo "<h2>Gesamtpunkte</h2\n";
|
||||||
|
} else {
|
||||||
|
echo "<h2>" . get_station_name($con, $session)['name'] . "</h2>\n";
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
<div class="table-div">
|
<div class="table-div">
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
|
||||||
<th scope="col">Mannschaft</th>
|
|
||||||
<th scope="col">Feuerwehr</th>
|
|
||||||
<th scope="col">Gesamtpunkte</th>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<?php
|
<?php
|
||||||
|
if($session == "total-score") {
|
||||||
load_total_score($con);
|
load_total_score($con);
|
||||||
|
} else {
|
||||||
|
load_station_table($con, $session);
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
</tbody>
|
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -5,18 +5,6 @@ function handle_pdo_exception($e) {
|
|||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_Station() {
|
|
||||||
try {
|
|
||||||
$dbh = new PDO('mysql:host=mysql;dbname=ksp', 'grisu', 'secret');
|
|
||||||
foreach($dbh->query('SELECT * from Station') as $row) {
|
|
||||||
print_r($row);
|
|
||||||
}
|
|
||||||
$dbh = null;
|
|
||||||
} catch(PDOException $e) {
|
|
||||||
handle_pdo_exception($e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function check_user_id($con, $user_id) {
|
function check_user_id($con, $user_id) {
|
||||||
try {
|
try {
|
||||||
$stmt = $con->prepare('SELECT user_id FROM users WHERE user_id = :user_id limit 1');
|
$stmt = $con->prepare('SELECT user_id FROM users WHERE user_id = :user_id limit 1');
|
||||||
@@ -75,6 +63,17 @@ function get_stations($con) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function get_stations_all($con) {
|
||||||
|
try {
|
||||||
|
$stmt = $con->prepare("SELECT * FROM Station");
|
||||||
|
$stmt->execute();
|
||||||
|
$stmt->setFetchMode(PDO::FETCH_ASSOC);
|
||||||
|
return $stmt;
|
||||||
|
} catch(PDOException $e) {
|
||||||
|
handle_pdo_exceptio($e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function get_teams($con) {
|
function get_teams($con) {
|
||||||
try {
|
try {
|
||||||
$stmt = $con->prepare("SELECT name, feuerwehr FROM Mannschaft");
|
$stmt = $con->prepare("SELECT name, feuerwehr FROM Mannschaft");
|
||||||
@@ -96,3 +95,25 @@ function get_total_score($con) {
|
|||||||
handle_pdo_exception($e);
|
handle_pdo_exception($e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function get_station_name($con, $s_id) {
|
||||||
|
try {
|
||||||
|
$stmt = $con->prepare("SELECT name FROM Station WHERE s_id= :s_id");
|
||||||
|
$stmt->execute(['s_id' => $s_id]);
|
||||||
|
$stmt->setFetchMode(PDO::FETCH_ASSOC);
|
||||||
|
return $stmt->fetch();
|
||||||
|
} catch(PDOException $e) {
|
||||||
|
handle_pdo_exception($e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_station($con, $s_id) {
|
||||||
|
try {
|
||||||
|
$stmt = $con->prepare("SELECT M.name as Name, M.feuerwehr as Feuerwehr, P.punkte as Punkte, P.zeit as Zeit FROM Punkte as P, Station as S, Mannschaft as M WHERE P.s_id = S.s_id AND S.s_id = :s_id AND M.m_id = P.m_id ORDER BY Punkte DESC");
|
||||||
|
$stmt->execute(['s_id' => $s_id]);
|
||||||
|
$stmt->setFetchMode(PDO::FETCH_ASSOC);
|
||||||
|
return $stmt;
|
||||||
|
} catch(PDOException $e) {
|
||||||
|
handle_pdo_exception($e);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -55,12 +55,57 @@ function load_teams_table($con) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function load_total_score($con) {
|
function load_total_score($con) {
|
||||||
|
echo "<thead> \n
|
||||||
|
<th scope=\"col\">Mannschaft</th>\n
|
||||||
|
<th scope=\"col\">Feuerwehr</th>\n
|
||||||
|
<th scope=\"col\">Gesamtpunkte</th>\n
|
||||||
|
</thead>\n
|
||||||
|
<tbody>\n";
|
||||||
$stmt = get_total_score($con);
|
$stmt = get_total_score($con);
|
||||||
foreach($stmt->fetchAll() as $row) {
|
foreach($stmt->fetchAll() as $row) {
|
||||||
echo "<tr>";
|
echo "<tr>\n";
|
||||||
echo "<td>" . $row['Mannschaftsname'] . "</td>";
|
echo "<td>" . $row['Mannschaftsname'] . "</td>\n";
|
||||||
echo "<td>" . $row['Feuerwehr'] . "</td>";
|
echo "<td>" . $row['Feuerwehr'] . "</td>\n";
|
||||||
echo "<td>" . $row['Gesamtpunkte'] . "</td>";
|
echo "<td>" . $row['Gesamtpunkte'] . "</td>\n";
|
||||||
echo "</tr>";
|
echo "</tr>\n";
|
||||||
|
}
|
||||||
|
echo "</tbody>\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
function load_options_stations($con, $session) {
|
||||||
|
$stmt = get_stations_all($con);
|
||||||
|
if ($session == "total-score"){
|
||||||
|
$total_score_selected = " selected";
|
||||||
|
} else {
|
||||||
|
$total_score_selected = "";
|
||||||
|
}
|
||||||
|
echo "<option value=\"total-score\"" . $total_score_selected . ">Gesamtpunkte</option>";
|
||||||
|
foreach($stmt->fetchAll() as $option) {
|
||||||
|
if($session == $option['s_id']){
|
||||||
|
$station_selected = " selected";
|
||||||
|
} else {
|
||||||
|
$station_selected = "";
|
||||||
|
}
|
||||||
|
echo "<option value=\"" . $option['s_id'] . "\"" . $station_selected . ">" . $option['name'] . "</option>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function load_station_table($con, $s_id) {
|
||||||
|
echo "<thead> \n
|
||||||
|
<th scope=\"col\">Mannschaft</th>
|
||||||
|
<th scope=\"col\">Feuerwehr</th>
|
||||||
|
<th scope=\"col\">Punkte</th>
|
||||||
|
<th scope=\"col\">Zeit</th>
|
||||||
|
</thead>
|
||||||
|
<tbody>\n";
|
||||||
|
$stmt = get_station($con, $s_id);
|
||||||
|
foreach($stmt->fetchAll() as $row) {
|
||||||
|
echo "<tr>\n";
|
||||||
|
echo "<td>" . $row['Name'] . "</td>\n";
|
||||||
|
echo "<td>" . $row['Feuerwehr'] . "</td>\n";
|
||||||
|
echo "<td>" . $row['Punkte'] . "</td>\n";
|
||||||
|
echo "<td>" . $row["Zeit"] . "</td>\n";
|
||||||
|
echo "</tr>\n";
|
||||||
|
}
|
||||||
|
echo "</tbody>\n";
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user