session.class.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. class session
  3. {
  4. public static function createSession(array $_array, string $_type = "user")
  5. {
  6. $_SESSION[$_type] = $_array;
  7. }
  8. public static function getId(string $_type = "user")
  9. {
  10. return $_SESSION[$_type]["id"];
  11. }
  12. public static function getValue(string $_val, string $_type = "user")
  13. {
  14. return $_SESSION[$_type][$_val];
  15. }
  16. public static function getName(string $_type = "user")
  17. {
  18. return $_SESSION[$_type]["prenom"] . " " . $_SESSION[$_type]["nom"];
  19. }
  20. public static function isConnect(string $_type = "user")
  21. {
  22. return (isset($_SESSION[$_type]["id"])) ? TRUE : FALSE;
  23. }
  24. public static function accessUserByType(int $_type)
  25. {
  26. if (isset($_SESSION["user"]["id"])) {
  27. if ($_SESSION["user"]["idType"] == 1) {
  28. return TRUE;
  29. } elseif ($_SESSION["user"]["idType"] == 4 and $_type == 4) {
  30. return TRUE;
  31. } elseif ($_SESSION["user"]["idType"] == 2 and $_type == 2) {
  32. return TRUE;
  33. } elseif ($_SESSION["user"]["idType"] == 3 and $_type == 3) {
  34. return TRUE;
  35. } else {
  36. return FALSE;
  37. }
  38. } else {
  39. return FALSE;
  40. }
  41. }
  42. public static function access(array $_type){
  43. return (in_array($_SESSION["user"]["idType"], $_type)) ? TRUE : FALSE;
  44. }
  45. public static function accessElement(string $_element, string $_type)
  46. {
  47. // Eléments autorisé sans authentification
  48. if (self::elementWhite($_element, $_type)) {
  49. return TRUE;
  50. } else {
  51. if (isset($_SESSION["salarie"]["id"])) { // Espaces spécifiques aux Salariés
  52. if (self::elementSalaries($_element, $_type)) {
  53. return TRUE;
  54. }
  55. } elseif (isset($_SESSION["user"]["idType"]) and $_SESSION["user"]["idType"] == 2) { // Espaces spécifiques aux Contrôleurs
  56. if (self::elementControleurs($_element, $_type)) {
  57. return TRUE;
  58. }
  59. } elseif (isset($_SESSION["user"]["idType"]) and $_SESSION["user"]["idType"] == 3) { // Espaces spécifiques aux Contrôleurs
  60. if (self::elementServiceSocial($_element, $_type)) {
  61. return TRUE;
  62. }
  63. } elseif (isset($_SESSION["user"]["idType"]) and $_SESSION["user"]["idType"] == 4) { // Espaces spécifiques aux Modérateurs du CMS
  64. if (self::elementModerateur($_element, $_type)) {
  65. return TRUE;
  66. }
  67. } elseif (isset($_SESSION["user"]["idType"]) and $_SESSION["user"]["idType"] == 1) { // Espaces spécifiques aux Admins
  68. return TRUE;
  69. }
  70. }
  71. return FALSE;
  72. }
  73. public static function accessNotConnected(string $_element, string $_type)
  74. {
  75. return (in_array($_element, NOT_CONNECTED[$_type])) ? TRUE : FALSE;
  76. }
  77. private static function elementWhite(string $_element, string $_type)
  78. {
  79. return (in_array($_element, ACCESS_WHITE[$_type])) ? TRUE : FALSE;
  80. }
  81. private static function elementModerateur(string $_element, string $_type)
  82. {
  83. switch ($_type) {
  84. case 'page':
  85. $noAccessPage = array(
  86. "parametres",
  87. );
  88. return (core::isInArrayString($noAccessPage, $_element)) ? FALSE : TRUE;
  89. break;
  90. case 'submit':
  91. $noAccessSubmit = array(
  92. "parametres",
  93. );
  94. return (core::isInArrayString($noAccessSubmit, $_element)) ? FALSE : TRUE;
  95. break;
  96. case 'json':
  97. $noAccessJson = array(
  98. "parametres",
  99. );
  100. return (core::isInArrayString($noAccessJson, $_element)) ? FALSE : TRUE;
  101. break;
  102. default:
  103. return TRUE;
  104. break;
  105. }
  106. }
  107. private static function elementSalaries(string $_element, string $_type)
  108. {
  109. return (in_array($_element, ACCESS_SALARIES[$_type])) ? TRUE : FALSE;
  110. }
  111. private static function elementControleurs(string $_element, string $_type)
  112. {
  113. return (in_array($_element, ACCESS_CONTROLEURS[$_type])) ? TRUE : FALSE;
  114. }
  115. private static function elementServiceSocial(string $_element, string $_type)
  116. {
  117. return (in_array($_element, ACCESS_SOCIAL[$_type])) ? TRUE : FALSE;
  118. }
  119. }