getPDO(); if ($_FILES['csv_file']['error'] !== UPLOAD_ERR_OK) { throw new Exception("Erreur lors du téléversement du fichier."); } $handle = fopen($_FILES['csv_file']['tmp_name'], 'r'); if (!$handle) throw new Exception("Impossible d'ouvrir le fichier CSV."); fgetcsv($handle, 0, ',', '"', ''); fgetcsv($handle, 0, ',', '"', ''); fgetcsv($handle, 0, ',', '"', ''); fgetcsv($handle, 0, ',', '"', ''); // skip 4 header rows $orientationMap = [ 'SC'=>'Sculpture','VI'=>'Vidéographie','CA'=>"Cinéma d'animation", 'IP'=>'Installation-Performance','PE'=>'Peinture','PH'=>'Photographie', 'DE'=>'Dessin','AN'=>'Arts Numériques','GR'=>'Graphisme', 'TY'=>'Typographie','DN'=>'Design Numérique','IL'=>'Illustration', 'BD'=>'Bande-Dessinée','SE'=>'Sérigraphie','GV'=>'Gravure', ]; $lineNumber = 5; while (($row = fgetcsv($handle, 0, ',', '"', '')) !== false) { $lineNumber++; if (empty($row[0]) && empty($row[1])) continue; try { $importDb->beginTransaction(); $identifier = trim($row[0] ?? ''); $title = trim($row[1] ?? ''); $subtitle = trim($row[2] ?? ''); $authorsRaw = trim($row[3] ?? ''); $contact = trim($row[4] ?? ''); $supervisorsRaw = trim($row[5] ?? ''); $formatsRaw = trim($row[6] ?? ''); $year = intval($row[7] ?? 0); $apCode = trim($row[8] ?? ''); $orientationCode = trim($row[9] ?? ''); $finalityName = trim($row[10] ?? ''); $keywordsRaw = trim($row[11] ?? ''); $synopsis = trim($row[12] ?? ''); $context = trim($row[13] ?? ''); $remarks = trim($row[14] ?? ''); $languageRaw = trim($row[15] ?? ''); $access = trim($row[16] ?? ''); $license = trim($row[17] ?? ''); $sizeInfo = trim($row[18] ?? ''); $juryPoints = !empty($row[19]) ? floatval($row[19]) : null; $baiuLink = trim($row[20] ?? ''); if (empty($title) || empty($year)) throw new Exception("Titre et année requis."); $orientationName = $orientationMap[$orientationCode] ?? null; $orientationId = null; if ($orientationName) { $s = $importPdo->prepare("SELECT id FROM orientations WHERE name = ?"); $s->execute([$orientationName]); $r = $s->fetch(); $orientationId = $r ? $r['id'] : null; } $apProgramId = null; if (!empty($apCode)) { $s = $importPdo->prepare("SELECT id FROM ap_programs WHERE code = ?"); $s->execute([$apCode]); $r = $s->fetch(); $apProgramId = $r ? $r['id'] : null; } $finalityId = null; if (!empty($finalityName)) { $s = $importPdo->prepare("SELECT id FROM finality_types WHERE name = ?"); $s->execute([$finalityName]); $r = $s->fetch(); $finalityId = $r ? $r['id'] : null; } $accessTypeId = null; if (!empty($access)) { $s = $importPdo->prepare("SELECT id FROM access_types WHERE name = ?"); $s->execute([ucfirst(strtolower($access))]); $r = $s->fetch(); $accessTypeId = $r ? $r['id'] : null; } if ($accessTypeId === null) $accessTypeId = 1; if (!empty($identifier)) { $s = $importPdo->prepare("SELECT id FROM theses WHERE identifier = ?"); $s->execute([$identifier]); if ($s->fetch()) { $importDb->rollback(); $skippedCount++; $importResults[] = ['type'=>'skip', 'msg'=>"Ligne $lineNumber: identifiant \"$identifier\" déjà présent, ignoré."]; continue; } } $s = $importPdo->prepare(" INSERT INTO theses ( identifier, title, subtitle, year, orientation_id, ap_program_id, finality_id, synopsis, context_note, remarks, file_size_info, jury_points, baiu_link, access_type_id, is_published, submitted_at ) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,1,CURRENT_TIMESTAMP) "); $s->execute([ !empty($identifier) ? $identifier : null, $title, !empty($subtitle) ? $subtitle : null, $year, $orientationId, $apProgramId, $finalityId, !empty($synopsis) ? $synopsis : null, !empty($context) ? $context : null, !empty($remarks) ? $remarks : null, !empty($sizeInfo) ? $sizeInfo : null, $juryPoints, !empty($baiuLink) ? $baiuLink : null, $accessTypeId, ]); $thesisId = $importPdo->lastInsertId(); if (!empty($authorsRaw)) { foreach (array_map('trim', explode(',', $authorsRaw)) as $idx => $name) { if ($name) { $aId = $importDb->findOrCreateAuthor($name, $idx === 0 ? $contact : null); $s = $importPdo->prepare("INSERT INTO thesis_authors (thesis_id, author_id, author_order) VALUES (?,?,?)"); $s->execute([$thesisId, $aId, $idx + 1]); } } } if (!empty($supervisorsRaw)) { foreach (array_map('trim', explode(',', $supervisorsRaw)) as $idx => $name) { if ($name) { $sId = $importDb->findOrCreateSupervisor($name); $s = $importPdo->prepare("INSERT INTO thesis_supervisors (thesis_id, supervisor_id, supervisor_order) VALUES (?,?,?)"); $s->execute([$thesisId, $sId, $idx + 1]); } } } if (!empty($keywordsRaw)) { foreach (array_slice(array_map('trim', explode(',', $keywordsRaw)), 0, 10) as $kw) { if ($kw) { $tId = $importDb->findOrCreateTag($kw); if ($tId) { $s = $importPdo->prepare("INSERT INTO thesis_tags (thesis_id, tag_id) VALUES (?,?)"); $s->execute([$thesisId, $tId]); } } } } if (!empty($languageRaw)) { $s = $importPdo->prepare("SELECT id FROM languages WHERE name = ?"); $s->execute([ucfirst(strtolower($languageRaw))]); $r = $s->fetch(); if ($r) { $s2 = $importPdo->prepare("INSERT INTO thesis_languages (thesis_id, language_id) VALUES (?,?)"); $s2->execute([$thesisId, $r['id']]); } } if (!empty($formatsRaw)) { foreach (array_map('trim', explode(',', $formatsRaw)) as $fmt) { if ($fmt) { $s = $importPdo->prepare("SELECT id FROM format_types WHERE name = ?"); $s->execute([ucfirst(strtolower($fmt))]); $r = $s->fetch(); if ($r) { $s2 = $importPdo->prepare("INSERT INTO thesis_formats (thesis_id, format_id) VALUES (?,?)"); $s2->execute([$thesisId, $r['id']]); } } } } $importDb->commit(); $importedCount++; $importResults[] = ['type'=>'ok', 'msg'=>"\"$title\" (ID: $thesisId)"]; } catch (Exception $e) { $importDb->rollback(); $skippedCount++; $importResults[] = ['type'=>'error', 'msg'=>"Ligne $lineNumber: " . $e->getMessage()]; error_log("Import error on line $lineNumber: " . $e->getMessage()); } } fclose($handle); $importMessage = "Import terminé : $importedCount TFE importés, $skippedCount ignorés."; $importDone = true; } catch (Exception $e) { $importErrors[] = $e->getMessage(); error_log("CSV import error: " . $e->getMessage()); } } $_SESSION['csrf_token'] = bin2hex(random_bytes(32)); } try { $db = new Database(); $searchQuery = isset($_GET['search']) ? trim($_GET['search']) : ''; $yearFilter = isset($_GET['year']) ? intval($_GET['year']) : null; $orientationFilter = isset($_GET['orientation']) ? intval($_GET['orientation']) : null; $apFilter = isset($_GET['ap']) ? intval($_GET['ap']) : null; $filters = []; if ($searchQuery) $filters['search'] = $searchQuery; if ($yearFilter) $filters['year'] = $yearFilter; if ($orientationFilter) $filters['orientation'] = $orientationFilter; if ($apFilter) $filters['ap'] = $apFilter; $perPage = 25; $page = isset($_GET['page']) ? max(1, intval($_GET['page'])) : 1; $totalCount = $db->getThesesListCount($filters); $totalPages = $totalCount > 0 ? (int) ceil($totalCount / $perPage) : 1; $page = min($page, $totalPages); $offset = ($page - 1) * $perPage; $theses = $db->getThesesList($filters, $perPage, $offset); $stats = $db->getThesesStats(); $years = $db->getAllYears(); $orientations = $db->getAllOrientations(); $apPrograms = $db->getAllAPPrograms(); } catch (Exception $e) { error_log("Error loading theses list: " . $e->getMessage()); die("Erreur lors du chargement de la liste."); } ?>

Liste des TFE

Total
Publiés
Attente

Aucun TFE trouvé.

1) { echo "$from–$to sur $totalCount TFE"; } else { echo "$totalCount TFE"; } ?>

ID Titre Auteur(s) Année Orientation AP Statut Actions

Voir Éditer
$searchQuery, 'year' => $yearFilter ?: '', 'orientation' => $orientationFilter ?: '', 'ap' => $apFilter ?: '', ]); include APP_ROOT . '/templates/partials/pagination.php'; ?>

Importer une liste de TFE

Colonnes : Identifiant, Titre, Sous-titre, Auteur·ice(s), Contact, Promoteur·ice(s), Format, Année, AP, Orientation, Finalité, Mots-clés, Synopsis, Contexte, Remarques, Langue, Autorisation, License, taille, Points sur 20, lien BAIU
Quatre premières lignes ignorées — Séparateur : virgule — UTF-8

Résultats