reservation.class.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <?php
  2. class Reservation
  3. {
  4. public $db;
  5. private $selects = ["area", "facilitie", "profile"];
  6. private function timelineGenerator($from, $to)
  7. {
  8. $intervals = [];
  9. $startTime = strtotime($from);
  10. $endTime = strtotime($to);
  11. $index = 0;
  12. while ($startTime < $endTime) {
  13. $start = date("H:i", $startTime);
  14. $end = date("H:i", strtotime('+30 minutes', $startTime));
  15. $intervals[$index] = "$start - $end";
  16. $startTime = strtotime('+30 minutes', $startTime);
  17. $index++;
  18. }
  19. return $intervals;
  20. }
  21. public function generateSelectorInput($id, $selector, $selected)
  22. {
  23. $this->selectorInputFirstSegment($id);
  24. $this->generateOptions($selector, $selected);
  25. print '</select>
  26. <p id="request_' . $id . '" style="color:red;" class="displayNone">Kötelező kitölteni</p>';
  27. if ($id == 'facilitie') {
  28. print '</div>';
  29. }
  30. }
  31. public function generateSelectorInputForProfiles($id, $selector, $selected)
  32. {
  33. $this->selectorInputFirstSegment($id);
  34. $this->generateOptionsFromArray($selector, $selected);
  35. print '</select>
  36. <p id="request_' . $id . '" style="color:red;" class="displayNone">Kötelező kitölteni</p>
  37. </div></div>';
  38. }
  39. public function generateSelectorDateInput($id, $daterange)
  40. {
  41. global $langs;
  42. print '<div class="box ' . $id . 'Class displayNone">
  43. <label for="' . $id . '" class="form-label">' . $langs->trans('DateSelector') . ':</label>
  44. <input type="text" style="height: 28px; width: 200px;" id="date-range" name="daterange" value="' . $daterange . '"><i class="fa fa-calendar" style="margin-left: -20px;"></i>
  45. <p id="request_' . $id . '" style="color:red;" class="displayNone">Kötelező kitölteni</p></div>';
  46. }
  47. private function selectorInputFirstSegment($id)
  48. {
  49. global $langs;
  50. $class = $id == 'facilitie' ? '' : 'displayNone';
  51. if ($id == 'facilitie') {
  52. print '<div class="box ' . $id . 'Class ' . $class . '">';
  53. }
  54. print '<label for="' . $id . '" class="form-label">' . $id . ' :</label>
  55. <select class="flat widthcentpercentminusx maxwidth300" id="' . $id . '" name="' . $id . '" data-select2-id="' . $id . '" tabindex="-1"><option class="optiongrey" value="-1" data-select2-id="33">&nbsp;</option>
  56. ';
  57. }
  58. public function generateJavaScriptFirstSection($profile)
  59. {
  60. $script = '<script>var eventSelect = $("#profile");
  61. eventSelect.select2();
  62. eventSelect.on("change", function(e) {
  63. var selectedValue = $(this).val();
  64. var selectedText = $(this).find("option:selected").text();';
  65. print $script;
  66. exit;
  67. return $script;
  68. }
  69. public function generateJavascript($profile, $time)
  70. {
  71. $script = 'if (selectedValue == ' . $profile['id'] . ') {';
  72. $script .= '
  73. $("#' . $profile['frameName'] . '").removeClass("displayNone").addClass("displayBlock");';
  74. $script .= '}';
  75. $script .= '$("#time1").val("' . $time[0] . '");
  76. $("#time2").val("' . $time[1] . '");';
  77. return $script;
  78. }
  79. public function generateJavaScriptLastSection($profiles)
  80. {
  81. $script = '});
  82. $(document).ready(function() {
  83. var areaSelect = $("#area").val();
  84. if(areaSelect == -1){
  85. $("#area").prop("disabled", true);
  86. }
  87. var profileSelect = $("#profile").val();
  88. if(profileSelect == -1){
  89. $("#profile").prop("disabled", true);
  90. }';
  91. foreach ($this->selects as $select) {
  92. $script .= '$("#' . $select . '").select2({
  93. dir: "ltr",
  94. width: "resolve",
  95. minimumInputLength: 0,
  96. language: select2arrayoflanguage,
  97. matcher: function(params, data) {
  98. if ($.trim(params.term) === "") {
  99. return data;
  100. }
  101. keywords = (params.term).split(" ");
  102. for (var i = 0; i < keywords.length; i++) {
  103. if (((data.text).toUpperCase()).indexOf((keywords[i]).toUpperCase()) == -1) {
  104. return null;
  105. }
  106. }
  107. return data;
  108. },
  109. theme: "default",
  110. containerCssClass: ":all:",
  111. selectionCssClass: ":all:",
  112. templateResult: function(data, container) {
  113. if (data.element) {
  114. $(container).addClass($(data.element).attr("class"));
  115. }
  116. if (data.id == -1 && $(data.element).attr("data-html") == undefined) {
  117. return "&nbsp;";
  118. }
  119. if ($(data.element).attr("data-html") != undefined) return htmlEntityDecodeJs($(data.element).attr("data-html")); // If property html set, we decode html entities and use this
  120. return data.text;
  121. },
  122. templateSelection: function(selection) {
  123. if (selection.id == -1) return \'<span class="placeholder">\' + selection.text + "</span>";
  124. return selection.text;
  125. },
  126. escapeMarkup: function(markup) {
  127. return markup;
  128. },
  129. dropdownCssClass: "ui-dialog"
  130. });';
  131. }
  132. $script .= 'var eventSelect = $("#' . $select . '");
  133. eventSelect.select2();
  134. var selectedText = eventSelect.find("option:selected").val();
  135. console.log("selectedText: " + selectedText);
  136. if (selectedText == -1) {';
  137. foreach ($profiles as $profile) {
  138. $script .= '$("#' . $profile['frameName'] . '").addClass("displayNone");';
  139. }
  140. $script .= '}else{';
  141. foreach ($profiles as $profile) {
  142. foreach ($profiles as $profile) {
  143. $script .= 'var profile_' . $profile['name'] . ' = ' . $profile['id'] . ';';
  144. $script .= 'if(profile_' . $profile['name'] . ' == selectedText){';
  145. $script .= '$("#' . $profile['frameName'] . '").addClass("displayBlock");';
  146. $script .= '}else{';
  147. $script .= '$("#' . $profile['frameName'] . '").addClass("displayNone");}';
  148. }
  149. }
  150. $script .= '}';
  151. $script .= '})</script><!-- generateJavaScriptFirstSection END -->';
  152. return $script;
  153. }
  154. public function selectedProfile($profile)
  155. {
  156. $content = '';
  157. if ($profile['type'] == 'H') {
  158. $content .= '<div id="' . $profile['frameName'] . '"><p style="text-align: center;">' . $profile['name'] . '</p>';
  159. for ($i = 1; $i <= $profile['lines']; $i++) {
  160. $Availability = 'LineGreen';
  161. $content .= '<div id="' . $profile['idclass'] . $i . '" class="' . $Availability . ' ' . $profile['idclass'] . '" onClick="lineClick(' . $profile['id'] . ',' . $i . ',\'' . $profile['idclass'] . '\')">' . $i . '.</div>';
  162. //$content .= '<!-- ' . $profile['idclass'] . ' Line ' . $i . '. JS -->';
  163. }
  164. $content .= '</div>';
  165. }
  166. if ($profile['type'] == 'V') {
  167. $content .= '<div id="' . $profile['frameName'] . '"><p style="text-align: center;">' . $profile['name'] . '</p>';
  168. $content .= '<div id="VerticalContainer">';
  169. for ($i = 1; $i <= $profile['lines']; $i++) {
  170. $Availability = 'LineGreen';
  171. $content .= '<div id="' . $profile['idclass'] . $i . '" class="' . $Availability . ' ' . $profile['idclass'] . '" onClick="lineClick(' . $profile['id'] . ',' . $i . ',\'' . $profile['idclass'] . '\')">' . $i . '.</div>';
  172. //$content .= '<!-- ' . $profile['idclass'] . ' Line ' . $i . '. JS -->';
  173. }
  174. $content .= '</div>';
  175. $content .= '</div>';
  176. }
  177. return $content;
  178. }
  179. public function selectedProfileWithTimes($profile, $times)
  180. {
  181. $from = $times[0];
  182. $to = $times[1];
  183. $content = '';
  184. $content .= '<div id="' . $profile['frameName'] . '" class="profilesClass"><p style="text-align: center;">' . $profile['name'] . '</p>';
  185. foreach ($this->timelineGenerator($from, $to) as $key => $value) {
  186. $content .= '<div id="VerticalContainer">';
  187. $content .= '<div style="width: 100px; text-align: right; padding-right: 10px;" class="PoloTitle">' . $value . '</div>';
  188. $array = [];
  189. for ($i = 1; $i <= $profile['lines']; $i++) {
  190. $Availability = 'LineGreen';
  191. $content .= '<div id="' . $profile['idclass'] . '_' . $key . '_' . $i . '" class="' . $Availability . ' ' . $profile['idclass'] . '" onClick="lineClick(' . $profile['id'] . ',' . $key . ',' . $i . ',\'' . $profile['idclass'] . '\')">&nbsp;</div>';
  192. $array[] = 0;
  193. }
  194. $content .= '<input id="' . $profile['idclass'] . '_' . $key . '" type="hidden" name="' . $profile['idclass'] . '_lines[]" class="" value=' . json_encode($array) . '>';
  195. $content .= '<div onClick="lineFullClick(' . $profile['id'] . ',' . $key . ',' . $i . ',\'' . $profile['idclass'] . '\')">&nbsp;<i class="fa fa-arrow-left"></i></div>';
  196. $content .= '</div>';
  197. }
  198. $content .= '</div>';
  199. return $content;
  200. }
  201. private function generateOptions($array, $selected)
  202. {
  203. foreach ($array as $Key => $Value) {
  204. $selectedString = $Key == $selected ? 'selected' : '';
  205. print '<option value="' . $Key . '" ' . $selectedString . '>' . $Value . '</option>';
  206. }
  207. }
  208. private function generateOptionsFromArray($array, $selected)
  209. {
  210. foreach ($array as $item) {
  211. $selectedString = $item['id'] == $selected ? 'selected' : '';
  212. print '<option value="' . $item['id'] . '" ' . $selectedString . '>' . $item['name'] . '</option>';
  213. }
  214. }
  215. public function generateTimerLine($time1Value, $time2Value)
  216. {
  217. print '<div class="timerClass displayNone" style="margin: 20px 5px 0px 5px; text-align: center; background-color: lightgrey; padding-top: 10px; padding-bottom: 10px;">
  218. <button type="button" onclick="adjustTime(\'' . $time1Value . '\',\'decrease\')">-</button>
  219. <input type="text" pattern="[0-9]+:[0-9]{2}$" placeholder="hh:mm" id="time1" name="time1" value="' . $time1Value . '">
  220. <button type="button" onclick="adjustTime(\'' . $time1Value . '\',\'increase\')">+</button>
  221. -
  222. <button type="button" onclick="adjustTime(\'' . $time2Value . '\',\'decrease\')">-</button>
  223. <input type="text" pattern="[0-9]+:[0-9]{2}$" placeholder="hh:mm" id="time2" name="time2" value="' . $time2Value . '">
  224. <button type="button" onclick="adjustTime(\'' . $time2Value . '\',\'increase\')">+</button>
  225. </div>';
  226. }
  227. }