PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / 1.2.17
VikAppointments Services Booking Calendar v1.2.17
trunk 1.2.17 1.2.18 1.2.19
vikappointments / admin / controllers / langoption.php
vikappointments / admin / controllers Last commit date
analytics.php 5 months ago apiban.php 5 months ago apilog.php 5 months ago apiplugin.php 5 months ago apiuser.php 5 months ago backup.php 5 months ago calendar.php 5 months ago city.php 5 months ago closure.php 5 months ago configapp.php 5 months ago configcldays.php 5 months ago configcron.php 5 months ago configemp.php 5 months ago configsmsapi.php 5 months ago configuration.php 5 months ago conversion.php 5 months ago country.php 5 months ago coupon.php 5 months ago coupongroup.php 5 months ago cronjob.php 5 months ago cronjoblog.php 5 months ago customer.php 5 months ago customf.php 5 months ago dashboard.php 5 months ago emplocwdays.php 5 months ago employee.php 5 months ago emprates.php 5 months ago export.php 5 months ago exportres.php 5 months ago file.php 5 months ago findreservation.php 5 months ago group.php 5 months ago import.php 5 months ago index.html 5 months ago invoice.php 5 months ago langcustomf.php 5 months ago langemployee.php 5 months ago langgroup.php 5 months ago langmedia.php 5 months ago langoption.php 5 months ago langoptiongroup.php 5 months ago langpackage.php 5 months ago langpackgroup.php 5 months ago langpayment.php 5 months ago langservice.php 5 months ago langstatuscode.php 5 months ago langsubscr.php 5 months ago langtax.php 5 months ago location.php 5 months ago mailtext.php 5 months ago makerecurrence.php 5 months ago media.php 5 months ago multiorder.php 5 months ago option.php 5 months ago optiongroup.php 5 months ago package.php 5 months ago packgroup.php 5 months ago packorder.php 5 months ago payment.php 5 months ago rate.php 5 months ago reportsemp.php 5 months ago reportsser.php 5 months ago reservation.php 5 months ago restriction.php 5 months ago review.php 5 months ago service.php 5 months ago serworkday.php 5 months ago state.php 5 months ago statuscode.php 5 months ago subscription.php 5 months ago subscrorder.php 5 months ago tag.php 5 months ago tax.php 5 months ago usernote.php 5 months ago waitinglist.php 5 months ago webhook.php 5 months ago wizard.php 5 months ago
langoption.php
297 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 language controller.
18 *
19 * @since 1.7
20 */
21 class VikAppointmentsControllerLangoption 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.langoption.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 $id_option = $app->input->getUint('id_option');
47
48 $this->setRedirect('index.php?option=com_vikappointments&view=managelangoption&id_option=' . $id_option);
49
50 return true;
51 }
52
53 /**
54 * Task used to access the management page of an existing record.
55 *
56 * @return boolean
57 */
58 public function edit()
59 {
60 $app = JFactory::getApplication();
61 $user = JFactory::getUser();
62
63 // unset user state for being recovered again
64 $app->setUserState('vap.langoption.data', array());
65
66 // check user permissions
67 if (!$user->authorise('core.edit', 'com_vikappointments') || !$user->authorise('core.access.options', 'com_vikappointments'))
68 {
69 // back to main list, not authorised to edit records
70 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
71 $this->cancel();
72
73 return false;
74 }
75
76 $cid = $app->input->getUint('cid', array(0));
77
78 $this->setRedirect('index.php?option=com_vikappointments&view=managelangoption&cid[]=' . $cid[0]);
79
80 return true;
81 }
82
83 /**
84 * Task used to save the record data set in the request.
85 * After saving, the user is redirected to the main list.
86 *
87 * @return void
88 */
89 public function saveclose()
90 {
91 if ($this->save())
92 {
93 $this->cancel();
94 }
95 }
96
97 /**
98 * Task used to save the record data set in the request.
99 * After saving, the user is redirected to the creation
100 * page of a new record.
101 *
102 * @return void
103 */
104 public function savenew()
105 {
106 if ($this->save())
107 {
108 $input = JFactory::getApplication()->input;
109
110 $url = 'index.php?option=com_vikappointments&task=langoption.add';
111
112 // recover option ID from request
113 $id_option = $input->getUint('id_option');
114
115 if ($id_option)
116 {
117 $url .= '&id_option=' . $id_option;
118 }
119
120 $this->setRedirect($url);
121 }
122 }
123
124 /**
125 * Task used to save the record data set in the request.
126 * After saving, the user is redirected to the management
127 * page of the record that has been saved.
128 *
129 * @return boolean
130 */
131 public function save()
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->get('name', '', 'string');
153 $args['description'] = JComponentHelper::filterText($input->get('description', '', 'raw'));
154 $args['id'] = $input->get('id', 0, 'uint');
155 $args['id_option'] = $input->get('id_option', 0, 'uint');
156 $args['tag'] = $input->get('tag', '', 'string');
157
158 $rule = 'core.' . ($args['id'] > 0 ? 'edit' : 'create');
159
160 // check user permissions
161 if (!$user->authorise($rule, 'com_vikappointments') || !$user->authorise('core.access.options', 'com_vikappointments'))
162 {
163 // back to main list, not authorised to create/edit records
164 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
165 $this->cancel();
166
167 return false;
168 }
169
170 // get db model
171 $langoption = $this->getModel();
172
173 // try to save arguments
174 $id = $langoption->save($args);
175
176 if (!$id)
177 {
178 // get string error
179 $error = $langoption->getError(null, true);
180
181 // display error message
182 $app->enqueueMessage(JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $error), 'error');
183
184 $url = 'index.php?option=com_vikappointments&view=managelangoption';
185
186 if ($args['id'])
187 {
188 $url .= '&cid[]=' . $args['id'];
189 }
190 else
191 {
192 $url .= '&id_option=' . $args['id_option'];
193 }
194
195 // redirect to new/edit page
196 $this->setRedirect($url);
197
198 return false;
199 }
200
201 // retrieve variations from request
202 $var_id = $input->get('var_id', array(), 'uint');
203 $var_lang_id = $input->get('var_lang_id', array(), 'uint');
204 $var_name = $input->get('var_name', array(), 'string');
205
206 $langvar = $this->getModel('langoptionvar');
207
208 for ($i = 0; $i < count($var_id); $i++)
209 {
210 $src = array();
211 $src['id'] = $var_lang_id[$i];
212 $src['id_variation'] = $var_id[$i];
213 $src['name'] = $var_name[$i];
214 $src['id_parent'] = $id;
215 $src['tag'] = $args['tag'];
216
217 $langvar->save($src);
218 }
219
220 // display generic successful message
221 $app->enqueueMessage(JText::translate('JLIB_APPLICATION_SAVE_SUCCESS'));
222
223 // redirect to edit page
224 $this->setRedirect('index.php?option=com_vikappointments&task=langoption.edit&cid[]=' . $id);
225
226 return true;
227 }
228
229 /**
230 * Deletes a list of records set in the request.
231 *
232 * @return boolean
233 */
234 public function delete()
235 {
236 $app = JFactory::getApplication();
237 $user = JFactory::getUser();
238
239 /**
240 * Added token validation.
241 * Both GET and POST are supported.
242 *
243 * @since 1.7
244 */
245 if (!JSession::checkToken() && !JSession::checkToken('get'))
246 {
247 // back to main list, missing CSRF-proof token
248 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
249 $this->cancel();
250
251 return false;
252 }
253
254 $cid = $app->input->get('cid', array(), 'uint');
255
256 // check user permissions
257 if (!$user->authorise('core.delete', 'com_vikappointments') || !$user->authorise('core.access.options', 'com_vikappointments'))
258 {
259 // back to main list, not authorised to delete records
260 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
261 $this->cancel();
262
263 return false;
264 }
265
266 // delete selected records
267 $this->getModel()->delete($cid);
268
269 // back to main list
270 $this->cancel();
271
272 return true;
273 }
274
275 /**
276 * Redirects the users to the main records list.
277 *
278 * @return void
279 */
280 public function cancel()
281 {
282 $input = JFactory::getApplication()->input;
283
284 // recover option ID from request
285 $id_option = $input->getUint('id_option');
286
287 $url = 'index.php?option=com_vikappointments&view=langoptions';
288
289 if ($id_option)
290 {
291 $url .= '&id_option=' . $id_option;
292 }
293
294 $this->setRedirect($url);
295 }
296 }
297