getConnection(); $error = null; $success = null; $action_taken = false; // Parametri dalla mail / form $email = trim($_POST['email'] ?? $_GET['email'] ?? ''); $school_id = (int)($_POST['school_id'] ?? $_GET['school_id'] ?? 0); $link_id = (int)($_POST['link_id'] ?? $_GET['link_id'] ?? 0); // Validazione minima: o link_id valido, oppure email+school_id if ($link_id <= 0) { if (empty($email) || $school_id <= 0 || !filter_var($email, FILTER_VALIDATE_EMAIL)) { die("Link non valido. Parametri mancanti o email errata."); } } // Recupera scuola (serve sempre per messaggi UI) $school = null; if ($school_id > 0) { $stmt = $pdo->prepare("SELECT id, name FROM schools WHERE id = ?"); $stmt->execute([$school_id]); $school = $stmt->fetch(PDO::FETCH_ASSOC); } // ✅ Se link_id NON c'è (vecchie mail), ricavalo dal pending usando email+school_id if ($link_id <= 0 && $school) { $stmt = $pdo->prepare(" SELECT ts.id FROM teacher_schools ts JOIN teachers t ON ts.teacher_id = t.id JOIN auth_users u ON t.user_id = u.id WHERE u.email = ? AND ts.school_id = ? AND ts.status = 'pending' LIMIT 1 "); $stmt->execute([$email, $school_id]); $tmp = $stmt->fetch(PDO::FETCH_ASSOC); if ($tmp) { $link_id = (int)$tmp['id']; } } // Carica richiesta (solo pending) tramite link_id $request = null; if ($link_id > 0) { $stmt = $pdo->prepare(" SELECT ts.id, ts.status, u.first_name, u.last_name, s.id AS school_id, s.name AS school_name FROM teacher_schools ts JOIN schools s ON ts.school_id = s.id JOIN teachers t ON ts.teacher_id = t.id JOIN auth_users u ON t.user_id = u.id WHERE ts.id = ? LIMIT 1 "); $stmt->execute([$link_id]); $request = $stmt->fetch(PDO::FETCH_ASSOC); } if (!$request || $request['status'] !== 'pending') { $error = "Nessuna richiesta di collegamento in attesa (potrebbe essere già stata gestita)."; } else { // Allinea school dalla request (così non dipendi da school_id passato) $school = ['id' => (int)$request['school_id'], 'name' => $request['school_name']]; $teacher_name = trim(($request['first_name'] ?? '') . ' ' . ($request['last_name'] ?? '')); } // POST: accetta/rifiuta usando SOLO link_id if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) { $link_id = (int)($_POST['link_id'] ?? 0); $stmt = $pdo->prepare(" SELECT id FROM teacher_schools WHERE id = ? AND status = 'pending' LIMIT 1 "); $stmt->execute([$link_id]); $row = $stmt->fetch(PDO::FETCH_ASSOC); if (!$row) { $error = "Questa richiesta non è più disponibile (potrebbe essere già stata gestita)."; } else { if ($_POST['action'] === 'accept') { $stmt = $pdo->prepare(" UPDATE teacher_schools SET status = 'active', updated_at = NOW() WHERE id = ? AND status = 'pending' "); $stmt->execute([$link_id]); $success = "Collegamento accettato! Ora sei collegata alla scuola " . htmlspecialchars($school['name']) . "."; $action_taken = true; } elseif ($_POST['action'] === 'reject') { $stmt = $pdo->prepare("DELETE FROM teacher_schools WHERE id = ? AND status = 'pending'"); $stmt->execute([$link_id]); $success = "Hai rifiutato il collegamento con la scuola " . htmlspecialchars($school['name']) . "."; $action_taken = true; } } } ?> Conferma Collegamento Scuola - YogiBoook

Operazione completata!

Per gestire le lezioni di questa scuola, accedi o registrati su YogiBoook.

Accedi Registrati

Errore

Torna al sito

Richiesta di collegamento scuola

Ciao ,

La scuola vorrebbe collegarti alla sua struttura su YogiBoook.

Accettando, verrai visualizzata/o nelle lezioni della scuola.