fichinter.lib.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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 (!getDolGlobalString('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 (!getDolGlobalString('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/agenda.php?id='.$object->id;
  112. $head[$h][1] = $langs->trans('Events');
  113. if (isModEnabled('agenda')&& ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
  114. $nbEvent = 0;
  115. // Enable caching of thirdparty count actioncomm
  116. require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
  117. $cachekey = 'count_events_fichinter_'.$object->id;
  118. $dataretrieved = dol_getcache($cachekey);
  119. if (!is_null($dataretrieved)) {
  120. $nbEvent = $dataretrieved;
  121. } else {
  122. $sql = "SELECT COUNT(id) as nb";
  123. $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm";
  124. $sql .= " WHERE fk_element = ".((int) $object->id);
  125. $sql .= " AND elementtype = 'fichinter'";
  126. $resql = $db->query($sql);
  127. if ($resql) {
  128. $obj = $db->fetch_object($resql);
  129. $nbEvent = $obj->nb;
  130. } else {
  131. dol_syslog('Failed to count actioncomm '.$db->lasterror(), LOG_ERR);
  132. }
  133. dol_setcache($cachekey, $nbEvent, 120); // If setting cache fails, this is not a problem, so we do not test result.
  134. }
  135. $head[$h][1] .= '/';
  136. $head[$h][1] .= $langs->trans("Agenda");
  137. if ($nbEvent > 0) {
  138. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbEvent.'</span>';
  139. }
  140. }
  141. $head[$h][2] = 'agenda';
  142. $h++;
  143. complete_head_from_modules($conf, $langs, $object, $head, $h, 'intervention', 'add', 'external');
  144. complete_head_from_modules($conf, $langs, $object, $head, $h, 'intervention', 'remove');
  145. return $head;
  146. }
  147. /**
  148. * Return array head with list of tabs to view object informations.
  149. *
  150. * @return array head array with tabs
  151. */
  152. function fichinter_admin_prepare_head()
  153. {
  154. global $langs, $conf, $user, $db;
  155. $extrafields = new ExtraFields($db);
  156. $extrafields->fetch_name_optionals_label('fichinter');
  157. $extrafields->fetch_name_optionals_label('fichinterdet');
  158. $h = 0;
  159. $head = array();
  160. $h = 0;
  161. $head[$h][0] = DOL_URL_ROOT."/admin/fichinter.php";
  162. $head[$h][1] = $langs->trans("Interventions");
  163. $head[$h][2] = 'ficheinter';
  164. $h++;
  165. // Show more tabs from modules
  166. // Entries must be declared in modules descriptor with line
  167. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  168. // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
  169. complete_head_from_modules($conf, $langs, null, $head, $h, 'fichinter_admin');
  170. $head[$h][0] = DOL_URL_ROOT.'/fichinter/admin/fichinter_extrafields.php';
  171. $head[$h][1] = $langs->trans("ExtraFields");
  172. $nbExtrafields = $extrafields->attributes['fichinter']['count'];
  173. if ($nbExtrafields > 0) {
  174. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
  175. }
  176. $head[$h][2] = 'attributes';
  177. $h++;
  178. $head[$h][0] = DOL_URL_ROOT.'/fichinter/admin/fichinterdet_extrafields.php';
  179. $head[$h][1] = $langs->trans("ExtraFieldsLines");
  180. $nbExtrafields = $extrafields->attributes['fichinterdet']['count'];
  181. if ($nbExtrafields > 0) {
  182. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
  183. }
  184. $head[$h][2] = 'attributesdet';
  185. $h++;
  186. complete_head_from_modules($conf, $langs, null, $head, $h, 'fichinter_admin', 'remove');
  187. return $head;
  188. }
  189. /**
  190. * Prepare array with list of tabs
  191. *
  192. * @param Object $object Object related to tabs
  193. * @return array Array of tabs to show
  194. */
  195. function fichinter_rec_prepare_head($object)
  196. {
  197. global $langs, $conf; //, $user;
  198. $h = 0;
  199. $head = array();
  200. $head[$h][0] = DOL_URL_ROOT.'/fichinter/card-rec.php?id='.$object->id;
  201. $head[$h][1] = $langs->trans("CardFichinter");
  202. $head[$h][2] = 'card';
  203. $h++;
  204. complete_head_from_modules($conf, $langs, $object, $head, $h, 'intervention-rec');
  205. complete_head_from_modules($conf, $langs, $object, $head, $h, 'intervention-rec', 'remove');
  206. return $head;
  207. }