Merge branch 'laura' of https://github.com/Yasder5/projet_php into laura
This commit is contained in:
commit
4d834823e7
123 changed files with 2589 additions and 13232 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;
|
||||
|
|
@ -306,4 +389,4 @@
|
|||
header("Location: index.php");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -151,37 +151,38 @@ class UserCtrl extends MotherCtrl {
|
|||
*/
|
||||
public function user(){
|
||||
|
||||
$intId = isset($_GET['id']) ? (int)$_GET['id'] : 0;
|
||||
$intId = isset($_GET['id']) ? (int)$_GET['id'] : 0;
|
||||
|
||||
if ($intId <= 0) {
|
||||
header("Location: index.php");
|
||||
exit;
|
||||
}
|
||||
if ($intId <= 0) {
|
||||
header("Location:index.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
//affichage info utilisateur
|
||||
$objUserModel = new UserModel;
|
||||
$arrUserData = $objUserModel->findUserById($intId);
|
||||
//affichage info utilisateur
|
||||
$objUserModel = new UserModel;
|
||||
$arrUserData = $objUserModel->findUserById($intId);
|
||||
|
||||
if ($arrUserData === false) {
|
||||
header("Location: index.php");
|
||||
exit;
|
||||
}
|
||||
$objUser = new User;
|
||||
$objUser->hydrate($arrUserData);
|
||||
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,'',$intId);
|
||||
//affichage projet de l'utilisateur
|
||||
$objProjectModel = new ProjectModel;
|
||||
$arrProjects = $objProjectModel->findAll(0,'',$intId);
|
||||
|
||||
$arrProjectToDisplay = array();
|
||||
foreach($arrProjects as $projectData) {
|
||||
$objProject = new Project();
|
||||
$objProject->hydrate($projectData);
|
||||
$arrProjectToDisplay[] = $objProject;
|
||||
}
|
||||
$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");
|
||||
$this->_arrData['user'] = $objUser;
|
||||
$this->_arrData['arrProjectToDisplay'] = $arrProjectToDisplay;
|
||||
$this->_display("user");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue