You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
2.0 KiB
55 lines
2.0 KiB
<?php
|
|
class FrontController
|
|
{
|
|
function __construct()
|
|
{
|
|
try {
|
|
global $error, $view, $rep;
|
|
$nettoyage = new Nettoyage();
|
|
session_start();
|
|
// Check role permissions
|
|
if (isset($_SESSION['role'])) {
|
|
$role = $nettoyage->clean($_SESSION['role']);
|
|
} else {
|
|
$role = "visitor";
|
|
}
|
|
// Check if action exists
|
|
//echo "FrontConroller : action = " . $_REQUEST['action'] . "<br>";
|
|
//echo "role = " . $role . "<br>";
|
|
$action = $nettoyage->clean($_REQUEST['action']);
|
|
if ($role == "user") {
|
|
if ($action == NULL) {
|
|
$_REQUEST['action'] = $action;
|
|
new UserController();
|
|
} else if (method_exists('UserController', $action) == false) {
|
|
$error = "Action non valide " . $action;
|
|
require($rep . $view['erreur']);
|
|
} else {
|
|
//echo "action user valide";
|
|
$_REQUEST['action'] = $action;
|
|
new UserController();
|
|
}
|
|
}
|
|
else if ($role == "admin") {
|
|
if ($action == NULL) {
|
|
$_REQUEST['action'] = $action;
|
|
new AdminController();
|
|
} else if (method_exists('AdminController', $action) == false) {
|
|
$error = "Action non valide" . $action;
|
|
require($rep . $view['erreur']);
|
|
} else {
|
|
//echo "action admin valide";
|
|
$_REQUEST['action'] = $action;
|
|
new AdminController();
|
|
}
|
|
} else {
|
|
//echo "action visiteur";
|
|
$_REQUEST['action'] = $action;
|
|
new VisitorController();
|
|
}
|
|
} catch (Exception $e) {
|
|
$error = $e->getMessage();
|
|
require($rep . $view['erreur']);
|
|
}
|
|
}
|
|
} |