Files
xamxam/public/admin
Pontoporeia 2841e05716 Extract ThesisCreateController; add Database publish methods
Consolidate action handlers into controller methods (todo/02-php-components.md).

src/ThesisCreateController.php (new, 435 lines)
  Mirrors ThesisEditController for the add-thesis flow.

  make()           — factory; instantiates Database via new Database()
  loadFormData()   — returns all lookup tables needed by admin/add.php
                     (orientations, apPrograms, finalityTypes, languages,
                      formatTypes, licenseTypes)
  submit(post, files) — full new-thesis creation pipeline:
    1. validateAndSanitise() — trims/strips HTML, validates required fields,
       year range, orientation/ap/finality IDs, language selection, max-10
       keywords, URL format; throws named Exception on failure
    2. findOrCreateAuthor() — reuses existing DB method
    3. Transaction: createThesis + setThesisJury + setThesisLanguages +
       setThesisFormats + setThesisTags; rolls back on any failure
    4. File uploads outside transaction: cover image (JPG/PNG only, stored in
       storage/covers/), banner via handleBannerUpload(), thesis files
       (PDF/JPG/PNG/MP4/ZIP/VTT, stored in storage/theses/YEAR/IDENT/,
       file_type auto-detected: caption/annex/main/other)
  autofocusFieldForError() — static; maps exception messages to field names
    for WCAG 3.3.1 autofocus on re-render (same contract as
    ThesisEditController::autofocusFieldForError)

admin/actions/formulaire.php  346 → 45 lines
  Now: bootstrap + CSRF guard + ThesisCreateController::make()->submit() +
  flash/redirect on error. All validation, DB logic, and file handling removed.

admin/add.php
  Lookup-table block (new Database() + 6 individual DB calls) replaced with
  ThesisCreateController::make()->loadFormData() + extract().

src/Database.php — two new methods added
  setPublished(int , bool ): void
    UPDATE theses SET is_published = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ?
  bulkSetPublished(int[] , bool ): void
    Same but with an IN (...) clause for multiple IDs

admin/actions/publish.php  100 → 65 lines
  Raw SQL (->prepare('UPDATE theses SET is_published = ?...')) replaced
  with ->setPublished() / ->bulkSetPublished(). No raw PDO calls remain
  in any action handler file.
2026-04-06 15:33:08 +02:00
..

Admin Panel Structure

This directory contains the admin panel for managing Post-ERG thesis database.

Directory Structure

public/admin/
├── index.php          # List all theses (main page)
├── add.php            # Add new thesis form
├── edit.php           # Edit existing thesis form
├── import.php         # CSV import form
├── thanks.php         # Thank you page after submission
├── actions/           # Backend processing scripts (no HTML output)
│   ├── formulaire.php # Process thesis submission from add.php
│   └── publish.php    # Toggle publish/unpublish status
├── inc/               # Shared templates
│   ├── head.php       # HTML head, CSS, navigation
│   └── footer.php     # HTML footer
└── data/              # Upload directory (not in git)
    ├── theses/        # PDF files
    └── covers/        # Cover images

File Types

User-Facing Templates (Root Directory)

Files that display HTML to users:

  • index.php - Lists all theses with filters and bulk actions
  • add.php - Form to add a new thesis
  • edit.php - Form to edit an existing thesis
  • import.php - CSV import interface
  • thanks.php - Success confirmation page

Backend Scripts (actions/)

Files that process forms and redirect (no HTML output):

  • formulaire.php - Processes thesis submission from add.php
  • publish.php - Handles publish/unpublish actions

Shared Templates (inc/)

Reusable HTML components:

  • head.php - HTML head, CSS links, navigation menu
  • footer.php - HTML footer

Workflow

Adding a Thesis

  1. User visits add.php (displays form)
  2. User submits form to actions/formulaire.php (processes data)
  3. On success, redirects to thanks.php?id=123
  4. On error, redirects back to add.php with error message

Publishing/Unpublishing

  1. User clicks publish/unpublish button in index.php
  2. Form submits to actions/publish.php (processes action)
  3. Redirects back to index.php with success/error message

Security

  • All pages require HTTP Basic Auth (configured in nginx) — primary layer
  • All pages require PHP session auth (AdminAuth::requireLogin()) — defence-in-depth
  • CSRF tokens protect all forms
  • File uploads validated and sanitized
  • Database queries use prepared statements
  • Upload directory outside public/ in production

See nginx/PHP_AUTH_LAYER.md for details on the dual-auth architecture.

Templates

The inc/ folder contains shared templates:

  • head.php - Included at the top of each page (DOCTYPE, CSS, nav)
  • footer.php - Included at the bottom of each page (closing tags)

Usage:

<?php include "inc/head.php" ?>
<!-- Page content here -->
<?php include "inc/footer.php" ?>

URL Structure

  • /admin/ - List theses (index.php)
  • /admin/add.php - Add new thesis
  • /admin/edit.php?id=123 - Edit thesis #123
  • /admin/import.php - Import CSV
  • /admin/thanks.php?id=123 - Thank you page

Backend actions (not directly accessed):

  • /admin/actions/formulaire.php - Form processor
  • /admin/actions/publish.php - Publish toggle

Development

Adding a New Page

  1. Create the template in /admin/yourpage.php:
<?php
require_once __DIR__ . "/../../config/bootstrap.php";
require_once __DIR__ . '/../../lib/AdminAuth.php';
AdminAuth::requireLogin();
$pageTitle = "Your Page Title";
?>
<?php include "inc/head.php" ?>

<!-- Your content here -->

<?php include "inc/footer.php" ?>
  1. Add navigation link in inc/head.php if needed

Adding a New Action

  1. Create the script in /admin/actions/youraction.php:
<?php
require_once __DIR__ . "/../../config/bootstrap.php";
require_once __DIR__ . '/../../lib/AdminAuth.php';
AdminAuth::requireLogin();

// Verify CSRF token
if (!hash_equals($_SESSION['csrf_token'], $_POST['csrf_token'])) {
    $_SESSION['error'] = "Security error";
    header('Location: ../index.php');
    exit;
}

// Process action...

// Redirect
header('Location: ../yourpage.php');
exit;
  1. Create form in template that posts to actions/youraction.php

Notes

  • Bootstrap path from actions/: __DIR__ . "/../../config/bootstrap.php"
  • Redirects from actions/: use ../ prefix (e.g., ../index.php)
  • Database class: require_once __DIR__ . '/../../lib/Database.php'
  • All forms must include CSRF token from $_SESSION['csrf_token']