Merge branch 'main' into yass
This commit is contained in:
commit
750b5715bc
49 changed files with 2573 additions and 1504 deletions
17
controllers/page_controller.php
Normal file
17
controllers/page_controller.php
Normal 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");
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -25,7 +25,7 @@
|
|||
public function home(){
|
||||
|
||||
|
||||
$intCategory = 0;
|
||||
$intCategory = 0;
|
||||
if (!empty($_GET['filter_cat'])) {
|
||||
$intCategory = (int) $_GET['filter_cat'];
|
||||
}
|
||||
|
|
@ -88,87 +88,170 @@
|
|||
$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 project (){
|
||||
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
|
||||
}
|
||||
|
||||
// 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
|
||||
$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{
|
||||
// Vérification des codes d'erreur
|
||||
switch ($_FILES['thumbnail']['error']){
|
||||
case 0 :
|
||||
// Renommage de l'image
|
||||
$strImageName = uniqid().".webp";
|
||||
|
||||
// Récupère le nom de l'image avant changement
|
||||
$strOldImg = $objProject->getThumbnail();
|
||||
// Mise à jour du nom de l'image dans l'objet
|
||||
$objProject->setThumbnail($strImageName);
|
||||
break;
|
||||
case 1 :
|
||||
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{
|
||||
// Est-ce que le fichier existe ?
|
||||
if (is_null($objProject->getThumbnail())){
|
||||
$arrError['thumbnail'] = "L'image est obligatoire";
|
||||
}
|
||||
}
|
||||
|
||||
$objProjectModel = new ProjectModel;
|
||||
$arrProject = $objProjectModel->findAll(4);
|
||||
$arrProjectToDisplay = array();
|
||||
foreach($arrProject as $arrDetProject){
|
||||
$objProject = new Project;
|
||||
$objProject->hydrate($arrDetProject);
|
||||
$arrProjectToDisplay[] = $objProject;
|
||||
}
|
||||
// SI pas d'erreur : on traite l'image depuis la bdd
|
||||
if (count($arrError) == 0){
|
||||
|
||||
$objImageModel = new ImageModel;
|
||||
$arrImage = $objImageModel->findAllImage(4);
|
||||
$arrImageToDisplay = array();
|
||||
foreach($arrImage as $arrDetImage){
|
||||
$objImage = new Image;
|
||||
$objImage->hydrate($arrDetImage);
|
||||
$arrImageToDisplay[] = $objImage;
|
||||
}
|
||||
//Variable data
|
||||
$_SESSION['title'] = $_POST['titleProject']??"";
|
||||
$_SESSION['description'] = $_POST['descProject']??"";
|
||||
$_SESSION['content'] = $_POST['textProject']??"";
|
||||
$_SESSION['thumbnail'] = $_FILES['imageThumbnail']['name']??"";
|
||||
$_SESSION['status'] = 'en_attente';
|
||||
$_SESSION['user_id'] = $_SESSION['user']['user_id'];
|
||||
$boolImageOk = true;
|
||||
|
||||
// Redimensionnement de l'image
|
||||
if (isset($strImageName)){
|
||||
$strDest = $_ENV['IMG_PATH'].$strImageName;
|
||||
$strSource = $_FILES['thumbnail']['tmp_name'];
|
||||
list($intWidth, $intHeight) = getimagesize($strSource);
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
// Condition en fonction de l'extension de l'image
|
||||
$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);
|
||||
|
||||
// Sauvegarde du fichier
|
||||
$boolImageOk = imagewebp($objDest, $strDest);
|
||||
imagedestroy($objDest);
|
||||
imagedestroy($objSource);
|
||||
}
|
||||
|
||||
$objProject = new Project();
|
||||
// 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Créer par Besnik le GOAT et l'autre GOAT de Guillaume
|
||||
*
|
||||
* @return bool pour savoir si le fichier existe,
|
||||
* puis déplace vers le fichier uploads avec les images projet des utilisateurs
|
||||
* Communication avec la BDD
|
||||
*/
|
||||
if (($_SESSION['thumbnail'] != null)){
|
||||
$strDest = "";
|
||||
if ((count($_FILES) > 0) && ($_FILES['imageProject']['error'] != 4)){
|
||||
$strDest = 'uploads/projects/'.$_FILES['imageProject']['name'];
|
||||
move_uploaded_file($_FILES['imageProject']['tmp_name'], $strDest);
|
||||
}
|
||||
}
|
||||
if ($boolOk){
|
||||
// Suppression de l'ancienne image
|
||||
if(isset($strOldImg) && !empty($strOldImg) && isset($strImageName)){
|
||||
$strOldFile = $_ENV['IMG_PATH'].$strOldImg;
|
||||
if (file_exists($strOldFile)) unlink($strOldFile);
|
||||
}
|
||||
|
||||
/** En cas d'appuis sur le bouton d'envoie ou celui de remettre a plus tard
|
||||
* 1. Changement de status
|
||||
* 2. Hydratation avec les informations récupéré de l'utilisateur
|
||||
* 3. Envoie des données à la BDD
|
||||
*/
|
||||
if (isset($_POST['sendMessage'])) {
|
||||
$_SESSION['status'] = 'publié';
|
||||
$objProject->hydrate($_SESSION);
|
||||
$objProject->setThumbnail($strDest);
|
||||
var_dump($strDest);
|
||||
var_dump($objProject);
|
||||
$objProjectModel->insert($objProject);
|
||||
$_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";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else if (isset($_POST['toContinue'])) {
|
||||
$objProject->hydrate($_SESSION);
|
||||
$objProject->setThumbnail($strDest);
|
||||
$objProjectModel->insert($objProject);
|
||||
}
|
||||
|
||||
var_dump($_SESSION);
|
||||
var_dump($objProject);
|
||||
$this->_arrData['arrProjectToDiplay'] = $arrProjectToDisplay;
|
||||
$this->_arrData['arrImageToDiplay'] = $arrImageToDisplay;
|
||||
|
||||
$this->_display("project");
|
||||
}
|
||||
// Données pour la vue
|
||||
$this->_arrData['arrCategory'] = $objCategoryModel->findAllCategory();
|
||||
$this->_arrData['objProject'] = $objProject;
|
||||
$this->_arrData['arrError'] = $arrError;
|
||||
|
||||
$this->_display('addedit_project');
|
||||
}
|
||||
|
||||
public function display() {
|
||||
$intId = $_GET['id'] ?? null;
|
||||
|
|
@ -193,74 +276,68 @@
|
|||
}
|
||||
}
|
||||
|
||||
public function sendEmail(){
|
||||
if (count($_POST) > 0) {
|
||||
|
||||
public function shareProject(){
|
||||
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 = 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.gmail.com";
|
||||
$objMail->Username = "projet.folliow@gmail.com";
|
||||
$objMail->Password = "dqnw mqbu cwvg enbp";
|
||||
|
||||
$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@gmail.com', 'Projet Folliow');
|
||||
|
||||
|
||||
// Destinataire
|
||||
|
||||
$objMail->setFrom('projet.folliow@hotmail.com', 'Folliow');
|
||||
$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
|
||||
|
||||
$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 {
|
||||
// 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;
|
||||
}
|
||||
|
|
@ -306,4 +383,22 @@
|
|||
header("Location: index.php");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Page mentions légales
|
||||
*/
|
||||
public function mentions(){
|
||||
// Afficher
|
||||
$this->_display("mentions");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Page à propos
|
||||
*/
|
||||
public function about(){
|
||||
// Afficher
|
||||
$this->_display("about");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -309,4 +309,5 @@ class UserCtrl extends MotherCtrl {
|
|||
$this->_display("useredit");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue