diff --git a/controllers/admin_controller.php b/controllers/admin_controller.php index 9b38286..8e4a509 100644 --- a/controllers/admin_controller.php +++ b/controllers/admin_controller.php @@ -8,6 +8,8 @@ require("./entities/image_entity.php"); require("./models/user_model.php"); require("./entities/user_entity.php"); + require("./models/authorisation_model.php"); + require("./entities/authorisation_entity.php"); require("mother_controller.php"); /** @@ -23,6 +25,8 @@ header("Location:index.php?ctrl=error&action=error_403"); exit; } + + //gestion de l'user $objCategoryModel = new CategoryModel; if (!empty($_POST['new_category'])) { @@ -42,6 +46,7 @@ exit; } + //affichage select des catégories $arrCategory = $objCategoryModel->findAllCategory(); $arrCategoryToDisplay = array(); @@ -50,9 +55,56 @@ $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['message_success'] = "Le statut a bien été modifié !"; + } + } + elseif ($_POST['action'] === 'delete_user') { + $objUserModel->delete_soft($intUserId); + $_SESSION['message_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['arrCategoryToDisplay'] = $arrCategoryToDisplay; + $this->_arrData['arrUserToDisplay'] = $arrUserToDisplay; + $this->_arrData['arrAuthorisationToDisplay'] = $arrAuthorisationToDisplay; $this->_display("admin"); } } diff --git a/entities/authorisation_entity.php b/entities/authorisation_entity.php new file mode 100644 index 0000000..1cb600b --- /dev/null +++ b/entities/authorisation_entity.php @@ -0,0 +1,24 @@ +_prefix = 'authorisation_'; + } + + public function getId():int{ + return $this->_id; + } + public function setId(int $id){ + $this->_id = $id; + } + + public function getName():string{ + return $this->_name; + } + + } \ No newline at end of file diff --git a/models/authorisation_model.php b/models/authorisation_model.php new file mode 100644 index 0000000..84a3dd6 --- /dev/null +++ b/models/authorisation_model.php @@ -0,0 +1,29 @@ +_db->query($strRq)->fetchAll(); + } + + } \ No newline at end of file diff --git a/models/user_model.php b/models/user_model.php index 72f1ada..fd682e7 100644 --- a/models/user_model.php +++ b/models/user_model.php @@ -22,7 +22,8 @@ public function findAllUsers():array{ // Ecrire la requête $strRq = "SELECT user_id, user_firstname, user_name, user_image, user_status, authorisation_name - FROM users INNER JOIN authorisation ON authorisation.authorisation_id = users.user_status"; + FROM users INNER JOIN authorisation ON authorisation.authorisation_id = users.user_status + WHERE user_deleted_at IS NULL"; // Lancer la requête et récupérer les résultats return $this->_db->query($strRq)->fetchAll(); } @@ -50,7 +51,6 @@ } } - //public function insert(string $strName, string $strFirstname, string $strMail, string $strPwd):int{ /** * Fonction d'insertion d'un utilisateur en BDD * @param object $objUser L'objet utilisateur @@ -75,13 +75,10 @@ $rqPrep->bindValue(':location', $objUser->getLocation() ?? "", PDO::PARAM_STR); $rqPrep->bindValue(':description', $objUser->getDescription() ?? "", PDO::PARAM_STR); - - - // 3. Executer la requête - //var_dump($strRq);die; - //return $db->exec($strRq); return $rqPrep->execute(); } + + public function mailExists(string $mail): bool { $rq = $this->_db->prepare("SELECT 1 FROM users WHERE user_mail = :mail LIMIT 1"); @@ -90,4 +87,38 @@ return (bool)$rq->fetchColumn(); } + + /** + * Fonction de changement de status d'un utilisateur + * @param object $objUser L'objet utilisateur + * @return bool Est-ce que la requête s'est bien passée (true/false) + */ + + public function editStatus(object $objUser):bool{ + + $strRq = "UPDATE users + SET user_status = :status + WHERE user_id = :id"; + + $rqPrep = $this->_db->prepare($strRq); + $rqPrep->bindValue(":id", $objUser->getId(), PDO::PARAM_INT); + $rqPrep->bindValue(":status", $objUser->getStatus(), PDO::PARAM_INT); + return $rqPrep->execute(); + } + + /** + * Fonction permettant de supprimer un utilisateur avec une date de suppression + * @param int $intId L'identifiant de l'utilisateur + * @return bool Est-ce que la requête s'est bien passée (true/false) + */ + public function delete_soft(int $intId):bool{ + + $strRq = "UPDATE users + SET user_deleted_at = NOW() + WHERE user_id = :id"; + + $rqPrep = $this->_db->prepare($strRq); + $rqPrep->bindValue(":id", $intId, PDO::PARAM_INT); + return $rqPrep->execute(); + } } diff --git a/templates_c/5375cd75c92fd8c801b429efee0d6437582d377e_0.file_login.tpl.php b/templates_c/5375cd75c92fd8c801b429efee0d6437582d377e_0.file_login.tpl.php index c008541..272b1ad 100644 --- a/templates_c/5375cd75c92fd8c801b429efee0d6437582d377e_0.file_login.tpl.php +++ b/templates_c/5375cd75c92fd8c801b429efee0d6437582d377e_0.file_login.tpl.php @@ -1,11 +1,11 @@ getCompiled()->isFresh($_smarty_tpl, array ( 'version' => '5.7.0', - 'unifunc' => 'content_6989df814ecac5_82975272', + 'unifunc' => 'content_6989f5152cc653_86103445', 'has_nocache_code' => false, 'file_dependency' => array ( @@ -20,18 +20,18 @@ if ($_smarty_tpl->getCompiled()->isFresh($_smarty_tpl, array ( array ( ), ))) { -function content_6989df814ecac5_82975272 (\Smarty\Template $_smarty_tpl) { +function content_6989f5152cc653_86103445 (\Smarty\Template $_smarty_tpl) { $_smarty_current_dir = 'C:\\wamp64\\www\\DWWM_2025\\projet2\\views'; $_smarty_tpl->getInheritance()->init($_smarty_tpl, true); ?> getInheritance()->instanceBlock($_smarty_tpl, 'Block_10819558166989df814817a5_66837906', "content"); +$_smarty_tpl->getInheritance()->instanceBlock($_smarty_tpl, 'Block_15010700106989f5152c2920_08155243', "content"); $_smarty_tpl->getInheritance()->endChild($_smarty_tpl, "views/layout.tpl", $_smarty_current_dir); } /* {block "content"} */ -class Block_10819558166989df814817a5_66837906 extends \Smarty\Runtime\Block +class Block_15010700106989f5152c2920_08155243 extends \Smarty\Runtime\Block { public function callBlock(\Smarty\Template $_smarty_tpl) { $_smarty_current_dir = 'C:\\wamp64\\www\\DWWM_2025\\projet2\\views'; diff --git a/templates_c/947d9aa54bf412a952e2af2d8a8255035d91b950_0.file_layout.tpl.php b/templates_c/947d9aa54bf412a952e2af2d8a8255035d91b950_0.file_layout.tpl.php index 2f9bc08..00e05e0 100644 --- a/templates_c/947d9aa54bf412a952e2af2d8a8255035d91b950_0.file_layout.tpl.php +++ b/templates_c/947d9aa54bf412a952e2af2d8a8255035d91b950_0.file_layout.tpl.php @@ -1,11 +1,11 @@ getCompiled()->isFresh($_smarty_tpl, array ( 'version' => '5.7.0', - 'unifunc' => 'content_6989e0891f99a9_84268185', + 'unifunc' => 'content_6989f7051730f9_04925440', 'has_nocache_code' => false, 'file_dependency' => array ( @@ -22,21 +22,21 @@ if ($_smarty_tpl->getCompiled()->isFresh($_smarty_tpl, array ( 'file:views/_partial/footer.tpl' => 1, ), ))) { -function content_6989e0891f99a9_84268185 (\Smarty\Template $_smarty_tpl) { +function content_6989f7051730f9_04925440 (\Smarty\Template $_smarty_tpl) { $_smarty_current_dir = 'C:\\wamp64\\www\\DWWM_2025\\projet2\\views'; $_smarty_tpl->getInheritance()->init($_smarty_tpl, false); $_smarty_tpl->renderSubTemplate("file:views/_partial/header.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, $_smarty_tpl->cache_lifetime, array(), (int) 0, $_smarty_current_dir); ?> getInheritance()->instanceBlock($_smarty_tpl, 'Block_1226719426989e0891f66b5_10703637', "content"); +$_smarty_tpl->getInheritance()->instanceBlock($_smarty_tpl, 'Block_15212756776989f70516f3e1_13586621', "content"); ?> renderSubTemplate("file:views/_partial/footer.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, $_smarty_tpl->cache_lifetime, array(), (int) 0, $_smarty_current_dir); } /* {block "content"} */ -class Block_1226719426989e0891f66b5_10703637 extends \Smarty\Runtime\Block +class Block_15212756776989f70516f3e1_13586621 extends \Smarty\Runtime\Block { public function callBlock(\Smarty\Template $_smarty_tpl) { $_smarty_current_dir = 'C:\\wamp64\\www\\DWWM_2025\\projet2\\views'; diff --git a/templates_c/ac77f39f91cdf26a0eb3f0963ead4008a7bda8fb_0.file_admin.tpl.php b/templates_c/ac77f39f91cdf26a0eb3f0963ead4008a7bda8fb_0.file_admin.tpl.php index d200d8c..515379e 100644 --- a/templates_c/ac77f39f91cdf26a0eb3f0963ead4008a7bda8fb_0.file_admin.tpl.php +++ b/templates_c/ac77f39f91cdf26a0eb3f0963ead4008a7bda8fb_0.file_admin.tpl.php @@ -1,18 +1,18 @@ getCompiled()->isFresh($_smarty_tpl, array ( 'version' => '5.7.0', - 'unifunc' => 'content_6989e088f38338_64666135', + 'unifunc' => 'content_6989f704df71e4_04792390', 'has_nocache_code' => false, 'file_dependency' => array ( 'ac77f39f91cdf26a0eb3f0963ead4008a7bda8fb' => array ( 0 => 'views/admin.tpl', - 1 => 1770643565, + 1 => 1770649348, 2 => 'file', ), ), @@ -20,18 +20,18 @@ if ($_smarty_tpl->getCompiled()->isFresh($_smarty_tpl, array ( array ( ), ))) { -function content_6989e088f38338_64666135 (\Smarty\Template $_smarty_tpl) { +function content_6989f704df71e4_04792390 (\Smarty\Template $_smarty_tpl) { $_smarty_current_dir = 'C:\\wamp64\\www\\DWWM_2025\\projet2\\views'; $_smarty_tpl->getInheritance()->init($_smarty_tpl, true); ?> getInheritance()->instanceBlock($_smarty_tpl, 'Block_19184882506989e088f2e080_15773704', "content"); +$_smarty_tpl->getInheritance()->instanceBlock($_smarty_tpl, 'Block_3881550706989f704ddce33_55904583', "content"); $_smarty_tpl->getInheritance()->endChild($_smarty_tpl, "views/layout.tpl", $_smarty_current_dir); } /* {block "content"} */ -class Block_19184882506989e088f2e080_15773704 extends \Smarty\Runtime\Block +class Block_3881550706989f704ddce33_55904583 extends \Smarty\Runtime\Block { public function callBlock(\Smarty\Template $_smarty_tpl) { $_smarty_current_dir = 'C:\\wamp64\\www\\DWWM_2025\\projet2\\views'; @@ -124,29 +124,48 @@ $_smarty_current_dir = 'C:\\wamp64\\www\\DWWM_2025\\projet2\\views';
-
+
-
- + + getSmarty()->getRuntime('Foreach')->init($_smarty_tpl, $_smarty_tpl->getValue('arrUserToDisplay'), 'user'); $foreach0DoElse = true; -foreach ($_from ?? [] as $_smarty_tpl->getVariable('arrDetStatus')->value) { +foreach ($_from ?? [] as $_smarty_tpl->getVariable('user')->value) { $foreach0DoElse = false; ?> - - getSmarty()->getRuntime('Foreach')->restore($_smarty_tpl, 1);?> - -
-
- -
+ + +
+
+ + +
+
@@ -160,9 +179,9 @@ $_smarty_tpl->getSmarty()->getRuntime('Foreach')->restore($_smarty_tpl, 1);?> getSmarty()->getRuntime('Foreach')->init($_smarty_tpl, $_smarty_tpl->getValue('arrCategoryToDisplay'), 'category'); -$foreach1DoElse = true; +$foreach2DoElse = true; foreach ($_from ?? [] as $_smarty_tpl->getVariable('category')->value) { -$foreach1DoElse = false; +$foreach2DoElse = false; ?>