settlementssingleuserindex.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <?php
  2. /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file settlements/settlementsindex.php
  22. * \ingroup settlements
  23. * \brief Home page of settlements top menu
  24. */
  25. // Load Dolibarr environment
  26. $res = 0;
  27. // Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
  28. if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
  29. $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"] . "/main.inc.php";
  30. }
  31. // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
  32. $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME'];
  33. $tmp2 = realpath(__FILE__);
  34. $i = strlen($tmp) - 1;
  35. $j = strlen($tmp2) - 1;
  36. while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
  37. $i--;
  38. $j--;
  39. }
  40. if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1)) . "/main.inc.php")) {
  41. $res = @include substr($tmp, 0, ($i + 1)) . "/main.inc.php";
  42. }
  43. if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1))) . "/main.inc.php")) {
  44. $res = @include dirname(substr($tmp, 0, ($i + 1))) . "/main.inc.php";
  45. }
  46. // Try main.inc.php using relative path
  47. if (!$res && file_exists("../main.inc.php")) {
  48. $res = @include "../main.inc.php";
  49. }
  50. if (!$res && file_exists("../../main.inc.php")) {
  51. $res = @include "../../main.inc.php";
  52. }
  53. if (!$res && file_exists("../../../main.inc.php")) {
  54. $res = @include "../../../main.inc.php";
  55. }
  56. if (!$res) {
  57. die("Include of main fails");
  58. }
  59. use Luracast\Restler\RestException;
  60. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
  61. require_once DOL_DOCUMENT_ROOT . '/user/class/usergroup.class.php';
  62. require_once DOL_DOCUMENT_ROOT . '/custom/settlements/class/groupusers.class.php';
  63. require_once DOL_DOCUMENT_ROOT . '/custom/settlements/class/usernaplo.class.php';
  64. require_once DOL_DOCUMENT_ROOT . '/custom/settlements/class/helper.class.php';
  65. require_once DOL_DOCUMENT_ROOT . '/custom/financialreport/class/helper.class.php';
  66. $helper = new Helper($db);
  67. $userInvoiceHelper = new HelperUserInvoice($db);
  68. // Load translation files required by the page
  69. $langs->loadLangs(array("settlements@settlements"));
  70. $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
  71. $massactionadd = GETPOST('massactionadd', 'alpha'); // The bulk action (combo box choice into lists)
  72. $action = GETPOST('action', 'aZ09');
  73. $id = GETPOST('id', 'int');
  74. $idmenu = GETPOST('idmenu', 'int');
  75. $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
  76. $toselectnewuser = GETPOST('toselectnewuser', 'array'); // Array of ids of elements selected into a list
  77. $search_title = GETPOST('search_title', 'alpha');
  78. $confirmbutton = GETPOST('confirmbutton', 'int');
  79. // Security check
  80. // if (! $user->rights->settlements->myobject->read) {
  81. // accessforbidden();
  82. // }
  83. $socid = GETPOST('socid', 'int');
  84. if (isset($user->socid) && $user->socid > 0) {
  85. $action = '';
  86. $socid = $user->socid;
  87. }
  88. $max = 5;
  89. $now = dol_now();
  90. $form = new Form($db);
  91. $formfile = new FormFile($db);
  92. $userNaplo = new UserNaplo($db);
  93. $groups = $helper->getSingleUserGroupsFromGroupClass($db);
  94. if (empty($id)) {
  95. $keys = array_keys($groups);
  96. $id = $keys[0];
  97. }
  98. if ($confirmbutton) {
  99. foreach ($toselect as $selected) {
  100. $moredata = explode('_', $selected);
  101. $data = $helper->createDataArray($id, 'add', $moredata[1]);
  102. $userNaplo->createUserNaplo($user, $data);
  103. }
  104. setEventMessage($langs->trans("usersconfirmed"));
  105. }
  106. $usersOfGroups = $helper->getUsersById($db, $id);
  107. $allUsers = $helper->getAllUsers($db);
  108. $confirmButtonDisplay = empty($helper->getUsersOfGroupsFromNaploToday($db, $id)) && !empty($usersOfGroups) ? "display:block;" : "display:none;";
  109. $entities = $helper->getAllEntities();
  110. llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'classforhorizontalscrolloftabs');
  111. //print_r($_REQUEST);
  112. $url = $_SERVER["PHP_SELF"] . '?idmenu=' . $idmenu . '&mainmenu=settlements&leftmenu=';
  113. if (isset($massaction) || isset($massactionadd)) {
  114. $url .= "&id={$id}";
  115. }
  116. print '<form method="POST" id="searchFormList" action="' . $url . '" onkeyup="submitForm()">' . "\n";
  117. print '<input type="hidden" name="token" value="' . newToken() . '">';
  118. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  119. print '<input type="hidden" name="action" value="list">';
  120. /*print '<input type="hidden" name="sortfield" value="' . $sortfield . '">';
  121. print '<input type="hidden" name="sortorder" value="' . $sortorder . '">';
  122. print '<input type="hidden" name="page" value="' . $page . '">';
  123. print '<input type="hidden" name="contextpage" value="' . $contextpage . '">';*/
  124. print load_fiche_titre($langs->trans("SettlementsSingleUser"), '', 'settlements.png@settlements');
  125. //include DOL_DOCUMENT_ROOT . '/custom/settlements/core/tpl/usercheckboxes.tpl.php';
  126. //---------------------------------------------
  127. # 1
  128. //---------------------------------------------
  129. print '<div class=""><div class="" style="width:60%;float:left;">';
  130. print '<table style="width:100%;">';
  131. print '<tr style="width: 100%; height: 40px; text-align: center; background-color: lightgrey;"><td>' . $langs->trans("groupname") . '</td></tr>';
  132. foreach ($groups as $key => $val) {
  133. $coloredLine = $id == $key ? ' background-color: #b0c4de' : '';
  134. print '<tr style="height:30px;' . $coloredLine . '">
  135. <td>
  136. <div>
  137. <a href="' . $_SERVER['PHP_SELF'] . '?id=' . $key . '"><span class="fa fa-group pictofixedwidth"></span> ' . $val . '</a>
  138. </div>
  139. <div class="groupColumn2ndLine" style="float:left;">
  140. ' . $entities[$userInvoiceHelper->getGroupEntityId($key)] . '
  141. </div>
  142. </td>
  143. </tr>';
  144. }
  145. print '</table>';
  146. print '</div>';
  147. //---------------------------------------------
  148. # 2
  149. //---------------------------------------------
  150. print '<div class="" style="width:40%;float:left;">';
  151. print '<table style="width:100%;">';
  152. print '<tr style="width: 100%; height: 40px; text-align: center; background-color: lightgrey;"><td colspan="2">' . $langs->trans("usersofgroup", $groups[$id]) . '</td></tr>';
  153. print '<tr style="width=100%; height:40px;"><td colspan="2" class="center"><button class="btn" name="confirmbutton" value="1" onclick="groupconfirm()"
  154. style="width:100%; height:40px; cursor:pointer; background-color: #98FB98; ' . $confirmButtonDisplay . '">' . $langs->trans("confirm") . '</button></td></tr>';
  155. if (!empty($usersOfGroups)) {
  156. foreach ($usersOfGroups as $user) {
  157. print '<tr style="height:30px;">
  158. <td><span class="fa fa-user pictofixedwidth"></span> ' . $user['lastname'] . ' ' . $user['firstname'] . ' (' . $user['login'] . ')</td>
  159. <td class="nowrap center" style="display: none;"><input id="cb911" class="flat checkforselect" type="checkbox" name="toselect[]" value="' . $user['rowid'] . '_' . $user['fk_user'] . '"></td>
  160. </tr>';
  161. }
  162. } else {
  163. print '<tr style="height: 60px; text-align: center; color:red;"><td>' . $langs->trans('nouser') . '</td></tr>';
  164. }
  165. print '</table>';
  166. print '</div>';
  167. print '</form>' . "\n";
  168. // End of page
  169. llxFooter();
  170. $db->close();
  171. ?>
  172. <style>
  173. .groupColumn2ndLine {
  174. color: grey !important;
  175. }
  176. </style>
  177. <script>
  178. function groupconfirm() {
  179. $('.checkforselect').prop('checked', true);
  180. console.log('Confirm');
  181. }
  182. $('.checkforallselect').click(function () {
  183. if ($(this).is(':checked')) {
  184. // A checkbox be van pipálva
  185. $('.checkforselect').prop('checked', true);
  186. $('#massaction').css('display', 'inline-block');
  187. $('.massactionselect ').css('display', '');
  188. $('.massactionconfirmed ').css('display', '');
  189. } else {
  190. // A checkbox nincs bepipálva
  191. $('.checkforselect').prop('checked', false);
  192. $('#massaction').css('display', 'none');
  193. $('.massactionselect ').css('display', 'none');
  194. $('.massactionconfirmed ').css('display', 'none');
  195. }
  196. })
  197. $('.checkforselectadd').click(function () {
  198. console.log('click');
  199. if ($(this).is(':checked')) {
  200. // A checkbox be van pipálva
  201. $('#massactionadd').css('display', 'inline-block');
  202. $('.massactionaddselect ').css('display', '');
  203. $('.massactionaddconfirmed ').css('display', '');
  204. } else {
  205. // A checkbox nincs bepipálva
  206. $('#massactionadd').css('display', 'none');
  207. $('.massactionaddselect ').css('display', 'none');
  208. $('.massactionaddconfirmed ').css('display', 'none');
  209. }
  210. })
  211. function deleteFunction() {
  212. $("#name_search").val('');
  213. document.getElementById("searchFormList").submit();
  214. }
  215. function submitForm() {
  216. //document.getElementById("searchFormList").submit();
  217. var input = document.getElementById("name_search");
  218. var checkboxes = document.querySelectorAll('.checkforselectadd:checked');
  219. var values = Array.from(checkboxes).map(function (checkbox) {
  220. return checkbox.value;
  221. });
  222. var xhr = new XMLHttpRequest();
  223. xhr.open("GET", "test.php?search_title=" + input.value + "&toselectnewuser=" + values, true);
  224. xhr.onreadystatechange = function () {
  225. if (xhr.readyState === 4 && xhr.status === 200) {
  226. $("#searchedUsersDiv").html(xhr.responseText);
  227. }
  228. };
  229. xhr.send();
  230. }
  231. function submitForm2(event) {
  232. var checkbox = event.target;
  233. if (checkbox.checked) {
  234. console.log('A checkbox be van jelölve.');
  235. var input = document.getElementById("name_search");
  236. var checkboxes = document.querySelectorAll('.checkforselectadd:checked');
  237. var values = Array.from(checkboxes).map(function (checkbox1) {
  238. return checkbox1.value;
  239. });
  240. var xhr = new XMLHttpRequest();
  241. xhr.open("GET", "test.php?search_title=" + input.value + "&toselectnewuser=" + values, true);
  242. xhr.onreadystatechange = function () {
  243. if (xhr.readyState === 4 && xhr.status === 200) {
  244. $("#searchedUsersDiv").html(xhr.responseText);
  245. }
  246. };
  247. xhr.send();
  248. } else {
  249. console.log('A checkbox nincs jelölve.');
  250. var input = document.getElementById("name_search");
  251. var checkboxes = document.querySelectorAll('.checkforselectadd:checked');
  252. var values = Array.from(checkboxes).map(function (checkbox1) {
  253. return checkbox1.value;
  254. });
  255. console.log(values);
  256. //if (values.length !== 0) {
  257. var xhr = new XMLHttpRequest();
  258. xhr.open("GET", "test.php?search_title=" + input.value + "&reduction=" + values, true);
  259. xhr.onreadystatechange = function () {
  260. if (xhr.readyState === 4 && xhr.status === 200) {
  261. $("#searchedUsersDiv").html(xhr.responseText);
  262. }
  263. };
  264. xhr.send();
  265. //}
  266. }
  267. }
  268. var input = document.getElementById("name_search");
  269. input.focus();
  270. input.setSelectionRange(input.value.length, input.value.length);
  271. </script>