submit($_POST, $_FILES); $identifier = $ctrl->getIdentifier($thesisId); $logger->logSubmission('admin', $thesisId, $identifier, $authorName); unset($_SESSION['csrf_token']); $redirect = '../recapitulatif.php?id=' . $thesisId; header('Location: ' . $redirect); exit(); } catch (DuplicateThesisException $e) { $logger->logDuplicate('admin', $authorName, $e->existingThesisId, $e->existingIdentifier); error_log('ThesisCreateController duplicate: ' . $e->getMessage()); // Build a warning with a clickable link to the existing thesis. $existingUrl = htmlspecialchars('/admin/edit.php?id=' . $e->existingThesisId); $existingRef = htmlspecialchars($e->existingIdentifier . ' — ' . $e->existingTitle . ' (' . $e->existingYear . ')'); $warningHtml = 'Doublon détecté : un TFE très similaire existe déjà. ' . '' . $existingRef . '' . ' Vérifiez avant de soumettre à nouveau.'; App::flash('warning', $warningHtml); $_SESSION['form_data'] = $_POST; header('Location: ../add.php'); exit(); } catch (Exception $e) { $logger->logError('admin', $e->getMessage(), [ 'author' => $authorName, 'post_keys' => array_keys($_POST), ]); error_log('ThesisCreateController error: ' . $e->getMessage()); App::flash('error', $e->getMessage()); $_SESSION['form_data'] = $_POST; $redirect = '../add.php'; $autofocusField = ThesisCreateController::autofocusFieldForError($e->getMessage()); if ($autofocusField !== null) { App::flashAutofocus($autofocusField); } header('Location: ' . $redirect); exit(); }