diff --git a/api/opfer/delete.php b/api/opfer/delete.php new file mode 100644 index 0000000..c701518 --- /dev/null +++ b/api/opfer/delete.php @@ -0,0 +1,31 @@ +checkAuth()) { + header("Location: /index.html?status=500&error=Unauthorized"); + exit; +} + +if (!isset($_POST["id"])) { + die('{"status":500, "error":"Missing fields"}'); +} + +$id = intval($_POST["id"]); + +$db = $api->getDB(); + +$sql = "DELETE FROM opfer WHERE id = :id"; + +$stmt = $db->prepare($sql); + +$sql_exec = $stmt->execute([':id' => $id]); + +if ($sql_exec) { + header("Location: /index.html?status=200"); +}else{ + header("Location: /index.html?status=500&error=SQL Error"); +} +exit; +?> \ No newline at end of file diff --git a/api/opfer/edit.php b/api/opfer/edit.php new file mode 100644 index 0000000..78b72e7 --- /dev/null +++ b/api/opfer/edit.php @@ -0,0 +1,44 @@ +checkAuth()) { + header("Location: /index.html?status=500&error=Unauthorized"); + exit; +} + +if (!isset($_POST["id"]) || !isset($_POST["name"]) || !isset($_POST["mail"]) || !isset($_POST["number"])) { + die('{"status":500, "error":"Missing fields"}'); +} + +$name = htmlspecialchars($_POST["name"]); +$mail = htmlspecialchars($_POST["mail"]); +$number = intval(htmlspecialchars($_POST["number"])); +echo $number; +$id = intval(htmlspecialchars($_POST["id"])); +if (isset($_POST["enabled2"])) { + $enabled = 1; +}else{ + $enabled = 0; +} + +$db = $api->getDB(); + +$sql = "UPDATE opfer SET name = :name, mail = :mail, number = :number, status = :status WHERE id = :id"; + +$stmt = $db->prepare($sql); + +$sql_exec = $stmt->execute([':name' => $name, ':mail' => $mail, ':number' => $number, ':status' => $enabled, ':id' => $id]); + +if ($sql_exec) { + header("Location: /index.html?status=200"); +}else{ + header("Location: /index.html?status=500&error=SQL Error"); +} +exit; +?> \ No newline at end of file diff --git a/api/opfer/info.php b/api/opfer/info.php index 6cfade3..36fa685 100644 --- a/api/opfer/info.php +++ b/api/opfer/info.php @@ -19,7 +19,7 @@ $sql = "SELECT * FROM opfer WHERE id = :id"; $stmt = $db->prepare($sql); $stmt->execute([':id' => $id]); -$result = $stmt->fetchAll(PDO::FETCH_ASSOC); +$result = $stmt->fetch(PDO::FETCH_ASSOC); if ($result) { $json["opfer"] = $result; diff --git a/front/basic-tables.html b/front/basic-tables.html index 90b20af..8c5dce8 100644 --- a/front/basic-tables.html +++ b/front/basic-tables.html @@ -665,7 +665,7 @@ - ---> diff --git a/front/index.html b/front/index.html index 20a349d..c4d44ac 100644 --- a/front/index.html +++ b/front/index.html @@ -639,7 +639,7 @@

- Das neue Opfer wurde erfolgreich hinzugefügt! + Die Aktion wurde erfolgreich ausgeführt

@@ -751,7 +751,7 @@ - ---> @@ -1014,6 +1061,7 @@ -
+ +
+
+
+
- ---> diff --git a/tailadmin/src/index.html b/tailadmin/src/index.html index b9edfc3..24a80a0 100644 --- a/tailadmin/src/index.html +++ b/tailadmin/src/index.html @@ -96,7 +96,7 @@

- Das neue Opfer wurde erfolgreich hinzugefügt! + Die Aktion wurde erfolgreich ausgeführt

@@ -179,6 +179,115 @@ document.getElementById("alert-error").style.display = "block"; } } + + fetch("/api/opfer/list.php") + .then(response => response.json()) + .then(data => { + if (data.status == 500) { + console.error("API Error: " + data.error); + } + + var list = document.getElementById("opfer_table").innerHTML; + + for (const opfer of data.opfer) { + if (opfer.enabled) { + var status_class = "rounded-full bg-success-50 px-2 py-0.5 text-theme-xs font-medium text-success-700 dark:bg-success-500/15 dark:text-success-500"; + var status_text = "Enabled"; + }else{ + var status_class = "rounded-full bg-error-50 px-2 py-0.5 text-theme-xs font-medium text-error-700 dark:bg-error-500/15 dark:text-error-500"; + var status_text = "Disabled"; + } + + list += ` + + +
+
+
+ + ` + opfer.name + ` + +
+
+
+ + +
+

+ ` + opfer.mail + ` +

+
+ + +
+

+ ` + status_text + ` +

+
+ + +
+

` + opfer.number + `

+
+ + + `; + } + document.getElementById("opfer_table").innerHTML = list; + }) + .catch(error => console.error("API Error: " + error)) + + function opferEdit(id) { + console.log(document.getElementById("opfer_name")); + fetch("/api/opfer/info.php", { + method: "POST", + headers: { + "Content-Type": "application/x-www-form-urlencoded" + }, + body: "id=" + id + }) + .then(response => response.json()) + .then(data => { + if (data.status == 500) { + console.error("API Error: " + data.error); + } + + const opfer = data.opfer; + + document.getElementById("opfer_id").value = id; + document.getElementById("opfer_name").value = opfer.name; + document.getElementById("opfer_mail").value = opfer.mail; + document.getElementById("opfer_number").value = opfer.number; + + + if (data.status == 1) { + const toogle_el = document.querySelector('#toggle2'); + const toogle_data = Alpine.$data(document.getElementById("toogle2_div")); + + toogle_data.switcherToggle = data.status; + toogle_el.checked = data.status; + } + }) + } + + function removeOpfer() { + const id = document.getElementById("opfer_id").value; + + fetch("/api/opfer/delete.php", { + method: "POST", + headers: { + "Content-Type": "application/x-www-form-urlencoded" + }, + body: "id=" + id + }) + window.location.reload(); + } diff --git a/tailadmin/src/partials/profile/opfer_edit.html b/tailadmin/src/partials/profile/opfer_edit.html index ab5ac9a..73c539b 100644 --- a/tailadmin/src/partials/profile/opfer_edit.html +++ b/tailadmin/src/partials/profile/opfer_edit.html @@ -90,7 +90,7 @@ /> -
+ +
+
+
+
- ---> diff --git a/tmp/user_sessions/marc.json b/tmp/user_sessions/marc.json index 617ace5..7657dcf 100755 --- a/tmp/user_sessions/marc.json +++ b/tmp/user_sessions/marc.json @@ -1 +1 @@ -{"270":{"session_id":"896d8b84fd9ae2471bc70a2023f55db83a8e88244bfb92f0c06e7a05c8d03599"}} \ No newline at end of file +{"790":{"session_id":"a1e9095da4163edca39dac5b27750ebabbe40cb047115202465374ced9e3732b"}} \ No newline at end of file