58 lines
2 KiB
PHP
58 lines
2 KiB
PHP
<?php
|
|
|
|
require("./models/project_model.php");
|
|
require("./entities/project_entity.php");
|
|
require("./models/category_model.php");
|
|
require("./entities/category_entity.php");
|
|
require("./models/image_model.php");
|
|
require("./entities/image_entity.php");
|
|
require("./models/user_model.php");
|
|
require("./entities/user_entity.php");
|
|
require("mother_controller.php");
|
|
|
|
/**
|
|
* Le controller de la partie accessible uniquement par l'admin
|
|
* @author Laura
|
|
*/
|
|
|
|
class AdminCtrl extends MotherCtrl{
|
|
|
|
public function admin(){
|
|
|
|
if (!isset($_SESSION['user']) && ($_SESSION['user']['user_status'] != 1 )){
|
|
header("Location:index.php?ctrl=error&action=error_403");
|
|
exit;
|
|
}
|
|
$objCategoryModel = new CategoryModel;
|
|
|
|
if (!empty($_POST['new_category'])) {
|
|
$newCat = new Category();
|
|
$newCat->setName($_POST['new_category']);
|
|
$objCategoryModel->insertCategory($newCat);
|
|
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;
|
|
}
|
|
|
|
$arrCategory = $objCategoryModel->findAllCategory();
|
|
$arrCategoryToDisplay = array();
|
|
|
|
foreach($arrCategory as $arrDetCategory){
|
|
$objCategory = new Category;
|
|
$objCategory->hydrate($arrDetCategory);
|
|
$arrCategoryToDisplay[] = $objCategory;
|
|
}
|
|
|
|
//gérer l'affichage
|
|
$this->_arrData['arrCategoryToDisplay'] = $arrCategoryToDisplay;
|
|
$this->_display("admin");
|
|
}
|
|
}
|