contract.lib.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. /* Copyright (C) 2006-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2009-2012 Regis Houssin <regis.houssin@inodbox.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. * or see https://www.gnu.org/
  18. */
  19. /**
  20. * \file htdocs/core/lib/contract.lib.php
  21. * \brief Ensemble de fonctions de base pour le module contrat
  22. */
  23. /**
  24. * Prepare array with list of tabs
  25. *
  26. * @param Contrat $object Object related to tabs
  27. * @return array Array of tabs to show
  28. */
  29. function contract_prepare_head(Contrat $object)
  30. {
  31. global $db, $langs, $conf, $user;
  32. $h = 0;
  33. $head = array();
  34. $head[$h][0] = DOL_URL_ROOT.'/contrat/card.php?id='.$object->id;
  35. $head[$h][1] = $langs->trans("ContractCard");
  36. $head[$h][2] = 'card';
  37. $h++;
  38. if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
  39. $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
  40. $head[$h][0] = DOL_URL_ROOT.'/contrat/contact.php?id='.$object->id;
  41. $head[$h][1] = $langs->trans("ContactsAddresses");
  42. if ($nbContact > 0) {
  43. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
  44. }
  45. $head[$h][2] = 'contact';
  46. $h++;
  47. }
  48. // Show more tabs from modules
  49. // Entries must be declared in modules descriptor with line
  50. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  51. // $this->tabs = array('entity:-tabname); to remove a tab
  52. complete_head_from_modules($conf, $langs, $object, $head, $h, 'contract', 'add', 'core');
  53. if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
  54. $nbNote = 0;
  55. if (!empty($object->note_private)) {
  56. $nbNote++;
  57. }
  58. if (!empty($object->note_public)) {
  59. $nbNote++;
  60. }
  61. $head[$h][0] = DOL_URL_ROOT.'/contrat/note.php?id='.$object->id;
  62. $head[$h][1] = $langs->trans("Notes");
  63. if ($nbNote > 0) {
  64. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
  65. }
  66. $head[$h][2] = 'note';
  67. $h++;
  68. }
  69. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  70. require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
  71. $upload_dir = $conf->contrat->multidir_output[$object->entity]."/".dol_sanitizeFileName($object->ref);
  72. $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
  73. $nbLinks = Link::count($db, $object->element, $object->id);
  74. $head[$h][0] = DOL_URL_ROOT.'/contrat/document.php?id='.$object->id;
  75. $head[$h][1] = $langs->trans("Documents");
  76. if (($nbFiles + $nbLinks) > 0) {
  77. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
  78. }
  79. $head[$h][2] = 'documents';
  80. $h++;
  81. $head[$h][0] = DOL_URL_ROOT.'/contrat/agenda.php?id='.$object->id;
  82. $head[$h][1] = $langs->trans("Events");
  83. if (isModEnabled('agenda') && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) {
  84. $head[$h][1] .= '/';
  85. $head[$h][1] .= $langs->trans("Agenda");
  86. }
  87. $head[$h][2] = 'agenda';
  88. $h++;
  89. complete_head_from_modules($conf, $langs, $object, $head, $h, 'contract', 'add', 'external');
  90. complete_head_from_modules($conf, $langs, $object, $head, $h, 'contract', 'remove');
  91. return $head;
  92. }
  93. /**
  94. * Return array head with list of tabs to view object informations.
  95. *
  96. * @return array head array with tabs
  97. */
  98. function contract_admin_prepare_head()
  99. {
  100. global $langs, $conf, $db;
  101. $extrafields = new ExtraFields($db);
  102. $extrafields->fetch_name_optionals_label('contrat');
  103. $extrafields->fetch_name_optionals_label('contratdet');
  104. $h = 0;
  105. $head = array();
  106. $head[$h][0] = DOL_URL_ROOT."/admin/contract.php";
  107. $head[$h][1] = $langs->trans("Contracts");
  108. $head[$h][2] = 'contract';
  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, 'contract_admin', 'add', 'core');
  115. $head[$h][0] = DOL_URL_ROOT.'/contrat/admin/contract_extrafields.php';
  116. $head[$h][1] = $langs->trans("ExtraFields");
  117. $nbExtrafields = $extrafields->attributes['contrat']['count'];
  118. if ($nbExtrafields > 0) {
  119. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
  120. }
  121. $head[$h][2] = 'attributes';
  122. $h++;
  123. $head[$h][0] = DOL_URL_ROOT.'/contrat/admin/contractdet_extrafields.php';
  124. $head[$h][1] = $langs->trans("ExtraFieldsLines");
  125. $nbExtrafields = $extrafields->attributes['contratdet']['count'];
  126. if ($nbExtrafields > 0) {
  127. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
  128. }
  129. $head[$h][2] = 'attributeslines';
  130. $h++;
  131. complete_head_from_modules($conf, $langs, null, $head, $h, 'contract_admin', 'add', 'external');
  132. complete_head_from_modules($conf, $langs, null, $head, $h, 'contract_admin', 'remove');
  133. return $head;
  134. }