2
0

json.class.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <?php
  2. class json extends db
  3. {
  4. public function __construct()
  5. {
  6. }
  7. public static function create(string $_target)
  8. {
  9. if (isset($_target)) {
  10. if (preg_match('/^banque-lignes-(\d+)$/', $_target, $matches)) {
  11. return self::create_banque_lignes((int)$matches[1]);
  12. }
  13. switch ($_target) {
  14. case "salaries":
  15. return self::create_salaries();
  16. break;
  17. case "excel":
  18. return self::create_excel();
  19. break;
  20. case "excel-proweb":
  21. return self::create_excelProweb();
  22. break;
  23. case "events":
  24. return self::create_events();
  25. break;
  26. case "users":
  27. return self::create_users();
  28. break;
  29. case "salaries-proweb":
  30. return self::create_salariesProweb();
  31. break;
  32. case "lotterys":
  33. return self::create_lotterys();
  34. break;
  35. case "banque-csv":
  36. return self::create_banque_csv();
  37. break;
  38. case "documents":
  39. return self::create_document();
  40. break;
  41. case "documents-limited":
  42. return self::create_document("limited");
  43. break;
  44. }
  45. } else {
  46. return 0;
  47. }
  48. }
  49. public static function createBanks()
  50. {
  51. foreach (banque::getAll() as $compte) {
  52. self::create_banque_lignes($compte["id"]);
  53. }
  54. }
  55. private static function create_salaries()
  56. {
  57. $row = salaries::getSalaries();
  58. if (file_put_contents(DIR_DATAS_JSON . "salaries.json", json_encode($row))) {
  59. return 1;
  60. } else {
  61. return 0;
  62. }
  63. }
  64. private static function create_salariesProweb()
  65. {
  66. $row = proweb::getBase();
  67. if (file_put_contents(DIR_DATAS_JSON . "salaries-proweb.json", json_encode($row))) {
  68. return 1;
  69. } else {
  70. return 0;
  71. }
  72. }
  73. private static function create_excel()
  74. {
  75. db::query("SELECT
  76. " . DB_T_EXCEL . ".id,
  77. " . DB_T_FILES . ".name,
  78. " . DB_T_EXCEL . ".nbSalaries,
  79. CONCAT(ROUND((" . DB_T_FILES . ".size / 1024 / 1024), 2), ' Mo') AS size,
  80. " . DB_T_EXCEL . ".md5,
  81. " . DB_T_EXCEL . ".cree,
  82. CONCAT (" . DB_T_USER . ".prenom, ' ', " . DB_T_USER . ".nom) AS 'user',
  83. dateData,
  84. goMysql,
  85. md5forSFTP,
  86. log
  87. FROM " . DB_T_EXCEL . "
  88. INNER JOIN " . DB_T_USER . " ON " . DB_T_EXCEL . ".id_user = " . DB_T_USER . ".id
  89. LEFT JOIN " . DB_T_FILES . " ON " . DB_T_EXCEL . ".md5 = " . DB_T_FILES . ".id");
  90. $row = db::resultset();
  91. if (file_put_contents(DIR_DATAS_JSON . "excel.json", json_encode($row))) {
  92. return 1;
  93. } else {
  94. return 0;
  95. }
  96. }
  97. private static function create_excelProweb()
  98. {
  99. db::query("SELECT
  100. " . DB_T_EXCEL_PROWEB . ".id,
  101. " . DB_T_FILES . ".name,
  102. " . DB_T_EXCEL_PROWEB . ".nbSalaries,
  103. CONCAT(ROUND((" . DB_T_FILES . ".size / 1024 / 1024), 2), ' Mo') AS size,
  104. " . DB_T_EXCEL_PROWEB . ".md5,
  105. " . DB_T_EXCEL_PROWEB . ".cree,
  106. CONCAT (" . DB_T_USER . ".prenom, ' ', " . DB_T_USER . ".nom) AS 'user',
  107. dateData
  108. FROM " . DB_T_EXCEL_PROWEB . "
  109. INNER JOIN " . DB_T_USER . " ON " . DB_T_EXCEL_PROWEB . ".id_user = " . DB_T_USER . ".id
  110. LEFT JOIN " . DB_T_FILES . " ON " . DB_T_EXCEL_PROWEB . ".md5 = " . DB_T_FILES . ".id");
  111. $row = db::resultset();
  112. if (file_put_contents(DIR_DATAS_JSON . "excel-proweb.json", json_encode($row))) {
  113. return 1;
  114. } else {
  115. return 0;
  116. }
  117. }
  118. private static function create_events()
  119. {
  120. $row = event::getEvents();
  121. if (file_put_contents(DIR_DATAS_JSON . "events.json", json_encode($row))) {
  122. return 1;
  123. } else {
  124. return 0;
  125. }
  126. }
  127. private static function create_lotterys()
  128. {
  129. $row = lottery::getLotterys();
  130. if (file_put_contents(DIR_DATAS_JSON . "lotterys.json", json_encode($row))) {
  131. return 1;
  132. } else {
  133. return 0;
  134. }
  135. }
  136. private static function create_users()
  137. {
  138. $row = user::getUsers();
  139. if (file_put_contents(DIR_DATAS_JSON . "users.json", json_encode($row))) {
  140. return 1;
  141. } else {
  142. return 0;
  143. }
  144. }
  145. private static function create_banque_csv()
  146. {
  147. $row = banque::getHistoriqueCSV();
  148. if (file_put_contents(DIR_DATAS_JSON . "banque-csv.json", json_encode($row))) {
  149. return 1;
  150. } else {
  151. return 0;
  152. }
  153. }
  154. private static function create_banque_lignes(int $_id)
  155. {
  156. $row = array(banque::getInitial($_id));
  157. $row2 = banque::getLignes($_id, $row[0]["solde"]);
  158. $return = array_merge($row, $row2);
  159. if (file_put_contents(DIR_DATAS_JSON . "banque-lignes-" . $_id . ".json", json_encode($return))) {
  160. return 1;
  161. } else {
  162. return 0;
  163. }
  164. }
  165. public static function delete(string $_target)
  166. {
  167. if (is_file(DIR_DATAS_JSON . "/" . $_target . ".json")) {
  168. unlink(DIR_DATAS_JSON . "/" . $_target . ".json");
  169. }
  170. }
  171. public static function testSFTP()
  172. {
  173. return (sftp::testAccessHost()) ? "OK" : "KO";
  174. }
  175. private static function create_document(string $_limited = NULL)
  176. {
  177. $where = ($_limited == TRUE) ? " WHERE " . DB_T_DOCUMENTS . ".id_type != 3" : NULL;
  178. if(is_null($_limited)){
  179. $where = NULL;
  180. $file = "documents";
  181. } else {
  182. $where = " WHERE " . DB_T_DOCUMENTS . ".id_type != 3";
  183. $file = "documents-limited";
  184. }
  185. db::query("SELECT
  186. " . DB_T_DOCUMENTS . ".id,
  187. " . DB_T_DOCUMENTS . ".titre,
  188. " . DB_T_DOCUMENTS . ".date,
  189. " . DB_T_DOCUMENTS . ".deadline,
  190. " . DB_T_DOCUMENTS . ".description,
  191. " . DB_T_CLIENTS . ".label AS attach,
  192. " . DB_T_DOCUMENTS . ".montant,
  193. ( SELECT GROUP_CONCAT(" . DB_T_TAGS . ".label SEPARATOR ', ')
  194. FROM " . DB_T_DOCUMENT_TAGS . "
  195. INNER JOIN " . DB_T_TAGS . " ON " . DB_T_TAGS . ".id = " . DB_T_DOCUMENT_TAGS . ".id_tags
  196. WHERE id_documents = " . DB_T_DOCUMENTS . ".id AND " . DB_T_DOCUMENT_TAGS . ".id_type_tags = 2
  197. ORDER BY " . DB_T_DOCUMENT_TAGS . ".creer) AS tags,
  198. ( SELECT GROUP_CONCAT(" . DB_T_TAGS . ".label SEPARATOR ', ')
  199. FROM " . DB_T_DOCUMENT_TAGS . "
  200. INNER JOIN " . DB_T_TAGS . " ON " . DB_T_TAGS . ".id = " . DB_T_DOCUMENT_TAGS . ".id_tags
  201. WHERE id_documents = " . DB_T_DOCUMENTS . ".id AND " . DB_T_DOCUMENT_TAGS . ".id_type_tags = 1
  202. ORDER BY " . DB_T_DOCUMENT_TAGS . ".creer) AS assign,
  203. IF(" . DB_T_DOCUMENTS . ".id_user_done IS NOT NULL, 'Traité', 'Non traité') AS done,
  204. " . DB_T_TYPE_DOCUMENT . ".label
  205. FROM " . DB_T_DOCUMENTS . "
  206. LEFT JOIN " . DB_T_CLIENTS . " ON " . DB_T_CLIENTS . ".id = " . DB_T_DOCUMENTS . ".id_client
  207. INNER JOIN " . DB_T_TYPE_DOCUMENT . " ON " . DB_T_TYPE_DOCUMENT . ".id = " . DB_T_DOCUMENTS . ".id_type" . $where);
  208. $row = db::resultset();
  209. if (file_put_contents(DIR_DATAS_JSON . $file . ".json", json_encode($row))) {
  210. return 1;
  211. } else {
  212. return 0;
  213. }
  214. }
  215. }