<?php if (isset($_POST['action'])) { if ($_POST['action'] == "add") { if (isset($_POST['name'], $_POST['category'], $_POST['description'], $_POST['image'])) { $sub_name = $_POST['name']; $sub_id_category = $_POST['category']; $sub_description = $_POST['description']; $sub_image = $_POST['image']; $subcategoryManager = new SubCategoryManager($database); $categoryManager = new CategoryManager($database); $category = $categoryManager->findById($sub_id_category); try { $subcategoryManager->create($sub_name, $sub_description, $sub_image, $category); } catch (Exception $e) { $errors[] = $e->getMessage(); } if (count($errors) == 0) { $_SESSION['success'] = "La sous-categorie a bien été crée"; } else { $_SESSION['errors'] = $errors; } header('Location: ?page=admin'); exit; } } }
<?php $sub_categoryManager = new SubCategoryManager($db); try { $sub_category = $sub_categoryManager->findById($_GET['id']); } catch (Exception $e) { $sub_category = $e->getMessage(); } if (!is_string($sub_category)) { require 'views/sub_category.phtml'; } else { echo "Nothing to show"; }
public function __construct($db) { parent::__construct($db); $this->db = $db; }
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']); if (is_array($subCategory)) { $errors = array_merge($errors, $subCategory); $subCategory_name = $_POST['subCategory_name']; $subCategory_banner = $_POST['subCategory_banner']; $subCategory_description = $_POST['subCategory_description']; } else { $_SESSION['success'] = "Subcategory has been created"; header('Location: ?page=sub_category&id=' . $subCategory->getId());
<?php if (isset($_GET['page'])) { if ($_GET['page'] == 'create_product') { $name = $description = $price = $img = $stock = ""; if (isset($_POST['name'], $_POST['description'], $_POST['price'], $_POST['img'], $_POST['stock'], $_POST['subCategory_category'])) { $productManager = new ProductManager($db); $subCategoryManager = new SubCategoryManager($db); try { $subCategory = $subCategoryManager->findById($_POST['subCategory_category']); } catch (Exception $e) { $errors[] = $e->getMessage(); } $product = $productManager->create($subCategory, $_POST['name'], $_POST['description'], $_POST['price'], $_POST['img'], $_POST['stock']); if (is_array($product)) { $errors = array_merge($errors, $product); $name = $_POST['name']; $description = $_POST['description']; $price = $_POST['price']; $img = $_POST['img']; $stock = $_POST['stock']; } else { $_SESSION['success'] = "Produit créé avec succès"; header('Location: ?page=product&id=' . $product->getId()); exit; } } } }
<?php $productManager = new ProductManager($db); $sub_categoryManager = new SubCategoryManager($db); $sub_category = $sub_categoryManager->find(); require 'views/create_product.phtml';
<?php $subCategoryManager = new SubCategoryManager($db); try { $subcategory_list = $subCategoryManager->find(); } catch (Exception $e) { $subcategory_list = $e->getMessage(); } if (is_string($subcategory_list)) { $errors[] = "Nothing to show"; } else { for ($i = 0; $i < count($subcategory_list); $i++) { $subcategory = $subcategory_list[$i]; require 'views/create_sub_category_list.phtml'; } } require 'views/create_sub_category.phtml';