fichinter.lib.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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@capnetworks.com>
  5. * Copyright (C) 2016 Gilles Poirier <glgpoirier@gmail.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. * or see http://www.gnu.org/
  20. */
  21. /**
  22. * \file htdocs/core/lib/fichinter.lib.php
  23. * \brief Ensemble de fonctions de base pour le module fichinter
  24. * \ingroup fichinter
  25. */
  26. /**
  27. * Prepare array with list of tabs
  28. *
  29. * @param Object $object Object related to tabs
  30. * @return array Array of tabs to show
  31. */
  32. function fichinter_prepare_head($object)
  33. {
  34. global $db, $langs, $conf, $user;
  35. $langs->load("fichinter");
  36. $h = 0;
  37. $head = array();
  38. $head[$h][0] = DOL_URL_ROOT.'/fichinter/card.php?id='.$object->id;
  39. $head[$h][1] = $langs->trans("Card");
  40. $head[$h][2] = 'card';
  41. $h++;
  42. if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB))
  43. {
  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) $head[$h][1].= ' <span class="badge">'.$nbContact.'</span>';
  48. $head[$h][2] = 'contact';
  49. $h++;
  50. }
  51. // Show more tabs from modules
  52. // Entries must be declared in modules descriptor with line
  53. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  54. // $this->tabs = array('entity:-tabname); to remove a tab
  55. complete_head_from_modules($conf,$langs,$object,$head,$h,'intervention');
  56. // Tab to link resources
  57. if ($conf->resource->enabled)
  58. {
  59. require_once DOL_DOCUMENT_ROOT.'/resource/class/dolresource.class.php';
  60. $nbResource = 0;
  61. $objectres=new Dolresource($db);
  62. if (is_array($objectres->available_resources))
  63. {
  64. foreach ($objectres->available_resources as $modresources => $resources)
  65. {
  66. $resources=(array) $resources; // To be sure $resources is an array
  67. foreach($resources as $resource_obj)
  68. {
  69. $linked_resources = $object->getElementResources('fichinter',$object->id,$resource_obj);
  70. }
  71. }
  72. }
  73. $head[$h][0] = DOL_URL_ROOT.'/resource/element_resource.php?element=fichinter&element_id='.$object->id;
  74. $head[$h][1] = $langs->trans("Resources");
  75. if ($nbResource > 0) $head[$h][1].= ' <span class="badge">'.$nbResource.'</span>';
  76. $head[$h][2] = 'resource';
  77. $h++;
  78. }
  79. if (empty($conf->global->MAIN_DISABLE_NOTES_TAB))
  80. {
  81. $nbNote = 0;
  82. if(!empty($object->note_private)) $nbNote++;
  83. if(!empty($object->note_public)) $nbNote++;
  84. $head[$h][0] = DOL_URL_ROOT.'/fichinter/note.php?id='.$object->id;
  85. $head[$h][1] = $langs->trans('Notes');
  86. if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>';
  87. $head[$h][2] = 'note';
  88. $h++;
  89. }
  90. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  91. require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
  92. $upload_dir = $conf->ficheinter->dir_output . "/" . dol_sanitizeFileName($object->ref);
  93. $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview.*\.png)$'));
  94. $nbLinks=Link::count($db, $object->element, $object->id);
  95. $head[$h][0] = DOL_URL_ROOT.'/fichinter/document.php?id='.$object->id;
  96. $head[$h][1] = $langs->trans("Documents");
  97. if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>';
  98. $head[$h][2] = 'documents';
  99. $h++;
  100. $head[$h][0] = DOL_URL_ROOT.'/fichinter/info.php?id='.$object->id;
  101. $head[$h][1] = $langs->trans('Info');
  102. $head[$h][2] = 'info';
  103. $h++;
  104. complete_head_from_modules($conf,$langs,$object,$head,$h,'intervention','remove');
  105. return $head;
  106. }
  107. /**
  108. * Return array head with list of tabs to view object informations.
  109. *
  110. * @return array head array with tabs
  111. */
  112. function fichinter_admin_prepare_head()
  113. {
  114. global $langs, $conf, $user;
  115. $h = 0;
  116. $head = array();
  117. $h = 0;
  118. $head[$h][0] = DOL_URL_ROOT."/admin/fichinter.php";
  119. $head[$h][1] = $langs->trans("Interventions");
  120. $head[$h][2] = 'ficheinter';
  121. $h++;
  122. // Show more tabs from modules
  123. // Entries must be declared in modules descriptor with line
  124. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  125. // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
  126. complete_head_from_modules($conf,$langs,null,$head,$h,'fichinter_admin');
  127. $head[$h][0] = DOL_URL_ROOT.'/fichinter/admin/fichinter_extrafields.php';
  128. $head[$h][1] = $langs->trans("ExtraFields");
  129. $head[$h][2] = 'attributes';
  130. $h++;
  131. $head[$h][0] = DOL_URL_ROOT.'/fichinter/admin/fichinterdet_extrafields.php';
  132. $head[$h][1] = $langs->trans("ExtraFieldsLines");
  133. $head[$h][2] = 'attributesdet';
  134. $h++;
  135. complete_head_from_modules($conf,$langs,null,$head,$h,'fichinter_admin','remove');
  136. return $head;
  137. }