propal.lib.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. *
  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/propal.lib.php
  21. * \brief Ensemble de fonctions de base pour le module propal
  22. * \ingroup propal
  23. */
  24. /**
  25. * Prepare array with list of tabs
  26. *
  27. * @param object $object Object related to tabs
  28. * @return array Array of tabs to show
  29. */
  30. function propal_prepare_head($object)
  31. {
  32. global $db, $langs, $conf, $user;
  33. $langs->loadLangs(array('propal', 'compta', 'companies'));
  34. $h = 0;
  35. $head = array();
  36. $head[$h][0] = DOL_URL_ROOT.'/comm/propal/card.php?id='.$object->id;
  37. $head[$h][1] = $langs->trans('Proposal');
  38. $head[$h][2] = 'comm';
  39. $h++;
  40. if ((empty($conf->commande->enabled) && ((!empty($conf->expedition->enabled) && !empty($conf->expedition_bon->enabled) && $user->rights->expedition->lire)
  41. || (!empty($conf->expedition->enabled) && !empty($conf->livraison_bon->enabled) && $user->rights->expedition->livraison->lire))))
  42. {
  43. $langs->load("sendings");
  44. $text = '';
  45. $head[$h][0] = DOL_URL_ROOT.'/expedition/propal.php?id='.$object->id;
  46. if ($conf->expedition_bon->enabled) $text = $langs->trans("Shipment");
  47. if ($conf->livraison_bon->enabled) $text .= '/'.$langs->trans("Receivings");
  48. $head[$h][1] = $text;
  49. $head[$h][2] = 'shipping';
  50. $h++;
  51. }
  52. if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB))
  53. {
  54. $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
  55. $head[$h][0] = DOL_URL_ROOT.'/comm/propal/contact.php?id='.$object->id;
  56. $head[$h][1] = $langs->trans('ContactsAddresses');
  57. if ($nbContact > 0) $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
  58. $head[$h][2] = 'contact';
  59. $h++;
  60. }
  61. // Show more tabs from modules
  62. // Entries must be declared in modules descriptor with line
  63. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  64. // $this->tabs = array('entity:-tabname); to remove a tab
  65. complete_head_from_modules($conf, $langs, $object, $head, $h, 'propal');
  66. if (empty($conf->global->MAIN_DISABLE_NOTES_TAB))
  67. {
  68. $nbNote = 0;
  69. if (!empty($object->note_private)) $nbNote++;
  70. if (!empty($object->note_public)) $nbNote++;
  71. $head[$h][0] = DOL_URL_ROOT.'/comm/propal/note.php?id='.$object->id;
  72. $head[$h][1] = $langs->trans('Notes');
  73. if ($nbNote > 0) $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
  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->propal->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.'/comm/propal/document.php?id='.$object->id;
  83. $head[$h][1] = $langs->trans('Documents');
  84. if (($nbFiles + $nbLinks) > 0) $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
  85. $head[$h][2] = 'document';
  86. $h++;
  87. $head[$h][0] = DOL_URL_ROOT.'/comm/propal/info.php?id='.$object->id;
  88. $head[$h][1] = $langs->trans('Info');
  89. $head[$h][2] = 'info';
  90. $h++;
  91. complete_head_from_modules($conf, $langs, $object, $head, $h, 'propal', 'remove');
  92. return $head;
  93. }
  94. /**
  95. * Return array head with list of tabs to view object informations.
  96. *
  97. * @return array head array with tabs
  98. */
  99. function propal_admin_prepare_head()
  100. {
  101. global $langs, $conf, $user;
  102. $h = 0;
  103. $head = array();
  104. $head[$h][0] = DOL_URL_ROOT.'/admin/propal.php';
  105. $head[$h][1] = $langs->trans("Miscellaneous");
  106. $head[$h][2] = 'general';
  107. $h++;
  108. // Show more tabs from modules
  109. // Entries must be declared in modules descriptor with line
  110. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  111. // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
  112. complete_head_from_modules($conf, $langs, null, $head, $h, 'propal_admin');
  113. $head[$h][0] = DOL_URL_ROOT.'/comm/admin/propal_extrafields.php';
  114. $head[$h][1] = $langs->trans("ExtraFields");
  115. $head[$h][2] = 'attributes';
  116. $h++;
  117. $head[$h][0] = DOL_URL_ROOT.'/comm/admin/propaldet_extrafields.php';
  118. $head[$h][1] = $langs->trans("ExtraFieldsLines");
  119. $head[$h][2] = 'attributeslines';
  120. $h++;
  121. complete_head_from_modules($conf, $langs, null, $head, $h, 'propal_admin', 'remove');
  122. return $head;
  123. }