$idSCategory = $sCategory->getId(); if (isset($idSCategory)) { $managerTopic = new TopicManager($db); $idAuthor = $_SESSION['id']; try { $retour = $managerTopic->create($_POST['title'], $idAuthor, $sCategory); } catch (Exception $e) { $errors = $e->getMessage(); } $managerPost = new PostManager($db); $lastTopic = $managerTopic->getLast(); $lastTopicIdSCategory = $lastTopic->getIdSCategory(); $manager = new SCategoryManager($db); $sCategory = $manager->findById($lastTopicIdSCategory); try { $retour = $managerPost->create($_POST['content'], $idAuthor, $lastTopic, $sCategory); } catch (Exception $e) { $errors = $e->getMessage(); } $managerUser = new UserManager($db); try { $retour = $managerUser->addTopicUser($lastTopic); header('Location: index.php?page=XtopicX&id=' . $lastTopic->getId() . ''); exit; } catch (Exception $e) { $errors = $e->getMessage(); } } else { throw new Exception("Categorie inéxistance"); } }
if (isset($_GET['page'])) { $action = $_GET['page']; if ($action == 'addPost') { if (isset($_POST['content'])) { $manager = new TopicManager($db); $topic = $manager->findById($_GET['id']); $idTopic = $topic->getId(); $idScategoryTopic = $topic->getIdSCategory(); $manager = new SCategoryManager($db); $sCategory = $manager->findById($idScategoryTopic); if (isset($idTopic)) { $manager = new PostManager($db); $userManager = new UserManager($db); $idAuthor = $_SESSION['id']; try { $retour = $manager->create($_POST['content'], $idAuthor, $topic, $sCategory); $retour = $userManager->addTopicUser($topic); header('Location: index.php?page=XtopicX&id=' . $topic->getId() . ''); exit; } catch (Exception $e) { $errors = $e->getMessage(); } } else { throw new Exception("Categorie inéxistance"); } } } else { if ($action == 'updateSCategory') { if (isset($_POST['title'], $_POST['content'])) { $manager = new CategoryManager($db); $category = $manager->findById($_GET['id']);
$title = ''; $content = ''; if (isset($_GET['action']) && $_GET['action'] == 'create') { if (isset($_POST['title'], $_POST['content'], $_SESSION['id'], $_GET['id'])) { $SousRubriqueManager = new SousRubriqueManager($db); $currentSousRubrique = $SousRubriqueManager->findById($_GET['id']); $title = $_POST['title']; $manager = new TopicManager($db); $topic = $manager->create($currentSousRubrique, $currentUser, $title); if (is_string($topic)) { $errors[] = $topic; } else { $content = $_POST['content']; $idTopic = $topic->getId(); $PostManager = new PostManager($db); $post = $PostManager->create($idTopic, $content); if (is_string($post)) { var_dump($post); exit; $errors[] = $post; } else { header('Location: ?page=create_topic&id=1'); exit; } } } else { header('Location : ?page=error_404'); } } if (isset($_GET['action']) && $_GET['action'] == 'edit') { $manager = new TopicManager($db);
<?php $content = ''; // ________ CREATE POST ________ if (isset($_GET['action']) && $_GET['action'] == 'create') { if (isset($_POST['content'], $_GET['id'])) { $idTopic = $_GET['id']; $content = $_POST['content']; $manager = new PostManager($db); $back = $manager->create($idTopic, $content); if (is_string($back)) { $errors[] = $back; } else { $topic = $manager->getTopic($back->getId()); $postCount = count($manager->getList($topic->getId())); $lastPage = ceil($postCount / 10); $idTopic = $topic->getId(); $idPost = $back->getId(); header('Location: index.php?page=topic&id=' . $idTopic . '&p=' . $lastPage . '#' . $idPost . ''); exit; } } } // ________________ // ________ EDIT POST ________ if (isset($_GET['action']) && $_GET['action'] == 'edit') { if (isset($_POST['content'], $_GET['id'])) { $content = $_POST['content']; $idPost = $_GET['id']; $manager = new PostManager($db); $back = $manager->edit($idPost, $content);