save($thesisId, $_POST, $_FILES); // Regenerate CSRF token after successful save $_SESSION['csrf_token'] = bin2hex(random_bytes(32)); AdminLogger::make()->logEdit($thesisId, $_POST['titre'] ?? $_POST['title'] ?? ''); App::flash('success', "TFE mis à jour avec succès!"); header('Location: ../edit.php?id=' . $thesisId); exit(); } catch (Exception $e) { ErrorHandler::log('thesis_edit', $e, ['thesis_id' => $thesisId]); App::flash('error', ErrorHandler::userMessage($e)); // WCAG 3.3.1 — map error message to field name for autofocus on re-render. $autofocusField = ThesisEditController::autofocusFieldForError($e->getMessage()); if ($autofocusField !== null) { App::flashAutofocus($autofocusField); } header('Location: ../edit.php?id=' . $thesisId); exit(); }