fichinter.lib.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <?php
  2. /* Copyright (C) 2006-2007 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  4. * Copyright (C) 2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2016 Gilles Poirier <glgpoirier@gmail.com>
  6. * Copyright (C) 2018 charlene Benke <charlie@patas-monkey.com>
  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. * or see https://www.gnu.org/
  21. */
  22. /**
  23. * \file htdocs/core/lib/fichinter.lib.php
  24. * \brief Ensemble de fonctions de base pour le module fichinter
  25. * \ingroup fichinter
  26. */
  27. /**
  28. * Prepare array with list of tabs
  29. *
  30. * @param Object $object Object related to tabs
  31. * @return array Array of tabs to show
  32. */
  33. function fichinter_prepare_head($object)
  34. {
  35. global $db, $langs, $conf, $user;
  36. $langs->load("fichinter");
  37. $h = 0;
  38. $head = array();
  39. $head[$h][0] = DOL_URL_ROOT.'/fichinter/card.php?id='.$object->id;
  40. $head[$h][1] = $langs->trans("Intervention");
  41. $head[$h][2] = 'card';
  42. $h++;
  43. if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
  44. $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
  45. $head[$h][0] = DOL_URL_ROOT.'/fichinter/contact.php?id='.$object->id;
  46. $head[$h][1] = $langs->trans('InterventionContact');
  47. if ($nbContact > 0) {
  48. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
  49. }
  50. $head[$h][2] = 'contact';
  51. $h++;
  52. }
  53. // Show more tabs from modules
  54. // Entries must be declared in modules descriptor with line
  55. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  56. // $this->tabs = array('entity:-tabname); to remove a tab
  57. complete_head_from_modules($conf, $langs, $object, $head, $h, 'intervention', 'add', 'core');
  58. // Tab to link resources
  59. if (isModEnabled('resource')) {
  60. require_once DOL_DOCUMENT_ROOT.'/resource/class/dolresource.class.php';
  61. $objectres = new Dolresource($db);
  62. $linked_resources = $objectres->getElementResources('fichinter', $object->id);
  63. $nbResource = (is_array($linked_resources) ?count($linked_resources) : 0);
  64. // if (is_array($objectres->available_resources))
  65. // {
  66. // foreach ($objectres->available_resources as $modresources => $resources)
  67. // {
  68. // $resources=(array) $resources; // To be sure $resources is an array
  69. // foreach($resources as $resource_obj)
  70. // {
  71. // $linked_resources = $object->getElementResources('fichinter', $object->id, $resource_obj);
  72. // }
  73. // }
  74. // }
  75. $head[$h][0] = DOL_URL_ROOT.'/resource/element_resource.php?element=fichinter&element_id='.$object->id;
  76. $head[$h][1] = $langs->trans("Resources");
  77. if ($nbResource > 0) {
  78. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbResource.'</span>';
  79. }
  80. $head[$h][2] = 'resource';
  81. $h++;
  82. }
  83. if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
  84. $nbNote = 0;
  85. if (!empty($object->note_private)) {
  86. $nbNote++;
  87. }
  88. if (!empty($object->note_public)) {
  89. $nbNote++;
  90. }
  91. $head[$h][0] = DOL_URL_ROOT.'/fichinter/note.php?id='.$object->id;
  92. $head[$h][1] = $langs->trans('Notes');
  93. if ($nbNote > 0) {
  94. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
  95. }
  96. $head[$h][2] = 'note';
  97. $h++;
  98. }
  99. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  100. require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
  101. $upload_dir = $conf->ficheinter->dir_output."/".dol_sanitizeFileName($object->ref);
  102. $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
  103. $nbLinks = Link::count($db, $object->element, $object->id);
  104. $head[$h][0] = DOL_URL_ROOT.'/fichinter/document.php?id='.$object->id;
  105. $head[$h][1] = $langs->trans("Documents");
  106. if (($nbFiles + $nbLinks) > 0) {
  107. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
  108. }
  109. $head[$h][2] = 'documents';
  110. $h++;
  111. $head[$h][0] = DOL_URL_ROOT.'/fichinter/info.php?id='.$object->id;
  112. $head[$h][1] = $langs->trans('Info');
  113. $head[$h][2] = 'info';
  114. $h++;
  115. complete_head_from_modules($conf, $langs, $object, $head, $h, 'intervention', 'add', 'external');
  116. complete_head_from_modules($conf, $langs, $object, $head, $h, 'intervention', 'remove');
  117. return $head;
  118. }
  119. /**
  120. * Return array head with list of tabs to view object informations.
  121. *
  122. * @return array head array with tabs
  123. */
  124. function fichinter_admin_prepare_head()
  125. {
  126. global $langs, $conf, $user, $db;
  127. $extrafields = new ExtraFields($db);
  128. $extrafields->fetch_name_optionals_label('fichinter');
  129. $extrafields->fetch_name_optionals_label('fichinterdet');
  130. $h = 0;
  131. $head = array();
  132. $h = 0;
  133. $head[$h][0] = DOL_URL_ROOT."/admin/fichinter.php";
  134. $head[$h][1] = $langs->trans("Interventions");
  135. $head[$h][2] = 'ficheinter';
  136. $h++;
  137. // Show more tabs from modules
  138. // Entries must be declared in modules descriptor with line
  139. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  140. // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
  141. complete_head_from_modules($conf, $langs, null, $head, $h, 'fichinter_admin');
  142. $head[$h][0] = DOL_URL_ROOT.'/fichinter/admin/fichinter_extrafields.php';
  143. $head[$h][1] = $langs->trans("ExtraFields");
  144. $nbExtrafields = $extrafields->attributes['fichinter']['count'];
  145. if ($nbExtrafields > 0) {
  146. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
  147. }
  148. $head[$h][2] = 'attributes';
  149. $h++;
  150. $head[$h][0] = DOL_URL_ROOT.'/fichinter/admin/fichinterdet_extrafields.php';
  151. $head[$h][1] = $langs->trans("ExtraFieldsLines");
  152. $nbExtrafields = $extrafields->attributes['fichinterdet']['count'];
  153. if ($nbExtrafields > 0) {
  154. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
  155. }
  156. $head[$h][2] = 'attributesdet';
  157. $h++;
  158. complete_head_from_modules($conf, $langs, null, $head, $h, 'fichinter_admin', 'remove');
  159. return $head;
  160. }
  161. /**
  162. * Prepare array with list of tabs
  163. *
  164. * @param Object $object Object related to tabs
  165. * @return array Array of tabs to show
  166. */
  167. function fichinter_rec_prepare_head($object)
  168. {
  169. global $langs, $conf; //, $user;
  170. $h = 0;
  171. $head = array();
  172. $head[$h][0] = DOL_URL_ROOT.'/fichinter/card-rec.php?id='.$object->id;
  173. $head[$h][1] = $langs->trans("CardFichinter");
  174. $head[$h][2] = 'card';
  175. $h++;
  176. complete_head_from_modules($conf, $langs, $object, $head, $h, 'intervention-rec');
  177. complete_head_from_modules($conf, $langs, $object, $head, $h, 'intervention-rec', 'remove');
  178. return $head;
  179. }