| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359 |
- <?php
- /**
- * Classe json
- *
- * Cette classe étend la classe db et fournit des méthodes pour gérer la création, la suppression et la manipulation de fichiers JSON.
- */
- class json extends db
- {
- /**
- * Crée un fichier JSON en fonction de la cible spécifiée.
- *
- * @param string $_target La cible pour laquelle le fichier JSON doit être créé.
- * @return int|mixed Résultat de la création du fichier JSON.
- */
- public static function create(string $_target)
- {
- if (isset($_target)) {
- if (preg_match('/^banque-lignes-(\d+)$/', $_target, $matches)) {
- return self::create_banque_lignes((int)$matches[1]);
- }
- switch ($_target) {
- case "salaries":
- return self::create_salaries();
- break;
- case "excel":
- return self::create_excel();
- break;
- case "excel-proweb":
- return self::create_excelProweb();
- break;
- case "excel-proweb-dossiers":
- return self::create_excelProwebDossiers();
- break;
- case "events":
- return self::create_events();
- break;
- case "users":
- return self::create_users();
- break;
- case "salaries-proweb":
- return self::create_salariesProweb();
- break;
- case "dossiers-proweb":
- return self::create_dossiersProweb();
- break;
- case "lotterys":
- return self::create_lotterys();
- break;
- case "banque-csv":
- return self::create_banque_csv();
- break;
- case "documents":
- return self::create_document();
- break;
- case "documents-limited":
- return self::create_document("limited");
- break;
- }
- } else {
- return 0;
- }
- }
- /**
- * Crée des fichiers JSON pour toutes les banques disponibles.
- */
- public static function createBanks()
- {
- foreach (banque::getAll() as $compte) {
- self::create_banque_lignes($compte["id"]);
- }
- }
- /**
- * Crée un fichier JSON pour les dossiers Proweb.
- *
- * @return int Succès ou échec de la création du fichier.
- */
- private static function create_dossiersProweb()
- {
- $row = prowebDossiers::all();
- if (file_put_contents(DIR_DATAS_JSON . "dossiers-proweb.json", json_encode($row))) {
- return 1;
- } else {
- return 0;
- }
- }
- /**
- * Crée un fichier JSON pour les salariés Proweb.
- *
- * @return int Succès ou échec de la création du fichier.
- */
- private static function create_salariesProweb()
- {
- $row = proweb::getBase();
- if (file_put_contents(DIR_DATAS_JSON . "salaries-proweb.json", json_encode($row))) {
- return 1;
- } else {
- return 0;
- }
- }
- /**
- * Crée un fichier JSON pour les salariés.
- *
- * @return int Succès ou échec de la création du fichier.
- */
- private static function create_salaries()
- {
- $row = salaries::getSalaries();
- if (file_put_contents(DIR_DATAS_JSON . "salaries.json", json_encode($row))) {
- return 1;
- } else {
- return 0;
- }
- }
- /**
- * Crée un fichier JSON pour les données Excel.
- *
- * @return int Succès ou échec de la création du fichier.
- */
- private static function create_excel()
- {
- db::query("SELECT
- " . DB_T_EXCEL . ".id,
- " . DB_T_FILES . ".name,
- " . DB_T_EXCEL . ".nbSalaries,
- CONCAT(ROUND((" . DB_T_FILES . ".size / 1024 / 1024), 2), ' Mo') AS size,
- " . DB_T_EXCEL . ".md5,
- " . DB_T_EXCEL . ".cree,
- CONCAT (" . DB_T_USER . ".prenom, ' ', " . DB_T_USER . ".nom) AS 'user',
- dateData,
- goMysql,
- md5forSFTP,
- log
- FROM " . DB_T_EXCEL . "
- INNER JOIN " . DB_T_USER . " ON " . DB_T_EXCEL . ".id_user = " . DB_T_USER . ".id
- LEFT JOIN " . DB_T_FILES . " ON " . DB_T_EXCEL . ".md5 = " . DB_T_FILES . ".id");
- $row = db::resultset();
- if (file_put_contents(DIR_DATAS_JSON . "excel.json", json_encode($row))) {
- return 1;
- } else {
- return 0;
- }
- }
- /**
- * Crée un fichier JSON pour les données Excel Proweb.
- *
- * @return int Succès ou échec de la création du fichier.
- */
- private static function create_excelProweb()
- {
- db::query("SELECT
- " . DB_T_EXCEL_PROWEB . ".id,
- " . DB_T_FILES . ".name,
- " . DB_T_EXCEL_PROWEB . ".nbSalaries,
- CONCAT(ROUND((" . DB_T_FILES . ".size / 1024 / 1024), 2), ' Mo') AS size,
- " . DB_T_EXCEL_PROWEB . ".md5,
- " . DB_T_EXCEL_PROWEB . ".cree,
- CONCAT (" . DB_T_USER . ".prenom, ' ', " . DB_T_USER . ".nom) AS 'user',
- dateData
- FROM " . DB_T_EXCEL_PROWEB . "
- INNER JOIN " . DB_T_USER . " ON " . DB_T_EXCEL_PROWEB . ".id_user = " . DB_T_USER . ".id
- LEFT JOIN " . DB_T_FILES . " ON " . DB_T_EXCEL_PROWEB . ".md5 = " . DB_T_FILES . ".id");
- $row = db::resultset();
- if (file_put_contents(DIR_DATAS_JSON . "excel-proweb.json", json_encode($row))) {
- return 1;
- } else {
- return 0;
- }
- }
- /**
- * Crée un fichier JSON pour les dossiers Excel Proweb.
- *
- * @return int Succès ou échec de la création du fichier.
- */
- private static function create_excelProwebDossiers(){
- db::query("SELECT
- " . DB_T_EXCEL_PROWEB_DOSSIERS . ".id,
- " . DB_T_FILES . ".name,
- " . DB_T_EXCEL_PROWEB_DOSSIERS . ".nbDossiers,
- CONCAT(ROUND((" . DB_T_FILES . ".size / 1024 / 1024), 2), ' Mo') AS size,
- " . DB_T_EXCEL_PROWEB_DOSSIERS . ".md5,
- " . DB_T_EXCEL_PROWEB_DOSSIERS . ".cree,
- CONCAT (" . DB_T_USER . ".prenom, ' ', " . DB_T_USER . ".nom) AS 'user',
- dateData
- FROM " . DB_T_EXCEL_PROWEB_DOSSIERS . "
- INNER JOIN " . DB_T_USER . " ON " . DB_T_EXCEL_PROWEB_DOSSIERS . ".id_user = " . DB_T_USER . ".id
- LEFT JOIN " . DB_T_FILES . " ON " . DB_T_EXCEL_PROWEB_DOSSIERS . ".md5 = " . DB_T_FILES . ".id");
- $row = db::resultset();
- if (file_put_contents(DIR_DATAS_JSON . "excel-proweb-dossiers.json", json_encode($row))) {
- return 1;
- } else {
- return 0;
- }
- }
- /**
- * Crée un fichier JSON pour les événements.
- *
- * @return int Succès ou échec de la création du fichier.
- */
- private static function create_events()
- {
- $row = event::getEvents();
- if (file_put_contents(DIR_DATAS_JSON . "events.json", json_encode($row))) {
- return 1;
- } else {
- return 0;
- }
- }
- /**
- * Crée un fichier JSON pour les loteries.
- *
- * @return int Succès ou échec de la création du fichier.
- */
- private static function create_lotterys()
- {
- $row = lottery::getLotterys();
- if (file_put_contents(DIR_DATAS_JSON . "lotterys.json", json_encode($row))) {
- return 1;
- } else {
- return 0;
- }
- }
- /**
- * Crée un fichier JSON pour les utilisateurs.
- *
- * @return int Succès ou échec de la création du fichier.
- */
- private static function create_users()
- {
- $row = user::getUsers();
- if (file_put_contents(DIR_DATAS_JSON . "users.json", json_encode($row))) {
- return 1;
- } else {
- return 0;
- }
- }
- /**
- * Crée un fichier JSON pour l'historique des banques au format CSV.
- *
- * @return int Succès ou échec de la création du fichier.
- */
- private static function create_banque_csv()
- {
- $row = banque::getHistoriqueCSV();
- if (file_put_contents(DIR_DATAS_JSON . "banque-csv.json", json_encode($row))) {
- return 1;
- } else {
- return 0;
- }
- }
- /**
- * Crée un fichier JSON pour les lignes d'une banque spécifique.
- *
- * @param int $_id L'identifiant de la banque.
- * @return int Succès ou échec de la création du fichier.
- */
- private static function create_banque_lignes(int $_id)
- {
- $row = array(banque::getInitial($_id));
- $row2 = banque::getLignes($_id, $row[0]["solde"]);
- $return = array_merge($row, $row2);
- if (file_put_contents(DIR_DATAS_JSON . "banque-lignes-" . $_id . ".json", json_encode($return))) {
- return 1;
- } else {
- return 0;
- }
- }
- /**
- * Supprime un fichier JSON spécifié.
- *
- * @param string $_target Le nom du fichier JSON à supprimer.
- */
- public static function delete(string $_target)
- {
- if (is_file(DIR_DATAS_JSON . "/" . $_target . ".json")) {
- unlink(DIR_DATAS_JSON . "/" . $_target . ".json");
- }
- }
- /**
- * Teste l'accès SFTP.
- *
- * @return string "OK" si l'accès est réussi, "KO" sinon.
- */
- public static function testSFTP()
- {
- return (sftp::testAccessHost()) ? "OK" : "KO";
- }
- /**
- * Crée un fichier JSON pour les documents.
- *
- * @param string|null $_limited Indique si seuls les documents limités doivent être inclus.
- * @return int Succès ou échec de la création du fichier.
- */
- private static function create_document(?string $_limited = NULL)
- {
- $where = ($_limited == TRUE) ? " WHERE " . DB_T_DOCUMENTS . ".id_type != 3" : NULL;
- if(is_null($_limited)){
- $where = NULL;
- $file = "documents";
- } else {
- $where = " WHERE " . DB_T_DOCUMENTS . ".id_type != 3";
- $file = "documents-limited";
- }
-
- db::query("SELECT
- " . DB_T_DOCUMENTS . ".id,
- " . DB_T_DOCUMENTS . ".titre,
- " . DB_T_DOCUMENTS . ".date,
- " . DB_T_DOCUMENTS . ".deadline,
- " . DB_T_DOCUMENTS . ".description,
- " . DB_T_CLIENTS . ".label AS attach,
- " . DB_T_DOCUMENTS . ".montant,
- ( SELECT GROUP_CONCAT(" . DB_T_TAGS . ".label SEPARATOR ', ')
- FROM " . DB_T_DOCUMENT_TAGS . "
- INNER JOIN " . DB_T_TAGS . " ON " . DB_T_TAGS . ".id = " . DB_T_DOCUMENT_TAGS . ".id_tags
- WHERE id_documents = " . DB_T_DOCUMENTS . ".id AND " . DB_T_DOCUMENT_TAGS . ".id_type_tags = 2
- ORDER BY " . DB_T_DOCUMENT_TAGS . ".creer) AS tags,
- ( SELECT GROUP_CONCAT(" . DB_T_TAGS . ".label SEPARATOR ', ')
- FROM " . DB_T_DOCUMENT_TAGS . "
- INNER JOIN " . DB_T_TAGS . " ON " . DB_T_TAGS . ".id = " . DB_T_DOCUMENT_TAGS . ".id_tags
- WHERE id_documents = " . DB_T_DOCUMENTS . ".id AND " . DB_T_DOCUMENT_TAGS . ".id_type_tags = 1
- ORDER BY " . DB_T_DOCUMENT_TAGS . ".creer) AS assign,
- IF(" . DB_T_DOCUMENTS . ".id_user_done IS NOT NULL, 'Traité', 'Non traité') AS done,
- " . DB_T_TYPE_DOCUMENT . ".label
- FROM " . DB_T_DOCUMENTS . "
- LEFT JOIN " . DB_T_CLIENTS . " ON " . DB_T_CLIENTS . ".id = " . DB_T_DOCUMENTS . ".id_client
- INNER JOIN " . DB_T_TYPE_DOCUMENT . " ON " . DB_T_TYPE_DOCUMENT . ".id = " . DB_T_DOCUMENTS . ".id_type" . $where);
- $row = db::resultset();
- if (file_put_contents(DIR_DATAS_JSON . $file . ".json", json_encode($row))) {
- return 1;
- } else {
- return 0;
- }
- }
- }
|