SQL $errors = []; if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (trim($title) === '') { $errors[] = 'Le titre est obligatoire.'; } if (empty($errors)) { $postId = $postManager->create($title, $content, $published_at); if (!empty($_FILES['files']['name'][0])) { foreach ($_FILES['files']['tmp_name'] as $i => $tmpName) { if ($_FILES['files']['error'][$i] === UPLOAD_ERR_OK) { $file = [ 'name' => $_FILES['files']['name'][$i], 'type' => $_FILES['files']['type'][$i], 'tmp_name' => $_FILES['files']['tmp_name'][$i], 'error' => $_FILES['files']['error'][$i], 'size' => $_FILES['files']['size'][$i], ]; $fileManager->upload($postId, $file); } } } header('Location: route.php'); exit; } } $formAction = 'route.php?action=create'; $action = 'create'; include BASE_PATH . '/templates/post_form.php'; break; case 'view': if (!$id) { echo 'ID manquant.'; exit; } $post = $postManager->get($id); if (!$post) { echo 'Post introuvable.'; exit; } include __DIR__ . '/../templates/post_view.php'; break; case 'delete': if ($id) { $postManager->delete($id); } header('Location: route.php'); exit; case 'edit': if (!$id) { echo 'ID manquant.'; exit; } $post = $postManager->get($id); if (!$post) { echo 'Post introuvable.'; exit; } $title = $_POST['title'] ?? $post['title']; $content = $_POST['content'] ?? $post['content']; $published_at = $_POST['published_at'] ?? date('Y-m-d\TH:i', strtotime($post['created_at'])); $published = isset($_POST['published']) ? true : $post['is_published']; $errors = []; if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (trim($title) === '') { $errors[] = 'Le titre est obligatoire.'; } if (empty($errors)) { $published_at_sql = str_replace('T', ' ', $_POST['published_at']); $postManager->update($id, $title, $content, $published_at_sql, $published); if (!empty($_FILES['files']['name'][0])) { foreach ($_FILES['files']['tmp_name'] as $i => $tmpName) { if ($_FILES['files']['error'][$i] === UPLOAD_ERR_OK) { $file = [ 'name' => $_FILES['files']['name'][$i], 'type' => $_FILES['files']['type'][$i], 'tmp_name' => $_FILES['files']['tmp_name'][$i], 'error' => $_FILES['files']['error'][$i], 'size' => $_FILES['files']['size'][$i], ]; $fileManager->upload($id, $file); } } } header("Location: route.php?action=view&id=$id"); exit; } } $formAction = "route.php?action=edit&id=$id"; $action = 'edit'; include BASE_PATH . '/templates/post_form.php'; break; case 'legal': include BASE_PATH . '/templates/legal.php'; break; case 'licenses': include BASE_PATH . '/templates/licenses.php'; break; case 'list': default: $posts = $postManager->getAll(); include BASE_PATH . '/templates/post_list.php'; break; }