getPDO(); // Handle form submission if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['csrf_token'])) { // Verify CSRF token if (!hash_equals($_SESSION['csrf_token'], $_POST['csrf_token'])) { throw new Exception("Erreur de sécurité : token invalide."); } try { $db->beginTransaction(); // Update thesis basic info $stmt = $pdo->prepare(" UPDATE theses SET title = ?, subtitle = ?, year = ?, orientation_id = ?, ap_program_id = ?, finality_id = ?, synopsis = ?, file_size_info = ?, baiu_link = ?, is_published = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ? "); $stmt->execute([ trim($_POST['titre']), !empty($_POST['subtitle']) ? trim($_POST['subtitle']) : null, intval($_POST['année']), intval($_POST['orientation']), intval($_POST['ap']), intval($_POST['finality']), trim($_POST['synopsis']), !empty($_POST['duration_info']) ? trim($_POST['duration_info']) : null, !empty($_POST['lien']) ? trim($_POST['lien']) : null, isset($_POST['is_published']) ? 1 : 0, $thesisId ]); // Update authors $pdo->prepare("DELETE FROM thesis_authors WHERE thesis_id = ?")->execute([$thesisId]); $authorsRaw = trim($_POST['auteurice'] ?? ''); if (!empty($authorsRaw)) { $authors = array_map('trim', explode(',', $authorsRaw)); foreach ($authors as $index => $authorName) { if (!empty($authorName)) { $authorId = $db->findOrCreateAuthor($authorName, $index === 0 ? ($_POST['mail'] ?? null) : null); $stmt = $pdo->prepare("INSERT INTO thesis_authors (thesis_id, author_id, author_order) VALUES (?, ?, ?)"); $stmt->execute([$thesisId, $authorId, $index + 1]); } } } // Update supervisors $pdo->prepare("DELETE FROM thesis_supervisors WHERE thesis_id = ?")->execute([$thesisId]); $supervisorsRaw = trim($_POST['promoteurice'] ?? ''); if (!empty($supervisorsRaw)) { $supervisors = array_map('trim', explode(',', $supervisorsRaw)); foreach ($supervisors as $index => $supervisorName) { if (!empty($supervisorName)) { $supervisorId = $db->findOrCreateSupervisor($supervisorName); $stmt = $pdo->prepare("INSERT INTO thesis_supervisors (thesis_id, supervisor_id, supervisor_order) VALUES (?, ?, ?)"); $stmt->execute([$thesisId, $supervisorId, $index + 1]); } } } // Update languages $pdo->prepare("DELETE FROM thesis_languages WHERE thesis_id = ?")->execute([$thesisId]); if (isset($_POST['languages']) && is_array($_POST['languages'])) { foreach ($_POST['languages'] as $languageId) { $stmt = $pdo->prepare("INSERT INTO thesis_languages (thesis_id, language_id) VALUES (?, ?)"); $stmt->execute([$thesisId, intval($languageId)]); } } // Update formats $pdo->prepare("DELETE FROM thesis_formats WHERE thesis_id = ?")->execute([$thesisId]); if (isset($_POST['formats']) && is_array($_POST['formats'])) { foreach ($_POST['formats'] as $formatId) { $stmt = $pdo->prepare("INSERT INTO thesis_formats (thesis_id, format_id) VALUES (?, ?)"); $stmt->execute([$thesisId, intval($formatId)]); } } // Update keywords $pdo->prepare("DELETE FROM thesis_keywords WHERE thesis_id = ?")->execute([$thesisId]); $keywordsRaw = trim($_POST['tag'] ?? ''); if (!empty($keywordsRaw)) { $keywords = array_map('trim', explode(',', $keywordsRaw)); $keywords = array_slice($keywords, 0, 10); // Max 10 foreach ($keywords as $keyword) { if (!empty($keyword)) { $keywordId = $db->findOrCreateKeyword($keyword); if ($keywordId) { $stmt = $pdo->prepare("INSERT INTO thesis_keywords (thesis_id, keyword_id) VALUES (?, ?)"); $stmt->execute([$thesisId, $keywordId]); } } } } $db->commit(); $success = "TFE mis à jour avec succès!"; // Regenerate CSRF token $_SESSION['csrf_token'] = bin2hex(random_bytes(32)); } catch (Exception $e) { $db->rollback(); $error = $e->getMessage(); error_log("Edit error: " . $e->getMessage()); } } // Load thesis data $thesis = $db->getThesis($thesisId); if (!$thesis) { die("TFE non trouvé"); } // Load current relationships $stmt = $pdo->prepare("SELECT language_id FROM thesis_languages WHERE thesis_id = ?"); $stmt->execute([$thesisId]); $currentLanguages = $stmt->fetchAll(PDO::FETCH_COLUMN); $stmt = $pdo->prepare("SELECT format_id FROM thesis_formats WHERE thesis_id = ?"); $stmt->execute([$thesisId]); $currentFormats = $stmt->fetchAll(PDO::FETCH_COLUMN); // Load reference data $orientations = $db->getAllOrientations(); $apPrograms = $db->getAllAPPrograms(); $finalityTypes = $db->getAllFinalityTypes(); $languages = $db->getAllLanguages(); $formatTypes = $db->getAllFormatTypes(); // Set page title for header $pageTitle = "Éditer TFE - " . htmlspecialchars($thesis['title']); } catch (Exception $e) { error_log("Error loading edit page: " . $e->getMessage()); die("Erreur lors du chargement: " . $e->getMessage()); } ?>

Modifier un TFE

Séparer par des virgules. Max 10.

Annuler