core.class.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <?php
  2. class core
  3. {
  4. public static function ifGet(string $_string)
  5. {
  6. if (isset($_GET[$_string])) {
  7. return TRUE;
  8. } else {
  9. return FALSE;
  10. }
  11. }
  12. public static function ifPost(string $_string)
  13. {
  14. if (isset($_POST[$_string])) {
  15. return TRUE;
  16. } else {
  17. return FALSE;
  18. }
  19. }
  20. public static function getGet(string $_string = NULL)
  21. {
  22. if ($_string == NULL) {
  23. return $_GET;
  24. } else {
  25. if (isset($_GET[$_string])) {
  26. return $_GET[$_string];
  27. } else {
  28. return NULL;
  29. }
  30. }
  31. }
  32. public static function getPost(string $_string = NULL)
  33. {
  34. if ($_string == NULL) {
  35. return $_POST;
  36. } else {
  37. if (isset($_POST[$_string])) {
  38. return $_POST[$_string];
  39. } else {
  40. return NULL;
  41. }
  42. }
  43. }
  44. public static function cleanAccent(string $_data)
  45. {
  46. $search = array('À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'à', 'á', 'â', 'ã', 'ä', 'å', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ð', 'ò', 'ó', 'ô', 'õ', 'ö', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ');
  47. $replace = array('A', 'A', 'A', 'A', 'A', 'A', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 'a', 'a', 'a', 'a', 'a', 'a', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y');
  48. $return = str_replace($search, $replace, $_data);
  49. return strtoupper($return);
  50. }
  51. public static function convertDate(string $_datetime, bool $_hour = TRUE)
  52. {
  53. $pieces = explode(" ", $_datetime);
  54. $pieces3 = explode(":", $pieces[1]);
  55. $pieces2 = explode("-", $pieces[0]);
  56. if($_hour == TRUE){
  57. return $pieces2[2] . "/" . $pieces2[1] . "/" . $pieces2[0] . " à " . $pieces3[0] . ":" . $pieces3[1];
  58. } else {
  59. return $pieces2[2] . "/" . $pieces2[1] . "/" . $pieces2[0];
  60. }
  61. }
  62. public static function dateFr(string $_timestampMysql = NULL)
  63. {
  64. if ($_timestampMysql == NULL) {
  65. $Now = new DateTime('now', new DateTimeZone(TIME_ZONE));
  66. return $Now->format("d/m/Y H:i:s");
  67. } else {
  68. return DateTime::createFromFormat("d/m/Y H:i:s", $_timestampMysql);
  69. }
  70. }
  71. public static function dateFromTimestamp(int $_timestamp = NULL)
  72. {
  73. if ($_timestamp == NULL) {
  74. return NULL;
  75. } else {
  76. return date("Y-m-d H:i:s", $_timestamp);
  77. }
  78. }
  79. public static function formatFileSize(float $_size, int $_decimalplaces = 0)
  80. {
  81. $sizes = array('O', 'Ko', 'Mo', 'Go', 'To');
  82. for ($i = 0; $_size > 1024 && $i < count($sizes) - 1; $i++) {
  83. $_size /= 1024;
  84. }
  85. return round($_size, $_decimalplaces) . ' ' . $sizes[$i];
  86. }
  87. public static function checkStringOnly(string $_string)
  88. {
  89. if (!ctype_alpha($_string)) {
  90. return TRUE;
  91. } else {
  92. return FALSE;
  93. }
  94. }
  95. public static function print_r(array $_array, int $_exit = NULL)
  96. {
  97. echo "<pre>";
  98. print_r($_array);
  99. echo "</pre>";
  100. ($_exit != NULL) ? exit() : NULL;
  101. }
  102. public static function elementMenu(string $_id, string $_href, string $_titre, string $_feather, string $_style = NULL)
  103. {
  104. ($_style != NULL) ? $_style = ' style="' . $_style . '"' : NULL;
  105. echo '<li class="nav-item">
  106. <a class="nav-link' . get::currentPage($_id) . '" aria-current="page" href="' . $_href . '"' . $_style . '>
  107. <span data-feather="' . $_feather . '"' . $_style . '></span>
  108. ' . $_titre . '
  109. </a>
  110. </li>';
  111. }
  112. public static function elementMenuLink(string $_href, string $_titre, string $_feather, string $_style = NULL, string $_target = "_blank")
  113. {
  114. ($_style != NULL) ? $_style = ' style="' . $_style . '"' : NULL;
  115. echo '<li class="nav-item">
  116. <a class="nav-link" target="'. $_target .'" href="' . $_href . '"' . $_style . '>
  117. <span data-feather="' . $_feather . '"' . $_style . '></span>
  118. ' . $_titre . '
  119. </a>
  120. </li>';
  121. }
  122. public static function elementMenuH6(string $_titre, string $_style = NULL)
  123. {
  124. ($_style != NULL) ? $_style = ' style="' . $_style . '"' : NULL;
  125. echo '<h6 class="sidebar-heading d-flex justify-content-between align-items-center px-3 mt-4 mb-1 text-muted">
  126. <span' . $_style . '>' . $_titre . '</span>
  127. </h6>';
  128. }
  129. public static function filAriane(array $_arbo)
  130. {
  131. $return = '<nav aria-label="breadcrumb bg-300">';
  132. $return .= '<ol class="breadcrumb" style="padding:5px 10px; border-bottom: 1px solid #e9ecef;">';
  133. foreach ($_arbo["arbo"] as $label => $lien) {
  134. if ($_arbo["current"] == $label) {
  135. $return .= '<li class="breadcrumb-item active" aria-current="page">' . $label . '</li>';
  136. } elseif ($lien == NULL) {
  137. $return .= '<li class="breadcrumb-item">' . $label . '</li>';
  138. } else {
  139. $return .= '<li class="breadcrumb-item"><a href="' . $lien . '" title="' . $label . '">' . $label . '</a></li>';
  140. }
  141. }
  142. $return .= '</ol>';
  143. $return .= '</nav>';
  144. return $return;
  145. }
  146. public static function caculPourcentage(?int $_nombre, ?int $_total, int $_pourcentage = 100)
  147. {
  148. if ($_nombre == NULL) return 0;
  149. $resultat = ($_nombre/$_total) * $_pourcentage;
  150. return round($resultat);
  151. }
  152. public static function encodeUTF8(string $_data)
  153. {
  154. return (mb_detect_encoding($_data) != "UTF-8") ? mb_convert_encoding($_data, 'UTF-8', mb_list_encodings()) : $_data;
  155. }
  156. public static function testConnexionInternet()
  157. {
  158. $hosts = ['1.1.1.1', '1.0.0.1', '8.8.8.8', '8.8.4.4'];
  159. foreach ($hosts as $host) {
  160. if ($connected = @fsockopen($host, 443)) {
  161. fclose($connected);
  162. return TRUE;
  163. }
  164. }
  165. return FALSE;
  166. }
  167. public static function printDateTxt()
  168. {
  169. $date = new IntlDateFormatter('fr_FR', IntlDateFormatter::LONG, IntlDateFormatter::NONE);
  170. return $date->format(time()) . " à " . date("H:i:s");
  171. }
  172. public static function addFileMaintenance(){
  173. $myfile = fopen(DOCUMENT_ROOT . FILE_MAINTENANCE, "w");
  174. fclose($myfile);
  175. }
  176. public static function removeFileMaintenance(){
  177. unlink(DOCUMENT_ROOT . FILE_MAINTENANCE);
  178. }
  179. public static function isMaintenance(){
  180. return (file_exists(DOCUMENT_ROOT . FILE_MAINTENANCE)) ? TRUE : FALSE;
  181. }
  182. public static function addFileDebug(){
  183. $myfile = fopen(DOCUMENT_ROOT . FILE_DEBUG, "w");
  184. fclose($myfile);
  185. }
  186. public static function removeFileDebug(){
  187. unlink(DOCUMENT_ROOT . FILE_DEBUG);
  188. }
  189. public static function isDebug(){
  190. return (file_exists(DOCUMENT_ROOT . FILE_DEBUG)) ? TRUE : FALSE;
  191. }
  192. public static function checkboxSelecter(bool $_val){
  193. echo ($_val == TRUE) ? "checked" : "";
  194. }
  195. public static function resetDatas()
  196. {
  197. db::query("TRUNCATE " . DB_T_TEMP_SALARIES);
  198. db::execute();
  199. json::delete("tmp_salaries");
  200. db::query("TRUNCATE " . DB_T_SALARIES);
  201. db::execute();
  202. json::delete("salaries");
  203. db::query("TRUNCATE " . DB_T_FILES);
  204. db::execute();
  205. file::cleanAllFiles(DIR_DATAS_FILES);
  206. db::query("TRUNCATE " . DB_T_EXCEL);
  207. db::execute();
  208. json::delete("excel");
  209. db::query("TRUNCATE " . DB_T_SALARIES_PROWEB);
  210. db::execute();
  211. json::delete("salaries-proweb");
  212. db::query("TRUNCATE " . DB_T_EVENTS_INSCRITS);
  213. db::execute();
  214. db::query("TRUNCATE " . DB_T_EVENTS);
  215. db::execute();
  216. json::delete("events");
  217. db::query("TRUNCATE " . DB_T_EXCEL_PROWEB);
  218. db::execute();
  219. json::delete("excel-proweb");
  220. file::cleanAllFiles(SFTP_LOCAL);
  221. }
  222. public static function base64_url_encode(string $val) {
  223. return strtr(base64_encode($val), '+/=', '-_,');
  224. }
  225. public static function base64_url_decode(string $val) {
  226. return base64_decode(strtr($val, '-_,', '+/='));
  227. }
  228. }