bbus.js.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. /* Copyright (C) 2023 Birnstein Lajos <birnstein.lajos@urbanms.hu>
  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. * Library javascript to enable Browser notifications
  18. */
  19. if (!defined('NOREQUIREUSER')) {
  20. define('NOREQUIREUSER', '1');
  21. }
  22. if (!defined('NOREQUIREDB')) {
  23. define('NOREQUIREDB', '1');
  24. }
  25. if (!defined('NOREQUIRESOC')) {
  26. define('NOREQUIRESOC', '1');
  27. }
  28. if (!defined('NOREQUIRETRAN')) {
  29. define('NOREQUIRETRAN', '1');
  30. }
  31. if (!defined('NOCSRFCHECK')) {
  32. define('NOCSRFCHECK', 1);
  33. }
  34. if (!defined('NOTOKENRENEWAL')) {
  35. define('NOTOKENRENEWAL', 1);
  36. }
  37. if (!defined('NOLOGIN')) {
  38. define('NOLOGIN', 1);
  39. }
  40. if (!defined('NOREQUIREMENU')) {
  41. define('NOREQUIREMENU', 1);
  42. }
  43. if (!defined('NOREQUIREHTML')) {
  44. define('NOREQUIREHTML', 1);
  45. }
  46. if (!defined('NOREQUIREAJAX')) {
  47. define('NOREQUIREAJAX', '1');
  48. }
  49. /**
  50. * \file bbus/js/bbus.js.php
  51. * \ingroup bbus
  52. * \brief JavaScript file for module BBus.
  53. */
  54. // Load Dolibarr environment
  55. $res = 0;
  56. // Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
  57. if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
  58. $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
  59. }
  60. // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
  61. $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
  62. while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
  63. $i--; $j--;
  64. }
  65. if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) {
  66. $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
  67. }
  68. if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/../main.inc.php")) {
  69. $res = @include substr($tmp, 0, ($i + 1))."/../main.inc.php";
  70. }
  71. // Try main.inc.php using relative path
  72. if (!$res && file_exists("../../main.inc.php")) {
  73. $res = @include "../../main.inc.php";
  74. }
  75. if (!$res && file_exists("../../../main.inc.php")) {
  76. $res = @include "../../../main.inc.php";
  77. }
  78. if (!$res) {
  79. die("Include of main fails");
  80. }
  81. // Define js type
  82. header('Content-Type: application/javascript');
  83. // Important: Following code is to cache this file to avoid page request by browser at each Dolibarr page access.
  84. // You can use CTRL+F5 to refresh your browser cache.
  85. if (empty($dolibarr_nocache)) {
  86. header('Cache-Control: max-age=3600, public, must-revalidate');
  87. } else {
  88. header('Cache-Control: no-cache');
  89. }
  90. ?>
  91. /* Javascript library of module BBus */
  92. var checkboxContainerId = 'product_extras_is_in_bundle_';
  93. var id = 0;
  94. function getBundleProductsName(pId) {
  95. var names = '';
  96. var params = {
  97. product_id: pId,
  98. action: 'get_bundle_names'
  99. };
  100. // ajax lekeres
  101. $.ajax({
  102. type: 'POST',
  103. url: '/custom/bbus/bbajaxhandler.php',
  104. success: function (data) {
  105. names = data;
  106. addLabelToCheckbox(names);
  107. },
  108. data: params
  109. });
  110. return names;
  111. }
  112. function addLabelToCheckbox(bundleNames) {
  113. $($('#' + checkboxContainerId + id).find('input')).after(' ' + bundleNames);
  114. }
  115. $(function() {
  116. let _currentPage = window.location.pathname;
  117. if (_currentPage == '/product/card.php') {
  118. let params = (window.location.search).replace('?', '').split('&').map(function (pItem) {
  119. let param = pItem.split('=');
  120. if (param[0] == 'id') {
  121. id = parseInt(param[1]);
  122. }
  123. });
  124. if ($($('#' + checkboxContainerId + id).find('input')).attr('checked') == 'checked') {
  125. if (id > 0) {
  126. getBundleProductsName(id);
  127. }
  128. }
  129. }
  130. });