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->find($_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['imageThumbnail']['error'] != 4){ if (!in_array($_FILES['imageThumbnail']['type'], $arrTypeAllowed)){ $arrError['imageThumbnail'] = "Le type de fichier n'est pas autorisé"; }else{ // Vérification des codes d'erreur switch ($_FILES['imageThumbnail']['error']){ case 0 : // Renommage de l'image $strImageName = uniqid().".webp"; /* uniquement si on veut garder l'extension du fichier originel */ /*switch ($_FILES['img']['type']){ case 'image/jpeg' : $strImageName .= '.jpg'; break; case 'image/png' : $strImageName .= '.png'; break; }*/ // 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 : $arrError['imageThumbnail'] = "Le fichier est trop volumineux"; break; case 2 : $arrError['imageThumbnail'] = "Le fichier est trop volumineux"; break; case 3 : $arrError['imageThumbnail'] = "Le fichier a été partiellement téléchargé"; break; case 6 : $arrError['imageThumbnail'] = "Le répertoire temporaire est manquant"; break; default : $arrError['imageThumbnail'] = "Erreur sur l'image"; break; } } }else{ // Est-ce que le fichier existe ? if (is_null($objProject->getThumbnail())){ $arrError['imageThumbnail'] = "L'image est obligatoire"; } } // Si le formulaire est rempli correctement if (count($arrError) == 0){ if (is_null($objProject->getId())){ // => Ajout dans la base de données $boolOk = $objProjectModel->insert($objProject); }else{ $boolOk = $objProjectModel->updateProject($objProject); } if ($boolOk === true){ if (isset($strImageName)){ // Création du chemin de destination $strDest = $_ENV['IMG_PATH'].$strImageName; // Récupération de la source de l'image $strSource = $_FILES['imageThumbnail']['tmp_name']; // Récupération des dimensions de l'image source list($intWidth, $intHeight) = getimagesize($strSource); // Dimensions de destination $intDestWidth = 200; $intDestHeight = 250; // Calcul du ratio de destination $fltDestRatio = $intDestWidth / $intDestHeight; // Calcul du ratio de la source $fltSourceRatio = $intWidth / $intHeight; // Détermination de la zone à cropper if ($fltSourceRatio > $fltDestRatio) { // L'image source est plus large → on crop en largeur $intCropHeight = $intHeight; $intCropWidth = round($intHeight * $fltDestRatio); $intCropX = ($intWidth - $intCropWidth) / 2; // Centrage horizontal $intCropY = 0; } else { // L'image source est plus haute → on crop en hauteur $intCropWidth = $intWidth; $intCropHeight = round($intWidth / $fltDestRatio); $intCropX = 0; $intCropY = ($intHeight - $intCropHeight) / 2; // Centrage vertical } // Création d'une image 'vide' $objDest = imagecreatetruecolor($intDestWidth, $intDestHeight); // Création d'un objet image à partir de la source (attention au type de fichier) switch ($_FILES['imageThumbnail']['type']){ case 'image/jpeg' : $objSource = imagecreatefromjpeg($strSource); break; case 'image/png' : $objSource = imagecreatefrompng($strSource); break; case 'image/webp' : $objSource = imagecreatefromwebp($strSource); break; } // Mise à jour de l'image 'vide' avec les informations de dimension //imagecopyresized($objDest, $objSource, 0, 0, 0, 0, 200, 250, $intWidth, $intHeight); imagecopyresampled($objDest, $objSource, 0, 0, $intCropX, $intCropY, $intDestWidth, $intDestHeight, $intCropWidth, $intCropHeight); // Si la copie de l'image a bien été effectuée à la destination voulue $boolOk = imagewebp($objDest, $strDest); } if ($boolOk === true){ //if (move_uploaded_file($_FILES['img']['tmp_name'], $strDest)){ // suppression de l'ancienne image $strOldFile = $_ENV['IMG_PATH'].$strOldImg; if (file_exists($strOldFile)){ unlink($strOldFile); } if (is_null($objProject->getId())){ $_SESSION['success'] = "Le projet a bien été créé"; }else{ $_SESSION['success'] = "Le projet a bien été modifié"; } header("Location:index.php"); exit; }else{ $arrError['imageThumbnail'] = "Erreur dans le traitement de l'image"; } }else{ $arrError[] = "Erreur lors de l'ajout"; } } } var_dump($_SESSION); var_dump($objProject); var_dump($arrError); // Données pour la vue $this->_arrData['arrCategory'] = $objCategoryModel->findAllCategory(); $this->_arrData['objProject'] = $objProject; // On passe l'objet à la vue pour pré-remplir les champs $this->_arrData['arrError'] = $arrError; $this->_display('addedit_project'); } 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("project_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 = "

" . $objProject->getTitle() . "

" . "

" . $objProject->getDescription() . "

" . "

Voir le projet

"; // 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; } 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; } 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; } 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; } public function modify(){ //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->modify($intId); //Redirection vers la page projet header("Location: index.php?ctrl=project&action=addedit_project&id=".$intId); exit; } }