diff --git a/controllers/admin_controller.php b/controllers/admin_controller.php index 8e4a509..5fd9e56 100644 --- a/controllers/admin_controller.php +++ b/controllers/admin_controller.php @@ -25,6 +25,7 @@ header("Location:index.php?ctrl=error&action=error_403"); exit; } + var_dump($_SESSION); //gestion de l'user $objCategoryModel = new CategoryModel; @@ -33,6 +34,7 @@ $newCat = new Category(); $newCat->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; } @@ -68,12 +70,12 @@ $objUser->setId($intUserId); $objUser->setStatus((int)$_POST['new_status']); if ($objUserModel->editStatus($objUser)) { - $_SESSION['message_success'] = "Le statut a bien été modifié !"; + $_SESSION['success'] = "Le statut a bien été modifié !"; } } elseif ($_POST['action'] === 'delete_user') { $objUserModel->delete_soft($intUserId); - $_SESSION['message_success'] = "L'utilisateur a été supprimé."; + $_SESSION['success'] = "L'utilisateur a été supprimé."; } header("Location: index.php?ctrl=admin&action=admin"); exit; diff --git a/controllers/mother_controller.php b/controllers/mother_controller.php index 953a1ef..743606c 100644 --- a/controllers/mother_controller.php +++ b/controllers/mother_controller.php @@ -10,7 +10,7 @@ /** * Méthode d'affichage des pages */ - protected function _display($strView){ + protected function _display($strView, bool $boolDisplay = true){ // Création de l'objet Smarty $objSmarty = new Smarty(); // Ajouter le var_dump au modificateur de smarty : vardump est le nom appelé après le | @@ -32,8 +32,18 @@ // Message de succès $objSmarty->assign("success_message", $_SESSION['success']??''); unset($_SESSION['success']); + + if (isset($_SESSION['error'])){ + $objSmarty->assign("arrError", array($_SESSION['error'])); + unset($_SESSION['error']); + } + + if ($boolDisplay){ + $objSmarty->display("views/".$strView.".tpl"); + }else{ + return $objSmarty->fetch("views/".$strView.".tpl"); + } - $objSmarty->display("views/".$strView.".tpl"); // inclusion du header diff --git a/views/_partial/header.tpl b/views/_partial/header.tpl index 17898e0..5cacc32 100644 --- a/views/_partial/header.tpl +++ b/views/_partial/header.tpl @@ -84,5 +84,5 @@ - - + {$success_message|vardump} + {include file="views/_partial/messages.tpl"} \ No newline at end of file diff --git a/views/_partial/messages.tpl b/views/_partial/messages.tpl new file mode 100644 index 0000000..29cf5b4 --- /dev/null +++ b/views/_partial/messages.tpl @@ -0,0 +1,14 @@ + + {if ($success_message != '')} +
+

{$success_message}

+
+ {/if} + + {if (isset($arrError) && count($arrError) > 0) } +
+ {foreach $arrError as $strError} +

{$strError}

+ {/foreach} +
+ {/if} diff --git a/views/admin.tpl b/views/admin.tpl index 7b0fefe..640702a 100644 --- a/views/admin.tpl +++ b/views/admin.tpl @@ -33,7 +33,7 @@
- +