file_note.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <?php
  2. /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
  6. * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/ecm/file_note.php
  23. * \ingroup ecm
  24. * \brief Tab for notes on an ECM file
  25. */
  26. // Load Dolibarr environment
  27. require '../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/ecm.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmdirectory.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
  32. // Load translation files required by the page
  33. $langs->loadLangs(array('ecm'));
  34. $id = GETPOST('id', 'int');
  35. $ref = GETPOST('ref', 'alpha');
  36. $socid = GETPOST('socid', 'int');
  37. $action = GETPOST('action', 'aZ09');
  38. // Get parameters
  39. $socid = GETPOST("socid", "int");
  40. // Security check
  41. if ($user->socid > 0) {
  42. $action = '';
  43. $socid = $user->socid;
  44. }
  45. $backtopage = GETPOST('backtopage', 'alpha');
  46. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  47. $sortfield = GETPOST('sortfield', 'aZ09comma');
  48. $sortorder = GETPOST('sortorder', 'aZ09comma');
  49. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  50. if (empty($page) || $page == -1) {
  51. $page = 0;
  52. } // If $page is not defined, or '' or -1
  53. $offset = $limit * $page;
  54. $pageprev = $page - 1;
  55. $pagenext = $page + 1;
  56. if (!$sortorder) {
  57. $sortorder = "ASC";
  58. }
  59. if (!$sortfield) {
  60. $sortfield = "label";
  61. }
  62. $section = GETPOST("section", 'alpha');
  63. if (!$section) {
  64. dol_print_error('', 'Error, section parameter missing');
  65. exit;
  66. }
  67. $urlfile = (string) dol_sanitizePathName(GETPOST("urlfile"));
  68. if (!$urlfile) {
  69. dol_print_error('', "ErrorParamNotDefined");
  70. exit;
  71. }
  72. // Load ecm object
  73. $ecmdir = new EcmDirectory($db);
  74. $result = $ecmdir->fetch(GETPOST("section", 'alpha'));
  75. if (!($result > 0)) {
  76. dol_print_error($db, $ecmdir->error);
  77. exit;
  78. }
  79. $relativepath = $ecmdir->getRelativePath();
  80. $upload_dir = $conf->ecm->dir_output.'/'.$relativepath;
  81. $fullpath = $conf->ecm->dir_output.'/'.$relativepath.$urlfile;
  82. $relativetodocument = 'ecm/'.$relativepath; // $relativepath is relative to ECM dir, we need relative to document
  83. $filepath = $relativepath.$urlfile;
  84. $filepathtodocument = $relativetodocument.$urlfile;
  85. // Try to load object from index
  86. $object = new EcmFiles($db);
  87. $extrafields = new ExtraFields($db);
  88. // fetch optionals attributes and labels
  89. $extrafields->fetch_name_optionals_label($object->table_element);
  90. $result = $object->fetch(0, '', $filepathtodocument);
  91. if ($result < 0) {
  92. dol_print_error($db, $object->error, $object->errors);
  93. exit;
  94. }
  95. $permissionnote = $user->rights->ecm->setup; // Used by the include of actions_setnotes.inc.php
  96. $permissiontoread = $user->rights->ecm->read;
  97. if (!$permissiontoread) {
  98. accessforbidden();
  99. }
  100. /*
  101. * Actions
  102. */
  103. include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once
  104. /*
  105. * View
  106. */
  107. llxHeader('', $langs->trans('EcmFiles'));
  108. $form = new Form($db);
  109. $object->section_id = $ecmdir->id;
  110. $object->label = $urlfile;
  111. $head = ecm_file_prepare_head($object);
  112. print dol_get_fiche_head($head, 'note', $langs->trans("File"), -1, 'generic');
  113. $s = '';
  114. $tmpecmdir = new EcmDirectory($db); // Need to create a new one
  115. $tmpecmdir->fetch($ecmdir->id);
  116. $result = 1;
  117. $i = 0;
  118. while ($tmpecmdir && $result > 0) {
  119. $tmpecmdir->ref = $tmpecmdir->label;
  120. $s = $tmpecmdir->getNomUrl(1).$s;
  121. if ($tmpecmdir->fk_parent) {
  122. $s = ' -> '.$s;
  123. $result = $tmpecmdir->fetch($tmpecmdir->fk_parent);
  124. } else {
  125. $tmpecmdir = 0;
  126. }
  127. $i++;
  128. }
  129. $urlfiletoshow = preg_replace('/\.noexe$/', '', $urlfile);
  130. $s = img_picto('', 'object_dir').' <a href="'.DOL_URL_ROOT.'/ecm/index.php">'.$langs->trans("ECMRoot").'</a> -> '.$s.' -> ';
  131. if ($action == 'edit') {
  132. $s .= '<input type="text" name="label" class="quatrevingtpercent" value="'.$urlfiletoshow.'">';
  133. } else {
  134. $s .= $urlfiletoshow;
  135. }
  136. $linkback = '';
  137. if ($backtopage) {
  138. $linkback = '<a href="'.$backtopage.'">'.$langs->trans("BackToTree").'</a>';
  139. }
  140. $object->ref = ''; // Force to hide ref
  141. dol_banner_tab($object, '', $linkback, 0, '', '', $s);
  142. print '<div class="fichecenter">';
  143. print '<div class="underbanner clearboth"></div>';
  144. $cssclass = "titlefield";
  145. $moreparam = '&amp;section='.$section.'&amp;urlfile='.$urlfile;
  146. include DOL_DOCUMENT_ROOT.'/core/tpl/notes.tpl.php';
  147. print '</div>';
  148. print dol_get_fiche_end();
  149. // End of page
  150. llxFooter();
  151. $db->close();