From 81078ddf9c3d47d24b12985bf89615b4e6addf72 Mon Sep 17 00:00:00 2001 From: Vichingo455 Date: Thu, 11 Sep 2025 08:32:33 +0200 Subject: [PATCH] Change gestione orario --- htdocs/admin/timetable.php | 266 +++++++++++++++++++++---------------- 1 file changed, 150 insertions(+), 116 deletions(-) diff --git a/htdocs/admin/timetable.php b/htdocs/admin/timetable.php index 5c7c024..00d3c92 100644 --- a/htdocs/admin/timetable.php +++ b/htdocs/admin/timetable.php @@ -1,32 +1,52 @@ query("INSERT INTO timetable (class_id,day,hour,subject_id) VALUES ($class_id,'$day',$hour,$subject_id)"); - header("Location: timetable.php"); exit; -} -?> -query("DELETE FROM timetable WHERE id=$id"); +// --- Recupera tutte le materie --- +$subjects = []; +$res = $conn->query("SELECT * FROM subjects ORDER BY name ASC"); +while ($r = $res->fetch_assoc()) { + $label = $r['name']; + if (!empty($r['teacher'])) $label .= " ({$r['teacher']})"; + if (!empty($r['room'])) $label .= " ({$r['room']})"; + $subjects[] = ['id' => $r['id'], 'label' => $label]; } -// Se è stato cliccato il link "Elimina" -if(isset($_GET['delete'])) { - deleteTimetableEntry($conn, $_GET['delete']); - // Dopo l'eliminazione, reindirizza per evitare duplicazioni - header("Location: timetable.php"); - exit; +// --- Salvataggio orario --- +if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST['class_id']) && isset($_POST['subject'])) { + $class_id = intval($_POST['class_id']); + if ($class_id > 0) { + // Cancella solo l'orario di questa classe + $conn->query("DELETE FROM timetable WHERE class_id=$class_id"); + + foreach ($_POST['subject'] as $day => $hours) { + foreach ($hours as $hour => $sub_ids) { + foreach ($sub_ids as $subject_id) { + $subject_id = intval($subject_id); + if (!empty($subject_id)) { + $conn->query("INSERT INTO timetable (class_id, day, hour, subject_id) + VALUES ($class_id, '" . $conn->real_escape_string($day) . "', $hour, $subject_id)"); + } + } + } + } + + header("Location: timetable.php?class_id=$class_id&saved=1"); + exit; + } +} + +// --- Selezione classe corrente --- +$class_id = isset($_GET['class_id']) ? intval($_GET['class_id']) : 0; + +// --- Precaricamento dati orario --- +$preselectedData = []; +if ($class_id > 0) { + $res = $conn->query("SELECT * FROM timetable WHERE class_id=$class_id"); + while ($r = $res->fetch_assoc()) { + $preselectedData[$r['day']][$r['hour']][] = $r['subject_id']; + } } ?> @@ -35,115 +55,129 @@ if(isset($_GET['delete'])) { Gestisci Orario + - -
-

Gestisci Orario

- ⬅ Torna al Dashboard +

Gestisci Orario

+ ⬅ Torna al Dashboard -
- Classe: - + + Classe: + - Giorno: - +

- Ora: - + + + + + + + + + + + + + + "; + echo ""; + foreach ($days as $day) { + $preselected = $preselectedData[$day][$hour] ?? ['']; + echo ""; + } + echo ""; + } + ?> + +
OraLunedìMartedìMercoledìGiovedìVenerdìSabato
{$hour}ª ora"; + echo "
"; + foreach ($preselected as $subject_id) { + echo "
"; + echo ""; + echo ""; + echo "
"; + } + echo ""; + echo "
"; + echo "
- Materia: - +
+ - -
-query("SELECT timetable.id, classes.name AS class_name, timetable.day, timetable.hour, subjects.name AS subject_name, subjects.teacher as teacher, subjects.room as room - FROM timetable - LEFT JOIN classes ON timetable.class_id = classes.id - LEFT JOIN subjects ON timetable.subject_id = subjects.id - ORDER BY class_name, day, hour"); -?> - -

Orario Inserito

-
- - - - - - - - - - fetch_assoc()): ?> - - - - - - - - -
ClasseGiornoOraMateriaAzione
- - Elimina - -
-
-

+ +

✅ Orario salvato con successo!

+ + +

Nota: Questa pagina si vede meglio da computer desktop. Se sei da computer, puoi ignorare questo messaggio.

Copyright (C) 2025 EmmeV. All rights reserved.

+