smarty ça casse les couilles zebi

This commit is contained in:
Yasder5 2026-02-04 22:51:01 +01:00
parent b1960b2f35
commit aec3c845e0
469 changed files with 53465 additions and 69 deletions

0
controllers/.gitkeep Normal file
View file

View file

@ -0,0 +1,42 @@
<?php
require("../app/models/project_model.php");
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");
require("../app/models/user_model.php");
require("../app/entities/user_entity.php");
/**
* Le controller de la partie accessible uniquement par l'admin
* @author Laura
*/
class AdminCtrl{
public function admin() {
/* $objCategory = new Category ();
$objCategory->setName($_POST['category_name'] ?? "");
$objCategory->setParent($_POST['category_parent'] ?? "");
$objCategoryModel = new CategoryModel();
$boolInsert = $objCategoryModel->insert($objCategory);
EN ATTENTE
if ($boolInsert === true) {
$_SESSION['success'] = "Catégorie ajoutée avec succès";
header("Location:index.php?ctrl=admin&action=admin");
exit;
} else {
// Erreur globale
$arrError['global'] = "Erreur lors de l'ajout";
}
*/
include('../app/views/admin.php');
}
}

View file

@ -0,0 +1,45 @@
<?php
use Smarty\Smarty;
class MotherCtrl {
protected array $_arrData = array(); // ou = []
/**
* Méthode d'affichage des pages
*/
protected function _display($strView){
// 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 |
$objSmarty->registerPlugin('modifier', 'vardump', 'var_dump');
// Désactiver la mise en cache
$objSmarty->caching = false;
// Forcer la recompilation des templates
$objSmarty->force_compile = true;
// Vérifier si les templates ont été modifiés
$objSmarty->compile_check = true;
// Récupérer les variables
foreach($this->_arrData as $key=>$value){
//$$key = $value;
$objSmarty->assign($key, $value);
}
// Message de succès
$objSmarty->assign("success_message", $_SESSION['success']??'');
unset($_SESSION['success']);
$objSmarty->display("views/".$strView.".tpl");
// inclusion du header
/*include("views/_partial/header.php");
include("views/".$strView.".php");
include("views/_partial/footer.php");*/
}
}

View file

@ -0,0 +1,115 @@
<?php
require("./models/project_model.php");
require("./entities/project_entity.php");
require("./models/category_model.php");
require("./entities/category_entity.php");
require("./models/image_model.php");
require("./entities/image_entity.php");
require("mother_controller.php");
/**
* Le controler des Project
* @author Yasser & Laura
*/
class ProjectCtrl extends MotherCtrl{
/**
* Fonction d'affichage de la page d'acceuil
*/
public function home(){
$objProjectModel = new ProjectModel;
$arrProject = $objProjectModel->findAll(4);
$arrProjectToDisplay = array();
foreach($arrProject as $arrDetProject){
$objProject = new Project;
$objProject->hydrate($arrDetProject);
$arrProjectToDisplay[] = $objProject;
}
//$this->_arrData['arrArticleToDisplay'] = $arrArticleToDisplay;
var_dump($this->_arrData);
$this->_display("home");
}
/**
* Fonction d'affichage de la barre de recherche
*/
public function search(){
//Récupérer les informations du formulaire
$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;
$arrProject = $objProjectModel->findAll(intAuthor:$intAuthor, intPeriod:$intPeriod, strDate:$strDate,
strKeywords:$strKeywords, strStartDate:$strStartDate, strEndDate:$strEndDate, intCategory:$intCategory);
// Initialisation d'un tableau => objets
$arrProjectToDisplay = array();
// Boucle de transformation du tableau de tableau en tableau d'objets
foreach($arrProject as $arrDetProject){
$objProject = new Project;
$objProject->hydrate($arrDetProject);
$arrProjectToDisplay[] = $objProject;
}
$objUserModel = new UserModel;
$arrUser = $objUserModel->findAllUsers();
$objCategoryModel = new CategoryModel;
$arrCategory = $objCategoryModel->findAllCategory();
include('../app/views/search.php');
include('../app/views/partials/footer.php');
}
/**
* 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');
}
public function admin(){
include('../app/views/admin.php');
}
}

View file

@ -0,0 +1,147 @@
<?php
require("../app/models/user_model.php");
require("../app/entities/user_entity.php");
class UserCtrl{
public function login(){
include("../app/views/partials/header.php");
$strMail = $_POST['mail']??"";
$strPwd = $_POST['pwd']??"";
// Tester le formulaire
$arrError = [];
if (count($_POST) > 0) {
// Vérifier le formulaire
if ($strMail == ""){
$arrError['mail'] = "Le mail est obligatoire";
}
if ($strPwd == ""){
$arrError['pwd'] = "Le mot de passe est obligatoire";
}
// Si le formulaire est rempli correctement
if (count($arrError) == 0){
// Vérifier l'utilisateur en BDD
$objUserModel = new UserModel;
$arrResult = $objUserModel->verifUser($strMail, $strPwd);
//var_dump($arrResult);
if ($arrResult === false){ // Si la base de données ne renvoie rien
$arrError[] = "Mail ou mot de passe invalide";
}else{
// Ajoute l'utilisateur en session
$_SESSION['user'] = $arrResult;
$_SESSION['success'] = "Bienvenue, vous êtes bien connecté";
header("Location:index.php");
exit;
}
}
}
include("../app/views/login.php");
include("../app/views/partials/footer.php");
}
public function logout(){
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;
}
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");
}
}