edit user

This commit is contained in:
Yasder5 2026-02-19 20:33:24 +01:00
parent 216de9c8df
commit 09ec39c7bb
11 changed files with 293 additions and 68 deletions

View file

@ -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");
}
}

View file

@ -9,7 +9,6 @@
$strCtrl = $_GET['ctrl']??'project';
$strMethod = $_GET['action']??'home';
$intId = $_GET['id']??null;
$boolError = false;
$strFileName = "./controllers/".$strCtrl."_controller.php";

View file

@ -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

View file

@ -1,18 +1,18 @@
<?php
/* Smarty version 5.7.0, created on 2026-02-14 17:35:37
/* Smarty version 5.7.0, created on 2026-02-19 18:00:36
from 'file:views/home.tpl' */
/* @var \Smarty\Template $_smarty_tpl */
if ($_smarty_tpl->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);
?>
<?php
$_smarty_tpl->getInheritance()->instanceBlock($_smarty_tpl, 'Block_11076089026990b269cc7970_84790211', "content");
$_smarty_tpl->getInheritance()->instanceBlock($_smarty_tpl, 'Block_147623784469974fc48fc6e0_21060000', "content");
?>
<?php $_smarty_tpl->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';

View file

@ -1,18 +1,18 @@
<?php
/* Smarty version 5.7.0, created on 2026-02-14 17:35:40
/* Smarty version 5.7.0, created on 2026-02-19 18:00:38
from 'file:views/layout.tpl' */
/* @var \Smarty\Template $_smarty_tpl */
if ($_smarty_tpl->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);
?>
<?php
$_smarty_tpl->getInheritance()->instanceBlock($_smarty_tpl, 'Block_2132004286990b26c1e59d6_94176803', "content");
$_smarty_tpl->getInheritance()->instanceBlock($_smarty_tpl, 'Block_49941558469974fc6b5c4e0_48832484', "content");
?>
<?php $_smarty_tpl->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';

View file

