mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-06-25 16:19:19 +02:00
175 lines
6.5 KiB
PHP
175 lines
6.5 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../../bootstrap.php';
|
|
require_once __DIR__ . '/../../src/AdminAuth.php';
|
|
require_once __DIR__ . '/../../src/Form/FormBootstrap.php';
|
|
AdminAuth::requireLogin();
|
|
|
|
if (empty($_SESSION['csrf_token'])) {
|
|
$_SESSION['csrf_token'] = bin2hex(random_bytes(32));
|
|
}
|
|
|
|
$thesisId = isset($_GET['id']) ? intval($_GET['id']) : 0;
|
|
if ($thesisId <= 0) {
|
|
die('ID invalide');
|
|
}
|
|
|
|
require_once __DIR__ . '/../../src/Controllers/ThesisEditController.php';
|
|
|
|
$formData = [];
|
|
$siteSettings = Database::getInstance()->getAllSettings();
|
|
$helpBlocks = Database::getInstance()->getAllFormHelpBlocks();
|
|
|
|
try {
|
|
$ctrl = ThesisEditController::create();
|
|
$view = $ctrl->load($thesisId);
|
|
extract($view);
|
|
} catch (Exception $e) {
|
|
error_log('Error loading edit page: ' . $e->getMessage());
|
|
die('Erreur lors du chargement: ' . $e->getMessage());
|
|
}
|
|
|
|
// Merge flash repopulation data (from redirects after validation errors)
|
|
// with current thesis data so old() can fall back to DB values.
|
|
$formData = array_merge($formData, [
|
|
'titre' => $thesis['title'],
|
|
'subtitle' => $thesis['subtitle'] ?? '',
|
|
'auteurice' => $thesis['authors'] ?? '',
|
|
'mail' => $contactInterne ?? '',
|
|
'contact_visible' => $currentContactVisible ?? '',
|
|
'synopsis' => $thesis['synopsis'] ?? '',
|
|
'tag' => $thesis['keywords'] ?? '',
|
|
'année' => $thesis['year'],
|
|
'orientation' => $thesis['orientation'],
|
|
'ap' => $thesis['ap_program'],
|
|
'finality' => $thesis['finality_type'],
|
|
'lien' => $thesis['baiu_link'] ?? '',
|
|
'contact_public' => $contactPublic ?? false,
|
|
'contact_interne' => $contactInterne ?? '',
|
|
]);
|
|
|
|
// Build jury arrays
|
|
$juryPromoteurs = [];
|
|
$juryPromoteursUlb = [];
|
|
$lecteursInternes = [];
|
|
$lecteursExternes = [];
|
|
$juryPromoteur = null;
|
|
$juryPromoteurUlb = null;
|
|
|
|
foreach ($jury as $jm) {
|
|
if ($jm['role'] === 'president') continue;
|
|
if ($jm['role'] === 'promoteur') {
|
|
if (($jm['is_ulb'] ?? 0) == 1) {
|
|
$juryPromoteursUlb[] = $jm;
|
|
} else {
|
|
$juryPromoteurs[] = $jm;
|
|
}
|
|
} elseif ($jm['role'] === 'lecteur') {
|
|
if (($jm['is_external'] ?? 0) == 1) {
|
|
$lecteursExternes[] = $jm;
|
|
} else {
|
|
$lecteursInternes[] = $jm;
|
|
}
|
|
}
|
|
}
|
|
if (!empty($juryPromoteurs) && $juryPromoteur === null) $juryPromoteur = $juryPromoteurs[0]['name'];
|
|
if (!empty($juryPromoteursUlb) && $juryPromoteurUlb === null) $juryPromoteurUlb = $juryPromoteursUlb[0]['name'];
|
|
|
|
// Build existing website URL / label from current files
|
|
$existingWebsiteUrl = '';
|
|
$existingWebsiteLabel = '';
|
|
foreach ($currentFiles as $f) {
|
|
if ($f['file_type'] === 'website') {
|
|
$existingWebsiteUrl = $f['file_path'] ?? '';
|
|
$existingWebsiteLabel = $f['display_label'] ?? '';
|
|
break;
|
|
}
|
|
}
|
|
|
|
// Languages — either from flash repopulation or current thesis data
|
|
$formData['languages'] = $formData['languages'] ?? $currentLanguages ?? [];
|
|
|
|
// Compute "other" languages (not in the predefined checkbox list)
|
|
$predefinedLangIds = array_column($languages, 'id');
|
|
$otherLangIds = array_diff($currentLanguages ?? [], $predefinedLangIds);
|
|
$selectedOtherLanguages = [];
|
|
if (!empty($otherLangIds)) {
|
|
$allLangs = Database::getInstance()->getAllLanguages();
|
|
$allLangMap = [];
|
|
foreach ($allLangs as $al) {
|
|
$allLangMap[(int)$al['id']] = $al['name'];
|
|
}
|
|
foreach ($otherLangIds as $lid) {
|
|
$lid = (int)$lid;
|
|
if (isset($allLangMap[$lid])) {
|
|
$selectedOtherLanguages[] = $allLangMap[$lid];
|
|
}
|
|
}
|
|
sort($selectedOtherLanguages, SORT_NATURAL | SORT_FLAG_CASE);
|
|
}
|
|
|
|
// Tags — either from flash repopulation or current thesis data
|
|
$keywordsStr = $thesis['keywords'] ?? '';
|
|
$currentTags = $keywordsStr !== '' ? array_map('trim', explode(',', $keywordsStr)) : [];
|
|
if (!empty($formData['tag']) && is_array($formData['tag'])) {
|
|
$currentTags = $formData['tag'];
|
|
}
|
|
|
|
// Formats — either from flash repopulation or current thesis data
|
|
$checkedFormats = $formData['formats'] ?? $currentFormats ?? [];
|
|
$formData['formats'] = $checkedFormats;
|
|
|
|
// Shared form variables from the bootstrap helper
|
|
extract(FormBootstrap::adminFormVariables(
|
|
mode: 'edit',
|
|
formAction: '/admin/actions/edit.php',
|
|
hiddenFields:
|
|
'<input type="hidden" name="csrf_token" value="' . htmlspecialchars($_SESSION['csrf_token']) . '">',
|
|
formData: $formData,
|
|
siteSettings: $siteSettings,
|
|
helpBlocks: $helpBlocks,
|
|
options: [
|
|
'thesisId' => $thesisId,
|
|
'filesMode' => 'edit',
|
|
'existingWebsiteUrl' => $existingWebsiteUrl,
|
|
'existingWebsiteLabel' => $existingWebsiteLabel,
|
|
'checkedFormats' => $checkedFormats,
|
|
'juryPromoteurs' => $juryPromoteurs,
|
|
'juryPromoteursUlb' => $juryPromoteursUlb,
|
|
'lecteursInternes' => $lecteursInternes,
|
|
'lecteursExternes' => $lecteursExternes,
|
|
'juryPromoteur' => $juryPromoteur,
|
|
'juryPromoteurUlb' => $juryPromoteurUlb,
|
|
'currentRaw' => $currentRaw ?? [],
|
|
'currentCover' => $currentCover ?? null,
|
|
'currentFiles' => $currentFiles ?? [],
|
|
'currentContextNote' => $currentContextNote ?? null,
|
|
'currentContactVisible' => $currentContactVisible ?? null,
|
|
'currentDurationValue' => $currentDurationValue ?? null,
|
|
'currentDurationUnit' => $currentDurationUnit ?? 'pages',
|
|
'contactInterne' => $contactInterne ?? null,
|
|
'contactPublic' => $contactPublic ?? false,
|
|
'showCoverPreview' => true,
|
|
'showExistingFiles' => true,
|
|
'defaultAccessTypeId' => $currentAccessTypeId ?? 2,
|
|
],
|
|
));
|
|
|
|
// Inject thesis-derived values into formData for the template
|
|
$formData['access_type_id'] = $currentAccessTypeId;
|
|
$formData['license_id'] = $currentLicenseId;
|
|
$formData['license_custom'] = $currentRaw['license_custom'] ?? '';
|
|
$formData['cc2r'] = $currentRaw['cc2r'] ?? false;
|
|
|
|
// Duration variables for the form template
|
|
$durationValue = $currentDurationValue ?? null;
|
|
$durationUnit = $currentDurationUnit ?? 'pages';
|
|
|
|
// Asset arrays and page chrome
|
|
$isAdmin = true;
|
|
$bodyClass = 'admin-body';
|
|
extract(FormBootstrap::adminAssetArrays());
|
|
require_once APP_ROOT . '/templates/head.php';
|
|
include APP_ROOT . '/templates/header.php';
|
|
include APP_ROOT . '/templates/admin/edit.php';
|
|
require_once APP_ROOT . '/templates/admin/footer.php';
|