Add Button angepasst
This commit is contained in:
@@ -77,7 +77,6 @@ require_once '../inc/header.php';
|
|||||||
?>
|
?>
|
||||||
|
|
||||||
<div class="container mt-5">
|
<div class="container mt-5">
|
||||||
<h2 class="mb-4">Farbverwaltung</h2>
|
|
||||||
|
|
||||||
<?php if ($message) : ?>
|
<?php if ($message) : ?>
|
||||||
<div class="alert alert-<?= $message_type ?> alert-dismissible fade show" role="alert">
|
<div class="alert alert-<?= $message_type ?> alert-dismissible fade show" role="alert">
|
||||||
@@ -86,42 +85,54 @@ require_once '../inc/header.php';
|
|||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
<div class="card shadow mb-4">
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||||
<div class="card-header bg-primary-subtle text-secondary">
|
<h2 class="mb-0">Farbverwaltung</h2>
|
||||||
<h4 class="mb-0"><?= $edit_mode ? 'Farbe bearbeiten' : 'Neue Farbe hinzufügen'; ?></h4>
|
<a class="btn btn-sm btn-outline-primary" data-bs-toggle="collapse" href="#colorFormCollapse" role="button" aria-expanded="false" aria-controls="colorFormCollapse">
|
||||||
</div>
|
<span class="material-symbols-outlined">add</span>
|
||||||
<div class="card-body">
|
</a>
|
||||||
<form action="colors.php" method="post">
|
</div>
|
||||||
<?php if ($edit_mode): ?>
|
|
||||||
<input type="hidden" name="id" value="<?= htmlspecialchars($edit_color['id']); ?>">
|
<div class="collapse <?= $edit_mode ? 'show' : '' ?>" id="colorFormCollapse">
|
||||||
<?php endif; ?>
|
<div class="card shadow mb-4">
|
||||||
<div class="row g-3">
|
<div class="card-header bg-primary-subtle text-secondary">
|
||||||
<div class="col-md-6">
|
<h4 class="mb-0"><?= $edit_mode ? 'Farbe bearbeiten' : 'Neue Farbe hinzufügen'; ?></h4>
|
||||||
<label for="name" class="form-label">Name der Farbe</label>
|
</div>
|
||||||
<input type="text" class="form-control" id="name" name="name"
|
<div class="card-body">
|
||||||
value="<?= htmlspecialchars($edit_color['name'] ?? ''); ?>" required>
|
<form action="colors.php" method="post">
|
||||||
</div>
|
<?php if ($edit_mode): ?>
|
||||||
<div class="col-md-6">
|
<input type="hidden" name="id" value="<?= htmlspecialchars($edit_color['id']); ?>">
|
||||||
<label for="hex_code" class="form-label">Hex-Code</label>
|
<?php endif; ?>
|
||||||
<input type="color" class="form-control form-control-color" id="hex_code" name="hex_code"
|
<div class="row g-3">
|
||||||
value="<?= htmlspecialchars($edit_color['hex_code'] ?? '#'); ?>">
|
<div class="col-md-6">
|
||||||
</div>
|
<label for="name" class="form-label">Name der Farbe</label>
|
||||||
<div class="col-12 d-flex justify-content-start mt-2">
|
<input type="text" class="form-control" id="name" name="name"
|
||||||
<button type="submit" class="btn btn-sm btn-outline-<?= $edit_mode ? 'success' : 'primary'; ?> me-2">
|
value="<?= htmlspecialchars($edit_color['name'] ?? ''); ?>" required>
|
||||||
<?= $edit_mode ? 'Speichern' : 'Hinzufügen'; ?>
|
</div>
|
||||||
</button>
|
<div class="col-md-6">
|
||||||
<?php if ($edit_mode): ?>
|
<label for="hex_code" class="form-label">Hex-Code</label>
|
||||||
<a href="colors.php" class="btn btn-sm btn-outline-secondary">Abbrechen</a>
|
<input type="color" class="form-control form-control-color" id="hex_code" name="hex_code"
|
||||||
<?php endif; ?>
|
value="<?= htmlspecialchars($edit_color['hex_code'] ?? '#'); ?>">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div class="col-12 d-flex justify-content-start mt-2">
|
||||||
</form>
|
<button type="submit" class="btn btn-sm btn-outline-<?= $edit_mode ? 'success' : 'primary'; ?> me-2">
|
||||||
|
<?= $edit_mode ? 'Speichern' : 'Hinzufügen'; ?>
|
||||||
|
</button>
|
||||||
|
<?php if ($edit_mode): ?>
|
||||||
|
<a href="colors.php" class="btn btn-sm btn-outline-secondary">Abbrechen</a>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<hr class="mt-4 mb-4">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="card shadow">
|
<div class="card shadow">
|
||||||
<div class="card-header bg-secondary bg-opacity-50 text-secondary">
|
<div class="card-header bg-secondary bg-opacity-50 text-secondary">
|
||||||
|
|
||||||
<h4 class="mb-0">Aktuelle Farben</h4>
|
<h4 class="mb-0">Aktuelle Farben</h4>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<?php if (empty($colors)): ?>
|
<?php if (empty($colors)): ?>
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ if (isset($_GET['action']) && $_GET['action'] == 'delete' && isset($_GET['id']))
|
|||||||
// Aktion Bearbeiten (Formular laden)
|
// Aktion Bearbeiten (Formular laden)
|
||||||
if (isset($_GET['action']) && $_GET['action'] == 'edit' && isset($_GET['id'])) {
|
if (isset($_GET['action']) && $_GET['action'] == 'edit' && isset($_GET['id'])) {
|
||||||
$id = $_GET['id'];
|
$id = $_GET['id'];
|
||||||
$stmt = mysqli_prepare($conn, "SELECT id, meeting_date, color_id, reason FROM meetings WHERE id = ?"); // <<< NEU: 'reason' in der Abfrage
|
$stmt = mysqli_prepare($conn, "SELECT id, meeting_date, color_id, reason FROM meetings WHERE id = ?");
|
||||||
mysqli_stmt_bind_param($stmt, "i", $id);
|
mysqli_stmt_bind_param($stmt, "i", $id);
|
||||||
mysqli_stmt_execute($stmt);
|
mysqli_stmt_execute($stmt);
|
||||||
$result = mysqli_stmt_get_result($stmt);
|
$result = mysqli_stmt_get_result($stmt);
|
||||||
@@ -93,15 +93,15 @@ if (isset($_GET['action']) && $_GET['action'] == 'edit' && isset($_GET['id'])) {
|
|||||||
|
|
||||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
$meeting_date_only = $_POST['meeting_date'];
|
$meeting_date_only = $_POST['meeting_date'];
|
||||||
$meeting_time_only = $_POST['meeting_time'] ?? '12:00'; // Standardwert 12:00 Uhr
|
$meeting_time_only = $_POST['meeting_time'] ?? '12:00';
|
||||||
$meeting_date = $meeting_date_only . ' ' . $meeting_time_only;
|
$meeting_date = $meeting_date_only . ' ' . $meeting_time_only;
|
||||||
$color_id = $_POST['color_id'];
|
$color_id = $_POST['color_id'];
|
||||||
$reason = $_POST['reason'] ?? 'Zufallsfarbe'; // <<< NEU: Grund aus dem Formular holen, Standardwert bei leerem Feld
|
$reason = $_POST['reason'] ?? 'Zufallsfarbe';
|
||||||
$id = $_POST['id'] ?? null;
|
$id = $_POST['id'] ?? null;
|
||||||
|
|
||||||
if ($id) { // Update-Logik
|
if ($id) { // Update-Logik
|
||||||
$stmt = mysqli_prepare($conn, "UPDATE meetings SET meeting_date = ?, color_id = ?, reason = ? WHERE id = ?"); // <<< NEU: 'reason' in der Abfrage
|
$stmt = mysqli_prepare($conn, "UPDATE meetings SET meeting_date = ?, color_id = ?, reason = ? WHERE id = ?");
|
||||||
mysqli_stmt_bind_param($stmt, "sisi", $meeting_date, $color_id, $reason, $id); // <<< NEU: 's' für den String-Parameter
|
mysqli_stmt_bind_param($stmt, "sisi", $meeting_date, $color_id, $reason, $id);
|
||||||
if (mysqli_stmt_execute($stmt)) {
|
if (mysqli_stmt_execute($stmt)) {
|
||||||
$message = "Termin erfolgreich aktualisiert!";
|
$message = "Termin erfolgreich aktualisiert!";
|
||||||
$message_type = 'success';
|
$message_type = 'success';
|
||||||
@@ -111,8 +111,8 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|||||||
}
|
}
|
||||||
mysqli_stmt_close($stmt);
|
mysqli_stmt_close($stmt);
|
||||||
} else { // Insert-Logik
|
} else { // Insert-Logik
|
||||||
$stmt = mysqli_prepare($conn, "INSERT INTO meetings (meeting_date, color_id, reason) VALUES (?, ?, ?)"); // <<< NEU: 'reason' in der Abfrage
|
$stmt = mysqli_prepare($conn, "INSERT INTO meetings (meeting_date, color_id, reason) VALUES (?, ?, ?)");
|
||||||
mysqli_stmt_bind_param($stmt, "sis", $meeting_date, $color_id, $reason); // <<< NEU: 's' für den String-Parameter
|
mysqli_stmt_bind_param($stmt, "sis", $meeting_date, $color_id, $reason);
|
||||||
if (mysqli_stmt_execute($stmt)) {
|
if (mysqli_stmt_execute($stmt)) {
|
||||||
$message = "Neuer Termin erfolgreich hinzugefügt!";
|
$message = "Neuer Termin erfolgreich hinzugefügt!";
|
||||||
$message_type = 'success';
|
$message_type = 'success';
|
||||||
@@ -139,9 +139,9 @@ for ($i = 0; $i < 2; $i++) {
|
|||||||
if (mysqli_stmt_num_rows($stmt) == 0) {
|
if (mysqli_stmt_num_rows($stmt) == 0) {
|
||||||
$color_id = get_weighted_random_color($conn);
|
$color_id = get_weighted_random_color($conn);
|
||||||
if ($color_id) {
|
if ($color_id) {
|
||||||
$stmt_insert = mysqli_prepare($conn, "INSERT INTO meetings (meeting_date, color_id, reason) VALUES (?, ?, ?)"); // <<< NEU: 'reason' in der Abfrage
|
$stmt_insert = mysqli_prepare($conn, "INSERT INTO meetings (meeting_date, color_id, reason) VALUES (?, ?, ?)");
|
||||||
$default_reason = "Zufallsfarbe"; // <<< NEU: Grund für automatisch erstellte Termine
|
$default_reason = "Zufallsfarbe";
|
||||||
mysqli_stmt_bind_param($stmt_insert, "sis", $next_thursday, $color_id, $default_reason); // <<< NEU: 's' für den String-Parameter
|
mysqli_stmt_bind_param($stmt_insert, "sis", $next_thursday, $color_id, $default_reason);
|
||||||
mysqli_stmt_execute($stmt_insert);
|
mysqli_stmt_execute($stmt_insert);
|
||||||
mysqli_stmt_close($stmt_insert);
|
mysqli_stmt_close($stmt_insert);
|
||||||
}
|
}
|
||||||
@@ -159,7 +159,7 @@ while ($row = mysqli_fetch_assoc($result)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$meetings = [];
|
$meetings = [];
|
||||||
$result = mysqli_query($conn, "SELECT m.id, m.meeting_date, m.created_at, m.reason, c.name AS color_name, c.hex_code FROM meetings m JOIN colors c ON m.color_id = c.id ORDER BY m.meeting_date"); // <<< NEU: 'reason' in der Abfrage
|
$result = mysqli_query($conn, "SELECT m.id, m.meeting_date, m.created_at, m.reason, c.name AS color_name, c.hex_code FROM meetings m JOIN colors c ON m.color_id = c.id WHERE m.meeting_date >= CURDATE() ORDER BY m.meeting_date");
|
||||||
while ($row = mysqli_fetch_assoc($result)) {
|
while ($row = mysqli_fetch_assoc($result)) {
|
||||||
$meetings[] = $row;
|
$meetings[] = $row;
|
||||||
}
|
}
|
||||||
@@ -168,7 +168,6 @@ require_once '../inc/header.php';
|
|||||||
?>
|
?>
|
||||||
|
|
||||||
<div class="container mt-5">
|
<div class="container mt-5">
|
||||||
<h2 class="mb-4">Terminverwaltung</h2>
|
|
||||||
|
|
||||||
<?php if ($message) : ?>
|
<?php if ($message) : ?>
|
||||||
<div id="status-message" class="alert alert-<?php echo $message_type; ?> alert-dismissible fade show" role="alert">
|
<div id="status-message" class="alert alert-<?php echo $message_type; ?> alert-dismissible fade show" role="alert">
|
||||||
@@ -177,55 +176,65 @@ require_once '../inc/header.php';
|
|||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
<div class="card shadow mb-4">
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||||
<div class="card-header bg-primary-subtle text-secondary">
|
<h2 class="mb-0">Terminverwaltung</h2>
|
||||||
<h4 class="mb-0"><?php echo $edit_mode ? 'Termin bearbeiten' : 'Neuen Termin hinzufügen'; ?></h4>
|
<a class="btn btn-sm btn-outline-primary" data-bs-toggle="collapse" href="#planningFormCollapse" role="button" aria-expanded="false" aria-controls="planningFormCollapse">
|
||||||
</div>
|
<span class="material-symbols-outlined">add</span>
|
||||||
<div class="card-body">
|
</a>
|
||||||
<form action="planning.php" method="post">
|
</div>
|
||||||
<?php if ($edit_mode): ?>
|
|
||||||
<input type="hidden" name="id" value="<?php echo htmlspecialchars($edit_meeting['id']); ?>">
|
<div class="collapse <?= $edit_mode ? 'show' : '' ?>" id="planningFormCollapse">
|
||||||
<?php endif; ?>
|
<div class="card shadow mb-4">
|
||||||
<div class="row g-1 align-items-end">
|
<div class="card-header bg-primary-subtle text-secondary">
|
||||||
<div class="col-md-4">
|
<h4 class="mb-0"><?= $edit_mode ? 'Termin bearbeiten' : 'Neuen Termin hinzufügen'; ?></h4>
|
||||||
<label for="meeting_date" class="form-label">Datum</label>
|
</div>
|
||||||
<input type="date" class="form-control" id="meeting_date" name="meeting_date" value="<?php echo htmlspecialchars($edit_meeting['meeting_date_only'] ?? ''); ?>" required>
|
<div class="card-body">
|
||||||
<div class="form-text" style="visibility: hidden;"> </div>
|
<form action="planning.php" method="post">
|
||||||
</div>
|
<?php if ($edit_mode): ?>
|
||||||
<div class="col-md-4">
|
<input type="hidden" name="id" value="<?= htmlspecialchars($edit_meeting['id']); ?>">
|
||||||
<label for="meeting_time" class="form-label">Uhrzeit</label>
|
<?php endif; ?>
|
||||||
<input type="time" class="form-control" id="meeting_time" name="meeting_time" value="<?php echo htmlspecialchars($edit_meeting['meeting_time_only'] ?? '12:00'); ?>" required>
|
<div class="row g-1 align-items-end">
|
||||||
<div class="form-text" style="visibility: hidden;"> </div>
|
<div class="col-md-4">
|
||||||
</div>
|
<label for="meeting_date" class="form-label">Datum</label>
|
||||||
<div class="col-md-4">
|
<input type="date" class="form-control" id="meeting_date" name="meeting_date" value="<?= htmlspecialchars($edit_meeting['meeting_date_only'] ?? ''); ?>" required>
|
||||||
<label for="color_id" class="form-label">Farbe</label>
|
<div class="form-text" style="visibility: hidden;"> </div>
|
||||||
<select class="form-select" id="color_id" name="color_id" required>
|
</div>
|
||||||
<?php foreach ($all_colors as $color): ?>
|
<div class="col-md-4">
|
||||||
<option value="<?php echo htmlspecialchars($color['id']); ?>" <?php echo (($edit_meeting['color_id'] ?? '') == $color['id']) ? 'selected' : ''; ?>>
|
<label for="meeting_time" class="form-label">Uhrzeit</label>
|
||||||
<?php echo htmlspecialchars($color['name']); ?>
|
<input type="time" class="form-control" id="meeting_time" name="meeting_time" value="<?= htmlspecialchars($edit_meeting['meeting_time_only'] ?? '12:00'); ?>" required>
|
||||||
</option>
|
<div class="form-text" style="visibility: hidden;"> </div>
|
||||||
<?php endforeach; ?>
|
</div>
|
||||||
</select>
|
<div class="col-md-4">
|
||||||
<div class="form-text" style="visibility: hidden;"> </div>
|
<label for="color_id" class="form-label">Farbe</label>
|
||||||
</div>
|
<select class="form-select" id="color_id" name="color_id" required>
|
||||||
<div class="col-md-6">
|
<?php foreach ($all_colors as $color): ?>
|
||||||
<label for="reason" class="form-label">Grund für die Farbe (optional)</label>
|
<option value="<?= htmlspecialchars($color['id']); ?>" <?= (($edit_meeting['color_id'] ?? '') == $color['id']) ? 'selected' : ''; ?>>
|
||||||
<input type="text" class="form-control" id="reason" name="reason" value="<?php echo htmlspecialchars($edit_meeting['reason'] ?? ''); ?>">
|
<?= htmlspecialchars($color['name']); ?>
|
||||||
<div class="form-text">wenn leer, wird automatisch "Zufallsfarbe" eingetragen</div>
|
</option>
|
||||||
</div>
|
<?php endforeach; ?>
|
||||||
<div class="col-12 d-flex justify-content-start">
|
</select>
|
||||||
<div class="d-flex w-100">
|
<div class="form-text" style="visibility: hidden;"> </div>
|
||||||
<button type="submit" class="btn btn-sm btn-outline-<?php echo $edit_mode ? 'success' : 'primary'; ?> w-auto me-2">
|
</div>
|
||||||
<?php echo $edit_mode ? 'Speichern' : 'Hinzufügen'; ?>
|
<div class="col-md-6">
|
||||||
</button>
|
<label for="reason" class="form-label">Grund für die Farbe (optional)</label>
|
||||||
<?php if ($edit_mode): ?>
|
<input type="text" class="form-control" id="reason" name="reason" value="<?= htmlspecialchars($edit_meeting['reason'] ?? ''); ?>">
|
||||||
<a href="planning.php" class="btn btn-sm btn-outline-secondary w-auto">Abbrechen</a>
|
<div class="form-text">wenn leer, wird automatisch "Zufallsfarbe" eingetragen</div>
|
||||||
<?php endif; ?>
|
</div>
|
||||||
|
<div class="col-12 d-flex justify-content-start">
|
||||||
|
<div class="d-flex w-100">
|
||||||
|
<button type="submit" class="btn btn-sm btn-outline-<?= $edit_mode ? 'success' : 'primary'; ?> w-auto me-2">
|
||||||
|
<?= $edit_mode ? 'Speichern' : 'Hinzufügen'; ?>
|
||||||
|
</button>
|
||||||
|
<?php if ($edit_mode): ?>
|
||||||
|
<a href="planning.php" class="btn btn-sm btn-outline-secondary w-auto">Abbrechen</a>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</form>
|
||||||
</form>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<hr class="mt-4 mb-4">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="card shadow">
|
<div class="card shadow">
|
||||||
@@ -248,21 +257,21 @@ require_once '../inc/header.php';
|
|||||||
<tbody>
|
<tbody>
|
||||||
<?php foreach ($meetings as $meeting): ?>
|
<?php foreach ($meetings as $meeting): ?>
|
||||||
<tr>
|
<tr>
|
||||||
<td><?php echo date('d.m.Y H:i', strtotime($meeting['meeting_date'])); ?></td>
|
<td><?= date('d.m.Y H:i', strtotime($meeting['meeting_date'])); ?></td>
|
||||||
<td>
|
<td>
|
||||||
<div class="d-flex align-items-center">
|
<div class="d-flex align-items-center">
|
||||||
<div class="color-preview rounded me-2" style="background-color: <?php echo htmlspecialchars($meeting['hex_code']); ?>;"></div>
|
<div class="color-preview rounded me-2" style="background-color: <?= htmlspecialchars($meeting['hex_code']); ?>;"></div>
|
||||||
<div>
|
<div>
|
||||||
<span><?php echo htmlspecialchars($meeting['color_name']); ?></span>
|
<span><?= htmlspecialchars($meeting['color_name']); ?></span>
|
||||||
<div class="small text-muted mt-1">Grund: <?php echo htmlspecialchars($meeting['reason']); ?></div>
|
<div class="small text-muted mt-1">Grund: <?= htmlspecialchars($meeting['reason']); ?></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<a href="planning.php?action=edit&id=<?php echo htmlspecialchars($meeting['id']); ?>" class="text-dark me-1 text-decoration-none" data-bs-toggle="tooltip" data-bs-placement="top" title="Bearbeiten">
|
<a href="planning.php?action=edit&id=<?= htmlspecialchars($meeting['id']); ?>" class="text-dark me-1 text-decoration-none" data-bs-toggle="tooltip" data-bs-placement="top" title="Bearbeiten">
|
||||||
<span class="material-icons">mode_edit_outline</span>
|
<span class="material-icons">mode_edit_outline</span>
|
||||||
</a>
|
</a>
|
||||||
<a href="planning.php?action=delete&id=<?php echo htmlspecialchars($meeting['id']); ?>" class="text-danger text-decoration-none" onclick="return confirm('Sind Sie sicher, dass Sie diesen Termin löschen möchten?');" data-bs-toggle="tooltip" data-bs-placement="top" title="Löschen">
|
<a href="planning.php?action=delete&id=<?= htmlspecialchars($meeting['id']); ?>" class="text-danger text-decoration-none" onclick="return confirm('Sind Sie sicher, dass Sie diesen Termin löschen möchten?');" data-bs-toggle="tooltip" data-bs-placement="top" title="Löschen">
|
||||||
<span class="material-icons">delete_outline</span>
|
<span class="material-icons">delete_outline</span>
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
117
admin/users.php
117
admin/users.php
@@ -28,7 +28,8 @@ if (isset($_GET['action']) && $_GET['action'] == 'delete' && isset($_GET['id']))
|
|||||||
// Aktion Bearbeiten (Formular laden)
|
// Aktion Bearbeiten (Formular laden)
|
||||||
if (isset($_GET['action']) && $_GET['action'] == 'edit' && isset($_GET['id'])) {
|
if (isset($_GET['action']) && $_GET['action'] == 'edit' && isset($_GET['id'])) {
|
||||||
$id = $_GET['id'];
|
$id = $_GET['id'];
|
||||||
$stmt = mysqli_prepare($conn, "SELECT id, username, role FROM users WHERE id = ?");
|
// E-Mail-Feld zur Abfrage hinzugefügt, da es für das Bearbeiten benötigt wird
|
||||||
|
$stmt = mysqli_prepare($conn, "SELECT id, username, email, role FROM users WHERE id = ?");
|
||||||
mysqli_stmt_bind_param($stmt, "i", $id);
|
mysqli_stmt_bind_param($stmt, "i", $id);
|
||||||
mysqli_stmt_execute($stmt);
|
mysqli_stmt_execute($stmt);
|
||||||
$result = mysqli_stmt_get_result($stmt);
|
$result = mysqli_stmt_get_result($stmt);
|
||||||
@@ -42,6 +43,8 @@ if (isset($_GET['action']) && $_GET['action'] == 'edit' && isset($_GET['id'])) {
|
|||||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
$username = $_POST['username'];
|
$username = $_POST['username'];
|
||||||
$password = $_POST['password'];
|
$password = $_POST['password'];
|
||||||
|
// E-Mail-Feld aus dem Formular auslesen
|
||||||
|
$email = $_POST['email'] ?? null;
|
||||||
$role = $_POST['role'] === 'admin' ? 'admin' : 'member';
|
$role = $_POST['role'] === 'admin' ? 'admin' : 'member';
|
||||||
$id = $_POST['id'] ?? null;
|
$id = $_POST['id'] ?? null;
|
||||||
|
|
||||||
@@ -49,11 +52,15 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|||||||
// Überprüfen, ob ein neues Passwort gesetzt wurde
|
// Überprüfen, ob ein neues Passwort gesetzt wurde
|
||||||
if (!empty($password)) {
|
if (!empty($password)) {
|
||||||
$password_hashed = password_hash($password, PASSWORD_DEFAULT);
|
$password_hashed = password_hash($password, PASSWORD_DEFAULT);
|
||||||
$stmt = mysqli_prepare($conn, "UPDATE users SET username = ?, password = ?, role = ? WHERE id = ?");
|
// E-Mail-Feld zum UPDATE-Statement hinzugefügt
|
||||||
mysqli_stmt_bind_param($stmt, "sssi", $username, $password_hashed, $role, $id);
|
$stmt = mysqli_prepare($conn, "UPDATE users SET username = ?, password = ?, email = ?, role = ? WHERE id = ?");
|
||||||
|
// `email` zur Parameter-Bindung hinzugefügt
|
||||||
|
mysqli_stmt_bind_param($stmt, "ssssi", $username, $password_hashed, $email, $role, $id);
|
||||||
} else {
|
} else {
|
||||||
$stmt = mysqli_prepare($conn, "UPDATE users SET username = ?, role = ? WHERE id = ?");
|
// E-Mail-Feld zum UPDATE-Statement hinzugefügt
|
||||||
mysqli_stmt_bind_param($stmt, "ssi", $username, $role, $id);
|
$stmt = mysqli_prepare($conn, "UPDATE users SET username = ?, email = ?, role = ? WHERE id = ?");
|
||||||
|
// `email` zur Parameter-Bindung hinzugefügt
|
||||||
|
mysqli_stmt_bind_param($stmt, "sssi", $username, $email, $role, $id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mysqli_stmt_execute($stmt)) {
|
if (mysqli_stmt_execute($stmt)) {
|
||||||
@@ -66,8 +73,10 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|||||||
mysqli_stmt_close($stmt);
|
mysqli_stmt_close($stmt);
|
||||||
} else { // Insert-Logik
|
} else { // Insert-Logik
|
||||||
$password_hashed = password_hash($password, PASSWORD_DEFAULT);
|
$password_hashed = password_hash($password, PASSWORD_DEFAULT);
|
||||||
$stmt = mysqli_prepare($conn, "INSERT INTO users (username, password, role) VALUES (?, ?, ?)");
|
// E-Mail-Feld zum INSERT-Statement hinzugefügt
|
||||||
mysqli_stmt_bind_param($stmt, "sss", $username, $password_hashed, $role);
|
$stmt = mysqli_prepare($conn, "INSERT INTO users (username, password, email, role) VALUES (?, ?, ?, ?)");
|
||||||
|
// `email` zur Parameter-Bindung hinzugefügt
|
||||||
|
mysqli_stmt_bind_param($stmt, "ssss", $username, $password_hashed, $email, $role);
|
||||||
if (mysqli_stmt_execute($stmt)) {
|
if (mysqli_stmt_execute($stmt)) {
|
||||||
$message = "Benutzer erfolgreich hinzugefügt.";
|
$message = "Benutzer erfolgreich hinzugefügt.";
|
||||||
$message_type = 'success';
|
$message_type = 'success';
|
||||||
@@ -79,7 +88,7 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Benutzerübersicht abrufen
|
// Benutzerübersicht abrufen (E-Mail-Feld entfernt)
|
||||||
$users = [];
|
$users = [];
|
||||||
$result = mysqli_query($conn, "SELECT id, username, role FROM users ORDER BY id ASC");
|
$result = mysqli_query($conn, "SELECT id, username, role FROM users ORDER BY id ASC");
|
||||||
if ($result) {
|
if ($result) {
|
||||||
@@ -92,7 +101,6 @@ require_once('../inc/header.php');
|
|||||||
?>
|
?>
|
||||||
|
|
||||||
<div class="container mt-5">
|
<div class="container mt-5">
|
||||||
<h2 class="mb-4">Benutzerverwaltung</h2>
|
|
||||||
|
|
||||||
<?php if ($message) : ?>
|
<?php if ($message) : ?>
|
||||||
<div id="status-message" class="alert alert-<?php echo $message_type; ?> alert-dismissible fade show" role="alert">
|
<div id="status-message" class="alert alert-<?php echo $message_type; ?> alert-dismissible fade show" role="alert">
|
||||||
@@ -101,47 +109,62 @@ require_once('../inc/header.php');
|
|||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
<div class="card shadow mb-4">
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||||
<div class="card-header bg-primary-subtle text-secondary">
|
<h2 class="mb-0">Benutzerverwaltung</h2>
|
||||||
<h4 class="mb-0"><?php echo $edit_mode ? 'Benutzer bearbeiten' : 'Neuen Benutzer hinzufügen'; ?></h4>
|
<a class="btn btn-sm btn-outline-primary" data-bs-toggle="collapse" href="#userFormCollapse" role="button" aria-expanded="false" aria-controls="userFormCollapse">
|
||||||
</div>
|
<span class="material-symbols-outlined">add</span>
|
||||||
<div class="card-body">
|
</a>
|
||||||
<form action="users.php" method="post">
|
</div>
|
||||||
<?php if ($edit_mode): ?>
|
|
||||||
<input type="hidden" name="id" value="<?php echo htmlspecialchars($edit_user['id']); ?>">
|
<div class="collapse <?= $edit_mode ? 'show' : '' ?>" id="userFormCollapse">
|
||||||
<?php endif; ?>
|
<div class="card shadow mb-4">
|
||||||
<div class="row g-1 align-items-end">
|
<div class="card-header bg-primary-subtle text-secondary">
|
||||||
<div class="col-md-4">
|
<h4 class="mb-0"><?= $edit_mode ? 'Benutzer bearbeiten' : 'Neuen Benutzer hinzufügen'; ?></h4>
|
||||||
<label for="username" class="form-label">Benutzername</label>
|
</div>
|
||||||
<input type="text" class="form-control" id="username" name="username" value="<?php echo htmlspecialchars($edit_user['username'] ?? ''); ?>" required>
|
<div class="card-body">
|
||||||
<div class="form-text" style="visibility: hidden;"> </div>
|
<form action="users.php" method="post">
|
||||||
</div>
|
<?php if ($edit_mode): ?>
|
||||||
<div class="col-md-4">
|
<input type="hidden" name="id" value="<?= htmlspecialchars($edit_user['id']); ?>">
|
||||||
<label for="password" class="form-label">Passwort</label>
|
<?php endif; ?>
|
||||||
<input type="password" class="form-control" id="password" name="password" <?php echo $edit_mode ? '' : 'required'; ?>>
|
<div class="row g-1 align-items-end">
|
||||||
<div class="form-text">
|
<div class="col-md-3">
|
||||||
<?php echo $edit_mode ? 'Feld leer lassen, um das Passwort nicht zu ändern.' : ' '; ?>
|
<label for="username" class="form-label">Benutzername</label>
|
||||||
|
<input type="text" class="form-control" id="username" name="username" value="<?= htmlspecialchars($edit_user['username'] ?? ''); ?>" required>
|
||||||
|
<div class="form-text" style="visibility: hidden;"> </div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3">
|
||||||
|
<label for="email" class="form-label">E-Mail (optional)</label>
|
||||||
|
<input type="email" class="form-control" id="email" name="email" value="<?= htmlspecialchars($edit_user['email'] ?? ''); ?>">
|
||||||
|
<div class="form-text" style="visibility: hidden;"> </div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3">
|
||||||
|
<label for="password" class="form-label">Passwort</label>
|
||||||
|
<input type="password" class="form-control" id="password" name="password" <?= $edit_mode ? '' : 'required'; ?>>
|
||||||
|
<div class="form-text">
|
||||||
|
<?= $edit_mode ? 'Feld leer lassen, um das Passwort nicht zu ändern.' : ' '; ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3">
|
||||||
|
<label for="role" class="form-label">Rolle</label>
|
||||||
|
<select class="form-select" id="role" name="role">
|
||||||
|
<option value="member" <?= (($edit_user['role'] ?? '') === 'member') ? 'selected' : ''; ?>>Mitglied</option>
|
||||||
|
<option value="admin" <?= (($edit_user['role'] ?? '') === 'admin') ? 'selected' : ''; ?>>Admin</option>
|
||||||
|
</select>
|
||||||
|
<div class="form-text" style="visibility: hidden;"> </div>
|
||||||
|
</div>
|
||||||
|
<div class="col-12 d-flex justify-content-start">
|
||||||
|
<button type="submit" class="btn btn-sm btn-outline-<?= $edit_mode ? 'success' : 'primary'; ?> w-auto me-2">
|
||||||
|
<?= $edit_mode ? 'Speichern' : 'Hinzufügen'; ?>
|
||||||
|
</button>
|
||||||
|
<?php if ($edit_mode): ?>
|
||||||
|
<a href="users.php" class="btn btn-sm btn-outline-secondary w-auto">Abbrechen</a>
|
||||||
|
<?php endif; ?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-4">
|
</form>
|
||||||
<label for="role" class="form-label">Rolle</label>
|
</div>
|
||||||
<select class="form-select" id="role" name="role">
|
|
||||||
<option value="member" <?php echo ($edit_user['role'] ?? '') === 'member' ? 'selected' : ''; ?>>Mitglied</option>
|
|
||||||
<option value="admin" <?php echo ($edit_user['role'] ?? '') === 'admin' ? 'selected' : ''; ?>>Admin</option>
|
|
||||||
</select>
|
|
||||||
<div class="form-text" style="visibility: hidden;"> </div>
|
|
||||||
</div>
|
|
||||||
<div class="col-12 d-flex justify-content-start">
|
|
||||||
<button type="submit" class="btn btn-sm btn-outline-<?php echo $edit_mode ? 'success' : 'primary'; ?> w-auto me-2">
|
|
||||||
<?php echo $edit_mode ? 'Speichern' : 'Hinzufügen'; ?>
|
|
||||||
</button>
|
|
||||||
<?php if ($edit_mode): ?>
|
|
||||||
<a href="users.php" class="btn btn-sm btn-outline-secondary w-auto">Abbrechen</a>
|
|
||||||
<?php endif; ?>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
</div>
|
||||||
|
<hr class="mt-4 mb-4">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="card shadow">
|
<div class="card shadow">
|
||||||
|
|||||||
Reference in New Issue
Block a user