Farbgrund hinzugefügt
This commit is contained in:
@@ -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 FROM meetings WHERE id = ?");
|
$stmt = mysqli_prepare($conn, "SELECT id, meeting_date, color_id, reason FROM meetings WHERE id = ?"); // <<< NEU: 'reason' in der Abfrage
|
||||||
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);
|
||||||
@@ -96,11 +96,12 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|||||||
$meeting_time_only = $_POST['meeting_time'] ?? '12:00'; // Standardwert 12:00 Uhr
|
$meeting_time_only = $_POST['meeting_time'] ?? '12:00'; // Standardwert 12:00 Uhr
|
||||||
$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
|
||||||
$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 = ? WHERE id = ?");
|
$stmt = mysqli_prepare($conn, "UPDATE meetings SET meeting_date = ?, color_id = ?, reason = ? WHERE id = ?"); // <<< NEU: 'reason' in der Abfrage
|
||||||
mysqli_stmt_bind_param($stmt, "sii", $meeting_date, $color_id, $id);
|
mysqli_stmt_bind_param($stmt, "sisi", $meeting_date, $color_id, $reason, $id); // <<< NEU: 's' für den String-Parameter
|
||||||
if (mysqli_stmt_execute($stmt)) {
|
if (mysqli_stmt_execute($stmt)) {
|
||||||
$message = "Termin erfolgreich aktualisiert!";
|
$message = "Termin erfolgreich aktualisiert!";
|
||||||
$message_type = 'success';
|
$message_type = 'success';
|
||||||
@@ -110,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) VALUES (?, ?)");
|
$stmt = mysqli_prepare($conn, "INSERT INTO meetings (meeting_date, color_id, reason) VALUES (?, ?, ?)"); // <<< NEU: 'reason' in der Abfrage
|
||||||
mysqli_stmt_bind_param($stmt, "si", $meeting_date, $color_id);
|
mysqli_stmt_bind_param($stmt, "sis", $meeting_date, $color_id, $reason); // <<< NEU: 's' für den String-Parameter
|
||||||
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';
|
||||||
@@ -138,8 +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) VALUES (?, ?)");
|
$stmt_insert = mysqli_prepare($conn, "INSERT INTO meetings (meeting_date, color_id, reason) VALUES (?, ?, ?)"); // <<< NEU: 'reason' in der Abfrage
|
||||||
mysqli_stmt_bind_param($stmt_insert, "si", $next_thursday, $color_id);
|
$default_reason = "Zufallsfarbe"; // <<< NEU: Grund für automatisch erstellte Termine
|
||||||
|
mysqli_stmt_bind_param($stmt_insert, "sis", $next_thursday, $color_id, $default_reason); // <<< NEU: 's' für den String-Parameter
|
||||||
mysqli_stmt_execute($stmt_insert);
|
mysqli_stmt_execute($stmt_insert);
|
||||||
mysqli_stmt_close($stmt_insert);
|
mysqli_stmt_close($stmt_insert);
|
||||||
}
|
}
|
||||||
@@ -157,7 +159,7 @@ while ($row = mysqli_fetch_assoc($result)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$meetings = [];
|
$meetings = [];
|
||||||
$result = mysqli_query($conn, "SELECT m.id, m.meeting_date, m.created_at, 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");
|
$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
|
||||||
while ($row = mysqli_fetch_assoc($result)) {
|
while ($row = mysqli_fetch_assoc($result)) {
|
||||||
$meetings[] = $row;
|
$meetings[] = $row;
|
||||||
}
|
}
|
||||||
@@ -206,6 +208,11 @@ require_once '../inc/header.php';
|
|||||||
</select>
|
</select>
|
||||||
<div class="form-text" style="visibility: hidden;"> </div>
|
<div class="form-text" style="visibility: hidden;"> </div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="col-md-6">
|
||||||
|
<label for="reason" class="form-label">Grund für die Farbe (optional)</label>
|
||||||
|
<input type="text" class="form-control" id="reason" name="reason" value="<?php echo htmlspecialchars($edit_meeting['reason'] ?? ''); ?>">
|
||||||
|
<div class="form-text">wenn leer, wird automatisch "Zufallsfarbe" eingetragen</div>
|
||||||
|
</div>
|
||||||
<div class="col-12 d-flex justify-content-start">
|
<div class="col-12 d-flex justify-content-start">
|
||||||
<div class="d-flex w-100">
|
<div class="d-flex w-100">
|
||||||
<button type="submit" class="btn btn-sm btn-outline-<?php echo $edit_mode ? 'success' : 'primary'; ?> w-auto me-2">
|
<button type="submit" class="btn btn-sm btn-outline-<?php echo $edit_mode ? 'success' : 'primary'; ?> w-auto me-2">
|
||||||
@@ -245,7 +252,10 @@ require_once '../inc/header.php';
|
|||||||
<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: <?php echo htmlspecialchars($meeting['hex_code']); ?>;"></div>
|
||||||
|
<div>
|
||||||
<span><?php echo htmlspecialchars($meeting['color_name']); ?></span>
|
<span><?php echo htmlspecialchars($meeting['color_name']); ?></span>
|
||||||
|
<div class="small text-muted mt-1">Grund: <?php echo htmlspecialchars($meeting['reason']); ?></div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
|||||||
Reference in New Issue
Block a user