2
0

cms.document.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <?php
  2. if (core::ifGet("id") == FALSE and access::ifAccesss("add-document") == FALSE) {
  3. get::page("unknow");
  4. exit();
  5. }
  6. if (core::getGet("id") == NULL) {
  7. $titre = "Ajouter un document";
  8. $id_form = '<input type="hidden" name="id" value="add">';
  9. $submit = "Ajouter ce nouveau document";
  10. $document = session::getTemp("document");
  11. } else {
  12. $datas = document::get(core::getGet("id"));
  13. $document = $datas["document"];
  14. $files = $datas["files"];
  15. if (empty($document["id"])) {
  16. get::page("unknow");
  17. exit();
  18. }
  19. $id_form = '<input type="hidden" name="id" value="' . $document["id"] . '">';
  20. $submit = "Modifier ce document";
  21. $badgeCSS = " font-size:0.4em; margin-top:-5px;";
  22. $titre = "[#" . $document["id"] . "] " . $document["titre"];
  23. }
  24. if (core::isDebug()) {
  25. (!empty($document)) ? debug::log($document, "Données brutes document") : NULL;
  26. (!empty($files)) ? debug::log($files, "Données brutes files") : NULL;
  27. }
  28. $userTags = user::getUserById(session::getId())["tags"];
  29. ?>
  30. <header class="d-flex flex-column flex-md-row align-items-md-center p-3 bg-light ">
  31. <h2 class="bd-title" id="content">
  32. <span><?php echo $titre ?></span>
  33. </h2>
  34. </header>
  35. <?php
  36. if (core::ifGet("add")) {
  37. $labelFil = "Ajouter un document";
  38. $lienFil = "/add-document.html";
  39. } else {
  40. $labelFil = "[#" . $document["id"] . "] " . $document["titre"];
  41. $lienFil = "/document-" . core::getGet("id") . ".html";
  42. }
  43. echo core::filAriane(array(
  44. "current" => $labelFil,
  45. "arbo" => array(
  46. "Factures" => NULL,
  47. "Listes des documents" => "/documents.html",
  48. $labelFil => $lienFil
  49. )
  50. ));
  51. if (isset($document["id"])) {
  52. ?>
  53. <div style="float:right; margin-top: -60px;">
  54. <a href="/submit.php?from=document-delete&id=<?php echo $document["id"] ?>" style="color: #dc3545; text-decoration:none;" onclick="return confirm('Voulez-vous supprimer ce document ?')"><button type="submit" class="btn btn-outline-danger btn-sm"><?php icon::getFont(["icon" => "bi-trash-fill"]) ?></i> Supprimer</button></a>
  55. </div>
  56. <?php
  57. }
  58. ?>
  59. <link rel="stylesheet" href="css/dragAndDrop.css">
  60. <form id="form-document" method="post" action="/submit.php" enctype="multipart/form-data" onsubmit="return(false);">
  61. <div class="row">
  62. <div class="col">
  63. <input type="hidden" name="from" value="document">
  64. <?php echo $id_form; ?>
  65. <?php $_titre = (isset($document["titre"])) ? $document["titre"] : NULL; ?>
  66. <div class="form-group">
  67. <label>Titre</label>
  68. <input type="text" class="form-control" value="<?php core::printFormValue($_titre) ?>" name="titre" placeholder="" required>
  69. </div>
  70. <br />
  71. <?php
  72. $_type_document = (isset($document["id_type"])) ? $document["id_type"] : NULL;
  73. $_label_type_document = document::getTypes();
  74. ?>
  75. <div class="form-group">
  76. <label>Type de document</label>
  77. <select name="id_type" class="form-select">
  78. <option value=""></option>
  79. <option value="1" <?php core::printFormSelectOption($_type_document, 1) ?>><?php echo $_label_type_document[1] ?></option>
  80. <option value="2" <?php core::printFormSelectOption($_type_document, 2) ?>><?php echo $_label_type_document[2] ?></option>
  81. <option value="3" <?php core::printFormSelectOption($_type_document, 3) ?>><?php echo $_label_type_document[3] ?></option>
  82. <option value="0" <?php core::printFormSelectOption($_type_document, 0) ?>><?php echo $_label_type_document[0] ?></option>
  83. </select>
  84. </div>
  85. <br />
  86. <?php $_montant = (isset($document["montant"])) ? $document["montant"] : NULL; ?>
  87. <div class="form-group">
  88. <label>Montant associé</label>
  89. <input type="text" class="form-control" value="<?php core::printFormValue($_montant) ?>" name="montant" placeholder="" onkeypress="return (event.charCode >= 48 && event.charCode <= 57) || event.charCode == 46 || event.charCode == 0 ">
  90. </div>
  91. <br />
  92. <?php $_tagsSupplier = (isset($document["tagsSupplier"])) ? $document["tagsSupplier"] : NULL; ?>
  93. <div class="form-group">
  94. <label>Tags associés</label>
  95. <input type="text" value="<?php core::printFormValue($_tagsSupplier) ?>" name="tagsSupplier" id="tagsSupplier" />
  96. </div>
  97. <br />
  98. <?php $_date = (isset($document["date"])) ? $document["date"] : NULL; ?>
  99. <div class="form-group">
  100. <label>Date associée à ce document</label>
  101. <input type="date" class="form-control" name="date" value="<?php core::printFormValue($_date) ?>" placeholder="" required>
  102. </div>
  103. <br />
  104. <?php $_deadline = (isset($document["deadline"])) ? $document["deadline"] : NULL; ?>
  105. <div class="form-group">
  106. <label>Date limite de traitement</label>
  107. <input type="date" class="form-control" name="deadline" value="<?php core::printFormValue($_deadline) ?>" placeholder="" required>
  108. </div>
  109. <br />
  110. <?php $_description = (isset($document["description"])) ? $document["description"] : NULL; ?>
  111. <div class="form-group">
  112. <label>Description et commentaires</label>
  113. <textarea class="form-control" name="description" style="height:100%;"><?php core::printFormValue($_description) ?></textarea>
  114. </div>
  115. <br />
  116. <?php $_tagsUser = (isset($document["tagsUser"])) ? $document["tagsUser"] : NULL; ?>
  117. <div class="form-group">
  118. <label>Attribution</label>
  119. <input type="text" value="<?php core::printFormValue($_tagsUser) ?>" name="tagsUser" id="tagsUser" />
  120. </div>
  121. <br />
  122. <?php if (isset($files[0]["id"])) { ?>
  123. <div style="border:1px #CCCCCC solid; background-color:#F6F6F6; padding:20px; border-radius:.375rem;">
  124. <?php
  125. if ((isset($document) AND tags::compareUserDocument($userTags, $document["tagsUser"]) == TRUE) OR (isset($document["date_done"]))) {
  126. $checkDone = (isset($document["id_user_done"])) ? " disabled" : NULL;
  127. $checkColor = (isset($document["id_user_done"])) ? " style=\"background-color:#d1e7dd;\"" : NULL;
  128. $checkText = (isset($document["id_user_done"])) ? "Document traité par <span style=\"font-weight: bold;\">" . $document["doneUser"] . "</span> le": "Document traité le";
  129. $_dateDone = (isset($document["date_done"])) ? $document["date_done"] : NULL;
  130. echo ' <div class="form-group">
  131. <label>'.$checkText.'</label>
  132. <input type="date" class="form-control"'.$checkColor.' name="date_done" value="'. core::getFormValue($_dateDone) . '"' . $checkDone .'>
  133. </div><br />';
  134. }
  135. document::printAttachement($files);
  136. ?>
  137. <div class="file-drop-area">
  138. <span class="choose-file-button">Ajouter une pièce jointe</span>
  139. <span class="file-message">ou drag & drop</span>
  140. <input id="attachement-document" class="import-excel" name="attachement-document" type="file" onchange="dargAndDropAttachment()" accept="image/jpeg,image/png,application/pdf">
  141. </div>
  142. </div>
  143. <br />
  144. <?php } ?>
  145. </div>
  146. <div class="col">
  147. <?php if (empty($files[0]["id"])) { ?>
  148. <div class="file-drop-area" style="margin-top:22px;" id="file-document-import">
  149. <span class="choose-file-button">Choisissez votre document</span>
  150. <span class="file-message">ou drag & drop</span>
  151. <input id="document-import" class="import-excel" name="document-import" type="file" onchange="dargAndDrop()" accept="image/jpeg,image/png,application/pdf" required>
  152. </div>
  153. <br />
  154. <?php } else {
  155. $heigh = (mime_content_type(file::download($files[0]["id"], DIR_DATAS_DOCS)) == "application/pdf") ? "height:110vh;" : NULL;
  156. echo ' <div style="margin-top:22px;">
  157. <embed src="/document.php?id=' . $files[0]["id"] . '" style="width:100%; margin-top:10px;' . $heigh . '" /></embed>
  158. </div><br />
  159. ';
  160. }
  161. ?>
  162. </div>
  163. </div>
  164. <input class="btn btn-primary btn-lg" style="width: 100%;" type="button" value="<?php echo $submit ?>" onclick="validateAndSubmit()">
  165. <br /><br />
  166. </form>
  167. <script>
  168. function validateAndSubmit() {
  169. const form = document.getElementById('form-document');
  170. const requiredFields = form.querySelectorAll('[required]');
  171. let allFieldsFilled = true;
  172. requiredFields.forEach(field => {
  173. if (!field.value.trim()) {
  174. if (field.name === "document-import") {
  175. const fileDoc = document.getElementById('file-document-import');
  176. fileDoc.style.borderColor = 'red';
  177. }
  178. allFieldsFilled = false;
  179. field.style.borderColor = 'red';
  180. } else {
  181. field.style.borderColor = '';
  182. if (typeof fileDoc !== 'undefined' && fileDoc !== null) {
  183. fileDoc.style.borderColor = '';
  184. }
  185. }
  186. });
  187. if (allFieldsFilled) {
  188. form.submit();
  189. }
  190. }
  191. function dargAndDrop() {
  192. var fileName = $("#document-import").val().split('\\').pop();
  193. var ext = fileName.split('.').pop();
  194. if(ext!=="pdf" && ext!=="png" && ext!=="jpg"){
  195. $("#printToastErrorTxt").html("Seuls les fichiers PDF, JPG et PNG sont acceptés");
  196. $("#printToastError").toast('show');
  197. $('#attachement-document').val("");
  198. } else {
  199. $(".file-message").text($(".file-message").text().replace("ou drag & drop", fileName));
  200. }
  201. }
  202. function dargAndDropAttachment() {
  203. var fileName = $("#attachement-document").val().split('\\').pop();
  204. var ext = fileName.split('.').pop();
  205. if(ext!=="pdf" && ext!=="png" && ext!=="jpg"){
  206. $("#printToastErrorTxt").html("Seuls les fichiers PDF, JPG et PNG sont acceptés");
  207. $("#printToastError").toast('show');
  208. $('#attachement-document').val("");
  209. } else {
  210. $(".file-message").text($(".file-message").text().replace("ou drag & drop", fileName));
  211. }
  212. }
  213. function deleteAttachment(id){
  214. const elementsCadre = $('#attach-' + id);
  215. const elementsAlerte = $('#select-attach-' + id);
  216. const elementsButton = $('#button-attach-' + id);
  217. if($('#del-jquery-' + id).length) {
  218. const elementsRevert = $('#del-jquery-' + id);
  219. elementsCadre.css('background-color', '');
  220. elementsAlerte.html('');
  221. elementsButton.html('<?php echo icon::getFont(["icon" => "bi bi-trash"]) ?>');
  222. } else {
  223. elementsCadre.css('background-color', '#f8d7da');
  224. elementsAlerte.html('Ce document sera supprimé à la validation du formulaire.<input id="del-jquery-' + id + '" type="hidden" name="delete-attachement[]" value="' + id + '">');
  225. elementsButton.html('<?php echo icon::getFont(["icon" => "bi bi-x-square-fill"]) ?>');
  226. }
  227. }
  228. function upperCase(input) {
  229. input.value = input.value.toUpperCase();
  230. }
  231. $(document).ready(function() {
  232. $('#tagsUser').inputTags({
  233. autocomplete: {
  234. values: <?php echo tags::getJquery(1) ?>,
  235. only: true
  236. },
  237. max: 3
  238. });
  239. $('#tagsSupplier').inputTags({
  240. autocomplete: {
  241. values: <?php echo tags::getJquery(2) ?>
  242. },
  243. max: 3
  244. });
  245. });
  246. </script>