PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.8.16
VikBooking Hotel Booking Engine & PMS v1.8.16
1.8.16 1.8.15 1.8.14 1.8.13 1.8.12 1.8.11 1.8.10 1.8.9 1.8.6 1.8.7 1.8.8 trunk 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 All 37 releases
← All changes | admin/helpers/widgets/reminders.php +173 -36 1.6.4 → 1.8.16 View file →
@@ -136,8 +136,9 @@
136 136 $length = VikRequest::getInt('length', $this->reminders_per_page, 'request');
137 137 $completed = VikRequest::getInt('completed', 0, 'request');
138 138 $expired = VikRequest::getInt('expired', 0, 'request');
139 139 $bid = VikRequest::getInt('bid', 0, 'request');
140 + $reminder_id = VikRequest::getInt('reminder_id', 0, 'request');
140 141 $wrapper = VikRequest::getString('wrapper', '', 'request');
141 142
142 143 // load reminders starting from today at 00:00:00
143 144 $now_info = getdate();
@@ -158,17 +159,36 @@
158 159 // check if a next page can be available
159 160 $has_next_page = (count($reminders) >= $length);
160 161
161 162 // compose bookings base URI
162 - $bookings_base_uri = 'index.php?option=com_vikbooking&task=editorder&cid[]=%d';
163 - if (VBOPlatformDetection::isWordPress()) {
164 - $bookings_base_uri = str_replace('index.php', 'admin.php', $bookings_base_uri);
163 + $bookings_base_uri = VBOFactory::getPlatform()->getUri()->admin('index.php?option=com_vikbooking&task=editorder&cid[]=%d', $xhtml = false);
164 +
165 + // check if a specific reminder ID was requested
166 + if ($reminder_id) {
167 + // check if the requested ID was found among the most recent ones
168 + $reminder_found = false;
169 + foreach ($reminders as $reminder) {
170 + if ($reminder->id == $reminder_id) {
171 + $reminder_found = true;
172 + break;
173 + }
174 + }
175 +
176 + if (!$reminder_found) {
177 + // fetch the record by ID
178 + $reminder_record = $helper->getReminder($reminder_id);
179 +
180 + if ($reminder_record) {
181 + // prepend element to the list
182 + array_unshift($reminders, $reminder_record);
183 + }
184 + }
165 185 }
166 186
167 187 // start output buffering
168 188 ob_start();
169 189
170 - if (!count($reminders)) {
190 + if (!$reminders) {
171 191 ?>
172 192 <p class="info"><?php echo JText::translate('VBONORESULTS'); ?></p>
173 193 <?php
174 194 } else {
@@ -215,8 +235,17 @@
215 235 ?>
216 236 <div class="vbo-widget-reminders-record <?php echo implode(' ', $extra_classes); ?>" data-reminderid="<?php echo $reminder->id; ?>">
217 237 <div class="vbo-widget-reminders-record-status">
218 238 <button type="button" class="vbo-reminder-status-dot" onclick="vboWidgetRemindersComplete('<?php echo $wrapper; ?>', '<?php echo $reminder->id; ?>');"><?php VikBookingIcons::e($use_icn_status); ?></button>
239 + <?php
240 + if ($reminder->important) {
241 + ?>
242 + <div class="vbo-widget-reminders-record-important">
243 + <?php VikBookingIcons::e('exclamation-triangle'); ?>
244 + </div>
245 + <?php
246 + }
247 + ?>
219 248 </div>
220 249 <div class="vbo-widget-reminders-record-info">
221 250 <div class="vbo-widget-reminders-record-txt">
222 251 <span class="vbo-widget-reminder-title"><?php echo htmlspecialchars($reminder->title); ?></span>
@@ -294,8 +323,18 @@
294 323 </div>
295 324 </div>
296 325 <?php
297 326
327 + if ($reminder_id) {
328 + ?>
329 + <script type="text/javascript">
330 + setTimeout(() => {
331 + vboWidgetRemindersEdit('<?php echo $wrapper; ?>', '<?php echo $reminder_id; ?>');
332 + }, 200);
333 + </script>
334 + <?php
335 + }
336 +
298 337 // get the HTML buffer
299 338 $html_content = ob_get_contents();
300 339 ob_end_clean();
301 340
@@ -314,14 +353,15 @@
314 353 * @return array
315 354 */
316 355 public function saveReminder()
317 356 {
318 - $title = VikRequest::getString('title', '', 'request');
319 - $descr = VikRequest::getString('descr', '', 'request');
320 - $date = VikRequest::getString('date', '', 'request');
321 - $hours = VikRequest::getInt('hours', 0, 'request');
322 - $minutes = VikRequest::getInt('minutes', 0, 'request');
323 - $bid = VikRequest::getInt('bid', 0, 'request');
357 + $title = VikRequest::getString('title', '', 'request');
358 + $descr = VikRequest::getString('descr', '', 'request');
359 + $date = VikRequest::getString('date', '', 'request');
360 + $hours = VikRequest::getInt('hours', 0, 'request');
361 + $minutes = VikRequest::getInt('minutes', 0, 'request');
362 + $bid = VikRequest::getInt('bid', 0, 'request');
363 + $important = VikRequest::getInt('important', 0, 'request');
324 364
325 365 // create reminder object
326 366 $reminder = new stdClass;
327 367 $reminder->title = $title;
@@ -340,8 +380,9 @@
340 380 $reminder->usetime = $use_time;
341 381 if (!empty($bid)) {
342 382 $reminder->idorder = $bid;
343 383 }
384 + $reminder->important = $important;
344 385
345 386 if (!VBORemindersHelper::getInstance()->saveReminder($reminder)) {
346 387 VBOHttpDocument::getInstance()->close(400, 'Could not create the reminder');
347 388 }
@@ -363,15 +404,16 @@
363 404 * @return array
364 405 */
365 406 public function updateReminder()
366 407 {
367 - $rid = VikRequest::getInt('rid', 0, 'request');
368 - $title = VikRequest::getString('title', '', 'request');
369 - $descr = VikRequest::getString('descr', '', 'request');
370 - $date = VikRequest::getString('date', '', 'request');
371 - $hours = VikRequest::getInt('hours', 0, 'request');
372 - $minutes = VikRequest::getInt('minutes', 0, 'request');
373 - $bid = VikRequest::getInt('bid', 0, 'request');
408 + $rid = VikRequest::getInt('rid', 0, 'request');
409 + $title = VikRequest::getString('title', '', 'request');
410 + $descr = VikRequest::getString('descr', '', 'request');
411 + $date = VikRequest::getString('date', '', 'request');
412 + $hours = VikRequest::getInt('hours', 0, 'request');
413 + $minutes = VikRequest::getInt('minutes', 0, 'request');
414 + $bid = VikRequest::getInt('bid', 0, 'request');
415 + $important = VikRequest::getInt('important', 0, 'request');
374 416
375 417 if (empty($rid)) {
376 418 VBOHttpDocument::getInstance()->close(400, 'Missing reminder ID to update');
377 419 }
@@ -477,13 +519,13 @@
477 519 /**
478 520 * Main method to invoke the widget. Contents will be loaded
479 521 * through AJAX requests, not via PHP when the page loads.
480 522 *
481 - * @param VBOMultitaskData $data multitask data object.
523 + * @param ?VBOMultitaskData $data multitask data object.
482 524 *
483 525 * @return void
484 526 */
485 - public function render(VBOMultitaskData $data = null)
527 + public function render(?VBOMultitaskData $data = null)
486 528 {
487 529 // increase widget's instance counter
488 530 static::$instance_counter++;
489 531
@@ -494,8 +536,9 @@
494 536 $wrapper_instance = !$is_ajax ? static::$instance_counter : rand();
495 537 $wrapper_id = 'vbo-widget-reminders-' . $wrapper_instance;
496 538
497 539 // default filters
540 + $reminder_id = 0;
498 541 $def_completed = 0;
499 542 $def_expired = 0;
500 543 $def_duedate = time();
501 544 $def_duehours = -1;
@@ -501,12 +544,30 @@
501 544 $def_duehours = -1;
502 545 $def_duemins = -1;
503 546
504 547 // check multitask data
505 - $page_bid = '';
548 + $page_bid = '';
549 + $auto_action = '';
550 + $js_modal_id = '';
506 551 if ($data) {
552 + // access Multitask data
507 553 $page_bid = $data->getBookingID();
508 - $booking_info = VikBooking::getBookingInfoFromID($page_bid);
554 + if ($data->isModalRendering()) {
555 + // get modal JS identifier
556 + $js_modal_id = $data->getModalJsIdentifier();
557 + }
558 +
559 + // we allow the page booking ID to be passed as an option as well
560 + $page_bid = !$page_bid ? $this->options()->fetchBookingId() : $page_bid;
561 +
562 + // check for options
563 + $reminder_id = (int) $this->getOption('reminder_id', 0);
564 + $auto_action = $this->getOption('action', '');
565 + $def_completed = (int) $this->getOption('completed', $def_completed);
566 + $def_expired = (int) $this->getOption('expired', $def_expired);
567 +
568 + // attempt to define values for this precise booking
569 + $booking_info = $page_bid ? VikBooking::getBookingInfoFromID($page_bid) : [];
509 570 if ($booking_info) {
510 571 $def_time_info = [];
511 572 if ($booking_info['checkin'] > $def_duedate) {
512 573 $def_duedate = $booking_info['checkin'];
@@ -575,10 +636,16 @@
575 636 <div class="vbo-widget-reminders-filter vbo-widget-reminders-filter-descr">
576 637 <textarea class="vbo-widget-reminders-fdescr" placeholder="<?php echo htmlspecialchars(JText::translate('VBPVIEWOPTIONALSTWO')); ?>" maxlength="2000"></textarea>
577 638 </div>
578 639 <div class="vbo-widget-reminders-filter vbo-widget-reminders-filter-booking vbo-toggle-small" style="<?php echo empty($page_bid) ? 'display: none;' : ''; ?>">
579 - <label for="assign_booking<?php echo $wrapper_instance; ?>-on"><span class="label label-info vbo-widget-reminders-filter-booking-id"><?php echo $page_bid; ?></span> <?php echo JText::translate('VBO_ASSIGN_TO_BOOKING'); ?></label>
580 - <?php echo $this->vbo_app->printYesNoButtons('assign_booking' . $wrapper_instance, JText::translate('VBYES'), JText::translate('VBNO'), (!empty($page_bid) ? 1 : 0), 1, 0); ?>
640 + <span class="vbo-widget-reminders-filter-tobooking">
641 + <label for="assign_booking<?php echo $wrapper_instance; ?>-on"><span class="label label-info vbo-widget-reminders-filter-booking-id"><?php echo $page_bid; ?></span> <?php echo JText::translate('VBO_ASSIGN_TO_BOOKING'); ?></label>
642 + <?php echo $this->vbo_app->printYesNoButtons('assign_booking' . $wrapper_instance, JText::translate('VBYES'), JText::translate('VBNO'), (!empty($page_bid) ? 1 : 0), 1, 0); ?>
643 + </span>
644 + <span class="vbo-widget-reminders-filter-importance">
645 + <label for="is_important<?php echo $wrapper_instance; ?>-on"><?php VikBookingIcons::e('exclamation-triangle'); ?> <?php echo JText::translate('VBO_IMPORTANT'); ?></label>
646 + <?php echo $this->vbo_app->printYesNoButtons('is_important' . $wrapper_instance, JText::translate('VBYES'), JText::translate('VBNO'), 0, 1, 0); ?>
647 + </span>
581 648 </div>
582 649 <div class="vbo-widget-reminders-filter-datetime">
583 650 <div class="vbo-widget-reminders-filter vbo-widget-reminders-filter-date">
584 651 <div class="vbo-field-calendar">
@@ -751,15 +818,17 @@
751 818
752 819 // check if we need to hide the assign-to-booking option
753 820 var page_bid = widget_instance.attr('data-pagebid');
754 821 if (page_bid.length && page_bid > 0) {
755 - // show assign-to-booking option
822 + // show assign-to-booking option and important reminder
756 823 widget_instance.find('.vbo-widget-reminders-filter-booking-id').text(page_bid);
757 824 widget_instance.find('input[name^="assign_booking"]').prop('checked', true);
825 + widget_instance.find('input[name^="is_important"]').prop('checked', false);
758 826 widget_instance.find('.vbo-widget-reminders-filter-booking').show();
759 827 } else {
760 - // hide assign-to-booking option
828 + // hide assign-to-booking option and important reminder
761 829 widget_instance.find('input[name^="assign_booking"]').prop('checked', false);
830 + widget_instance.find('input[name^="is_important"]').prop('checked', false);
762 831 widget_instance.find('.vbo-widget-reminders-filter-booking').hide();
763 832 }
764 833
765 834 // reset the rest of the fields in case of previous editing
@@ -813,8 +882,15 @@
813 882 widget_instance.find('input[name^="assign_booking"]').prop('checked', false);
814 883 widget_instance.find('.vbo-widget-reminders-filter-booking').hide();
815 884 }
816 885
886 + // handle important reminder flag
887 + if (booking_assigned && reminder_instance.find('.vbo-widget-reminders-record-important').length) {
888 + widget_instance.find('input[name^="is_important"]').prop('checked', true);
889 + } else {
890 + widget_instance.find('input[name^="is_important"]').prop('checked', false);
891 + }
892 +
817 893 // enter edit mode
818 894 vboWidgetRemindersToggleManage(wrapper);
819 895 }
820 896
@@ -935,8 +1011,11 @@
935 1011 console.error('Unexpected or invalid JSON response', obj_res);
936 1012 return false;
937 1013 }
938 1014
1015 + // turn flag on
1016 + vbo_reminders_changed = true;
1017 +
939 1018 // toggle edit mode
940 1019 vboWidgetRemindersToggleManage(wrapper);
941 1020
942 1021 // enable delete button
@@ -972,9 +1051,9 @@
972 1051
973 1052 /**
974 1053 * Perform the request to load the reminders.
975 1054 */
976 - function vboWidgetRemindersLoad(wrapper) {
1055 + function vboWidgetRemindersLoad(wrapper, reminder_id) {
977 1056 var widget_instance = jQuery('#' + wrapper);
978 1057 if (!widget_instance.length) {
979 1058 return false;
980 1059 }
@@ -1002,8 +1081,9 @@
1002 1081 length: length_per_page,
1003 1082 completed: show_completed,
1004 1083 expired: show_expired,
1005 1084 bid: page_bid,
1085 + reminder_id: reminder_id,
1006 1086 wrapper: wrapper,
1007 1087 tmpl: "component"
1008 1088 },
1009 1089 (response) => {
@@ -1102,8 +1182,14 @@
1102 1182 }
1103 1183 }
1104 1184 }
1105 1185
1186 + // check importance
1187 + var is_important = 0;
1188 + if (r_bid && widget_instance.find('input[name^="is_important"]').prop('checked')) {
1189 + is_important = 1;
1190 + }
1191 +
1106 1192 // disable save button
1107 1193 var save_btn = widget_instance.find('.vbo-widget-reminders-filter-save button');
1108 1194 save_btn.prop('disabled', true);
1109 1195
@@ -1123,8 +1209,9 @@
1123 1209 descr: r_descr,
1124 1210 date: r_date,
1125 1211 hours: r_hours,
1126 1212 minutes: r_mins,
1213 + important: is_important,
1127 1214 wrapper: wrapper,
1128 1215 tmpl: "component"
1129 1216 },
1130 1217 (response) => {
@@ -1134,8 +1221,12 @@
1134 1221 console.error('Unexpected or invalid JSON response', obj_res);
1135 1222 return false;
1136 1223 }
1137 1224
1225 + // turn flag on & store booking involved, if any
1226 + vbo_reminders_changed = true;
1227 + vbo_reminders_changed_bid = r_bid;
1228 +
1138 1229 // toggle edit mode
1139 1230 vboWidgetRemindersToggleManage(wrapper);
1140 1231
1141 1232 // enable save button
@@ -1228,8 +1319,14 @@
1228 1319 ?>
1229 1320
1230 1321 <script type="text/javascript">
1231 1322
1323 + // keep track of any changes related to reminders
1324 + var vbo_reminders_changed = false;
1325 +
1326 + // keep track of changes to reminders related to a bookind ID
1327 + var vbo_reminders_changed_bid = null;
1328 +
1232 1329 jQuery(function() {
1233 1330
1234 1331 // render datepicker calendar
1235 1332 jQuery('#<?php echo $wrapper_id; ?>').find('.vbo-reminders-dtpicker').datepicker({
@@ -1250,10 +1347,46 @@
1250 1347 }
1251 1348 });
1252 1349
1253 1350 // when document is ready, load reminders for this widget's instance
1254 - vboWidgetRemindersLoad('<?php echo $wrapper_id; ?>');
1351 + vboWidgetRemindersLoad('<?php echo $wrapper_id; ?>', <?php echo $reminder_id; ?>);
1255 1352
1353 + // subscribe to the multitask-panel-close event to emit the event for the reminders changed
1354 + document.addEventListener(VBOCore.multitask_close_event, function() {
1355 + if (vbo_reminders_changed) {
1356 + // emit the event with data for anyone who is listening to it
1357 + VBOCore.emitEvent('vbo_reminders_changed', {
1358 + bid: vbo_reminders_changed_bid
1359 + });
1360 + }
1361 + });
1362 +
1363 + <?php
1364 + if ($js_modal_id) {
1365 + // widget can be dismissed through the modal
1366 + ?>
1367 + // subscribe to the modal-dismissed event to emit the event for the reminders changed
1368 + document.addEventListener(VBOCore.widget_modal_dismissed + '<?php echo $js_modal_id; ?>', function() {
1369 + if (vbo_reminders_changed) {
1370 + // emit the event with data for anyone who is listening to it
1371 + VBOCore.emitEvent('vbo_reminders_changed', {
1372 + bid: vbo_reminders_changed_bid
1373 + });
1374 + }
1375 + });
1376 + <?php
1377 + }
1378 +
1379 + if ($auto_action == 'add_new') {
1380 + // injected optinos require to add a new reminder
1381 + ?>
1382 + setTimeout(() => {
1383 + vboWidgetRemindersAdd('<?php echo $wrapper_id; ?>');
1384 + }, 300);
1385 + <?php
1386 + }
1387 + ?>
1388 +
1256 1389 });
1257 1390
1258 1391 </script>
1259 1392
@@ -1285,22 +1418,26 @@
1285 1418
1286 1419 // default due-date for the newly added reminders
1287 1420 $def_due_date = date('Y-m-d H:i:s', strtotime("+1 minute"));
1288 1421
1422 + // default reminder payload
1423 + $payload = [
1424 + 'airbnb_host_guest_review' => 1,
1425 + ];
1426 +
1289 1427 // parse all eligible reservations
1290 1428 foreach ($airbnb_checkouts as $airbnb_res) {
1291 1429 // make sure this airbnb reservation requires a host-to-guest review
1292 - if (!$helper->bookingHasReminder($airbnb_res['id']) && VikChannelManager::hostToGuestReviewSupported($airbnb_res)) {
1430 + if (!$helper->bookingHasReminder($airbnb_res['id'], $payload) && VikChannelManager::hostToGuestReviewSupported($airbnb_res)) {
1293 1431 // build and schedule an automatic reminder
1294 1432 $reminder = new stdClass;
1295 - $reminder->title = JText::translate('VBO_REVIEW_YOUR_GUEST');
1296 - $reminder->descr = 'Airbnb - ' . JText::translate('VBDASHBOOKINGID') . ' ' . $airbnb_res['id'];
1297 - $reminder->duedate = $def_due_date;
1298 - $reminder->usetime = 1;
1299 - $reminder->idorder = $airbnb_res['id'];
1300 - $reminder->payload = [
1301 - 'airbnb_host_guest_review' => 1,
1302 - ];
1433 + $reminder->title = JText::translate('VBO_REVIEW_YOUR_GUEST');
1434 + $reminder->descr = 'Airbnb - ' . JText::translate('VBDASHBOOKINGID') . ' ' . $airbnb_res['id'];
1435 + $reminder->duedate = $def_due_date;
1436 + $reminder->usetime = 1;
1437 + $reminder->idorder = $airbnb_res['id'];
1438 + $reminder->payload = $payload;
1439 + $reminder->important = 1;
1303 1440
1304 1441 if ($helper->saveReminder($reminder)) {
1305 1442 // increase counter
1306 1443 $scheduled++;