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 / site / controllers / waitinglist.php
vikappointments / site / controllers Last commit date
calendarweek.php 2 days ago cart.php 2 days ago confirmapp.php 2 days ago empattachser.php 2 days ago empeditcoupon.php 2 days ago empeditcustfield.php 2 days ago empeditlocation.php 2 days ago empeditpay.php 2 days ago empeditprofile.php 2 days ago empeditservice.php 2 days ago empeditwdays.php 2 days ago emplocwdays.php 2 days ago emplogin.php 2 days ago employeesearch.php 2 days ago employeeslist.php 2 days ago empmakerecur.php 2 days ago empmanres.php 2 days ago empsettings.php 2 days ago empsubscr.php 2 days ago empsubscrorder.php 2 days ago index.html 2 days ago modules.php 2 days ago order.php 2 days ago packages.php 2 days ago packagesconfirm.php 2 days ago packagesorder.php 2 days ago servicesearch.php 2 days ago subscriptions.php 2 days ago subscrpayment.php 2 days ago userprofile.php 2 days ago waitinglist.php 2 days ago
waitinglist.php
125 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 VAPLoader::import('libraries.mvc.controllers.admin');
15
16 /**
17 * VikAppointments waiting list controller.
18 *
19 * @since 1.7
20 */
21 class VikAppointmentsControllerWaitinglist extends VAPControllerAdmin
22 {
23 /**
24 * AJAX end-point used to subscribe a user into the waiting list.
25 * This method expects the following parameters to be sent
26 * via POST or GET.
27 *
28 * @param string date The date for which the user should be subscribed.
29 * @param integer id_service The ID of the service for which the user is interested.
30 * @param integer id_employee The ID of the employee for which the user is interested.
31 * @param string email The user e-mail.
32 * @param string phone The user phone number.
33 *
34 * @return void
35 */
36 public function subscribeajax()
37 {
38 $app = JFactory::getApplication();
39 $input = $app->input;
40
41 if (!VikAppointments::isWaitingList())
42 {
43 // waiting list feature is blocked
44 UIErrorFactory::raiseError(403, JText::translate('JERROR_ALERTNOAUTHOR'));
45 }
46
47 $args = array();
48 $args['timestamp'] = $input->getString('date', null);
49 $args['id_service'] = $input->getUint('id_service', 0);
50 $args['id_employee'] = $input->getUint('id_employee', 0);
51 $args['email'] = $input->getString('mail');
52 $args['phone_number'] = $input->getString('phone');
53
54 // get waiting list model
55 $model = $this->getModel();
56
57 // subscribe into waiting list
58 if (!$model->subscribe($args))
59 {
60 // get last error fetched
61 $error = $model->getError($index = null, $string = true);
62 UIErrorFactory::raiseError(500, $error ? $error : JText::translate('VAPWAITLISTADDED0'));
63 }
64
65 // send response to caller
66 $this->sendJSON(json_encode(JText::translate('VAPWAITLISTADDED1')));
67 }
68
69 /**
70 * Task used to unsubscribe a user from the waiting list.
71 * This method expects the following parameters to be sent
72 * via POST or GET.
73 *
74 * @param string email The user e-mail.
75 * @param string phone The user phone number.
76 *
77 * @return boolean
78 */
79 public function unsubscribe()
80 {
81 $app = JFactory::getApplication();
82 $input = $app->input;
83 $session = JFactory::getSession();
84
85 $itemid = $input->getUint('Itemid', 0);
86
87 // set redirect URL
88 $url = 'index.php?option=com_vikappointments&view=unsubscr_waiting_list' . ($itemid ? '&Itemid=' . $itemid : '');
89
90 if (!JSession::checkToken())
91 {
92 // direct access attempt
93 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
94 $this->setRedirect(JRoute::rewrite($url, false));
95 return false;
96 }
97
98 $args = array();
99 $args['email'] = $input->getString('email');
100 $args['phone_number'] = $input->getString('phone');
101
102 // get waiting list model
103 $model = $this->getModel();
104
105 // try to unsubscribe user
106 $count = $model->unsubscribe($args);
107
108 // register count of deleted records in URL
109 $url .= '&deleted=' . $count;
110 $this->setRedirect(JRoute::rewrite($url, false));
111
112 if (!$count)
113 {
114 // get error message fetched by the model, if any
115 $error = $model->getError($index = null, $string = true);
116
117 if ($error)
118 {
119 // enqueue error message
120 $app->enqueueMessage($error, 'error');
121 }
122 }
123 }
124 }
125