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");
}
}