Files
Backend/WEBROOT/services/ticket_control.php
T

103 lines
3.8 KiB
PHP

<?php
include_once(__DIR__ . '/../controller/DatabaseController.php');
include_once(__DIR__ . '/../controller/RoutesController.php');
include_once(__DIR__ . '/../modules/Mail.php');
$view = $_GET['view'] ?? 'show';
$selectedService = $_GET['service'] ?? null;
$allowedStatuses = ['OFFEN', 'DEPLOYED', 'ABGELEHNT', 'ANGENOMMEN'];
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['edit_entry'])) {
$id = $_POST['id'];
$status = $_POST['status'] ?? '';
if (in_array($status, $allowedStatuses, true)) {
DatabaseUpdate(
"Tickets",
"STATUS = ?",
"ID = ?",
$status,
$id
);
}
redirectToWebsite((new getSpecificData())->getReferer());
exit;
}
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete_entry'])) {
$id = $_POST['id'];
DatabaseDelete(
"Tickets",
"ID = ?",
$id
);
redirectToWebsite((new getSpecificData())->getReferer());
exit;
}
$entries = DatabaseShow(
"Tickets",
"ID, TITEL, BESCHREIBUNG, STATUS, ERSTELLER",
);
?>
<div>
<div class="table-container" style="margin-top: 30px;">
<h3>Ticket Verwaltung</h3>
<?php if (!empty($entries)): ?>
<table class="db-table mobile-responsive-table">
<thead>
<tr>
<th>Titel</th>
<th>Beschreibung</th>
<th>Status</th>
<th>Ersteller</th>
<th style="width: 220px;">Aktion</th>
</tr>
</thead>
<tbody>
<?php foreach ($entries as $entry): ?>
<tr>
<td data-label="Titel"><?= htmlspecialchars($entry['TITEL'] ?? '') ?></td>
<td data-label="Beschreibung"><?= htmlspecialchars($entry['BESCHREIBUNG'] ?? '') ?></td>
<td data-label="Status"><?= htmlspecialchars($entry['STATUS'] ?? '') ?></td>
<td data-label="Ersteller"><?= htmlspecialchars($entry['ERSTELLER'] ?? '') ?></td>
<td data-label="Aktion">
<form method="POST"
style="margin: 0; display: flex; flex-direction: column; gap: 6px; align-items: stretch;">
<input type="hidden" name="id" value="<?= htmlspecialchars($entry['ID'] ?? '') ?>">
<select name="status" class="status-select">
<?php foreach ($allowedStatuses as $statusOption): ?>
<option value="<?= htmlspecialchars($statusOption) ?>"
<?= ($entry['STATUS'] ?? '') === $statusOption ? 'selected' : '' ?>>
<?= htmlspecialchars($statusOption) ?>
</option>
<?php endforeach; ?>
</select>
<button type="submit" name="edit_entry" class="btn-edit">
Speichern
</button>
</form>
<form method="POST"
style="margin: 0; display: flex; flex-direction: column; gap: 6px; align-items: stretch; margin-top: 3pt;">
<input type="hidden" name="id" value="<?= $entry['ID'] ?? '' ?>">
<button type="submit" name="delete_entry" class="btn-delete">
Löschen
</button>
</form>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php else: ?>
<p>Keine Tickets vorhanden.</p>
<?php endif; ?>
</div>
</div>