Refactored file system
Changed the file system to a more ordered state and updated links in files accordingly. Also the reffering to files is now uniform
This commit is contained in:
130
php/admin.php
Normal file
130
php/admin.php
Normal file
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
session_start();
|
||||
if (!isset($_SESSION["loggedIn"])) {
|
||||
header("Location: ../pages/login.html");
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Admin Dashboard</title>
|
||||
<link rel="stylesheet" href="../css/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container-dashboard">
|
||||
<div class="header-with-image">
|
||||
<h2>Admin Dashboard</h2>
|
||||
<img src="img/csg.png" width="100" />
|
||||
</div>
|
||||
|
||||
<a href="../php/logout.php" class="logout-btn">Logout</a>
|
||||
|
||||
<div class="dashboard">
|
||||
<!-- Linke Ticket-Übersicht -->
|
||||
<div id="ticket-list" class="ticket-list">
|
||||
<h3>Tickets Übersicht</h3>
|
||||
<ul id="tickets-ul"></ul>
|
||||
</div>
|
||||
|
||||
<!-- Rechte Ticket-Details -->
|
||||
<div id="ticket-details" class="ticket-details">
|
||||
<p>Wähle ein Ticket aus der Liste links aus.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
let tickets = [];
|
||||
|
||||
async function ladeTickets() {
|
||||
try {
|
||||
const response = await fetch('../data/tickets.json?ts=' + Date.now(), {cache:"no-store"});
|
||||
tickets = await response.json();
|
||||
|
||||
const ul = document.getElementById('tickets-ul');
|
||||
ul.innerHTML = '';
|
||||
|
||||
if (!Array.isArray(tickets) || tickets.length === 0) {
|
||||
ul.innerHTML = '<li>Keine Tickets vorhanden</li>';
|
||||
return;
|
||||
}
|
||||
|
||||
tickets.forEach((ticket, index) => {
|
||||
const li = document.createElement('li');
|
||||
li.textContent = ticket.title ?? "Kein Titel";
|
||||
li.className = 'ticket-item';
|
||||
li.addEventListener('click', () => showTicketDetails(index));
|
||||
ul.appendChild(li);
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
document.getElementById('ticket-details').innerHTML = 'Fehler beim Laden der Tickets.';
|
||||
}
|
||||
}
|
||||
|
||||
function showTicketDetails(index) {
|
||||
const ticket = tickets[index];
|
||||
const details = document.getElementById('ticket-details');
|
||||
|
||||
details.innerHTML = `
|
||||
<h3>${ticket.title ?? "Kein Titel"}</h3>
|
||||
<p><strong>Kategorie:</strong> ${ticket.category ?? "-"}</p>
|
||||
<p><strong>Raum:</strong> ${ticket.room ?? "-"}</p>
|
||||
<p><strong>Name:</strong> ${ticket.name ?? "-"}</p>
|
||||
<p>${ticket.description ?? "-"}</p>
|
||||
<p><em>${ticket.date ?? "-"}</em></p>
|
||||
|
||||
<label>Status ändern:</label>
|
||||
<select id="status-select">
|
||||
<option value="To-Do" ${ticket.status==="To-Do"?"selected":""}>To-Do</option>
|
||||
<option value="InProgress" ${ticket.status==="InProgress"?"selected":""}>InProgress</option>
|
||||
<option value="Done" ${ticket.status==="Done"?"selected":""}>Done</option>
|
||||
</select>
|
||||
<button id="save-status">Speichern</button>
|
||||
<button id="delete-ticket" class="delete-btn">Löschen</button>
|
||||
`;
|
||||
|
||||
document.getElementById('save-status').addEventListener('click', async () => {
|
||||
const newStatus = document.getElementById('status-select').value;
|
||||
ticket.status = newStatus;
|
||||
|
||||
const res = await fetch('./update_ticket.php', {
|
||||
method:'POST',
|
||||
headers:{'Content-Type':'application/json'},
|
||||
body:JSON.stringify({index, ticket})
|
||||
});
|
||||
const data = await res.json();
|
||||
if(data.success){
|
||||
alert("Status aktualisiert!");
|
||||
ladeTickets();
|
||||
} else {
|
||||
alert("Fehler beim Aktualisieren!");
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById('delete-ticket').addEventListener('click', async () => {
|
||||
if(!confirm("Ticket wirklich löschen?")) return;
|
||||
|
||||
const res = await fetch('./backend/delete_ticket.php', {
|
||||
method:'POST',
|
||||
headers:{'Content-Type':'application/json'},
|
||||
body:JSON.stringify({index})
|
||||
});
|
||||
const data = await res.json();
|
||||
if(data.success){
|
||||
alert("Ticket gelöscht!");
|
||||
details.innerHTML = "<p>Wähle ein Ticket aus der Liste links aus.</p>";
|
||||
ladeTickets();
|
||||
} else {
|
||||
alert("Fehler beim Löschen!");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ladeTickets();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
141
php/dashboard.php
Normal file
141
php/dashboard.php
Normal file
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
session_start();
|
||||
if(!isset($_SESSION['user_id'])){
|
||||
header("Location: ../pages/login.html");
|
||||
exit;
|
||||
}
|
||||
echo "Willkommen im Dashboard, ".$_SESSION['role']."!";
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Admin Dashboard</title>
|
||||
<link rel="stylesheet" href="../css/style.css"> <!-- Pfad zu CSS anpassen -->
|
||||
<style>
|
||||
body {
|
||||
display: flex;
|
||||
margin: 0;
|
||||
font-family: Arial, sans-serif;
|
||||
}
|
||||
/* Sidebar */
|
||||
.sidebar {
|
||||
width: 220px;
|
||||
background-color: #2b79c2;
|
||||
color: white;
|
||||
height: 100vh;
|
||||
padding-top: 2rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.sidebar a {
|
||||
color: white;
|
||||
text-decoration: none;
|
||||
padding: 1rem 1.5rem;
|
||||
display: block;
|
||||
transition: background 0.3s;
|
||||
}
|
||||
.sidebar a:hover, .sidebar a.active {
|
||||
background-color: #1d5fa0;
|
||||
}
|
||||
|
||||
/* Content */
|
||||
.content {
|
||||
flex: 1;
|
||||
padding: 2rem;
|
||||
background: #f0f2f5;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
h2 {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.button-panel {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
flex-wrap: wrap;
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.button-panel button {
|
||||
padding: 1rem 1.5rem;
|
||||
font-size: 1rem;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
background-color: #2b79c2;
|
||||
color: white;
|
||||
transition: background 0.3s;
|
||||
}
|
||||
|
||||
.button-panel button:hover {
|
||||
background-color: #1d5fa0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="sidebar">
|
||||
<a href="#" class="active" data-section="welcome">Willkommen</a>
|
||||
<a href="#" data-section="tickets">Tickets</a>
|
||||
<a href="#" data-section="users">Benutzer</a>
|
||||
<a href="#" data-section="settings">Persönliche Einstellungen</a>
|
||||
<a href="./logout.php">Logout</a>
|
||||
</div>
|
||||
|
||||
<div class="content" id="main-content">
|
||||
<!-- Start: Welcome -->
|
||||
<div class="welcome-box">
|
||||
<h2>Admin Dashboard</h2>
|
||||
<p>Angemeldet als: <?= htmlspecialchars($_SESSION["username"]) ?></p>
|
||||
<a href="./logout.php">Logout</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const username = "<?php echo $username; ?>"; // Variable aus PHP ins JS
|
||||
|
||||
const links = document.querySelectorAll('.sidebar a');
|
||||
const content = document.getElementById('main-content');
|
||||
|
||||
links.forEach(link => {
|
||||
link.addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
links.forEach(l => l.classList.remove('active'));
|
||||
this.classList.add('active');
|
||||
|
||||
const section = this.dataset.section;
|
||||
switch(section) {
|
||||
case 'welcome':
|
||||
content.innerHTML = `
|
||||
<div class="welcome-box">
|
||||
<h2>Willkommen, ${username}!</h2>
|
||||
<p>Hier siehst du eine Übersicht und kannst über die Buttons neue Bereiche öffnen:</p>
|
||||
<div class="button-panel">
|
||||
<button onclick="window.location.href='./users.php'">Benutzer erstellen</button>
|
||||
<button onclick="window.location.href='./admin.php'">Tickets verwalten</button>
|
||||
<button onclick="window.location.href='./deleted_tickets.php'">Gelöschte Tickets</button>
|
||||
<button onclick="window.location.href='./settings.php'">Persönliche Einstellungen</button>
|
||||
</div>
|
||||
</div>`;
|
||||
break;
|
||||
case 'tickets':
|
||||
content.innerHTML = '<h2>Tickets</h2><p>Tickets-Panel wird hier geladen...</p>';
|
||||
break;
|
||||
case 'users':
|
||||
content.innerHTML = '<h2>Benutzerverwaltung</h2><p>Hier kannst du Benutzer hinzufügen, bearbeiten oder löschen.</p>';
|
||||
break;
|
||||
case 'settings':
|
||||
content.innerHTML = '<h2>Persönliche Einstellungen</h2><p>Hier kannst du dein Passwort oder andere Einstellungen ändern.</p>';
|
||||
break;
|
||||
default:
|
||||
content.innerHTML = '<p>Unbekannte Sektion</p>';
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
32
php/delete_ticket.php
Normal file
32
php/delete_ticket.php
Normal 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__ . '../data/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
php/login.php
Normal file
32
php/login.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
$username = $_POST['username'] ?? '';
|
||||
$password = $_POST['password'] ?? '';
|
||||
|
||||
$usersFile = __DIR__ . "../data/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: ../pages/login.html?error=1");
|
||||
exit;
|
||||
}
|
||||
6
php/logout.php
Normal file
6
php/logout.php
Normal file
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
session_start();
|
||||
session_destroy();
|
||||
header("Location: ../pages/login.html");
|
||||
exit;
|
||||
?>
|
||||
40
php/save_ticket.php
Normal file
40
php/save_ticket.php
Normal 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__ . '../data/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: ../pages/ticket_submit.html?success=1');
|
||||
exit;
|
||||
33
php/update_ticket.php
Normal file
33
php/update_ticket.php
Normal 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__ . '../data/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]);
|
||||
Reference in New Issue
Block a user