PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / 1.2.17
VikAppointments Services Booking Calendar v1.2.17
trunk 1.2.17 1.2.18 1.2.19
vikappointments / admin / controllers / serworkday.php
vikappointments / admin / controllers Last commit date
analytics.php 5 months ago apiban.php 5 months ago apilog.php 5 months ago apiplugin.php 5 months ago apiuser.php 5 months ago backup.php 5 months ago calendar.php 5 months ago city.php 5 months ago closure.php 5 months ago configapp.php 5 months ago configcldays.php 5 months ago configcron.php 5 months ago configemp.php 5 months ago configsmsapi.php 5 months ago configuration.php 5 months ago conversion.php 5 months ago country.php 5 months ago coupon.php 5 months ago coupongroup.php 5 months ago cronjob.php 5 months ago cronjoblog.php 5 months ago customer.php 5 months ago customf.php 5 months ago dashboard.php 5 months ago emplocwdays.php 5 months ago employee.php 5 months ago emprates.php 5 months ago export.php 5 months ago exportres.php 5 months ago file.php 5 months ago findreservation.php 5 months ago group.php 5 months ago import.php 5 months ago index.html 5 months ago invoice.php 5 months ago langcustomf.php 5 months ago langemployee.php 5 months ago langgroup.php 5 months ago langmedia.php 5 months ago langoption.php 5 months ago langoptiongroup.php 5 months ago langpackage.php 5 months ago langpackgroup.php 5 months ago langpayment.php 5 months ago langservice.php 5 months ago langstatuscode.php 5 months ago langsubscr.php 5 months ago langtax.php 5 months ago location.php 5 months ago mailtext.php 5 months ago makerecurrence.php 5 months ago media.php 5 months ago multiorder.php 5 months ago option.php 5 months ago optiongroup.php 5 months ago package.php 5 months ago packgroup.php 5 months ago packorder.php 5 months ago payment.php 5 months ago rate.php 5 months ago reportsemp.php 5 months ago reportsser.php 5 months ago reservation.php 5 months ago restriction.php 5 months ago review.php 5 months ago service.php 5 months ago serworkday.php 5 months ago state.php 5 months ago statuscode.php 5 months ago subscription.php 5 months ago subscrorder.php 5 months ago tag.php 5 months ago tax.php 5 months ago usernote.php 5 months ago waitinglist.php 5 months ago webhook.php 5 months ago wizard.php 5 months ago
serworkday.php
373 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 service working days controller.
18 *
19 * @since 1.7
20 */
21 class VikAppointmentsControllerSerworkday 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.serworkday.data', array());
35
36 // check user permissions
37 if (!$user->authorise('core.create', 'com_vikappointments') || !$user->authorise('core.access.services', 'com_vikappointments'))
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 $url = 'index.php?option=com_vikappointments&view=manageserworkday';
47
48 $id_service = $app->input->getUint('id_service', 0);
49 $id_employee = $app->input->getUint('id_employee', 0);
50
51 $url .= '&id_service=' . $id_service;
52 $url .= '&id_employee=' . $id_employee;
53
54 $this->setRedirect($url);
55
56 return true;
57 }
58
59 /**
60 * Task used to access the management page of an existing record.
61 *
62 * @return boolean
63 */
64 public function edit()
65 {
66 $app = JFactory::getApplication();
67 $user = JFactory::getUser();
68
69 // unset user state for being recovered again
70 $app->setUserState('vap.serworkday.data', array());
71
72 // check user permissions
73 if (!$user->authorise('core.edit', 'com_vikappointments') || !$user->authorise('core.access.services', 'com_vikappointments'))
74 {
75 // back to main list, not authorised to edit records
76 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
77 $this->cancel();
78
79 return false;
80 }
81
82 $cid = $app->input->getUint('cid', array(0));
83
84 $url = 'index.php?option=com_vikappointments&view=manageserworkday&cid[]=' . $cid[0];
85
86 $this->setRedirect($url);
87
88 return true;
89 }
90
91 /**
92 * Task used to save the record data set in the request.
93 * After saving, the user is redirected to the main list.
94 *
95 * @return void
96 */
97 public function saveclose()
98 {
99 if ($this->save())
100 {
101 $this->cancel();
102 }
103 }
104
105 /**
106 * Task used to save the record data set in the request.
107 * After saving, the user is redirected to the creation
108 * page of a new record.
109 *
110 * @return void
111 */
112 public function savenew()
113 {
114 if ($this->save())
115 {
116 $url = 'index.php?option=com_vikappointments&task=serworkday.add';
117
118 $id_service = $app->input->getUint('id_service', 0);
119 $id_employee = $app->input->getUint('id_employee', 0);
120
121 $url .= '&id_service=' . $id_service;
122 $url .= '&id_employee=' . $id_employee;
123
124 $this->setRedirect($url);
125 }
126 }
127
128 /**
129 * Task used to save the record data as a copy of the current item.
130 * After saving, the user is redirected to the management
131 * page of the record that has been saved.
132 *
133 * @return void
134 */
135 public function savecopy()
136 {
137 $this->save(true);
138 }
139
140 /**
141 * Task used to save the record data set in the request.
142 * After saving, the user is redirected to the management
143 * page of the record that has been saved.
144 *
145 * @param boolean $copy True to save the record as a copy.
146 *
147 * @return boolean
148 */
149 public function save($copy = false)
150 {
151 $app = JFactory::getApplication();
152 $input = $app->input;
153 $user = JFactory::getUser();
154
155 /**
156 * Added token validation.
157 *
158 * @since 1.7
159 */
160 if (!JSession::checkToken())
161 {
162 // back to main list, missing CSRF-proof token
163 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
164 $this->cancel();
165
166 return false;
167 }
168
169 $id_employee = $input->getUint('id_employee', 0);
170
171 $args = array();
172 $args['id_service'] = $input->getUint('id_service', 0);
173 $args['id_employee'] = $input->getUint('id_employee', 0);
174 $args['day'] = $input->getInt('day', 0);
175 $args['fromts'] = $input->getUint('fromts', 0);
176 $args['endts'] = $input->getUint('endts', 0);
177 $args['closed'] = $input->getUint('closed', 0);
178 $args['id_location'] = $input->getUint('id_location', 0);
179 $args['id'] = $input->getUint('id', 0);
180
181 if ($args['day'] == -1)
182 {
183 $args['date'] = $input->getString('date', '');
184 }
185
186 if ($copy)
187 {
188 // unset ID to create a copy
189 $args['id'] = 0;
190 }
191
192 // always unset parent, because we don't want to
193 // keep a relation with the original working day
194 $args['parent'] = -1;
195
196 $rule = 'core.' . ($args['id'] > 0 ? 'edit' : 'create');
197
198 // check user permissions
199 if (!$user->authorise($rule, 'com_vikappointments') || !$user->authorise('core.access.services', 'com_vikappointments'))
200 {
201 // back to main list, not authorised to create/edit records
202 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
203 $this->cancel();
204
205 return false;
206 }
207
208 // get worktime model
209 $model = $this->getModel('worktime');
210
211 // try to save arguments
212 $id = $model->save($args);
213
214 if (!$id)
215 {
216 // get string error
217 $error = $model->getError(null, true);
218
219 // display error message
220 $app->enqueueMessage(JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $error), 'error');
221
222 $url = 'index.php?option=com_vikappointments&view=manageserworkday';
223
224 if ($args['id'])
225 {
226 $url .= '&cid[]=' . $args['id'];
227 }
228 else
229 {
230 $url .= '&id_service=' . $args['id_service'];
231 $url .= '&id_employee=' . $args['id_employee'];
232 }
233
234 // redirect to new/edit page
235 $this->setRedirect($url);
236
237 return false;
238 }
239
240 // display generic successful message
241 $app->enqueueMessage(JText::translate('JLIB_APPLICATION_SAVE_SUCCESS'));
242
243 $url = 'index.php?option=com_vikappointments&task=serworkday.edit&cid[]=' . $id;
244
245 // redirect to edit page
246 $this->setRedirect($url);
247
248 return true;
249 }
250
251 /**
252 * Deletes a list of records set in the request.
253 *
254 * @return boolean
255 */
256 public function delete()
257 {
258 $app = JFactory::getApplication();
259 $user = JFactory::getUser();
260
261 /**
262 * Added token validation.
263 * Both GET and POST are supported.
264 *
265 * @since 1.7
266 */
267 if (!JSession::checkToken() && !JSession::checkToken('get'))
268 {
269 // back to main list, missing CSRF-proof token
270 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
271 $this->cancel();
272
273 return false;
274 }
275
276 $cid = $app->input->get('cid', array(), 'uint');
277
278 // check user permissions
279 if (!$user->authorise('core.delete', 'com_vikappointments') || !$user->authorise('core.access.services', 'com_vikappointments'))
280 {
281 // back to main list, not authorised to delete records
282 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
283 $this->cancel();
284
285 return false;
286 }
287
288 // delete selected records
289 $this->getModel('worktime')->delete($cid);
290
291 // back to main list
292 $this->cancel();
293
294 return true;
295 }
296
297 /**
298 * Deletes a list of records set in the request.
299 *
300 * @return boolean
301 */
302 public function restore()
303 {
304 $app = JFactory::getApplication();
305 $user = JFactory::getUser();
306
307 /**
308 * Added token validation.
309 * Both GET and POST are supported.
310 *
311 * @since 1.7
312 */
313 if (!JSession::checkToken() && !JSession::checkToken('get'))
314 {
315 // back to main list, missing CSRF-proof token
316 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
317 $this->cancel();
318
319 return false;
320 }
321
322 // check user permissions
323 if (!$user->authorise('core.delete', 'com_vikappointments') || !$user->authorise('core.access.services', 'com_vikappointments'))
324 {
325 // back to main list, not authorised to delete records
326 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
327 $this->cancel();
328
329 return false;
330 }
331
332 $id_service = $app->input->get('id_service', 0, 'uint');
333 $id_employee = $app->input->get('id_employee', 0, 'uint');
334
335 // delete selected records
336 $restored = $this->getModel('worktime')->restore($id_service, $id_employee);
337
338 if ($restored)
339 {
340 $app->enqueueMessage(JText::translate('VAPSERWORKDAYSRESTORED1'));
341 }
342 else
343 {
344 $app->enqueueMessage(JText::translate('VAPSERWORKDAYSRESTORED0'), 'warning');
345 }
346
347 // back to main list
348 $this->cancel();
349
350 return true;
351 }
352
353 /**
354 * Redirects the users to the main records list.
355 *
356 * @return void
357 */
358 public function cancel()
359 {
360 $input = JFactory::getApplication()->input;
361
362 $id_service = $input->getUint('id_service', 0);
363 $id_employee = $input->getUint('id_employee', 0);
364
365 $url = 'index.php?option=com_vikappointments&view=serworkdays';
366
367 $url .= '&id_service=' . $id_service;
368 $url .= '&id_employee=' . $id_employee;
369
370 $this->setRedirect($url);
371 }
372 }
373