core.class.php 9.3 KB

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