resource.lib.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. /* Module to manage locations, buildings, floors and rooms into Dolibarr ERP/CRM
  3. * Copyright (C) 2013 Jean-François Ferry <jfefe@aternatik.fr>
  4. * Copyright (C) 2016 Gilles Poirier <gilles.poirier@netlogic.fr>
  5. * Copyright (C) 2023 Frédéric France <frederic.france@netlogic.fr>
  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 <https://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/core/lib/resource.lib.php
  22. * \ingroup resource
  23. * \brief This file is library for resource module
  24. */
  25. /**
  26. * Prepare head for tabs
  27. *
  28. * @param Dolresource $object Object
  29. * @return array Array of head entries
  30. */
  31. function resource_prepare_head($object)
  32. {
  33. global $langs, $conf, $user;
  34. $h = 0;
  35. $head = array();
  36. $head[$h][0] = dol_buildpath('/resource/card.php', 1).'?id='.$object->id;
  37. $head[$h][1] = $langs->trans("ResourceCard");
  38. $head[$h][2] = 'resource';
  39. $h++;
  40. if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && (empty($conf->global->RESOURCE_HIDE_ADD_CONTACT_USER) || empty($conf->global->RESOURCE_HIDE_ADD_CONTACT_THIPARTY))) {
  41. $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
  42. $head[$h][0] = DOL_URL_ROOT.'/resource/contact.php?id='.$object->id;
  43. $head[$h][1] = $langs->trans('ContactsAddresses');
  44. if ($nbContact > 0) {
  45. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
  46. }
  47. $head[$h][2] = 'contact';
  48. $h++;
  49. }
  50. // Show more tabs from modules
  51. // Entries must be declared in modules descriptor with line
  52. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  53. // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
  54. complete_head_from_modules($conf, $langs, $object, $head, $h, 'resource', 'add', 'core');
  55. if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
  56. $nbNote = 0;
  57. if (!empty($object->note_private)) {
  58. $nbNote++;
  59. }
  60. if (!empty($object->note_public)) {
  61. $nbNote++;
  62. }
  63. $head[$h][0] = DOL_URL_ROOT.'/resource/note.php?id='.$object->id;
  64. $head[$h][1] = $langs->trans('Notes');
  65. if ($nbNote > 0) {
  66. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
  67. }
  68. $head[$h][2] = 'note';
  69. $h++;
  70. }
  71. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  72. $upload_dir = $conf->resource->dir_output."/".dol_sanitizeFileName($object->ref);
  73. $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
  74. $head[$h][0] = DOL_URL_ROOT.'/resource/document.php?id='.$object->id;
  75. $head[$h][1] = $langs->trans("Documents");
  76. if ($nbFiles > 0) {
  77. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbFiles.'</span>';
  78. }
  79. $head[$h][2] = 'documents';
  80. $h++;
  81. $head[$h][0] = DOL_URL_ROOT.'/resource/agenda.php?id='.$object->id;
  82. $head[$h][1] = $langs->trans("Events");
  83. if (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
  84. $head[$h][1] .= '/';
  85. $head[$h][1] .= $langs->trans("Agenda");
  86. }
  87. $head[$h][2] = 'agenda';
  88. $h++;
  89. /*$head[$h][0] = DOL_URL_ROOT.'/resource/info.php?id='.$object->id;
  90. $head[$h][1] = $langs->trans('Info');
  91. $head[$h][2] = 'info';
  92. $h++;*/
  93. complete_head_from_modules($conf, $langs, $object, $head, $h, 'resource', 'add', 'external');
  94. complete_head_from_modules($conf, $langs, $object, $head, $h, 'resource', 'remove');
  95. return $head;
  96. }
  97. /**
  98. * Prepare head for admin tabs
  99. *
  100. * @return array Array of head entries
  101. */
  102. function resource_admin_prepare_head()
  103. {
  104. global $conf, $db, $langs, $user;
  105. $extrafields = new ExtraFields($db);
  106. $extrafields->fetch_name_optionals_label('resource');
  107. $h = 0;
  108. $head = array();
  109. $head[$h][0] = DOL_URL_ROOT.'/admin/resource.php';
  110. $head[$h][1] = $langs->trans("ResourceSetup");
  111. $head[$h][2] = 'general';
  112. $h++;
  113. // Show more tabs from modules
  114. // Entries must be declared in modules descriptor with line
  115. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  116. // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
  117. complete_head_from_modules($conf, $langs, null, $head, $h, 'resource_admin');
  118. $head[$h][0] = DOL_URL_ROOT.'/admin/resource_extrafields.php';
  119. $head[$h][1] = $langs->trans("ExtraFields");
  120. $nbExtrafields = $extrafields->attributes['resource']['count'];
  121. if ($nbExtrafields > 0) {
  122. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
  123. }
  124. $head[$h][2] = 'attributes';
  125. $h++;
  126. complete_head_from_modules($conf, $langs, null, $head, $h, 'resource_admin', 'remove');
  127. return $head;
  128. }