Début de la fonctionnalité de dépôt de Img dans le projet

This commit is contained in:
GuillaumeH-Cci 2026-02-10 16:17:59 +01:00
parent 4e9b27772b
commit 1df2ed36a5
35 changed files with 2014 additions and 168 deletions

View file

@ -8,6 +8,8 @@
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");
/**
@ -18,33 +20,33 @@
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;
}*/
}
//gestion de l'user
$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;
}
$newCat = new Category();
$newCat->setName($_POST['new_category']);
$objCategoryModel->insertCategory($newCat);
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;
}
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);
header('Location: index.php?ctrl=admin&action=admin');
exit;
}
//affichage select des catégories
$arrCategory = $objCategoryModel->findAllCategory();
$arrCategoryToDisplay = array();
@ -53,10 +55,56 @@
$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['message_success'] = "Le statut a bien été modifié !";
}
}
elseif ($_POST['action'] === 'delete_user') {
$objUserModel->delete_soft($intUserId);
$_SESSION['message_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;
}
// Il faudra donner à maman et gérer l'affichage quand Smarty sera prêt
$this->_arrData['arrCategoryToDisplay'] = $arrCategoryToDisplay;
//$this->_arrData['intCategory'] = $objCategoryModel->;
//gérer l'affichage
$this->_arrData['arrCategoryToDisplay'] = $arrCategoryToDisplay;
$this->_arrData['arrUserToDisplay'] = $arrUserToDisplay;
$this->_arrData['arrAuthorisationToDisplay'] = $arrAuthorisationToDisplay;
$this->_display("admin");
}
}

View file

@ -23,9 +23,20 @@
*/
public function home(){
$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();
$arrProject = $objProjectModel->findAll(0,'',0,0,'','','',$intCategory,$boolOld);
$arrProjectToDisplay = array();
foreach($arrProject as $arrDetProject){
$objProject = new Project;
@ -34,8 +45,6 @@
}
$this->_arrData['arrProjectToDisplay'] = $arrProjectToDisplay;
$this->_display("home");
}
@ -43,8 +52,8 @@
/**
* 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;
@ -87,8 +96,6 @@
/**
* Fonction d'affichage de la page projet
*/
public function project (){
$objProjectModel = new ProjectModel;
@ -112,33 +119,33 @@
$_SESSION['title'] = $_POST['titleProject']??"";
$_SESSION['description'] = $_POST['descProject']??"";
$_SESSION['content'] = $_POST['textProject']??"";
$_SESSION['thumbnail'] = $_FILES['imageProject']['name']??"";
$_SESSION['thumbnail'] = $_FILES['imageThumbnail']['name']??"";
$_SESSION['status'] = 'en_attente';
$objProject = new Project();
/**
/* 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
* 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 = '../public/uploads/projects/'.$_FILES['imageProject']['name'];
$strDest = 'uploads/projects/'.$_FILES['imageProject']['name'];
var_dump($strDest);
move_uploaded_file($_FILES['imageProject']['tmp_name'], $strDest);
}
}
/** 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
*/
* 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);
@ -151,14 +158,12 @@
$objProjectModel->insert($objProject);
}
//Débuggage
var_dump($_SESSION);
var_dump($objProject);
$this->_arrData['arrProjectToDiplay'] = $arrProjectToDiplay;
$this->_arrData['arrImageToDiplay'] = $arrImageToDiplay;
$this->_display("project");
}

View file

@ -41,12 +41,8 @@ class UserCtrl extends MotherCtrl {
}
}
$this->_arrData['arrError'] = $arrError;
$this->_display("login");
}