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 / restriction.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
restriction.php
320 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 special restriction controller.
18 *
19 * @since 1.7
20 */
21 class VikAppointmentsControllerRestriction 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.restriction.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 $this->setRedirect('index.php?option=com_vikappointments&view=managerestriction');
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.restriction.data', array());
63
64 // check user permissions
65 if (!$user->authorise('core.edit', 'com_vikappointments') || !$user->authorise('core.access.services', 'com_vikappointments'))
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=managerestriction&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=restriction.add');
107 }
108 }
109
110 /**
111 * Task used to save the record data as a copy of the current item.
112 * After saving, the user is redirected to the management
113 * page of the record that has been saved.
114 *
115 * @return void
116 */
117 public function savecopy()
118 {
119 $this->save(true);
120 }
121
122 /**
123 * Task used to save the record data set in the request.
124 * After saving, the user is redirected to the management
125 * page of the record that has been saved.
126 *
127 * @param boolean $copy True to save the record as a copy.
128 *
129 * @return boolean
130 */
131 public function save($copy = false)
132 {
133 $app = JFactory::getApplication();
134 $input = $app->input;
135 $user = JFactory::getUser();
136
137 /**
138 * Added token validation.
139 *
140 * @since 1.7
141 */
142 if (!JSession::checkToken())
143 {
144 // back to main list, missing CSRF-proof token
145 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
146 $this->cancel();
147
148 return false;
149 }
150
151 $args = array();
152 $args['name'] = $input->getString('name');
153 $args['published'] = $input->getUint('published', 0);
154 $args['maxapp'] = $input->getUint('maxapp', 1);
155 $args['interval'] = $input->getString('interval');
156 $args['mode'] = $input->getUint('mode', 1);
157 $args['usergroups'] = $input->getString('usergroups', array());
158 $args['services'] = $input->getUint('services', array());
159 $args['id'] = $input->getUint('id', 0);
160
161 if ($copy)
162 {
163 // unset ID to create a copy
164 $args['id'] = 0;
165 }
166
167 $rule = 'core.' . ($args['id'] > 0 ? 'edit' : 'create');
168
169 // check user permissions
170 if (!$user->authorise($rule, 'com_vikappointments') || !$user->authorise('core.access.services', 'com_vikappointments'))
171 {
172 // back to main list, not authorised to create/edit records
173 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
174 $this->cancel();
175
176 return false;
177 }
178
179 // get restriction model
180 $restr = $this->getModel();
181
182 // try to save arguments
183 $id = $restr->save($args);
184
185 if (!$id)
186 {
187 // get string error
188 $error = $restr->getError(null, true);
189
190 // display error message
191 $app->enqueueMessage(JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $error), 'error');
192
193 $url = 'index.php?option=com_vikappointments&view=managerestriction';
194
195 if ($args['id'])
196 {
197 $url .= '&cid[]=' . $args['id'];
198 }
199
200 // redirect to new/edit page
201 $this->setRedirect($url);
202
203 return false;
204 }
205
206 // display generic successful message
207 $app->enqueueMessage(JText::translate('JLIB_APPLICATION_SAVE_SUCCESS'));
208
209 // redirect to edit page
210 $this->setRedirect('index.php?option=com_vikappointments&task=restriction.edit&cid[]=' . $id);
211
212 return true;
213 }
214
215 /**
216 * Deletes a list of records set in the request.
217 *
218 * @return boolean
219 */
220 public function delete()
221 {
222 $app = JFactory::getApplication();
223 $user = JFactory::getUser();
224
225 /**
226 * Added token validation.
227 * Both GET and POST are supported.
228 *
229 * @since 1.7
230 */
231 if (!JSession::checkToken() && !JSession::checkToken('get'))
232 {
233 // back to main list, missing CSRF-proof token
234 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
235 $this->cancel();
236
237 return false;
238 }
239
240 $cid = $app->input->get('cid', array(), 'uint');
241
242 // check user permissions
243 if (!$user->authorise('core.delete', 'com_vikappointments') || !$user->authorise('core.access.services', 'com_vikappointments'))
244 {
245 // back to main list, not authorised to delete records
246 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
247 $this->cancel();
248
249 return false;
250 }
251
252 // delete selected records
253 $this->getModel()->delete($cid);
254
255 // back to main list
256 $this->cancel();
257
258 return true;
259 }
260
261 /**
262 * Publishes the selected records.
263 *
264 * @return boolean
265 */
266 public function publish()
267 {
268 $app = JFactory::getApplication();
269 $user = JFactory::getUser();
270
271 /**
272 * Added token validation.
273 * Both GET and POST are supported.
274 *
275 * @since 1.7
276 */
277 if (!JSession::checkToken() && !JSession::checkToken('get'))
278 {
279 // back to main list, missing CSRF-proof token
280 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
281 $this->cancel();
282
283 return false;
284 }
285
286 $cid = $app->input->get('cid', array(), 'uint');
287 $task = $app->input->get('task', null);
288
289 $state = $task == 'unpublish' ? 0 : 1;
290
291 // check user permissions
292 if (!$user->authorise('core.edit.state', 'com_vikappointments') || !$user->authorise('core.access.services', 'com_vikappointments'))
293 {
294 // back to main list, not authorised to edit records
295 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
296 $this->cancel();
297
298 return false;
299 }
300
301 // change state of selected records
302 $this->getModel()->publish($cid, $state);
303
304 // back to main list
305 $this->cancel();
306
307 return true;
308 }
309
310 /**
311 * Redirects the users to the main records list.
312 *
313 * @return void
314 */
315 public function cancel()
316 {
317 $this->setRedirect('index.php?option=com_vikappointments&view=restrictions');
318 }
319 }
320