PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / 1.2.20
VikAppointments Services Booking Calendar v1.2.20
1.2.21 1.2.20 trunk 1.2.17 1.2.18 1.2.19
vikappointments / site / layouts / blocks / calendar / weekly.php
vikappointments / site / layouts / blocks / calendar Last commit date
index.html 1 month ago monthly.php 1 month ago weekly.php 1 month ago
weekly.php
290 lines
1 <?php
2 /**
3 * @package VikAppointments
4 * @subpackage core
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved.
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 * @link https://vikwp.com
9 */
10
11 // No direct access
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 /**
15 * Layout variables
16 * -----------------
17 * @var object calendar An object holding the calendar details.
18 * @var integer id_service The service ID.
19 * @var integer id_employee The employee ID.
20 * @var string date The selected check-in date.
21 * @var int|null hour The selected check-in hour.
22 * @var int|null min The selected check-in minutes.
23 */
24 extract($displayData);
25
26 $vik = VAPApplication::getInstance();
27
28 $config = VAPFactory::getConfig();
29
30 // get all the days with a valid timeline
31 $open_days = array_filter($calendar->days, function($day)
32 {
33 return $day->timeline;
34 });
35
36 ?>
37
38 <div id="weeklycal-wrapper">
39
40 <style>
41 /* hide default timeline when using this calendar layout */
42 #vaptimeline {
43 display: none !important;
44 visibility: hidden !important;
45 }
46 </style>
47
48 <div class="emp-avail-table weekly-calendar">
49
50 <!-- TABLE HEADING (days and arrows) -->
51
52 <div class="avail-table-head">
53
54 <!-- LEFT ARROW TO SEE PREVIOUS DAYS -->
55
56 <div class="table-head-left-arrow">
57 <?php
58 if ($calendar->prev)
59 {
60 ?>
61 <a href="javascript:void(0)" onclick="vapGetTimeline('<?php echo $calendar->prev; ?>');">
62 <i class="fas fa-chevron-left"></i>
63 </a>
64 <?php
65 }
66 else
67 {
68 ?>
69 <i class="fas fa-chevron-left"></i>
70 <?php
71 }
72 ?>
73 </div>
74
75 <!-- CURRENT DAYS -->
76
77 <div class="table-head-center">
78 <?php
79 foreach ($calendar->days as $day)
80 {
81 ?>
82 <div class="table-head-day" data-date="<?php echo $day->date; ?>">
83 <div class="day-name"><?php echo JHtml::fetch('date', $day->date, 'D', 'UTC'); ?></div>
84 <div class="day-desc"><?php echo JHtml::fetch('date', $day->date, 'j M', 'UTC'); ?></div>
85 </div>
86 <?php
87 }
88 ?>
89 </div>
90
91 <!-- RIGHT ARROW TO SEE NEXT DAYS -->
92
93 <div class="table-right-arrow">
94 <?php
95 if ($calendar->next)
96 {
97 ?>
98 <a href="javascript:void(0)" onclick="vapGetTimeline('<?php echo $calendar->next; ?>');">
99 <i class="fas fa-chevron-right"></i>
100 </a>
101 <?php
102 }
103 else
104 {
105 ?>
106 <i class="fas fa-chevron-right"></i>
107 <?php
108 }
109 ?>
110 </div>
111
112 </div>
113
114 <!-- TABLE BODY (times) -->
115
116 <div class="avail-table-body">
117
118 <div class="avail-table-body-cols">
119 <?php
120 if ($open_days)
121 {
122 foreach ($calendar->days as $day)
123 {
124 ?>
125 <div class="avail-table-day-col vaptimeline" data-date="<?php echo $day->date; ?>">
126 <?php
127 // make sure we have a timeline to parse
128 if ($day->timeline)
129 {
130 echo $day->timeline->display();
131 }
132 ?>
133 </div>
134 <?php
135 }
136 }
137 else
138 {
139 // get first available error
140 $errors = array_filter($calendar->days, function($day)
141 {
142 return !empty($day->timelineError);
143 });
144
145 // no available days, display error message
146 ?>
147 <div class="closed-warn">
148 <?php
149 if ($errors)
150 {
151 // display a descriptive error message
152 echo array_shift($errors)->timelineError;
153 }
154 else
155 {
156 // generic "Closed" message
157 echo strtoupper(JText::translate('VAPEDITEMPLOYEE17'));
158 }
159 ?>
160 </div>
161 <?php
162 }
163 ?>
164 </div>
165
166 </div>
167
168 </div>
169
170 <script>
171
172 (function($) {
173
174 $(function() {
175 // always display the button to subscribe into the waiting list
176 $('#vapwaitlistbox').show();
177
178 // after picking a time slot, adjust the selected date, since it may be different
179 // than the one stored within the hidden input field
180 $('a[onclick*="vapTimeClicked"]').on('timeline.afterpicktime', function(event) {
181 var date = $(this).closest('[data-date]').data('date');
182
183 $('#vapdayselected').val(date);
184 $('#vapconfdayselected').val(date);
185 });
186
187 // rewrite the default function used to reload the timeline
188 window.vapGetTimeline = (date) => {
189 const input = $('#vapdayselected');
190
191 if (typeof date === 'undefined') {
192 // get first date within the table
193 date = $('.weekly-calendar [data-date]').first().data('date');
194
195 if (!input.val()) {
196 // no selected date, register it to bypass this check for later calls
197 input.val(date);
198
199 return false;
200 }
201 }
202
203 // always update currently selected date
204 input.val(date);
205
206 /**
207 * @see views/employeesearch/tmpl/default.php
208 */
209 LAST_TIMESTAMP_USED = null;
210
211 /**
212 * @see layouts/blocks/checkout.php
213 */
214 isTimeChoosen = false;
215
216 // prepare timeline data
217 let data = {
218 day: date,
219 id_emp: <?php echo (int) $id_employee; ?>,
220 id_ser: <?php echo (int) $id_service; ?>,
221 people: jQuery('#vapserpeopleselect').val(),
222 locations: [],
223 };
224
225 // Make a request to refresh the price according to the new parameters.
226 UIAjax.do(
227 '<?php echo VAPApplication::getInstance()->ajaxUrl('index.php?option=com_vikappointments&task=employeesearch.refreshprice'); ?>',
228 data,
229 (result) => {
230 // refresh the service price
231 vapUpdateServiceRate(result.rate);
232 }
233 );
234
235 // unset hours and minutes as the checkin day has changed
236 jQuery('#vapconfhourselected').val('');
237 jQuery('#vapconfminselected').val('');
238
239 // update input hidden holding the selected number of participants
240 jQuery('#vappeopleselected').val(data.people);
241
242 // flag used to check whether all the locations are selected
243 let all = true;
244
245 jQuery('.vap-empsearch-locval').each(function() {
246 if (jQuery(this).is(':checked')) {
247 data.locations.push(jQuery(this).val());
248 } else {
249 // at least one not selected
250 all = false;
251 }
252 });
253
254 if (all) {
255 // all locations are selected, so we can ignore this filter
256 delete data.locations;
257 }
258
259 UIAjax.do(
260 '<?php echo $vik->ajaxUrl('index.php?option=com_vikappointments&task=calendarweek.availtableajax'); ?>',
261 data,
262 (resp) => {
263 // self-replace the HTML of this layout
264 $('#weeklycal-wrapper').replaceWith(resp);
265
266 <?php
267 /**
268 * If hours and minutes are set, try to pre-select
269 * the specified block.
270 *
271 * @since 1.6
272 */
273 if (isset($date) && isset($hour) && isset($min)): ?>
274 $('.vaptimeline[data-date="<?php echo $date; ?>"]')
275 .find('.vap-timeline-block[data-hour="<?php echo (int) $hour; ?>"][data-min="<?php echo (int) $min; ?>"]')
276 .closest('a')
277 .trigger('click');
278 <?php endif; ?>
279 },
280 (err) => {
281 // do nothing on error
282 }
283 );
284 }
285 });
286
287 })(jQuery);
288
289 </script>
290 </div>