file_note.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. require '../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/ecm.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmdirectory.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
  31. // Load translation files required by the page
  32. $langs->loadLangs(array('ecm'));
  33. $id = GETPOST('id', 'int');
  34. $ref = GETPOST('ref', 'alpha');
  35. $socid = GETPOST('socid', 'int');
  36. $action = GETPOST('action', 'aZ09');
  37. // Get parameters
  38. $socid = GETPOST("socid", "int");
  39. // Security check
  40. if ($user->socid > 0) {
  41. $action = '';
  42. $socid = $user->socid;
  43. }
  44. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  45. $sortfield = GETPOST('sortfield', 'aZ09comma');
  46. $sortorder = GETPOST('sortorder', 'aZ09comma');
  47. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  48. if (empty($page) || $page == -1) {
  49. $page = 0;
  50. } // If $page is not defined, or '' or -1
  51. $offset = $limit * $page;
  52. $pageprev = $page - 1;
  53. $pagenext = $page + 1;
  54. if (!$sortorder) {
  55. $sortorder = "ASC";
  56. }
  57. if (!$sortfield) {
  58. $sortfield = "label";
  59. }
  60. $section = GETPOST("section", 'alpha');
  61. if (!$section) {
  62. dol_print_error('', 'Error, section parameter missing');
  63. exit;
  64. }
  65. $urlfile = (string) dol_sanitizePathName(GETPOST("urlfile"));
  66. if (!$urlfile) {
  67. dol_print_error('', "ErrorParamNotDefined");
  68. exit;
  69. }
  70. // Load ecm object
  71. $ecmdir = new EcmDirectory($db);
  72. $result = $ecmdir->fetch(GETPOST("section", 'alpha'));
  73. if (!$result > 0) {
  74. dol_print_error($db, $ecmdir->error);
  75. exit;
  76. }
  77. $relativepath = $ecmdir->getRelativePath();
  78. $upload_dir = $conf->ecm->dir_output.'/'.$relativepath;
  79. $fullpath = $conf->ecm->dir_output.'/'.$relativepath.$urlfile;
  80. $relativetodocument = 'ecm/'.$relativepath; // $relativepath is relative to ECM dir, we need relative to document
  81. $filepath = $relativepath.$urlfile;
  82. $filepathtodocument = $relativetodocument.$urlfile;
  83. // Try to load object from index
  84. $object = new ECMFiles($db);
  85. $extrafields = new ExtraFields($db);
  86. // fetch optionals attributes and labels
  87. $extrafields->fetch_name_optionals_label($object->table_element);
  88. $result = $object->fetch(0, '', $filepathtodocument);
  89. if ($result < 0) {
  90. dol_print_error($db, $object->error, $object->errors);
  91. exit;
  92. }
  93. $permissionnote = $user->rights->ecm->setup; // Used by the include of actions_setnotes.inc.php
  94. $permtoread = $user->rights->ecm->read;
  95. if (!$permtoread) {
  96. accessforbidden();
  97. }
  98. /*
  99. * Actions
  100. */
  101. include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once
  102. /*
  103. * View
  104. */
  105. llxHeader('', $langs->trans('EcmFiles'));
  106. $form = new Form($db);
  107. $object->section_id = $ecmdir->id;
  108. $object->label = $urlfile;
  109. $head = ecm_file_prepare_head($object);
  110. print dol_get_fiche_head($head, 'note', $langs->trans("File"), -1, 'generic');
  111. $s = '';
  112. $tmpecmdir = new EcmDirectory($db); // Need to create a new one
  113. $tmpecmdir->fetch($ecmdir->id);
  114. $result = 1;
  115. $i = 0;
  116. while ($tmpecmdir && $result > 0) {
  117. $tmpecmdir->ref = $tmpecmdir->label;
  118. $s = $tmpecmdir->getNomUrl(1).$s;
  119. if ($tmpecmdir->fk_parent) {
  120. $s = ' -> '.$s;
  121. $result = $tmpecmdir->fetch($tmpecmdir->fk_parent);
  122. } else {
  123. $tmpecmdir = 0;
  124. }
  125. $i++;
  126. }
  127. $urlfiletoshow = preg_replace('/\.noexe$/', '', $urlfile);
  128. $s = img_picto('', 'object_dir').' <a href="'.DOL_URL_ROOT.'/ecm/index.php">'.$langs->trans("ECMRoot").'</a> -> '.$s.' -> ';
  129. if ($action == 'edit') {
  130. $s .= '<input type="text" name="label" class="quatrevingtpercent" value="'.$urlfiletoshow.'">';
  131. } else {
  132. $s .= $urlfiletoshow;
  133. }
  134. $linkback = '';
  135. if ($backtopage) {
  136. $linkback = '<a href="'.$backtopage.'">'.$langs->trans("BackToTree").'</a>';
  137. }
  138. $object->ref = ''; // Force to hide ref
  139. dol_banner_tab($object, '', $linkback, 0, '', '', $s);
  140. print '<div class="fichecenter">';
  141. print '<div class="underbanner clearboth"></div>';
  142. $cssclass = "titlefield";
  143. $moreparam = '&amp;section='.$section.'&amp;urlfile='.$urlfile;
  144. include DOL_DOCUMENT_ROOT.'/core/tpl/notes.tpl.php';
  145. print '</div>';
  146. print dol_get_fiche_end();
  147. // End of page
  148. llxFooter();
  149. $db->close();