2
0

core.class.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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 convertDate(string $_datetime, bool $_hour = TRUE)
  45. {
  46. $pieces = explode(" ", $_datetime);
  47. $pieces3 = explode(":", $pieces[1]);
  48. $pieces2 = explode("-", $pieces[0]);
  49. if($_hour == TRUE){
  50. return $pieces2[2] . "/" . $pieces2[1] . "/" . $pieces2[0] . " à " . $pieces3[0] . ":" . $pieces3[1];
  51. } else {
  52. return $pieces2[2] . "/" . $pieces2[1] . "/" . $pieces2[0];
  53. }
  54. }
  55. public static function dateFr(string $_timestampMysql = NULL)
  56. {
  57. if ($_timestampMysql == NULL) {
  58. $Now = new DateTime('now', new DateTimeZone(TIME_ZONE));
  59. return $Now->format("d/m/Y H:i:s");
  60. } else {
  61. return DateTime::createFromFormat("d/m/Y H:i:s", $_timestampMysql);
  62. }
  63. }
  64. public static function dateFromTimestamp(int $_timestamp = NULL)
  65. {
  66. if ($_timestamp == NULL) {
  67. return NULL;
  68. } else {
  69. return date("Y-m-d H:i:s", $_timestamp);
  70. }
  71. }
  72. public static function formatFileSize(float $_size, int $_decimalplaces = 0)
  73. {
  74. $sizes = array('O', 'Ko', 'Mo', 'Go', 'To');
  75. for ($i = 0; $_size > 1024 && $i < count($sizes) - 1; $i++) {
  76. $_size /= 1024;
  77. }
  78. return round($_size, $_decimalplaces) . ' ' . $sizes[$i];
  79. }
  80. public static function checkStringOnly(string $_string)
  81. {
  82. if (!ctype_alpha($_string)) {
  83. return TRUE;
  84. } else {
  85. return FALSE;
  86. }
  87. }
  88. public static function print_r(array $_array, int $_exit = NULL)
  89. {
  90. echo "<pre>";
  91. print_r($_array);
  92. echo "</pre>";
  93. ($_exit != NULL) ? exit() : NULL;
  94. }
  95. public static function elementMenu(string $_id, string $_href, string $_titre, string $_feather, string $_style = NULL)
  96. {
  97. ($_style != NULL) ? $_style = ' style="' . $_style . '"' : NULL;
  98. echo '<li class="nav-item">
  99. <a class="nav-link' . get::currentPage($_id) . '" aria-current="page" href="' . $_href . '"' . $_style . '>
  100. <span data-feather="' . $_feather . '"' . $_style . '></span>
  101. ' . $_titre . '
  102. </a>
  103. </li>';
  104. }
  105. public static function elementMenuLink(string $_href, string $_titre, string $_feather, string $_style = NULL, string $_target = "_blank")
  106. {
  107. ($_style != NULL) ? $_style = ' style="' . $_style . '"' : NULL;
  108. echo '<li class="nav-item">
  109. <a class="nav-link" target="'. $_target .'" href="' . $_href . '"' . $_style . '>
  110. <span data-feather="' . $_feather . '"' . $_style . '></span>
  111. ' . $_titre . '
  112. </a>
  113. </li>';
  114. }
  115. public static function elementMenuH6(string $_titre, string $_style = NULL)
  116. {
  117. ($_style != NULL) ? $_style = ' style="' . $_style . '"' : NULL;
  118. echo '<h6 class="sidebar-heading d-flex justify-content-between align-items-center px-3 mt-4 mb-1 text-muted">
  119. <span' . $_style . '>' . $_titre . '</span>
  120. </h6>';
  121. }
  122. public static function filAriane(array $_arbo)
  123. {
  124. $return = '<nav aria-label="breadcrumb bg-300">';
  125. $return .= '<ol class="breadcrumb" style="padding:5px 10px; border-bottom: 1px solid #e9ecef;">';
  126. foreach ($_arbo["arbo"] as $label => $lien) {
  127. if ($_arbo["current"] == $label) {
  128. $return .= '<li class="breadcrumb-item active" aria-current="page">' . $label . '</li>';
  129. } elseif ($lien == NULL) {
  130. $return .= '<li class="breadcrumb-item">' . $label . '</li>';
  131. } else {
  132. $return .= '<li class="breadcrumb-item"><a href="' . $lien . '" title="' . $label . '">' . $label . '</a></li>';
  133. }
  134. }
  135. $return .= '</ol>';
  136. $return .= '</nav>';
  137. return $return;
  138. }
  139. public static function caculPourcentage(?int $_nombre, ?int $_total, int $_pourcentage = 100)
  140. {
  141. if ($_nombre == NULL) return 0;
  142. $resultat = ($_nombre/$_total) * $_pourcentage;
  143. return round($resultat);
  144. }
  145. public static function encodeUTF8(string $_data)
  146. {
  147. return (mb_detect_encoding($_data) != "UTF-8") ? mb_convert_encoding($_data, 'UTF-8', mb_list_encodings()) : $_data;
  148. }
  149. public static function testConnexionInternet()
  150. {
  151. $hosts = ['1.1.1.1', '1.0.0.1', '8.8.8.8', '8.8.4.4'];
  152. foreach ($hosts as $host) {
  153. if ($connected = @fsockopen($host, 443)) {
  154. fclose($connected);
  155. return TRUE;
  156. }
  157. }
  158. return FALSE;
  159. }
  160. public static function printDateTxt()
  161. {
  162. $date = new IntlDateFormatter('fr_FR', IntlDateFormatter::LONG, IntlDateFormatter::NONE);
  163. return $date->format(time()) . " à " . date("H:i:s");
  164. }
  165. public static function addFileMaintenance(){
  166. $myfile = fopen(DOCUMENT_ROOT . FILE_MAINTENANCE, "w");
  167. fclose($myfile);
  168. }
  169. public static function removeFileMaintenance(){
  170. unlink(DOCUMENT_ROOT . FILE_MAINTENANCE);
  171. }
  172. public static function isMaintenance(){
  173. return (file_exists(DOCUMENT_ROOT . FILE_MAINTENANCE)) ? TRUE : FALSE;
  174. }
  175. public static function addFileDebug(){
  176. $myfile = fopen(DOCUMENT_ROOT . FILE_DEBUG, "w");
  177. fclose($myfile);
  178. }
  179. public static function removeFileDebug(){
  180. unlink(DOCUMENT_ROOT . FILE_DEBUG);
  181. }
  182. public static function isDebug(){
  183. return (file_exists(DOCUMENT_ROOT . FILE_DEBUG)) ? TRUE : FALSE;
  184. }
  185. public static function checkboxSelecter(bool $_val){
  186. echo ($_val == TRUE) ? "checked" : "";
  187. }
  188. public static function resetDatas()
  189. {
  190. db::query("TRUNCATE " . DB_T_TEMP_SALARIES);
  191. db::execute();
  192. json::delete("tmp_salaries");
  193. db::query("TRUNCATE " . DB_T_SALARIES);
  194. db::execute();
  195. json::delete("salaries");
  196. db::query("TRUNCATE " . DB_T_FILES);
  197. db::execute();
  198. file::cleanAllFiles(DIR_DATAS_FILES);
  199. db::query("TRUNCATE " . DB_T_EXCEL);
  200. db::execute();
  201. json::delete("excel");
  202. db::query("TRUNCATE " . DB_T_SALARIES_PROWEB);
  203. db::execute();
  204. json::delete("salaries-proweb");
  205. db::query("TRUNCATE " . DB_T_EVENTS_INSCRITS);
  206. db::execute();
  207. db::query("TRUNCATE " . DB_T_EVENTS);
  208. db::execute();
  209. json::delete("events");
  210. db::query("TRUNCATE " . DB_T_EXCEL_PROWEB);
  211. db::execute();
  212. json::delete("excel-proweb");
  213. file::cleanAllFiles(SFTP_LOCAL);
  214. }
  215. public static function base64_url_encode(string $val) {
  216. return strtr(base64_encode($val), '+/=', '-_,');
  217. }
  218. public static function base64_url_decode(string $val) {
  219. return base64_decode(strtr($val, '-_,', '+/='));
  220. }
  221. }