PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / trunk
VikAppointments Services Booking Calendar vtrunk
trunk 1.2.17 1.2.18 1.2.19
vikappointments / admin / controllers / optiongroup.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
optiongroup.php
246 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 option group controller.
18 *
19 * @since 1.7
20 */
21 class VikAppointmentsControllerOptiongroup 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.optiongroup.data', array());
35
36 // check user permissions
37 if (!$user->authorise('core.create', 'com_vikappointments') || !$user->authorise('core.access.options', '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=manageoptiongroup');
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.optiongroup.data', array());
63
64 // check user permissions
65 if (!$user->authorise('core.edit', 'com_vikappointments') || !$user->authorise('core.access.options', '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=manageoptiongroup&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=optiongroup.add');
107 }
108 }
109
110 /**
111 * Task used to save the record data set in the request.
112 * After saving, the user is redirected to the management
113 * page of the record that has been saved.
114 *
115 * @return boolean
116 */
117 public function save()
118 {
119 $app = JFactory::getApplication();
120 $input = $app->input;
121 $user = JFactory::getUser();
122
123 /**
124 * Added token validation.
125 *
126 * @since 1.7
127 */
128 if (!JSession::checkToken())
129 {
130 // back to main list, missing CSRF-proof token
131 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
132 $this->cancel();
133
134 return false;
135 }
136
137 $args = array();
138 $args['name'] = $input->getString('name');
139 $args['description'] = JComponentHelper::filterText($input->get('description', '', 'raw'));
140 $args['id'] = $input->getUint('id', 0);
141
142 $rule = 'core.' . ($args['id'] > 0 ? 'edit' : 'create');
143
144 // check user permissions
145 if (!$user->authorise($rule, 'com_vikappointments') || !$user->authorise('core.access.options', 'com_vikappointments'))
146 {
147 // back to main list, not authorised to create/edit records
148 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
149 $this->cancel();
150
151 return false;
152 }
153
154 // get db model
155 $group = $this->getModel();
156
157 // try to save arguments
158 $id = $group->save($args);
159
160 if (!$id)
161 {
162 // get string error
163 $error = $group->getError(null, true);
164
165 // display error message
166 $app->enqueueMessage(JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $error), 'error');
167
168 $url = 'index.php?option=com_vikappointments&view=manageoptiongroup';
169
170 if ($args['id'])
171 {
172 $url .= '&cid[]=' . $args['id'];
173 }
174
175 // redirect to new/edit page
176 $this->setRedirect($url);
177
178 return false;
179 }
180
181 // display generic successful message
182 $app->enqueueMessage(JText::translate('JLIB_APPLICATION_SAVE_SUCCESS'));
183
184 // redirect to edit page
185 $this->setRedirect('index.php?option=com_vikappointments&task=optiongroup.edit&cid[]=' . $id);
186
187 return true;
188 }
189
190 /**
191 * Deletes a list of records set in the request.
192 *
193 * @return boolean
194 */
195 public function delete()
196 {
197 $app = JFactory::getApplication();
198 $user = JFactory::getUser();
199
200 /**
201 * Added token validation.
202 * Both GET and POST are supported.
203 *
204 * @since 1.7
205 */
206 if (!JSession::checkToken() && !JSession::checkToken('get'))
207 {
208 // back to main list, missing CSRF-proof token
209 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
210 $this->cancel();
211
212 return false;
213 }
214
215 $cid = $app->input->get('cid', array(), 'uint');
216
217 // check user permissions
218 if (!$user->authorise('core.delete', 'com_vikappointments') || !$user->authorise('core.access.options', 'com_vikappointments'))
219 {
220 // back to main list, not authorised to delete records
221 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
222 $this->cancel();
223
224 return false;
225 }
226
227 // delete selected records
228 $this->getModel()->delete($cid);
229
230 // back to main list
231 $this->cancel();
232
233 return true;
234 }
235
236 /**
237 * Redirects the users to the main records list.
238 *
239 * @return void
240 */
241 public function cancel()
242 {
243 $this->setRedirect('index.php?option=com_vikappointments&view=optiongroups');
244 }
245 }
246