Files
maria_uslugi/public/includes/init_auth.php
T
2026-03-05 10:25:39 +01:00

64 lines
2.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
//init_auth.php
declare(strict_types=1);
require_once __DIR__ . '/../../../includes/bootstrap_global.php';
require_once __DIR__ . '/securite.php';
function init_auth_page(?array $roles = null): void
{
require_login_or_redirect($roles);
// Push config (si utilisé dans header site)
$pushCfgPath = __DIR__ . '/../../push/config.php'; // /public/push/config.php
$GLOBALS['pushCfg'] = is_file($pushCfgPath) ? require $pushCfgPath : [];
// Abonnement (si tu l’utilises dans le header site praticien)
$abonnementPath = __DIR__ . '/verifier_abonnement.php';
if (is_file($abonnementPath)) {
require $abonnementPath;
$GLOBALS['alerte_abonnement'] = $alerte_abonnement ?? null;
} else {
$GLOBALS['alerte_abonnement'] = null;
}
// Avatars
$GLOBALS['initiales'] = 'U';
$GLOBALS['avatar_svg'] = null;
$role = strtolower((string)($_SESSION['role'] ?? ''));
// Admin / Secrétaire => SVG
if ($role === 'admin') {
$GLOBALS['avatar_svg'] = '/public/uploads/img/avatar_admin.svg';
return;
}
if ($role === 'secretaire') {
$GLOBALS['avatar_svg'] = '/public/uploads/img/avatar_secretaire.svg';
return;
}
// Client / Praticien => initiales depuis tables
$refId = (int)($_SESSION['reference_id'] ?? 0);
$pdo = $GLOBALS['pdo'] ?? null;
if (!($pdo instanceof PDO) || $refId <= 0) return;
if ($role === 'client') {
$stmt = $pdo->prepare("SELECT nom, prenom FROM client WHERE id = ?");
} elseif ($role === 'praticien') {
$stmt = $pdo->prepare("SELECT nom, prenom FROM praticien WHERE id = ?");
} else {
return;
}
$stmt->execute([$refId]);
$u = $stmt->fetch(PDO::FETCH_ASSOC) ?: [];
$nom = trim((string)($u['nom'] ?? ''));
$prenom = trim((string)($u['prenom'] ?? ''));
$ini = mb_strtoupper(
mb_substr($prenom, 0, 1, 'UTF-8') . mb_substr($nom, 0, 1, 'UTF-8'),
'UTF-8'
);
$GLOBALS['initiales'] = $ini !== '' ? $ini : 'U';
}