resource.lib.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 <glgpoirier@gmail.com>
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/core/lib/resource.lib.php
  21. * \ingroup resource
  22. * \brief This file is library for resource module
  23. */
  24. /**
  25. * Prepare head for tabs
  26. *
  27. * @param Object $object Object
  28. * @return array Array of head entries
  29. */
  30. function resource_prepare_head($object)
  31. {
  32. global $langs, $conf, $user;
  33. $h = 0;
  34. $head = array();
  35. $head[$h][0] = dol_buildpath('/resource/card.php', 1).'?id='.$object->id;
  36. $head[$h][1] = $langs->trans("ResourceCard");
  37. $head[$h][2] = 'resource';
  38. $h++;
  39. if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && (empty($conf->global->RESOURCE_HIDE_ADD_CONTACT_USER) || empty($conf->global->RESOURCE_HIDE_ADD_CONTACT_THIPARTY))) {
  40. $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
  41. $head[$h][0] = DOL_URL_ROOT.'/resource/contact.php?id='.$object->id;
  42. $head[$h][1] = $langs->trans('ContactsAddresses');
  43. if ($nbContact > 0) {
  44. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
  45. }
  46. $head[$h][2] = 'contact';
  47. $h++;
  48. }
  49. // Show more tabs from modules
  50. // Entries must be declared in modules descriptor with line
  51. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  52. // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
  53. complete_head_from_modules($conf, $langs, $object, $head, $h, 'resource', 'add', 'core');
  54. if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
  55. $nbNote = 0;
  56. if (!empty($object->note_private)) {
  57. $nbNote++;
  58. }
  59. if (!empty($object->note_public)) {
  60. $nbNote++;
  61. }
  62. $head[$h][0] = DOL_URL_ROOT.'/resource/note.php?id='.$object->id;
  63. $head[$h][1] = $langs->trans('Notes');
  64. if ($nbNote > 0) {
  65. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
  66. }
  67. $head[$h][2] = 'note';
  68. $h++;
  69. }
  70. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  71. $upload_dir = $conf->resource->dir_output."/".dol_sanitizeFileName($object->ref);
  72. $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
  73. $head[$h][0] = DOL_URL_ROOT.'/resource/document.php?id='.$object->id;
  74. $head[$h][1] = $langs->trans("Documents");
  75. if ($nbFiles > 0) {
  76. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbFiles.'</span>';
  77. }
  78. $head[$h][2] = 'documents';
  79. $h++;
  80. $head[$h][0] = DOL_URL_ROOT.'/resource/agenda.php?id='.$object->id;
  81. $head[$h][1] = $langs->trans("Events");
  82. if (isModEnabled('agenda') && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) {
  83. $head[$h][1] .= '/';
  84. $head[$h][1] .= $langs->trans("Agenda");
  85. }
  86. $head[$h][2] = 'agenda';
  87. $h++;
  88. /*$head[$h][0] = DOL_URL_ROOT.'/resource/info.php?id='.$object->id;
  89. $head[$h][1] = $langs->trans('Info');
  90. $head[$h][2] = 'info';
  91. $h++;*/
  92. complete_head_from_modules($conf, $langs, $object, $head, $h, 'resource', 'add', 'external');
  93. complete_head_from_modules($conf, $langs, $object, $head, $h, 'resource', 'remove');
  94. return $head;
  95. }
  96. /**
  97. * Prepare head for admin tabs
  98. *
  99. * @return array Array of head entries
  100. */
  101. function resource_admin_prepare_head()
  102. {
  103. global $langs, $conf, $user;
  104. $h = 0;
  105. $head = array();
  106. $head[$h][0] = DOL_URL_ROOT.'/admin/resource.php';
  107. $head[$h][1] = $langs->trans("ResourceSetup");
  108. $head[$h][2] = 'general';
  109. $h++;
  110. // Show more tabs from modules
  111. // Entries must be declared in modules descriptor with line
  112. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  113. // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
  114. complete_head_from_modules($conf, $langs, null, $head, $h, 'resource_admin');
  115. $head[$h][0] = DOL_URL_ROOT.'/admin/resource_extrafields.php';
  116. $head[$h][1] = $langs->trans("ExtraFields");
  117. $head[$h][2] = 'attributes';
  118. $h++;
  119. complete_head_from_modules($conf, $langs, null, $head, $h, 'resource_admin', 'remove');
  120. return $head;
  121. }