| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- <?php
- /* Copyright (C) 2023 Birnstein Lajos <birnstein.lajos@urbanms.hu>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- *
- * Library javascript to enable Browser notifications
- */
- if (!defined('NOREQUIREUSER')) {
- define('NOREQUIREUSER', '1');
- }
- if (!defined('NOREQUIREDB')) {
- //define('NOREQUIREDB', '1');
- }
- if (!defined('NOREQUIRESOC')) {
- define('NOREQUIRESOC', '1');
- }
- if (!defined('NOREQUIRETRAN')) {
- //define('NOREQUIRETRAN', '1');
- }
- if (!defined('NOCSRFCHECK')) {
- define('NOCSRFCHECK', 1);
- }
- if (!defined('NOTOKENRENEWAL')) {
- define('NOTOKENRENEWAL', 1);
- }
- if (!defined('NOLOGIN')) {
- define('NOLOGIN', 1);
- }
- if (!defined('NOREQUIREMENU')) {
- define('NOREQUIREMENU', 1);
- }
- if (!defined('NOREQUIREHTML')) {
- define('NOREQUIREHTML', 1);
- }
- if (!defined('NOREQUIREAJAX')) {
- define('NOREQUIREAJAX', '1');
- }
- /**
- * \file bbus/js/bbus.js.php
- * \ingroup bbus
- * \brief JavaScript file for module BBus.
- */
- // Load Dolibarr environment
- $res = 0;
- // Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
- if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
- $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"] . "/main.inc.php";
- }
- // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
- $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME'];
- $tmp2 = realpath(__FILE__);
- $i = strlen($tmp) - 1;
- $j = strlen($tmp2) - 1;
- while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
- $i--;
- $j--;
- }
- if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1)) . "/main.inc.php")) {
- $res = @include substr($tmp, 0, ($i + 1)) . "/main.inc.php";
- }
- if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1)) . "/../main.inc.php")) {
- $res = @include substr($tmp, 0, ($i + 1)) . "/../main.inc.php";
- }
- // Try main.inc.php using relative path
- if (!$res && file_exists("../../main.inc.php")) {
- $res = @include "../../main.inc.php";
- }
- if (!$res && file_exists("../../../main.inc.php")) {
- $res = @include "../../../main.inc.php";
- }
- if (!$res) {
- die("Include of main fails");
- }
- // Define js type
- header('Content-Type: text/html');
- // Important: Following code is to cache this file to avoid page request by browser at each Dolibarr page access.
- // You can use CTRL+F5 to refresh your browser cache.
- if (empty($dolibarr_nocache)) {
- header('Cache-Control: max-age=3600, public, must-revalidate');
- } else {
- header('Cache-Control: no-cache');
- }
- require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
- require_once DOL_DOCUMENT_ROOT . '/custom/bbus/class/bbappversion.class.php';
- $action = GETPOST('action');
- // **********************
- // get bundle names
- // **********************
- if ($action == 'get_bundle_names') {
- $bundleNames = '';
- $productId = GETPOST('product_id', 'int');
- if ($productId > 0) {
- $product = new Product($db);
- if ($product->fetch($productId) > 0) {
- $bundles = $product->getFather();
- if (!empty($bundles)) {
- $bundleNames = implode(', ', array_map(function ($item) {
- return $item['label'];
- }, $bundles));
- }
- }
- }
- echo $bundleNames;
- }
- // **********************
- // version
- // **********************
- if ($action == 'app_version') {
- $version = 'all version';
- $versionObj = new BbAppVersion($db);
- $rows = $versionObj->fetchAll('DESC', 'release_date', 1, 0, ['customsql' => 'release_date::DATE <= CURRENT_DATE']);
- if (is_array($rows)) {
- foreach ($rows as $row) {
- $version = $row->version . '-' . $row->build;
- }
- }
- echo $version;
- }
- // **********************
- // entity by IMEI
- // **********************
- if ($action == 'entity_by_imei') {
- $imei = GETPOST('imei', 'aZ09');
- if ($imei == '11111') {
- echo 1;
- } else {
- $imei = GETPOST('imei', 'aZ09');
- $sql = "SELECT p.fk_entity FROM llx_inventory as i
- INNER JOIN llx_inventory_extrafields as ie ON ie.fk_object = i.rowid
- INNER JOIN llx_settlements_packagetool as pt ON pt.device_id = i.rowid
- INNER JOIN llx_settlements_package as p ON p.rowid = pt.package_id
- WHERE ie.unique_identifier = '{$imei}'";
- $data = $db->query($sql);
- while ($row = pg_fetch_assoc($data)) {
- echo $row['fk_entity'];
- exit;
- }
- echo 0;
- }
- }
|