PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / trunk
VikAppointments Services Booking Calendar vtrunk
trunk 1.2.17 1.2.18 1.2.19
vikappointments / admin / controllers / customf.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 4 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 4 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 4 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 4 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
customf.php
415 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 VAPLoader::import('libraries.customfields.factory');
16
17 /**
18 * VikAppointments custom field controller.
19 *
20 * @since 1.7
21 */
22 class VikAppointmentsControllerCustomf extends VAPControllerAdmin
23 {
24 /**
25 * Task used to access the creation page of a new record.
26 *
27 * @return boolean
28 */
29 public function add()
30 {
31 $app = JFactory::getApplication();
32 $user = JFactory::getUser();
33
34 $data = array();
35 $group = $app->input->getUint('group', null);
36
37 if (!is_null($group))
38 {
39 $data['group'] = $group;
40 }
41
42 // unset user state for being recovered again
43 $app->setUserState('vap.customf.data', $data);
44
45 // check user permissions
46 if (!$user->authorise('core.create', 'com_vikappointments') || !$user->authorise('core.access.custfields', 'com_vikappointments'))
47 {
48 // back to main list, not authorised to create records
49 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
50 $this->cancel();
51
52 return false;
53 }
54
55 $this->setRedirect('index.php?option=com_vikappointments&view=managecustomf');
56
57 return true;
58 }
59
60 /**
61 * Task used to access the management page of an existing record.
62 *
63 * @return boolean
64 */
65 public function edit()
66 {
67 $app = JFactory::getApplication();
68 $user = JFactory::getUser();
69
70 // unset user state for being recovered again
71 $app->setUserState('vap.customf.data', array());
72
73 // check user permissions
74 if (!$user->authorise('core.edit', 'com_vikappointments') || !$user->authorise('core.access.custfields', 'com_vikappointments'))
75 {
76 // back to main list, not authorised to edit records
77 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
78 $this->cancel();
79
80 return false;
81 }
82
83 $cid = $app->input->getUint('cid', array(0));
84
85 $this->setRedirect('index.php?option=com_vikappointments&view=managecustomf&cid[]=' . $cid[0]);
86
87 return true;
88 }
89
90 /**
91 * Task used to save the record data set in the request.
92 * After saving, the user is redirected to the main list.
93 *
94 * @return void
95 */
96 public function saveclose()
97 {
98 if ($this->save())
99 {
100 $this->cancel();
101 }
102 }
103
104 /**
105 * Task used to save the record data set in the request.
106 * After saving, the user is redirected to the creation
107 * page of a new record.
108 *
109 * @return void
110 */
111 public function savenew()
112 {
113 if ($this->save())
114 {
115 $input = JFactory::getApplication()->input;
116
117 $url = 'index.php?option=com_vikappointments&task=customf.add';
118
119 $group = $input->getUint('group', null);
120
121 if (!is_null($group))
122 {
123 // preserve group for the next record
124 $url .= '&group=' . $group;
125 }
126
127 $this->setRedirect($url);
128 }
129 }
130
131 /**
132 * Task used to save the record data set in the request.
133 * After saving, the user is redirected to the management
134 * page of the record that has been saved.
135 *
136 * @return boolean
137 */
138 public function save()
139 {
140 $app = JFactory::getApplication();
141 $input = $app->input;
142 $user = JFactory::getUser();
143
144 /**
145 * Added token validation.
146 *
147 * @since 1.7
148 */
149 if (!JSession::checkToken())
150 {
151 // back to main list, missing CSRF-proof token
152 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
153 $this->cancel();
154
155 return false;
156 }
157
158 $args = array();
159 $args['group'] = $input->getUint('group', 0);
160 $args['name'] = $input->getString('name', '');
161 $args['description'] = JComponentHelper::filterText($input->getRaw('description', ''));
162 $args['type'] = $input->getString('type', '');
163 $args['required'] = $input->getUint('required', 0);
164 $args['repeat'] = $input->getUint('repeat', 0);
165 $args['readonly'] = $input->getUint('readonly', 0);
166 $args['page'] = $input->getString('page', '*');
167 $args['rule'] = $input->getString('rule', '');
168 $args['locale'] = $input->getString('locale', '*');
169 $args['multiple'] = 0;
170 $args['poplink'] = '';
171 $args['choose'] = '';
172 $args['id'] = $input->getUint('id', 0);
173
174 if ($args['group'] == 0)
175 {
176 // customers group
177 $args['id_employee'] = $input->getUint('id_employee', 0);
178 $args['services'] = $input->getUint('services', array());
179 }
180 else if ($args['group'] == 1)
181 {
182 // employees group
183 $args['formname'] = $input->getString('formname', null);
184 }
185
186 if ($args['type'] == 'select')
187 {
188 /**
189 * Do not use a string filter so that we can preserve the keys
190 * of the options. Use array_filter instead to get rid of the
191 * options with blank contents.
192 *
193 * @since 1.7
194 */
195 $args['choose'] = array_filter($input->get('choose', array(), 'array'));
196 $args['multiple'] = $input->getUint('multiple', 0);
197 }
198 else if ($args['type'] == 'textarea')
199 {
200 $args['choose'] = array(
201 'editor' => $input->getUint('use_editor', 0),
202 );
203 }
204 else if ($args['type'] == 'number')
205 {
206 $args['choose'] = array(
207 'min' => $input->getString('number_min', ''),
208 'max' => $input->getString('number_max', ''),
209 'decimals' => $input->getUint('number_decimals', 0),
210 );
211
212 if (strlen($args['choose']['min']))
213 {
214 $args['choose']['min'] = (float) $args['choose']['min'];
215 }
216
217 if (strlen($args['choose']['max']))
218 {
219 $args['choose']['max'] = (float) $args['choose']['max'];
220 }
221 }
222 else if ($args['type'] == 'checkbox')
223 {
224 $args['poplink'] = $input->getString('poplink', '');
225 }
226 else if ($args['type'] == 'file')
227 {
228 $args['choose'] = $input->getString('filters', '');
229 $args['multiple'] = $input->getUint('multiple', 0);
230 }
231 else if ($args['type'] == 'separator')
232 {
233 $args['choose'] = $input->getString('sep_suffix', '');
234 }
235
236 if ($args['rule'] == 'phone')
237 {
238 $args['choose'] = $input->getString('country_code', '');
239 }
240
241 $rule = 'core.' . ($args['id'] > 0 ? 'edit' : 'create');
242
243 // check user permissions
244 if (!$user->authorise($rule, 'com_vikappointments') || !$user->authorise('core.access.custfields', 'com_vikappointments'))
245 {
246 // back to main list, not authorised to create/edit records
247 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
248 $this->cancel();
249
250 return false;
251 }
252
253 // get custom field model
254 $customf = $this->getModel();
255
256 // try to save arguments
257 $id = $customf->save($args);
258
259 if (!$id)
260 {
261 // get string error
262 $error = $customf->getError(null, true);
263
264 // display error message
265 $app->enqueueMessage(JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $error), 'error');
266
267 $url = 'index.php?option=com_vikappointments&view=managecustomf';
268
269 if ($args['id'])
270 {
271 $url .= '&cid[]=' . $args['id'];
272 }
273
274 // redirect to new/edit page
275 $this->setRedirect($url);
276
277 return false;
278 }
279
280 // display generic successful message
281 $app->enqueueMessage(JText::translate('JLIB_APPLICATION_SAVE_SUCCESS'));
282
283 // try to obtain an error, because the model might register
284 // an error message also in case of successful saving
285 $error = $customf->getError(null, true);
286
287 if ($error)
288 {
289 $app->enqueueMessage($error, 'error');
290 }
291
292 // redirect to edit page
293 $this->setRedirect('index.php?option=com_vikappointments&task=customf.edit&cid[]=' . $id);
294
295 return true;
296 }
297
298 /**
299 * Deletes a list of records set in the request.
300 *
301 * @return boolean
302 */
303 public function delete()
304 {
305 $app = JFactory::getApplication();
306 $user = JFactory::getUser();
307
308 /**
309 * Added token validation.
310 * Both GET and POST are supported.
311 *
312 * @since 1.7
313 */
314 if (!JSession::checkToken() && !JSession::checkToken('get'))
315 {
316 // back to main list, missing CSRF-proof token
317 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
318 $this->cancel();
319
320 return false;
321 }
322
323 $cid = $app->input->get('cid', array(), 'uint');
324
325 // check user permissions
326 if (!$user->authorise('core.delete', 'com_vikappointments') || !$user->authorise('core.access.custfields', 'com_vikappointments'))
327 {
328 // back to main list, not authorised to delete records
329 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
330 $this->cancel();
331
332 return false;
333 }
334
335 // delete selected records
336 $this->getModel()->delete($cid);
337
338 // back to main list
339 $this->cancel();
340
341 return true;
342 }
343
344 /**
345 * Toggles the required/optional status of an option.
346 *
347 * @return boolean
348 */
349 public function required()
350 {
351 $app = JFactory::getApplication();
352 $user = JFactory::getUser();
353
354 /**
355 * Added token validation.
356 * Both GET and POST are supported.
357 *
358 * @since 1.7
359 */
360 if (!JSession::checkToken() && !JSession::checkToken('get'))
361 {
362 // back to main list, missing CSRF-proof token
363 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
364 $this->cancel();
365
366 return false;
367 }
368
369 $cid = $app->input->get('cid', array(), 'uint');
370 $task = $app->input->get('task', null);
371
372 $state = $app->input->get('state', 0, 'uint');
373
374 // check user permissions
375 if (!$user->authorise('core.edit.state', 'com_vikappointments') || !$user->authorise('core.access.custfields', 'com_vikappointments'))
376 {
377 // back to main list, not authorised to edit records
378 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
379 $this->cancel();
380
381 return false;
382 }
383
384 // change state of selected records
385 $this->getModel()->publish($cid, $state, 'required');
386
387 // back to main list
388 $this->cancel();
389
390 return true;
391 }
392
393 /**
394 * Redirects the users to the main records list.
395 *
396 * @return void
397 */
398 public function cancel()
399 {
400 $input = JFactory::getApplication()->input;
401
402 $url = 'index.php?option=com_vikappointments&view=customf';
403
404 $group = $input->getUint('group', null);
405
406 if (!is_null($group))
407 {
408 // preserve group to change list filtering
409 $url .= '&group=' . $group;
410 }
411
412 $this->setRedirect($url);
413 }
414 }
415