cms.document.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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 if ((isset($document) AND tags::compareUserDocument($userTags, $document["tagsUser"]) == TRUE) OR (isset($document["date_done"]))) {
  125. $checkDone = (isset($document["id_user_done"])) ? " disabled" : NULL;
  126. $checkText = (isset($document["id_user_done"])) ? "Document traité par " . $document["doneUser"] . " le": "Document traité le";
  127. ?>
  128. <?php $_dateDone = (isset($document["date_done"])) ? $document["date_done"] : NULL; ?>
  129. <div class="form-group">
  130. <label><?php echo $checkText ?></label>
  131. <input type="date" class="form-control" name="date_done" value="<?php core::printFormValue($_dateDone) ?>"<?php echo $checkDone ?>>
  132. </div>
  133. <br />
  134. <?php } ?>
  135. <?php document::printAttachement($files); ?>
  136. <div class="file-drop-area">
  137. <span class="choose-file-button">Ajouter une pièce jointe</span>
  138. <span class="file-message">ou drag & drop</span>
  139. <input id="attachement-document" class="import-excel" name="attachement-document" type="file" onchange="dargAndDropAttachment()" accept="image/jpeg,image/png,application/pdf">
  140. </div>
  141. </div>
  142. <br />
  143. <?php } ?>
  144. </div>
  145. <div class="col">
  146. <?php if (empty($files[0]["id"])) { ?>
  147. <div class="file-drop-area" style="margin-top:22px;" id="file-document-import">
  148. <span class="choose-file-button">Choisissez votre document</span>
  149. <span class="file-message">ou drag & drop</span>
  150. <input id="document-import" class="import-excel" name="document-import" type="file" onchange="dargAndDrop()" accept="image/jpeg,image/png,application/pdf" required>
  151. </div>
  152. <br />
  153. <?php } else {
  154. $heigh = (mime_content_type(file::download($files[0]["id"], DIR_DATAS_DOCS)) == "application/pdf") ? "height:110vh;" : NULL;
  155. echo ' <div style="margin-top:22px;">
  156. <embed src="/document.php?id=' . $files[0]["id"] . '" style="width:100%; margin-top:10px;' . $heigh . '" /></embed>
  157. </div><br />
  158. ';
  159. }
  160. ?>
  161. </div>
  162. </div>
  163. <input class="btn btn-primary btn-lg" style="width: 100%;" type="button" value="<?php echo $submit ?>" onclick="validateAndSubmit()">
  164. <br /><br />
  165. </form>
  166. <script>
  167. function validateAndSubmit() {
  168. const form = document.getElementById('form-document');
  169. const requiredFields = form.querySelectorAll('[required]');
  170. let allFieldsFilled = true;
  171. requiredFields.forEach(field => {
  172. if (!field.value.trim()) {
  173. if (field.name === "document-import") {
  174. const fileDoc = document.getElementById('file-document-import');
  175. fileDoc.style.borderColor = 'red';
  176. }
  177. allFieldsFilled = false;
  178. field.style.borderColor = 'red';
  179. } else {
  180. field.style.borderColor = '';
  181. if (typeof fileDoc !== 'undefined' && fileDoc !== null) {
  182. fileDoc.style.borderColor = '';
  183. }
  184. }
  185. });
  186. if (allFieldsFilled) {
  187. form.submit();
  188. }
  189. }
  190. function dargAndDrop() {
  191. var fileName = $("#document-import").val().split('\\').pop();
  192. var ext = fileName.split('.').pop();
  193. if(ext!=="pdf" && ext!=="png" && ext!=="jpg"){
  194. $("#printToastErrorTxt").html("Seuls les fichiers PDF, JPG et PNG sont acceptés");
  195. $("#printToastError").toast('show');
  196. $('#attachement-document').val("");
  197. } else {
  198. $(".file-message").text($(".file-message").text().replace("ou drag & drop", fileName));
  199. }
  200. }
  201. function dargAndDropAttachment() {
  202. var fileName = $("#attachement-document").val().split('\\').pop();
  203. var ext = fileName.split('.').pop();
  204. if(ext!=="pdf" && ext!=="png" && ext!=="jpg"){
  205. $("#printToastErrorTxt").html("Seuls les fichiers PDF, JPG et PNG sont acceptés");
  206. $("#printToastError").toast('show');
  207. $('#attachement-document').val("");
  208. } else {
  209. $(".file-message").text($(".file-message").text().replace("ou drag & drop", fileName));
  210. }
  211. }
  212. function deleteAttachment(id){
  213. const elementsCadre = $('#attach-' + id);
  214. const elementsAlerte = $('#select-attach-' + id);
  215. const elementsButton = $('#button-attach-' + id);
  216. if($('#del-jquery-' + id).length) {
  217. const elementsRevert = $('#del-jquery-' + id);
  218. elementsCadre.css('background-color', '');
  219. elementsAlerte.html('');
  220. elementsButton.html('<?php echo icon::getFont(["icon" => "bi bi-trash"]) ?>');
  221. } else {
  222. elementsCadre.css('background-color', '#f8d7da');
  223. elementsAlerte.html('Ce document sera supprimé à la validation du formulaire.<input id="del-jquery-' + id + '" type="hidden" name="delete-attachement[]" value="' + id + '">');
  224. elementsButton.html('<?php echo icon::getFont(["icon" => "bi bi-x-square-fill"]) ?>');
  225. }
  226. }
  227. function upperCase(input) {
  228. input.value = input.value.toUpperCase();
  229. }
  230. $(document).ready(function() {
  231. $('#tagsUser').inputTags({
  232. autocomplete: {
  233. values: <?php echo tags::getJquery(1) ?>,
  234. only: true
  235. },
  236. max: 3
  237. });
  238. $('#tagsSupplier').inputTags({
  239. autocomplete: {
  240. values: <?php echo tags::getJquery(2) ?>
  241. },
  242. max: 3
  243. });
  244. });
  245. </script>