From 09ec39c7bbd06714770c6ec65dfd532360ccdf2c Mon Sep 17 00:00:00 2001 From: Yasder5 <102179445+Yasder5@users.noreply.github.com> Date: Thu, 19 Feb 2026 20:33:24 +0100 Subject: [PATCH 1/8] edit user --- controllers/user_controller.php | 89 +++++++--- index.php | 1 - models/user_model.php | 31 +++- ...94486bfa02ee91c2c5fe68_0.file_home.tpl.php | 12 +- ...82584009ce981aa35e0b_0.file_layout.tpl.php | 12 +- ...56e3cf6837f9df55d7fb_0.file_footer.tpl.php | 8 +- ...2993687bad91a1cf0f6_0.file_preview.tpl.php | 8 +- ...db1687a6d7b7b3c501bb_0.file_search.tpl.php | 22 +-- ...947735d13c8d176ec944_0.file_header.tpl.php | 16 +- views/_partial/header.tpl | 1 - views/useredit.tpl | 161 ++++++++++++++++++ 11 files changed, 293 insertions(+), 68 deletions(-) create mode 100644 views/useredit.tpl diff --git a/controllers/user_controller.php b/controllers/user_controller.php index 1a3b464..8e185a6 100644 --- a/controllers/user_controller.php +++ b/controllers/user_controller.php @@ -151,37 +151,74 @@ class UserCtrl extends MotherCtrl { */ public function user(){ - $intId = isset($_GET['id']) ? (int)$_GET['id'] : 0; + $intId = isset($_GET['id']) ? (int)$_GET['id'] : 0; - if ($intId <= 0) { - header("Location: index.php"); - exit; - } + if ($intId <= 0) { + header("Location: index.php"); + exit; + } - //affichage info utilisateur - $objUserModel = new UserModel; - $arrUserData = $objUserModel->findUserById($intId); + //affichage info utilisateur + $objUserModel = new UserModel; + $arrUserData = $objUserModel->findUserById($intId); - if ($arrUserData === false) { - header("Location: index.php"); - exit; - } - $objUser = new User; - $objUser->hydrate($arrUserData); + if ($arrUserData === false) { + header("Location: index.php"); + exit; + } + $objUser = new User; + $objUser->hydrate($arrUserData); - //affichage projet de l'utilisateur - $objProjectModel = new ProjectModel; - $arrProjects = $objProjectModel->findAll(0,'',$intId); + //affichage projet de l'utilisateur + $objProjectModel = new ProjectModel; + $arrProjects = $objProjectModel->findAll(0,'',$intId); - $arrProjectToDisplay = array(); - foreach($arrProjects as $projectData) { - $objProject = new Project(); - $objProject->hydrate($projectData); - $arrProjectToDisplay[] = $objProject; - } + $arrProjectToDisplay = array(); + foreach($arrProjects as $projectData) { + $objProject = new Project(); + $objProject->hydrate($projectData); + $arrProjectToDisplay[] = $objProject; + } + + $this->_arrData['user'] = $objUser; + $this->_arrData['arrProjectToDisplay'] = $arrProjectToDisplay; + $this->_display("user"); + } + + public function edit(){ + if(!isset($_SESSION['user'])){ + header("Location: index.php"); + exit; + } + + $objUserModel = new UserModel; + $arrError = []; + $objUser = new User; + $arrUserData = $objUserModel->findUserById($_SESSION['user']['user_id']); + $objUser->hydrate($arrUserData); + if (!empty($_POST)) { + if ($objUserModel->mailExists($objUser->getMail()) && ($_POST['user_mail'] != $objUser->getMail())) { + + $arrError['user_mail'] = "Ce mail est déjà associé"; + } else { + $objUser->hydrate($_POST); + $objUser->setId($_SESSION['user']['user_id']); + $boolInsert = $objUserModel->update($objUser); + + if ($boolInsert === true) { + $_SESSION['success'] = "Compte créé avec succès"; + header("Location:?ctrl=user&action=user&id=".$objUser->getId()); + exit; + } else { + $arrError['global'] = "Erreur lors de l'update"; + } + } + } + + + $this->_arrData["arrError"] = $arrError; + $this->_arrData['objUser'] = $objUser; + $this->_display("useredit"); - $this->_arrData['user'] = $objUser; - $this->_arrData['arrProjectToDisplay'] = $arrProjectToDisplay; - $this->_display("user"); } } diff --git a/index.php b/index.php index 090bef2..ae6424c 100644 --- a/index.php +++ b/index.php @@ -9,7 +9,6 @@ $strCtrl = $_GET['ctrl']??'project'; $strMethod = $_GET['action']??'home'; - $intId = $_GET['id']??null; $boolError = false; $strFileName = "./controllers/".$strCtrl."_controller.php"; diff --git a/models/user_model.php b/models/user_model.php index baa46dd..e229af6 100644 --- a/models/user_model.php +++ b/models/user_model.php @@ -52,7 +52,7 @@ */ public function insert(object $objUser):bool{ - $strRq = "INSERT INTO users (user_name, user_firstname, user_pseudo, user_mail, user_password, user_phone, user_work, user_location, user_description) + $strRq = "INSERT INTO users (user_name, user_firstname, user_pseudo, user_mail, user_password, user_phone, user_work, user_location, user_description) VALUES (:name, :firstname, :pseudo,:mail, :pwd, :phone, :work, :location,:description)"; $rqPrep = $this->_db->prepare($strRq); @@ -70,6 +70,35 @@ return $rqPrep->execute(); } + public function update(object $objUser):bool{ + $strRq = "UPDATE users SET + user_name = :name, + user_firstname = :firstname, + user_pseudo = :pseudo, + user_mail = :mail, + user_phone = :phone, + user_work = :work, + user_location = :location, + user_description = :description + WHERE user_id = :id"; + + + $rqPrep = $this->_db->prepare($strRq); + + $rqPrep->bindValue(":id", $objUser->getId(), PDO::PARAM_INT); + $rqPrep->bindValue(":name", $objUser->getName(), PDO::PARAM_STR); + $rqPrep->bindValue(":firstname", $objUser->getFirstname(), PDO::PARAM_STR); + $rqPrep->bindValue(":pseudo", $objUser->getPseudo(), PDO::PARAM_STR); + $rqPrep->bindValue(":mail", $objUser->getMail(), PDO::PARAM_STR); + $rqPrep->bindValue(':phone', $objUser->getPhone() ?? "", PDO::PARAM_STR); + $rqPrep->bindValue(':work', $objUser->getWork() ?? "", PDO::PARAM_STR); + $rqPrep->bindValue(':location', $objUser->getLocation() ?? "", PDO::PARAM_STR); + $rqPrep->bindValue(':description', $objUser->getDescription() ?? "", PDO::PARAM_STR); + + return $rqPrep->execute(); + + } + /** * Fonction de vérification de mail * @param string $mail diff --git a/templates_c/0f54e8b5c9bcafd01d94486bfa02ee91c2c5fe68_0.file_home.tpl.php b/templates_c/0f54e8b5c9bcafd01d94486bfa02ee91c2c5fe68_0.file_home.tpl.php index 55fa0ec..e911eb8 100644 --- a/templates_c/0f54e8b5c9bcafd01d94486bfa02ee91c2c5fe68_0.file_home.tpl.php +++ b/templates_c/0f54e8b5c9bcafd01d94486bfa02ee91c2c5fe68_0.file_home.tpl.php @@ -1,18 +1,18 @@ getCompiled()->isFresh($_smarty_tpl, array ( 'version' => '5.7.0', - 'unifunc' => 'content_6990b269ccba39_37501247', + 'unifunc' => 'content_69974fc49008e7_88350972', 'has_nocache_code' => false, 'file_dependency' => array ( '0f54e8b5c9bcafd01d94486bfa02ee91c2c5fe68' => array ( 0 => 'views/home.tpl', - 1 => 1771010187, + 1 => 1771519241, 2 => 'file', ), ), @@ -21,20 +21,20 @@ if ($_smarty_tpl->getCompiled()->isFresh($_smarty_tpl, array ( 'file:views/_partial/preview.tpl' => 1, ), ))) { -function content_6990b269ccba39_37501247 (\Smarty\Template $_smarty_tpl) { +function content_69974fc49008e7_88350972 (\Smarty\Template $_smarty_tpl) { $_smarty_current_dir = 'D:\\projetphp\\views'; $_smarty_tpl->getInheritance()->init($_smarty_tpl, true); ?> getInheritance()->instanceBlock($_smarty_tpl, 'Block_11076089026990b269cc7970_84790211', "content"); +$_smarty_tpl->getInheritance()->instanceBlock($_smarty_tpl, 'Block_147623784469974fc48fc6e0_21060000', "content"); ?> getInheritance()->endChild($_smarty_tpl, "views/layout.tpl", $_smarty_current_dir); } /* {block "content"} */ -class Block_11076089026990b269cc7970_84790211 extends \Smarty\Runtime\Block +class Block_147623784469974fc48fc6e0_21060000 extends \Smarty\Runtime\Block { public function callBlock(\Smarty\Template $_smarty_tpl) { $_smarty_current_dir = 'D:\\projetphp\\views'; diff --git a/templates_c/1c51ad9f5c349145220f82584009ce981aa35e0b_0.file_layout.tpl.php b/templates_c/1c51ad9f5c349145220f82584009ce981aa35e0b_0.file_layout.tpl.php index b72d93d..e69245a 100644 --- a/templates_c/1c51ad9f5c349145220f82584009ce981aa35e0b_0.file_layout.tpl.php +++ b/templates_c/1c51ad9f5c349145220f82584009ce981aa35e0b_0.file_layout.tpl.php @@ -1,18 +1,18 @@ getCompiled()->isFresh($_smarty_tpl, array ( 'version' => '5.7.0', - 'unifunc' => 'content_6990b26c1e79e7_73815255', + 'unifunc' => 'content_69974fc6b5dc95_68713473', 'has_nocache_code' => false, 'file_dependency' => array ( '1c51ad9f5c349145220f82584009ce981aa35e0b' => array ( 0 => 'views/layout.tpl', - 1 => 1770649781, + 1 => 1771520226, 2 => 'file', ), ), @@ -22,21 +22,21 @@ if ($_smarty_tpl->getCompiled()->isFresh($_smarty_tpl, array ( 'file:views/_partial/footer.tpl' => 1, ), ))) { -function content_6990b26c1e79e7_73815255 (\Smarty\Template $_smarty_tpl) { +function content_69974fc6b5dc95_68713473 (\Smarty\Template $_smarty_tpl) { $_smarty_current_dir = 'D:\\projetphp\\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_2132004286990b26c1e59d6_94176803', "content"); +$_smarty_tpl->getInheritance()->instanceBlock($_smarty_tpl, 'Block_49941558469974fc6b5c4e0_48832484', "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_2132004286990b26c1e59d6_94176803 extends \Smarty\Runtime\Block +class Block_49941558469974fc6b5c4e0_48832484 extends \Smarty\Runtime\Block { public function callBlock(\Smarty\Template $_smarty_tpl) { $_smarty_current_dir = 'D:\\projetphp\\views'; diff --git a/templates_c/264314e384c04e79c5fa56e3cf6837f9df55d7fb_0.file_footer.tpl.php b/templates_c/264314e384c04e79c5fa56e3cf6837f9df55d7fb_0.file_footer.tpl.php index b5d14ba..13bb54e 100644 --- a/templates_c/264314e384c04e79c5fa56e3cf6837f9df55d7fb_0.file_footer.tpl.php +++ b/templates_c/264314e384c04e79c5fa56e3cf6837f9df55d7fb_0.file_footer.tpl.php @@ -1,18 +1,18 @@ getCompiled()->isFresh($_smarty_tpl, array ( 'version' => '5.7.0', - 'unifunc' => 'content_6990b26c437982_38235756', + 'unifunc' => 'content_69974fc6e880f1_33985729', 'has_nocache_code' => false, 'file_dependency' => array ( '264314e384c04e79c5fa56e3cf6837f9df55d7fb' => array ( 0 => 'views/_partial/footer.tpl', - 1 => 1771090184, + 1 => 1771519241, 2 => 'file', ), ), @@ -20,7 +20,7 @@ if ($_smarty_tpl->getCompiled()->isFresh($_smarty_tpl, array ( array ( ), ))) { -function content_6990b26c437982_38235756 (\Smarty\Template $_smarty_tpl) { +function content_69974fc6e880f1_33985729 (\Smarty\Template $_smarty_tpl) { $_smarty_current_dir = 'D:\\projetphp\\views\\_partial'; ?>