settlementsindex.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  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. //print_r($_REQUEST);exit;
  26. // Load Dolibarr environment
  27. $res = 0;
  28. // Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
  29. if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
  30. $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"] . "/main.inc.php";
  31. }
  32. // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
  33. $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME'];
  34. $tmp2 = realpath(__FILE__);
  35. $i = strlen($tmp) - 1;
  36. $j = strlen($tmp2) - 1;
  37. while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
  38. $i--;
  39. $j--;
  40. }
  41. if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1)) . "/main.inc.php")) {
  42. $res = @include substr($tmp, 0, ($i + 1)) . "/main.inc.php";
  43. }
  44. if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1))) . "/main.inc.php")) {
  45. $res = @include dirname(substr($tmp, 0, ($i + 1))) . "/main.inc.php";
  46. }
  47. // Try main.inc.php using relative path
  48. if (!$res && file_exists("../main.inc.php")) {
  49. $res = @include "../main.inc.php";
  50. }
  51. if (!$res && file_exists("../../main.inc.php")) {
  52. $res = @include "../../main.inc.php";
  53. }
  54. if (!$res && file_exists("../../../main.inc.php")) {
  55. $res = @include "../../../main.inc.php";
  56. }
  57. if (!$res) {
  58. die("Include of main fails");
  59. }
  60. use Luracast\Restler\RestException;
  61. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
  62. require_once DOL_DOCUMENT_ROOT . '/user/class/usergroup.class.php';
  63. require_once DOL_DOCUMENT_ROOT . '/custom/settlements/class/groupusers.class.php';
  64. require_once DOL_DOCUMENT_ROOT . '/custom/settlements/class/usernaplo.class.php';
  65. require_once DOL_DOCUMENT_ROOT . '/custom/settlements/class/clearallusernaplo.class.php';
  66. require_once DOL_DOCUMENT_ROOT . '/custom/settlements/class/helper.class.php';
  67. require_once DOL_DOCUMENT_ROOT . '/custom/settlements/class/group.class.php';
  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. $cancel = GETPOST('cancel', 'int');
  74. $id = GETPOST('id', 'int');
  75. $idmenu = GETPOST('idmenu', 'int');
  76. $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
  77. $toselectString = GETPOST('toselectString', 'alpha'); // Array of ids of elements selected into a list
  78. $toselectnewuser = GETPOST('toselectnewuser', 'array'); // Array of ids of elements selected into a list
  79. $search_title = GETPOST('search_title', 'alpha');
  80. $search_group_title = GETPOST('search_group_title', 'alpha');
  81. $confirmmassaction = GETPOST('confirmmassaction', 'alpha');
  82. $confirmbutton = GETPOST('confirmbutton', 'int');
  83. $userclearall = GETPOST('userclearall', 'int');
  84. $deleteall = GETPOST('deleteall', 'int');
  85. $confirm = GETPOST('confirm', 'alpha');
  86. // Security check
  87. // if (! $user->rights->settlements->myobject->read) {
  88. // accessforbidden();
  89. // }
  90. if ($deleteall) {
  91. unset($_SESSION['usersArray']);
  92. }
  93. $socid = GETPOST('socid', 'int');
  94. if (isset($user->socid) && $user->socid > 0) {
  95. $action = '';
  96. $socid = $user->socid;
  97. }
  98. $max = 5;
  99. $now = dol_now();
  100. $form = new Form($db);
  101. $formfile = new FormFile($db);
  102. $userNaplo = new UserNaplo($db);
  103. $clearAllUserNaplo = new ClearAllUserNaplo($db);
  104. $groupUsers = new GroupUsers($db);
  105. $helper = new Helper($db);
  106. $entities = $helper->getAllEntities();
  107. $entitiesArray = [];
  108. $selectedEntities = '';
  109. foreach ($entities as $key => $value) {
  110. $val = GETPOST('entity_' . $key, 'int');
  111. $entitiesArray[$key] = $val;
  112. /* if ($val != '') {
  113. $entitiesArrayIsEmpty = false;
  114. } */
  115. }
  116. if(empty(array_filter($entitiesArray))){
  117. $entitiesArray[1] = 1;
  118. }
  119. $selectedEntities = $helper->getEntities($entitiesArrayIsEmpty, $entities, $entitiesArray);
  120. $groups = $helper->getFilteredGroups($search_group_title, $selectedEntities);
  121. $groupToolsAndGroupUsersArray = $helper->getGTAndGUArray();
  122. if (empty($id) || $id == 0) {
  123. foreach ($groups as $group) {
  124. $keys[] = $group['rowid'];
  125. }
  126. unset($_SESSION['usersArray']);
  127. $id = $keys[0];
  128. }
  129. $allUsers = $helper->getAllUsers($db);
  130. $usersOfGroups = $helper->getUsersById($db, $id);
  131. $isConfirmedTheGroup = empty($helper->getUsersOfGroupsFromNaploToday($db, $id)) && !empty($usersOfGroups);
  132. $confirmButtonDisplay = $isConfirmedTheGroup ? "display:block;" : "display:none;";
  133. $permissiontoclearall = $user->hasRight('settlements', 'settlementsgroup', 'clearall');
  134. llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'classforhorizontalscrolloftabs');
  135. include DOL_DOCUMENT_ROOT . '/custom/settlements/core/actions_addupdatedelete.inc.php';
  136. if ($massaction == 'delete' && $confirmmassaction != '') {
  137. $toselectString = implode(',', $toselect);
  138. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '
  139. ?toselectString=' . $toselectString . '&id=' . $id . '&massaction=' . $massaction,
  140. $langs->trans('UserDeleteConfirm'),
  141. $langs->trans('UserDeleteConfirmObject', $userString),
  142. 'confirm_users_delete', '', 0, 1);
  143. }
  144. if ($massactionadd == 'add' && $confirmmassaction != '') {
  145. $usersOfGroups = $helper->getUsersById($db, $id);
  146. $usersOfGroupsFromNaploToday = $helper->getUsersOfGroupsFromNaploToday($db, $id);
  147. $confirmed = !empty($usersOfGroupsFromNaploToday) && !empty($usersOfGroups);
  148. $db->begin();
  149. $error = 0;
  150. $userObj = new User($db);
  151. $groupObj = new Group($db);
  152. $groupResult = $groupObj->fetch($id);
  153. $groupEntity = $groupObj->fk_entity;
  154. foreach ($_SESSION['usersArray'] as $newuser) {
  155. //print $newuser . '<br>';
  156. $createResult = $groupUsers->createGroupUsers($id, $newuser);
  157. if ($createResult < 0) {
  158. //print '1';
  159. $error++;
  160. }
  161. $data = $helper->createDataArray($id, $massactionadd, $newuser);
  162. $naploResult = $userNaplo->createUserNaplo($user, $data);
  163. if ($naploResult < 0) {
  164. //print '2';
  165. $error++;
  166. }
  167. $userUpdateResult = $helper->updateUserEntityInUser($newuser, $groupEntity);
  168. if ($userUpdateResult < 0) {
  169. //print '3';
  170. $error++;
  171. }
  172. }
  173. //print 'asdasd';exit;
  174. if ($error) {
  175. $db->rollback();
  176. unset($_SESSION['usersArray']);
  177. setEventMessage($langs->trans("PackageUserFailed", 'error'));
  178. } else {
  179. $db->commit();
  180. unset($_SESSION['usersArray']);
  181. $helper->returnWindowLocation($_SERVER["PHP_SELF"], $id, $idmenu);
  182. //setEventMessage($langs->trans("useradded"));
  183. }
  184. unset($_SESSION['usersArray']);
  185. }
  186. if ($confirmbutton) {
  187. $db->begin();
  188. $error = 0;
  189. $groupusers = new GroupUsers($db);
  190. $groupObj = new Group($db);
  191. $groupResult = $groupObj->fetch($id);
  192. $groupEntity = $groupObj->fk_entity;
  193. foreach ($toselect as $selected) {
  194. $moredata = explode('_', $selected);
  195. $array = [];
  196. $deleteResult = $groupusers->deleteLine($user, $moredata[0]);
  197. if ($deleteResult < 0) {
  198. $error++;
  199. $array['deleteLine'] = 1;
  200. }
  201. $createResult = $groupUsers->createGroupUsers($confirmbutton, $moredata[1]);
  202. if ($createResult < 0) {
  203. $error++;
  204. $array['createGroupUsers'] = 1;
  205. }
  206. $dataAdd = $helper->createDataArray($confirmbutton, 'add', $moredata[1]);
  207. $naploResult = $userNaplo->createUserNaplo($user, $dataAdd);
  208. if ($naploResult < 0) {
  209. $error++;
  210. $array['createUserNaplo'] = 1;
  211. }
  212. $userUpdateResult = $helper->updateUserEntityInUser($moredata[1], $groupEntity);
  213. if ($userUpdateResult < 0) {
  214. $error++;
  215. $array['updateUserEntityInUser'] = 1;
  216. }
  217. }
  218. if ($error) {
  219. $db->rollback();
  220. unset($toselect);
  221. setEventMessage($langs->trans("PackageUserFailed", 'error'));
  222. //setEventMessage(print_r($array), 'error');
  223. } else {
  224. $confirmbutton = null;
  225. $db->commit();
  226. $helper->returnWindowLocation($_SERVER["PHP_SELF"], $id, $idmenu);
  227. //setEventMessage($langs->trans("usersconfirmed"));
  228. }
  229. }
  230. if ($massaction == 'delete' && $confirmmassaction != '') {
  231. print $formconfirm;
  232. }
  233. $url = $_SERVER["PHP_SELF"] . '?idmenu=' . $idmenu . '&mainmenu=settlements&leftmenu=&id=' . $id;
  234. /* if ($massaction!=0 || $massactionadd != 0) {
  235. $url .= "&id={$id}";
  236. } */
  237. print '<form method="POST" id="searchFormList" action="' . $url . '" onkeyup="submitFormAjaxUser()">' . "\n";
  238. print '<input type="hidden" name="token" value="' . newToken() . '">';
  239. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  240. print '<input type="hidden" name="action" value="list">';
  241. if ($permissiontoclearall) {
  242. if ($helper->userGroupsAreEmpty()) {
  243. print '<div style="text-align: center; color:red; margin-bottom: 30px;">' . $langs->trans('EmptyUsersGroup') . '</div>';
  244. } else {
  245. include DOL_DOCUMENT_ROOT . '/custom/settlements/core/tpl/userclearall.tpl.php';
  246. }
  247. }
  248. print load_fiche_titre($langs->trans("UserGroups"), '', 'settlements.png@settlements');
  249. include DOL_DOCUMENT_ROOT . '/custom/settlements/core/tpl/usercheckboxes.tpl.php';
  250. //print_r($entitiesArrayIsEmpty);exit;
  251. print '<div style="width:100%; padding-bottom: 50px;">';
  252. $columnWidth = 100 / count($entities);
  253. foreach ($entities as $key => $value) {
  254. if (!$entitiesArrayIsEmpty) {
  255. $checked = $entitiesArray[$key] == $key ? 'checked' : '';
  256. } else {
  257. $checked = 'checked';
  258. }
  259. print '<div class="entitiesChk" style="float:left; width:' . $columnWidth . '%; text-align:center;"><input type="checkbox" class="entitycheckbox" id="entity_' . $key . '" name="entity_' . $key . '" value="' . $key . '" ' . $checked . '><label for="' . $key . '">' . $value . '</label></div>';
  260. }
  261. print '</div>';
  262. print '<div style="clear:both;></div>';
  263. //---------------------------------------------
  264. # 1
  265. //---------------------------------------------
  266. print '<div class=""><div class="" style="width:33%;float:left;">';
  267. print '<table style="width:100%;">';
  268. print '<tr style="width: 100%; height: 40px; text-align: center; background-color: lightgrey;"><td colspan="2">' . $langs->trans("groupname") . '</td></tr>';
  269. //print '<tr><td class="liste_titre"><input id="group_search" style="width:100%; height:30px;" type="text" class="" name="search_group_title" value="' . $search_group_title . '" placeholder="Search..." ' . $disabledGroupSearchField . '></td>
  270. print '<tr><td class="liste_titre"><input id="group_search" style="width:100%; height:30px;" type="text" class="" name="search_group_title" value="' . $search_group_title . '" placeholder="Search..."></td>
  271. <td id="delete_group_search" class="right"><div style="cursor: pointer;"><a href="' . $_SERVER["PHP_SELF"] . '?idmenu=' . $idmenu . '&mainmenu=settlements&leftmenu=&id=' . $id . '&deleteall=1"><span class="fa fa-trash"></span></a></div>
  272. </td></tr>';
  273. print '<tr><td colspan="3"><div id="searchedGroupsDiv">';
  274. print $helper->groupList($groups, $id);
  275. print '</div></td></tr></table>';
  276. //---------------------------------------------
  277. # 2
  278. //---------------------------------------------
  279. print '</div><div class="" style="width:33%;float:left;">';
  280. print '<table style="width:100%;">';
  281. print '<tr style="width: 100%; height: 40px; text-align: center; background-color: lightgrey;"><td colspan="2"><a href="/custom/settlements/settlementtoolssettingsindex.php?idmenu=1594&mainmenu=settlements&leftmenu=&id=' . $groupToolsAndGroupUsersArray[$id] . '&nopackageuser=1">' . $langs->trans("usersingroup", $helper->getGroupRefByID($id)) . '</a></td></tr>';
  282. /* print '<tr style="width=100%; height:40px;"><td colspan="2" class="center"><button class="btn" name="confirmbutton" value="' . $id . '" onclick="groupconfirm()"
  283. style="width:100%; height:40px; cursor:pointer; background-color: #98FB98; ' . $confirmButtonDisplay . '">' . $langs->trans("confirm") . '</button></td></tr>'; */
  284. if (!empty($usersOfGroups)) {
  285. print '<tr><td class="right" style="color:gray;">' . $langs->trans("selectall") . '</td><td class="nowrap center"><input id="cb912" class="flat checkforallselect" type="checkbox"></td></tr>';
  286. if(!empty($toselect)){
  287. $$toselectUsers = [];
  288. foreach($toselect as $toselectUser){
  289. list($toselectKey, $toselectValue) = explode('_', $toselectUser);
  290. $toselectUsers[] = $toselectValue;
  291. }
  292. }
  293. foreach ($usersOfGroups as $user) {
  294. if(!empty($toselect)){
  295. $checkedUser = in_array($user['fk_user'], $toselectUsers) ? 'checked' : '';
  296. }
  297. $rowidAndStatus = $helper->checkStatusToUsergroups($user, $id);
  298. if ($rowidAndStatus['status'] == 1 || empty($rowidAndStatus)) {
  299. //if ($rowidAndStatus) {
  300. $CashCLosed = '';
  301. $chkCol2Disabled = '';
  302. } else {
  303. $CashCLosed = ' <p style="margin-top:0px; margin-left: 25px;"><font color="red">' . $langs->trans('dailyClosingisOpen') . '</font>&nbsp;
  304. <a href="/custom/rollerstorage/packagehistory_card.php?id=' . $rowidAndStatus['rowid'] . '&idmenu=1594&fk_group_id=' . $rowidAndStatus['fk_group_id'] . '&changeback=1"><span style="cursor:pointer;" class="fa fa-link pictofixedwidth"></span></a></p> ';
  305. $chkCol2Disabled = 'disabled';
  306. }
  307. print '<tr style="height:30px;">
  308. <td><div><span class="fa fa-user pictofixedwidth"></span> ' . $user['lastname'] . ' ' . $user['firstname'] . ' (' . $user['login'] . ') ' . $CashCLosed . '</div></td>
  309. <td class="nowrap center"><input id="cb911" class="flat checkforselect" type="checkbox" name="toselect[]" value="' . $user['rowid'] . '_' . $user['fk_user'] . '" ' . $chkCol2Disabled . ' '. $checkedUser .'></td>
  310. </tr>';
  311. }
  312. } else {
  313. print '<tr style="height: 60px; text-align: center; color:red;"><td>' . $langs->trans('nouser') . '</td></tr>';
  314. }
  315. print '</table>';
  316. //---------------------------------------------
  317. # 3
  318. //---------------------------------------------
  319. print '</div><div class="" style="width:33%;float:left;">';
  320. print '<table style="width:100%;">';
  321. print '<tr style="width: 100%; height: 40px; text-align: center; background-color: lightgrey;"><td colspan="3">' . $langs->trans("freeusers") . '</td></tr>';
  322. print '<tr><td class="liste_titre"><input id="name_search" style="width:100%; height:30px;" type="text" class="" name="search_title" value="' . $search_title . '" placeholder="' . $placeholder . '" ' . $disabledSearchField . '></td>
  323. <td id="delete_search" class="center"><div style="cursor: pointer;"><a href="' . $_SERVER["PHP_SELF"] . '?idmenu=' . $idmenu . '&mainmenu=settlements&leftmenu=&id=' . $id . '&deleteall=1"><span class="fa fa-trash"></span></a></div>
  324. </td></tr>';
  325. print '<td colspan="3"><div id="searchedUsersDiv">
  326. <table style="width:100%;">';
  327. if (is_array($allUsers['freeUsers']) && !$isConfirmedTheGroup) {
  328. foreach ($allUsers['freeUsers'] as $freeUser) {
  329. $nickname = isset($freeUser['nickname']) ? '<b>' . $freeUser['nickname'] . '</b> - ' : '';
  330. $linkToDailyclosing = $freeUser['openDailyClosing'] > 0 ? '<div style="color: red;">' . $langs->trans('HasAnOpenDailyClosing') . '<a href="/custom/rollerstorage/packagehistory_card.php?id=' . $freeUser['openDailyClosing'] . '&idmenu=1594&fk_group_id=' . $id . '&changeback=1">Link</a></div>' : '';
  331. $dCDisabled = $freeUser['openDailyClosing'] > 0 ? 'disabled' : '';
  332. print '<tr style="height:30px;">
  333. <td class="nowrap center"><input id="cb912" class="flat checkforselectadd" type="checkbox" onclick="submitFormAddUser(event)" name="toselectnewuser[]" value="' . $freeUser['rowid'] . '" '. $dCDisabled .'></td>
  334. <td><span class="fa fa-user pictofixedwidth"></span>' . $nickname . $freeUser['lastname'] . ' ' . $freeUser['firstname'] . ' (' . $freeUser['login'] . ') ' . $linkToDailyclosing . '</td>
  335. </tr>';
  336. }
  337. } else {
  338. print '<tr style="height: 60px; text-align: center; color:red;"><td>' . $langs->trans('NoUser') . '</td></tr>';
  339. }
  340. print '</table><table style="width:100%; color: red;">';
  341. if (is_array($allUsers['addedUsers'])) {
  342. foreach ($allUsers['addedUsers'] as $addedUser) {
  343. $nickname = isset($addedUser['nickname']) ? '<b>' . $addedUser['nickname'] . '</b> - ' : '';
  344. print '<tr style="height:30px;">
  345. <td rowspan="2"><span class="fa fa-user pictofixedwidth"></span></td>
  346. <td>' . $nickname . $addedUser['lastname'] . ' ' . $addedUser['firstname'] . ' (' . $addedUser['login'] . ')</td></tr>';
  347. print '<tr>
  348. <td class="nowrap"><span class="fa fa-link pictofixedwidth"></span><a href="/custom/settlements/settlementsindex.php?idmenu=1587&mainmenu=settlements&leftmenu=&id=' . $addedUser['groupid'] . '">' . $addedUser['groupref'] . '</a></td>
  349. </tr>';
  350. }
  351. }
  352. print '</table>';
  353. print '</div></td>';
  354. print '</div></div>';
  355. print '</form>' . "\n";
  356. // End of page
  357. llxFooter();
  358. $db->close();
  359. ?>
  360. <script>
  361. $(document).ready(function () {
  362. // Az űrlap elküldése, ha a checkbox változik
  363. $('.entitiesChk').change(function () {
  364. $('#searchFormList').submit();
  365. });
  366. var elements = document.getElementsByClassName('submitFormLink');
  367. for (var i = 0; i < elements.length; i++) {
  368. elements[i].addEventListener('click', function (event) {
  369. event.preventDefault();
  370. var form = document.getElementById('searchFormList');
  371. var actionValue = form.getAttribute('action');
  372. var clickedElementValue = this.getAttribute('data-value');
  373. lastIndex = actionValue.lastIndexOf('&');
  374. var trimmedQueryString = actionValue.substring(0, lastIndex);
  375. form.action = trimmedQueryString + '&id=' + clickedElementValue;
  376. document.getElementById('searchFormList').submit();
  377. });
  378. }
  379. });
  380. function groupconfirm() {
  381. $('.checkforselect').prop('checked', true);
  382. }
  383. $('.massactionaddconfirmed').click(function () {
  384. $("#name_search").val('');
  385. groupconfirm();
  386. })
  387. $('.massactionconfirmed').click(function () {
  388. $("#name_search").val('');
  389. $("#deletechk").val(1);
  390. })
  391. $('.checkforallselect').click(function () {
  392. if ($(this).is(':checked')) {
  393. $('.checkforselect').prop('checked', true);
  394. $('#divDelete').css('display', 'inline-block');
  395. $('#massaction').css('display', 'inline-block');
  396. $('.massactionselect ').css('display', '');
  397. $('.massactionconfirmed ').css('display', '');
  398. } else {
  399. $('#divDelete').css('display', 'none');
  400. $('.checkforselect').prop('checked', false);
  401. $('#massaction').css('display', 'none');
  402. $('.massactionselect ').css('display', 'none');
  403. $('.massactionconfirmed ').css('display', 'none');
  404. }
  405. })
  406. $('.checkforselect').click(function () {
  407. if ($(this).is(':checked')) {
  408. $('#divDelete').css('display', 'inline-block');
  409. $('#massaction').css('display', 'inline-block');
  410. $('.massactionselect ').css('display', '');
  411. $('.massactionconfirmed ').css('display', '');
  412. } else {
  413. $('#massaction').css('display', 'none');
  414. $('#divDelete').css('display', 'none');
  415. $('.massactionselect ').css('display', 'none');
  416. $('.massactionconfirmed ').css('display', 'none');
  417. }
  418. })
  419. $('.checkforselectadd').click(function () {
  420. if ($(this).is(':checked')) {
  421. $('#divAdd').css('display', 'inline-block');
  422. $('#massactionadd').css('display', 'inline-block');
  423. $('.massactionaddselect ').css('display', '');
  424. $('.massactionaddconfirmed ').css('display', '');
  425. } else {
  426. $('#divAdd').css('display', 'none');
  427. $('#massactionadd').css('display', 'none');
  428. $('.massactionaddselect ').css('display', 'none');
  429. $('.massactionaddconfirmed ').css('display', 'none');
  430. }
  431. })
  432. function deleteFunction() {
  433. $("#name_search").val('');
  434. document.getElementById("searchFormList").submit();
  435. }
  436. function submitFormAjaxUser() {
  437. var input = document.getElementById("name_search");
  438. console.log(input.value);
  439. var inputGroup = document.getElementById("group_search");
  440. var checkboxes = document.querySelectorAll('.checkforselectadd:checked');
  441. var values = Array.from(checkboxes).map(function (checkbox) {
  442. return checkbox.value;
  443. });
  444. //if (input.value) {
  445. var xhr = new XMLHttpRequest();
  446. xhr.open("GET", "ajaxUser.php?search_title=" + input.value + "&toselectnewuser=" + values, true);
  447. xhr.onreadystatechange = function () {
  448. if (xhr.readyState === 4 && xhr.status === 200) {
  449. $("#searchedUsersDiv").html(xhr.responseText);
  450. }
  451. };
  452. xhr.send();
  453. //} else {
  454. // console.log('user: ' + input.value);
  455. //}
  456. //if (inputGroup.value) {
  457. var xhrGroup = new XMLHttpRequest();
  458. var selectedCheckboxes = $('input[type="checkbox"][id*="entity_"]:checked');
  459. var checkboxValues = selectedCheckboxes.toArray().map(function (checkbox) {
  460. return $(checkbox).val();
  461. });
  462. xhrGroup.open("GET", "ajaxGroupName.php?search_group_title=" + inputGroup.value + '&selectedEntities=' + checkboxValues, true);
  463. xhrGroup.onreadystatechange = function () {
  464. if (xhrGroup.readyState === 4 && xhrGroup.status === 200) {
  465. $("#searchedGroupsDiv").html(xhrGroup.responseText);
  466. }
  467. };
  468. xhrGroup.send();
  469. //} else {
  470. // console.log('Group: ' + inputGroup.value);
  471. //}
  472. }
  473. function submitFormAddUser(event) {
  474. var checkbox = event.target;
  475. if (checkbox.checked) {
  476. var input = document.getElementById("name_search");
  477. var checkboxes = document.querySelectorAll('.checkforselectadd:checked');
  478. var values = Array.from(checkboxes).map(function (checkbox1) {
  479. return checkbox1.value;
  480. });
  481. var xhr = new XMLHttpRequest();
  482. xhr.open("GET", "ajaxUser.php?search_title=" + input.value + "&toselectnewuser=" + values, true);
  483. xhr.onreadystatechange = function () {
  484. if (xhr.readyState === 4 && xhr.status === 200) {
  485. $("#searchedUsersDiv").html(xhr.responseText);
  486. }
  487. };
  488. xhr.send();
  489. } else {
  490. var input = document.getElementById("name_search");
  491. var checkboxes = document.querySelectorAll('.checkforselectadd:checked');
  492. var values = Array.from(checkboxes).map(function (checkbox1) {
  493. return checkbox1.value;
  494. });
  495. var xhr = new XMLHttpRequest();
  496. xhr.open("GET", "ajaxUser.php?search_title=" + input.value + "&reduction=" + values, true);
  497. xhr.onreadystatechange = function () {
  498. if (xhr.readyState === 4 && xhr.status === 200) {
  499. $("#searchedUsersDiv").html(xhr.responseText);
  500. }
  501. };
  502. xhr.send();
  503. }
  504. }
  505. var input = document.getElementById("name_search");
  506. input.focus();
  507. input.setSelectionRange(input.value.length, input.value.length);
  508. </script>