settlementsindex2.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  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[3] = 3;
  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(
  139. $_SERVER["PHP_SELF"] . '
  140. ?toselectString=' . $toselectString . '&id=' . $id . '&massaction=' . $massaction,
  141. $langs->trans('UserDeleteConfirm'),
  142. $langs->trans('UserDeleteConfirmObject', $userString),
  143. 'confirm_users_delete',
  144. '',
  145. 0,
  146. 1
  147. );
  148. }
  149. if ($massactionadd == 'add' && $confirmmassaction != '') {
  150. $usersOfGroups = $helper->getUsersById($db, $id);
  151. $usersOfGroupsFromNaploToday = $helper->getUsersOfGroupsFromNaploToday($db, $id);
  152. $confirmed = !empty($usersOfGroupsFromNaploToday) && !empty($usersOfGroups);
  153. $db->begin();
  154. $error = 0;
  155. $userObj = new User($db);
  156. $groupObj = new Group($db);
  157. $groupResult = $groupObj->fetch($id);
  158. $groupEntity = $groupObj->fk_entity;
  159. foreach ($_SESSION['usersArray'] as $newuser) {
  160. //print $newuser . '<br>';
  161. $createResult = $groupUsers->createGroupUsers($id, $newuser);
  162. if ($createResult < 0) {
  163. //print '1';
  164. $error++;
  165. }
  166. $data = $helper->createDataArray($id, $massactionadd, $newuser);
  167. $naploResult = $userNaplo->createUserNaplo($user, $data);
  168. if ($naploResult < 0) {
  169. //print '2';
  170. $error++;
  171. }
  172. $userUpdateResult = $helper->updateUserEntityInUser($newuser, $groupEntity);
  173. if ($userUpdateResult < 0) {
  174. //print '3';
  175. $error++;
  176. }
  177. }
  178. //print 'asdasd';exit;
  179. if ($error) {
  180. $db->rollback();
  181. unset($_SESSION['usersArray']);
  182. setEventMessage($langs->trans("PackageUserFailed", 'error'));
  183. } else {
  184. $db->commit();
  185. unset($_SESSION['usersArray']);
  186. $helper->returnWindowLocation($_SERVER["PHP_SELF"], $id, $idmenu);
  187. //setEventMessage($langs->trans("useradded"));
  188. }
  189. unset($_SESSION['usersArray']);
  190. }
  191. if ($confirmbutton) {
  192. $db->begin();
  193. $error = 0;
  194. $groupusers = new GroupUsers($db);
  195. $groupObj = new Group($db);
  196. $groupResult = $groupObj->fetch($id);
  197. $groupEntity = $groupObj->fk_entity;
  198. foreach ($toselect as $selected) {
  199. $moredata = explode('_', $selected);
  200. $array = [];
  201. $deleteResult = $groupusers->deleteLine($user, $moredata[0]);
  202. if ($deleteResult < 0) {
  203. $error++;
  204. $array['deleteLine'] = 1;
  205. }
  206. $createResult = $groupUsers->createGroupUsers($confirmbutton, $moredata[1]);
  207. if ($createResult < 0) {
  208. $error++;
  209. $array['createGroupUsers'] = 1;
  210. }
  211. $dataAdd = $helper->createDataArray($confirmbutton, 'add', $moredata[1]);
  212. $naploResult = $userNaplo->createUserNaplo($user, $dataAdd);
  213. if ($naploResult < 0) {
  214. $error++;
  215. $array['createUserNaplo'] = 1;
  216. }
  217. $userUpdateResult = $helper->updateUserEntityInUser($moredata[1], $groupEntity);
  218. if ($userUpdateResult < 0) {
  219. $error++;
  220. $array['updateUserEntityInUser'] = 1;
  221. }
  222. }
  223. if ($error) {
  224. $db->rollback();
  225. unset($toselect);
  226. setEventMessage($langs->trans("PackageUserFailed", 'error'));
  227. //setEventMessage(print_r($array), 'error');
  228. } else {
  229. $confirmbutton = null;
  230. $db->commit();
  231. $helper->returnWindowLocation($_SERVER["PHP_SELF"], $id, $idmenu);
  232. //setEventMessage($langs->trans("usersconfirmed"));
  233. }
  234. }
  235. if ($massaction == 'delete' && $confirmmassaction != '') {
  236. print $formconfirm;
  237. }
  238. $url = $_SERVER["PHP_SELF"] . '?idmenu=' . $idmenu . '&mainmenu=settlements&leftmenu=&id=' . $id;
  239. /* if ($massaction!=0 || $massactionadd != 0) {
  240. $url .= "&id={$id}";
  241. } */
  242. print '<form method="POST" id="searchFormList" action="' . $url . '" onkeyup="submitFormAjaxUser()">' . "\n";
  243. print '<input type="hidden" name="token" value="' . newToken() . '">';
  244. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  245. print '<input type="hidden" name="action" value="list">';
  246. if ($permissiontoclearall) {
  247. if ($helper->userGroupsAreEmpty()) {
  248. print '<div style="text-align: center; color:red; margin-bottom: 30px;">' . $langs->trans('EmptyUsersGroup') . '</div>';
  249. } else {
  250. include DOL_DOCUMENT_ROOT . '/custom/settlements/core/tpl/userclearall.tpl.php';
  251. }
  252. }
  253. print load_fiche_titre($langs->trans("UserGroups"), '', 'settlements.png@settlements');
  254. include DOL_DOCUMENT_ROOT . '/custom/settlements/core/tpl/usercheckboxes.tpl.php';
  255. //print_r($entitiesArrayIsEmpty);exit;
  256. print '<div style="width:100%; padding-bottom: 50px;">';
  257. $columnWidth = 100 / count($entities);
  258. foreach ($entities as $key => $value) {
  259. if (!$entitiesArrayIsEmpty) {
  260. $checked = $entitiesArray[$key] == $key ? 'checked' : '';
  261. } else {
  262. $checked = 'checked';
  263. }
  264. 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>';
  265. }
  266. print '</div>';
  267. print '<div style="clear:both;></div>';
  268. //---------------------------------------------
  269. # 1
  270. //---------------------------------------------
  271. print '<div class=""><div class="" style="width:33%;float:left;">';
  272. print '<table style="width:100%;">';
  273. print '<tr style="width: 100%; height: 40px; text-align: center; background-color: lightgrey;"><td colspan="2">' . $langs->trans("groupname") . '</td></tr>';
  274. //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>
  275. 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>
  276. <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>
  277. </td></tr>';
  278. print '<tr><td colspan="3"><div id="searchedGroupsDiv">';
  279. print $helper->groupList($groups, $id);
  280. print '</div></td></tr></table>';
  281. //---------------------------------------------
  282. # 2
  283. //---------------------------------------------
  284. print '</div><div class="" style="width:33%;float:left;">';
  285. print '<table style="width:100%;">';
  286. 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>';
  287. /* print '<tr style="width=100%; height:40px;"><td colspan="2" class="center"><button class="btn" name="confirmbutton" value="' . $id . '" onclick="groupconfirm()"
  288. style="width:100%; height:40px; cursor:pointer; background-color: #98FB98; ' . $confirmButtonDisplay . '">' . $langs->trans("confirm") . '</button></td></tr>'; */
  289. if (!empty($usersOfGroups)) {
  290. 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>';
  291. if (!empty($toselect)) {
  292. $$toselectUsers = [];
  293. foreach ($toselect as $toselectUser) {
  294. list($toselectKey, $toselectValue) = explode('_', $toselectUser);
  295. $toselectUsers[] = $toselectValue;
  296. }
  297. }
  298. foreach ($usersOfGroups as $user) {
  299. if (!empty($toselect)) {
  300. $checkedUser = in_array($user['fk_user'], $toselectUsers) ? 'checked' : '';
  301. }
  302. $rowidAndStatus = $helper->checkStatusToUsergroups($user, $id);
  303. if ($rowidAndStatus['status'] == 1 || empty($rowidAndStatus)) {
  304. //if ($rowidAndStatus) {
  305. $CashCLosed = '';
  306. $chkCol2Disabled = '';
  307. } else {
  308. $CashCLosed = ' <p style="margin-top:0px; margin-left: 25px;"><font color="red">' . $langs->trans('dailyClosingisOpen') . '</font>&nbsp;
  309. <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> ';
  310. $chkCol2Disabled = 'disabled';
  311. }
  312. print '<tr style="height:30px;">
  313. <td><div><span class="fa fa-user pictofixedwidth"></span> ' . $user['lastname'] . ' ' . $user['firstname'] . ' (' . $user['login'] . ')<span class="GenFac" onclick="GenFac(\'' . $user['api_key'] . '\')"> Generate </span> ' . $CashCLosed . '</div></td>
  314. <td class="nowrap center"><input id="cb911" class="flat checkforselect" type="checkbox" name="toselect[]" value="' . $user['rowid'] . '_' . $user['fk_user'] . '" ' . $chkCol2Disabled . ' ' . $checkedUser . '></td>
  315. </tr>';
  316. }
  317. } else {
  318. print '<tr style="height: 60px; text-align: center; color:red;"><td>' . $langs->trans('nouser') . '</td></tr>';
  319. }
  320. print '</table>';
  321. //---------------------------------------------
  322. # 3
  323. //---------------------------------------------
  324. print '</div><div class="" style="width:33%;float:left;">';
  325. print '<table style="width:100%;">';
  326. print '<tr style="width: 100%; height: 40px; text-align: center; background-color: lightgrey;"><td colspan="3">' . $langs->trans("freeusers") . '</td></tr>';
  327. 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>
  328. <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>
  329. </td></tr>';
  330. print '<td colspan="3"><div id="searchedUsersDiv">
  331. <table style="width:100%;">';
  332. if (is_array($allUsers['freeUsers']) && !$isConfirmedTheGroup) {
  333. foreach ($allUsers['freeUsers'] as $freeUser) {
  334. $nickname = isset($freeUser['nickname']) ? '<b>' . $freeUser['nickname'] . '</b> - ' : '';
  335. $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>' : '';
  336. $dCDisabled = $freeUser['openDailyClosing'] > 0 ? 'disabled' : '';
  337. print '<tr style="height:30px;">
  338. <td class="nowrap center"><input id="cb912" class="flat checkforselectadd" type="checkbox" onclick="submitFormAddUser(event)" name="toselectnewuser[]" value="' . $freeUser['rowid'] . '" ' . $dCDisabled . '></td>
  339. <td><span class="fa fa-user pictofixedwidth"></span>' . $nickname . $freeUser['lastname'] . ' ' . $freeUser['firstname'] . ' (' . $freeUser['login'] . ') ' . $linkToDailyclosing . '</td>
  340. </tr>';
  341. }
  342. } else {
  343. print '<tr style="height: 60px; text-align: center; color:red;"><td>' . $langs->trans('NoUser') . '</td></tr>';
  344. }
  345. print '</table><table style="width:100%; color: red;">';
  346. if (is_array($allUsers['addedUsers'])) {
  347. foreach ($allUsers['addedUsers'] as $addedUser) {
  348. $nickname = isset($addedUser['nickname']) ? '<b>' . $addedUser['nickname'] . '</b> - ' : '';
  349. print '<tr style="height:30px;">
  350. <td rowspan="2"><span class="fa fa-user pictofixedwidth"></span></td>
  351. <td>' . $nickname . $addedUser['lastname'] . ' ' . $addedUser['firstname'] . ' (' . $addedUser['login'] . ')</td></tr>';
  352. print '<tr>
  353. <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>
  354. </tr>';
  355. }
  356. }
  357. print '</table>';
  358. print '</div></td>';
  359. print '</div></div>';
  360. print '</form>' . "\n";
  361. // End of page
  362. print '<div id="myModal" class="modal">
  363. <div class="modal-content">
  364. <p>Operation in progress ...</p>
  365. </div>
  366. </div>';
  367. print '<div id="myModalError" class="modal">
  368. <div class="modal-content">
  369. <p>!!!!!!!Something went wrong!!!!!!!</p>
  370. </div>
  371. </div>';
  372. llxFooter();
  373. $db->close();
  374. ?>
  375. <style>
  376. .GenFac {
  377. margin-left: 20px;
  378. padding: 5px;
  379. border: 1px solid lightgray;
  380. border-radius: 5px;
  381. cursor: pointer;
  382. }
  383. .modal {
  384. display: none;
  385. /* Hidden by default */
  386. position: fixed;
  387. /* Stay in place */
  388. z-index: 1;
  389. /* Sit on top */
  390. left: 0;
  391. top: 0;
  392. width: 100%;
  393. /* Full width */
  394. height: 100%;
  395. /* Full height */
  396. overflow: auto;
  397. /* Enable scroll if needed */
  398. background-color: rgb(0, 0, 0);
  399. /* Fallback color */
  400. background-color: rgba(0, 0, 0, 0.4);
  401. /* Black w/ opacity */
  402. }
  403. /* Modal Content/Box */
  404. .modal-content {
  405. background-color: #fefefe;
  406. color: red;
  407. margin: 15% auto;
  408. /* 15% from the top and centered */
  409. padding: 20px;
  410. border: 1px solid #888;
  411. width: 30%;
  412. }
  413. </style>
  414. <script>
  415. // Get the button that opens the modal
  416. var btn = document.getElementById("myBtn");
  417. // Get the <span> element that closes the modal
  418. var span = document.getElementsByClassName("close")[0];
  419. // When the user clicks the button, open the modal
  420. btn.onclick = function () {
  421. modal.style.display = "block";
  422. }
  423. // When the user clicks on <span> (x), close the modal
  424. span.onclick = function () {
  425. modal.style.display = "none";
  426. }
  427. // When the user clicks anywhere outside of the modal, close it
  428. window.onclick = function (event) {
  429. if (event.target == modal) {
  430. modal.style.display = "none";
  431. }
  432. }
  433. $(document).ready(function () {
  434. // Az űrlap elküldése, ha a checkbox változik
  435. $('.entitiesChk').change(function () {
  436. $('#searchFormList').submit();
  437. });
  438. var elements = document.getElementsByClassName('submitFormLink');
  439. for (var i = 0; i < elements.length; i++) {
  440. elements[i].addEventListener('click', function (event) {
  441. event.preventDefault();
  442. var form = document.getElementById('searchFormList');
  443. var actionValue = form.getAttribute('action');
  444. var clickedElementValue = this.getAttribute('data-value');
  445. lastIndex = actionValue.lastIndexOf('&');
  446. var trimmedQueryString = actionValue.substring(0, lastIndex);
  447. form.action = trimmedQueryString + '&id=' + clickedElementValue;
  448. document.getElementById('searchFormList').submit();
  449. });
  450. }
  451. });
  452. function groupconfirm() {
  453. $('.checkforselect').prop('checked', true);
  454. }
  455. $('.massactionaddconfirmed').click(function () {
  456. $("#name_search").val('');
  457. groupconfirm();
  458. })
  459. $('.massactionconfirmed').click(function () {
  460. $("#name_search").val('');
  461. $("#deletechk").val(1);
  462. })
  463. $('.checkforallselect').click(function () {
  464. if ($(this).is(':checked')) {
  465. $('.checkforselect').prop('checked', true);
  466. $('#divDelete').css('display', 'inline-block');
  467. $('#massaction').css('display', 'inline-block');
  468. $('.massactionselect ').css('display', '');
  469. $('.massactionconfirmed ').css('display', '');
  470. } else {
  471. $('#divDelete').css('display', 'none');
  472. $('.checkforselect').prop('checked', false);
  473. $('#massaction').css('display', 'none');
  474. $('.massactionselect ').css('display', 'none');
  475. $('.massactionconfirmed ').css('display', 'none');
  476. }
  477. })
  478. $('.checkforselect').click(function () {
  479. if ($(this).is(':checked')) {
  480. $('#divDelete').css('display', 'inline-block');
  481. $('#massaction').css('display', 'inline-block');
  482. $('.massactionselect ').css('display', '');
  483. $('.massactionconfirmed ').css('display', '');
  484. } else {
  485. $('#massaction').css('display', 'none');
  486. $('#divDelete').css('display', 'none');
  487. $('.massactionselect ').css('display', 'none');
  488. $('.massactionconfirmed ').css('display', 'none');
  489. }
  490. })
  491. $('.checkforselectadd').click(function () {
  492. if ($(this).is(':checked')) {
  493. $('#divAdd').css('display', 'inline-block');
  494. $('#massactionadd').css('display', 'inline-block');
  495. $('.massactionaddselect ').css('display', '');
  496. $('.massactionaddconfirmed ').css('display', '');
  497. } else {
  498. $('#divAdd').css('display', 'none');
  499. $('#massactionadd').css('display', 'none');
  500. $('.massactionaddselect ').css('display', 'none');
  501. $('.massactionaddconfirmed ').css('display', 'none');
  502. }
  503. })
  504. function GenFac(user) {
  505. var modal = document.getElementById("myModal");
  506. var modalError = document.getElementById("myModalError");
  507. modal.style.display = "block";
  508. var xhr = new XMLHttpRequest();
  509. xhr.onreadystatechange = function () {
  510. if (xhr.readyState === XMLHttpRequest.DONE) {
  511. if (xhr.status === 200) {
  512. setTimeout(function () {
  513. modal.style.display = "none";
  514. }, 2000);
  515. } else {
  516. modal.style.display = "none";
  517. modalError.style.display = "block";
  518. setTimeout(function () {
  519. modalError.style.display = "none";
  520. }, 2000);
  521. }
  522. }
  523. };
  524. xhr.open("POST", window.location.origin + "/api/index.php/bbus/generateFactures", true);
  525. xhr.setRequestHeader("DOLAPIKEY", user);
  526. xhr.setRequestHeader("Content-Type", "application/json");
  527. xhr.setRequestHeader("Accept", "application/json");
  528. xhr.send();
  529. }
  530. function deleteFunction() {
  531. $("#name_search").val('');
  532. document.getElementById("searchFormList").submit();
  533. }
  534. function submitFormAjaxUser() {
  535. var input = document.getElementById("name_search");
  536. console.log(input.value);
  537. var inputGroup = document.getElementById("group_search");
  538. var checkboxes = document.querySelectorAll('.checkforselectadd:checked');
  539. var values = Array.from(checkboxes).map(function (checkbox) {
  540. return checkbox.value;
  541. });
  542. //if (input.value) {
  543. var xhr = new XMLHttpRequest();
  544. xhr.open("GET", "ajaxUser.php?search_title=" + input.value + "&toselectnewuser=" + values, true);
  545. xhr.onreadystatechange = function () {
  546. if (xhr.readyState === 4 && xhr.status === 200) {
  547. $("#searchedUsersDiv").html(xhr.responseText);
  548. }
  549. };
  550. xhr.send();
  551. //} else {
  552. // console.log('user: ' + input.value);
  553. //}
  554. //if (inputGroup.value) {
  555. var xhrGroup = new XMLHttpRequest();
  556. var selectedCheckboxes = $('input[type="checkbox"][id*="entity_"]:checked');
  557. var checkboxValues = selectedCheckboxes.toArray().map(function (checkbox) {
  558. return $(checkbox).val();
  559. });
  560. xhrGroup.open("GET", "ajaxGroupName.php?search_group_title=" + inputGroup.value + '&selectedEntities=' + checkboxValues, true);
  561. xhrGroup.onreadystatechange = function () {
  562. if (xhrGroup.readyState === 4 && xhrGroup.status === 200) {
  563. $("#searchedGroupsDiv").html(xhrGroup.responseText);
  564. }
  565. };
  566. xhrGroup.send();
  567. //} else {
  568. // console.log('Group: ' + inputGroup.value);
  569. //}
  570. }
  571. function submitFormAddUser(event) {
  572. var checkbox = event.target;
  573. if (checkbox.checked) {
  574. var input = document.getElementById("name_search");
  575. var checkboxes = document.querySelectorAll('.checkforselectadd:checked');
  576. var values = Array.from(checkboxes).map(function (checkbox1) {
  577. return checkbox1.value;
  578. });
  579. var xhr = new XMLHttpRequest();
  580. xhr.open("GET", "ajaxUser.php?search_title=" + input.value + "&toselectnewuser=" + values, true);
  581. xhr.onreadystatechange = function () {
  582. if (xhr.readyState === 4 && xhr.status === 200) {
  583. $("#searchedUsersDiv").html(xhr.responseText);
  584. }
  585. };
  586. xhr.send();
  587. } else {
  588. var input = document.getElementById("name_search");
  589. var checkboxes = document.querySelectorAll('.checkforselectadd:checked');
  590. var values = Array.from(checkboxes).map(function (checkbox1) {
  591. return checkbox1.value;
  592. });
  593. var xhr = new XMLHttpRequest();
  594. xhr.open("GET", "ajaxUser.php?search_title=" + input.value + "&reduction=" + values, true);
  595. xhr.onreadystatechange = function () {
  596. if (xhr.readyState === 4 && xhr.status === 200) {
  597. $("#searchedUsersDiv").html(xhr.responseText);
  598. }
  599. };
  600. xhr.send();
  601. }
  602. }
  603. var input = document.getElementById("name_search");
  604. input.focus();
  605. input.setSelectionRange(input.value.length, input.value.length);
  606. </script>