<br />
<b>Warning</b>:  Undefined variable $auth in <b>/home/pevo0181/public_html/pia-soft.com/cleania/routes/index.php</b> on line <b>542</b><br />
<br />
<b>Warning</b>:  Trying to access array offset on value of type null in <b>/home/pevo0181/public_html/pia-soft.com/cleania/routes/index.php</b> on line <b>542</b><br />
<?php
// ============================================================
//  GET /api/notes.php[?session_id=X]
//  Header: Authorization: Bearer <token>
// ============================================================
require_once __DIR__ . '/config.php';

$auth     = requireAuth();
$eleve_id = $auth['eleve_id'];
$db       = getDB();

// Sessions disponibles
$stmtSess = $db->prepare("
    SELECT DISTINCT se.id, se.nom_fr, se.nom_en, se.type, se.ordre, se.date_debut, se.date_fin
    FROM sessions_evaluation se
    JOIN notes n ON n.session_id = se.id
    WHERE n.eleve_id = ?
    ORDER BY se.ordre ASC
");
$stmtSess->execute([$eleve_id]);
$sessions = $stmtSess->fetchAll();

// Session demandée ou dernière par défaut
$session_id = isset($_GET['session_id']) ? (int)$_GET['session_id'] : null;
if (!$session_id && !empty($sessions)) {
    $session_id = end($sessions)['id'];
}

$notes = [];
$moyenne = null;

if ($session_id) {
    $stmtNotes = $db->prepare("
        SELECT n.id, n.note, n.note_max, n.appreciation, n.absent,
               m.nom_fr as matiere, m.nom_en as matiere_en, m.coefficient,
               se.nom_fr as session_nom
        FROM notes n
        JOIN matieres m ON m.id = n.matiere_id
        JOIN sessions_evaluation se ON se.id = n.session_id
        WHERE n.eleve_id = ? AND n.session_id = ?
        ORDER BY m.nom_fr ASC
    ");
    $stmtNotes->execute([$eleve_id, $session_id]);
    $notes = $stmtNotes->fetchAll();

    // Calculer la moyenne pondérée
    $somme = 0; $coefs = 0;
    foreach ($notes as $n) {
        if (!$n['absent'] && $n['note'] !== null) {
       