if ($action == 'addCategory') { if (isset($_POST['title'], $_POST['content'])) { $manager = new CategoryManager($db); $idAuthor = $_SESSION['id']; try { $retour = $manager->create($_POST['title'], $_POST['content'], $idAuthor); header('Location: index.php?page=XcategorysX'); exit; } catch (Exception $e) { $errors = $e->getMessage(); } } } else { if ($action == 'updateCategory') { if (isset($_POST['title'], $_POST['content'])) { $manager = new ArticleManager($db); $category = $manager->findById($_GET['id']); if ($category->getIdAuthor() == $currentUser->getId()) { $id = intval($_GET['id']); $category->setTitle($_POST['title']); $category->setContent($_POST['content']); $retour->{$manager}->update($category); } else { $user = $retour; header('Location : index.php?page=home'); exit; } } } } }
header('Location: index.php?page=articles'); exit; } catch (Exception $e) { $errors = $e->getMessage(); } } if (count($errors) == 0) { $_SESSION['success'] = "Create successful"; header('Location: index.php?page=home'); exit; } } else { if ($action == 'updateArticle') { if (isset($_POST['title'], $_POST['content'], $_POST['image'])) { $manager = new ArticleManager($db); $article = $manager->findById($_GET['id']); if ($article->getIdAuthor() == $currentUser->getId()) { $id = intval($_GET['id']); $article->setTitle($_POST['title']); $article->setContent($_POST['content']); $article->setImage($_POST['image']); $retour->{$manager}->update($article); } else { $user = $retour; header('Location: index.php?page=profil&id=' . $user->getId() . ''); exit; } } } } }