getConnection(); if (!isset($iduserlogin)) { die("Errore: utente non loggato."); } // Recupera scuola corrente $stmt = $pdo->prepare(" SELECT id, name, owner_id, email AS school_email FROM schools WHERE owner_id = ? "); $stmt->execute([$iduserlogin]); $school = $stmt->fetch(PDO::FETCH_ASSOC); if (!$school) { die("Errore: nessuna scuola trovata per questo proprietario."); } $school_id = $school['id']; $school_name = $school['name']; $school_email = $school['school_email']; // Messaggi $success = $_GET['success'] ?? null; $error = $_GET['error'] ?? null; // COLLEGAMENTO TRAMITE CODICE if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'link_by_code') { $unique_code = trim($_POST['unique_code'] ?? ''); $link_id = (int)$pdo->lastInsertId(); if (empty($unique_code)) { $error = "Inserisci un codice univoco valido."; } else { $stmt = $pdo->prepare(" SELECT t.id AS teacher_id, u.first_name, u.last_name, u.email FROM teachers t JOIN auth_users u ON t.user_id = u.id WHERE t.unique_code = ? "); $stmt->execute([$unique_code]); $teacher = $stmt->fetch(PDO::FETCH_ASSOC); if (!$teacher) { $error = "Nessun insegnante trovato con questo codice."; } else { $check = $pdo->prepare("SELECT id FROM teacher_schools WHERE teacher_id = ? AND school_id = ?"); $check->execute([$teacher['teacher_id'], $school_id]); if ($check->fetch()) { $error = "Insegnante già collegata."; } else { $stmt = $pdo->prepare(" INSERT INTO teacher_schools (teacher_id, school_id, status, created_at, updated_at) VALUES (?, ?, 'pending', NOW(), NOW()) "); $stmt->execute([$teacher['teacher_id'], $school_id]); // Email richiesta $subject = "Richiesta collegamento a {$school_name}"; $body = "

Ciao {$teacher['first_name']},

{$school_name} vorrebbe collegarti alla sua scuola su YogiBoook.

Accetta

Se non riconosci questa richiesta, ignora l'email.

"; $result = sendEmail($teacher['email'], $subject, $body); $success = $result['success'] ? "Richiesta inviata!" : "Collegamento creato, ma errore email: " . $result['message']; } } } } // LISTA INSEGNANTI $stmt = $pdo->prepare(" SELECT t.id, t.user_id, t.phone, t.description, t.specializations, t.profile_picture, u.first_name, u.last_name, u.email, ts.status AS link_status, ts.created_at AS linked_at, (t.created_by = ?) AS can_edit FROM teacher_schools ts JOIN teachers t ON ts.teacher_id = t.id JOIN auth_users u ON t.user_id = u.id WHERE ts.school_id = ? AND ts.status IN ('active','pending') ORDER BY u.last_name, u.first_name "); $stmt->execute([$iduserlogin, $school_id]); $teachers = $stmt->fetchAll(PDO::FETCH_ASSOC); ?> Insegnanti - <?= htmlspecialchars($school_name) ?>

Insegnanti di

Nessuna insegnante collegata.

Foto Nome Email Telefono Stato Azioni