|
@@ -0,0 +1,306 @@
|
|
|
|
|
+<?php
|
|
|
|
|
+require_once __DIR__ . "/../config.php";
|
|
|
|
|
+require_once __DIR__ . "/../includes/functions.php";
|
|
|
|
|
+
|
|
|
|
|
+if (empty($_SESSION['admin_logged_in'])) {
|
|
|
|
|
+ header("Location: login.php");
|
|
|
|
|
+ exit();
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+$pageTitle = "Namensschilder";
|
|
|
|
|
+$message = "";
|
|
|
|
|
+$messageType = "";
|
|
|
|
|
+
|
|
|
|
|
+if ($_SERVER['REQUEST_METHOD'] === "POST" && isset($_POST['add_nametag'])) {
|
|
|
|
|
+ if (!validateCsrfToken($_POST['csrf_token'] ?? "")) {
|
|
|
|
|
+ $message = "Ungültiges Token. Bitte versuchen Sie es erneut.";
|
|
|
|
|
+ $messageType = "error";
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $result = addNametagOrder(
|
|
|
|
|
+ $_POST['person_name'] ?? "",
|
|
|
|
|
+ $_POST['organization_id'] ?? "",
|
|
|
|
|
+ $_POST['quantity'] ?? 1,
|
|
|
|
|
+ $_POST['note'] ?? "",
|
|
|
|
|
+ );
|
|
|
|
|
+ $message = $result["success"]
|
|
|
|
|
+ ? "Namensschild-Bestellung wurde hinzugefügt."
|
|
|
|
|
+ : $result["message"];
|
|
|
|
|
+ $messageType = $result["success"] ? "success" : "error";
|
|
|
|
|
+
|
|
|
|
|
+ if ($result["success"]) {
|
|
|
|
|
+ logAccess("Admin added nametag order", [
|
|
|
|
|
+ "admin" => $_SESSION['admin_username'] ?? "unknown",
|
|
|
|
|
+ "person_name" => $_POST['person_name'] ?? "",
|
|
|
|
|
+ ]);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+if ($_SERVER['REQUEST_METHOD'] === "POST" && isset($_POST['mark_ordered'])) {
|
|
|
|
|
+ if (!validateCsrfToken($_POST['csrf_token'] ?? "")) {
|
|
|
|
|
+ $message = "Ungültiges Token. Bitte versuchen Sie es erneut.";
|
|
|
|
|
+ $messageType = "error";
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $result = markNametagOrdered($_POST['id'] ?? "");
|
|
|
|
|
+ $message = $result["success"]
|
|
|
|
|
+ ? "Namensschild wurde als bestellt markiert."
|
|
|
|
|
+ : $result["message"];
|
|
|
|
|
+ $messageType = $result["success"] ? "success" : "error";
|
|
|
|
|
+
|
|
|
|
|
+ if ($result["success"]) {
|
|
|
|
|
+ logAccess("Admin marked nametag ordered", [
|
|
|
|
|
+ "admin" => $_SESSION['admin_username'] ?? "unknown",
|
|
|
|
|
+ "id" => $_POST['id'] ?? "",
|
|
|
|
|
+ ]);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+if ($_SERVER['REQUEST_METHOD'] === "POST" && isset($_POST['mark_delivered'])) {
|
|
|
|
|
+ if (!validateCsrfToken($_POST['csrf_token'] ?? "")) {
|
|
|
|
|
+ $message = "Ungültiges Token. Bitte versuchen Sie es erneut.";
|
|
|
|
|
+ $messageType = "error";
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $result = markNametagDelivered($_POST['id'] ?? "");
|
|
|
|
|
+ $message = $result["success"]
|
|
|
|
|
+ ? "Namensschild wurde als geliefert markiert."
|
|
|
|
|
+ : $result["message"];
|
|
|
|
|
+ $messageType = $result["success"] ? "success" : "error";
|
|
|
|
|
+
|
|
|
|
|
+ if ($result["success"]) {
|
|
|
|
|
+ logAccess("Admin marked nametag delivered", [
|
|
|
|
|
+ "admin" => $_SESSION['admin_username'] ?? "unknown",
|
|
|
|
|
+ "id" => $_POST['id'] ?? "",
|
|
|
|
|
+ ]);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+if ($_SERVER['REQUEST_METHOD'] === "POST" && isset($_POST['delete_nametag'])) {
|
|
|
|
|
+ if (!validateCsrfToken($_POST['csrf_token'] ?? "")) {
|
|
|
|
|
+ $message = "Ungültiges Token. Bitte versuchen Sie es erneut.";
|
|
|
|
|
+ $messageType = "error";
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $result = deleteNametagOrder($_POST['id'] ?? "");
|
|
|
|
|
+ $message = $result["success"]
|
|
|
|
|
+ ? "Position wurde gelöscht."
|
|
|
|
|
+ : $result["message"];
|
|
|
|
|
+ $messageType = $result["success"] ? "success" : "error";
|
|
|
|
|
+
|
|
|
|
|
+ if ($result["success"]) {
|
|
|
|
|
+ logAccess("Admin deleted nametag order", [
|
|
|
|
|
+ "admin" => $_SESSION['admin_username'] ?? "unknown",
|
|
|
|
|
+ "id" => $_POST['id'] ?? "",
|
|
|
|
|
+ ]);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+$openNametags = getOpenNametagOrders();
|
|
|
|
|
+$orderedNametags = getOrderedNametagOrders();
|
|
|
|
|
+$organizations = getOrganizations(true);
|
|
|
|
|
+
|
|
|
|
|
+$bodyClass = "admin-page";
|
|
|
|
|
+include __DIR__ . "/../includes/header.php";
|
|
|
|
|
+?>
|
|
|
|
|
+
|
|
|
|
|
+<div class="admin-header">
|
|
|
|
|
+ <h2>Namensschilder</h2>
|
|
|
|
|
+ <div>
|
|
|
|
|
+ <a href="index.php" class="btn btn-secondary">Zurück zum Dashboard</a>
|
|
|
|
|
+ <a href="backorders.php" class="btn btn-secondary">Nachbestellungen</a>
|
|
|
|
|
+ </div>
|
|
|
|
|
+</div>
|
|
|
|
|
+
|
|
|
|
|
+<?php if ($message !== ""): ?>
|
|
|
|
|
+ <div class="alert alert-<?php echo escape($messageType); ?>">
|
|
|
|
|
+ <?php echo escape($message); ?>
|
|
|
|
|
+ </div>
|
|
|
|
|
+<?php endif; ?>
|
|
|
|
|
+
|
|
|
|
|
+<p class="text-muted">
|
|
|
|
|
+ Namensschilder werden personalisiert und separat vom Gerätewart bestellt.
|
|
|
|
|
+ Hier werden alle noch zu bestellenden Namensschilder mit dem Namen der Person aufgeführt.
|
|
|
|
|
+</p>
|
|
|
|
|
+
|
|
|
|
|
+<div class="admin-panel backorder-add-panel">
|
|
|
|
|
+ <h3>Namensschild-Bestellung anlegen</h3>
|
|
|
|
|
+ <form method="POST" class="admin-filter-form backorder-add-form">
|
|
|
|
|
+ <?php echo csrfField(); ?>
|
|
|
|
|
+ <div class="admin-filter-field">
|
|
|
|
|
+ <label for="nametag_person_name">Name der Person</label>
|
|
|
|
|
+ <input
|
|
|
|
|
+ type="text"
|
|
|
|
|
+ id="nametag_person_name"
|
|
|
|
|
+ name="person_name"
|
|
|
|
|
+ required
|
|
|
|
|
+ maxlength="120"
|
|
|
|
|
+ >
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div class="admin-filter-field">
|
|
|
|
|
+ <label for="nametag_organization">Organisation</label>
|
|
|
|
|
+ <select id="nametag_organization" name="organization_id">
|
|
|
|
|
+ <option value="">Keine</option>
|
|
|
|
|
+ <?php foreach ($organizations as $organization): ?>
|
|
|
|
|
+ <option value="<?php echo escape(
|
|
|
|
|
+ $organization["id"],
|
|
|
|
|
+ ); ?>">
|
|
|
|
|
+ <?php echo escape($organization["label"]); ?>
|
|
|
|
|
+ </option>
|
|
|
|
|
+ <?php endforeach; ?>
|
|
|
|
|
+ </select>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div class="admin-filter-field">
|
|
|
|
|
+ <label for="nametag_quantity">Anzahl</label>
|
|
|
|
|
+ <input
|
|
|
|
|
+ type="number"
|
|
|
|
|
+ id="nametag_quantity"
|
|
|
|
|
+ name="quantity"
|
|
|
|
|
+ min="1"
|
|
|
|
|
+ max="20"
|
|
|
|
|
+ value="1"
|
|
|
|
|
+ class="backorder-qty-input"
|
|
|
|
|
+ >
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div class="admin-filter-field admin-filter-field-wide">
|
|
|
|
|
+ <label for="nametag_note">Hinweis</label>
|
|
|
|
|
+ <input
|
|
|
|
|
+ type="text"
|
|
|
|
|
+ id="nametag_note"
|
|
|
|
|
+ name="note"
|
|
|
|
|
+ maxlength="200"
|
|
|
|
|
+ placeholder="Optional, z. B. Funktion oder Schreibweise"
|
|
|
|
|
+ >
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <button type="submit" name="add_nametag" class="btn">
|
|
|
|
|
+ Zur Bestellliste hinzufügen
|
|
|
|
|
+ </button>
|
|
|
|
|
+ </form>
|
|
|
|
|
+</div>
|
|
|
|
|
+
|
|
|
|
|
+<h3 class="section-title mt-4">Ausstehende Bestellungen</h3>
|
|
|
|
|
+<?php if (empty($openNametags)): ?>
|
|
|
|
|
+ <div class="alert alert-info">
|
|
|
|
|
+ <p>Keine ausstehenden Namensschild-Bestellungen vorhanden.</p>
|
|
|
|
|
+ </div>
|
|
|
|
|
+<?php else: ?>
|
|
|
|
|
+ <div class="table-responsive">
|
|
|
|
|
+ <table class="responsive-table">
|
|
|
|
|
+ <thead>
|
|
|
|
|
+ <tr>
|
|
|
|
|
+ <th>Name</th>
|
|
|
|
|
+ <th>Organisation</th>
|
|
|
|
|
+ <th>Anzahl</th>
|
|
|
|
|
+ <th>Hinweis</th>
|
|
|
|
|
+ <th>Angelegt</th>
|
|
|
|
|
+ <th>Aktionen</th>
|
|
|
|
|
+ </tr>
|
|
|
|
|
+ </thead>
|
|
|
|
|
+ <tbody>
|
|
|
|
|
+ <?php foreach ($openNametags as $entry): ?>
|
|
|
|
|
+ <tr>
|
|
|
|
|
+ <td data-label="Name"><strong><?php echo escape(
|
|
|
|
|
+ $entry["person_name"],
|
|
|
|
|
+ ); ?></strong></td>
|
|
|
|
|
+ <td data-label="Organisation"><?php echo $entry[
|
|
|
|
|
+ "organization_label"
|
|
|
|
|
+ ] !== ""
|
|
|
|
|
+ ? escape($entry["organization_label"])
|
|
|
|
|
+ : "-"; ?></td>
|
|
|
|
|
+ <td data-label="Anzahl"><?php echo (int) $entry[
|
|
|
|
|
+ "quantity"
|
|
|
|
|
+ ]; ?></td>
|
|
|
|
|
+ <td data-label="Hinweis"><?php echo $entry["note"] !== ""
|
|
|
|
|
+ ? escape($entry["note"])
|
|
|
|
|
+ : "-"; ?></td>
|
|
|
|
|
+ <td data-label="Angelegt"><?php echo escape(
|
|
|
|
|
+ formatDate($entry["created_at"]),
|
|
|
|
|
+ ); ?></td>
|
|
|
|
|
+ <td data-label="Aktionen">
|
|
|
|
|
+ <form method="POST" class="backorder-action-form">
|
|
|
|
|
+ <?php echo csrfField(); ?>
|
|
|
|
|
+ <input type="hidden" name="id" value="<?php echo escape(
|
|
|
|
|
+ $entry["id"],
|
|
|
|
|
+ ); ?>">
|
|
|
|
|
+ <button type="submit" name="mark_ordered" class="btn btn-small">
|
|
|
|
|
+ Als bestellt markieren
|
|
|
|
|
+ </button>
|
|
|
|
|
+ </form>
|
|
|
|
|
+ <form method="POST" class="backorder-action-form inline-form" onsubmit="return confirm('Position wirklich löschen?');">
|
|
|
|
|
+ <?php echo csrfField(); ?>
|
|
|
|
|
+ <input type="hidden" name="id" value="<?php echo escape(
|
|
|
|
|
+ $entry["id"],
|
|
|
|
|
+ ); ?>">
|
|
|
|
|
+ <button type="submit" name="delete_nametag" class="btn btn-small btn-secondary">
|
|
|
|
|
+ Löschen
|
|
|
|
|
+ </button>
|
|
|
|
|
+ </form>
|
|
|
|
|
+ </td>
|
|
|
|
|
+ </tr>
|
|
|
|
|
+ <?php endforeach; ?>
|
|
|
|
|
+ </tbody>
|
|
|
|
|
+ </table>
|
|
|
|
|
+ </div>
|
|
|
|
|
+<?php endif; ?>
|
|
|
|
|
+
|
|
|
|
|
+<h3 class="section-title mt-4">Bestellt, wartet auf Lieferung</h3>
|
|
|
|
|
+<?php if (empty($orderedNametags)): ?>
|
|
|
|
|
+ <div class="alert alert-info">
|
|
|
|
|
+ <p>Keine Namensschilder warten aktuell auf Lieferung.</p>
|
|
|
|
|
+ </div>
|
|
|
|
|
+<?php else: ?>
|
|
|
|
|
+ <div class="table-responsive">
|
|
|
|
|
+ <table class="responsive-table">
|
|
|
|
|
+ <thead>
|
|
|
|
|
+ <tr>
|
|
|
|
|
+ <th>Name</th>
|
|
|
|
|
+ <th>Organisation</th>
|
|
|
|
|
+ <th>Anzahl</th>
|
|
|
|
|
+ <th>Hinweis</th>
|
|
|
|
|
+ <th>Status</th>
|
|
|
|
|
+ <th>Bestellt am</th>
|
|
|
|
|
+ <th>Aktionen</th>
|
|
|
|
|
+ </tr>
|
|
|
|
|
+ </thead>
|
|
|
|
|
+ <tbody>
|
|
|
|
|
+ <?php foreach ($orderedNametags as $entry): ?>
|
|
|
|
|
+ <tr>
|
|
|
|
|
+ <td data-label="Name"><strong><?php echo escape(
|
|
|
|
|
+ $entry["person_name"],
|
|
|
|
|
+ ); ?></strong></td>
|
|
|
|
|
+ <td data-label="Organisation"><?php echo $entry[
|
|
|
|
|
+ "organization_label"
|
|
|
|
|
+ ] !== ""
|
|
|
|
|
+ ? escape($entry["organization_label"])
|
|
|
|
|
+ : "-"; ?></td>
|
|
|
|
|
+ <td data-label="Anzahl"><?php echo (int) $entry[
|
|
|
|
|
+ "quantity"
|
|
|
|
|
+ ]; ?></td>
|
|
|
|
|
+ <td data-label="Hinweis"><?php echo $entry["note"] !== ""
|
|
|
|
|
+ ? escape($entry["note"])
|
|
|
|
|
+ : "-"; ?></td>
|
|
|
|
|
+ <td data-label="Status">
|
|
|
|
|
+ <span class="status status-backorder-waiting">Wartet auf Lieferung</span>
|
|
|
|
|
+ </td>
|
|
|
|
|
+ <td data-label="Bestellt am"><?php echo escape(
|
|
|
|
|
+ formatDate($entry["ordered_at"]),
|
|
|
|
|
+ ); ?></td>
|
|
|
|
|
+ <td data-label="Aktionen">
|
|
|
|
|
+ <form method="POST" class="backorder-action-form">
|
|
|
|
|
+ <?php echo csrfField(); ?>
|
|
|
|
|
+ <input type="hidden" name="id" value="<?php echo escape(
|
|
|
|
|
+ $entry["id"],
|
|
|
|
|
+ ); ?>">
|
|
|
|
|
+ <button type="submit" name="mark_delivered" class="btn btn-small btn-secondary">
|
|
|
|
|
+ Lieferung eingetroffen
|
|
|
|
|
+ </button>
|
|
|
|
|
+ </form>
|
|
|
|
|
+ </td>
|
|
|
|
|
+ </tr>
|
|
|
|
|
+ <?php endforeach; ?>
|
|
|
|
|
+ </tbody>
|
|
|
|
|
+ </table>
|
|
|
|
|
+ </div>
|
|
|
|
|
+<?php endif; ?>
|
|
|
|
|
+
|
|
|
|
|
+<?php include __DIR__ . "/../includes/footer.php"; ?>
|