<?php if (isset($_GET['page'])) { $action = $_GET['page']; if ($action == 'addTopic') { if (isset($_POST['title'], $_POST['content'])) { $manager = new SCategoryManager($db); $sCategory = $manager->findById($_GET['id']); $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() . '');
<?php /* NE PAS OUBLIER L ID TOPIC*/ $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'); }