school id fixed
This commit is contained in:
parent
3fb512e713
commit
7c574649a0
@ -64,5 +64,12 @@ $_SESSION["photouser"] = $avatar;
|
||||
|
||||
$photouser = $_SESSION["photouser"];
|
||||
|
||||
|
||||
|
||||
|
||||
// include school settings
|
||||
include('schoolid_select.php');
|
||||
|
||||
|
||||
// include school settings
|
||||
include('school_settings_loader.php');
|
||||
|
||||
@ -9,7 +9,8 @@ if (!empty($_SESSION['school_id'])) {
|
||||
$stmt_school = $pdo->prepare("SELECT name, logo FROM schools WHERE id = ?");
|
||||
$stmt_school->execute([$school_id]);
|
||||
$current_school = $stmt_school->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
echo $current_school['name'];
|
||||
echo "Ciao";
|
||||
if ($current_school) {
|
||||
$school_display_name = $current_school['name'];
|
||||
|
||||
|
||||
47
public/userarea/include/schoolid_select.php
Normal file
47
public/userarea/include/schoolid_select.php
Normal file
@ -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.');
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 35 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 129 KiB |
Loading…
x
Reference in New Issue
Block a user