@ -1,18 +1,18 @@
<?php
/* Smarty version 5.7.0, created on 2026-02-14 17:35:40
/* Smarty version 5.7.0, created on 2026-02-19 18:00:38
from 'file:views/_partial/footer.tpl' */
/* @var \Smarty\Template $_smarty_tpl */
if ($_smarty_tpl->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';
?>
<footer class="footer container-fluid d-flex justify-content-around mt-auto">

View file

@ -1,18 +1,18 @@
<?php
/* Smarty version 5.7.0, created on 2026-02-14 17:35:40
/* Smarty version 5.7.0, created on 2026-02-19 18:00:38
from 'file:views/_partial/preview.tpl' */
/* @var \Smarty\Template $_smarty_tpl */
if ($_smarty_tpl->getCompiled()->isFresh($_smarty_tpl, array (
'version' => '5.7.0',
'unifunc' => 'content_6990b26c2fd501_13041464',
'unifunc' => 'content_69974fc6d37d90_86084313',
'has_nocache_code' => false,
'file_dependency' =>
array (
'67e1ae3a210fc2d1bf8782993687bad91a1cf0f6' =>
array (
0 => 'views/_partial/preview.tpl',
1 => 1771011101,
1 => 1771519241,
2 => 'file',
),
),
@ -20,7 +20,7 @@ if ($_smarty_tpl->getCompiled()->isFresh($_smarty_tpl, array (
array (
),
))) {
function content_6990b26c2fd501_13041464 (\Smarty\Template $_smarty_tpl) {
function content_69974fc6d37d90_86084313 (\Smarty\Template $_smarty_tpl) {
$_smarty_current_dir = 'D:\\projetphp\\views\\_partial';
?><article class="col-md-3 mb-5 <?php if ((true && (true && null !== ($_SESSION['user'] ?? null))) && $_SESSION['user']['user_status'] == 2) {?> pb-5 <?php }?>" style="border-radius: 100px ;">
<div class="card h-100 shadow article-card rounded-4" style="border-width: 2px; overflow: hidden;">

View file

@ -1,18 +1,18 @@
<?php
/* Smarty version 5.7.0, created on 2026-02-14 17:35:40
/* Smarty version 5.7.0, created on 2026-02-19 17:49:46
from 'file:views/search.tpl' */
/* @var \Smarty\Template $_smarty_tpl */
if ($_smarty_tpl->getCompiled()->isFresh($_smarty_tpl, array (
'version' => '5.7.0',
'unifunc' => 'content_6990b26c035cd6_15007530',
'unifunc' => 'content_69974d3a2fa051_88043479',
'has_nocache_code' => false,
'file_dependency' =>
array (
'72e5e5c0ee2729980deadb1687a6d7b7b3c501bb' =>
array (
0 => 'views/search.tpl',
1 => 1770649781,
1 => 1771519241,
2 => 'file',
),
),
@ -21,18 +21,18 @@ if ($_smarty_tpl->getCompiled()->isFresh($_smarty_tpl, array (
'file:views/_partial/preview.tpl' => 1,
),
))) {
function content_6990b26c035cd6_15007530 (\Smarty\Template $_smarty_tpl) {
function content_69974d3a2fa051_88043479 (\Smarty\Template $_smarty_tpl) {
$_smarty_current_dir = 'D:\\projetphp\\views';
$_smarty_tpl->getInheritance()->init($_smarty_tpl, true);
?>
<?php
$_smarty_tpl->getInheritance()->instanceBlock($_smarty_tpl, 'Block_19164984906990b26c022a65_59433489', "content");
$_smarty_tpl->getInheritance()->instanceBlock($_smarty_tpl, 'Block_129547300169974d3a2e7e19_65257480', "content");
$_smarty_tpl->getInheritance()->endChild($_smarty_tpl, "views/layout.tpl", $_smarty_current_dir);
}
/* {block "content"} */
class Block_19164984906990b26c022a65_59433489 extends \Smarty\Runtime\Block
class Block_129547300169974d3a2e7e19_65257480 extends \Smarty\Runtime\Block
{
public function callBlock(\Smarty\Template $_smarty_tpl) {
$_smarty_current_dir = 'D:\\projetphp\\views';
@ -57,7 +57,7 @@ $_smarty_current_dir = 'D:\\projetphp\\views';
class="form-control"
id="keywords"
name="keywords"
placeholder="Ex: JavaScript, CSS..."
placeholder="Design, IA, back-end"
aria-describedby="keywords-help">
<small id="keywords-help" class="form-text text-muted">
Recherchez dans les titres et contenus
@ -91,7 +91,7 @@ $_smarty_tpl->getSmarty()->getRuntime('Foreach')->restore($_smarty_tpl, 1);?>
<div class="col-6">
<fieldset>
<legend class="form-label">Type de recherche par date</legend>
<legend class="form-label">Recherche par date</legend>
<div class="form-check form-check-inline">
<input
class="form-check-input"
@ -123,7 +123,7 @@ $_smarty_tpl->getSmarty()->getRuntime('Foreach')->restore($_smarty_tpl, 1);?>
<!-- AJOUT RECHERCHE PAR CATEGORIE -->
<div class="col-6">
<fieldset>
<legend class="form-label">Type de recherche par catégories</legend>
<legend class="form-label">Recherche par catégories</legend>
<div class="col-md-6">
<label for="author" class="form-label">Catégorie</label>
<select class="form-select" id="category" name="category">
@ -194,10 +194,10 @@ $_smarty_tpl->getSmarty()->getRuntime('Foreach')->restore($_smarty_tpl, 1);?>
<i class="fas fa-search me-2" aria-hidden="true"></i>
Rechercher
</button>
<button type="reset" class="btn btn-secondary ms-2">
<a href="index.php?ctrl=project&action=search" class="btn btn-secondary ms-2">
<i class="fas fa-redo me-2" aria-hidden="true"></i>
Réinitialiser
</button>
</a>
</div>
</div>
</form>

View file

@ -1,26 +1,27 @@
<?php
/* Smarty version 5.7.0, created on 2026-02-14 17:35:40
/* Smarty version 5.7.0, created on 2026-02-19 18:00:38
from 'file:views/_partial/header.tpl' */
/* @var \Smarty\Template $_smarty_tpl */
if ($_smarty_tpl->getCompiled()->isFresh($_smarty_tpl, array (
'version' => '5.7.0',
'unifunc' => 'content_6990b26c2637b7_83238687',
'unifunc' => 'content_69974fc6bd10a6_20132978',
'has_nocache_code' => false,
'file_dependency' =>
array (
'8056b95e7f6b28be5e36947735d13c8d176ec944' =>
array (
0 => 'views/_partial/header.tpl',
1 => 1771090171,
1 => 1771520240,
2 => 'file',
),
),
'includes' =>
array (
'file:views/_partial/messages.tpl' => 1,
),
))) {
function content_6990b26c2637b7_83238687 (\Smarty\Template $_smarty_tpl) {
function content_69974fc6bd10a6_20132978 (\Smarty\Template $_smarty_tpl) {
$_smarty_current_dir = 'D:\\projetphp\\views\\_partial';
?><!DOCTYPE html>
<html lang="fr">
@ -96,7 +97,7 @@ $_smarty_current_dir = 'D:\\projetphp\\views\\_partial';
<li class="nav-item">
<a class="nav-link" href="index.php?ctrl=user&action=logout" title="Se déconnecter" aria-label="Se déconnecter">
Logout
Se déconnecter
</a>
</li>
</ul>
@ -105,7 +106,6 @@ $_smarty_current_dir = 'D:\\projetphp\\views\\_partial';
</div>
</div>
</nav>
</body>
</html>
<?php }
<?php $_smarty_tpl->renderSubTemplate("file:views/_partial/messages.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, $_smarty_tpl->cache_lifetime, array(), (int) 0, $_smarty_current_dir);
}
}

View file

@ -84,5 +84,4 @@
</div>
</div>
</nav>
{$success_message|vardump}
{include file="views/_partial/messages.tpl"}

161
views/useredit.tpl Normal file
View file

@ -0,0 +1,161 @@
{extends file="views/layout.tpl"}
{block name="content"}
<!-- Page : Inscription -->
<main class="container py-5">
<!-- Centrage horizontal du formulaire -->
<div class="row justify-content-center position-relative">
<div class="col-12 col-md-10 col-lg-6">
<!-- Carte contenant le formulaire d'inscription -->
<div class="card shadow-sm border-0 rounded-4 p-4 p-lg-5">
<!-- Titre principal de la page -->
<h1 class="h3 fw-bold mb-1">Edit du profile</h1>
{if (isset($arrError) && count($arrError) > 0) }
<div class="alert alert-danger">
{foreach $arrError as $strError}
<p>{$strError}</p>
{/foreach}
</div>
{/if}
<!-- Formulaire d'inscription -->
<!-- Les données seront traitées côté serveur en PHP via la méthode POST -->
<form method="POST">
<div class="row g-3">
<div class="col-md-6">
<label class="form-label" for="user_firstname">
Prénom
</label>
<input
class="form-control"
type="text"
id="user_firstname"
name="user_firstname"
value="{$objUser->getFirstname()}"
>
</div>
<div class="col-md-6">
<label class="form-label" for="user_name">
Nom
</label>
<input
class="form-control"
type="text"
id="user_name"
name="user_name"
value="{$objUser->getName()}"
>
</div>
<div class="col-12">
<label class="form-label" for="user_pseudo">
Pseudo
</label>
<div class="input-group">
<span class="input-group-text">@</span>
<input
class="form-control"
type="text"
id="user_pseudo"
name="user_pseudo"
value="{$objUser->getPseudo()}"
>
</div>
</div>
<div class="col-12">
<label class="form-label" for="user_mail">
Adresse e-mail
</label>
<input
class="form-control"
type="email"
id="user_mail"
name="user_mail"
value="{$objUser->getMail()}"
>
</div>
<div class="col-12">
<label class="form-label" for="user_phone">
Téléphone
</label>
<input
class="form-control"
type="text"
id="user_phone"
name="user_phone"
value="{$objUser->getPhone()}"
>
</div>
<div class="col-12">
<label class="form-label" for="user_work">
Profession
</label>
<input
class="form-control"
type="text"
id="user_work"
name="user_work"
value="{$objUser->getWork()}"
>
</div>
<div class="col-12">
<label class="form-label" for="user_location">
Localisation
</label>
<input
class="form-control"
type="text"
id="user_location"
name="user_location"
value="{$objUser->getLocation()}"
>
</div>
<div class="col-12">
<label class="form-label" for="user_description">
Phrase d'accroche
</label>
<textarea
class="form-control"
id="user_description"
name="user_description"
rows="3"
>
{$objUser->getDescription()}
</textarea>
</div>
<div class="col-12 d-grid mt-2">
<button type="submit" class="btn btn-primary btn-lg rounded-3">
Edit profile
</button>
</div>
</form>
</div>
</div>
</div>
</div>
</main>
{/block}