cms.document.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. } else {
  11. $document = document::get(core::getGet("id")); debug::log($document);
  12. if (empty($document["id"])) {
  13. get::page("unknow");
  14. exit();
  15. }
  16. $id_form = '<input type="hidden" name="id" value="' . $document["id"] . '">';
  17. $submit = "Modifier ce document";
  18. $badgeCSS = " font-size:0.4em; margin-top:-5px;";
  19. $titre = "[#" . $document["id"] . "] " . $document["titre"];
  20. $userTags = user::getUserById(session::getId())["tags"];
  21. }
  22. ?>
  23. <header class="d-flex flex-column flex-md-row align-items-md-center p-3 bg-light ">
  24. <h2 class="bd-title" id="content">
  25. <span><?php echo $titre ?></span>
  26. </h2>
  27. </header>
  28. <?php
  29. if (core::ifGet("add")) {
  30. $labelFil = "Ajouter un document";
  31. $lienFil = "/add-document.html";
  32. } else {
  33. $labelFil = "[#" . $document["id"] . "] " . $document["titre"];
  34. $lienFil = "/document-" . core::getGet("id") . ".html";
  35. }
  36. echo core::filAriane(array(
  37. "current" => $labelFil,
  38. "arbo" => array(
  39. "Factures" => NULL,
  40. "Listes des documents" => "/documents.html",
  41. $labelFil => $lienFil
  42. )
  43. ));
  44. if(isset($document["id"]) AND tags::compareUserDocument($userTags, $document["tags"]) == FALSE ){
  45. ?>
  46. <div style="float:right; margin-top: -60px;">
  47. <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"><span data-feather="trash-2"></span> Supprimer</button></a>
  48. </div>
  49. <?php
  50. }
  51. ?>
  52. <link rel="stylesheet" href="css/dragAndDrop.css">
  53. <form method="post" action="/submit.php" enctype="multipart/form-data" onsubmit="loading()">
  54. <div class="row">
  55. <div class="col">
  56. <input type="hidden" name="from" value="document">
  57. <?php echo $id_form; ?>
  58. <?php $_titre = (isset($document["titre"])) ? $document["titre"] : NULL; ?>
  59. <div class="form-group">
  60. <label>Titre</label>
  61. <input type="text" class="form-control" value="<?php core::printFormValue($_titre) ?>" name="titre" placeholder="" required>
  62. </div>
  63. <br />
  64. <?php
  65. $_type_document = (isset($document["id_type"])) ? $document["id_type"] : NULL;
  66. $_label_type_document = document::getTypes();
  67. ?>
  68. <div class="form-group">
  69. <label>Type de document</label>
  70. <select name="id_type" class="form-select">
  71. <option value=""></option>
  72. <option value="1" <?php core::printFormSelectOption($_type_document, 1) ?>><?php echo $_label_type_document[1]["label"] ?></option>
  73. <option value="2" <?php core::printFormSelectOption($_type_document, 2) ?>><?php echo $_label_type_document[2]["label"] ?></option>
  74. <option value="3" <?php core::printFormSelectOption($_type_document, 3) ?>><?php echo $_label_type_document[3]["label"] ?></option>
  75. <option value="0" <?php core::printFormSelectOption($_type_document, 0) ?>><?php echo $_label_type_document[0]["label"] ?></option>
  76. </select>
  77. </div>
  78. <br />
  79. <?php $_date = (isset($document["date"])) ? $document["date"] : NULL; ?>
  80. <div class="form-group">
  81. <label>Date associée à ce document</label>
  82. <input type="date" class="form-control" name="date" value="<?php core::printFormValue($_date) ?>" placeholder="" required>
  83. </div>
  84. <br />
  85. <?php $_deadline = (isset($document["deadline"])) ? $document["deadline"] : NULL; ?>
  86. <div class="form-group">
  87. <label>Date limite de traitement</label>
  88. <input type="date" class="form-control" name="deadline" value="<?php core::printFormValue($_deadline) ?>" placeholder="" required>
  89. </div>
  90. <br />
  91. <?php $_description = (isset($document["description"])) ? $document["description"] : NULL; ?>
  92. <div class="form-group">
  93. <label>Description et commentaires</label>
  94. <textarea class="form-control" name="description" style="height:100%;"><?php core::printFormValue($_description) ?></textarea>
  95. </div>
  96. <br />
  97. <?php $_assign_document = (isset($document["tags"])) ? $document["tags"] : NULL; ?>
  98. <div class="form-group">
  99. <label>Attribution</label>
  100. <input type="text" value="<?php
  101. if (isset($document["tags"])) {
  102. echo $document["tags"];
  103. }
  104. ?>" name="tags" id="tags" />
  105. </div>
  106. <br />
  107. <?php if(tags::compareUserDocument($userTags, $document["tags"]) == TRUE){
  108. $checkDone = (isset($document["id_user_done"])) ? " checked disabled" : NULL;
  109. $checkText = (isset($document["id_user_done"])) ? "Ce document a été traité par ". $document["doneUser"] . " le " . $document["date_done"] : "Ce document a été traité";
  110. ?>
  111. <div class="form-check form-switch">
  112. <input class="form-check-input" style="width:40px; height:20px;" type="checkbox" name="done" id="doneDocument"<?php echo $checkDone ?>>
  113. <label class="form-check-label" style="font-size:larger; margin-left:10px;" for="doneDocument" id="doneDocumentTxt"><?php echo $checkText ?></label>
  114. </div>
  115. <br />
  116. <?php } ?>
  117. <?php if(isset($document["id_file"])) { ?>
  118. <div class="form-group" style="opacity:0.5">
  119. <label style="color:var(--bs-link-color)">Nom du fichier</label>
  120. <input type="text" class="form-control" style="border-color:var(--bs-link-color); color:var(--bs-link-color);" value="<?php echo $document["name"] ?>" readonly>
  121. </div>
  122. <br />
  123. <div class="form-group" style="opacity:0.5">
  124. <label style="color:var(--bs-link-color)">Taille</label>
  125. <input type="text" class="form-control" style="border-color:var(--bs-link-color); color:var(--bs-link-color)" value="<?php echo $document["size"] ?>" readonly>
  126. </div>
  127. <br />
  128. <?php } ?>
  129. </div>
  130. <div class="col">
  131. <?php if(empty($document["id_file"])) { ?>
  132. <div class="file-drop-area" style="margin-top:22px;">
  133. <span class="choose-file-button">Choisissez votre document</span>
  134. <span class="file-message">ou drag & drop</span>
  135. <input id="document-import" class="import-excel" name="document-import" type="file" onchange="dargAndDrop()">
  136. </div>
  137. <br />
  138. <?php } else {
  139. $heigh = (mime_content_type(file::download($document["id_file"], DIR_DATAS_DOCS)) == "application/pdf") ? "height:110vh;" : NULL;
  140. echo ' <div style="margin-top:22px;">
  141. <a href="/document.php?id='.$document["id_file"].'" target="_blank" style="right:0;">
  142. <input class="btn btn-outline-secondary btn-sm" style="width: 100%; opacity:0.6;" value="Ouvrir le document">
  143. </a>
  144. <embed src="/document.php?id='.$document["id_file"].'" style="width:100%; margin-top:10px;'.$heigh.'" /></embed>
  145. </div><br />
  146. ';
  147. }
  148. ?>
  149. </div>
  150. </div>
  151. <input class="btn btn-primary btn-lg" style="width: 100%;" type="submit" value="<?php echo $submit ?>">
  152. <br /><br />
  153. </form>
  154. <script>
  155. function dargAndDrop() {
  156. var fileName = $("#document-import").val().split('\\').pop();
  157. $(".file-message").text($(".file-message").text().replace("ou drag & drop", fileName));
  158. }
  159. $(document).ready(function () {
  160. $('#tags').inputTags({
  161. autocomplete: {
  162. values: <?php echo tags::getJquery() ?>,
  163. only: true
  164. },
  165. max: 3
  166. });
  167. });
  168. </script>