<?php if (isset($_GET['page'])) { $action = $_GET['page']; 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; }
<?php if (isset($_GET['page'])) { if ($_GET['page'] == 'create_category') { $category_name = $category_banner = $category_description = ""; if (isset($_POST['category_name'], $_POST['category_banner'], $_POST['category_description'])) { $categoryManager = new CategoryManager($db); $category = $categoryManager->create($_POST['category_name'], $_POST['category_description'], $_POST['category_banner']); if (is_array($category)) { $errors = array_merge($errors, $category); $category_name = $_POST['category_name']; $category_banner = $_POST['category_banner']; $category_description = $_POST['category_description']; } else { $_SESSION['success'] = "Categorie créée avec succès"; header('Location: ?page=category&id=' . $category->getId()); exit; } } } if ($_GET['page'] == 'create_sub_category') { $subCategory_name = $subCategory_banner = $subCategory_description = ""; if (isset($_POST['subCategory_name'], $_POST['subCategory_banner'], $_POST['subCategory_description'], $_POST['subCategory_category'])) { $subCategoryManager = new SubCategoryManager($db); $categoryManager = new CategoryManager($db); try { $category = $categoryManager->findById($_POST['subCategory_category']); } catch (Exception $e) { $errors[] = $e->getMessage(); } $subCategory = $subCategoryManager->create($category, $_POST['subCategory_name'], $_POST['subCategory_description'], $_POST['subCategory_banner']);
<?php if (isset($_POST['action'])) { if ($_POST['action'] == "add") { if (isset($_POST['name'], $_POST['description'])) { $category_name = $_POST['name']; $category_description = $_POST['description']; $categoryManager = new CategoryManager($database); try { $categoryManager->create($currentUser, $category_name, $category_description); } catch (Exception $e) { $_SESSION['errors'] = $e->getMessage(); } if (!isset($_SESSION['errors']) || $_SESSION['errors'] == "") { $_SESSION['success'] = "Category a bien été crée"; } header('Location: ?page=admin'); exit; } } }
<?php if (isset($_SESSION['id']) && $currentUser->getStatus() > 0) { // Categories admin page if ($_GET['page'] == 'dashboard_categories') { // Create new category if (isset($_POST['new_name'], $_POST['new_description'])) { $categoryManager = new CategoryManager($db); try { $category = $categoryManager->create($_POST['new_name'], $_POST['new_description']); } catch (Exception $e) { $errors[] = $e->getMessage(); } if (isset($category)) { header('Location: ?page=dashboard_categories'); exit; } } } }