| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <?php
- class session
- {
- public static function createSession(array $_array, string $_type = "user")
- {
- $_SESSION[$_type] = $_array;
- }
- public static function getId(string $_type = "user")
- {
- return $_SESSION[$_type]["id"];
- }
- public static function getValue(string $_val, string $_type = "user")
- {
- return $_SESSION[$_type][$_val];
- }
- public static function getName(string $_type = "user")
- {
- return $_SESSION[$_type]["prenom"] . " " . $_SESSION[$_type]["nom"];
- }
- public static function isConnect(string $_type = "user")
- {
- return (isset($_SESSION[$_type]["id"])) ? TRUE : FALSE;
- }
- public static function accessUserByType(int $_type)
- {
- if (isset($_SESSION["user"]["id"])) {
- if ($_SESSION["user"]["idType"] == 1) {
- return TRUE;
- } elseif ($_SESSION["user"]["idType"] == 4 and $_type == 4) {
- return TRUE;
- } elseif ($_SESSION["user"]["idType"] == 2 and $_type == 2) {
- return TRUE;
- } elseif ($_SESSION["user"]["idType"] == 3 and $_type == 3) {
- return TRUE;
- } else {
- return FALSE;
- }
- } else {
- return FALSE;
- }
- }
- public static function access(array $_type){
- return (in_array($_SESSION["user"]["idType"], $_type)) ? TRUE : FALSE;
- }
- public static function accessElement(string $_element, string $_type)
- {
- // Eléments autorisé sans authentification
- if (self::elementWhite($_element, $_type)) {
- return TRUE;
- } else {
- if (isset($_SESSION["salarie"]["id"])) { // Espaces spécifiques aux Salariés
- if (self::elementSalaries($_element, $_type)) {
- return TRUE;
- }
- } elseif (isset($_SESSION["user"]["idType"]) and $_SESSION["user"]["idType"] == 2) { // Espaces spécifiques aux Contrôleurs
- if (self::elementControleurs($_element, $_type)) {
- return TRUE;
- }
- } elseif (isset($_SESSION["user"]["idType"]) and $_SESSION["user"]["idType"] == 3) { // Espaces spécifiques aux Contrôleurs
- if (self::elementServiceSocial($_element, $_type)) {
- return TRUE;
- }
- } elseif (isset($_SESSION["user"]["idType"]) and $_SESSION["user"]["idType"] == 4) { // Espaces spécifiques aux Modérateurs du CMS
- if (self::elementModerateur($_element, $_type)) {
- return TRUE;
- }
- } elseif (isset($_SESSION["user"]["idType"]) and $_SESSION["user"]["idType"] == 1) { // Espaces spécifiques aux Admins
- return TRUE;
- }
- }
- return FALSE;
- }
- public static function accessNotConnected(string $_element, string $_type)
- {
- return (in_array($_element, NOT_CONNECTED[$_type])) ? TRUE : FALSE;
- }
- private static function elementWhite(string $_element, string $_type)
- {
- return (in_array($_element, ACCESS_WHITE[$_type])) ? TRUE : FALSE;
- }
- private static function elementModerateur(string $_element, string $_type)
- {
- switch ($_type) {
- case 'page':
- $noAccessPage = array(
- "parametres",
- );
- return (core::isInArrayString($noAccessPage, $_element)) ? FALSE : TRUE;
- break;
- case 'submit':
- $noAccessSubmit = array(
- "parametres",
- );
- return (core::isInArrayString($noAccessSubmit, $_element)) ? FALSE : TRUE;
- break;
- case 'json':
- $noAccessJson = array(
- "parametres",
- );
- return (core::isInArrayString($noAccessJson, $_element)) ? FALSE : TRUE;
- break;
- default:
- return TRUE;
- break;
- }
- }
- private static function elementSalaries(string $_element, string $_type)
- {
- return (in_array($_element, ACCESS_SALARIES[$_type])) ? TRUE : FALSE;
- }
- private static function elementControleurs(string $_element, string $_type)
- {
- return (in_array($_element, ACCESS_CONTROLEURS[$_type])) ? TRUE : FALSE;
- }
- private static function elementServiceSocial(string $_element, string $_type)
- {
- return (in_array($_element, ACCESS_SOCIAL[$_type])) ? TRUE : FALSE;
- }
- }
|