Initial commit

This commit is contained in:
2026-01-25 21:03:33 +01:00
commit 8d8e213f1c
2570 changed files with 479666 additions and 0 deletions
@@ -0,0 +1,47 @@
<?php
// check school id if user go to select school
// include/require_school_context.php
if (Auth::user()->hasRole('User')) {
$school_id = (int)($_SESSION['school_id'] ?? 0);
if ($school_id <= 0) {
// manda alla pagina che decide: 1 scuola -> set in automatico, >1 -> selezione
header('Location: /select-school.php');
exit;
}
}
// --- SCHOOL OWNER & ADMIN: assegna automaticamente la scuola ---
if (
Auth::check() &&
(
Auth::user()->hasRole('school_owner') ||
Auth::user()->hasRole('Admin')
)
) {
$school_id = (int)($_SESSION['school_id'] ?? 0);
if ($school_id <= 0) {
$stmt = $db->prepare("
SELECT id
FROM schools
WHERE owner_id = ?
AND status = 'active'
LIMIT 1
");
$stmt->execute([$iduserlogin]);
$owner_school_id = (int)$stmt->fetchColumn();
if ($owner_school_id > 0) {
$_SESSION['school_id'] = $owner_school_id;
} else {
// caso limite: admin/owner senza scuola
die('Nessuna scuola associata a questo account.');
}
}
}