contract.lib.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. * Copyright (C) 2023 Charlene BENKE <charlene@patas-monkey.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. * or see https://www.gnu.org/
  19. */
  20. /**
  21. * \file htdocs/core/lib/contract.lib.php
  22. * \brief Ensemble de fonctions de base pour le module contrat
  23. */
  24. /**
  25. * Prepare array with list of tabs
  26. *
  27. * @param Contrat $object Object related to tabs
  28. * @return array Array of tabs to show
  29. */
  30. function contract_prepare_head(Contrat $object)
  31. {
  32. global $db, $langs, $conf, $user;
  33. $h = 0;
  34. $head = array();
  35. $head[$h][0] = DOL_URL_ROOT.'/contrat/card.php?id='.$object->id;
  36. $head[$h][1] = $langs->trans("ContractCard");
  37. $head[$h][2] = 'card';
  38. $h++;
  39. if (!getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB')) {
  40. $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
  41. $head[$h][0] = DOL_URL_ROOT.'/contrat/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. /* deprecated. Contracts and tickets are already linked with the generic "Link to" feature */
  50. if (isModEnabled('ticket') && getDolGlobalString('TICKET_LINK_TO_CONTRACT_WITH_HARDLINK')) {
  51. $head[$h][0] = DOL_URL_ROOT.'/contrat/ticket.php?id='.$object->id;
  52. $head[$h][1] = $langs->trans("Tickets");
  53. $head[$h][2] = 'ticket';
  54. $h++;
  55. }
  56. // Show more tabs from modules
  57. // Entries must be declared in modules descriptor with line
  58. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  59. // $this->tabs = array('entity:-tabname); to remove a tab
  60. complete_head_from_modules($conf, $langs, $object, $head, $h, 'contract', 'add', 'core');
  61. if (!getDolGlobalString('MAIN_DISABLE_NOTES_TAB')) {
  62. $nbNote = 0;
  63. if (!empty($object->note_private)) {
  64. $nbNote++;
  65. }
  66. if (!empty($object->note_public)) {
  67. $nbNote++;
  68. }
  69. $head[$h][0] = DOL_URL_ROOT.'/contrat/note.php?id='.$object->id;
  70. $head[$h][1] = $langs->trans("Notes");
  71. if ($nbNote > 0) {
  72. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
  73. }
  74. $head[$h][2] = 'note';
  75. $h++;
  76. }
  77. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  78. require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
  79. $upload_dir = $conf->contrat->multidir_output[$object->entity]."/".dol_sanitizeFileName($object->ref);
  80. $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
  81. $nbLinks = Link::count($db, $object->element, $object->id);
  82. $head[$h][0] = DOL_URL_ROOT.'/contrat/document.php?id='.$object->id;
  83. $head[$h][1] = $langs->trans("Documents");
  84. if (($nbFiles + $nbLinks) > 0) {
  85. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
  86. }
  87. $head[$h][2] = 'documents';
  88. $h++;
  89. $head[$h][0] = DOL_URL_ROOT.'/contrat/agenda.php?id='.$object->id;
  90. $head[$h][1] = $langs->trans("Events");
  91. if (isModEnabled('agenda')&& ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
  92. $nbEvent = 0;
  93. // Enable caching of thirdparty count actioncomm
  94. require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
  95. $cachekey = 'count_events_contract_'.$object->id;
  96. $dataretrieved = dol_getcache($cachekey);
  97. if (!is_null($dataretrieved)) {
  98. $nbEvent = $dataretrieved;
  99. } else {
  100. $sql = "SELECT COUNT(id) as nb";
  101. $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm";
  102. $sql .= " WHERE fk_element = ".((int) $object->id);
  103. $sql .= " AND elementtype = 'contract'";
  104. $resql = $db->query($sql);
  105. if ($resql) {
  106. $obj = $db->fetch_object($resql);
  107. $nbEvent = $obj->nb;
  108. } else {
  109. dol_syslog('Failed to count actioncomm '.$db->lasterror(), LOG_ERR);
  110. }
  111. dol_setcache($cachekey, $nbEvent, 120); // If setting cache fails, this is not a problem, so we do not test result.
  112. }
  113. $head[$h][1] .= '/';
  114. $head[$h][1] .= $langs->trans("Agenda");
  115. if ($nbEvent > 0) {
  116. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbEvent.'</span>';
  117. }
  118. }
  119. $head[$h][2] = 'agenda';
  120. $h++;
  121. complete_head_from_modules($conf, $langs, $object, $head, $h, 'contract', 'add', 'external');
  122. complete_head_from_modules($conf, $langs, $object, $head, $h, 'contract', 'remove');
  123. return $head;
  124. }
  125. /**
  126. * Return array head with list of tabs to view object informations.
  127. *
  128. * @return array head array with tabs
  129. */
  130. function contract_admin_prepare_head()
  131. {
  132. global $langs, $conf, $db;
  133. $extrafields = new ExtraFields($db);
  134. $extrafields->fetch_name_optionals_label('contrat');
  135. $extrafields->fetch_name_optionals_label('contratdet');
  136. $h = 0;
  137. $head = array();
  138. $head[$h][0] = DOL_URL_ROOT."/admin/contract.php";
  139. $head[$h][1] = $langs->trans("Contracts");
  140. $head[$h][2] = 'contract';
  141. $h++;
  142. // Show more tabs from modules
  143. // Entries must be declared in modules descriptor with line
  144. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  145. // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
  146. complete_head_from_modules($conf, $langs, null, $head, $h, 'contract_admin', 'add', 'core');
  147. $head[$h][0] = DOL_URL_ROOT.'/contrat/admin/contract_extrafields.php';
  148. $head[$h][1] = $langs->trans("ExtraFields");
  149. $nbExtrafields = $extrafields->attributes['contrat']['count'];
  150. if ($nbExtrafields > 0) {
  151. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
  152. }
  153. $head[$h][2] = 'attributes';
  154. $h++;
  155. $head[$h][0] = DOL_URL_ROOT.'/contrat/admin/contractdet_extrafields.php';
  156. $head[$h][1] = $langs->trans("ExtraFieldsLines");
  157. $nbExtrafields = $extrafields->attributes['contratdet']['count'];
  158. if ($nbExtrafields > 0) {
  159. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
  160. }
  161. $head[$h][2] = 'attributeslines';
  162. $h++;
  163. complete_head_from_modules($conf, $langs, null, $head, $h, 'contract_admin', 'add', 'external');
  164. complete_head_from_modules($conf, $langs, null, $head, $h, 'contract_admin', 'remove');
  165. return $head;
  166. }