setName($_POST['new_category']); $objCategoryModel->insertCategory($newCat); $_SESSION['success'] = "La catégorie a bien été ajoutée"; 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); $_SESSION['success'] = "La catégorie a bien été modifiée"; header('Location: index.php?ctrl=admin&action=admin'); exit; } //affichage select des catégories $arrCategory = $objCategoryModel->findAllCategory(); $arrCategoryToDisplay = array(); foreach($arrCategory as $arrDetCategory){ $objCategory = new Category; $objCategory->hydrate($arrDetCategory); $arrCategoryToDisplay[] = $objCategory; } //gestion de l'user $objUserModel = new UserModel; if (!empty($_POST['action'])) { $intUserId = (int)$_POST['user_id']; if ($intUserId > 0) { if ($_POST['action'] === 'update_status' && !empty($_POST['new_status'])) { $objUser = new User(); $objUser->setId($intUserId); $objUser->setStatus((int)$_POST['new_status']); if ($objUserModel->editStatus($objUser)) { $_SESSION['success'] = "Le statut a bien été modifié !"; } } elseif ($_POST['action'] === 'delete_user') { $objUserModel->delete_soft($intUserId); $_SESSION['success'] = "L'utilisateur a été supprimé."; } header("Location: index.php?ctrl=admin&action=admin"); exit; } } //affichage select des users $arrUser = $objUserModel->findAllUsers(); $arrUserToDisplay = array(); foreach($arrUser as $arrDetUser){ $objUser = new User; $objUser->hydrate($arrDetUser); $arrUserToDisplay[] = $objUser; } //affichage select des authorisations $objAuthorisationModel = new AuthorisationModel; $arrAuthorisation = $objAuthorisationModel->findAllAuthorisation(); $arrAuthorisationToDisplay = array(); foreach($arrAuthorisation as $arrDetAuthorisation){ $objAuthorisation = new Authorisation; $objAuthorisation->hydrate($arrDetAuthorisation); $arrAuthorisationToDisplay[] = $objAuthorisation; } //gérer l'affichage $this->_arrData['arrCategoryToDisplay'] = $arrCategoryToDisplay; $this->_arrData['arrUserToDisplay'] = $arrUserToDisplay; $this->_arrData['arrAuthorisationToDisplay'] = $arrAuthorisationToDisplay; $this->_display("admin"); } }