| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- <?php
- class Reservation
- {
- public $db;
- private $selects = ["area", "facilitie", "profile"];
- private function timelineGenerator($from, $to)
- {
- $intervals = [];
- $startTime = strtotime($from);
- $endTime = strtotime($to);
- $index = 0;
- while ($startTime < $endTime) {
- $start = date("H:i", $startTime);
- $end = date("H:i", strtotime('+30 minutes', $startTime));
- $intervals[$index] = "$start - $end";
- $startTime = strtotime('+30 minutes', $startTime);
- $index++;
- }
- return $intervals;
- }
- public function generateSelectorInput($id, $selector, $selected)
- {
- $this->selectorInputFirstSegment($id);
- $this->generateOptions($selector, $selected);
- print '</select>
- <p id="request_' . $id . '" style="color:red;" class="displayNone">Kötelező kitölteni</p>';
- if ($id == 'facilitie') {
- print '</div>';
- }
- }
- public function generateSelectorInputForProfiles($id, $selector, $selected)
- {
- $this->selectorInputFirstSegment($id);
- $this->generateOptionsFromArray($selector, $selected);
- print '</select>
- <p id="request_' . $id . '" style="color:red;" class="displayNone">Kötelező kitölteni</p>
- </div></div>';
- }
- public function generateSelectorDateInput($id, $daterange)
- {
- global $langs;
- print '<div class="box ' . $id . 'Class displayNone">
- <label for="' . $id . '" class="form-label">' . $langs->trans('DateSelector') . ':</label>
- <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>
- <p id="request_' . $id . '" style="color:red;" class="displayNone">Kötelező kitölteni</p></div>';
- }
- private function selectorInputFirstSegment($id)
- {
- global $langs;
- $class = $id == 'facilitie' ? '' : 'displayNone';
- if ($id == 'facilitie') {
- print '<div class="box ' . $id . 'Class ' . $class . '">';
- }
- print '<label for="' . $id . '" class="form-label">' . $id . ' :</label>
- <select class="flat widthcentpercentminusx maxwidth300" id="' . $id . '" name="' . $id . '" data-select2-id="' . $id . '" tabindex="-1"><option class="optiongrey" value="-1" data-select2-id="33"> </option>
- ';
- }
- public function generateJavaScriptFirstSection($profile)
- {
- $script = '<script>var eventSelect = $("#profile");
- eventSelect.select2();
- eventSelect.on("change", function(e) {
- var selectedValue = $(this).val();
- var selectedText = $(this).find("option:selected").text();';
- print $script;
- exit;
- return $script;
- }
- public function generateJavascript($profile, $time)
- {
- $script = 'if (selectedValue == ' . $profile['id'] . ') {';
- $script .= '
- $("#' . $profile['frameName'] . '").removeClass("displayNone").addClass("displayBlock");';
- $script .= '}';
- $script .= '$("#time1").val("' . $time[0] . '");
- $("#time2").val("' . $time[1] . '");';
- return $script;
- }
- public function generateJavaScriptLastSection($profiles)
- {
- $script = '});
- $(document).ready(function() {
- var areaSelect = $("#area").val();
- if(areaSelect == -1){
- $("#area").prop("disabled", true);
- }
- var profileSelect = $("#profile").val();
- if(profileSelect == -1){
- $("#profile").prop("disabled", true);
- }';
- foreach ($this->selects as $select) {
- $script .= '$("#' . $select . '").select2({
- dir: "ltr",
- width: "resolve",
- minimumInputLength: 0,
- language: select2arrayoflanguage,
- matcher: function(params, data) {
- if ($.trim(params.term) === "") {
- return data;
- }
- keywords = (params.term).split(" ");
- for (var i = 0; i < keywords.length; i++) {
- if (((data.text).toUpperCase()).indexOf((keywords[i]).toUpperCase()) == -1) {
- return null;
- }
- }
- return data;
- },
- theme: "default",
- containerCssClass: ":all:",
- selectionCssClass: ":all:",
- templateResult: function(data, container) {
- if (data.element) {
- $(container).addClass($(data.element).attr("class"));
- }
- if (data.id == -1 && $(data.element).attr("data-html") == undefined) {
- return " ";
- }
- 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
- return data.text;
- },
- templateSelection: function(selection) {
- if (selection.id == -1) return \'<span class="placeholder">\' + selection.text + "</span>";
- return selection.text;
- },
- escapeMarkup: function(markup) {
- return markup;
- },
- dropdownCssClass: "ui-dialog"
- });';
- }
- $script .= 'var eventSelect = $("#' . $select . '");
- eventSelect.select2();
- var selectedText = eventSelect.find("option:selected").val();
- console.log("selectedText: " + selectedText);
- if (selectedText == -1) {';
- foreach ($profiles as $profile) {
- $script .= '$("#' . $profile['frameName'] . '").addClass("displayNone");';
- }
- $script .= '}else{';
- foreach ($profiles as $profile) {
- foreach ($profiles as $profile) {
- $script .= 'var profile_' . $profile['name'] . ' = ' . $profile['id'] . ';';
- $script .= 'if(profile_' . $profile['name'] . ' == selectedText){';
- $script .= '$("#' . $profile['frameName'] . '").addClass("displayBlock");';
- $script .= '}else{';
- $script .= '$("#' . $profile['frameName'] . '").addClass("displayNone");}';
- }
- }
- $script .= '}';
- $script .= '})</script><!-- generateJavaScriptFirstSection END -->';
- return $script;
- }
- public function selectedProfile($profile)
- {
- $content = '';
- if ($profile['type'] == 'H') {
- $content .= '<div id="' . $profile['frameName'] . '"><p style="text-align: center;">' . $profile['name'] . '</p>';
- for ($i = 1; $i <= $profile['lines']; $i++) {
- $Availability = 'LineGreen';
- $content .= '<div id="' . $profile['idclass'] . $i . '" class="' . $Availability . ' ' . $profile['idclass'] . '" onClick="lineClick(' . $profile['id'] . ',' . $i . ',\'' . $profile['idclass'] . '\')">' . $i . '.</div>';
- //$content .= '<!-- ' . $profile['idclass'] . ' Line ' . $i . '. JS -->';
- }
- $content .= '</div>';
- }
- if ($profile['type'] == 'V') {
- $content .= '<div id="' . $profile['frameName'] . '"><p style="text-align: center;">' . $profile['name'] . '</p>';
- $content .= '<div id="VerticalContainer">';
- for ($i = 1; $i <= $profile['lines']; $i++) {
- $Availability = 'LineGreen';
- $content .= '<div id="' . $profile['idclass'] . $i . '" class="' . $Availability . ' ' . $profile['idclass'] . '" onClick="lineClick(' . $profile['id'] . ',' . $i . ',\'' . $profile['idclass'] . '\')">' . $i . '.</div>';
- //$content .= '<!-- ' . $profile['idclass'] . ' Line ' . $i . '. JS -->';
- }
- $content .= '</div>';
- $content .= '</div>';
- }
- return $content;
- }
- public function selectedProfileWithTimes($profile, $times)
- {
- $from = $times[0];
- $to = $times[1];
- $content = '';
- $content .= '<div id="' . $profile['frameName'] . '" class="profilesClass"><p style="text-align: center;">' . $profile['name'] . '</p>';
- foreach ($this->timelineGenerator($from, $to) as $key => $value) {
- $content .= '<div id="VerticalContainer">';
- $content .= '<div style="width: 100px; text-align: right; padding-right: 10px;" class="PoloTitle">' . $value . '</div>';
- $array = [];
- for ($i = 1; $i <= $profile['lines']; $i++) {
- $Availability = 'LineGreen';
- $content .= '<div id="' . $profile['idclass'] . '_' . $key . '_' . $i . '" class="' . $Availability . ' ' . $profile['idclass'] . '" onClick="lineClick(' . $profile['id'] . ',' . $key . ',' . $i . ',\'' . $profile['idclass'] . '\')"> </div>';
- $array[] = 0;
- }
- $content .= '<input id="' . $profile['idclass'] . '_' . $key . '" type="hidden" name="' . $profile['idclass'] . '_lines[]" class="" value=' . json_encode($array) . '>';
- $content .= '<div onClick="lineFullClick(' . $profile['id'] . ',' . $key . ',' . $i . ',\'' . $profile['idclass'] . '\')"> <i class="fa fa-arrow-left"></i></div>';
- $content .= '</div>';
- }
- $content .= '</div>';
- return $content;
- }
- private function generateOptions($array, $selected)
- {
- foreach ($array as $Key => $Value) {
- $selectedString = $Key == $selected ? 'selected' : '';
- print '<option value="' . $Key . '" ' . $selectedString . '>' . $Value . '</option>';
- }
- }
- private function generateOptionsFromArray($array, $selected)
- {
- foreach ($array as $item) {
- $selectedString = $item['id'] == $selected ? 'selected' : '';
- print '<option value="' . $item['id'] . '" ' . $selectedString . '>' . $item['name'] . '</option>';
- }
- }
- public function generateTimerLine($time1Value, $time2Value)
- {
- print '<div class="timerClass displayNone" style="margin: 20px 5px 0px 5px; text-align: center; background-color: lightgrey; padding-top: 10px; padding-bottom: 10px;">
- <button type="button" onclick="adjustTime(\'' . $time1Value . '\',\'decrease\')">-</button>
- <input type="text" pattern="[0-9]+:[0-9]{2}$" placeholder="hh:mm" id="time1" name="time1" value="' . $time1Value . '">
- <button type="button" onclick="adjustTime(\'' . $time1Value . '\',\'increase\')">+</button>
- -
- <button type="button" onclick="adjustTime(\'' . $time2Value . '\',\'decrease\')">-</button>
- <input type="text" pattern="[0-9]+:[0-9]{2}$" placeholder="hh:mm" id="time2" name="time2" value="' . $time2Value . '">
- <button type="button" onclick="adjustTime(\'' . $time2Value . '\',\'increase\')">+</button>
- </div>';
- }
- }
|