72 lines
2.4 KiB
PHP
72 lines
2.4 KiB
PHP
<?php
|
|
/**
|
|
* Prépare le contexte attendu par header.php (pushCfg, alerte_abonnement, avatar/initiales)
|
|
* SANS appeler init_praticien.php => pas de redirection abonnement.
|
|
*/
|
|
|
|
/* =========================
|
|
Helpers
|
|
========================= */
|
|
function is_logged_in(): bool {
|
|
$role = (string)($_SESSION['role'] ?? ($_SESSION['user_type'] ?? ''));
|
|
if (!empty($_SESSION['reference_id']) && $role !== '') return true;
|
|
if (!empty($_SESSION['user_id'])) return true;
|
|
if (!empty($_SESSION['client_id'])) return true;
|
|
if (!empty($_SESSION['praticien_id'])) return true;
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Inclut /public/includes/header.php sans DOCTYPE/HTML/HEAD/BODY et sans recharger bootstrap/css.
|
|
*/
|
|
function include_header_clean(string $absPath): void {
|
|
global $translations, $lang;
|
|
ob_start();
|
|
include $absPath;
|
|
$buf = ob_get_clean() ?: '';
|
|
|
|
$buf = preg_replace('~<!doctype\s+html[^>]*>~i', '', $buf);
|
|
$buf = preg_replace('~</?html\b[^>]*>~i', '', $buf);
|
|
$buf = preg_replace('~<head\b[^>]*>.*?</head>~is', '', $buf);
|
|
$buf = preg_replace('~</?body\b[^>]*>~i', '', $buf);
|
|
|
|
// éviter d’écraser la home
|
|
$buf = preg_replace('~<link[^>]+href="[^"]*(bootstrap[^"]*\.css|mobil_style\.css|site_style\.css|fonts\.googleapis)[^"]*"[^>]*>~i', '', $buf);
|
|
$buf = preg_replace('~<script[^>]+src="[^"]*bootstrap[^"]*bundle[^"]*\.js[^"]*"[^>]*>\s*</script>~i', '', $buf);
|
|
|
|
echo $buf;
|
|
}
|
|
function prepare_secure_header_context(): void {
|
|
$pdo = $GLOBALS['pdo'] ?? null;
|
|
if (!($pdo instanceof PDO)) return;
|
|
|
|
$role = strtolower((string)($_SESSION['role'] ?? ''));
|
|
$refId = (int)($_SESSION['reference_id'] ?? 0);
|
|
|
|
|
|
|
|
// Initiales client/praticien
|
|
if ($refId > 0 && ($role === 'client' || $role === 'praticien')) {
|
|
try {
|
|
$table = ($role === 'client') ? 'client' : 'praticien';
|
|
$st = $pdo->prepare("SELECT nom, prenom FROM {$table} WHERE id = ? LIMIT 1");
|
|
$st->execute([$refId]);
|
|
$u = $st->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';
|
|
} catch (Throwable $e) {
|
|
$GLOBALS['initiales'] = 'U';
|
|
}
|
|
}
|
|
}
|
|
|
|
// Si connecté -> préparer le contexte header sécurisé (sans redirection)
|
|
$logged = is_logged_in();
|
|
if ($logged) prepare_secure_header_context();
|
|
|