backup du projet

This commit is contained in:
Yasder5
2026-02-26 00:19:11 +01:00
commit 4655c05be6
670 changed files with 87655 additions and 0 deletions

0
controllers/.gitkeep Normal file
View File

View File

@@ -0,0 +1,112 @@
<?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("./models/user_model.php");
require("./entities/user_entity.php");
require("./models/authorisation_model.php");
require("./entities/authorisation_entity.php");
require("mother_controller.php");
/**
* Le controller de la partie accessible uniquement par l'admin
* @author Laura
*/
class AdminCtrl extends MotherCtrl{
public function admin(){
if (!isset($_SESSION['user']) && ($_SESSION['user']['user_status'] != 1 )){
header("Location:index.php?ctrl=error&action=error_403");
exit;
}
//gestion de l'user
$objCategoryModel = new CategoryModel;
if (!empty($_POST['new_category'])) {
$newCat = new Category();
$newCat->setName($_POST['new_category']);
$objCategoryModel->insertCategory($newCat);
$_SESSION['success'] = "La catégorie a bien été ajoutée";
header('Location: index.php?ctrl=admin&action=admin');
exit;
}
if (!empty($_POST['id_to_edit']) && !empty($_POST['new_name'])) {
$editCat = new Category();
$editCat->setId($_POST['id_to_edit']);
$editCat->setName($_POST['new_name']);
$objCategoryModel->editCategory($editCat);
$_SESSION['success'] = "La catégorie a bien été modifiée";
header('Location: index.php?ctrl=admin&action=admin');
exit;
}
//affichage select des catégories
$arrCategory = $objCategoryModel->findAllCategory();
$arrCategoryToDisplay = array();
foreach($arrCategory as $arrDetCategory){
$objCategory = new Category;
$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['success'] = "Le statut a bien été modifié !";
}
}
elseif ($_POST['action'] === 'delete_user') {
$objUserModel->delete_soft($intUserId);
$_SESSION['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['arrUserToDisplay'] = $arrUserToDisplay;
$this->_arrData['arrAuthorisationToDisplay'] = $arrAuthorisationToDisplay;
$this->_display("admin");
}
}

View File

@@ -0,0 +1,24 @@
<?php
require("mother_controller.php");
/**
* Le contrôleur des erreurs
* @author Laura (largement inspiré de Christel)
*/
class ErrorCtrl extends MotherCtrl{
/**
* Page erreur 404
*/
public function error_404(){
$this->_display("error_404");
}
/**
* Page erreur 403
*/
public function error_403(){
$this->_display("error_403");
}
}

View File

@@ -0,0 +1,56 @@
<?php
use Smarty\Smarty;
class MotherCtrl {
protected array $_arrData = array(); // ou = []
/**
* Méthode d'affichage des pages
*/
protected function _display($strView, bool $boolDisplay = true){
// 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']);
if (isset($_SESSION['error'])){
$objSmarty->assign("arrError", array($_SESSION['error']));
unset($_SESSION['error']);
}
if ($boolDisplay){
$objSmarty->display("views/".$strView.".tpl");
}else{
return $objSmarty->fetch("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,17 @@
<?php
require("mother_controller.php");
/**
* Le controller de la page d'aide utilisateur
* @author Laura
*/
class PageCtrl extends MotherCtrl{
public function help(){
$this->_display("help");
}
}

View File

@@ -0,0 +1,631 @@
<?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("./models/user_model.php");
require("./entities/user_entity.php");
require("mother_controller.php");
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\SMTP;
/**
* Le controler des Project
* @author Yasser & Laura
*/
class ProjectCtrl extends MotherCtrl{
/**
* Fonction d'affichage de la page d'acceuil
*/
public function home(){
if (!isset($_SESSION['user']) && isset($_COOKIE['remember_me'])) {
$token_du_cookie = $_COOKIE['remember_me'];
$hash_a_verifier = hash('sha256', $token_du_cookie);
$objUserModel = new UserModel;
// 2. On cherche le jeton dans TA table "tokens" (avec token_user_id)
$row = $objUserModel->getTokenUser($hash_a_verifier);
if ($row) {
// 3. Jeton trouvé ! On récupère les infos de l'utilisateur
$user = $objUserModel->findUserById($row['token_user_id']);
if ($user) {
// 4. On recrée la session comme lors d'un login normal
$_SESSION['user'] = $user;
}
}
}
$intCategory = 0;
if (!empty($_GET['filter_cat'])) {
$intCategory = (int) $_GET['filter_cat'];
}
$boolOld = false;
if (!empty($_GET['filter_old']) && $_GET['filter_old'] == 'true') {
$boolOld = true;
}
$objProjectModel = new ProjectModel;
$arrProject = $objProjectModel->findAll(0,'',0,0,'','','',$intCategory,$boolOld);
$arrProjectToDisplay = array();
foreach($arrProject as $arrDetProject){
$objProject = new Project;
$objProject->hydrate($arrDetProject);
$arrProjectToDisplay[] = $objProject;
}
$this->_arrData['arrProjectToDisplay'] = $arrProjectToDisplay;
$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 projets
$objProjectModel = new ProjectModel;
$arrProject = $objProjectModel->findAll(intAuthor:$intAuthor, intPeriod:$intPeriod, strDate:$strDate,
strKeywords:$strKeywords, strStartDate:$strStartDate, strEndDate:$strEndDate, intCategory:$intCategory);
$arrProjectToDisplay = array();
foreach($arrProject as $arrDetProject){
$objProject = new Project;
$objProject->hydrate($arrDetProject);
$arrProjectToDisplay[] = $objProject;
}
// Récupération des utilisateurs
$objUserModel = new UserModel;
$arrUser = $objUserModel->findAllUsers();
// Récupération des catégories
$objCategoryModel = new CategoryModel;
$arrCategory = $objCategoryModel->findAllCategory();
$this->_arrData['arrProjectToDisplay'] = $arrProjectToDisplay;
$this->_arrData['arrCategory'] = $arrCategory;
$this->_arrData['arrProject'] = $arrProject;
$this->_arrData['arrUser'] = $arrUser;
$this->_display("search");
}
/**
* Fonction d'affichage de la page projet
* @author Christel adapter par Guillaume
*/
public function addedit_project(){
if (!isset($_SESSION['user'])){ // Pas d'utilisateur connecté
header("Location:index.php?ctrl=error&action=error_403");
exit;
}
$objProject = new Project;
$objProjectModel = new ProjectModel;
$objCategoryModel = new CategoryModel;
// Dans la cas de modif
if (isset($_GET['id'])){
$arrProject = $objProjectModel->findOne($_GET['id']);
$objProject->hydrate($arrProject); // BDD
$this->_arrData['arrImages'] = $objProjectModel->getImagesByProjectId($objProject->getId());
}
// Tester le formulaire
$arrError = [];
if (count($_POST) > 0) {
$objProject->hydrate($_POST); // Formulaire
if ($objProject->getTitle() == ""){
$arrError['title'] = "Le titre est obligatoire";
}
if ($objProject->getDescription() == ""){
$arrError['description'] = "La description est obligatoire";
}
if ($objProject->getContent() == ""){
$arrError['content'] = "Le contenu est obligatoire";
}
// Vérification de l'image (Thumbnail)
$arrTypeAllowed = array('image/jpeg', 'image/png', 'image/webp');
if ($_FILES['thumbnail']['error'] != 4){
if (!in_array($_FILES['thumbnail']['type'], $arrTypeAllowed)){
$arrError['thumbnail'] = "Le type de fichier n'est pas autorisé";
}else{
switch ($_FILES['thumbnail']['error']){
case 0 :
$strImageName = uniqid().".webp";
$strOldImg = $objProject->getThumbnail();
$objProject->setThumbnail($strImageName);
break;
case 1 :
$arrError['thumbnail'] = "Le fichier est trop volumineux";
break;
case 2 :
$arrError['thumbnail'] = "Le fichier est trop volumineux";
break;
case 3 :
$arrError['thumbnail'] = "Le fichier a été partiellement téléchargé";
break;
case 6 :
$arrError['thumbnail'] = "Le répertoire temporaire est manquant";
break;
default :
$arrError['thumbnail'] = "Erreur sur l'image";
break;
}
}
}else{
if (is_null($objProject->getThumbnail())){
$arrError['thumbnail'] = "L'image est obligatoire";
}
}
// SI pas d'erreur : on traite l'image principale
if (count($arrError) == 0){
$boolImageOk = true;
// On peux changer ces dimensions si on veux que la miniature soit plus grande/petite
if (isset($strImageName)){
$strDest = $_ENV['IMG_PROJECT_PATH'].$strImageName;
$strSource = $_FILES['thumbnail']['tmp_name'];
list($intWidth, $intHeight) = getimagesize($strSource);
// Redimensionnement de la Thumbnail
$intDestWidth = 200; $intDestHeight = 250;
$fltDestRatio = $intDestWidth / $intDestHeight;
$fltSourceRatio = $intWidth / $intHeight;
if ($fltSourceRatio > $fltDestRatio) {
$intCropHeight = $intHeight;
$intCropWidth = (int)round($intHeight * $fltDestRatio);
$intCropX = (int)(($intWidth - $intCropWidth) / 2);
$intCropY = 0;
} else {
$intCropWidth = $intWidth;
$intCropHeight = (int)round($intWidth / $fltDestRatio);
$intCropX = 0;
$intCropY = (int)(($intHeight - $intCropHeight) / 2);
}
$objDest = imagecreatetruecolor($intDestWidth, $intDestHeight);
switch ($_FILES['thumbnail']['type']) {
case 'image/jpeg' :
$objSource = imagecreatefromjpeg($strSource);
break;
case 'image/png' :
$objSource = imagecreatefrompng($strSource);
break;
case 'image/webp' :
$objSource = imagecreatefromwebp($strSource);
break;
}
imagecopyresampled($objDest, $objSource, 0, 0, $intCropX, $intCropY, $intDestWidth, $intDestHeight, $intCropWidth, $intCropHeight);
$boolImageOk = imagewebp($objDest, $strDest);
//Suppression des doublons pour la mémoire vive
imagedestroy($objDest);
imagedestroy($objSource);
}
// SI image ok, on balance tout dans la bdd
if ($boolImageOk){
if (!isset($_GET['id'])){
$objProject->setUser_id($_SESSION['user']['user_id']);
$boolOk = $objProjectModel->insert($objProject);
} else {
$boolOk = $objProjectModel->updateProject($objProject);
}
// Gestion des 20 Images après l'envoie de la Thumbnail en BDD
if ($boolOk){
//Si pas d'erreur
if (isset($_FILES['imageProject']) && $_FILES['imageProject']['error'][0] != 4) {
$files = $_FILES['imageProject'];
$maxPhotos = 20;
// 1. On compte combien d'images le projet possède déjà en BDD
$currentImages = $objProjectModel->getImagesByProjectId($objProject->getId());
$totalExisting = count($currentImages);
// 2. On calcule combien de photos on peut encore ajouter
$remainingSlots = $maxPhotos - $totalExisting;
// Si on a déjà atteint ou dépassé la limite, on ne traite même pas les fichiers
if ($remainingSlots <= 0) {
$_SESSION['error'] = "Limite de $maxPhotos photos atteinte. Supprimez-en pour en ajouter de nouvelles.";
} else {
$uploadedCount = 0;
foreach ($files['name'] as $key => $name) {
// 3. On utilise le quota restant comme condition d'arrêt
if ($uploadedCount >= $remainingSlots) break;
if ($files['error'][$key] === 0 && in_array($files['type'][$key], $arrTypeAllowed)) {
$galleryName = uniqid() . "_gallery.webp";
$strDestGallery = $_ENV['IMG_PROJECT_PATH'].$galleryName;
$strSourceGallery = $files['tmp_name'][$key];
// Reprise de la logique de redimensionnement
list($intW, $intH) = getimagesize($strSourceGallery);
// On peux changer ces dimensions si on veux que la galerie soit plus grande/petite
$intDestW = 150; $intDestH = 150;
$fltDestR = $intDestW / $intDestH;
$fltSourceR = $intW / $intH;
if ($fltSourceR > $fltDestR) {
$intCropH = $intH;
$intCropW = (int)round($intH * $fltDestR);
$intCropX = (int)(($intW - $intCropW) / 2);
$intCropY = 0;
} else {
$intCropW = $intW;
$intCropH = (int)round($intW / $fltDestR);
$intCropX = 0;
$intCropY = (int)(($intH - $intCropH) / 2);
}
$objDestGallery = imagecreatetruecolor($intDestW, $intDestH);
// Création de la source selon le type de chaque image de la boucle
switch ($files['type'][$key]) {
case 'image/jpeg' :
$objSourceGallery = imagecreatefromjpeg($strSourceGallery);
break;
case 'image/png' :
$objSourceGallery = imagecreatefrompng($strSourceGallery);
break;
case 'image/webp' :
$objSourceGallery = imagecreatefromwebp($strSourceGallery);
break;
}
if ($objSourceGallery) {
imagecopyresampled($objDestGallery, $objSourceGallery, 0, 0, $intCropX, $intCropY, $intDestW, $intDestH, $intCropW, $intCropH);
if (imagewebp($objDestGallery, $strDestGallery)) {
// Insertion en BDD
$objProjectModel->addImageInProject($galleryName, $objProject->getId());
$uploadedCount++;
}
imagedestroy($objDestGallery);
imagedestroy($objSourceGallery);
}
}
}
if ($uploadedCount > 0) {
$_SESSION['success'] = "$uploadedCount image(s) ajoutée(s) à la galerie !";
}
}
}
// Suppression de l'ancienne miniature
if(isset($strOldImg) && !empty($strOldImg) && isset($strImageName)){
$strOldFile = $_ENV['IMG_PROJECT_PATH'].$strOldImg;
if (file_exists($strOldFile)) unlink($strOldFile);
}
$_SESSION['success'] = (!isset($_GET['id'])) ? "Le projet a bien été créé" : "Le projet a bien été modifié";
header("Location:index.php");
exit;
} else {
$arrError[] = "Erreur lors de l'enregistrement en base de données";
}
} else {
$arrError['thumbnail'] = "Erreur dans le traitement de l'image";
}
}
}
// Données pour la vue
$this->_arrData['arrCategory'] = $objCategoryModel->findAllCategory();
$this->_arrData['objProject'] = $objProject;
$this->_arrData['arrError'] = $arrError;
// Si on est en modifications de projet, on récupère les images pour les afficher dans le formulaire
if ($objProject->getId()) {
// On récupère les images via le modèle et on les stocke dans le tableau de données
$this->_arrData['arrImages'] = $objProjectModel->getImagesByProjectId($objProject->getId());
} else {
// Sinon on initialise un tableau vide pour éviter que Smarty ne râle
$this->_arrData['arrImages'] = [];
}
$this->_display('addedit_project');
}
/**
* Fonction d'affichage de projet
*/
public function display() {
$intId = $_GET['id'] ?? null;
if ($intId) {
$objProjectModel = new ProjectModel();
$arrProject = $objProjectModel->findOne((int)$intId);
// CORRECTION ICI : on utilise $intId (pas $id)
$arrImages = $objProjectModel->getImagesByProjectId((int)$intId);
if ($arrProject) {
$objProject = new Project();
$objProject->hydrate($arrProject);
$this->_arrData["objProject"] = $objProject;
$this->_arrData["arrImages"] = $arrImages;
$this->_display("project_display");
} else {
header("Location: index.php?ctrl=project&action=home");
exit;
}
} else {
header("Location: index.php?ctrl=project&action=home");
exit;
}
}
/**
* Fonction de partage de projet
*/
public function shareProject(){
if (count($_POST) > 0)
{
$projectId = (int)($_POST['project_id'] ?? 0);
$toEmail = trim($_POST['to_email'] ?? '');
$objProjectModel = new ProjectModel();
$arrProject = $objProjectModel->findOne($projectId);
if (!$arrProject) {
header("Location: index.php?ctrl=project&action=home");
exit;
}
$objProject = new Project();
$objProject->hydrate($arrProject);
$objMail = new PHPMailer();
$objMail->IsSMTP();
$objMail->Mailer = "smtp";
$objMail->CharSet = PHPMailer::CHARSET_UTF8;
$objMail->SMTPDebug = 0;
$objMail->SMTPAuth = true;
$objMail->SMTPSecure = "tls";
$objMail->Port = 587;
$objMail->Host = 'smtp-relay.brevo.com';
$objMail->Username = 'a2a67e001@smtp-brevo.com';
$objMail->Password = 'xsmtpsib-f2af87e12d3db6f1b99802a92c1acda32d45fc32a8446eeed7e49ec91c4ec7ef-AX8Y7YkRWYSmKHwS';
// Désactive la vérification du certificat SSL
// Cela permet d'éviter les erreurs liées au certificat, mais réduit la sécurité de la connexion.
$objMail->SMTPOptions = [
'ssl' => [
'verify_peer' => false,
],
];
$objMail->IsHTML(true);
$objMail->setFrom('projet.folliow@hotmail.com', 'Folliow');
$objMail->addAddress($toEmail);
$objMail->Subject = "Projet : " . $objProject->getTitle();
$url = "https://php.boulayoune.com/index.php?ctrl=project&action=display&id=" . $projectId;
$this->_arrData['projectTitle'] = $objProject->getTitle();
$this->_arrData['projectDescription'] = $objProject->getDescription();
$this->_arrData['projectUrl'] = $url;
$objMail->Body = $this->_display("mail_message", false);
if ($objMail->Send()) {
header("Location: index.php?ctrl=project&action=display&id=".$projectId."&mail=ok");
} else {
header("Location: index.php?ctrl=project&action=display&id=".$projectId."&mail=fail");
}
exit;
}
header("Location: index.php?ctrl=project&action=home");
exit;
}
/**
* Fonction de modération de projet = accepté
* @author Guillaume
*/
public function accept(){
//Récupéré l'id dans l'url
$intId = $_GET['id'];
//Je créer un nouveau model pour exec la commande SQL
$objProjectModel = new ProjectModel;
$objProjectModel->accept($intId);
//Redirection vers la page
header("Location: index.php");
exit;
}
/**
* Fonction de modération de projet = refusé
* @author Guillaume
*/
public function refuse(){
//Récupéré l'id dans l'url
$intId = $_GET['id'];
//Je créer un nouveau model pour exec la commande SQL
$objProjectModel = new ProjectModel;
$objProjectModel->refuse($intId);
//Redirection vers la page
header("Location: index.php");
exit;
}
/**
* Fonction de suppression de projet
* @author Guillaume
*/
public function delete(){
//Récupéré l'id dans l'url
$intId = $_GET['id'];
//Je créer un nouveau model pour exec la commande SQL
$objProjectModel = new ProjectModel;
$objProjectModel->delete($intId);
//Redirection vers la page
header("Location: index.php");
exit;
}
/**
* Fonction de changement de statut (Approuvé, Refusé, En attente)
* @author Guillaume
*/
public function change_image_status() {
if (isset($_GET['id_img']) && isset($_GET['status'])) {
$idImg = (int)$_GET['id_img'];
$status = $_GET['status']; // "en_attente" passage à "approuvé"
$objProjectModel = new ProjectModel();
// On passe le statut texte directement à ta méthode de modèle
if ($objProjectModel->updateImageStatus($idImg, $status)) {
$_SESSION['success'] = "Le statut de l'image est désormais : " . ucfirst($status);
}
}
// La redirection : Si on sait d'où on vient, on y retourne, sinon index
$urlRedirect = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : "index.php";
header("Location: " . $urlRedirect);
exit;
}
/**
* Fonction de validation de l'image de projet
* @author Guillaume
*/
public function delete_image() {
// Vérifier l'id de l'image
$idImg = $_GET['id_img'];
$objProjectModel = new ProjectModel();
// Récupérer le nom du fichier pour le supprimer physiquement
$image = $objProjectModel->findImage($idImg);
if ($image) {
$filePath = $_ENV['IMG_PROJECT_PATH'] . $image['image_name'];
if (file_exists($filePath)) unlink($filePath);
$objProjectModel->deleteImage($idImg);
$_SESSION['success'] = "Image supprimée !";
}
// La redirection : Si on sait d'où on vient, on y retourne, sinon index
$url = (isset($_SERVER['HTTP_REFERER'])) ? $_SERVER['HTTP_REFERER'] : "index.php";
header("Location: " . $url);
exit;
}
/**
* Fonction d'ajout des 20 images max du projet
* @author Guillaume
* @param string $fileName = le nom de l'image, int $projectId = L'Id du projet que l'on veut afficher, string $alt = qui affichera pars défaut "Image de projet"
* @return bool Est-ce que la requête s'est bien passée
*/
public function addImageInProject(string $fileName, int $projectId, string $alt = "Image de projet"): bool {
$strRq = "INSERT INTO image (
image_name,
image_alt,
image_status,
image_project
)
VALUES (:name, :alt, :status, :project)";
$rqPrep = $this->_db->prepare($strRq);
$rqPrep->bindValue(":name", $fileName, PDO::PARAM_STR);
$rqPrep->bindValue(":alt", $alt, PDO::PARAM_STR);
$rqPrep->bindValue(":status", "en_attente", PDO::PARAM_STR); // Valeur string en brute
$rqPrep->bindValue(":project", $projectId, PDO::PARAM_INT);
return $rqPrep->execute();
}
/**
* Fonction d'affichage des 20 images max du projet
* @author Guillaume
* @param array $ProjectId L'Id du projet que l'on veut afficher
* @return bool Est-ce que la requête s'est bien passée
*/
public function getImagesByProjectId(int $projectId): array {
$strRq = "SELECT image_id, image_name, image_alt, image_status
FROM image
WHERE image_project = :id";
$rqPrep = $this->_db->prepare($strRq);
$rqPrep->bindValue(":id", $projectId, PDO::PARAM_INT);
$rqPrep->execute();
return $rqPrep->fetchAll(PDO::FETCH_ASSOC);
}
/**
* Page mentions légales
*/
public function mentions(){
// Afficher
$this->_display("mentions");
}
/**
* Page à propos
*/
public function about(){
// Afficher
$this->_display("about");
}
}

View File

@@ -0,0 +1,69 @@
<?php
/* Smarty version 5.7.0, created on 2026-02-06 08:21:14
from 'file:views/home.tpl' */
/* @var \Smarty\Template $_smarty_tpl */
if ($_smarty_tpl->getCompiled()->isFresh($_smarty_tpl, array (
'version' => '5.7.0',
'unifunc' => 'content_6985a47abcda40_19846426',
'has_nocache_code' => false,
'file_dependency' =>
array (
'299f75d7692a19207f23bf5795a2721f507c3fc6' =>
array (
0 => 'views/home.tpl',
1 => 1770365364,
2 => 'file',
),
),
'includes' =>
array (
'file:views/_partial/preview.tpl' => 1,
),
))) {
function content_6985a47abcda40_19846426 (\Smarty\Template $_smarty_tpl) {
$_smarty_current_dir = 'C:\\wamp64\\www\\projetphp\\views';
$_smarty_tpl->getInheritance()->init($_smarty_tpl, false);
?>
<?php
$_smarty_tpl->getInheritance()->instanceBlock($_smarty_tpl, 'Block_3150142016985a47abb6c29_00747518', "content");
?>
<?php }
/* {block "content"} */
class Block_3150142016985a47abb6c29_00747518 extends \Smarty\Runtime\Block
{
public function callBlock(\Smarty\Template $_smarty_tpl) {
$_smarty_current_dir = 'C:\\wamp64\\www\\projetphp\\views';
?>
<section class="container mt-5 p-5 d-flex flex-column align-items-center text-center">
<h1 class="logo">Folliow</h1>
<h2>Là où les talents rencontrent leur avenir</h2>
<p class="col-6">Une plateforme de portfolio adapté à vos besoins et aux besoins des entreprises.
Créer un portfolio réellement pertinent aux exigences du marché et rentrez
directement en contact avec les entreprises.</p>
</section>
<section class="container" aria-label="Articles récents">
<h2 class="visually-hidden">Les 4 derniers articles</h2>
<div class="row mb-2">
<?php
$_from = $_smarty_tpl->getSmarty()->getRuntime('Foreach')->init($_smarty_tpl, $_smarty_tpl->getValue('arrProjectToDisplay'), 'objProject');
$foreach0DoElse = true;
foreach ($_from ?? [] as $_smarty_tpl->getVariable('objProject')->value) {
$foreach0DoElse = false;
?>
<?php $_smarty_tpl->renderSubTemplate("file:views/_partial/preview.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, $_smarty_tpl->cache_lifetime, array(), (int) 0, $_smarty_current_dir);
?>
<?php
}
$_smarty_tpl->getSmarty()->getRuntime('Foreach')->restore($_smarty_tpl, 1);?>
</section>
<?php
}
}
/* {/block "content"} */
}

View File

@@ -0,0 +1,66 @@
<?php
/* Smarty version 5.7.0, created on 2026-02-06 08:21:14
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_6985a47ad585d5_25749521',
'has_nocache_code' => false,
'file_dependency' =>
array (
'c724044e55872f26030b02de6dcd14dc34a20b16' =>
array (
0 => 'views/_partial/preview.tpl',
1 => 1770365554,
2 => 'file',
),
),
'includes' =>
array (
),
))) {
function content_6985a47ad585d5_25749521 (\Smarty\Template $_smarty_tpl) {
$_smarty_current_dir = 'C:\\wamp64\\www\\projetphp\\views\\_partial';
?><article class="col-md-3 mb-4">
<div class="card h-100 shadow-sm article-card">
<div class="ratio ratio-16x9">
<img src=".<?php echo $_smarty_tpl->getValue('objProject')->getThumbnail();?>
"
class="w-100 h-100 object-fit-cover"
alt=""
loading="lazy">
</div>
<div class="d-flex align-items-start gap-3">
<img src=".<?php echo $_smarty_tpl->getValue('objProject')->getUser_image();?>
"
class="rounded-circle flex-shrink-0 mt-2 ml-5"
style="width: 48px; height: 48px; object-fit: cover;"
alt="Photo de profil">
<div class="flex-grow-1 card-body p-3">
<h3 class="h6 mb-1"><?php echo $_smarty_tpl->getValue('objProject')->getTitle();?>
</h3>
<small class="text-body-secondary d-block mb-1">
<time><?php echo $_smarty_tpl->getValue('objProject')->getCreation_date();?>
</time>
<?php echo $_smarty_tpl->getValue('objProject')->getCreatorname();?>
</small>
<a href="?id=<?php echo $_smarty_tpl->getValue('objProject')->getId();?>
"
class="stretched-link small">
Lire la suite →
</a>
</div>
</div>
</div>
</article><?php }
}

View File

@@ -0,0 +1,343 @@
<?php
require("models/user_model.php");
require("entities/user_entity.php");
require("mother_controller.php");
require("./models/project_model.php");
require("./entities/project_entity.php");
class UserCtrl extends MotherCtrl {
public function login(){
$strMail = $_POST['user_mail']??"";
$strPwd = $_POST['user_password']??"";
// 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é";
if (isset($_POST['remember_me'])) {
$token = bin2hex(random_bytes(32));
$token_hash = hash('sha256', $token);
$objUserModel->remember($_SESSION['user']['user_id'],$token_hash);
setcookie('remember_me', $token, time() + (15*24*60*60), "/", "", true, true);
}
header("Location:index.php");
exit;
}
}
}
$this->_arrData['arrError'] = $arrError;
$this->_display("login");
}
public function logout(){
if (isset($_COOKIE['remember_me'])) {
$hash = hash('sha256', $_COOKIE['remember_me']);
$objUserModel = new UserModel;
$objUserModel->deleteToken($hash);
setcookie('remember_me', '', time() - 3600, "/");
}
unset($_SESSION['user']);
$_SESSION['success'] = "Vous êtes bien déconnecté";
header("Location:index.php");
exit;
}
/**
* Fonction d'inscription d'un utilisateur
* Effectue les validations du formulaire,
* vérifie l'unicité du mail et du pseudo,
* puis insère l'utilisateur en base de données
* @return void
*/
public function signup(){
// 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'] = "L'adresse e-mail est obligatoire";
} elseif (!filter_var($objUser->getMail(), FILTER_VALIDATE_EMAIL)) {
$arrError['user_mail'] = "Le format de l'adresse e-mail est invalide";
}
if (trim($objUser->getPseudo()) === "") {
$arrError['user_pseudo'] = "Le pseudo est obligatoire";
}
$strRegex = "/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{15,}$/";
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 respecte pas les critères";
}else if($objUser->getPwd() != $strPwdConfirm){
$arrError['pwd_confirm'] = "La confirmation du mot de passe ne correspond pas";
}
// Si pas d'erreurs => insertion
if (count($arrError) === 0) {
$objUserModel = new UserModel();
// Vérif mail
if ($objUserModel->mailExists($objUser->getMail())) {
$arrError['user_mail'] = "Impossible de créer le compte avec ces informations";
}
// Vérif pseudo
if ($objUserModel->pseudoExists($objUser->getPseudo())) {
$arrError['user_pseudo'] = "Ce pseudo existe déjà";
}
// Si aucune erreur => insert
if (count($arrError) === 0) {
$boolInsert = $objUserModel->insert($objUser);
if ($boolInsert === true) {
$_SESSION['success'] = "Compte créé avec succès";
header("Location:index.php?ctrl=user&action=login");
exit;
} else {
$arrError['global'] = "Erreur lors de l'ajout";
}
}
}
}
// Affichage de la vue inscription
$this->_arrData['objUser'] = $objUser;
$this->_arrData['arrError'] = $arrError;
$this->_display("signup");
}
/**
* le controlleur affichage de la page user
*/
public function user(){
/**$intId = isset($_GET['id']) ? (int)$_GET['id'] : 0;
if ($intId <= 0) {
header("Location: index.php");
exit;
}
//affichage info utilisateur
$objUserModel = new UserModel;
$arrUserData = $objUserModel->findUserById($intId);
if ($arrUserData === false) {
header("Location: index.php");
exit;
}*/
$strPseudo = $_GET['pseudo']??'';
$objUserModel = new UserModel;
$arrUserData = $objUserModel->findUserByPseudo($strPseudo);
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,'',$objUser->getId());
$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($_POST['user_mail']) && ($_POST['user_mail'] != $objUser->getMail())) {
$arrError['user_mail'] = "Ce mail est déjà associé";
} else {
if ($objUserModel->pseudoExists($_POST['user_pseudo']) && ($_POST['user_pseudo'] != $objUser->getPseudo())){
$arrError['user_pseudo'] = "Ce pseudo est déjà utiliser";
}else{
$objUser->hydrate($_POST);
$objUser->setId($_SESSION['user']['user_id']);
// Vérification de l'image
$arrTypeAllowed = array('image/jpeg', 'image/png', 'image/webp');
$boolImageOk = true;
if ($_FILES['image']['error'] != 4) {
if (!in_array($_FILES['image']['type'], $arrTypeAllowed)) {
$arrError['image'] = "Le type de fichier n'est pas autorisé";
} else {
switch ($_FILES['image']['error']) {
case 0:
$strImageName = uniqid() . ".webp";
$strOldImg = $objUser->getImage();
$objUser->setImage($strImageName);
break;
case 1:
case 2:
$arrError['image'] = "Le fichier est trop volumineux";
break;
case 3:
$arrError['image'] = "Le fichier a été partiellement téléchargé";
break;
case 6:
$arrError['image'] = "Le répertoire temporaire est manquant";
break;
default:
$arrError['image'] = "Erreur sur l'image";
break;
}
}
}
// Traitement de l'image si pas d'erreur
if (count($arrError) == 0 && isset($strImageName)) {
$strDest = $_ENV['IMG_USER_PATH'] . $strImageName;
$strSource = $_FILES['image']['tmp_name'];
list($intWidth, $intHeight) = getimagesize($strSource);
$intDestWidth = 200; $intDestHeight = 200;
$fltDestRatio = $intDestWidth / $intDestHeight;
$fltSourceRatio = $intWidth / $intHeight;
if ($fltSourceRatio > $fltDestRatio) {
$intCropHeight = $intHeight;
$intCropWidth = (int)round($intHeight * $fltDestRatio);
$intCropX = (int)(($intWidth - $intCropWidth) / 2);
$intCropY = 0;
} else {
$intCropWidth = $intWidth;
$intCropHeight = (int)round($intWidth / $fltDestRatio);
$intCropX = 0;
$intCropY = (int)(($intHeight - $intCropHeight) / 2);
}
$objDest = imagecreatetruecolor($intDestWidth, $intDestHeight);
switch ($_FILES['image']['type']) {
case 'image/jpeg': $objSource = imagecreatefromjpeg($strSource); break;
case 'image/png': $objSource = imagecreatefrompng($strSource); break;
case 'image/webp': $objSource = imagecreatefromwebp($strSource); break;
}
imagecopyresampled($objDest, $objSource, 0, 0, $intCropX, $intCropY, $intDestWidth, $intDestHeight, $intCropWidth, $intCropHeight);
$boolImageOk = imagewebp($objDest, $strDest);
imagedestroy($objDest);
imagedestroy($objSource);
}
$boolInsert = $objUserModel->update($objUser);
if ($boolInsert === true) {
if (isset($strOldImg) && !empty($strOldImg) && isset($strImageName)) {
$strOldFile = $_ENV['IMG_USER_PATH'] . $strOldImg;
if (file_exists($strOldFile)) unlink($strOldFile);
}
$arrNewInfo = $objUserModel->findUserByPseudo($objUser->getPseudo());
$_SESSION['user'] = $arrNewInfo;
$_SESSION['success'] = "Compte modifier avec succès";
header("Location:?ctrl=user&action=user&pseudo=".$objUser->getPseudo());
exit;
} else {
$arrError['global'] = "Erreur lors de l'update";
}
}
}
}
$this->_arrData["arrError"] = $arrError;
$this->_arrData['objUser'] = $objUser;
$this->_display("useredit");
}
}