PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / trunk
VikAppointments Services Booking Calendar vtrunk
trunk 1.2.17 1.2.18 1.2.19
vikappointments / admin / controllers / group.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
group.php
321 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 group controller.
18 *
19 * @since 1.7
20 */
21 class VikAppointmentsControllerGroup 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.group.data', array());
35
36 // check user permissions
37 if (!$user->authorise('core.create', 'com_vikappointments') || !$user->authorise('core.access.groups', '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 // extract page type from request:
47 // - 1 for services (default)
48 // - 2 for employees
49 $pagetype = $app->input->get('type', 1, 'uint');
50
51 $this->setRedirect('index.php?option=com_vikappointments&view=managegroup&type=' . $pagetype);
52
53 return true;
54 }
55
56 /**
57 * Task used to access the management page of an existing record.
58 *
59 * @return boolean
60 */
61 public function edit()
62 {
63 $app = JFactory::getApplication();
64 $user = JFactory::getUser();
65
66 // unset user state for being recovered again
67 $app->setUserState('vap.group.data', array());
68
69 // check user permissions
70 if (!$user->authorise('core.edit', 'com_vikappointments') || !$user->authorise('core.access.groups', 'com_vikappointments'))
71 {
72 // back to main list, not authorised to edit records
73 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
74 $this->cancel();
75
76 return false;
77 }
78
79 $cid = $app->input->getUint('cid', array(0));
80
81 // extract page type from request:
82 // - 1 for services (default)
83 // - 2 for employees
84 $pagetype = $app->input->get('type', 1, 'uint');
85
86 $this->setRedirect('index.php?option=com_vikappointments&view=managegroup&cid[]=' . $cid[0] . '&type=' . $pagetype);
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 $input = JFactory::getApplication()->input;
117
118 // extract page type from request:
119 // - 1 for services (default)
120 // - 2 for employees
121 $type = $input->get('type', 1, 'uint');
122
123 $this->setRedirect('index.php?option=com_vikappointments&task=group.add&type=' . $type);
124 }
125 }
126
127 /**
128 * Task used to save the record data as a copy of the current item.
129 * After saving, the user is redirected to the management
130 * page of the record that has been saved.
131 *
132 * @return void
133 */
134 public function savecopy()
135 {
136 $this->save(true);
137 }
138
139 /**
140 * Task used to save the record data set in the request.
141 * After saving, the user is redirected to the management
142 * page of the record that has been saved.
143 *
144 * @param boolean $copy True to save the record as a copy.
145 *
146 * @return boolean
147 */
148 public function save($copy = false)
149 {
150 $app = JFactory::getApplication();
151 $input = $app->input;
152 $user = JFactory::getUser();
153
154 /**
155 * Added token validation.
156 *
157 * @since 1.7
158 */
159 if (!JSession::checkToken())
160 {
161 // back to main list, missing CSRF-proof token
162 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
163 $this->cancel();
164
165 return false;
166 }
167
168 $args = array();
169 $args['name'] = $input->getString('name');
170 $args['description'] = JComponentHelper::filterText($input->get('description', '', 'raw'));
171 $args['id'] = $input->getUint('id', 0);
172
173 if ($copy)
174 {
175 // unset ID to create a copy
176 $args['id'] = 0;
177 }
178
179 $rule = 'core.' . ($args['id'] > 0 ? 'edit' : 'create');
180
181 // check user permissions
182 if (!$user->authorise($rule, 'com_vikappointments') || !$user->authorise('core.access.groups', 'com_vikappointments'))
183 {
184 // back to main list, not authorised to create/edit records
185 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
186 $this->cancel();
187
188 return false;
189 }
190
191 // extract page type from request:
192 // - 1 for services (default)
193 // - 2 for employees
194 $pagetype = $input->get('type', 1, 'uint');
195
196 // get db model
197 $group = $this->getGroupModel($pagetype);
198
199 // try to save arguments
200 $id = $group->save($args);
201
202 if (!$id)
203 {
204 // get string error
205 $error = $group->getError(null, true);
206
207 // display error message
208 $app->enqueueMessage(JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $error), 'error');
209
210 $url = 'index.php?option=com_vikappointments&view=managegroup&type=' . $pagetype;
211
212 if ($args['id'])
213 {
214 $url .= '&cid[]=' . $args['id'];
215 }
216
217 // redirect to new/edit page
218 $this->setRedirect($url);
219
220 return false;
221 }
222
223 // display generic successful message
224 $app->enqueueMessage(JText::translate('JLIB_APPLICATION_SAVE_SUCCESS'));
225
226 // redirect to edit page
227 $this->setRedirect('index.php?option=com_vikappointments&task=group.edit&cid[]=' . $id . '&type=' . $pagetype);
228
229 return true;
230 }
231
232 /**
233 * Deletes a list of records set in the request.
234 *
235 * @return boolean
236 */
237 public function delete()
238 {
239 $app = JFactory::getApplication();
240 $user = JFactory::getUser();
241
242 /**
243 * Added token validation.
244 * Both GET and POST are supported.
245 *
246 * @since 1.7
247 */
248 if (!JSession::checkToken() && !JSession::checkToken('get'))
249 {
250 // back to main list, missing CSRF-proof token
251 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
252 $this->cancel();
253
254 return false;
255 }
256
257 $cid = $app->input->get('cid', array(), 'uint');
258
259 // check user permissions
260 if (!$user->authorise('core.delete', 'com_vikappointments') || !$user->authorise('core.access.groups', 'com_vikappointments'))
261 {
262 // back to main list, not authorised to delete records
263 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
264 $this->cancel();
265
266 return false;
267 }
268
269 // delete selected records
270 $this->getGroupModel()->delete($cid);
271
272 // back to main list
273 $this->cancel();
274
275 return true;
276 }
277
278 /**
279 * Redirects the users to the main records list.
280 *
281 * @return void
282 */
283 public function cancel()
284 {
285 $input = JFactory::getApplication()->input;
286
287 // extract page type from request:
288 // - 1 for services (default)
289 // - 2 for employees
290 $type = $input->get('type', 1, 'uint');
291
292 $this->setRedirect('index.php?option=com_vikappointments&view=groups&type=' . $type);
293 }
294
295 /**
296 * Creates the correct database model.
297 *
298 * @param mixed $type An optional page type. If not specified,
299 * it will be retrieved from the request.
300 *
301 * @return JModel
302 */
303 protected function getGroupModel($type = null)
304 {
305 if (!$type)
306 {
307 $input = JFactory::getApplication()->input;
308
309 // extract page type from request:
310 // - 1 for services (default)
311 // - 2 for employees
312 $type = $input->get('type', 1, 'uint');
313 }
314
315 // use correct model according to the specified page type
316 $tbl = $type == 1 ? 'group' : 'empgroup';
317
318 return $this->getModel($tbl);
319 }
320 }
321