2
0

session.class.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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"] == 2 and $_type == 2) {
  30. return TRUE;
  31. } elseif ($_SESSION["user"]["idType"] == 3 and $_type == 3) {
  32. return TRUE;
  33. } else {
  34. return FALSE;
  35. }
  36. } else {
  37. return FALSE;
  38. }
  39. }
  40. public static function accessElement(string $_element, string $_type)
  41. {
  42. // Eléments autorisé sans authentification
  43. if (self::elementWhite($_element, $_type)) {
  44. return TRUE;
  45. } else {
  46. if (isset($_SESSION["salarie"]["id"])) { // Espaces spécifiques aux Salariés
  47. if (self::elementSalaries($_element, $_type)) {
  48. return TRUE;
  49. }
  50. } elseif (isset($_SESSION["user"]["idType"]) and $_SESSION["user"]["idType"] == 2) { // Espaces spécifiques aux Contrôleurs
  51. if (self::elementControleurs($_element, $_type)) {
  52. return TRUE;
  53. }
  54. } elseif (isset($_SESSION["user"]["idType"]) and $_SESSION["user"]["idType"] == 3) { // Espaces spécifiques aux Contrôleurs
  55. if (self::elementServiceSocial($_element, $_type)) {
  56. return TRUE;
  57. }
  58. } elseif (isset($_SESSION["user"]["idType"]) and $_SESSION["user"]["idType"] == 1) { // Espaces spécifiques aux Admins
  59. return TRUE;
  60. }
  61. }
  62. return FALSE;
  63. }
  64. private static function elementWhite(string $_element, string $_type)
  65. {
  66. return (in_array($_element, ACCESS_WHITE[$_type])) ? TRUE : FALSE;
  67. }
  68. private static function elementSalaries(string $_element, string $_type)
  69. {
  70. return (in_array($_element, ACCESS_SALARIES[$_type])) ? TRUE : FALSE;
  71. }
  72. private static function elementControleurs(string $_element, string $_type)
  73. {
  74. return (in_array($_element, ACCESS_CONTROLEURS[$_type])) ? TRUE : FALSE;
  75. }
  76. private static function elementServiceSocial(string $_element, string $_type)
  77. {
  78. return (in_array($_element, ACCESS_SOCIAL[$_type])) ? TRUE : FALSE;
  79. }
  80. }