bbajaxhandler.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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'];
  62. $tmp2 = realpath(__FILE__);
  63. $i = strlen($tmp) - 1;
  64. $j = strlen($tmp2) - 1;
  65. while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
  66. $i--;
  67. $j--;
  68. }
  69. if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1)) . "/main.inc.php")) {
  70. $res = @include substr($tmp, 0, ($i + 1)) . "/main.inc.php";
  71. }
  72. if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1)) . "/../main.inc.php")) {
  73. $res = @include substr($tmp, 0, ($i + 1)) . "/../main.inc.php";
  74. }
  75. // Try main.inc.php using relative path
  76. if (!$res && file_exists("../../main.inc.php")) {
  77. $res = @include "../../main.inc.php";
  78. }
  79. if (!$res && file_exists("../../../main.inc.php")) {
  80. $res = @include "../../../main.inc.php";
  81. }
  82. if (!$res) {
  83. die("Include of main fails");
  84. }
  85. // Define js type
  86. header('Content-Type: text/html');
  87. // Important: Following code is to cache this file to avoid page request by browser at each Dolibarr page access.
  88. // You can use CTRL+F5 to refresh your browser cache.
  89. if (empty($dolibarr_nocache)) {
  90. header('Cache-Control: max-age=3600, public, must-revalidate');
  91. } else {
  92. header('Cache-Control: no-cache');
  93. }
  94. require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
  95. require_once DOL_DOCUMENT_ROOT . '/custom/bbus/class/bbappversion.class.php';
  96. $action = GETPOST('action');
  97. // **********************
  98. // get bundle names
  99. // **********************
  100. if ($action == 'get_bundle_names') {
  101. $bundleNames = '';
  102. $productId = GETPOST('product_id', 'int');
  103. if ($productId > 0) {
  104. $product = new Product($db);
  105. if ($product->fetch($productId) > 0) {
  106. $bundles = $product->getFather();
  107. if (!empty($bundles)) {
  108. $bundleNames = implode(', ', array_map(function ($item) {
  109. return $item['label'];
  110. }, $bundles));
  111. }
  112. }
  113. }
  114. echo $bundleNames;
  115. }
  116. // **********************
  117. // version
  118. // **********************
  119. if ($action == 'app_version') {
  120. $version = 'all version';
  121. $versionObj = new BbAppVersion($db);
  122. $rows = $versionObj->fetchAll('DESC', 'release_date', 1, 0, ['customsql' => 'release_date::DATE <= CURRENT_DATE']);
  123. if (is_array($rows)) {
  124. foreach ($rows as $row) {
  125. $version = $row->version . '-' . $row->build;
  126. }
  127. }
  128. echo $version;
  129. }
  130. // **********************
  131. // entity by IMEI
  132. // **********************
  133. if ($action == 'entity_by_imei') {
  134. $imei = GETPOST('imei', 'aZ09');
  135. if ($imei == '11111') {
  136. echo 1;
  137. } else {
  138. $imei = GETPOST('imei', 'aZ09');
  139. $sql = "SELECT p.fk_entity FROM llx_inventory as i
  140. INNER JOIN llx_inventory_extrafields as ie ON ie.fk_object = i.rowid
  141. INNER JOIN llx_settlements_packagetool as pt ON pt.device_id = i.rowid
  142. INNER JOIN llx_settlements_package as p ON p.rowid = pt.package_id
  143. WHERE ie.unique_identifier = '{$imei}'";
  144. $data = $db->query($sql);
  145. while ($row = pg_fetch_assoc($data)) {
  146. echo $row['fk_entity'];
  147. exit;
  148. }
  149. echo 0;
  150. }
  151. }