PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / 1.2.21
VikAppointments Services Booking Calendar v1.2.21
1.2.21 1.2.20 trunk 1.2.17 1.2.18 1.2.19
vikappointments / libraries / lite / helper.php
vikappointments / libraries / lite Last commit date
helper.php 2 days ago manager.php 2 days ago
helper.php
608 lines
1 <?php
2 /**
3 * @package VikAppointments - Libraries
4 * @subpackage lite
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 * Helper implementor used to apply the restrictions of the LITE version.
16 *
17 * @since 1.2.3
18 */
19 class VikAppointmentsLiteHelper
20 {
21 /**
22 * The platform application instance.
23 *
24 * @var JApplication
25 */
26 private $app;
27
28 /**
29 * The platform database instance.
30 *
31 * @var JDatabase
32 */
33 private $db;
34
35 /**
36 * Class constructor.
37 */
38 public function __construct()
39 {
40 $this->app = JFactory::getApplication();
41 $this->db = JFactory::getDbo();
42 }
43
44 /**
45 * Helper method used to disable the capabilities according
46 * to the restrictions applied by the LITE version.
47 *
48 * @param array $capabilities Array of key/value pairs where keys represent a capability name and boolean values
49 * represent whether the role has that capability.
50 *
51 * @return array The resulting capabilities lookup.
52 */
53 public function restrictCapabilities(array $capabilities)
54 {
55 if ($this->app->input->get('option') === 'com_vikappointments')
56 {
57 switch ($this->app->input->get('view'))
58 {
59 case 'customf':
60 // disable both CREATE and EDIT capabilities
61 $capabilities['com_vikappointments_create'] = false;
62 $capabilities['com_vikappointments_edit'] = false;
63 break;
64
65 case 'reservations':
66 // disable only EDIT capability
67 $capabilities['com_vikappointments_edit'] = false;
68 break;
69 }
70 }
71
72 return $capabilities;
73 }
74
75 /**
76 * Helper function used to auto-redirect the customers to the creation page of a
77 * new reservation while trying to manually edit an existing one.
78 *
79 * @return void
80 */
81 public function preventEditReservationAccess()
82 {
83 // edit disabled, reach add reservation instead
84 if ($this->app->input->get('option') === 'com_vikappointments' && $this->app->input->get('task') == 'reservation.edit')
85 {
86 $this->app->redirect('index.php?option=com_vikappointments&view=findreservation');
87 $this->app->close();
88 }
89 }
90
91 /**
92 * Helper method used to display an advertsing banner while trying
93 * to reach a page available only in the PRO version.
94 *
95 * @return void
96 */
97 public function displayBanners()
98 {
99 $input = $this->app->input;
100
101 // get current view
102 $view = $input->get('view');
103
104 // define list of pages not supported by the LITE version
105 $lookup = array(
106 'acl',
107 'customers',
108 'editconfigemp',
109 'editconfigcron',
110 'invoices',
111 'locations',
112 'options',
113 'rates',
114 'restrictions',
115 'reviews',
116 );
117
118 // check whether the view is supported
119 if (!$view || !in_array($view, $lookup))
120 {
121 return;
122 }
123
124 // display menu before unsetting the view
125 AppointmentsHelper::printMenu();
126
127 // use a missing view to display blank contents
128 $input->set('view', 'liteview');
129
130 // display LITE banner
131 echo JLayoutHelper::render('html.license.lite', array('view' => $view));
132 }
133
134 /**
135 * Helper method used to pre-load the resources needed by the LITE version.
136 *
137 * @return void
138 */
139 public function includeLiteAssets()
140 {
141 JFactory::getDocument()->addStyleSheet(
142 VIKAPPOINTMENTS_CORE_MEDIA_URI . 'css/lite.css',
143 ['version' => VIKAPPOINTMENTS_SOFTWARE_VERSION],
144 ['id' => 'vap-lite-style']
145 );
146 }
147
148 /**
149 * Helper method used to remove all wizard steps that refer to
150 * a feature that is not supported by the LITE version.
151 *
152 * @param boolean $status True on success, false otherwise.
153 * @param VAPWizard $wizard The wizard instance.
154 *
155 * @return void
156 */
157 public function removeWizardSteps($status, $wizard)
158 {
159 // remove steps that refer to the PRO version
160 $wizard->removeStep('options');
161 $wizard->removeStep('locations');
162 $wizard->removeStep('locwdays');
163 $wizard->removeStep('payments');
164 $wizard->removeStep('syspack');
165 $wizard->removeStep('packages');
166 $wizard->removeStep('syssubscr');
167 $wizard->removeStep('subscriptions');
168
169 return $status;
170 }
171
172 /**
173 * Helper method used to disable the possibility to switch group from the
174 * custom fields list view.
175 *
176 * @param JView $view The view instance.
177 *
178 * @return void
179 */
180 public function disableCustomFieldsGroupFilter($view)
181 {
182 // hide group filter
183 JFactory::getDocument()->addStyleDeclaration('#vap-group-sel { display: none; }');
184
185 // always manually force the group to "customers"
186 $this->app->input->set('group', 0);
187 }
188
189 /**
190 * Helper method used to display the scripts and the HTML needed to
191 * allow the management of the terms-of-service custom field.
192 *
193 * @param JView $view The view instance.
194 *
195 * @return void
196 */
197 public function displayTosFieldManagementForm($view)
198 {
199 // iterate all custom fields
200 foreach ($view->rows as $cf)
201 {
202 // check if we have a checkbox field
203 if ($cf['type'] == 'checkbox')
204 {
205 // use scripts to manage ToS
206 echo JLayoutHelper::render('html.managetos.script', array('field' => $cf));
207 }
208 }
209 }
210
211 /**
212 * Helper method used to intercept the custom request used to update
213 * the terms-of-service custom field.
214 *
215 * @return void
216 */
217 public function listenTosFieldSavingTask()
218 {
219 $input = $this->app->input;
220
221 // check if we should save the TOS field
222 if ($input->get('task') == 'customf.savetosajax')
223 {
224 $user = JFactory::getUser();
225
226 $args = array();
227 $args['name'] = $input->get('name', '', 'string');
228 $args['poplink'] = $input->get('poplink', '', 'string');
229 $args['id'] = $input->get('id', 0, 'uint');
230
231 // check user permissions
232 if (!$user->authorise('core.edit', 'com_vikappointments')
233 || !$user->authorise('core.access.custfields', 'com_vikappointments')
234 || !$args['id'])
235 {
236 UIErrorFactory::raiseError(403, JText::translate('JERROR_ALERTNOAUTHOR'));
237 }
238
239 // get record model
240 $field = JModelVAP::getInstance('customf');
241
242 // try to save arguments
243 if (!$field->save($args))
244 {
245 // get string error
246 $error = $field->getError(null, true);
247 $error = JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $error);
248
249 UIErrorFactory::raiseError(403, $error);
250 }
251
252 $this->app->setHeader('Content-Type', 'application/json');
253 $this->app->sendHeaders();
254
255 echo json_encode($field->getData());
256
257 $this->app->close();
258 }
259 }
260
261 /**
262 * Helper method used to detach the Save button from the toolbar, since
263 * the edit feature is not supported. Renames also the Save & Close button.
264 *
265 * @return void
266 */
267 public function adjustToolbarFromReservationManagement()
268 {
269 $toolbar = JToolbar::getInstance();
270
271 // load the list of registered buttons
272 $buttons = $toolbar->getButtons();
273
274 // iterate all buttons
275 foreach ($buttons as $btn)
276 {
277 // access button properties
278 $options = $btn->getDisplayData();
279
280 if ($options['id'] === 'jbutton-reservation-save' || $options['id'] === 'jbutton-reservation-saveclose')
281 {
282 // delete button from toolbar
283 $toolbar->removeButton($btn);
284 }
285 }
286
287 // register at the beginning a new save button that automatically goes back to the list
288 $toolbar->prependButton('Standard', 'apply', JText::translate('VAPSAVE'), 'reservation.saveclose', false);
289 }
290
291 /**
292 * When accessing the details of an appointment outside from the reservations list, the
293 * popup will display a button to edit the reservation. Since editing is no more allowed,
294 * we should totally remove that button in order to avoid letting it to seem buggy.
295 *
296 * @return void
297 */
298 public function disableEditFromOrderinfoModal()
299 {
300 JFactory::getDocument()->addStyleDeclaration('.modal-footer button[data-role="reservation.edit"] { display: none; }');
301 }
302
303 /**
304 * The Checkin column within the dashboard page contains a link to access the details of
305 * the reservation. Even if the management page is not accessible, it doesn't make sense
306 * to redirect the customers to the page to create new appointments.
307 *
308 * @return void
309 */
310 public function disableEditFromOrderinfoDashboardModal()
311 {
312 $document = JFactory::getDocument();
313
314 $document->addStyleDeclaration(
315 <<<CSS
316 /* edit footer from reservation modal */
317 #jmodal-orderinfo .modal-footer {
318 display: none;
319 }
320 #jmodal-orderinfo .modal-header + div.has-footer {
321 height: calc(100% - 70px) !important;
322 }
323 CSS
324 );
325
326 // since the widgets of the Dashboard tries to manually access the edit button of the modal,
327 // we need to replicate the same button somewhere else to prevent JavaScript errors
328 $document->addScriptDeclaration(
329 <<<JS
330 (function($) {
331 'use strict';
332
333 $(function() {
334 $('body').append('<a href="" style="display:none;" id="orderinfo-edit-btn">&nbsp;</a>');
335 });
336 })(jQuery);
337 JS
338 );
339 }
340
341 /**
342 * Since the multilingual is not supported by the LITE version, we need to remove the
343 * related setting from the global configuration of the program.
344 *
345 * @param JView $view The view instance.
346 *
347 * @return void
348 */
349 public function removeMultilingualSettingFromConfiguration($view)
350 {
351 $document = JFactory::getDocument();
352
353 // hide via CSS first to avoid weird behaviors due to loading delayes
354 $document->addStyleDeclaration('.multilingual-setting { display: none !important; }');
355 // then remove the whole block via JS to prevent issues with the search bar
356 $document->addScriptDeclaration(
357 <<<JS
358 (function($) {
359 'use strict';
360
361 $(function() {
362 $('.multilingual-setting').remove();
363 });
364 })(jQuery);
365 JS
366 );
367 }
368
369 /**
370 * Since the conversion codes are not supported by the LITE version, we need to remove the
371 * related setting from the global configuration of the program.
372 *
373 * @param JView $view The view instance.
374 *
375 * @return void
376 */
377 public function removeConversionsSettingFromConfiguration($view)
378 {
379 $document = JFactory::getDocument();
380
381 // hide via CSS first to avoid weird behaviors due to loading delayes
382 $document->addStyleDeclaration('.conversions-setting { display: none !important; }');
383 // then remove the whole block via JS to prevent issues with the search bar
384 $document->addScriptDeclaration(
385 <<<JS
386 (function($) {
387 'use strict';
388
389 $(function() {
390 $('.conversions-setting').remove();
391 });
392 })(jQuery);
393 JS
394 );
395 }
396
397 /**
398 * Since the e-mail custom texts are not supported by the LITE version, we need to remove the
399 * related setting from the global configuration of the program.
400 *
401 * @param JView $view The view instance.
402 *
403 * @return void
404 */
405 public function removeMailTextSettingFromConfiguration($view)
406 {
407 $document = JFactory::getDocument();
408
409 // hide via CSS first to avoid weird behaviors due to loading delayes
410 $document->addStyleDeclaration('.mailtext-setting { display: none !important; }');
411 // then remove the whole block via JS to prevent issues with the search bar
412 $document->addScriptDeclaration(
413 <<<JS
414 (function($) {
415 'use strict';
416
417 $(function() {
418 $('.mailtext-setting').remove();
419 });
420 })(jQuery);
421 JS
422 );
423 }
424
425 /**
426 * Since the cart is not supported by the LITE version, we need to remove the
427 * related settings from the global configuration of the program.
428 *
429 * @param JView $view The view instance.
430 *
431 * @return void
432 */
433 public function removeShopCartSettingsFromConfiguration($view)
434 {
435 $document = JFactory::getDocument();
436
437 // hide via CSS first to avoid weird behaviors due to loading delayes
438 $document->addStyleDeclaration('.shop-cart-setting, .vapcartchildtr { display: none !important; }');
439 // then remove the whole block via JS to prevent issues with the search bar
440 $document->addScriptDeclaration(
441 <<<JS
442 (function($) {
443 'use strict';
444
445 $(function() {
446 $('.shop-cart-setting, .vapcartchildtr').remove();
447 });
448 })(jQuery);
449 JS
450 );
451 }
452
453 /**
454 * Since the waiting list is not supported by the LITE version, we need to remove the
455 * related tab from the global configuration of the program.
456 *
457 * @param JView $view The view instance.
458 *
459 * @return void
460 */
461 public function removeShopWaitingListTabFromConfiguration($view)
462 {
463 $document = JFactory::getDocument();
464
465 // hide via CSS first to avoid weird behaviors due to loading delayes
466 $document->addStyleDeclaration('#vaptabview4 .config-panel-subnav li[data-id="vapconfigglobtitle14"],
467 #vaptabview4 .config-panel-tabview .config-panel-tabview-inner[data-id="vapconfigglobtitle14"] { display: none !important; }');
468
469 // then remove the whole block via JS to prevent issues with the search bar
470 $document->addScriptDeclaration(
471 <<<JS
472 (function($) {
473 'use strict';
474
475 $(function() {
476 $('#vaptabview4').find('.config-panel-subnav li[data-id="vapconfigglobtitle14"]').remove();
477 $('#vaptabview4').find('.config-panel-tabview .config-panel-tabview-inner[data-id="vapconfigglobtitle14"]').remove();
478 });
479 })(jQuery);
480 JS
481 );
482 }
483
484 /**
485 * Since the recurrence is not supported by the LITE version, we need to remove the
486 * related tab from the global configuration of the program.
487 *
488 * @param JView $view The view instance.
489 *
490 * @return void
491 */
492 public function removeShopRecurrenceTabFromConfiguration($view)
493 {
494 $document = JFactory::getDocument();
495
496 // hide via CSS first to avoid weird behaviors due to loading delayes
497 $document->addStyleDeclaration('#vaptabview4 .config-panel-subnav li[data-id="vapconfigglobtitle3"],
498 #vaptabview4 .config-panel-tabview .config-panel-tabview-inner[data-id="vapconfigglobtitle3"] { display: none !important; }');
499
500 // then remove the whole block via JS to prevent issues with the search bar
501 $document->addScriptDeclaration(
502 <<<JS
503 (function($) {
504 'use strict';
505
506 $(function() {
507 $('#vaptabview4').find('.config-panel-subnav li[data-id="vapconfigglobtitle3"]').remove();
508 $('#vaptabview4').find('.config-panel-tabview .config-panel-tabview-inner[data-id="vapconfigglobtitle3"]').remove();
509 });
510 })(jQuery);
511 JS
512 );
513 }
514
515 /**
516 * Since the reviews are not supported by the LITE version, we need to remove the
517 * related tab from the global configuration of the program.
518 *
519 * @param JView $view The view instance.
520 *
521 * @return void
522 */
523 public function removeShopReviewsTabFromConfiguration($view)
524 {
525 $document = JFactory::getDocument();
526
527 // hide via CSS first to avoid weird behaviors due to loading delayes
528 $document->addStyleDeclaration('#vaptabview4 .config-panel-subnav li[data-id="vapconfigglobtitle12"],
529 #vaptabview4 .config-panel-tabview .config-panel-tabview-inner[data-id="vapconfigglobtitle12"] { display: none !important; }');
530
531 // then remove the whole block via JS to prevent issues with the search bar
532 $document->addScriptDeclaration(
533 <<<JS
534 (function($) {
535 'use strict';
536
537 $(function() {
538 $('#vaptabview4').find('.config-panel-subnav li[data-id="vapconfigglobtitle12"]').remove();
539 $('#vaptabview4').find('.config-panel-tabview .config-panel-tabview-inner[data-id="vapconfigglobtitle12"]').remove();
540 });
541 })(jQuery);
542 JS
543 );
544 }
545
546 /**
547 * Since the packages are not supported by the LITE version, we need to remove the
548 * related tab from the global configuration of the program.
549 *
550 * @param JView $view The view instance.
551 *
552 * @return void
553 */
554 public function removeShopPackagesTabFromConfiguration($view)
555 {
556 $document = JFactory::getDocument();
557
558 // hide via CSS first to avoid weird behaviors due to loading delayes
559 $document->addStyleDeclaration('#vaptabview4 .config-panel-subnav li[data-id="vapconfigglobtitle16"],
560 #vaptabview4 .config-panel-tabview .config-panel-tabview-inner[data-id="vapconfigglobtitle16"] { display: none !important; }');
561
562 // then remove the whole block via JS to prevent issues with the search bar
563 $document->addScriptDeclaration(
564 <<<JS
565 (function($) {
566 'use strict';
567
568 $(function() {
569 $('#vaptabview4').find('.config-panel-subnav li[data-id="vapconfigglobtitle16"]').remove();
570 $('#vaptabview4').find('.config-panel-tabview .config-panel-tabview-inner[data-id="vapconfigglobtitle16"]').remove();
571 });
572 })(jQuery);
573 JS
574 );
575 }
576
577 /**
578 * Since the subscriptions are not supported by the LITE version, we need to remove the
579 * related tab from the global configuration of the program.
580 *
581 * @param JView $view The view instance.
582 *
583 * @return void
584 */
585 public function removeShopSubscriptionsTabFromConfiguration($view)
586 {
587 $document = JFactory::getDocument();
588
589 // hide via CSS first to avoid weird behaviors due to loading delayes
590 $document->addStyleDeclaration('#vaptabview4 .config-panel-subnav li[data-id="vapmenusubscriptions"],
591 #vaptabview4 .config-panel-tabview .config-panel-tabview-inner[data-id="vapmenusubscriptions"] { display: none !important; }');
592
593 // then remove the whole block via JS to prevent issues with the search bar
594 $document->addScriptDeclaration(
595 <<<JS
596 (function($) {
597 'use strict';
598
599 $(function() {
600 $('#vaptabview4').find('.config-panel-subnav li[data-id="vapmenusubscriptions"]').remove();
601 $('#vaptabview4').find('.config-panel-tabview .config-panel-tabview-inner[data-id="vapmenusubscriptions"]').remove();
602 });
603 })(jQuery);
604 JS
605 );
606 }
607 }
608