reservation.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. <?php
  2. /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2003 Eric Seigne <erics@rycks.com>
  4. * Copyright (C) 2004-2018 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
  7. * Copyright (C) 2014 Cedric GROSS <c.gross@kreiz-it.fr>
  8. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  9. * Copyright (C) 2017 Open-DSI <support@open-dsi.fr>
  10. * Copyright (C) 2018-2021 Frédéric France <frederic.france@netlogic.fr>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  24. */
  25. /**
  26. * \file htdocs/custom/booking/booking_agenda.php
  27. * \ingroup agenda
  28. * \brief Home page of calendar events
  29. */
  30. // Load Dolibarr environment
  31. require '../../main.inc.php';
  32. require_once DOL_DOCUMENT_ROOT . '/custom/booking/reservation.class.php';
  33. if (isModEnabled('project')) {
  34. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php';
  35. }
  36. if (!isset($conf->global->AGENDA_MAX_EVENTS_DAY_VIEW)) {
  37. $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW = 3;
  38. }
  39. if (empty($conf->global->AGENDA_EXT_NB)) {
  40. $conf->global->AGENDA_EXT_NB = 5;
  41. }
  42. $MAXAGENDA = $conf->global->AGENDA_EXT_NB;
  43. $disabledefaultvalues = GETPOST('disabledefaultvalues', 'int');
  44. $check_holiday = GETPOST('check_holiday', 'int');
  45. $filter = GETPOST("search_filter", 'alpha', 3) ? GETPOST("search_filter", 'alpha', 3) : GETPOST("filter", 'alpha', 3);
  46. $filtert = GETPOST("search_filtert", "int", 3) ? GETPOST("search_filtert", "int", 3) : GETPOST("filtert", "int", 3);
  47. $usergroup = GETPOST("search_usergroup", "int", 3) ? GETPOST("search_usergroup", "int", 3) : GETPOST("usergroup", "int", 3);
  48. $showbirthday = empty($conf->use_javascript_ajax) ? GETPOST("showbirthday", "int") : 1;
  49. // If not choice done on calendar owner (like on left menu link "Agenda"), we filter on user.
  50. if (empty($filtert) && empty($conf->global->AGENDA_ALL_CALENDARS)) {
  51. $filtert = $user->id;
  52. }
  53. $newparam = '';
  54. $sortfield = GETPOST('sortfield', 'aZ09comma');
  55. $sortorder = GETPOST('sortorder', 'aZ09comma');
  56. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  57. if (empty($page) || $page == -1) {
  58. $page = 0;
  59. } // If $page is not defined, or '' or -1
  60. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  61. $offset = $limit * $page;
  62. if (!$sortorder) {
  63. $sortorder = "ASC";
  64. }
  65. if (!$sortfield) {
  66. $sortfield = "a.datec";
  67. }
  68. // Security check
  69. $socid = GETPOST("search_socid", "int") ? GETPOST("search_socid", "int") : GETPOST("socid", "int");
  70. if ($user->socid) {
  71. $socid = $user->socid;
  72. }
  73. if ($socid < 0) {
  74. $socid = '';
  75. }
  76. $canedit = 1;
  77. if (empty($user->rights->agenda->myactions->read)) {
  78. accessforbidden();
  79. }
  80. if (empty($user->rights->agenda->allactions->read)) {
  81. $canedit = 0;
  82. }
  83. if (empty($user->rights->agenda->allactions->read) || $filter == 'mine') { // If no permission to see all, we show only affected to me
  84. $filtert = $user->id;
  85. }
  86. $action = GETPOST('action', 'aZ09');
  87. $time1 = GETPOST('time1', 'none');
  88. $time2 = GETPOST('time2', 'none');
  89. $facilitie = GETPOST('facilitie', 'numeric');
  90. $area = GETPOST('area', 'numeric');
  91. $profile = GETPOST('profile', 'numeric');
  92. $daterange = GETPOST('daterange', 'none');
  93. $addreservation = GETPOST('addreservation', 'numeric');
  94. $mode = GETPOST('mode', 'aZ09');
  95. if (empty($mode) && preg_match('/show_/', $action)) {
  96. $mode = $action; // For backward compatibility
  97. }
  98. // Load translation files required by the page
  99. $langs->loadLangs(array('agenda', 'other', 'commercial'));
  100. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  101. $hookmanager->initHooks(array('agenda'));
  102. $result = restrictedArea($user, 'agenda', 0, 'actioncomm&societe', 'myactions|allactions', 'fk_soc', 'id');
  103. if ($user->socid && $socid) {
  104. $result = restrictedArea($user, 'societe', $socid);
  105. }
  106. $reshook = $hookmanager->executeHooks('beforeAgenda', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  107. if ($reshook < 0) {
  108. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  109. }
  110. $help_url = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:M&oacute;dulo_Agenda';
  111. llxHeader('', $langs->trans("Agenda"), $help_url);
  112. $form = new Form($db);
  113. $reservation = new Reservation();
  114. $facilities = ["1" => "Gellért fürdő", "2" => "Széchenyi fürdő", "3" => "Lukács fürdő"];
  115. $area2 = [
  116. "1" => ["1" => "Medence_1", "2" => "Medence_2", "3" => "Focipálya"],
  117. "2" => ["1" => "Medence_1", "2" => "Medence_2"],
  118. "3" => ["1" => "Medence_1", "2" => "Focipálya"]
  119. ];
  120. $areas = ["1" => "Medence_1", "2" => "Medence_2", "3" => "Focipálya"];
  121. $profiles = [
  122. "1" => ["id" => 1, "idclass" => "SwimmingPoolLine", "name" => "SwimmingPool", "lines" => "6", "type" => 'H', "frameName" => "SwimmingPoolTitle"],
  123. "2" => ["id" => 2, "idclass" => "PoolLine", "name" => "Pool", "lines" => "4", "type" => 'V', "frameName" => "PoolTitle"],
  124. "3" => ["id" => 3, "idclass" => "PoloLine", "name" => "Polo", "lines" => "3", "type" => 'V', "frameName" => "PoloTitle"]
  125. ];
  126. //print_r($_REQUEST);
  127. if ($addreservation == 1) {
  128. print_r($_REQUEST);
  129. /* $reservation = new stdClass();
  130. $reservation->facilitie = $facilitie;
  131. $reservation->area = $area;
  132. $reservation->daterange = $daterange;
  133. $reservation->profile = $profile;
  134. $reservation->fromtime = $time1;
  135. $reservation->totime = $time2;
  136. print_r($reservation);exit; */
  137. }
  138. // Fürdő és Medence választás
  139. print '<div class="container mt-5"><h2>' . $langs->trans("reservationTitle") . '</h2><form id="reservatonForm" name="reservatonForm" onsubmit="return validatePage()">';
  140. print '<div class="container2">';
  141. print '<div style="width:100%; text-align:center; margin-top: 20px; margin-bottom: 20px;">
  142. <button type="button" style="width:25%;margin: 0em; margin-top: 20px;" class="butSetDefault" onclick="setDefault()">' . $langs->trans('SetDefault') . '</button></div>';
  143. print '</div>';
  144. print '<div class="container2">';
  145. if ($daterange == '') {
  146. $daterange = date("Y-m-d", dol_now()) . ' - ' . date("Y-m-d", dol_now());
  147. }
  148. $reservation->generateSelectorInput('facilitie', $facilities, $facilitie);
  149. print '<div class="box areaClass displayNone"></div>';
  150. $reservation->generateSelectorDateInput('date', $daterange);
  151. print '<div class="box profileClass displayNone"></div>';
  152. print '</div>';
  153. $time1Value = $time1 == '' ? '06:00' : $time1;
  154. $time2Value = $time2 == '' ? '22:00' : $time2;
  155. //$reservation->generateTimerLine($time1Value, $time2Value);
  156. print '<div class="timerClass displayNone" style="margin: 20px 5px 0px 5px; text-align: center; background-color: lightgrey; padding-top: 10px; padding-bottom: 10px;">
  157. <button type="button" onclick="adjustTime(\'time1\',\'decrease\')">-</button>
  158. <input style="text-align: center;" type="text" pattern="[0-9]+:[0-9]{2}$" placeholder="hh:mm" id="time1" name="time1" maxlength="5" value="' . $time1Value . '" readonly>
  159. <button type="button" onclick="adjustTime(\'time1\',\'increase\')">+</button>
  160. -
  161. <button type="button" onclick="adjustTime(\'time2\',\'decrease\')">-</button>
  162. <input style="text-align: center;" type="text" pattern="[0-9]+:[0-9]{2}$" placeholder="hh:mm" id="time2" name="time2" maxlength="5" value="' . $time2Value . '" readonly>
  163. <button type="button" onclick="adjustTime(\'time2\',\'increase\')">+</button>
  164. </div>';
  165. print '<div class="profileTypeClass"></div>';
  166. print '<div style="width:100%; margin: 0px 5px 0px 5px;"><button style="width:100%;margin: 0em; margin-top: 20px;" id="addreservation" name="addreservation" type="submit" value="1" class="butAction">Küldés</button></div>';
  167. print '</div>';
  168. print '</form></div>';
  169. ?>
  170. <link rel="stylesheet" type="text/css" href="reservation.css">
  171. <script>
  172. var gen = {
  173. setElem: "ok",
  174. init: function() {
  175. var now = new Date;
  176. $("#date-range").attr("date-start", now.toISOString().slice(0, 10));
  177. $("#date-range").attr("date-end", now.toISOString().slice(0, 10));
  178. $(document).on("input", ".timestart", function(event) {
  179. if (gen.setElem == "ok") {
  180. gen.setElem = "input";
  181. var elem = $(this);
  182. var a = (elem.val()).split(":");
  183. var b = (elem.parent().find(".durationtime").val()).split(":");
  184. var time = new Date();
  185. time.setHours(parseInt(a[0]), parseInt(a[1]), 00, 000);
  186. time.setMinutes(time.getMinutes() + parseInt(b[1]));
  187. time.setHours(time.getHours() + parseInt(b[0]));
  188. // var c = [time.getHours(), time.getMinutes()];
  189. elem.parent().find(".timeend").val(time.getHours() + ":" + time.getMinutes())
  190. var minutes = [parseInt(a[0]) * 60 + parseInt(a[1]), parseInt(b[0]) * 60 + parseInt(b[1])];
  191. if (isNaN(minutes[0])) {
  192. minutes[0] = 0;
  193. }
  194. if (isNaN(minutes[1])) {
  195. minutes[1] = 0;
  196. }
  197. elem.parent().parent().find(".time_slider").slider("values", 0, minutes[0]);
  198. elem.parent().parent().find(".time_slider").slider("values", 1, minutes[0] + minutes[1]);
  199. elem.parent().find(".timestart").attr("info", minutes[0]);
  200. elem.parent().find(".timeend").attr("info", minutes[0] + minutes[1]);
  201. // elem.parent().find(".durationtime").attr("info",minutes[1]);
  202. gen.setElem = "ok";
  203. }
  204. });
  205. $(document).on("input", ".durationtime", function(event) {
  206. if (gen.setElem == "ok") {
  207. gen.setElem = "input";
  208. var elem = $(this);
  209. var a = (elem.parent().find(".timestart").val()).split(":");
  210. var b = (elem.val()).split(":");
  211. var time = new Date();
  212. time.setHours(parseInt(a[0]), parseInt(a[1]), 00, 000);
  213. time.setMinutes(time.getMinutes() + parseInt(b[1]));
  214. time.setHours(time.getHours() + parseInt(b[0]));
  215. // var c = [time.getHours(), time.getMinutes()];
  216. elem.parent().find(".timeend").val(time.getHours() + ":" + time.getMinutes())
  217. var minutes = [parseInt(a[0]) * 60 + parseInt(a[1]), parseInt(b[0]) * 60 + parseInt(b[1])];
  218. if (isNaN(minutes[0])) {
  219. minutes[0] = 0;
  220. }
  221. if (isNaN(minutes[1])) {
  222. minutes[1] = 0;
  223. }
  224. // console.log(minutes);
  225. elem.parent().parent().find(".time_slider").slider("values", 0, minutes[0]);
  226. elem.parent().parent().find(".time_slider").slider("values", 1, minutes[0] + minutes[1]);
  227. elem.parent().find(".timestart").attr("info", minutes[0]);
  228. elem.parent().find(".timeend").attr("info", minutes[0] + minutes[1]);
  229. // elem.parent().find(".durationtime").attr("info",minutes[1]);
  230. gen.setElem = "ok";
  231. }
  232. });
  233. var option = {
  234. //autoUpdateInput: false,
  235. locale: {
  236. "format": "YYYY-MM-DD",
  237. cancelLabel: "M&eacute;gse",
  238. applyLabel: "Ok",
  239. "monthNames": [
  240. "janu&aacute;r",
  241. "febru&aacute;r",
  242. "m&aacute;rcius",
  243. "&aacute;prilis",
  244. "m&aacute;jus",
  245. "j&uacute;nius",
  246. "j&uacute;lius",
  247. "augusztus",
  248. "szeptember",
  249. "okt&oacute;ber",
  250. "november",
  251. "december"
  252. ],
  253. "daysOfWeek": [
  254. "Vas",
  255. "H&eacute;",
  256. "Ke",
  257. "Sze",
  258. "Cs&uuml;t",
  259. "P&eacute;",
  260. "Szo"
  261. ],
  262. }
  263. };
  264. $("#date-range").daterangepicker(option, function(start, end, label) {
  265. $("#date-range").attr("date-start", start.format("YYYY-MM-DD"));
  266. $("#date-range").attr("date-end", end.format("YYYY-MM-DD"));
  267. });
  268. },
  269. };
  270. $(function() {
  271. gen.init();
  272. });
  273. </script>
  274. <script type="text/javascript" src="https://cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
  275. <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js"></script>
  276. <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css">
  277. <script>
  278. $("form").on("keydown", function(event) {
  279. if (event.key === "Enter") {
  280. event.preventDefault();
  281. }
  282. });
  283. /* document.getElementById("time1").addEventListener("input", function() {
  284. let input = this.value.replace(/[^0-9]/g, ""); // Csak számokat enged meg
  285. let hours = input.slice(0, 2);
  286. let minutes = input.slice(2, 4);
  287. if (hours.length === 1 && hours > "2") {
  288. hours = "0" + hours;
  289. } else if (hours.length === 2 && parseInt(hours, 10) > 23) {
  290. hours = "23";
  291. }
  292. if (minutes.length === 2 && parseInt(minutes, 10) > 59) {
  293. minutes = "59";
  294. }
  295. this.value = hours + (minutes ? ':' + minutes : '');
  296. });
  297. document.getElementById("time2").addEventListener("input", function() {
  298. let input = this.value.replace(/[^0-9]/g, ""); // Csak számokat enged meg
  299. let hours = input.slice(0, 2);
  300. let minutes = input.slice(2, 4);
  301. if (hours.length === 1 && hours > "2") {
  302. hours = "0" + hours;
  303. } else if (hours.length === 2 && parseInt(hours, 10) > 23) {
  304. hours = "23";
  305. }
  306. if (minutes.length === 2 && parseInt(minutes, 10) > 59) {
  307. minutes = "59";
  308. }
  309. this.value = hours + (minutes ? ':' + minutes : '');
  310. });
  311. */
  312. function lineClick(profile, timeline, lineNumber, idclass) {
  313. var currentClass = $('#' + idclass + '_' + timeline + '_' + lineNumber).attr('class');
  314. if (currentClass.includes('LineRed')) {
  315. $('#' + idclass + '_' + timeline + '_' + lineNumber).removeClass('LineRed').addClass('LineGreen');
  316. var hiddenInput = document.getElementById(idclass + '_' + timeline);
  317. var arr = JSON.parse(hiddenInput.value);
  318. arr[lineNumber - 1] = 0;
  319. hiddenInput.value = arr;
  320. console.log("New value of hidden input:", arr);
  321. }
  322. if (currentClass.includes('LineGreen')) {
  323. $('#' + idclass + '_' + timeline + '_' + lineNumber).removeClass('LineGreen').addClass('LineRed');
  324. var hiddenInput = document.getElementById(idclass + '_' + timeline);
  325. var arr = JSON.parse(hiddenInput.value);
  326. arr[lineNumber - 1] = 1;
  327. hiddenInput.value = JSON.stringify(arr);
  328. console.log("New value of hidden input:", arr);
  329. }
  330. }
  331. function lineFullClick(profile, timeline, lineNumber, idclass) {
  332. for (i = 1; i < lineNumber; i++) {
  333. var currentClass = $('#' + idclass + '_' + timeline + '_' + i).attr('class');
  334. if (currentClass.includes('LineRed')) {
  335. $('#' + idclass + '_' + timeline + '_' + i).removeClass('LineRed').addClass('LineGreen');
  336. var hiddenInput = document.getElementById(idclass + '_' + timeline);
  337. var arr = JSON.parse(hiddenInput.value);
  338. arr[i - 1] = 0;
  339. hiddenInput.value = JSON.stringify(arr);
  340. }
  341. if (currentClass.includes('LineGreen')) {
  342. $('#' + idclass + '_' + timeline + '_' + i).removeClass('LineGreen').addClass('LineRed');
  343. var hiddenInput = document.getElementById(idclass + '_' + timeline);
  344. var arr = JSON.parse(hiddenInput.value);
  345. arr[i - 1] = 1;
  346. hiddenInput.value = JSON.stringify(arr);
  347. }
  348. }
  349. }
  350. </script>
  351. <script>
  352. function setDefault() {
  353. var fullUrl = window.location.origin;
  354. window.location.href = fullUrl + "/custom/booking/reservation.php";
  355. }
  356. function adjustTime(inputId, action) {
  357. var input = document.getElementById(inputId);
  358. var currentTime = input.value || "06:00"; // Alapértelmezett idő, ha nincs megadva
  359. var parts = currentTime.split(':');
  360. var hours = parseInt(parts[0], 10);
  361. var minutes = parseInt(parts[1], 10);
  362. // Növelés vagy csökkentés 30 perccel
  363. if (action === 'increase') {
  364. minutes += 30;
  365. } else if (action === 'decrease') {
  366. minutes -= 30;
  367. }
  368. // Kezelés a túlcsordulásokra
  369. if (minutes >= 60) {
  370. hours += 1;
  371. minutes = minutes % 60;
  372. } else if (minutes < 0) {
  373. hours -= 1;
  374. minutes = 60 + minutes;
  375. }
  376. if (hours >= 24) {
  377. hours = 0;
  378. } else if (hours < 0) {
  379. hours = 23;
  380. }
  381. // Formázás, hogy mindig kétjegyű legyen az óra és perc
  382. var formattedTime = ("0" + hours).slice(-2) + ":" + ("0" + minutes).slice(-2);
  383. input.value = formattedTime;
  384. var from = document.getElementById("time1");
  385. var to = document.getElementById("time2");
  386. var selectedProfileVal = $("#profile").find("option:selected").val();
  387. var xhrIntervalChange = new XMLHttpRequest();
  388. xhrIntervalChange.open("POST", "reservation_intervalchange.php", true);
  389. xhrIntervalChange.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  390. xhrIntervalChange.send("from=" + encodeURIComponent(from.value) + "&to=" + encodeURIComponent(to.value) + "&profile=" + selectedProfileVal);
  391. xhrIntervalChange.onload = function() {
  392. if (xhrIntervalChange.status === 200) {
  393. const profileTypeDiv = document.querySelector('.profileTypeClass');
  394. profileTypeDiv.innerHTML = xhrIntervalChange.responseText;
  395. } else {
  396. alert("Request failed");
  397. }
  398. };
  399. //document.getElementById('reservatonForm').submit();
  400. }
  401. function validatePage() {
  402. var selectfac = document.getElementById("facilitie");
  403. var selectarea = document.getElementById("area");
  404. var selectprof = document.getElementById("profile");
  405. var selectdaterange = document.getElementById("date-range");
  406. if ((!selectfac || selectfac.value == -1) ||
  407. (!selectarea || selectarea.value == -1) ||
  408. (!selectprof || selectprof.value == -1) ||
  409. (!selectdaterange || selectdaterange.value == '')) {
  410. if (!selectfac || selectfac.value == -1) {
  411. $("#request_facilitie").removeClass("displayNone").addClass("displayBlock");
  412. } else {
  413. $("#request_facilitie").addClass("displayNone");
  414. }
  415. if (!selectarea || selectarea.value == -1) {
  416. $("#request_area").removeClass("displayNone").addClass("displayBlock");
  417. } else {
  418. $("#request_area").addClass("displayNone");
  419. }
  420. if (!selectdaterange || selectdaterange.value == '') {
  421. console.log('date-range: ' + (selectdaterange ? selectdaterange.value : 'N/A'));
  422. $("#request_date").removeClass("displayNone").addClass("displayBlock");
  423. } else {
  424. $("#request_date").addClass("displayNone");
  425. }
  426. if (!selectprof || selectprof.value == -1) {
  427. $("#request_profile").removeClass("displayNone").addClass("displayBlock");
  428. } else {
  429. $("#request_profile").addClass("displayNone");
  430. }
  431. return false;
  432. } else {
  433. $("#request_facilitie").addClass("displayNone");
  434. $("#request_area").addClass("displayNone");
  435. $("#request_date").addClass("displayNone");
  436. $("#request_profile").addClass("displayNone");
  437. alert('Mentve');
  438. }
  439. }
  440. var facilitiesSelect = $("#facilitie");
  441. var areaSelect = $("#area");
  442. var profileSelect = $("#profile");
  443. var daterangeInput = $("#date-range");
  444. facilitiesSelect.select2();
  445. areaSelect.select2();
  446. profileSelect.select2();
  447. facilitiesSelect.on("change", function(e) {
  448. var selectedFacilityValue = $(this).val();
  449. var selectedFacilityText = $(this).find("option:selected").text();
  450. if (selectedFacilityValue == -1) {
  451. $("#date-range, #time1, #time2").val("");
  452. $("#time1, #time2, #area, #date-range, #profile").prop("disabled", true);
  453. var fullUrl = window.location.origin;
  454. window.location.href = fullUrl + "/custom/booking/reservation.php";
  455. } else {
  456. var xhr = new XMLHttpRequest();
  457. xhr.open("POST", "reservation_area.php", true);
  458. xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  459. // Kérés elküldése
  460. xhr.send("facilitie=" + encodeURIComponent(selectedFacilityValue) /* + "&email=" + encodeURIComponent('valami2')*/ );
  461. // Válasz kezelése
  462. xhr.onload = function() {
  463. if (xhr.status === 200) {
  464. $("#area").prop("disabled", false);
  465. $(".areaClass").removeClass("displayNone").addClass("displayBlock");
  466. const areaDiv = document.querySelector('.areaClass');
  467. areaDiv.innerHTML = xhr.responseText;
  468. var areaSelect = $("#area");
  469. areaSelect.on("change", function(e) {
  470. var selectedAreaVal = $(this).find("option:selected").val();
  471. if (selectedAreaVal == -1) {
  472. $("#time1, #time2").val("").prop("disabled", true);
  473. $(".profilesClass, .profileClass, .timerClass, .dateClass")
  474. .removeClass("displayBlock")
  475. .addClass("displayNone");
  476. } else {
  477. var xhrArea = new XMLHttpRequest();
  478. xhrArea.open("POST", "reservation_profile.php", true);
  479. xhrArea.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  480. xhrArea.send("area=" + encodeURIComponent(selectedAreaVal));
  481. xhrArea.onload = function() {
  482. if (xhrArea.status === 200) {
  483. $(".dateClass").removeClass("displayNone").addClass("displayBlock");
  484. $("#profile").prop("disabled", false);
  485. $(".profileClass").removeClass("displayNone").addClass("displayBlock");
  486. const profileDiv = document.querySelector('.profileClass');
  487. profileDiv.innerHTML = xhrArea.responseText;
  488. var profileSelect = $("#profile");
  489. profileSelect.on("change", function(e) {
  490. $(".timerClass").removeClass("displayNone").addClass("displayBlock");
  491. var selectedProfileVal = $(this).find("option:selected").val();
  492. if (selectedProfileVal == -1) {
  493. $("#time1, #time2").val("").prop("disabled", true);
  494. $(".profilesClass").removeClass("displayBlock").addClass("displayNone");
  495. } else {
  496. $("#time1").val("06:00");
  497. $("#time2").val("22:00");
  498. var selectedProfileText = $(this).find("option:selected").text();
  499. var xhrProfile = new XMLHttpRequest();
  500. xhrProfile.open("POST", "reservation_profile_type.php", true);
  501. xhrProfile.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  502. xhrProfile.send("profile=" + encodeURIComponent(selectedProfileVal));
  503. xhrProfile.onload = function() {
  504. if (xhrProfile.status === 200) {
  505. const profileTypeDiv = document.querySelector('.profileTypeClass');
  506. profileTypeDiv.innerHTML = xhrProfile.responseText;
  507. } else {
  508. alert("Request failed");
  509. }
  510. };
  511. }
  512. });
  513. } else {
  514. alert("Request failed");
  515. }
  516. };
  517. }
  518. });
  519. } else {
  520. alert("Request failed");
  521. }
  522. };
  523. }
  524. });
  525. daterangeInput.on("change", function(e) {
  526. $("#request_date").removeClass("displayBlock").addClass("displayNone");
  527. })
  528. </script>