diff --git a/app/controllers/project_controller.php b/app/controllers/project_controller.php index 422fb58..dd455fa 100644 --- a/app/controllers/project_controller.php +++ b/app/controllers/project_controller.php @@ -3,6 +3,8 @@ require("../app/entities/project_entity.php"); require("../app/models/category_model.php"); require("../app/entities/category_entity.php"); + require("../app/models/image_model.php"); + require("../app/entities/image_entity.php"); /** * Le controler des Project @@ -37,23 +39,24 @@ public function search(){ + //variable pour faire fonctionner le script en footer + $strPage = "search"; + // inclusion du header include('../app/views/partials/header.php'); //Récupérer les informations du Formulaire - $strKeywords = $_GET['keywords']??''; - $intAuthor = $_GET['author']??0; - $intPeriod = $_GET['period']??0; - $strDate = $_GET['date']??''; - $strStartDate = $_GET['startdate']??''; - $strEndDate = $_GET['enddate']??''; - $intCategory = $_GET['category']??0; - - // Récupération des Projects + $strKeywords = $_POST['keywords']??''; + $intAuthor = $_POST['author']??0; + $intPeriod = $_POST['period']??0; + $strDate = $_POST['date']??''; + $strStartDate = $_POST['startdate']??''; + $strEndDate = $_POST['enddate']??''; + $intCategory = $_POST['category']??0; + // Récupération des projetc $objProjectModel = new ProjectModel; - - // Depuis PHP 8 - accès direct aux paramètres - $arrProject = $objProjectModel->findAll(); + $arrProject = $objProjectModel->findAll(intAuthor:$intAuthor, intPeriod:$intPeriod, strDate:$strDate, + strKeywords:$strKeywords, strStartDate:$strStartDate, strEndDate:$strEndDate, intCategory:$intCategory); // Initialisation d'un tableau => objets $arrProjectToDisplay = array(); @@ -84,9 +87,30 @@ * Fonction d'affichage de la page projet */ + public function project (){ + + $objProjectModel = new ProjectModel; + $arrProject = $objProjectModel->findAll(4); + $arrProjectToDiplay = array(); + foreach($arrProject as $arrDetProject){ + $objProject = new Project; + $objProject->hydrate($arrDetProject); + $arrProjectToDiplay[] = $objProject; + } + + $objImageModel = new ImageModel; + $arrImage = $objImageModel->findAllImage(4); + $arrImageToDiplay = array(); + foreach($arrImage as $arrDetImage){ + $objImage = new Image; + $objImage->hydrate($arrDetImage); + $arrImageToDiplay[] = $objImage; + } + include("../app/views/partials/header.php"); include('../app/views/project.php'); include('../app/views/partials/footer.php'); + } } \ No newline at end of file diff --git a/app/controllers/user_controller.php b/app/controllers/user_controller.php index f612a4a..ae38767 100644 --- a/app/controllers/user_controller.php +++ b/app/controllers/user_controller.php @@ -43,19 +43,105 @@ class UserCtrl{ include("../app/views/login.php"); include("../app/views/partials/footer.php"); - } + } public function logout(){ - session_start(); - - // on supprime l'utilisateur en session - unset($_SESSION['user']); - - $_SESSION['success'] = "Vous êtes bien déconnecté"; - - header("Location:index.php"); - exit; + session_start(); + /*session_destroy(); + session_start();*/ + + // on supprime l'utilisateur en session + unset($_SESSION['user']); + + $_SESSION['success'] = "Vous êtes bien déconnecté"; + + header("Location:index.php"); + exit; } - } \ No newline at end of file + + public function signin(){ + + // Inclusion du header + include("../app/views/partials/header.php"); + + // Entité pour réafficher les valeurs dans le formulaire + $objUser = new User(); + + // Récupération des champs + $strPwdConfirm = $_POST['pwd_confirm'] ?? ""; + + // Tableau d'erreurs + $arrError = []; + + // Traitement du formulaire uniquement si POST + if (!empty($_POST)) { + + // Hydratation + $objUser->setName($_POST['user_name'] ?? ""); + $objUser->setFirstname($_POST['user_firstname'] ?? ""); + $objUser->setMail($_POST['user_mail'] ?? ""); + $objUser->setPseudo($_POST['user_pseudo'] ?? ""); + $objUser->setPwd($_POST['user_password'] ?? ""); + + // Champs optionnels : on les stocke aussi même si ils sont vides + $objUser->setPhone($_POST['user_phone'] ?? ""); + $objUser->setWork($_POST['user_work'] ?? ""); + $objUser->setLocation($_POST['user_location'] ?? ""); + $objUser->setDescription($_POST['user_description'] ?? ""); + + + // --- VALIDATIONS (obligatoires) --- + if (trim($objUser->getName()) === "") { + $arrError['user_name'] = "Le nom est obligatoire"; + } + + if (trim($objUser->getFirstname()) === "") { + $arrError['user_firstname'] = "Le prénom est obligatoire"; + } + + if (trim($objUser->getMail()) === "") { + $arrError['user_mail'] = "Le mail est obligatoire"; + } elseif (!filter_var($objUser->getMail(), FILTER_VALIDATE_EMAIL)) { + $arrError['user_mail'] = "Le format du mail n'est pas correct"; + } + + if (trim($objUser->getPseudo()) === "") { + $arrError['user_pseudo'] = "Le pseudo est obligatoire"; + } + + $strRegex = "/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{16,}$/"; + if ($objUser->getPwd() == ""){ + $arrError['user_password'] = "Le mot de passe est obligatoire"; + }else if (!preg_match($strRegex, $objUser->getPwd())){ + $arrError['user_password'] = "Le mot de passe ne correspond pas aux règles"; + }else if($objUser->getPwd() != $strPwdConfirm){ + $arrError['pwd_confirm'] = "Le mot de passe et sa confirmation ne sont pas identiques"; + } + + + // Si pas d'erreurs => insertion + if (count($arrError) === 0) { + $objUserModel = new UserModel(); + $boolInsert = $objUserModel->insert($objUser); + + if ($boolInsert === true) { + $_SESSION['success'] = "Compte créé avec succès"; + header("Location:index.php?ctrl=user&action=login"); + exit; + } else { + // Erreur globale (pas liée à un champ) + $arrError['global'] = "Erreur lors de l'ajout"; + } + } + } + + // Affichage de la vue inscription + include("../app/views/inscription.php"); + include("../app/views/partials/footer.php"); + } + + + +} diff --git a/app/entities/category_entity.php b/app/entities/category_entity.php index eecebdc..72ac739 100644 --- a/app/entities/category_entity.php +++ b/app/entities/category_entity.php @@ -1,5 +1,7 @@ _prefix = 'image_'; + } + + // Méthode Getter et Setter + + /** + * Récuperation de l'id de l'image + * @return int l'id de l'image + */ + public function getId():int{ + return $this->_id; + } + + /** + * Mise à jour de l'id de l'image + * @param int le nouvelle id + */ + public function setId($id){ + $this->_id = $id; + } + + /** + * Récuperation du nom de l'image + * @return string nom de l'image + */ + public function getName(){ + return $this->_name; + } + + /** + * Mise à jour du nom de l'image + * @param string le nouveau nom de l'image + */ + public function setName($name){ + $this->_name = $name; + } + + /** + * Récuperation de l'alt + * @return string contenu de l'alt + */ + public function getAlt(){ + return $this->_alt; + } + + /** + * Mise à jour de l'alt + * @param string le nouveau contenu de l'alt + */ + public function setAlt($alt){ + $this->_alt = $alt; + } + + /** + * Récuperation du statut de la photo + * @return string du statut + */ + public function getStatus(){ + return $this->_status; + } + + /** + * Mise à jour du statut de la photo + * @param string le nouveau statut de la photo + */ + public function setStatus($status){ + $this->_status = $status; + } + + } \ No newline at end of file diff --git a/app/entities/mother_entity.php b/app/entities/mother_entity.php index 5f18ab3..992fb89 100644 --- a/app/entities/mother_entity.php +++ b/app/entities/mother_entity.php @@ -1,8 +1,8 @@ $value){ $strMethodName = "set".ucfirst(str_replace($this->_prefix,'',$key)); - var_dump($strMethodName); if (method_exists($this,$strMethodName)){ $this->$strMethodName($value); } diff --git a/app/entities/project_entity.php b/app/entities/project_entity.php index c4dc9ef..ab9047e 100644 --- a/app/entities/project_entity.php +++ b/app/entities/project_entity.php @@ -1,6 +1,5 @@ _prefix = 'user_'; + } + + public function getId():int{ + return $this->_id; + } + public function setId(int $id){ + $this->_id = $id; + } + + public function getName():string{ + return $this->_name; + } + public function setName(string $name){ + $this->_name = $name; + } + + public function getFirstname():string{ + return $this->_firstname; + } + public function setFirstname(string $firstname){ + $this->_firstname = $firstname; + } + + public function getPseudo():string{ + return $this->_pseudo; + } + public function setPseudo(string $pseudo){ + $this->_pseudo = $pseudo; + } + + public function getImage():string{ + return $this->_image; + } + public function setImage(string $image){ + $this->_image = $image; + } + + public function getMail():string{ + return $this->_mail; + } + public function setMail(string $mail){ + $this->_mail = strtolower($mail); + } + + public function getPwd():string{ + return $this->_pwd; + } + public function getPwdHash():string{ + return password_hash($this->_pwd, PASSWORD_DEFAULT); + } + public function setPwd(string $pwd){ + $this->_pwd = $pwd; + } + + public function getPhone():string{ + return $this->_phone; + } + public function setPhone(string $phone){ + $this->_phone = $phone; + } + + public function getWork():string{ + return $this->_work; + } + public function setWork(string $work){ + $this->_work = $work; + } + + public function getBirth():string{ + return $this->_birth; + } + public function setBirth(string $birth){ + $this->_birth = $birth; + } + + public function getLocation():string{ + return $this->_location; + } + public function setLocation(string $location){ + $this->_location = $location; + } + + public function getDescription():string{ + return $this->_description; + } + public function setDescription(string $description){ + $this->_description = $description; + } + + public function getAccountCreation():string{ + return $this->_account_creation; + } + public function setAccountCreation(string $account_creation){ + $this->_account_creation = $account_creation; + } + + public function getStatus():int{ + return $this->_status; + } + public function setStatus(int $status){ + $this->_status = $status; + } + } diff --git a/app/models/category_model.php b/app/models/category_model.php index aa13516..4aa3e6c 100644 --- a/app/models/category_model.php +++ b/app/models/category_model.php @@ -1,10 +1,10 @@ 0){ + $strRq .= " LIMIT ".$intLimit; + } + + // Lancer la requête et récupérer les résultats + return $this->_db->query($strRq)->fetchAll(); + } + } \ No newline at end of file diff --git a/app/models/project_model.php b/app/models/project_model.php index 2cb9cbf..eff801b 100644 --- a/app/models/project_model.php +++ b/app/models/project_model.php @@ -1,9 +1,16 @@ 0){ + $strRq .= $strWhere." user_id = ".$intAuthor; + $strWhere = " AND "; + } + + // Recherche par catégorie + if ($intCategory > 0){ + $strRq .= $strWhere." project_category = ".$intCategory; + $strWhere = " AND "; + } + + // Recherche par dates + if ($intPeriod == 0){ + // Par date exacte + if ($strDate != ''){ + $strRq .= $strWhere." project_creation_date = '".$strDate."'"; + } + }else{ + // Par période de dates + if ($strStartDate != '' && $strEndDate != ''){ + $strRq .= $strWhere." project_creation_date BETWEEN '".$strStartDate."' AND '".$strEndDate."'"; + }else{ + if ($strStartDate != ''){ + // A partir de + $strRq .= $strWhere." project_creation_date >= '".$strStartDate."'"; + }else if ($strEndDate != ''){ + // Avant le + $strRq .= $strWhere." project_creation_date <= '".$strEndDate."'"; + } + } + } + + $strRq .= " ORDER BY project_creation_date DESC"; + + if ($intLimit > 0){ $strRq .= " LIMIT ".$intLimit; } diff --git a/app/models/user_model.php b/app/models/user_model.php index 73a5d34..706931b 100644 --- a/app/models/user_model.php +++ b/app/models/user_model.php @@ -3,7 +3,7 @@ /** * Traitement des requêtes pour les utilisateurs - * @author : Christel + * @author : meilleurGroup * @version : V0.5 */ class UserModel extends Connect{ @@ -58,17 +58,31 @@ public function insert(object $objUser):bool{ // 2. Construire la requête - $strRq = "INSERT INTO users (user_name, user_firstname, user_mail, user_pwd) - VALUES (:name, :firstname, :mail, :pwd)"; + /*$strRq = "INSERT INTO users (user_name, user_firstname, user_mail, user_pwd) + VALUES ('".$objUser->getName()."', + '".$objUser->getFirstname()."', + '".$objUser->getMail()."', + '".$objUser->getPwdHash()."')";*/ + $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)"; // Préparer la requête $rqPrep = $this->_db->prepare($strRq); // Donne les informations $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(":pwd", $objUser->getPwdHash(), 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); + + // 3. Executer la requête + //var_dump($strRq);die; + //return $db->exec($strRq); return $rqPrep->execute(); } - } \ No newline at end of file + } diff --git a/app/views/connexion.php b/app/views/connexion.php index 96e2244..acd4908 100644 --- a/app/views/connexion.php +++ b/app/views/connexion.php @@ -1,4 +1,9 @@ + +
+ + +
@@ -95,3 +100,92 @@
+

Connexion

+ +

+ Connectez-vous à votre compte. +

+ + + + + + +
+ +
+ + +
+ + +
+ + +
+ + +
+ + +
+
+ + +
+
+ + +
+ +
+ + +
+ + Pas encore de compte ? + Créer un compte + +
+ + + +
+
+ + + + + + diff --git a/app/views/inscription.php b/app/views/inscription.php index efa1750..0856e2e 100644 --- a/app/views/inscription.php +++ b/app/views/inscription.php @@ -1,4 +1,9 @@ + +
+ + +
@@ -66,6 +71,193 @@ required >
+ +
+ + +

Inscription

+

+ Créez votre compte utilisateur. +

+ + + + + + + +
+ +
+ + +
+ + +
+ + +
+ + +
+ + +
+ +
+ @ + +
+
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + Déjà un compte ? + Se connecter + +
+ + +
+ +
+ +
+
@@ -186,3 +378,5 @@ + +
diff --git a/app/views/partials/footer.php b/app/views/partials/footer.php index 1d2a71c..c380f5b 100644 --- a/app/views/partials/footer.php +++ b/app/views/partials/footer.php @@ -1,5 +1,32 @@ -

coucou c'est le footer

- + \ No newline at end of file diff --git a/app/views/search.php b/app/views/search.php index c64b875..2eaf765 100644 --- a/app/views/search.php +++ b/app/views/search.php @@ -168,3 +168,28 @@ + diff --git a/public/assests/css/style.css b/public/assests/css/style.css index 74cb2d6..c1209cd 100644 --- a/public/assests/css/style.css +++ b/public/assests/css/style.css @@ -96,3 +96,17 @@ body { height: 20%; padding: 0.75rem; } + +.footer{ + color: white; + background-color: #0000ff; +} + +.footer ul{ + list-style: none; +} + +.footer a{ + text-decoration: none; + color: white; +} diff --git a/uploads/profiles/.gitkeep b/uploads/profiles/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/uploads/projects/.gitkeep b/uploads/projects/.gitkeep deleted file mode 100644 index e69de29..0000000