| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- <?php
- $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(dirname(substr($tmp, 0, ($i + 1))) . "/main.inc.php")) {
- $res = @include dirname(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 && file_exists("../../../main.inc.php")) {
- $res = @include "../../../main.inc.php";
- }
- if (!$res) {
- die("Include of main fails");
- }
- require_once DOL_DOCUMENT_ROOT . '/custom/settlements/class/helper.class.php';
- $helper = new Helper($db);
- $oneselect = GETPOST('oneselect', 'int');
- $search_package_name = GETPOST('search_package_name', 'alpha');
- $toselectnewpackage = GETPOST('toselectnewpackage', 'alpha');
- $reduction = GETPOST('reduction', 'alpha');
- $groupid = GETPOST('groupid', 'int');
- $selectedArray = explode(',', $toselectnewpackage);
- if (isset($_SESSION['package_array'])) {
- $package_array = $_SESSION['package_array'];
- if ($toselectnewpackage !== '') {
- $_SESSION['package_array'] = array_unique(array_merge($package_array, $selectedArray));
- }
- if ($reduction !== '') {
- $_SESSION['package_array'] = explode(',', $reduction);
- }
- $selectedArray = $_SESSION['package_array'];
- if ($toselectnewpackage === '' && $reduction === '' && $search_package_name === '') {
- unset($_SESSION['package_array']);
- $selectedArray = [];
- }
- } else {
- $_SESSION['package_array'] = $selectedArray;
- }
- $allPackages = $search_package_name !== '' ? $helper->getFilteredPackages($search_package_name, $groupid) : $helper->getAllPackagesFromSelectedEntity($groupid);
- $form = new Form($db);
- if (is_array($allPackages)) {
- print '<form method="POST" id="AssociationFormList" action="' . $url . '" onkeyup="submitFormAjaxTools()">' . "\n";
- $searchedString = '<table style="width:100%;">';
- $DeviceCounter = $helper->getNumberOfDevices();
- if (!empty($allPackages['freePackages'])) {
- foreach ($allPackages['freePackages'] as $freePackage) {
- $numberOfDevices3 = '';
- $devicesArray3 = [];
- if (isset($DeviceCounter[$freePackage['rowid']])) {
- $numberOfDevices3 = '(' . $DeviceCounter[$freePackage['rowid']] . ' ' . $langs->trans('device') . ')';
- $devicesArray3 = $helper->getDevicesById($db, $freePackage['rowid']);
- }
- $popupBox3Text = $helper->createPopoupBoxForDeviceList($numberOfDevices3, $devicesArray3);
- $popupBox3 = $popupBox3Text != '' ? $popupBox3Text : '<font style="color:red;">' . $langs->trans('emptyPackage') . '</font>';
- $selected = in_array($freePackage['rowid'], $selectedArray) ? 'checked' : '';
- $searchedString .= '<tr style="height:30px;">
- <td class="nowrap center"><input id="id_3_' . $freePackage['rowid'] . '" class="flat checkforselectadd" type="checkbox" onclick="submitFormAjaxAddPackage(event)" name="toselectnewpackage[]" value="' . $freePackage['rowid'] . '" ' . $selected . '></td>
- <td><span class="fa fa-toolbox pictofixedwidth"></span> ' . $freePackage['ref'] . '</td>
- <td>' . $popupBox3 . '</td>
- </tr>';
- }
- }
- $searchedString .= '</table><table style="width:100%; color: red;"><tr><td>';
- if (is_array($allPackages['addedPackages'])) {
- foreach ($allPackages['addedPackages'] as $addedPackage) {
- $numberOfDevices4 = '';
- $devicesArray4 = [];
- if (isset($DeviceCounter[$addedPackage['gprowid']])) {
- $numberOfDevices4 = '(' . $DeviceCounter[$addedPackage['gprowid']] . ' ' . $langs->trans('device') . ')';
- $devicesArray4 = $helper->getDevicesById($db, $addedPackage['rowid']);
- }
- $popupBox4Text = $helper->createPopoupBoxForDeviceList($numberOfDevices4, $devicesArray4);
- $popupBox4 = $popupBox4Text != '' ? $popupBox4Text : '<font style="color:red;">' . $langs->trans('emptyPackage') . '</font>';
- $searchedString .= '
- <table style="width:100%; border: 1px solid lightgrey; border-radius: 10px; margin-bottom: 20px;">
- <tr>
- <td colspan="2" style="text-align: center; width: 100%;"><a href="settlementtoolssettingsindex.php?idmenu=926&mainmenu=settlements&leftmenu=&id=' . $addedPackage['gprowid'] . '&nopackageuser=1">' . $addedPackage['gplabel'] . '</td>
- </tr>
- <tr style="height:30px;">
- <td><span class="fa fa-toolbox pictofixedwidth"></span><a href="/custom/settlements/settlementpackagetoolssettingsindex.php?idmenu=1592&mainmenu=settlements&leftmenu=&id=' . $addedPackage['rowid'] . '"> ' . $addedPackage['ref'] . '</a></td>
- <td>' . $popupBox4 . '</td>
- </tr>
- </table>'
- ;
- }
- }
- $searchedString .= '</td></tr></table>';
- }
- print $searchedString;
- ?>
- <script>
- function submitFormAjaxAddPackage(event) {
- console.log('submit');
- var checkbox = event.target;
- var groupid = document.getElementById("groupid");
- if (checkbox.checked) {
- var input = document.getElementById("package_search");
- var checkboxes = document.querySelectorAll('.checkforselectadd:checked');
- var values = Array.from(checkboxes).map(function (checkbox1) {
- return checkbox1.value;
- });
- var xhr = new XMLHttpRequest();
- xhr.open("GET", "ajaxPackage.php?search_package_name=" + input.value + "&toselectnewpackage=" + values + "&groupid=" + groupid.value, true);
- xhr.onreadystatechange = function () {
- if (xhr.readyState === 4 && xhr.status === 200) {
- $("#ajaxPackage").html(xhr.responseText);
- }
- };
- xhr.send();
- } else {
- var input = document.getElementById("package_search");
- var checkboxes = document.querySelectorAll('.checkforselectadd:checked');
- var values = Array.from(checkboxes).map(function (checkbox1) {
- return checkbox1.value;
- });
- var xhr = new XMLHttpRequest();
- xhr.open("GET", "ajaxPackage.php?search_package_name=" + input.value + "&reduction=" + values + "&groupid=" + groupid.value, true);
- xhr.onreadystatechange = function () {
- if (xhr.readyState === 4 && xhr.status === 200) {
- $("#ajaxPackage").html(xhr.responseText);
- }
- };
- xhr.send();
- }
- }
- $('.checkforselectadd').click(function () {
- if ($(this).is(':checked')) {
- $('#divAdd').css('display', 'inline-block');
- $('#massactionadd').css('display', 'inline-block');
- $('.massactionaddselect ').css('display', '');
- $('.massactionaddconfirmed ').css('display', '');
- } else {
- var checkboxes = document.querySelectorAll('.checkforselectadd:checked');
- var values = Array.from(checkboxes).map(function (checkbox) {
- return checkbox.value;
- });
- if (values.length === 0) {
- $('#divAdd').css('display', 'none');
- $('#massactionadd').css('display', 'none');
- $('.massactionaddselect ').css('display', 'none');
- $('.massactionaddconfirmed ').css('display', 'none');
- }
- }
- })
- </script>
|