supplier_proposal.lib.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. /* Copyright (C) 2006-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  4. * Copyright (C) 2022 Frédéric France <frederic.france@netlogic.fr>
  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/propal.lib.php
  22. * \brief Ensemble de fonctions de base pour le module propal
  23. * \ingroup propal
  24. */
  25. /**
  26. * Prepare array with list of tabs
  27. *
  28. * @param object $object Object related to tabs
  29. * @return array Array of tabs to show
  30. */
  31. function supplier_proposal_prepare_head($object)
  32. {
  33. global $db, $langs, $conf, $user;
  34. // Load translation files required by the page
  35. $langs->loadLangs(array("supplier_proposal", "compta"));
  36. $h = 0;
  37. $head = array();
  38. $head[$h][0] = DOL_URL_ROOT.'/supplier_proposal/card.php?id='.$object->id;
  39. $head[$h][1] = $langs->trans('CommRequests');
  40. $head[$h][2] = 'comm';
  41. $h++;
  42. if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
  43. $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
  44. $head[$h][0] = DOL_URL_ROOT.'/supplier_proposal/contact.php?id='.$object->id;
  45. $head[$h][1] = $langs->trans('ContactsAddresses');
  46. if ($nbContact > 0) {
  47. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
  48. }
  49. $head[$h][2] = 'contact';
  50. $h++;
  51. }
  52. // Show more tabs from modules
  53. // Entries must be declared in modules descriptor with line
  54. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  55. // $this->tabs = array('entity:-tabname); to remove a tab
  56. complete_head_from_modules($conf, $langs, $object, $head, $h, 'supplier_proposal', 'add', 'core');
  57. if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
  58. $nbNote = 0;
  59. if (!empty($object->note_private)) {
  60. $nbNote++;
  61. }
  62. if (!empty($object->note_public)) {
  63. $nbNote++;
  64. }
  65. $head[$h][0] = DOL_URL_ROOT.'/supplier_proposal/note.php?id='.$object->id;
  66. $head[$h][1] = $langs->trans('Notes');
  67. if ($nbNote > 0) {
  68. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
  69. }
  70. $head[$h][2] = 'note';
  71. $h++;
  72. }
  73. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  74. require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
  75. $upload_dir = $conf->supplier_proposal->dir_output."/".dol_sanitizeFileName($object->ref);
  76. $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
  77. $nbLinks = Link::count($db, $object->element, $object->id);
  78. $head[$h][0] = DOL_URL_ROOT.'/supplier_proposal/document.php?id='.$object->id;
  79. $head[$h][1] = $langs->trans('Documents');
  80. if (($nbFiles + $nbLinks) > 0) {
  81. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
  82. }
  83. $head[$h][2] = 'document';
  84. $h++;
  85. $head[$h][0] = DOL_URL_ROOT.'/supplier_proposal/info.php?id='.$object->id;
  86. $head[$h][1] = $langs->trans('Info');
  87. $head[$h][2] = 'info';
  88. $h++;
  89. complete_head_from_modules($conf, $langs, $object, $head, $h, 'supplier_proposal', 'add', 'external');
  90. complete_head_from_modules($conf, $langs, $object, $head, $h, 'supplier_proposal', '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 supplier_proposal_admin_prepare_head()
  99. {
  100. global $langs, $conf, $user, $db;
  101. $extrafields = new ExtraFields($db);
  102. $extrafields->fetch_name_optionals_label('supplier_proposal');
  103. $extrafields->fetch_name_optionals_label('supplier_proposaldet');
  104. $h = 0;
  105. $head = array();
  106. $head[$h][0] = DOL_URL_ROOT.'/admin/supplier_proposal.php';
  107. $head[$h][1] = $langs->trans("Miscellaneous");
  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, 'supplier_proposal_admin');
  115. $head[$h][0] = DOL_URL_ROOT.'/supplier_proposal/admin/supplier_proposal_extrafields.php';
  116. $head[$h][1] = $langs->trans("ExtraFields");
  117. $nbExtrafields = $extrafields->attributes['supplier_proposal']['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.'/supplier_proposal/admin/supplier_proposaldet_extrafields.php';
  124. $head[$h][1] = $langs->trans("ExtraFieldsLines");
  125. $nbExtrafields = $extrafields->attributes['supplier_proposaldet']['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, 'supplier_proposal_admin', 'remove');
  132. return $head;
  133. }