PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / trunk
VikAppointments Services Booking Calendar vtrunk
trunk 1.2.17 1.2.18 1.2.19
vikappointments / admin / controllers / serworkday.php
vikappointments / admin / controllers Last commit date
analytics.php 4 years ago apiban.php 4 years ago apilog.php 4 years ago apiplugin.php 4 years ago apiuser.php 4 years ago backup.php 4 years ago calendar.php 4 years ago city.php 4 years ago closure.php 1 month ago configapp.php 4 years ago configcldays.php 2 years ago configcron.php 4 years ago configemp.php 4 years ago configsmsapi.php 4 years ago configuration.php 1 month ago conversion.php 1 year ago country.php 4 years ago coupon.php 4 years ago coupongroup.php 4 years ago cronjob.php 2 years ago cronjoblog.php 4 years ago customer.php 5 months ago customf.php 1 year ago dashboard.php 4 years ago emplocwdays.php 4 years ago employee.php 1 year ago emprates.php 4 years ago export.php 4 years ago exportres.php 4 years ago file.php 5 months ago findreservation.php 1 month ago group.php 4 years ago import.php 4 years ago index.html 4 years ago invoice.php 1 month ago langcustomf.php 4 years ago langemployee.php 4 years ago langgroup.php 4 years ago langmedia.php 4 years ago langoption.php 4 years ago langoptiongroup.php 4 years ago langpackage.php 4 years ago langpackgroup.php 4 years ago langpayment.php 4 years ago langservice.php 4 years ago langstatuscode.php 4 years ago langsubscr.php 4 years ago langtax.php 4 years ago location.php 4 years ago mailtext.php 2 years ago makerecurrence.php 1 month ago media.php 4 years ago multiorder.php 4 years ago option.php 5 months ago optiongroup.php 4 years ago package.php 2 years ago packgroup.php 4 years ago packorder.php 1 year ago payment.php 4 years ago rate.php 4 years ago reportsemp.php 4 years ago reportsser.php 4 years ago reservation.php 1 month ago restriction.php 4 years ago review.php 4 years ago service.php 1 year ago serworkday.php 5 months ago state.php 4 years ago statuscode.php 4 years ago subscription.php 4 years ago subscrorder.php 4 years ago tag.php 4 years ago tax.php 4 years ago usernote.php 4 years ago waitinglist.php 4 years ago webhook.php 4 years ago wizard.php 1 year 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