ecm.lib.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <?php
  2. /* Copyright (C) 2008-2014 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2022 Frédéric France <frederic.france@netlogic.fr>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. * or see https://www.gnu.org/
  18. */
  19. /**
  20. * \file htdocs/core/lib/ecm.lib.php
  21. * \brief Ensemble de fonctions de base pour le module ecm
  22. * \ingroup ecm
  23. */
  24. /**
  25. * Prepare array with list of different ecm main dashboard
  26. *
  27. * @param object $object Object related to tabs
  28. * @return array Array of tabs to show
  29. */
  30. function ecm_prepare_dasboard_head($object)
  31. {
  32. global $langs, $conf, $user, $form;
  33. $h = 0;
  34. $head = array();
  35. $showmediasection = 0;
  36. if (isModEnabled('mailing') || isModEnabled('website')) {
  37. $showmediasection = 1;
  38. }
  39. $helptext = $langs->trans("ECMAreaDesc").'<br>';
  40. $helptext .= $langs->trans("ECMAreaDesc2a").'<br>';
  41. $helptext .= $langs->trans("ECMAreaDesc2b");
  42. if ($showmediasection) {
  43. $helptext .= '<br>'.$langs->trans("ECMAreaDesc3");
  44. }
  45. $head[$h][0] = DOL_URL_ROOT.'/ecm/index.php';
  46. $head[$h][1] = $langs->trans("ECMSectionsManual").$form->textwithpicto('', $helptext, 1, 'info', '', 0, 3);
  47. $head[$h][2] = 'index';
  48. $h++;
  49. if (!empty($conf->global->ECM_AUTO_TREE_ENABLED)) {
  50. $head[$h][0] = DOL_URL_ROOT.'/ecm/index_auto.php';
  51. $head[$h][1] = $langs->trans("ECMSectionsAuto").$form->textwithpicto('', $helptext, 1, 'info', '', 0, 3);
  52. $head[$h][2] = 'index_auto';
  53. $h++;
  54. }
  55. if ($showmediasection && getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) {
  56. $head[$h][0] = DOL_URL_ROOT.'/ecm/index_medias.php?file_manager=1';
  57. $head[$h][1] = $langs->trans("ECMSectionsMedias").$form->textwithpicto('', $helptext, 1, 'info', '', 0, 3);
  58. $head[$h][2] = 'index_medias';
  59. $h++;
  60. }
  61. // Show more tabs from modules
  62. // Entries must be declared in modules descriptor with line
  63. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  64. // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
  65. complete_head_from_modules($conf, $langs, $object, $head, $h, 'ecm');
  66. complete_head_from_modules($conf, $langs, $object, $head, $h, 'ecm', 'remove');
  67. return $head;
  68. }
  69. /**
  70. * Prepare array with list of tabs
  71. *
  72. * @param object $object Object related to tabs
  73. * @param string $module Module
  74. * @param string $section Section
  75. * @return array Array of tabs to show
  76. */
  77. function ecm_prepare_head($object, $module = 'ecm', $section = '')
  78. {
  79. global $langs, $conf, $user;
  80. $h = 0;
  81. $head = array();
  82. if ($module == 'ecm') {
  83. $head[$h][0] = DOL_URL_ROOT.'/ecm/dir_card.php?section='.$object->id;
  84. $head[$h][1] = $langs->trans("Directory");
  85. $head[$h][2] = 'card';
  86. $h++;
  87. } else {
  88. $head[$h][0] = DOL_URL_ROOT.'/ecm/dir_card.php?section='.$section.'&module='.$module;
  89. $head[$h][1] = $langs->trans("Directory");
  90. $head[$h][2] = 'card';
  91. $h++;
  92. }
  93. return $head;
  94. }
  95. /**
  96. * Prepare array with list of tabs
  97. *
  98. * @param Object $object Object related to tabs
  99. * @return array Array of tabs to show
  100. */
  101. function ecm_file_prepare_head($object)
  102. {
  103. global $langs, $conf, $user;
  104. $h = 0;
  105. $head = array();
  106. $head[$h][0] = DOL_URL_ROOT.'/ecm/file_card.php?section='.$object->section_id.'&urlfile='.urlencode($object->label);
  107. $head[$h][1] = $langs->trans("File");
  108. $head[$h][2] = 'card';
  109. $h++;
  110. // Notes
  111. $head[$h][0] = DOL_URL_ROOT.'/ecm/file_note.php?section='.$object->section_id.'&urlfile='.urlencode($object->label);
  112. $head[$h][1] = $langs->trans("Notes");
  113. $nbNote = 0;
  114. if (!empty($object->note_private)) {
  115. $nbNote++;
  116. }
  117. if (!empty($object->note_public)) {
  118. $nbNote++;
  119. }
  120. if ($nbNote > 0) {
  121. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
  122. }
  123. $head[$h][2] = 'note';
  124. $h++;
  125. return $head;
  126. }
  127. /**
  128. * Prepare array with list of tabs
  129. *
  130. * @param object $object Object related to tabs
  131. * @return array Array of tabs to show
  132. */
  133. function ecm_prepare_head_fm($object)
  134. {
  135. global $langs, $conf;
  136. $h = 0;
  137. $head = array();
  138. $head[$h][0] = DOL_URL_ROOT.'/ecm/index.php?action=file_manager';
  139. $head[$h][1] = $langs->trans('ECMFileManager');
  140. $head[$h][2] = 'file_manager';
  141. $h++;
  142. $head[$h][0] = DOL_URL_ROOT.'/ecm/search.php';
  143. $head[$h][1] = $langs->trans('Search');
  144. $head[$h][2] = 'search_form';
  145. $h++;
  146. return $head;
  147. }
  148. /**
  149. * Return array head with list of tabs to view object informations.
  150. *
  151. * @return array head array with tabs
  152. */
  153. function ecm_admin_prepare_head()
  154. {
  155. global $langs, $conf, $db;
  156. $extrafields = new ExtraFields($db);
  157. $extrafields->fetch_name_optionals_label('ecm_files');
  158. $extrafields->fetch_name_optionals_label('ecm_directories');
  159. $langs->load("ecm");
  160. $h = 0;
  161. $head = array();
  162. $head[$h][0] = DOL_URL_ROOT."/admin/ecm.php";
  163. $head[$h][1] = $langs->trans("Setup");
  164. $head[$h][2] = 'ecm';
  165. $h++;
  166. $head[$h][0] = DOL_URL_ROOT.'/admin/ecm_files_extrafields.php';
  167. $head[$h][1] = $langs->trans("ExtraFieldsEcmFiles");
  168. $nbExtrafields = $extrafields->attributes['ecm_files']['count'];
  169. if ($nbExtrafields > 0) {
  170. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
  171. }
  172. $head[$h][2] = 'attributes_ecm_files';
  173. $h++;
  174. $head[$h][0] = DOL_URL_ROOT.'/admin/ecm_directories_extrafields.php';
  175. $head[$h][1] = $langs->trans("ExtraFieldsEcmDirectories");
  176. $nbExtrafields = $extrafields->attributes['ecm_directories']['count'];
  177. if ($nbExtrafields > 0) {
  178. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
  179. }
  180. $head[$h][2] = 'attributes_ecm_directories';
  181. $h++;
  182. complete_head_from_modules($conf, $langs, null, $head, $h, 'ecm_admin');
  183. complete_head_from_modules($conf, $langs, null, $head, $h, 'ecm_admin', 'remove');
  184. return $head;
  185. }