|
|
@ -19,19 +19,20 @@ class ControllerAdminAdministrators
|
|
|
|
session_start();
|
|
|
|
session_start();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
|
|
if($_SESSION["idAdminConnected"] != null){
|
|
|
|
if ($_SESSION["idAdminConnected"] != null) {
|
|
|
|
$this->twig =$twig;
|
|
|
|
$this->twig = $twig;
|
|
|
|
$this->vues = $vues;
|
|
|
|
$this->vues = $vues;
|
|
|
|
|
|
|
|
|
|
|
|
$this->mdAdministrator = new ModelAdministrator();
|
|
|
|
$this->mdAdministrator = new ModelAdministrator();
|
|
|
|
|
|
|
|
|
|
|
|
$administrators = $this->mdAdministrator->getAdministrators();
|
|
|
|
$administrators = $this->mdAdministrator->getAdministrators();
|
|
|
|
|
|
|
|
|
|
|
|
echo $twig->render($vues["adminAdministrators"], [
|
|
|
|
echo $twig->render($vues["adminAdministrators"], [
|
|
|
|
'administrators' => $administrators,
|
|
|
|
'administrators' => $administrators,
|
|
|
|
|
|
|
|
'error' => $_SESSION["error"],
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
$_SESSION["error"] = null;
|
|
|
|
else {
|
|
|
|
} else {
|
|
|
|
header("Location:/loginAdmin");
|
|
|
|
header("Location:/loginAdmin");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (PDOException $e) {
|
|
|
|
} catch (PDOException $e) {
|
|
|
@ -41,27 +42,42 @@ class ControllerAdminAdministrators
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function delete($param) {
|
|
|
|
function delete($param)
|
|
|
|
|
|
|
|
{
|
|
|
|
$this->mdAdministrator->deleteAdministratorByID($param["id"]);
|
|
|
|
$this->mdAdministrator->deleteAdministratorByID($param["id"]);
|
|
|
|
header("Location:/admin/administrators");
|
|
|
|
header("Location:/admin/administrators");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function add($param) {
|
|
|
|
function add($param)
|
|
|
|
|
|
|
|
{
|
|
|
|
$username = $_POST['username'];
|
|
|
|
var_dump($_SERVER['REQUEST_METHOD'] !== 'POST');
|
|
|
|
$password = $_POST['password'];
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
|
|
|
|
|
|
|
$_SESSION["error"]="Méthode non autorisée.";
|
|
|
|
$Admin = [
|
|
|
|
} else {
|
|
|
|
'username' => $username,
|
|
|
|
$username = $_POST['username'];
|
|
|
|
'password' => $password,
|
|
|
|
$password = $_POST['password'];
|
|
|
|
];
|
|
|
|
$username = trim($_POST['username']);
|
|
|
|
|
|
|
|
$password = trim($_POST['password']);
|
|
|
|
$this->mdAdministrator->addAdministrator($Admin);
|
|
|
|
var_dump(!isset($_POST['username']) || !isset($_POST['password']) || empty($username) || empty($password));
|
|
|
|
|
|
|
|
if (!isset($username) || !isset($password) || empty($username) || empty($password)) {
|
|
|
|
header("Location:/admin/administrators");
|
|
|
|
$_SESSION["error"]="Veuillez remplir tous les champs.";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$Admin = [
|
|
|
|
|
|
|
|
'username' => $username,
|
|
|
|
|
|
|
|
'password' => $password,
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
if ($this->mdAdministrator->verifyAdministratorByName($Admin) != null) {
|
|
|
|
|
|
|
|
$_SESSION["error"]="Cet admin existe déjà.";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$this->mdAdministrator->addAdministrator($Admin);
|
|
|
|
|
|
|
|
header("Location:/admin/administrators");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function updatemodal($param) {
|
|
|
|
function updatemodal($param)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
$administrator = $this->mdAdministrator->getAdministratorByID($param["id"]);
|
|
|
|
$administrator = $this->mdAdministrator->getAdministratorByID($param["id"]);
|
|
|
|
|
|
|
|
|
|
|
@ -70,7 +86,8 @@ class ControllerAdminAdministrators
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function update($param) {
|
|
|
|
function update($param)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
$id = $_POST['id'];
|
|
|
|
$id = $_POST['id'];
|
|
|
|
$username = $_POST['username'];
|
|
|
|
$username = $_POST['username'];
|
|
|
@ -81,8 +98,8 @@ class ControllerAdminAdministrators
|
|
|
|
'password' => $password,
|
|
|
|
'password' => $password,
|
|
|
|
];
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
$this->mdAdministrator->updateAdministrator($id,$Admin);
|
|
|
|
$this->mdAdministrator->updateAdministrator($id, $Admin);
|
|
|
|
|
|
|
|
|
|
|
|
header("Location:/admin/administrators");
|
|
|
|
header("Location:/admin/administrators");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|