partnership.lib.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. /* Copyright (C) 2021 Dorian Laurent <i.merraha@sofimedmaroc.com>
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file partnership/lib/partnership.lib.php
  19. * \ingroup partnership
  20. * \brief Library files with common functions for Partnership
  21. */
  22. /**
  23. * Prepare admin pages header
  24. *
  25. * @return array
  26. */
  27. function partnershipAdminPrepareHead()
  28. {
  29. global $langs, $conf, $db;
  30. $langs->loadLangs(array("members", "partnership"));
  31. $extrafields = new ExtraFields($db);
  32. $extrafields->fetch_name_optionals_label('partnership');
  33. $h = 0;
  34. $head = array();
  35. $head[$h][0] = dol_buildpath("/partnership/admin/setup.php", 1);
  36. $head[$h][1] = $langs->trans("Settings");
  37. $head[$h][2] = 'settings';
  38. $h++;
  39. $head[$h][0] = dol_buildpath("/partnership/admin/partnership_extrafields.php", 1);
  40. $head[$h][1] = $langs->trans("ExtraFields");
  41. $nbExtrafields = $extrafields->attributes['partnership']['count'];
  42. if ($nbExtrafields > 0) {
  43. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
  44. }
  45. $head[$h][2] = 'partnership_extrafields';
  46. $h++;
  47. $head[$h][0] = dol_buildpath("/partnership/admin/website.php", 1);
  48. $head[$h][1] = $langs->trans("BlankSubscriptionForm");
  49. $head[$h][2] = 'website';
  50. $h++;
  51. // Show more tabs from modules
  52. // Entries must be declared in modules descriptor with line
  53. //$this->tabs = array(
  54. // 'entity:+tabname:Title:@partnership:/partnership/mypage.php?id=__ID__'
  55. //); // to add new tab
  56. //$this->tabs = array(
  57. // 'entity:-tabname:Title:@partnership:/partnership/mypage.php?id=__ID__'
  58. //); // to remove a tab
  59. complete_head_from_modules($conf, $langs, null, $head, $h, 'partnership');
  60. complete_head_from_modules($conf, $langs, null, $head, $h, 'partnership', 'remove');
  61. return $head;
  62. }
  63. /**
  64. * Prepare array of tabs for Partnership
  65. *
  66. * @param Partnership $object Partnership
  67. * @return array Array of tabs
  68. */
  69. function partnershipPrepareHead($object)
  70. {
  71. global $db, $langs, $conf;
  72. $langs->load("partnership");
  73. $h = 0;
  74. $head = array();
  75. $head[$h][0] = dol_buildpath("/partnership/partnership_card.php", 1).'?id='.$object->id;
  76. $head[$h][1] = $langs->trans("Card");
  77. $head[$h][2] = 'card';
  78. $h++;
  79. if (isset($object->fields['note_public']) || isset($object->fields['note_private'])) {
  80. $nbNote = 0;
  81. if (!empty($object->note_private)) {
  82. $nbNote++;
  83. }
  84. if (!empty($object->note_public)) {
  85. $nbNote++;
  86. }
  87. $head[$h][0] = dol_buildpath('/partnership/partnership_note.php', 1).'?id='.$object->id;
  88. $head[$h][1] = $langs->trans('Notes');
  89. if ($nbNote > 0) {
  90. $head[$h][1] .= (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ? '<span class="badge marginleftonlyshort">'.$nbNote.'</span>' : '');
  91. }
  92. $head[$h][2] = 'note';
  93. $h++;
  94. }
  95. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  96. require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
  97. $upload_dir = $conf->partnership->dir_output."/partnership/".dol_sanitizeFileName($object->ref);
  98. $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
  99. $nbLinks = Link::count($db, $object->element, $object->id);
  100. $head[$h][0] = dol_buildpath("/partnership/partnership_document.php", 1).'?id='.$object->id;
  101. $head[$h][1] = $langs->trans('Documents');
  102. if (($nbFiles + $nbLinks) > 0) {
  103. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
  104. }
  105. $head[$h][2] = 'document';
  106. $h++;
  107. $head[$h][0] = dol_buildpath("/partnership/partnership_agenda.php", 1).'?id='.$object->id;
  108. $head[$h][1] = $langs->trans("Events");
  109. $head[$h][2] = 'agenda';
  110. $h++;
  111. // Show more tabs from modules
  112. // Entries must be declared in modules descriptor with line
  113. //$this->tabs = array(
  114. // 'entity:+tabname:Title:@partnership:/partnership/mypage.php?id=__ID__'
  115. //); // to add new tab
  116. //$this->tabs = array(
  117. // 'entity:-tabname:Title:@partnership:/partnership/mypage.php?id=__ID__'
  118. //); // to remove a tab
  119. complete_head_from_modules($conf, $langs, $object, $head, $h, 'partnership');
  120. complete_head_from_modules($conf, $langs, $object, $head, $h, 'partnership', 'remove');
  121. return $head;
  122. }