session.class.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 getType(string $_type = "user")
  21. {
  22. return $_SESSION[$_type]["idType"];
  23. }
  24. public static function isConnect(string $_type = "user")
  25. {
  26. return (isset($_SESSION[$_type]["id"])) ? TRUE : FALSE;
  27. }
  28. public static function access(array $_type){
  29. return (in_array($_SESSION["user"]["idType"], $_type)) ? TRUE : FALSE;
  30. }
  31. public static function isEspaceControleurs(){
  32. return ($_SERVER['HTTP_HOST'] == DOMAIN_CONTROL) ? TRUE : FALSE;
  33. }
  34. public static function isEspaceSalaries(){
  35. return ($_SERVER['HTTP_HOST'] == DOMAIN_EVENTS) ? TRUE : FALSE;
  36. }
  37. public static function setTemp(array $_array, string $_name = NULL){
  38. if($_name == NULL){
  39. $_SESSION["TEMP"]["tmp"] = $_array;
  40. } else {
  41. $_SESSION["TEMP"][$_name] = $_array;
  42. }
  43. }
  44. public static function getTemp(string $_name = NULL){
  45. if(empty($_SESSION["TEMP"])){
  46. return NULL;
  47. } elseif($_name == NULL){
  48. $return = $_SESSION["TEMP"]["tmp"];
  49. } else {
  50. $return = $_SESSION["TEMP"][$_name];
  51. }
  52. self::resetTemp();
  53. return $return;
  54. }
  55. public static function resetTemp(string $_name = NULL){
  56. unset($_SESSION["TEMP"]);
  57. }
  58. }