94 lines
2.6 KiB
PHP
94 lines
2.6 KiB
PHP
<?php
|
|
session_set_cookie_params([
|
|
'lifetime' => 0,
|
|
'path' => '/',
|
|
'domain' => '',
|
|
'secure' => false,
|
|
'httponly' => true,
|
|
'samesite' => 'Lax'
|
|
]);
|
|
session_start();
|
|
|
|
header('Content-Type: application/json');
|
|
error_reporting(E_ALL);
|
|
ini_set('display_errors', '0');
|
|
|
|
if (empty($_SESSION['user_logged_in'])) {
|
|
http_response_code(401);
|
|
echo json_encode(['error' => 'Nicht eingeloggt']);
|
|
exit;
|
|
}
|
|
|
|
include_once(__DIR__ . '/../../../controller/DatabaseController.php');
|
|
include_once(__DIR__ . '/../../../controller/RoutesController.php');
|
|
include_once(__DIR__ . '/../../../modules/Mail.php');
|
|
|
|
$allowedStatuses = ['OFFEN', 'DEPLOYED', 'ABGELEHNT', 'ANGENOMMEN'];
|
|
|
|
$daten = json_decode(file_get_contents('php://input'), true) ?? [];
|
|
$action = $daten['action'] ?? '';
|
|
|
|
try {
|
|
switch ($action) {
|
|
|
|
// ---------- Alle Tickets laden (Verwaltungsansicht) ----------
|
|
case 'get_entries': {
|
|
$entries = DatabaseShow(
|
|
"Tickets",
|
|
"ID, TITEL, BESCHREIBUNG, STATUS, ERSTELLER",
|
|
);
|
|
|
|
echo json_encode(['success' => true, 'entries' => array_values($entries ?? [])]);
|
|
break;
|
|
}
|
|
|
|
// ---------- Status ändern ----------
|
|
case 'edit_entry': {
|
|
$id = $daten['id'] ?? null;
|
|
$status = $daten['status'] ?? '';
|
|
|
|
if (!is_numeric($id)) {
|
|
throw new InvalidArgumentException('Ungültige ID');
|
|
}
|
|
if (!in_array($status, $allowedStatuses, true)) {
|
|
throw new InvalidArgumentException('Ungültiger Status');
|
|
}
|
|
|
|
DatabaseUpdate(
|
|
"Tickets",
|
|
"STATUS = ?",
|
|
"ID = ?",
|
|
$status,
|
|
(int)$id
|
|
);
|
|
|
|
echo json_encode(['success' => true]);
|
|
break;
|
|
}
|
|
|
|
// ---------- Ticket löschen ----------
|
|
case 'delete_entry': {
|
|
$id = $daten['id'] ?? null;
|
|
|
|
if (!is_numeric($id)) {
|
|
throw new InvalidArgumentException('Ungültige ID');
|
|
}
|
|
|
|
DatabaseDelete("Tickets", "ID = ?", (int)$id);
|
|
|
|
echo json_encode(['success' => true]);
|
|
break;
|
|
}
|
|
|
|
default:
|
|
throw new InvalidArgumentException("Unbekannte Aktion: $action");
|
|
}
|
|
|
|
} catch (InvalidArgumentException $e) {
|
|
http_response_code(400);
|
|
echo json_encode(['error' => $e->getMessage()]);
|
|
} catch (Throwable $e) {
|
|
http_response_code(500);
|
|
error_log($e->getMessage());
|
|
echo json_encode(['error' => 'Serverfehler']);
|
|
} |