From 0f6492ec4696ccb40c21e5baf210fb604e24f5b0 Mon Sep 17 00:00:00 2001 From: Grisu Date: Fri, 17 Jun 2022 19:57:14 +0200 Subject: [PATCH] delete teams --- app/public/delete_team.php | 18 ++++++++++++++++++ app/public/js/edit_table.js | 24 ++++++++++++++++++++++-- app/public/mannschaft.php | 6 ++++++ 3 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 app/public/delete_team.php diff --git a/app/public/delete_team.php b/app/public/delete_team.php new file mode 100644 index 0000000..f6d694a --- /dev/null +++ b/app/public/delete_team.php @@ -0,0 +1,18 @@ +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; +?> \ No newline at end of file diff --git a/app/public/js/edit_table.js b/app/public/js/edit_table.js index f6ee1e2..7f3fb30 100644 --- a/app/public/js/edit_table.js +++ b/app/public/js/edit_table.js @@ -14,6 +14,7 @@ function init() { statistic_edit_button(); station_edit_button(); team_edit_button(); + team_delete_button(); } var selected = null; @@ -24,6 +25,7 @@ function highlight_row() { for( var i = 0; i < cells.length; i++) { var cell = cells[i]; + var buttons = document.getElementsByClassName('edit'); cell.onclick = function() { var rowId = this.parentNode.rowIndex; var rowsNotSelected = table.getElementsByTagName('tr'); @@ -36,12 +38,16 @@ function highlight_row() { selected = null; rowSelected.style.backgroundColor = ""; rowSelected.classList.remove('selected'); - document.getElementsByClassName("edit")[0].disabled = true; + Array.prototype.forEach.call(buttons, function(button) { + button.disabled = true; + }) } else { selected = rowId; rowSelected.style.backgroundColor = "yellow"; rowSelected.className += " selected"; - document.getElementsByClassName("edit")[0].disabled = false; + Array.prototype.forEach.call(buttons, function(button) { + button.disabled = false; + }) } } } @@ -89,4 +95,18 @@ function team_edit_button() { this.form.submit(); } } +} + +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(); + } + } + } } \ No newline at end of file diff --git a/app/public/mannschaft.php b/app/public/mannschaft.php index 4ff9224..2f3f8ab 100644 --- a/app/public/mannschaft.php +++ b/app/public/mannschaft.php @@ -23,6 +23,12 @@ +
+
+ + +
+