bookcal_calendar.lib.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. /* Copyright (C) 2023 Alice Adminson <aadminson@example.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 lib/bookcal_calendar.lib.php
  19. * \ingroup bookcal
  20. * \brief Library files with common functions for Calendar
  21. */
  22. /**
  23. * Prepare array of tabs for Calendar
  24. *
  25. * @param Calendar $object Calendar
  26. * @return array Array of tabs
  27. */
  28. function calendarPrepareHead($object)
  29. {
  30. global $db, $langs, $conf;
  31. $langs->load("agenda");
  32. $showtabofpagecontact = 0;
  33. $showtabofpagenote = 1;
  34. $showtabofpagedocument = 0;
  35. $showtabofpageagenda = 1;
  36. $h = 0;
  37. $head = array();
  38. $head[$h][0] = dol_buildpath("/bookcal/calendar_card.php", 1).'?id='.$object->id;
  39. $head[$h][1] = $langs->trans("Calendar");
  40. $head[$h][2] = 'card';
  41. $h++;
  42. if ($showtabofpagecontact) {
  43. $head[$h][0] = dol_buildpath("/bookcal/calendar_contact.php", 1).'?id='.$object->id;
  44. $head[$h][1] = $langs->trans("Contacts");
  45. $head[$h][2] = 'contact';
  46. $h++;
  47. }
  48. if ($showtabofpagenote) {
  49. if (isset($object->fields['note_public']) || isset($object->fields['note_private'])) {
  50. $nbNote = 0;
  51. if (!empty($object->note_private)) {
  52. $nbNote++;
  53. }
  54. if (!empty($object->note_public)) {
  55. $nbNote++;
  56. }
  57. $head[$h][0] = dol_buildpath('/bookcal/calendar_note.php', 1).'?id='.$object->id;
  58. $head[$h][1] = $langs->trans('Notes');
  59. if ($nbNote > 0) {
  60. $head[$h][1] .= (!getDolGlobalInt('MAIN_OPTIMIZEFORTEXTBROWSER') ? '<span class="badge marginleftonlyshort">'.$nbNote.'</span>' : '');
  61. }
  62. $head[$h][2] = 'note';
  63. $h++;
  64. }
  65. }
  66. if ($showtabofpagedocument) {
  67. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  68. require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
  69. $upload_dir = $conf->bookcal->dir_output."/calendar/".dol_sanitizeFileName($object->ref);
  70. $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
  71. $nbLinks = Link::count($db, $object->element, $object->id);
  72. $head[$h][0] = dol_buildpath("/bookcal/calendar_document.php", 1).'?id='.$object->id;
  73. $head[$h][1] = $langs->trans('Documents');
  74. if (($nbFiles + $nbLinks) > 0) {
  75. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
  76. }
  77. $head[$h][2] = 'document';
  78. $h++;
  79. }
  80. if ($showtabofpageagenda) {
  81. $head[$h][0] = dol_buildpath("/bookcal/calendar_agenda.php", 1).'?id='.$object->id;
  82. $head[$h][1] = $langs->trans("Events");
  83. $head[$h][2] = 'agenda';
  84. $h++;
  85. }
  86. // Show more tabs from modules
  87. // Entries must be declared in modules descriptor with line
  88. //$this->tabs = array(
  89. // 'entity:+tabname:Title:@bookcal:/bookcal/mypage.php?id=__ID__'
  90. //); // to add new tab
  91. //$this->tabs = array(
  92. // 'entity:-tabname:Title:@bookcal:/bookcal/mypage.php?id=__ID__'
  93. //); // to remove a tab
  94. complete_head_from_modules($conf, $langs, $object, $head, $h, 'calendar@bookcal');
  95. complete_head_from_modules($conf, $langs, $object, $head, $h, 'calendar@bookcal', 'remove');
  96. return $head;
  97. }