| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817 |
- <?php
- /**
- * Classe `core`
- *
- * Cette classe fournit des outils utilitaires pour diverses opérations courantes dans l'application.
- *
- * Fonctionnalités principales :
- * - Gestion des données GET, POST et FILES.
- * - Manipulation des dates et des formats.
- * - Gestion des configurations de l'application.
- * - Génération d'éléments d'interface utilisateur (menus, badges, etc.).
- * - Outils divers pour le traitement des chaînes, des fichiers et des données.
- *
- * @package Core\Class
- */
- class core
- {
- /**
- * Vérifie si une variable GET est définie.
- *
- * @param string|null $_string Le nom de la variable GET (optionnel).
- * @return bool TRUE si la variable est définie, FALSE sinon.
- */
- public static function ifGet(?string $_string = NULL)
- {
- if ($_string == NULL) {
- return (empty($_GET)) ? FALSE : TRUE;
- } else {
- if (isset($_GET[$_string])) {
- return TRUE;
- } else {
- return FALSE;
- }
- }
- }
- /**
- * Vérifie si une variable POST est définie.
- *
- * @param string|null $_string Le nom de la variable POST (optionnel).
- * @return bool TRUE si la variable est définie, FALSE sinon.
- */
- public static function ifPost(?string $_string = NULL)
- {
- if ($_string == NULL) {
- return (empty($_POST)) ? FALSE : TRUE;
- } else {
- if (isset($_POST[$_string])) {
- return TRUE;
- } else {
- return FALSE;
- }
- }
- }
- /**
- * Vérifie si une variable FILES est définie.
- *
- * @param string|null $_string Le nom de la variable FILES (optionnel).
- * @return bool TRUE si la variable est définie, FALSE sinon.
- */
- public static function ifFiles(?string $_string = NULL)
- {
- if ($_string == NULL) {
- return (empty($_FILES)) ? FALSE : TRUE;
- } else {
- if (isset($_FILES[$_string]) and $_FILES[$_string]["size"] > 0) {
- return TRUE;
- } else {
- return FALSE;
- }
- }
- }
- /**
- * Récupère une variable GET.
- *
- * @param string|null $_string Le nom de la variable GET (optionnel).
- * @return mixed La valeur de la variable GET ou NULL si non définie.
- */
- public static function getGet(?string $_string = NULL)
- {
- if ($_string == NULL) {
- return $_GET;
- } else {
- if (isset($_GET[$_string])) {
- return $_GET[$_string];
- } else {
- return NULL;
- }
- }
- }
- /**
- * Récupère une variable POST.
- *
- * @param string|null $_string Le nom de la variable POST (optionnel).
- * @return mixed La valeur de la variable POST ou NULL si non définie.
- */
- public static function getPost(?string $_string = NULL)
- {
- if ($_string == NULL) {
- return $_POST;
- } else {
- if (isset($_POST[$_string])) {
- return $_POST[$_string];
- } else {
- return NULL;
- }
- }
- }
- /**
- * Récupère une variable FILES.
- *
- * @param string|null $_string Le nom de la variable FILES (optionnel).
- * @return mixed La valeur de la variable FILES ou NULL si non définie.
- */
- public static function getFiles(?string $_string = NULL)
- {
- if ($_string == NULL) {
- return $_FILES;
- } else {
- if (isset($_FILES[$_string])) {
- return $_FILES[$_string];
- } else {
- return NULL;
- }
- }
- }
- /**
- * Vérifie si une chaîne est présente dans un tableau.
- *
- * @param array $_array Le tableau à vérifier.
- * @param string $_string La chaîne à rechercher.
- * @param int|null $_exact Indique si la correspondance doit être exacte (1 pour oui, NULL pour non).
- * @return bool TRUE si la chaîne est trouvée, FALSE sinon.
- */
- public static function isInArrayString(array $_array, string $_string, ?int $_exact = NULL)
- {
- foreach ($_array as $value) {
- if (strripos($_string, $value) !== FALSE and $_exact == NULL) {
- return TRUE;
- } elseif ($_string == $value and $_exact == 1) {
- return TRUE;
- }
- }
- return FALSE;
- }
- /**
- * Génère un attribut "checked" pour une case à cocher.
- *
- * @param bool $_val Indique si la case doit être cochée.
- * @param int $_echo Indique si le résultat doit être affiché (1) ou retourné (0).
- * @return string|null L'attribut "checked" ou NULL.
- */
- public static function checkboxSelecter(bool $_val, $_echo = 1)
- {
- $tmp = ($_val == TRUE) ? "checked" : "";
- if ($_echo == 1) {
- echo $tmp;
- } else {
- return $tmp;
- }
- }
- /**
- * Récupère toutes les configurations de l'application.
- *
- * @return array|bool Les configurations ou FALSE en cas d'erreur.
- */
- public static function getAllConfig()
- {
- db::query("SELECT "
- . "" . DB_T_CONFIG . ".name, "
- . "" . DB_T_CONFIG . ".value "
- . "FROM " . DB_T_CONFIG);
- return db::resultset();
- }
- /**
- * Récupère une configuration spécifique de l'application.
- *
- * @param string $_name Le nom de la configuration.
- * @return mixed La valeur de la configuration.
- */
- public static function getConfig(string $_name)
- {
- db::query("SELECT value FROM " . DB_T_CONFIG . " WHERE name = :name");
- db::bind(':name', $_name);
- return db::single()["value"];
- }
- /**
- * Met à jour une configuration de l'application.
- *
- * @param string $_name Le nom de la configuration.
- * @param string $_value La nouvelle valeur de la configuration.
- * @return bool TRUE si la mise à jour a réussi, FALSE sinon.
- */
- public static function updateConfig(string $_name, string $_value)
- {
- db::query("UPDATE " . DB_T_CONFIG . " SET "
- . "value = :value "
- . "WHERE name = :name");
- db::bind(':value', $_value);
- db::bind(':name', $_name);
- try {
- db::execute();
- return TRUE;
- } catch (Exception $ex) {
- return FALSE;
- }
- }
- /**
- * Supprime les accents d'une chaîne de caractères.
- *
- * @param string $_data La chaîne à traiter.
- * @return string La chaîne sans accents.
- */
- public static function cleanAccent(string $_data)
- {
- $search = array('À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'à', 'á', 'â', 'ã', 'ä', 'å', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ð', 'ò', 'ó', 'ô', 'õ', 'ö', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ');
- $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');
- $return = str_replace($search, $replace, $_data);
- return strtoupper($return);
- }
- /**
- * Convertit une date MySQL en format français.
- *
- * @param string $_datetime La date au format MySQL.
- * @param bool $_hour Indique si l'heure doit être incluse.
- * @return string La date au format français.
- */
- public static function convertDate(string $_datetime, bool $_hour = TRUE)
- {
- $pieces = explode(" ", $_datetime);
- if ($_hour == TRUE) {
- $pieces3 = explode(":", $pieces[1]);
- }
- $pieces2 = explode("-", $pieces[0]);
- if ($_hour == TRUE) {
- return $pieces2[2] . "/" . $pieces2[1] . "/" . $pieces2[0] . " à " . $pieces3[0] . ":" . $pieces3[1];
- } else {
- return $pieces2[2] . "/" . $pieces2[1] . "/" . $pieces2[0];
- }
- }
- /**
- * Retourne la date actuelle au format français.
- *
- * @param string|null $_timestampMysql Le timestamp MySQL (optionnel).
- * @return string|DateTime La date au format français ou un objet DateTime.
- */
- public static function dateFr(?string $_timestampMysql = NULL)
- {
- if ($_timestampMysql == NULL) {
- $Now = new DateTime('now', new DateTimeZone(TIME_ZONE));
- return $Now->format("d/m/Y H:i:s");
- } else {
- return DateTime::createFromFormat("d/m/Y H:i:s", $_timestampMysql);
- }
- }
- /**
- * Convertit un timestamp en date.
- *
- * @param int|null $_timestamp Le timestamp à convertir (optionnel).
- * @return string|null La date au format MySQL ou NULL si aucun timestamp n'est fourni.
- */
- public static function dateFromTimestamp(?int $_timestamp = NULL)
- {
- if ($_timestamp == NULL) {
- return NULL;
- } else {
- return date("Y-m-d H:i:s", $_timestamp);
- }
- }
- /**
- * Extrait la date sans l'heure d'une chaîne datetime.
- *
- * @param string $_datetime La chaîne datetime.
- * @return string La date sans l'heure.
- */
- public static function dateWhithoutHours(string $_datetime)
- {
- return explode(" ", $_datetime)[0];
- }
- /**
- * Formate une taille de fichier en unités lisibles.
- *
- * @param float $_size La taille en octets.
- * @param int $_decimalplaces Le nombre de décimales à inclure.
- * @return string La taille formatée.
- */
- public static function formatFileSize(float $_size, int $_decimalplaces = 0)
- {
- $sizes = array('O', 'Ko', 'Mo', 'Go', 'To');
- for ($i = 0; $_size > 1024 && $i < count($sizes) - 1; $i++) {
- $_size /= 1024;
- }
- return round($_size, $_decimalplaces) . ' ' . $sizes[$i];
- }
- /**
- * Formate un montant en euros.
- *
- * @param float $_amount Le montant à formater.
- * @return string Le montant formaté en euros.
- */
- public static function formatEuro($_amount)
- {
- $amount = (float)$_amount;
- $formattedAmount = number_format($amount, 2, ',', ' ');
- return $formattedAmount . ' €';
- }
- /**
- * Vérifie si une chaîne ne contient que des caractères alphabétiques.
- *
- * @param string $_string La chaîne à vérifier.
- * @return bool TRUE si la chaîne contient uniquement des lettres, FALSE sinon.
- */
- public static function checkStringOnly(string $_string)
- {
- if (!ctype_alpha($_string)) {
- return TRUE;
- } else {
- return FALSE;
- }
- }
- /**
- * Génère un élément de menu.
- *
- * @param string $_id L'identifiant de l'élément de menu.
- * @param string $_href L'URL de destination.
- * @param string $_titre Le titre de l'élément de menu.
- * @param string|null $_style Le style CSS à appliquer (optionnel).
- * @param string|null $_icon L'icône à afficher (optionnel).
- * @return void
- */
- public static function elementMenu(string $_id, string $_href, string $_titre, ?string $_style = NULL, ?string $_icon = NULL)
- {
- if (access::ifAccesss($_id)) {
- ($_style != NULL) ? $_style = ' style="' . $_style . '"' : NULL;
- echo '<li class="nav-item" style="margin:5px 0;"><a style="display:unset;" class="nav-link' . get::currentPage($_id) . '" aria-current="page" href="' . $_href . '"' . $_style . '>';
- echo (preg_match('/^compte-\d+$/', $_id)) ? icon::getFont(["type" => $_icon, "size" => "18px"]) : icon::getFont(["type" => $_id, "size" => "18px"]);
- echo ' ' . $_titre . '</a></li>';
- }
- }
- /**
- * Génère un élément de menu avec un lien.
- *
- * @param string $_id L'identifiant de l'élément de menu.
- * @param string $_href L'URL de destination.
- * @param string $_titre Le titre de l'élément de menu.
- * @param string|null $_style Le style CSS à appliquer (optionnel).
- * @param string $_target La cible du lien (par défaut "_blank").
- * @return void
- */
- public static function elementMenuLink(string $_id, string $_href, string $_titre, ?string $_style = NULL, string $_target = "_blank")
- {
- if (access::ifAccesss($_id)) {
- ($_style != NULL) ? $_style = ' style="' . $_style . '"' : NULL;
- echo '<li class="nav-item" style="margin:5px 0;"><a style="display:unset;" class="nav-link" target="' . $_target . '" href="' . $_href . '"' . $_style . '>';
- echo icon::getFont(["type" => $_id, "size" => "18px"]);
- echo ' ' . $_titre . '</a></li>';
- }
- }
- /**
- * Génère un en-tête de section.
- *
- * @param string $_id L'identifiant de l'en-tête.
- * @param string $_titre Le titre de l'en-tête.
- * @param string|null $_style Le style CSS à appliquer (optionnel).
- * @param string|null $_collapse L'identifiant de la section à réduire/étendre (optionnel).
- * @return void
- */
- public static function elementMenuH6(string $_id, string $_titre, ?string $_style = NULL, ?string $_collapse = NULL)
- {
- if (access::ifAccesss($_id)) {
- ($_style != NULL) ? $_style = $_style : NULL;
- echo '<h6 class="sidebar-heading d-flex justify-content-between align-items-center px-3 mt-4 mb-1 text-muted">
- <a style="text-decoration: none; ' . $_style . '" href="#' . $_collapse . '" data-toggle="collapse" aria-expanded="false" class="dropdown-toggle text-dark">' . $_titre . '</a>
- </h6>';
- }
- }
- /**
- * Génère une fil d'Ariane (breadcrumb).
- *
- * @param array $_arbo Les éléments de la fil d'Ariane.
- * @return string Le code HTML de la fil d'Ariane.
- */
- public static function filAriane(array $_arbo)
- {
- $return = '<nav aria-label="breadcrumb bg-300">';
- $return .= '<ol class="breadcrumb" style="padding:5px 10px; border-bottom: 1px solid #e9ecef;">';
- foreach ($_arbo["arbo"] as $label => $lien) {
- if ($_arbo["current"] == $label) {
- $return .= '<li class="breadcrumb-item active" aria-current="page"';
- if (isset($_arbo["refresh-json"])) {
- $return .= 'title="Cliquez ici pour rafraichir les données Json" onclick="return confirm(\'Voulez-vous rafraichir les données Json?\')" id="json-refresh"><a href="#" style="text-decoration:none;">' . icon::getFont(["icon" => "bi bi-arrow-clockwise"]) . ' ';
- } else {
- $return .= '>';
- }
- $return .= $label;
- if (isset($_arbo["refresh-json"])) {
- $return .= '</a>';
- }
- $return .= '</li>';
- } elseif ($lien == NULL) {
- $return .= '<li class="breadcrumb-item">' . $label . '</li>';
- } else {
- $return .= '<li class="breadcrumb-item"><a href="' . $lien . '" title="' . $label . '">' . $label . '</a></li>';
- }
- }
- $return .= '</ol>';
- $return .= '</nav>';
- if (isset($_arbo["refresh-json"])) {
- $return .= "<script>
- $('#json-refresh').on('click', function() {
- $.ajax({
- url: '/json.refresh.php',
- type: 'GET',
- data: {
- data: '" . $_arbo["refresh-json"] . "'
- },
- success: function(response) {
- $('#printToastSuccessTxt').html('Mise à jour du Json. Rechargement dans quelques secondes...');
- $('#printToastSuccess').toast('show');
- $('#printToastSuccess').on('hidden.bs.toast', function () {
- location.reload();
- });
- },
- error: function(xhr, status, error) {
- $('#printToastErrorTxt').html('Erreur lors de la mise à jour du Json');
- $('#printToastError').toast('show');
- }
- });
- });
- </script>";
- }
- return $return;
- }
- /**
- * Calcule un pourcentage.
- *
- * @param int|null $_nombre Le nombre partiel.
- * @param int|null $_total Le nombre total.
- * @param int $_pourcentage Le pourcentage à calculer (par défaut 100).
- * @return int Le pourcentage calculé.
- */
- public static function caculPourcentage(?int $_nombre, ?int $_total, int $_pourcentage = 100)
- {
- if ($_nombre == NULL) return 0;
- $resultat = ($_nombre / $_total) * $_pourcentage;
- return round($resultat);
- }
- /**
- * Encode une chaîne en UTF-8.
- *
- * @param string $_data La chaîne à encoder.
- * @return string La chaîne encodée en UTF-8.
- */
- public static function encodeUTF8(string $_data)
- {
- return (mb_detect_encoding($_data) != "UTF-8") ? mb_convert_encoding($_data, 'UTF-8', mb_list_encodings()) : $_data;
- }
- /**
- * Vérifie la connexion à Internet.
- *
- * @return bool TRUE si connecté, FALSE sinon.
- */
- public static function testConnexionInternet()
- {
- $hosts = ['1.1.1.1', '1.0.0.1', '8.8.8.8', '8.8.4.4'];
- foreach ($hosts as $host) {
- if ($connected = @fsockopen($host, 443)) {
- fclose($connected);
- return TRUE;
- }
- }
- return FALSE;
- }
- /**
- * Retourne la date et l'heure actuelles au format texte.
- *
- * @return string La date et l'heure au format texte.
- */
- public static function printDateTxt()
- {
- $date = new IntlDateFormatter('fr_FR', IntlDateFormatter::LONG, IntlDateFormatter::NONE);
- return $date->format(time()) . " à " . date("H:i:s");
- }
- /**
- * Réinitialise les données dans la base de données.
- *
- * @return void
- */
- public static function resetDatas()
- {
- db::query("TRUNCATE " . DB_T_TEMP_SALARIES);
- db::execute();
- json::delete("tmp_salaries");
- db::query("TRUNCATE " . DB_T_SALARIES);
- db::execute();
- json::delete("salaries");
- db::query("TRUNCATE " . DB_T_FILES);
- db::execute();
- file::cleanAllFiles(DIR_DATAS_FILES);
- db::query("TRUNCATE " . DB_T_EXCEL);
- db::execute();
- json::delete("excel");
- db::query("TRUNCATE " . DB_T_SALARIES_PROWEB);
- db::execute();
- json::delete("salaries-proweb");
- db::query("TRUNCATE " . DB_T_EVENTS_INSCRITS);
- db::execute();
- db::query("TRUNCATE " . DB_T_EVENTS);
- db::execute();
- json::delete("events");
- db::query("TRUNCATE " . DB_T_EXCEL_PROWEB);
- db::execute();
- json::delete("excel-proweb");
- file::cleanAllFiles(SFTP_LOCAL);
- }
- /**
- * Encode une chaîne en base64 pour une utilisation dans une URL.
- *
- * @param string $val La chaîne à encoder.
- * @return string La chaîne encodée en base64.
- */
- public static function base64_url_encode(string $val)
- {
- return strtr(base64_encode($val), '+/=', '-_,');
- }
- /**
- * Décode une chaîne base64 encodée pour une utilisation dans une URL.
- *
- * @param string $val La chaîne à décoder.
- * @return string La chaîne décodée.
- */
- public static function base64_url_decode(string $val)
- {
- return base64_decode(strtr($val, '-_,', '+/='));
- }
- /**
- * Convertit un texte en UTF-8 si nécessaire.
- *
- * @param string $_texte Le texte à convertir.
- * @return string Le texte converti en UTF-8.
- */
- public static function convertirEnUtf8(string $_texte)
- {
- if (!mb_detect_encoding($_texte, 'UTF-8', TRUE)) {
- return mb_convert_encoding($_texte, 'UTF-8', 'auto');
- } else {
- return $_texte;
- }
- }
- /**
- * Imprime une option sélectionnée dans un formulaire.
- *
- * @param mixed $_value La valeur à comparer.
- * @param string|null $_string La valeur de l'option.
- * @return void
- */
- public static function printFormSelectOption($_value, ?string $_string = NULL)
- {
- if ($_string != NULL and $_string == $_value) {
- echo " selected";
- }
- }
- /**
- * Récupère la valeur d'un formulaire.
- *
- * @param string|null $_string La valeur à récupérer.
- * @return string|null La valeur récupérée ou NULL.
- */
- public static function getFormValue(?string $_string = NULL)
- {
- if ($_string != NULL) {
- return $_string;
- }
- }
- /**
- * Imprime la valeur d'un formulaire.
- *
- * @param string|null $_string La valeur à imprimer.
- * @return void
- */
- public static function printFormValue(?string $_string = NULL)
- {
- if ($_string != NULL) {
- echo $_string;
- }
- }
- /**
- * Convertit des octets entre différentes unités.
- *
- * @param float $val La valeur à convertir.
- * @param string $type_val L'unité d'origine.
- * @param string $type_wanted L'unité cible.
- * @param bool $_float Indique si le résultat doit être un flottant.
- * @return string La valeur convertie avec l'unité cible.
- */
- public static function convertBytes(float $val, string $type_val = "o", string $type_wanted = "Mo", bool $_float = FALSE)
- {
- $tab_val = array("o", "ko", "Mo", "Go", "To", "Po", "Eo");
- if (!(in_array($type_val, $tab_val) && in_array($type_wanted, $tab_val)))
- return 0;
- $tab = array_flip($tab_val);
- $diff = $tab[$type_val] - $tab[$type_wanted];
- $type_wanted_print = $_float == FALSE ? $type_wanted : NULL;
- if ($diff > 0)
- return round(($val * pow(1024, $diff)), 2) . $type_wanted_print;
- if ($diff < 0)
- return round(($val / pow(1024, -$diff)), 2) . $type_wanted_print;
- return round(($val), 2) . $type_wanted_print;
- }
- /**
- * Récupère la taille de la base de données.
- *
- * @return array Les informations sur la taille de la base de données.
- */
- public static function getSizeDataBase()
- {
- db::query("SELECT
- table_schema AS nameDB,
- ROUND(SUM( data_length + index_length ) / 1024 / 1024, 2) AS moDB
- FROM information_schema.TABLES
- WHERE TABLE_SCHEMA = '" . DB_NAME . "'");
- return db::single();
- }
- /**
- * Génère une barre de progression avec des avertissements.
- *
- * @param float $_num La valeur actuelle.
- * @param float $_max La valeur maximale.
- * @param string $_label L'étiquette de la barre de progression.
- * @param string $_icon L'icône à afficher.
- * @return void
- */
- public static function progressBarWarning(float $_num, float $_max, string $_label, string $_icon)
- {
- $changeUnit = 1073741824;
- $valueUnitNum = $_num >= $changeUnit ? "Go" : "Mo";
- $valueUnitMax = $_max >= $changeUnit ? "Go" : "Mo";
- $pourcentage = number_format(($_num / $_max) * 100, 2);
- if ($pourcentage < 50) {
- $infos = ["color" => "bg-success"];
- } elseif ($pourcentage < 75) {
- $infos = ["color" => "bg-warning"];
- } else {
- $infos = ["color" => "bg-danger"];
- }
- echo ' <div class="mb-3" style="margin:10px 0;">
- <label class="form-label" style=""><i class="' . $_icon . '" style="font-size:18px; margin:4px;"></i> <span style="font-weight: bold;">' . $_label . '</span> [' . core::convertBytes($_num, "o", $valueUnitNum) . ' / ' . core::convertBytes($_max, "o", $valueUnitMax) . ']</label>
- <div class="progress" role="progressbar" aria-label="Success example" aria-valuenow="' . $pourcentage . '" aria-valuemin="0" aria-valuemax="100">
- <div class="progress-bar ' . $infos["color"] . '" style="width: ' . $pourcentage . '%">' . $pourcentage . '%</div>
- </div>
- </div>';
- }
- /**
- * Génère un badge d'alerte si nécessaire.
- *
- * @param bool $_alerte Indique si l'alerte doit être affichée.
- * @return string|null Le code HTML du badge ou NULL.
- */
- static public function printBadgeGeneral(bool $_alerte)
- {
- return $_alerte == TRUE ? '<span class="position-absolute start-100 translate-middle p-1 bg-danger border border-light rounded-circle"></span>' : NULL;
- }
- /**
- * Vérifie les alertes pour les documents.
- *
- * @return array Les informations sur les alertes.
- */
- static public function ifbadge()
- {
- $return = [];
- $return["DOC"] = document::badgeAlert();
- if ($return["DOC"] != NULL) {
- $return["ALERTE"] = TRUE;
- } else {
- $return["ALERTE"] = FALSE;
- }
- return $return;
- }
- /**
- * Génère un menu de navigation.
- *
- * @param array $_navInfos Les informations de navigation.
- * @return void
- */
- static public function menu(array $_navInfos)
- {
- $badge = self::ifbadge();
- echo '<a href="/" style="box-shadow: none; background-color:' . $_navInfos["color"] . ';" class="navbar-brand">' . $_navInfos["title"] . '</a>' . debug::getBadges();
- echo '<div id="navbarCollapse" class="collapse navbar-collapse p-0">';
- echo '<ul class="nav navbar-nav ms-auto">';
- echo '<li class="nav-item dropdown">';
- echo '<a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown">' . session::getName() . self::printBadgeGeneral($badge["ALERTE"]) . '</a>';
- echo '<div class="dropdown-menu dropdown-menu-end">';
- echo '<a href="/user.html" class="dropdown-item">Mon profil</a>';
- if ((access::ifAccesss("documents") and session::getType() == 5) or session::getType() == 1) { // Membre du bureau ou Admin
- $nb = $badge["DOC"] > 0 ? '<span class="position-absolute badge rounded-pill bg-danger" style="right:-10px; margin-top:-10px;">' . $badge["DOC"] . '</span>' : NULL;
- echo '<a href="/documents-my-assign.html" class="dropdown-item">Vos assignations' . $nb . '</a>';
- echo '<a href="/alertes-emails.html" class="dropdown-item">Vos règles d\'alertes</a>';
- }
- echo '<div class="dropdown-divider"></div>';
- echo '<a href="/submit.php?from=logout" class="dropdown-item">Se déconnecter</a>';
- echo '</li>';
- echo '</div>';
- echo '</ul>';
- echo '</div>';
- }
- /**
- * Récupère l'adresse IP de l'utilisateur.
- *
- * @return string L'adresse IP de l'utilisateur.
- */
- static public function getUserIP()
- {
- $ip = 'Inconnue';
- if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
- // IP partagée par un proxy
- $ip = $_SERVER['HTTP_CLIENT_IP'];
- } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
- // IP du client derrière un proxy
- $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
- } else {
- // IP du client directement connectée au serveur
- $ip = $_SERVER['REMOTE_ADDR'];
- }
- // Nettoyage des IPs multiples dans le cas de 'HTTP_X_FORWARDED_FOR'
- if (strpos($ip, ',') !== false) {
- $ip = explode(',', $ip)[0];
- }
- return $ip;
- }
- /**
- * Aplatit un tableau multidimensionnel.
- *
- * @param array|null $_array Le tableau à aplatir (optionnel).
- * @return array|null Le tableau aplati ou NULL.
- */
- static public function extractArrayInArray(?array $_array = NULL)
- {
- if ($_array != NULL) {
- foreach ($_array as $item) {
- foreach ($item as $key => $value) {
- $flattened[$key] = $value;
- }
- }
- } else {
- $flattened = NULL;
- }
- return $flattened;
- }
- }
|