delete teams

This commit is contained in:
2022-06-17 19:57:14 +02:00
parent 0981887613
commit 0f6492ec46
3 changed files with 46 additions and 2 deletions

View File

@@ -0,0 +1,18 @@
<?php
session_start();
include("../scripts/connection.php");
include("../scripts/functions.php");
$user_data = check_login($con);
if($_SERVER['REQUEST_METHOD'] == "POST") {
try {
$stmt = $con->prepare("DELETE FROM Mannschaft WHERE m_id= :m_id");
$stmt->execute(['m_id' => $_POST['m_id']]);
} catch(PDOException $e) {
handle_pdo_exception($e);
}
}
header("Location: mannschaft.php");
die;
?>

View File

@@ -14,6 +14,7 @@ function init() {
statistic_edit_button(); statistic_edit_button();
station_edit_button(); station_edit_button();
team_edit_button(); team_edit_button();
team_delete_button();
} }
var selected = null; var selected = null;
@@ -24,6 +25,7 @@ function highlight_row() {
for( var i = 0; i < cells.length; i++) { for( var i = 0; i < cells.length; i++) {
var cell = cells[i]; var cell = cells[i];
var buttons = document.getElementsByClassName('edit');
cell.onclick = function() { cell.onclick = function() {
var rowId = this.parentNode.rowIndex; var rowId = this.parentNode.rowIndex;
var rowsNotSelected = table.getElementsByTagName('tr'); var rowsNotSelected = table.getElementsByTagName('tr');
@@ -36,12 +38,16 @@ function highlight_row() {
selected = null; selected = null;
rowSelected.style.backgroundColor = ""; rowSelected.style.backgroundColor = "";
rowSelected.classList.remove('selected'); rowSelected.classList.remove('selected');
document.getElementsByClassName("edit")[0].disabled = true; Array.prototype.forEach.call(buttons, function(button) {
button.disabled = true;
})
} else { } else {
selected = rowId; selected = rowId;
rowSelected.style.backgroundColor = "yellow"; rowSelected.style.backgroundColor = "yellow";
rowSelected.className += " selected"; rowSelected.className += " selected";
document.getElementsByClassName("edit")[0].disabled = false; Array.prototype.forEach.call(buttons, function(button) {
button.disabled = false;
})
} }
} }
} }
@@ -90,3 +96,17 @@ function team_edit_button() {
} }
} }
} }
function team_delete_button() {
var button = document.getElementById('delete_team');
if(button != null) {
button.onclick = function() {
var row = document.getElementsByClassName('selected')[0];
document.getElementById('m_id_delete').value = row.id;
let confirmAction = confirm("Wirklich löschen?");
if (confirmAction) {
this.form.submit();
}
}
}
}

View File

@@ -23,6 +23,12 @@
<input type="hidden" id="m_id" name="m_id"> <input type="hidden" id="m_id" name="m_id">
</form> </form>
</div> </div>
<div>
<form action="delete_team.php" method="post">
<input id="delete_team" type="button" value="Löschen" class="edit" disabled="true"/>
<input type="hidden" name="m_id" id="m_id_delete"/>
</form>
</div>
<div class="table-div"> <div class="table-div">
<table id="table"> <table id="table">
<thead> <thead>