prepare("DELETE FROM timetable WHERE class_id = ?"); $stmt->bind_param("i", $classe_id); $stmt->execute(); $stmt->close(); $inserimenti = 0; $materie_create = []; // Processa ogni giorno foreach ($data['giorni'] as $giorno => $ore) { foreach ($ore as $oraData) { // Salta ore vuote if ($oraData['materia'] === null) { continue; } $ora = $oraData['ora']; $materia = $oraData['materia']; $docenti = $oraData['docenti']; $laboratori = $oraData['laboratori']; // Ora è un array // Se non ci sono docenti, salta (situazione anomala) if (count($docenti) === 0) { continue; } // Caso 1: Stesso numero di docenti e laboratori → associazione 1:1 if (count($docenti) === count($laboratori) && count($laboratori) > 0) { foreach ($docenti as $idx => $docente) { $laboratorio = $laboratori[$idx]; // Cerca/crea materia $stmt = $conn->prepare("SELECT id FROM subjects WHERE name = ? AND teacher = ? AND room = ?"); $stmt->bind_param("sss", $materia, $docente, $laboratorio); $stmt->execute(); $result = $stmt->get_result(); if ($result->num_rows > 0) { $subject_id = $result->fetch_assoc()['id']; } else { $stmt2 = $conn->prepare("INSERT INTO subjects (name, teacher, room) VALUES (?, ?, ?)"); $stmt2->bind_param("sss", $materia, $docente, $laboratorio); $stmt2->execute(); $subject_id = $conn->insert_id; $stmt2->close(); $materie_create[] = "$materia ($docente - $laboratorio)"; } $stmt->close(); // Inserisci in timetable $stmt3 = $conn->prepare("INSERT INTO timetable (class_id, day, hour, subject_id) VALUES (?, ?, ?, ?)"); $stmt3->bind_param("isii", $classe_id, $giorno, $ora, $subject_id); $stmt3->execute(); $stmt3->close(); $inserimenti++; } } // Caso 2: Più docenti, un laboratorio (o nessuno) → stesso laboratorio per tutti else if (count($laboratori) <= 1) { $laboratorio = count($laboratori) > 0 ? $laboratori[0] : null; foreach ($docenti as $docente) { // Cerca/crea materia if ($laboratorio) { $stmt = $conn->prepare("SELECT id FROM subjects WHERE name = ? AND teacher = ? AND room = ?"); $stmt->bind_param("sss", $materia, $docente, $laboratorio); } else { $stmt = $conn->prepare("SELECT id FROM subjects WHERE name = ? AND teacher = ? AND (room IS NULL OR room = '')"); $stmt->bind_param("ss", $materia, $docente); } $stmt->execute(); $result = $stmt->get_result(); if ($result->num_rows > 0) { $subject_id = $result->fetch_assoc()['id']; } else { $stmt2 = $conn->prepare("INSERT INTO subjects (name, teacher, room) VALUES (?, ?, ?)"); $stmt2->bind_param("sss", $materia, $docente, $laboratorio); $stmt2->execute(); $subject_id = $conn->insert_id; $stmt2->close(); $materie_create[] = "$materia ($docente" . ($laboratorio ? " - $laboratorio" : "") . ")"; } $stmt->close(); // Inserisci in timetable $stmt3 = $conn->prepare("INSERT INTO timetable (class_id, day, hour, subject_id) VALUES (?, ?, ?, ?)"); $stmt3->bind_param("isii", $classe_id, $giorno, $ora, $subject_id); $stmt3->execute(); $stmt3->close(); $inserimenti++; } } // Caso 3: Più laboratori che docenti → usa il primo laboratorio per tutti else { $laboratorio = $laboratori[0]; foreach ($docenti as $docente) { $stmt = $conn->prepare("SELECT id FROM subjects WHERE name = ? AND teacher = ? AND room = ?"); $stmt->bind_param("sss", $materia, $docente, $laboratorio); $stmt->execute(); $result = $stmt->get_result(); if ($result->num_rows > 0) { $subject_id = $result->fetch_assoc()['id']; } else { $stmt2 = $conn->prepare("INSERT INTO subjects (name, teacher, room) VALUES (?, ?, ?)"); $stmt2->bind_param("sss", $materia, $docente, $laboratorio); $stmt2->execute(); $subject_id = $conn->insert_id; $stmt2->close(); $materie_create[] = "$materia ($docente - $laboratorio)"; } $stmt->close(); $stmt3 = $conn->prepare("INSERT INTO timetable (class_id, day, hour, subject_id) VALUES (?, ?, ?, ?)"); $stmt3->bind_param("isii", $classe_id, $giorno, $ora, $subject_id); $stmt3->execute(); $stmt3->close(); $inserimenti++; } } } } $message = "Importazione completata con successo!
"; $message .= "- Inserite $inserimenti ore di lezione
"; if (count($materie_create) > 0) { $message .= "- Create " . count($materie_create) . " nuove materie"; } $messageType = "success"; } catch (Exception $e) { $message = "Errore durante l'importazione: " . htmlspecialchars($e->getMessage()); $messageType = "error"; } } } ?> Importa Orario

Importa Orario da Sistema Esterno

⬅ Torna al Dashboard
Attenzione: L'importazione cancellerà l'orario esistente della classe selezionata e lo sostituirà con i dati importati dal sistema esterno. Verranno create automaticamente le materie mancanti.

Configura Importazione

Classe nel tuo database dove importare l'orario
Codice della classe nel sistema esterno
Endpoint dell'API Node.js per lo scraping

Come funziona l'importazione

  1. Assicurati che il server Node.js sia avviato (node server.js)
  2. Seleziona la classe di destinazione nel tuo database
  3. Inserisci il codice della classe nel sistema esterno (es: 3BIN, 1A, 5AINF)
  4. Clicca su "Importa Orario"
  5. Il sistema cancellerà l'orario esistente e importerà i nuovi dati

Gestione casi speciali

Copyright (C) 2025 EmmeV. - Released under GNU AGPL 3.0 License.