cms.document.php 14 KB

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