2
0

cms.document.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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"]) or access::ifLimitAccessException("salaire") and isset($document["id_type"]) and $document["id_type"] == 3) {
  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 (debug::isFile("debug")) {
  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"]) and access::ifAccesss("add-document")) {
  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. <?php if (access::ifAccesss("add-document")) { ?>
  61. <form id="form-document" method="post" action="/submit.php" enctype="multipart/form-data" onsubmit="return(false);">
  62. <?php } ?>
  63. <div class="row">
  64. <div class="col">
  65. <input type="hidden" name="from" value="document">
  66. <?php echo $id_form; ?>
  67. <?php $_titre = (isset($document["titre"])) ? $document["titre"] : NULL; ?>
  68. <div class="form-group">
  69. <label>Titre</label>
  70. <input type="text" class="form-control" value="<?php core::printFormValue($_titre) ?>" name="titre" placeholder="" required <?php if (!access::ifAccesss("add-document")) {
  71. echo "readonly";
  72. } ?>>
  73. </div>
  74. <br />
  75. <?php
  76. $_type_document = (isset($document["id_type"])) ? $document["id_type"] : NULL;
  77. $_label_type_document = document::getTypes();
  78. ?>
  79. <div class="form-group">
  80. <label>Type de document</label>
  81. <select id="id_type" name="id_type" class="form-select" <?php if (!access::ifAccesss("add-document")) {
  82. echo "disabled";
  83. } ?> required>
  84. <option value=""></option>
  85. <option value="1" <?php core::printFormSelectOption($_type_document, 1) ?>><?php echo $_label_type_document[1] ?></option>
  86. <option value="2" <?php core::printFormSelectOption($_type_document, 2) ?>><?php echo $_label_type_document[2] ?></option>
  87. <?php if (!access::ifLimitAccessException("salaire")) { ?>
  88. <option value="3" <?php core::printFormSelectOption($_type_document, 3) ?>><?php echo $_label_type_document[3] ?></option>
  89. <?php } ?>
  90. <option value="0" <?php core::printFormSelectOption($_type_document, 0) ?>><?php echo $_label_type_document[0] ?></option>
  91. </select>
  92. </div>
  93. <br />
  94. <?php
  95. $_client = (isset($document["id_client"])) ? $document["id_client"] : NULL;
  96. $_all_clients = clients::getAll();
  97. ?>
  98. <div class="form-group" id="client-section"<?php if($_type_document != 1 AND $_type_document != 0){ echo 'style=" display: none;"'; } ?>>
  99. <label>Facture(s) liée(s) à</label>
  100. <select name="id_client" id="id_client" class="form-select" <?php if (!access::ifAccesss("add-client")) {
  101. echo "disabled";
  102. } ?>>
  103. <option value=""></option>
  104. <?php
  105. foreach ($_all_clients as $client) {
  106. echo '<option value="' . $client["id"] . '"';
  107. echo $_client == $client["id"] ? " selected" : NULL;
  108. echo '>' . $client["label"] . '</option>';
  109. }
  110. ?>
  111. </select>
  112. <br />
  113. </div>
  114. <?php $_montant = (isset($document["montant"])) ? $document["montant"] : NULL; ?>
  115. <div class="form-group">
  116. <label>Montant associé</label>
  117. <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 " <?php if (!access::ifAccesss("add-document")) {
  118. echo "readonly";
  119. } ?>>
  120. </div>
  121. <br />
  122. <?php $_tagsSupplier = (isset($document["tagsSupplier"])) ? $document["tagsSupplier"] : NULL; ?>
  123. <div class="form-group">
  124. <label>Tags associés</label>
  125. <input type="text" value="<?php core::printFormValue($_tagsSupplier) ?>" name="tagsSupplier" id="tagsSupplier" <?php if (!access::ifAccesss("add-document")) {
  126. echo "class=\"form-control\" readonly";
  127. } ?> />
  128. </div>
  129. <br />
  130. <?php $_date = (isset($document["date"])) ? $document["date"] : NULL; ?>
  131. <div class="form-group">
  132. <label>Date associée à ce document</label>
  133. <input type="date" class="form-control" name="date" value="<?php core::printFormValue($_date) ?>" placeholder="" required <?php if (!access::ifAccesss("add-document")) {
  134. echo "readonly";
  135. } ?>>
  136. </div>
  137. <br />
  138. <?php $_deadline = (isset($document["deadline"])) ? $document["deadline"] : NULL; ?>
  139. <div class="form-group">
  140. <label>Date limite de traitement</label>
  141. <input type="date" class="form-control" name="deadline" value="<?php core::printFormValue($_deadline) ?>" placeholder="" required <?php if (!access::ifAccesss("add-document")) {
  142. echo "readonly";
  143. } ?>>
  144. </div>
  145. <br />
  146. <?php $_description = (isset($document["description"])) ? $document["description"] : NULL; ?>
  147. <div class="form-group">
  148. <label>Description et commentaires</label>
  149. <textarea class="form-control" name="description" style="height:100%;" <?php if (!access::ifAccesss("add-document")) {
  150. echo "readonly";
  151. } ?>><?php core::printFormValue($_description) ?></textarea>
  152. </div>
  153. <br />
  154. <?php $_tagsUser = (isset($document["tagsUser"])) ? $document["tagsUser"] : NULL; ?>
  155. <div class="form-group">
  156. <label>Attribution</label>
  157. <input type="text" value="<?php core::printFormValue($_tagsUser) ?>" name="tagsUser" id="tagsUser" <?php if (!access::ifAccesss("add-document")) {
  158. echo "class=\"form-control\" readonly";
  159. } ?> />
  160. </div>
  161. <br />
  162. <?php if (isset($files["principal"]["id"])) { ?>
  163. <div style="border:1px #CCCCCC solid; background-color:#F6F6F6; padding:20px; border-radius:.375rem;">
  164. <?php
  165. if ((isset($document) and tags::compareUserDocument($userTags, $document["tagsUser"]) == TRUE) or (isset($document["date_done"]))) {
  166. $checkDone = (isset($document["id_user_done"])) ? " disabled" : NULL;
  167. $checkColor = (isset($document["id_user_done"])) ? " style=\"background-color:#d1e7dd;\"" : NULL;
  168. $checkText = (isset($document["id_user_done"])) ? "Document traité par <span style=\"font-weight: bold;\">" . $document["doneUser"] . "</span> le" : "Document traité le";
  169. $_dateDone = (isset($document["date_done"])) ? $document["date_done"] : NULL;
  170. echo ' <div class="form-group">
  171. <label>' . $checkText . '</label>
  172. <input type="date" class="form-control"' . $checkColor . ' name="date_done" value="' . core::getFormValue($_dateDone) . '"' . $checkDone . '>
  173. </div><br />';
  174. }
  175. document::printAttachement($files);
  176. ?>
  177. <?php if (access::ifAccesss("add-document")) { ?>
  178. <div class="file-drop-area">
  179. <span class="choose-file-button">Ajouter une pièce jointe</span>
  180. <span class="file-message">ou drag & drop</span>
  181. <input id="attachement-document" class="import-excel" name="attachement-document" type="file" onchange="dargAndDropAttachment()" accept="image/jpeg,image/png,application/pdf,text/xml,application/xml">
  182. </div>
  183. <?php } ?>
  184. </div>
  185. <br />
  186. <?php } ?>
  187. </div>
  188. <div class="col">
  189. <?php if (empty($files["principal"]["id"])) { ?>
  190. <div class="file-drop-area" style="margin-top:22px;" id="file-document-import">
  191. <span class="choose-file-button">Choisissez votre document</span>
  192. <span class="file-message">ou drag & drop</span>
  193. <input id="document-import" class="import-excel" name="document-import" type="file" onchange="dargAndDrop()" accept="image/jpeg,image/png,application/pdf,text/xml,application/xml" required>
  194. </div>
  195. <br />
  196. <?php } else {
  197. $getMime = mime_content_type(file::download($files["principal"]["id"], DIR_DATAS_DOCS));
  198. $heigh = ($getMime == "application/pdf" or $getMime == "text/xml" or $getMime == "application/xml") ? "height:110vh;" : NULL;
  199. $marginTop = ($getMime == "text/xml" or $getMime == "application/xml") ? "margin-top:4px;" : "margin-top:22px;";
  200. echo ' <div style="' . $marginTop . '">
  201. <embed src="/document.php?id=' . $files["principal"]["id"] . '" style="width:100%; margin-top:10px;' . $heigh . '" /></embed>
  202. </div><br />
  203. ';
  204. }
  205. ?>
  206. </div>
  207. </div>
  208. <?php if (access::ifAccesss("add-document")) { ?>
  209. <input class="btn btn-primary btn-lg" style="width: 100%;" type="button" value="<?php echo $submit ?>" onclick="validateAndSubmit()">
  210. </form>
  211. <?php
  212. }
  213. get::javascript("document");
  214. ?>