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 / admin / controllers / waitinglist.php
vikappointments / admin / controllers Last commit date
analytics.php 3 days ago apiban.php 3 days ago apilog.php 3 days ago apiplugin.php 3 days ago apiuser.php 3 days ago backup.php 3 days ago calendar.php 3 days ago city.php 3 days ago closure.php 3 days ago configapp.php 3 days ago configcldays.php 3 days ago configcron.php 3 days ago configemp.php 3 days ago configsmsapi.php 3 days ago configuration.php 3 days ago conversion.php 3 days ago country.php 3 days ago coupon.php 3 days ago coupongroup.php 3 days ago cronjob.php 3 days ago cronjoblog.php 3 days ago customer.php 3 days ago customf.php 3 days ago dashboard.php 3 days ago emplocwdays.php 3 days ago employee.php 3 days ago emprates.php 3 days ago export.php 3 days ago exportres.php 3 days ago file.php 3 days ago findreservation.php 3 days ago group.php 3 days ago import.php 3 days ago index.html 3 days ago invoice.php 3 days ago langcustomf.php 3 days ago langemployee.php 3 days ago langgroup.php 3 days ago langmedia.php 3 days ago langoption.php 3 days ago langoptiongroup.php 3 days ago langpackage.php 3 days ago langpackgroup.php 3 days ago langpayment.php 3 days ago langservice.php 3 days ago langstatuscode.php 3 days ago langsubscr.php 3 days ago langtax.php 3 days ago location.php 3 days ago mailtext.php 3 days ago makerecurrence.php 3 days ago media.php 3 days ago multiorder.php 3 days ago option.php 3 days ago optiongroup.php 3 days ago package.php 3 days ago packgroup.php 3 days ago packorder.php 3 days ago payment.php 3 days ago rate.php 3 days ago reportsemp.php 3 days ago reportsser.php 3 days ago reservation.php 3 days ago restriction.php 3 days ago review.php 3 days ago service.php 3 days ago serworkday.php 3 days ago state.php 3 days ago statuscode.php 3 days ago subscription.php 3 days ago subscrorder.php 3 days ago tag.php 3 days ago tax.php 3 days ago usernote.php 3 days ago waitinglist.php 3 days ago webhook.php 3 days ago wizard.php 3 days ago
waitinglist.php
261 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 * Task used to access the creation page of a new record.
25 *
26 * @return boolean
27 */
28 public function add()
29 {
30 $app = JFactory::getApplication();
31 $user = JFactory::getUser();
32
33 // unset user state for being recovered again
34 $app->setUserState('vap.waitinglist.data', array());
35
36 // check user permissions
37 if (!$user->authorise('core.create', 'com_vikappointments') || !$user->authorise('core.access.waitinglist', 'com_vikappointments') || !VikAppointments::isWaitingList())
38 {
39 // back to main list, not authorised to create records
40 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
41 $this->cancel();
42
43 return false;
44 }
45
46 $this->setRedirect('index.php?option=com_vikappointments&view=managewaitinglist');
47
48 return true;
49 }
50
51 /**
52 * Task used to access the management page of an existing record.
53 *
54 * @return boolean
55 */
56 public function edit()
57 {
58 $app = JFactory::getApplication();
59 $user = JFactory::getUser();
60
61 // unset user state for being recovered again
62 $app->setUserState('vap.waitinglist.data', array());
63
64 // check user permissions
65 if (!$user->authorise('core.edit', 'com_vikappointments') || !$user->authorise('core.access.waitinglist', 'com_vikappointments') || !VikAppointments::isWaitingList())
66 {
67 // back to main list, not authorised to edit records
68 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
69 $this->cancel();
70
71 return false;
72 }
73
74 $cid = $app->input->getUint('cid', array(0));
75
76 $this->setRedirect('index.php?option=com_vikappointments&view=managewaitinglist&cid[]=' . $cid[0]);
77
78 return true;
79 }
80
81 /**
82 * Task used to save the record data set in the request.
83 * After saving, the user is redirected to the main list.
84 *
85 * @return void
86 */
87 public function saveclose()
88 {
89 if ($this->save())
90 {
91 $this->cancel();
92 }
93 }
94
95 /**
96 * Task used to save the record data set in the request.
97 * After saving, the user is redirected to the creation
98 * page of a new record.
99 *
100 * @return void
101 */
102 public function savenew()
103 {
104 if ($this->save())
105 {
106 $this->setRedirect('index.php?option=com_vikappointments&task=waitinglist.add');
107 }
108 }
109
110 /**
111 * Task used to save the record data set in the request.
112 * After saving, the user is redirected to the management
113 * page of the record that has been saved.
114 *
115 * @return boolean
116 */
117 public function save()
118 {
119 $app = JFactory::getApplication();
120 $input = $app->input;
121 $user = JFactory::getUser();
122
123 /**
124 * Added token validation.
125 *
126 * @since 1.7
127 */
128 if (!JSession::checkToken())
129 {
130 // back to main list, missing CSRF-proof token
131 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
132 $this->cancel();
133
134 return false;
135 }
136
137 $args = array();
138 $args['id_service'] = $input->getUint('id_service', 0);
139 $args['id_employee'] = $input->getUint('id_employee', 0);
140 $args['timestamp'] = $input->getString('timestamp', '');
141 $args['email'] = $input->getString('email', '');
142 $args['phone_number'] = $input->getString('phone_number', '');
143 $args['phone_prefix'] = $input->getString('phone_prefix', '');
144 $args['jid'] = $input->getUint('jid', 0);
145 $args['id'] = $input->getUint('id', 0);
146
147 // convert formatted date into SQL date
148 $args['timestamp'] = VAPDateHelper::getSqlDate($args['timestamp']);
149
150 $rule = 'core.' . ($args['id'] > 0 ? 'edit' : 'create');
151
152 // check user permissions
153 if (!$user->authorise($rule, 'com_vikappointments') || !$user->authorise('core.access.waitinglist', 'com_vikappointments') || !VikAppointments::isWaitingList())
154 {
155 // back to main list, not authorised to create/edit records
156 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
157 $this->cancel();
158
159 return false;
160 }
161
162 // get db model
163 $model = $this->getModel();
164
165 // try to save arguments
166 $id = $model->save($args);
167
168 if (!$id)
169 {
170 // get string error
171 $error = $model->getError(null, true);
172
173 // display error message
174 $app->enqueueMessage(JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $error), 'error');
175
176 $url = 'index.php?option=com_vikappointments&view=managewaitinglist';
177
178 if ($args['id'])
179 {
180 $url .= '&cid[]=' . $args['id'];
181 }
182
183 // redirect to new/edit page
184 $this->setRedirect($url);
185
186 return false;
187 }
188
189 // display generic successful message
190 $app->enqueueMessage(JText::translate('JLIB_APPLICATION_SAVE_SUCCESS'));
191
192 // redirect to edit page
193 $this->setRedirect('index.php?option=com_vikappointments&task=waitinglist.edit&cid[]=' . $id);
194
195 return true;
196 }
197
198 /**
199 * Deletes a list of records set in the request.
200 *
201 * @return boolean
202 */
203 public function delete()
204 {
205 $app = JFactory::getApplication();
206 $user = JFactory::getUser();
207
208 /**
209 * Added token validation.
210 * Both GET and POST are supported.
211 *
212 * @since 1.7
213 */
214 if (!JSession::checkToken() && !JSession::checkToken('get'))
215 {
216 // back to main list, missing CSRF-proof token
217 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
218 $this->cancel();
219
220 return false;
221 }
222
223 $cid = $app->input->get('cid', array(), 'uint');
224
225 // check user permissions
226 if (!$user->authorise('core.delete', 'com_vikappointments') || !$user->authorise('core.access.waitinglist', 'com_vikappointments') || !VikAppointments::isWaitingList())
227 {
228 // back to main list, not authorised to delete records
229 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
230 $this->cancel();
231
232 return false;
233 }
234
235 // delete selected records
236 $this->getModel()->delete($cid);
237
238 // back to main list
239 $this->cancel();
240
241 return true;
242 }
243
244 /**
245 * Redirects the users to the main records list.
246 *
247 * @return void
248 */
249 public function cancel()
250 {
251 if (VikAppointments::isWaitingList())
252 {
253 $this->setRedirect('index.php?option=com_vikappointments&view=waitinglist');
254 }
255 else
256 {
257 $this->setRedirect('index.php?option=com_vikappointments');
258 }
259 }
260 }
261