get.class.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <?php
  2. class get
  3. {
  4. public static function environnement()
  5. {
  6. if(!isset($_SERVER['HTTP_HOST'])){
  7. return "cms.";
  8. } elseif ($_SERVER['HTTP_HOST'] == DOMAIN_CMS) {
  9. return "cms.";
  10. } elseif ($_SERVER['HTTP_HOST'] == DOMAIN_EVENTS OR $_SERVER['HTTP_HOST'] == DOMAIN_CONTROL) {
  11. return "events.";
  12. }
  13. }
  14. public static function getDefautPage(){
  15. return HOME_TYPE_USER[session::getType()]["home"];
  16. }
  17. public static function isDefautMenu(array $_menu){
  18. return (core::ifGet("p") == FALSE AND in_array(self::getDefautPage(), $_menu)) ? TRUE : FALSE;
  19. }
  20. public static function page(?string $_page = NULL, array $vars = [])
  21. {
  22. if (isset($_page)) {
  23. $page = $_page;
  24. } elseif (core::ifGet("p")) {
  25. $page = core::getGet("p");
  26. } else {
  27. $page = self::getDefautPage();
  28. }
  29. if (access::check($page, "page") || in_array($page, WHITE_ACCESS)) {
  30. $file = DIR_PHP_VIEWS_PAGE . self::environnement() . $page . '.php';
  31. if (file_exists($file)) {
  32. extract($vars); // rend les variables disponibles dans la page
  33. include $file;
  34. } else {
  35. alert::recError("Page introuvable : " . $page);
  36. }
  37. } else {
  38. alert::recError("La page que vous tentez de charger ne vous est pas disponible.");
  39. }
  40. }
  41. public static function submit()
  42. {
  43. if (core::ifPost("from")) {
  44. $submit = core::getPost("from");
  45. } elseif (core::ifGet("from")) {
  46. $submit = core::getGet("from");
  47. } else {
  48. alert::recError("Submit introuvable #1");
  49. header("Location: /");
  50. exit();
  51. }
  52. if (access::ifAccesss($submit)) {
  53. if (file_exists(DIR_PHP_SUBMIT . self::environnement() . $submit . '.php')) {
  54. require_once DIR_PHP_SUBMIT . self::environnement() . $submit . '.php';
  55. } else {
  56. alert::recError("Submit introuvable #2");
  57. header("Location: /");
  58. exit();
  59. }
  60. }
  61. }
  62. public static function javascript(string $_string){
  63. if (file_exists(DIR_PHP_JAVASCRIPT . self::environnement() . $_string . '.php')) {
  64. include DIR_PHP_JAVASCRIPT . self::environnement() . $_string . '.php';
  65. }
  66. }
  67. public static function json()
  68. {
  69. if (core::ifGet("file")) {
  70. if (access::check(core::getGet("file"), "json")) {
  71. // Exception
  72. if(core::getGet("file") == "documents" AND access::ifLimitAccessException("salaire")){
  73. $file = "documents-limited";
  74. } else {
  75. $file = core::getGet("file");
  76. }
  77. // Exception
  78. if (file_exists(DIR_DATAS_JSON . $file . '.json')) {
  79. header('Content-type: application/json');
  80. require_once DIR_DATAS_JSON . $file . '.json';
  81. exit();
  82. } else {
  83. echo json_encode("['No found']");
  84. exit();
  85. }
  86. } else {
  87. header('HTTP/1.0 401 Unauthorized');
  88. exit();
  89. }
  90. }
  91. }
  92. public static function jsonData()
  93. {
  94. if (core::ifGet("jsonData")) {
  95. if (access::check(core::getGet("jsonData"), "json") == TRUE) {
  96. if (file_exists(DIR_DATAS_JSONDATA . self::environnement() . core::getGet("jsonData") . '.php')) {
  97. require_once DIR_DATAS_JSONDATA . self::environnement() . core::getGet("jsonData") . '.php';
  98. exit();
  99. } else {
  100. exit();
  101. }
  102. } else {
  103. header('HTTP/1.0 401 Unauthorized');
  104. exit();
  105. }
  106. }
  107. }
  108. public static function jsonDateDataExcel()
  109. {
  110. db::query("SELECT dateData FROM " . DB_T_EXCEL . " ORDER BY id DESC LIMIT 0, 1");
  111. $data = db::single();
  112. return (isset($data["dateData"])) ? $data["dateData"] : NULL;
  113. }
  114. public static function jsonDateDataExcelProweb()
  115. {
  116. db::query("SELECT dateData FROM " . DB_T_EXCEL_PROWEB . " ORDER BY id DESC LIMIT 0, 1");
  117. $data = db::single();
  118. return (isset($data["dateData"])) ? $data["dateData"] : NULL;
  119. }
  120. public static function jsonDateDataExcelProwebDossiers()
  121. {
  122. db::query("SELECT dateData FROM " . DB_T_EXCEL_PROWEB_DOSSIERS . " ORDER BY id DESC LIMIT 0, 1");
  123. $data = db::single();
  124. return (isset($data["dateData"])) ? $data["dateData"] : NULL;
  125. }
  126. public static function splitIdPage($_page = NULL)
  127. {
  128. $return = array(
  129. "page" => NULL,
  130. "id" => NULL,
  131. );
  132. $split = explode("-", $_page);
  133. foreach ($split as $val) {
  134. if (is_numeric($val)) {
  135. $return["id"] = $val;
  136. } else {
  137. $return["page"] .= $val . "-";
  138. }
  139. }
  140. $return["page"] = substr($return["page"], 0, -1);
  141. return $return;
  142. }
  143. public static function currentPage($_page = NULL)
  144. {
  145. if($_page != NULL){
  146. $page = self::splitIdPage($_page);
  147. } else {
  148. $page = NULL;
  149. }
  150. if (core::getGet("id") == $page["id"] AND core::getGet("p") == $page["page"]) {
  151. return " active";
  152. } elseif (core::getGet("p") == $_page) {
  153. return " active";
  154. } elseif (core::getGet("p") == $_page) {
  155. return " active";
  156. } elseif (self::getDefautPage() == $_page AND core::getGet("p") == $_page) {
  157. return " active";
  158. } elseif (self::getDefautPage() == $_page AND core::getGet("p") == "") {
  159. return " active";
  160. }
  161. }
  162. }