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