PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / trunk
VikAppointments Services Booking Calendar vtrunk
trunk 1.2.17 1.2.18 1.2.19
vikappointments / site / controllers / modules.php
vikappointments / site / controllers Last commit date
calendarweek.php 3 years ago cart.php 1 month ago confirmapp.php 2 years ago empattachser.php 4 years ago empeditcoupon.php 4 years ago empeditcustfield.php 4 years ago empeditlocation.php 4 years ago empeditpay.php 4 years ago empeditprofile.php 4 months ago empeditservice.php 4 years ago empeditwdays.php 4 years ago emplocwdays.php 4 years ago emplogin.php 2 years ago employeesearch.php 2 years ago employeeslist.php 4 years ago empmakerecur.php 1 month ago empmanres.php 1 month ago empsettings.php 2 years ago empsubscr.php 4 years ago empsubscrorder.php 1 year ago index.html 6 years ago modules.php 1 year ago order.php 4 months ago packages.php 4 years ago packagesconfirm.php 4 years ago packagesorder.php 1 year ago servicesearch.php 2 years ago subscriptions.php 4 years ago subscrpayment.php 1 year ago userprofile.php 4 months ago waitinglist.php 4 years ago
modules.php
363 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 modules helper controller.
18 *
19 * @since 1.7
20 */
21 class VikAppointmentsControllerModules extends VAPControllerAdmin
22 {
23 /**
24 * AJAX task used to validated the specified zip code
25 * for the given employee and service.
26 *
27 * @return void
28 */
29 function validatezip()
30 {
31 $input = JFactory::getApplication()->input;
32
33 /**
34 * Added token validation.
35 *
36 * @since 1.7
37 */
38 if (!JSession::checkToken())
39 {
40 // missing CSRF-proof token
41 UIErrorFactory::raiseError(403, JText::translate('JINVALID_TOKEN'));
42 }
43
44 $id_ser = $input->getUint('id_ser', 0);
45 $id_emp = $input->getUint('id_emp', 0);
46 $zip_code = $input->getString('zip', '');
47
48 // validate ZIP code
49 $valid = VikAppointments::validateZipCode($zip_code, $id_emp, $id_ser);
50
51 // send result to caller
52 $this->sendJSON($valid);
53 }
54
55 /**
56 * AJAX task used to return the list of employees
57 * assigned to the specified service.
58 *
59 * This task is used by the SEARCH module to obtain
60 * the employees after switching value from the services
61 * dropdown.
62 *
63 * @return void
64 */
65 function serviceemployees()
66 {
67 $input = JFactory::getApplication()->input;
68
69 /**
70 * Added token validation.
71 *
72 * @since 1.7
73 */
74 if (!JSession::checkToken())
75 {
76 // missing CSRF-proof token
77 UIErrorFactory::raiseError(403, JText::translate('JINVALID_TOKEN'));
78 }
79
80 $id_ser = $input->getUint('id_ser', 0);
81
82 // get service model
83 $model = $this->getModel('service');
84
85 // load service details
86 $service = $model->getItem($id_ser);
87
88 if (!$service || !$service->choose_emp)
89 {
90 // do not load the employees
91 $this->sendJSON([]);
92 }
93
94 // load all the available employees
95 $employees = $model->getEmployees($id_ser, $strict = true);
96
97 if ($employees)
98 {
99 // translate the employees
100 VikAppointments::translateEmployees($employees);
101 }
102
103 // send employees to caller
104 $this->sendJSON($employees);
105 }
106
107 /**
108 * AJAX task used to return the list of options assigned to the
109 * specified service.
110 *
111 * This task is used by the ONE PAGE BOOKING module to obtain
112 * the options after switching value from the services dropdown.
113 *
114 * @return void
115 *
116 * @since 1.7.3
117 */
118 function serviceoptions()
119 {
120 $input = JFactory::getApplication()->input;
121
122 if (!JSession::checkToken())
123 {
124 // missing CSRF-proof token
125 UIErrorFactory::raiseError(403, JText::translate('JINVALID_TOKEN'));
126 }
127
128 $id_ser = $input->getUint('id_ser', 0);
129 $mode = $input->getString('mode', 'array');
130
131 // get service search view model
132 $model = $this->getModel('servicesearch');
133
134 // load options
135 $options = $model->getOptions($id_ser);
136
137 if ($mode === 'html')
138 {
139 if ($options)
140 {
141 // render options form
142 $options = json_encode(JLayoutHelper::render('blocks.options', [
143 'options' => $options,
144 ]));
145 }
146 else
147 {
148 // no available options
149 $options = null;
150 }
151 }
152
153 // send response to caller
154 $this->sendJSON($options);
155 }
156
157 /**
158 * AJAX task used to return the list of services that
159 * belong to the specified group.
160 *
161 * This task is used by the EMPLOYEES FILTER module to
162 * obtain the list of services after switching group.
163 *
164 * @return void
165 */
166 function groupservices()
167 {
168 $input = JFactory::getApplication()->input;
169
170 /**
171 * Added token validation.
172 *
173 * @since 1.7
174 */
175 if (!JSession::checkToken())
176 {
177 // missing CSRF-proof token
178 UIErrorFactory::raiseError(403, JText::translate('JINVALID_TOKEN'));
179 }
180
181 $id_group = $input->getUint('id_group', 0);
182
183 $services = array();
184
185 $dbo = JFactory::getDbo();
186
187 $q = $dbo->getQuery(true)
188 ->select($dbo->qn(array('id', 'name')))
189 ->from($dbo->qn('#__vikappointments_service'))
190 ->order($dbo->qn('ordering') . ' ASC');
191
192 if ($id_group > 0)
193 {
194 $q->where($dbo->qn('id_group') . ' = ' . $id_group);
195 }
196
197 $dbo->setQuery($q);
198 $services = $dbo->loadAssocList();
199 VikAppointments::translateServices($services);
200
201 // send response to caller
202 $this->sendJSON($services);
203 }
204
205 /**
206 * AJAX task used to return the list of states that
207 * belong to the specified country.
208 *
209 * @return void.
210 */
211 function countrystates()
212 {
213 $input = JFactory::getApplication()->input;
214
215 /**
216 * Added token validation.
217 *
218 * @since 1.7
219 */
220 if (!JSession::checkToken())
221 {
222 // missing CSRF-proof token
223 UIErrorFactory::raiseError(403, JText::translate('JINVALID_TOKEN'));
224 }
225
226 $id_country = $input->getUint('id_country', 0);
227 $states = VAPLocations::getStates($id_country, 'state_name');
228
229 // send states to caller
230 $this->sendJSON($states);
231 }
232
233 /**
234 * AJAX task used to return the list of cities that
235 * belong to the specified state.
236 *
237 * @return void.
238 */
239 function statecities()
240 {
241 $input = JFactory::getApplication()->input;
242
243 /**
244 * Added token validation.
245 *
246 * @since 1.7
247 */
248 if (!JSession::checkToken())
249 {
250 // missing CSRF-proof token
251 UIErrorFactory::raiseError(403, JText::translate('JINVALID_TOKEN'));
252 }
253
254 $id_state = $input->getUint('id_state', 0);
255 $cities = VAPLocations::getCities($id_state, 'city_name');
256
257 // send cities to caller
258 $this->sendJSON($cities);
259 }
260
261 /**
262 * AJAX end-point used to fetch the availability timeline.
263 * This task expects the following arguments set in request.
264 *
265 * @param integer $id_ser The service ID.
266 * @param integer $id_emp The employee ID.
267 * @param string $day The check-in date.
268 * @param integer $people The number of participants.
269 * @param array $locations A list of selected locations.
270 *
271 * @return void
272 */
273 public function timelineajax()
274 {
275 $input = JFactory::getApplication()->input;
276
277 /**
278 * Added token validation.
279 *
280 * @since 1.7.6
281 */
282 if (!JSession::checkToken())
283 {
284 // missing CSRF-proof token
285 UIErrorFactory::raiseError(403, JText::translate('JINVALID_TOKEN'));
286 }
287
288 $args = array();
289 $args['id_emp'] = $input->getUint('id_emp', 0);
290 $args['id_ser'] = $input->getUint('id_ser', 0);
291 $args['date'] = $input->getString('day', '');
292 $args['people'] = $input->getUint('people', 1);
293 $args['locations'] = $input->getUint('locations', null);
294
295 /**
296 * Auto-remove the expired reservations while checking the
297 * availability through the OPB module too.
298 *
299 * @since 1.7.6
300 */
301 $this->getModel('reservation')->checkExpired(['id_service' => (int) $args['id_ser']]);
302
303 // get model
304 $model = $this->getModel('employeesearch');
305 // use model to create the timeline
306 $timeline = $model->getTimeline($args);
307
308 $result = new stdClass;
309
310 if ($timeline)
311 {
312 // create timeline response
313 $result->timeline = $timeline->getTimeline();
314
315 // recalculate rate by specifing the selected arguments
316 $result->rate = VAPSpecialRates::getRate($args['id_ser'], $args['id_emp'], $args['date'], $args['people']);
317 // multiply by the number of selected participants
318 $result->rate *= $args['people'];
319 }
320 else
321 {
322 // raise error message
323 $result->error = $model->getError($index = null, $string = true);
324 $result->timeline = array();
325 }
326
327 // send timeline to caller
328 $this->sendJSON($result);
329 }
330
331 /**
332 * Changes the preferred currency of the user.
333 *
334 * @return bool
335 *
336 * @since 1.7.6
337 */
338 public function changecurrency()
339 {
340 $app = JFactory::getApplication();
341
342 // fetch the return URL
343 $return = $app->input->getBase64('return');
344
345 // force the specified redirect URL, otherwise land to the home page
346 $this->setRedirect($return ? base64_decode($return) : JUri::root());
347
348 if (!JSession::checkToken())
349 {
350 // missing CSRF-proof token
351 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
352 return false;
353 }
354
355 // fetch selected currency
356 $currency = $app->input->get('currency', '');
357
358 // update the user state of the user
359 $app->setUserState('vikappointments.user.currency', strtoupper(substr($currency, 0, 3)));
360 return true;
361 }
362 }
363