Modification et ajout de catégorie fonctionne. Accès page admin protété

This commit is contained in:
laura.chevillet 2026-02-09 14:29:17 +01:00
parent 2535d13d7c
commit 3a80108ba5
11 changed files with 338 additions and 126 deletions

View file

@ -18,31 +18,28 @@
class AdminCtrl extends MotherCtrl{
public function admin(){
/*accès à la page admin
if (!isset($_SESSION['user']) && ($_SESSION['user']['user_status'] != 1 )){
header("Location:index.php?ctrl=error&action=error_403");
exit;
}*/
}
$objCategoryModel = new CategoryModel;
if (!empty($_POST['new_category'])) {
$objNewCategory = new Category;
if (!empty($objNewCategory->getName())) {
$objNewCategory = $_POST['new_category'];
$objCategoryModel->insertCategory($objNewCategory);
header("Location:index.php?ctrl=admin&action=admin");
exit;
}
$newCat = new Category();
$newCat->setName($_POST['new_category']);
$objCategoryModel->insertCategory($newCat);
header('Location: index.php?ctrl=admin&action=admin');
exit;
}
if (!empty($_POST['edit_category'])) {
$objEditCategory = new Category;
if ($objEditCategory->getId() > 0) {
$objEditCategory = $_POST['edit_category'];
$objCategoryModel->editCategory($objEditCategory);
header("Location:index.php?ctrl=admin&action=admin");
exit;
}
if (!empty($_POST['id_to_edit']) && !empty($_POST['new_name'])) {
$editCat = new Category();
$editCat->setId($_POST['id_to_edit']);
$editCat->setName($_POST['new_name']);
$objCategoryModel->editCategory($editCat);
header('Location: index.php?ctrl=admin&action=admin');
exit;
}
$arrCategory = $objCategoryModel->findAllCategory();
@ -54,8 +51,8 @@
$arrCategoryToDisplay[] = $objCategory;
}
//gérer l'affichage
$this->_arrData['arrCategoryToDisplay'] = $arrCategoryToDisplay;
//$this->_arrData['intCategory'] = $objCategoryModel->;
$this->_display("admin");
}
}