donation.lib.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. /* Copyright (C) 2015 Alexandre Spangaro <aspangaro@open-dsi.fr>
  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 htdocs/core/lib/donation.lib.php
  19. * \ingroup Donation
  20. * \brief Library of donation functions
  21. */
  22. /**
  23. * Prepare array with list of admin tabs
  24. *
  25. * @return array Array of tabs to show
  26. */
  27. function donation_admin_prepare_head()
  28. {
  29. global $langs, $conf, $db;
  30. $extrafields = new ExtraFields($db);
  31. $extrafields->fetch_name_optionals_label('don');
  32. $h = 0;
  33. $head = array();
  34. $head[$h][0] = DOL_URL_ROOT.'/don/admin/donation.php';
  35. $head[$h][1] = $langs->trans("Miscellaneous");
  36. $head[$h][2] = 'general';
  37. $h++;
  38. // Show more tabs from modules
  39. // Entries must be declared in modules descriptor with line
  40. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  41. // $this->tabs = array('entity:-tabname); to remove a tab
  42. complete_head_from_modules($conf, $langs, null, $head, $h, 'donation_admin');
  43. $head[$h][0] = DOL_URL_ROOT.'/don/admin/donation_extrafields.php';
  44. $head[$h][1] = $langs->trans("ExtraFields");
  45. $nbExtrafields = $extrafields->attributes['don']['count'];
  46. if ($nbExtrafields > 0) {
  47. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
  48. }
  49. $head[$h][2] = 'attributes';
  50. $h++;
  51. complete_head_from_modules($conf, $langs, null, $head, $h, 'donation_admin', 'remove');
  52. return $head;
  53. }
  54. /**
  55. * Prepare array with list of tabs
  56. *
  57. * @param Don $object Donation
  58. * @return array Array of tabs to show
  59. */
  60. function donation_prepare_head($object)
  61. {
  62. global $db, $langs, $conf;
  63. $h = 0;
  64. $head = array();
  65. $head[$h][0] = DOL_URL_ROOT.'/don/card.php?id='.$object->id;
  66. $head[$h][1] = $langs->trans("Donation");
  67. $head[$h][2] = 'card';
  68. $h++;
  69. // Show more tabs from modules
  70. // Entries must be declared in modules descriptor with line
  71. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  72. // $this->tabs = array('entity:-tabname); to remove a tab
  73. complete_head_from_modules($conf, $langs, $object, $head, $h, 'donation', 'add', 'core');
  74. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  75. require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
  76. $upload_dir = $conf->don->dir_output.'/'.dol_sanitizeFileName($object->ref);
  77. $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
  78. $nbLinks = Link::count($db, $object->element, $object->id);
  79. $head[$h][0] = DOL_URL_ROOT.'/don/document.php?id='.$object->id;
  80. $head[$h][1] = $langs->trans('Documents');
  81. if (($nbFiles + $nbLinks) > 0) {
  82. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
  83. }
  84. $head[$h][2] = 'documents';
  85. $h++;
  86. $nbNote = 0;
  87. if (!empty($object->note_private)) {
  88. $nbNote++;
  89. }
  90. if (!empty($object->note_public)) {
  91. $nbNote++;
  92. }
  93. $head[$h][0] = DOL_URL_ROOT.'/don/note.php?id='.$object->id;
  94. $head[$h][1] = $langs->trans("Notes");
  95. if ($nbNote > 0) {
  96. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
  97. }
  98. $head[$h][2] = 'note';
  99. $h++;
  100. $head[$h][0] = DOL_URL_ROOT.'/don/info.php?id='.$object->id;
  101. $head[$h][1] = $langs->trans("Info");
  102. $head[$h][2] = 'info';
  103. $h++;
  104. complete_head_from_modules($conf, $langs, $object, $head, $h, 'donation', 'add', 'external');
  105. complete_head_from_modules($conf, $langs, $object, $head, $h, 'donation', 'remove');
  106. return $head;
  107. }