entries in the team table can be edit now
This commit is contained in:
51
app/public/edit_team.php
Normal file
51
app/public/edit_team.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
session_start();
|
||||
include("../scripts/connection.php");
|
||||
include("../scripts/functions.php");
|
||||
$user_data = check_login($con);
|
||||
|
||||
if($_SERVER['REQUEST_METHOD'] == "GET") {
|
||||
$row = get_team($con, $_GET['m_id'])->fetch();
|
||||
}
|
||||
|
||||
if($_SERVER['REQUEST_METHOD'] == "POST") {
|
||||
$row = get_team($con, $_POST['m_id'])->fetch();
|
||||
|
||||
if($_POST['team_name'] != $row['name']) {
|
||||
update_team_name($con, $_POST['m_id'], $_POST['team_name']);
|
||||
}
|
||||
|
||||
if($_POST['fire_department'] != $row['feuerwehr']) {
|
||||
update_team_fire_department($con, $_POST['m_id'], $_POST['fire_department']);
|
||||
}
|
||||
|
||||
header("Location: mannschaft.php");
|
||||
die;
|
||||
}
|
||||
|
||||
include("header_footer/header.php");
|
||||
?>
|
||||
<body>
|
||||
<div class="headline">
|
||||
<h2>Mannschaft bearbeiten</h2>
|
||||
</div>
|
||||
<div>
|
||||
<form method="post">
|
||||
<label for="team_name">Mannschaftsname</label>
|
||||
<input type="text" name="team_name" <?php echo "value=\"" . $row['name'] . "\""?> /><br>
|
||||
<label for="fire_department">Feuerwehr</label>
|
||||
<input type="text" name="fire_department" list="fire_departments" <?php echo "value=\"" . $row['feuerwehr'] . "\"" ?>/><br>
|
||||
<datalist id="fire_departments">
|
||||
<?php
|
||||
load_fire_departments($con);
|
||||
?>
|
||||
</datalist>
|
||||
<input type="hidden" name="m_id" <?php echo "value=\"" . $row['m_id'] . "\""?> />
|
||||
<input type="submit" value="Speichern"/>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
<?php
|
||||
$con = null;
|
||||
echo file_get_contents("header_footer/footer.html");
|
||||
?>
|
||||
@@ -13,6 +13,7 @@ function init() {
|
||||
user_edit_button();
|
||||
statistic_edit_button();
|
||||
station_edit_button();
|
||||
team_edit_button();
|
||||
}
|
||||
|
||||
var selected = null;
|
||||
@@ -77,4 +78,15 @@ function station_edit_button() {
|
||||
this.form.submit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function team_edit_button() {
|
||||
var button = document.getElementById('edit_team');
|
||||
if(button != null) {
|
||||
button.onclick = function() {
|
||||
var row = document.getElementsByClassName('selected')[0];
|
||||
document.getElementById('m_id').value = row.id;
|
||||
this.form.submit();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,13 @@
|
||||
</div>
|
||||
<div>
|
||||
<form action="add_team.php" method="get">
|
||||
<input id="butto" type="submit" value="Mannschaft hinzufügen">
|
||||
<input id="button" type="submit" value="Mannschaft hinzufügen"/>
|
||||
</form>
|
||||
</div>
|
||||
<div>
|
||||
<form action="edit_team.php" method="get">
|
||||
<input id="edit_team" type="button" value="Bearbeiten" class="edit" disabled="true"/>
|
||||
<input type="hidden" id="m_id" name="m_id">
|
||||
</form>
|
||||
</div>
|
||||
<div class="table-div">
|
||||
|
||||
@@ -76,7 +76,7 @@ function get_stations_all($con) {
|
||||
|
||||
function get_teams($con) {
|
||||
try {
|
||||
$stmt = $con->prepare("SELECT name, feuerwehr FROM Mannschaft");
|
||||
$stmt = $con->prepare("SELECT * FROM Mannschaft");
|
||||
$stmt->execute();
|
||||
$stmt->setFetchMode(PDO::FETCH_ASSOC);
|
||||
return $stmt;
|
||||
@@ -373,8 +373,6 @@ function get_station_all($con, $s_id) {
|
||||
|
||||
function update_station_name($con, $s_id, $name) {
|
||||
try {
|
||||
echo $s_id . "\n";
|
||||
echo $name . "\n";
|
||||
$stmt = $con->prepare("UPDATE Station SET name = ? WHERE s_id = ?");
|
||||
$stmt->bindParam(1, $name, PDO::PARAM_STR);
|
||||
$stmt->bindParam(2, $s_id, PDO::PARAM_INT);
|
||||
@@ -393,4 +391,37 @@ function update_station_pos($con, $s_id, $pos) {
|
||||
} catch(PDOException $e) {
|
||||
handle_pdo_exception($e);
|
||||
}
|
||||
}
|
||||
|
||||
function get_team($con, $m_id) {
|
||||
try {
|
||||
$stmt = $con->prepare("SELECT * FROM Mannschaft WHERE m_id = :m_id");
|
||||
$stmt->execute(['m_id' => $m_id]);
|
||||
$stmt->setFetchMode(PDO::FETCH_ASSOC);
|
||||
return $stmt;
|
||||
} catch(PDOException $e) {
|
||||
handle_pdo_exception($e);
|
||||
}
|
||||
}
|
||||
|
||||
function update_team_name($con, $m_id, $name) {
|
||||
try {
|
||||
$stmt = $con->prepare("UPDATE Mannschaft SET name = ? WHERE m_id = ?");
|
||||
$stmt->bindParam(1, $name, PDO::PARAM_STR);
|
||||
$stmt->bindParam(2, $m_id, PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
} catch(PDOException $e) {
|
||||
handle_pdo_exception($e);
|
||||
}
|
||||
}
|
||||
|
||||
function update_team_fire_department($con, $m_id, $dep) {
|
||||
try {
|
||||
$stmt = $con->prepare("UPDATE Mannschaft SET feuerwehr = ? WHERE m_id = ?");
|
||||
$stmt->bindParam(1, $dep, PDO::PARAM_STR);
|
||||
$stmt->bindParam(2, $m_id, PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
} catch(PDOException $e) {
|
||||
handle_pdo_exception($e);
|
||||
}
|
||||
}
|
||||
@@ -47,7 +47,7 @@ function load_stations_table($con) {
|
||||
function load_teams_table($con) {
|
||||
$stmt = get_teams($con);
|
||||
foreach($stmt->fetchAll() as $row) {
|
||||
echo "<tr>";
|
||||
echo "<tr id=\"" . $row['m_id'] . "\" >";
|
||||
echo "<td>" . $row['name'] . "</td>";
|
||||
echo "<td>" . $row['feuerwehr'] . "</td>";
|
||||
echo "</tr>";
|
||||
|
||||
Reference in New Issue
Block a user