ajaxPackageName.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <?php
  2. $res = 0;
  3. // Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
  4. if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
  5. $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"] . "/main.inc.php";
  6. }
  7. // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
  8. $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME'];
  9. $tmp2 = realpath(__FILE__);
  10. $i = strlen($tmp) - 1;
  11. $j = strlen($tmp2) - 1;
  12. while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
  13. $i--;
  14. $j--;
  15. }
  16. if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1)) . "/main.inc.php")) {
  17. $res = @include substr($tmp, 0, ($i + 1)) . "/main.inc.php";
  18. }
  19. if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1))) . "/main.inc.php")) {
  20. $res = @include dirname(substr($tmp, 0, ($i + 1))) . "/main.inc.php";
  21. }
  22. // Try main.inc.php using relative path
  23. if (!$res && file_exists("../main.inc.php")) {
  24. $res = @include "../main.inc.php";
  25. }
  26. if (!$res && file_exists("../../main.inc.php")) {
  27. $res = @include "../../main.inc.php";
  28. }
  29. if (!$res && file_exists("../../../main.inc.php")) {
  30. $res = @include "../../../main.inc.php";
  31. }
  32. if (!$res) {
  33. die("Include of main fails");
  34. }
  35. require_once DOL_DOCUMENT_ROOT . '/custom/settlements/class/helper.class.php';
  36. $helper = new Helper($db);
  37. $search_group_title = GETPOST('search_group_title', 'alpha');
  38. $selectedEntities = GETPOST('selectedEntities', 'alpha');
  39. $groups = $search_group_title !== '' ? $helper->getFilteredpackageGroups($search_group_title, $selectedEntities) : $helper->getGroupsFromGroupToolsClass($db, $selectedEntities);
  40. $form = new Form($db);
  41. if (!empty($groups)) {
  42. print '<form method="POST" id="AssociationFormList" action="' . $url . '" onkeyup="submitFormAjaxTools()">' . "\n";
  43. $searchedGroupString = '<table style="width:100%;">';
  44. $userCounter = $helper->getNumberOfUsers();
  45. foreach ($groups as $group) {
  46. $confirmedGroup = $helper->checkConfirmation($group['rowid']);
  47. $numberOfUsers = '';
  48. $usersArray = [];
  49. if (isset($userCounter[$group['rowid']][0])) {
  50. $peopleOrPerson = intval($userCounter[$group['rowid']][0]) > 1 ? $langs->trans('people') : $langs->trans('person');
  51. $numberOfUsers = '(' . $userCounter[$group['rowid']][0] . ' ' . $langs->trans('person') . ')';
  52. $usersArray = $helper->getUsersById($db, $userCounter[$group['rowid']][1]);
  53. }
  54. $popoupBox = $helper->createPopoupBox($numberOfUsers, $usersArray, $group['rowid']);
  55. $coloredLine = $id == $group['rowid'] ? ' background-color: #b0c4de' : '';
  56. $checker = $confirmedGroup ? '<span class="fa fa-check" style="color: green;"></span>' : '<span class="fa fa-exclamation" style="color: red;"></span>';
  57. //$searchedGroupString .= '<tr style="height:30px; cursor:pointer;' . $coloredLine . '" class="submitFormLink" data-value="' . $group['rowid'] . '"><td><span class="fa fa-group pictofixedwidth"></span> ' . $group['ref'] . $popoupBox . '</td><td>' . $checker . '</td></tr>';
  58. $searchedGroupString .= '<tr style="height:30px; cursor:pointer;' . $coloredLine . '"><td><div class="submitFormLink" data-value="' . $group['rowid'] . '"><span class="fa fa-group pictofixedwidth"></span> ' . $group['ref'] . '</div><div class="groupColumn2ndLine submitFormLink" data-value="' . $group['rowid'] . '" style="float:left;">' . $group['label'] . '</div>' . $popupBox . '</td></tr>';
  59. $searchedGroupString .= '<tr id="users_' . $group['rowid'] . '" style="display:none; width:100%; background-color:lightgrey;"><td>';
  60. foreach ($usersArray as $users) {
  61. $searchedGroupString .= '&nbsp;<a href="/user/card.php?id=' . $users['fk_user'] . '&save_lastsearch_values=1"><span class="fas fa-user" style="color: #a69944; cursor: pointer;"></span>&nbsp;' . $users['lastname'] . ' ' . $users['firstname'] . ' (' . $users['login'] . ')</a><br>';
  62. }
  63. $searchedGroupString .= '</td></tr>';
  64. }
  65. } else {
  66. $searchedGroupString .= '<tr style="height: 60px; text-align: center; color:red;"><td>' . $langs->trans('nogroup') . '</td></tr>';
  67. }
  68. print $searchedGroupString;
  69. ?>
  70. <style>
  71. .groupColumn2ndLine {
  72. color: grey !important;
  73. }
  74. .createPackageHistoryRecord {
  75. display: block;
  76. height: 25px;
  77. width: 40px;
  78. background-color: green;
  79. border-radius: 5px;
  80. text-decoration: none;
  81. color: white !important;
  82. text-align: center;
  83. padding-top: 10px;
  84. }
  85. .confirmUsersButton {
  86. display: block;
  87. height: 40px;
  88. width: 100%;
  89. border-radius: 5px;
  90. text-decoration: none;
  91. text-align: center;
  92. background-color: #98FB98;
  93. }
  94. .createPackageHistoryRecord:hover {
  95. text-decoration: none;
  96. }
  97. .cursorNotAllowed {
  98. cursor: not-allowed;
  99. }
  100. .clearAllButton {
  101. height: 20px;
  102. width: 70px;
  103. background-color: red;
  104. border: 1px red solid;
  105. border-radius: 5px;
  106. text-align: center;
  107. color: white !important;
  108. text-decoration: none;
  109. }
  110. .clearAllButton:hover {
  111. text-decoration: none;
  112. }
  113. </style>
  114. <script>
  115. $(document).ready(function () {
  116. var elements = document.getElementsByClassName('submitFormLink');
  117. var inputGroup = document.getElementById("group_search");
  118. for (var i = 0; i < elements.length; i++) {
  119. elements[i].addEventListener('click', function (event) {
  120. event.preventDefault();
  121. var form = document.getElementById('AssociationFormList');
  122. var actionValue = form.getAttribute('action');
  123. var clickedElementValue = this.getAttribute('data-value');
  124. lastIndex = actionValue.lastIndexOf('&');
  125. var trimmedQueryString = actionValue.substring(0, lastIndex);
  126. form.action = trimmedQueryString + '&id=' + clickedElementValue + '&search_group_title=' + inputGroup.value;
  127. document.getElementById('AssociationFormList').submit();
  128. });
  129. }
  130. });
  131. function submitFormAjaxPackages() {
  132. var input = document.getElementById("package_search");
  133. var inputGroup = document.getElementById("group_search");
  134. var checkboxes = document.querySelectorAll('.checkforselectadd:checked');
  135. var values = Array.from(checkboxes).map(function (checkbox) {
  136. return checkbox.value;
  137. });
  138. //if (input.value != '') {
  139. var xhr = new XMLHttpRequest();
  140. xhr.open("GET", "ajaxPackage.php?search_package_name=" + input.value + "&toselectnewpackage=" + values + "&groupid=" + groupid.value, true);
  141. xhr.onreadystatechange = function () {
  142. if (xhr.readyState === 4 && xhr.status === 200) {
  143. $("#searchedPackageDiv").html(xhr.responseText);
  144. }
  145. };
  146. xhr.send();
  147. //}
  148. //if (inputGroup.value != '') {
  149. var xhrGroup = new XMLHttpRequest();
  150. var selectedCheckboxes = $('input[type="checkbox"][id*="entity_"]:checked');
  151. var checkboxValues = selectedCheckboxes.toArray().map(function (checkbox) {
  152. return $(checkbox).val();
  153. });
  154. xhrGroup.open("GET", "ajaxPackageName.php?search_group_title=" + inputGroup.value + '&selectedEntities=' + checkboxValues, true);
  155. xhrGroup.onreadystatechange = function () {
  156. if (xhrGroup.readyState === 4 && xhrGroup.status === 200) {
  157. $("#searchedPackagesDiv").html(xhrGroup.responseText);
  158. }
  159. };
  160. xhrGroup.send();
  161. //}
  162. }
  163. </script>