holiday.lib.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. /* Copyright (C) 2006-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2022 Frédéric France <frederic.france@netlogic.fr>
  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/holiday.lib.php
  21. * \brief base functions for holiday
  22. */
  23. /**
  24. * Return array head with list of tabs to view object informations
  25. *
  26. * @param Object $object Holiday
  27. * @return array head
  28. */
  29. function holiday_prepare_head($object)
  30. {
  31. global $db, $langs, $conf, $user;
  32. $h = 0;
  33. $head = array();
  34. $head[$h][0] = DOL_URL_ROOT.'/holiday/card.php?id='.$object->id;
  35. $head[$h][1] = $langs->trans("Leave");
  36. $head[$h][2] = 'card';
  37. $h++;
  38. // Attachments
  39. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  40. require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
  41. $upload_dir = $conf->holiday->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->ref);
  42. $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
  43. $nbLinks = Link::count($db, $object->element, $object->id);
  44. $head[$h][0] = DOL_URL_ROOT.'/holiday/document.php?id='.$object->id;
  45. $head[$h][1] = $langs->trans('Documents');
  46. if (($nbFiles + $nbLinks) > 0) {
  47. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
  48. }
  49. $head[$h][2] = 'documents';
  50. $h++;
  51. complete_head_from_modules($conf, $langs, $object, $head, $h, 'holiday', 'add', 'core');
  52. $head[$h][0] = DOL_URL_ROOT.'/holiday/info.php?id='.$object->id;
  53. $head[$h][1] = $langs->trans("Info");
  54. $head[$h][2] = 'info';
  55. $h++;
  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, 'holiday', 'add', 'external');
  61. complete_head_from_modules($conf, $langs, $object, $head, $h, 'holiday', 'remove');
  62. return $head;
  63. }
  64. /**
  65. * Return array head with list of tabs to view object informations
  66. *
  67. * @return array head
  68. */
  69. function holiday_admin_prepare_head()
  70. {
  71. global $db, $langs, $conf, $user;
  72. $extrafields = new ExtraFields($db);
  73. $extrafields->fetch_name_optionals_label('holiday');
  74. $h = 0;
  75. $head = array();
  76. $head[$h][0] = DOL_URL_ROOT.'/admin/holiday.php';
  77. $head[$h][1] = $langs->trans("Setup");
  78. $head[$h][2] = 'holiday';
  79. $h++;
  80. // Show more tabs from modules
  81. // Entries must be declared in modules descriptor with line
  82. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  83. // $this->tabs = array('entity:-tabname); to remove a tab
  84. complete_head_from_modules($conf, $langs, null, $head, $h, 'holiday_admin');
  85. $head[$h][0] = DOL_URL_ROOT.'/admin/holiday_extrafields.php';
  86. $head[$h][1] = $langs->trans("ExtraFields");
  87. $nbExtrafields = $extrafields->attributes['holiday']['count'];
  88. if ($nbExtrafields > 0) {
  89. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
  90. }
  91. $head[$h][2] = 'attributes';
  92. $h++;
  93. complete_head_from_modules($conf, $langs, null, $head, $h, 'holiday_admin', 'remove');
  94. return $head;
  95. }