This commit is contained in:
ninortbrgr
2025-10-10 13:45:59 +02:00
parent edde9f07fc
commit fa830f892e
16 changed files with 748 additions and 0 deletions

32
backend/delete_ticket.php Normal file
View File

@@ -0,0 +1,32 @@
<?php
session_start();
if(!isset($_SESSION["loggedIn"])){
echo json_encode(["success"=>false,"message"=>"Nicht eingeloggt"]);
exit;
}
$input = json_decode(file_get_contents("php://input"), true);
$index = $input['index'] ?? null;
if($index === null){
echo json_encode(["success"=>false,"message"=>"Kein Index angegeben"]);
exit;
}
$ticketsPath = __DIR__ . '/tickets.json';
$tickets = [];
if(file_exists($ticketsPath)){
$tickets = json_decode(file_get_contents($ticketsPath), true);
}
if(!isset($tickets[$index])){
echo json_encode(["success"=>false,"message"=>"Ticket existiert nicht"]);
exit;
}
// Ticket löschen
array_splice($tickets, $index, 1);
file_put_contents($ticketsPath, json_encode($tickets, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE), LOCK_EX);
echo json_encode(["success"=>true]);

32
backend/login.php Normal file
View File

@@ -0,0 +1,32 @@
<?php
session_start();
$username = $_POST['username'] ?? '';
$password = $_POST['password'] ?? '';
$usersFile = __DIR__ . "/users.json";
if (!file_exists($usersFile)) {
die("Benutzerdaten fehlen!");
}
$users = json_decode(file_get_contents($usersFile), true);
$loginOk = false;
if (is_array($users)) {
foreach ($users as $user) {
if ($user['username'] === $username && $user['password'] === $password) {
$loginOk = true;
break;
}
}
}
if ($loginOk) {
$_SESSION['loggedIn'] = true;
$_SESSION['username'] = $username;
header("Location: ../admin.php");
exit;
} else {
header("Location: ../login.html?error=1");
exit;
}

6
backend/logout.php Normal file
View File

@@ -0,0 +1,6 @@
<?php
session_start();
session_destroy();
header("Location: login.html");
exit;
?>

40
backend/save_ticket.php Normal file
View File

@@ -0,0 +1,40 @@
<?php
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
http_response_code(405);
echo "Method not allowed";
exit;
}
$title = trim($_POST['title'] ?? '');
$description = trim($_POST['description'] ?? '');
$category = $_POST['category'] ?? 'Sonstiges';
$room = trim($_POST['room'] ?? '');
$name = trim($_POST['name'] ?? '');
$date = date("Y-m-d H:i:s");
$newTicket = [
'title' => $title,
'description' => $description,
'category' => $category,
'room' => $room,
'name' => $name,
'status' => 'To-Do',
'date' => $date
];
$ticketsPath = __DIR__ . '/tickets.json';
$tickets = [];
if (file_exists($ticketsPath)) {
$json = file_get_contents($ticketsPath);
$tickets = json_decode($json, true);
if (!is_array($tickets)) $tickets = [];
}
$tickets[] = $newTicket;
file_put_contents($ticketsPath, json_encode($tickets, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE), LOCK_EX);
// Redirect zurück ins Dashboard oder zur Hauptseite
header('Location: ../index.html?success=1');
exit;

1
backend/tickets.json Normal file
View File

@@ -0,0 +1 @@
[]

33
backend/update_ticket.php Normal file
View File

@@ -0,0 +1,33 @@
<?php
session_start();
if(!isset($_SESSION["loggedIn"])){
echo json_encode(["success"=>false,"message"=>"Nicht eingeloggt"]);
exit;
}
$input = json_decode(file_get_contents("php://input"), true);
$index = $input['index'] ?? null;
$ticket = $input['ticket'] ?? null;
if($index === null || $ticket === null){
echo json_encode(["success"=>false,"message"=>"Keine Daten"]);
exit;
}
$ticketsPath = __DIR__ . '/tickets.json';
$tickets = [];
if(file_exists($ticketsPath)){
$tickets = json_decode(file_get_contents($ticketsPath), true);
}
if(!isset($tickets[$index])){
echo json_encode(["success"=>false,"message"=>"Ticket existiert nicht"]);
exit;
}
// Ticket aktualisieren
$tickets[$index] = $ticket;
file_put_contents($ticketsPath, json_encode($tickets, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE), LOCK_EX);
echo json_encode(["success"=>true]);

9
backend/users.json Normal file
View File

@@ -0,0 +1,9 @@
[
{ "username": "rtbrgr",
"password": "tNafets_9i"
},
{
"username": "admin",
"password": "1234"
}
]