Plan: real SQLite DB with migrations system

Co-authored-by: naielv <109038805+naielv@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-03-06 21:37:34 +00:00
parent c0a93ce109
commit 937a0f4083

View File

@@ -85,3 +85,40 @@ function user_has_permission($perm)
{ {
return in_array($perm, $_SESSION["auth_data"]["permissions"] ?? []); return in_array($perm, $_SESSION["auth_data"]["permissions"] ?? []);
} }
/**
* Returns all centro/tenant IDs the authenticated user belongs to.
* Supports both the legacy single-centro format (entreaulas.centro = "string")
* and the new multi-tenant format (entreaulas.centros = ["a", "b"]).
*/
function get_user_centros($auth_data = null)
{
$data = $auth_data ?? $_SESSION["auth_data"] ?? [];
$ea = $data["entreaulas"] ?? [];
if (!empty($ea["centros"]) && is_array($ea["centros"])) {
return array_values($ea["centros"]);
}
if (!empty($ea["centro"])) {
return [$ea["centro"]];
}
return [];
}
/**
* Ensures $_SESSION['active_centro'] is set to a valid centro for the user.
* Call after user data is loaded/reloaded.
*/
function init_active_centro($auth_data = null)
{
$centros = get_user_centros($auth_data);
if (empty($centros)) {
$_SESSION['active_centro'] = null;
return;
}
// Keep existing selection only if it is still valid
if (!empty($_SESSION['active_centro']) && in_array($_SESSION['active_centro'], $centros, true)) {
return;
}
$_SESSION['active_centro'] = $centros[0];
}