smarty et merge de tout fini ( ദ്ദി ˙ᗜ˙ )

This commit is contained in:
Yasder5 2026-02-09 11:19:00 +01:00
parent a774205594
commit 6ed4394dda
113 changed files with 11964 additions and 1192 deletions

View file

@ -18,8 +18,45 @@
class AdminCtrl extends MotherCtrl{
public function admin(){
/*accès à la page admin
if (!isset($_SESSION['user']) && ($_SESSION['user']['user_status'] != 1 )){
header("Location:index.php?ctrl=error&action=error_403");
exit;
}*/
$objCategoryModel = new CategoryModel;
if (!empty($_POST['new_category'])) {
$objNewCategory = new Category;
if (!empty($objNewCategory->getName())) {
$objNewCategory = $_POST['new_category'];
$objCategoryModel->insertCategory($objNewCategory);
header("Location:index.php?ctrl=admin&action=admin");
exit;
}
}
if (!empty($_POST['edit_category'])) {
$objEditCategory = new Category;
if ($objEditCategory->getId() > 0) {
$objEditCategory = $_POST['edit_category'];
$objCategoryModel->editCategory($objEditCategory);
header("Location:index.php?ctrl=admin&action=admin");
exit;
}
}
$arrCategory = $objCategoryModel->findAllCategory();
$arrCategoryToDisplay = array();
foreach($arrCategory as $arrDetCategory){
$objCategory = new Category;
$objCategory->hydrate($arrDetCategory);
$arrCategoryToDisplay[] = $objCategory;
}
$this->_display("admin");
// Il faudra donner à maman et gérer l'affichage quand Smarty sera prêt
$this->_arrData['arrCategoryToDisplay'] = $arrCategoryToDisplay;
//$this->_arrData['intCategory'] = $objCategoryModel->;
$this->_display("admin");
}
}

View file

@ -2,6 +2,7 @@
use Smarty\Smarty;
class MotherCtrl {
protected array $_arrData = array(); // ou = []

View file

@ -8,6 +8,9 @@
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
@ -50,25 +53,24 @@
$strStartDate = $_POST['startdate']??'';
$strEndDate = $_POST['enddate']??'';
$intCategory = $_POST['category']??0;
// Récupération des projetc
// 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);
// 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;
}
// Récupération des utilisateurs
$objUserModel = new UserModel;
$arrUser = $objUserModel->findAllUsers();
// Récupération des catégories
$objCategoryModel = new CategoryModel;
$arrCategory = $objCategoryModel->findAllCategory();
@ -159,9 +161,99 @@
}
public function admin(){
$this->_display("admin");
}
public function display() {
$intId = $_GET['id'] ?? null;
if ($intId) {
$objProjectModel = new ProjectModel();
$arrProject = $objProjectModel->findOne((int)$intId);
if ($arrProject) {
$objProject = new Project();
$objProject->hydrate($arrProject);
$this->_arrData["objProject"] = $objProject;
$this->_display("projet_display");
} else {
header("Location: index.php?ctrl=project&action=home");
exit;
}
} else {
header("Location: index.php?ctrl=project&action=home");
exit;
}
}
public function sendEmail()
{
if (count($_POST) > 0) {
$projectId = (int)($_POST['project_id'] ?? 0);
$toEmail = trim($_POST['to_email'] ?? '');
if ($projectId <= 0 || !filter_var($toEmail, FILTER_VALIDATE_EMAIL)) {
header("Location: index.php?ctrl=project&action=display&id=".$projectId."&mail=fail");
exit;
}
$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(); // Nouvel objet Mail
$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.gmail.com";
$objMail->Username = "projet.folliow@gmail.com";
$objMail->Password = "dqnw mqbu cwvg enbp";
$objMail->IsHTML(true);
$objMail->setFrom('projet.folliow@gmail.com', 'Projet Folliow');
// Destinataire
$objMail->addAddress($toEmail);
// Mail
$objMail->Subject = "Projet : " . $objProject->getTitle();
$url = "http://localhost/projet_php/public/index.php?ctrl=project&action=display&id=" . $projectId;
$objMail->Body =
"<h3>" . $objProject->getTitle() . "</h3>" .
"<p>" . $objProject->getDescription() . "</p>" .
"<p><a href='" . $url . "'>Voir le projet</a></p>";
// Envoi + redirection
if ($objMail->Send()) {
header("Location: index.php?ctrl=project&action=display&id=".$projectId."&mail=ok");
} else {
// Pour debug si besoin: echo $objMail->ErrorInfo; exit;
header("Location: index.php?ctrl=project&action=display&id=".$projectId."&mail=fail");
}
exit;
}
header("Location: index.php?ctrl=project&action=home");
exit;
}
}

View file

@ -8,8 +8,8 @@ class UserCtrl extends MotherCtrl {
public function login(){
$strMail = $_POST['mail']??"";
$strPwd = $_POST['pwd']??"";
$strMail = $_POST['user_mail']??"";
$strPwd = $_POST['user_password']??"";
// Tester le formulaire
$arrError = [];
@ -127,13 +127,19 @@ class UserCtrl extends MotherCtrl {
$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;
if ($objUserModel->mailExists($objUser->getMail())) {
$arrError['user_mail'] = "Ce mail existe déjà";
} else {
// Erreur globale (pas liée à un champ)
$arrError['global'] = "Erreur lors de l'ajout";
$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";
}
}
}
}