2
0

core.class.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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 dateFromTimestamp(int $_timestamp = NULL)
  100. {
  101. if ($_timestamp == NULL) {
  102. return NULL;
  103. } else {
  104. return date("Y-m-d H:i:s", $_timestamp);
  105. }
  106. }
  107. public static function dateWhithoutHours(string $_datetime)
  108. {
  109. return explode(" ", $_datetime)[0];
  110. }
  111. public static function formatFileSize(float $_size, int $_decimalplaces = 0)
  112. {
  113. $sizes = array('O', 'Ko', 'Mo', 'Go', 'To');
  114. for ($i = 0; $_size > 1024 && $i < count($sizes) - 1; $i++) {
  115. $_size /= 1024;
  116. }
  117. return round($_size, $_decimalplaces) . ' ' . $sizes[$i];
  118. }
  119. public static function checkStringOnly(string $_string)
  120. {
  121. if (!ctype_alpha($_string)) {
  122. return TRUE;
  123. } else {
  124. return FALSE;
  125. }
  126. }
  127. public static function print_r(array $_array, int $_exit = NULL)
  128. {
  129. echo "<pre>";
  130. print_r($_array);
  131. echo "</pre>";
  132. ($_exit != NULL) ? exit() : NULL;
  133. }
  134. public static function elementMenu(string $_id, string $_href, string $_titre, string $_feather, string $_style = NULL)
  135. {
  136. ($_style != NULL) ? $_style = ' style="' . $_style . '"' : NULL;
  137. echo '<li class="nav-item">
  138. <a class="nav-link' . get::currentPage($_id) . '" aria-current="page" href="' . $_href . '"' . $_style . '>
  139. <span data-feather="' . $_feather . '"' . $_style . '></span>
  140. ' . $_titre . '
  141. </a>
  142. </li>';
  143. }
  144. public static function elementMenuLink(string $_href, string $_titre, string $_feather, string $_style = NULL, string $_target = "_blank")
  145. {
  146. ($_style != NULL) ? $_style = ' style="' . $_style . '"' : NULL;
  147. echo '<li class="nav-item">
  148. <a class="nav-link" target="'. $_target .'" href="' . $_href . '"' . $_style . '>
  149. <span data-feather="' . $_feather . '"' . $_style . '></span>
  150. ' . $_titre . '
  151. </a>
  152. </li>';
  153. }
  154. public static function elementMenuH6(string $_titre, string $_style = NULL)
  155. {
  156. ($_style != NULL) ? $_style = ' style="' . $_style . '"' : NULL;
  157. echo '<h6 class="sidebar-heading d-flex justify-content-between align-items-center px-3 mt-4 mb-1 text-muted">
  158. <span' . $_style . '>' . $_titre . '</span>
  159. </h6>';
  160. }
  161. public static function filAriane(array $_arbo)
  162. {
  163. $return = '<nav aria-label="breadcrumb bg-300">';
  164. $return .= '<ol class="breadcrumb" style="padding:5px 10px; border-bottom: 1px solid #e9ecef;">';
  165. foreach ($_arbo["arbo"] as $label => $lien) {
  166. if ($_arbo["current"] == $label) {
  167. $return .= '<li class="breadcrumb-item active" aria-current="page">' . $label . '</li>';
  168. } elseif ($lien == NULL) {
  169. $return .= '<li class="breadcrumb-item">' . $label . '</li>';
  170. } else {
  171. $return .= '<li class="breadcrumb-item"><a href="' . $lien . '" title="' . $label . '">' . $label . '</a></li>';
  172. }
  173. }
  174. $return .= '</ol>';
  175. $return .= '</nav>';
  176. return $return;
  177. }
  178. public static function caculPourcentage(?int $_nombre, ?int $_total, int $_pourcentage = 100)
  179. {
  180. if ($_nombre == NULL) return 0;
  181. $resultat = ($_nombre/$_total) * $_pourcentage;
  182. return round($resultat);
  183. }
  184. public static function encodeUTF8(string $_data)
  185. {
  186. return (mb_detect_encoding($_data) != "UTF-8") ? mb_convert_encoding($_data, 'UTF-8', mb_list_encodings()) : $_data;
  187. }
  188. public static function testConnexionInternet()
  189. {
  190. $hosts = ['1.1.1.1', '1.0.0.1', '8.8.8.8', '8.8.4.4'];
  191. foreach ($hosts as $host) {
  192. if ($connected = @fsockopen($host, 443)) {
  193. fclose($connected);
  194. return TRUE;
  195. }
  196. }
  197. return FALSE;
  198. }
  199. public static function printDateTxt()
  200. {
  201. $date = new IntlDateFormatter('fr_FR', IntlDateFormatter::LONG, IntlDateFormatter::NONE);
  202. return $date->format(time()) . " à " . date("H:i:s");
  203. }
  204. public static function addFileMaintenance(){
  205. $myfile = fopen(DOCUMENT_ROOT . FILE_MAINTENANCE, "w");
  206. fclose($myfile);
  207. }
  208. public static function removeFileMaintenance(){
  209. unlink(DOCUMENT_ROOT . FILE_MAINTENANCE);
  210. }
  211. public static function isMaintenance(){
  212. return (file_exists(DOCUMENT_ROOT . FILE_MAINTENANCE)) ? TRUE : FALSE;
  213. }
  214. public static function addFileDebug(){
  215. $myfile = fopen(DOCUMENT_ROOT . FILE_DEBUG, "w");
  216. fclose($myfile);
  217. }
  218. public static function removeFileDebug(){
  219. unlink(DOCUMENT_ROOT . FILE_DEBUG);
  220. }
  221. public static function isDebug(){
  222. return (file_exists(DOCUMENT_ROOT . FILE_DEBUG)) ? TRUE : FALSE;
  223. }
  224. public static function resetDatas()
  225. {
  226. db::query("TRUNCATE " . DB_T_TEMP_SALARIES);
  227. db::execute();
  228. json::delete("tmp_salaries");
  229. db::query("TRUNCATE " . DB_T_SALARIES);
  230. db::execute();
  231. json::delete("salaries");
  232. db::query("TRUNCATE " . DB_T_FILES);
  233. db::execute();
  234. file::cleanAllFiles(DIR_DATAS_FILES);
  235. db::query("TRUNCATE " . DB_T_EXCEL);
  236. db::execute();
  237. json::delete("excel");
  238. db::query("TRUNCATE " . DB_T_SALARIES_PROWEB);
  239. db::execute();
  240. json::delete("salaries-proweb");
  241. db::query("TRUNCATE " . DB_T_EVENTS_INSCRITS);
  242. db::execute();
  243. db::query("TRUNCATE " . DB_T_EVENTS);
  244. db::execute();
  245. json::delete("events");
  246. db::query("TRUNCATE " . DB_T_EXCEL_PROWEB);
  247. db::execute();
  248. json::delete("excel-proweb");
  249. file::cleanAllFiles(SFTP_LOCAL);
  250. }
  251. public static function base64_url_encode(string $val) {
  252. return strtr(base64_encode($val), '+/=', '-_,');
  253. }
  254. public static function base64_url_decode(string $val) {
  255. return base64_decode(strtr($val, '-_,', '+/='));
  256. }
  257. }