mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-05-06 19:19:19 +02:00
refactor: use encapsulated Database methods in formulaire.php and edit.php
This commit is contained in:
@@ -183,27 +183,13 @@ try {
|
||||
$db->setThesisJury($thesisId, $juryMembers);
|
||||
|
||||
// ===== LINK LANGUAGES TO THESIS =====
|
||||
foreach ($languageIds as $languageId) {
|
||||
$stmt = $pdo->prepare("INSERT INTO thesis_languages (thesis_id, language_id) VALUES (?, ?)");
|
||||
$stmt->execute([$thesisId, $languageId]);
|
||||
}
|
||||
$db->setThesisLanguages($thesisId, $languageIds);
|
||||
|
||||
// ===== LINK FORMATS TO THESIS =====
|
||||
foreach ($formatIds as $formatId) {
|
||||
$stmt = $pdo->prepare("INSERT INTO thesis_formats (thesis_id, format_id) VALUES (?, ?)");
|
||||
$stmt->execute([$thesisId, $formatId]);
|
||||
}
|
||||
$db->setThesisFormats($thesisId, $formatIds);
|
||||
|
||||
// ===== LINK TAGS TO THESIS =====
|
||||
foreach ($keywords as $keyword) {
|
||||
if (!empty($keyword)) {
|
||||
$tagId = $db->findOrCreateTag($keyword);
|
||||
if ($tagId) {
|
||||
$stmt = $pdo->prepare("INSERT OR IGNORE INTO thesis_tags (tag_id, thesis_id) VALUES (?, ?)");
|
||||
$stmt->execute([$tagId, $thesisId]);
|
||||
}
|
||||
}
|
||||
}
|
||||
$db->setThesisTags($thesisId, $keywords);
|
||||
|
||||
// ===== HANDLE FILE UPLOADS =====
|
||||
|
||||
@@ -266,28 +252,7 @@ try {
|
||||
}
|
||||
|
||||
// Process banner image
|
||||
if ($bannerFile && isset($bannerFile["error"]) && $bannerFile["error"] === UPLOAD_ERR_OK) {
|
||||
$finfo = new finfo(FILEINFO_MIME_TYPE);
|
||||
$mimeType = $finfo->file($bannerFile["tmp_name"]);
|
||||
$fileExtension = strtolower(pathinfo($bannerFile["name"], PATHINFO_EXTENSION));
|
||||
$allowedBannerMimes = ['image/jpeg', 'image/png', 'image/webp'];
|
||||
$allowedBannerExts = ['jpg', 'jpeg', 'png', 'webp'];
|
||||
$maxBannerSize = 5 * 1024 * 1024; // 5 MB
|
||||
|
||||
if (in_array($mimeType, $allowedBannerMimes) && in_array($fileExtension, $allowedBannerExts)
|
||||
&& $bannerFile["size"] <= $maxBannerSize) {
|
||||
$randomName = bin2hex(random_bytes(16));
|
||||
$safeFileName = $randomName . "." . $fileExtension;
|
||||
$targetFile = $bannerDir . $safeFileName;
|
||||
if (move_uploaded_file($bannerFile["tmp_name"], $targetFile)) {
|
||||
chmod($targetFile, 0644);
|
||||
$db->setBannerPath($thesisId, "banners/" . $safeFileName);
|
||||
error_log("Banner image uploaded: " . $safeFileName);
|
||||
}
|
||||
} else {
|
||||
error_log("Invalid or oversized banner image: " . $bannerFile["name"]);
|
||||
}
|
||||
}
|
||||
$db->handleBannerUpload($thesisId, $bannerFile ?: null);
|
||||
|
||||
// Process thesis files
|
||||
if ($files && is_array($files["name"])) {
|
||||
|
||||
Reference in New Issue
Block a user