diff --git a/api/src/Controllers/UserController.php b/api/src/Controllers/UserController.php index 4328f797..5a5a8d2c 100755 --- a/api/src/Controllers/UserController.php +++ b/api/src/Controllers/UserController.php @@ -506,6 +506,26 @@ class UserController { // Récupérer l'opération active depuis la session (déjà récupérée lors du login) $activeOperationId = Session::getOperationId(); + // Fallback: si pas d'operation_id en session, récupérer depuis la base de données + if (!$activeOperationId) { + $stmtActiveOpe = $this->db->prepare(' + SELECT o.id + FROM operations o + INNER JOIN users u ON u.fk_entite = o.fk_entite + WHERE u.id = ? AND o.chk_active = 1 + LIMIT 1 + '); + $stmtActiveOpe->execute([$currentUserId]); + $activeOpeData = $stmtActiveOpe->fetch(PDO::FETCH_ASSOC); + $activeOperationId = $activeOpeData ? (int)$activeOpeData['id'] : null; + + LogService::log('Opération active récupérée depuis la base (pas en session)', [ + 'level' => 'warning', + 'userId' => $currentUserId, + 'activeOperationId' => $activeOperationId + ]); + } + $opeUserId = null; // Si une opération active existe, créer automatiquement l'entrée ope_users