PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / 1.2.17
VikAppointments Services Booking Calendar v1.2.17
1.2.21 1.2.20 trunk 1.2.17 1.2.18 1.2.19
vikappointments / admin / controllers / langtax.php
vikappointments / admin / controllers Last commit date
analytics.php 6 months ago apiban.php 6 months ago apilog.php 6 months ago apiplugin.php 6 months ago apiuser.php 6 months ago backup.php 6 months ago calendar.php 6 months ago city.php 6 months ago closure.php 6 months ago configapp.php 6 months ago configcldays.php 6 months ago configcron.php 6 months ago configemp.php 6 months ago configsmsapi.php 6 months ago configuration.php 6 months ago conversion.php 6 months ago country.php 6 months ago coupon.php 6 months ago coupongroup.php 6 months ago cronjob.php 6 months ago cronjoblog.php 6 months ago customer.php 6 months ago customf.php 6 months ago dashboard.php 6 months ago emplocwdays.php 6 months ago employee.php 6 months ago emprates.php 6 months ago export.php 6 months ago exportres.php 6 months ago file.php 6 months ago findreservation.php 6 months ago group.php 6 months ago import.php 6 months ago index.html 6 months ago invoice.php 6 months ago langcustomf.php 6 months ago langemployee.php 6 months ago langgroup.php 6 months ago langmedia.php 6 months ago langoption.php 6 months ago langoptiongroup.php 6 months ago langpackage.php 6 months ago langpackgroup.php 6 months ago langpayment.php 6 months ago langservice.php 6 months ago langstatuscode.php 6 months ago langsubscr.php 6 months ago langtax.php 6 months ago location.php 6 months ago mailtext.php 6 months ago makerecurrence.php 6 months ago media.php 6 months ago multiorder.php 6 months ago option.php 6 months ago optiongroup.php 6 months ago package.php 6 months ago packgroup.php 6 months ago packorder.php 6 months ago payment.php 6 months ago rate.php 6 months ago reportsemp.php 6 months ago reportsser.php 6 months ago reservation.php 6 months ago restriction.php 6 months ago review.php 6 months ago service.php 6 months ago serworkday.php 6 months ago state.php 6 months ago statuscode.php 6 months ago subscription.php 6 months ago subscrorder.php 6 months ago tag.php 6 months ago tax.php 6 months ago usernote.php 6 months ago waitinglist.php 6 months ago webhook.php 6 months ago wizard.php 6 months ago
langtax.php
303 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 tax language controller.
18 *
19 * @since 1.7
20 */
21 class VikAppointmentsControllerLangtax 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.langtax.data', array());
35
36 // check user permissions
37 if (!$user->authorise('core.create', 'com_vikappointments') || !$user->authorise('core.access.taxes', '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_tax = $app->input->getUint('id_tax');
47
48 $this->setRedirect('index.php?option=com_vikappointments&view=managelangtax&id_tax=' . $id_tax);
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.langtax.data', array());
65
66 // check user permissions
67 if (!$user->authorise('core.edit', 'com_vikappointments') || !$user->authorise('core.access.taxes', '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=managelangtax&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=langtax.add';
111
112 // recover option ID from request
113 $id_tax = $input->getUint('id_tax');
114
115 if ($id_tax)
116 {
117 $url .= '&id_tax=' . $id_tax;
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['id'] = $input->get('id', 0, 'uint');
154 $args['id_tax'] = $input->get('id_tax', 0, 'uint');
155 $args['tag'] = $input->get('tag', '', 'string');
156
157 $rule = 'core.' . ($args['id'] > 0 ? 'edit' : 'create');
158
159 // check user permissions
160 if (!$user->authorise($rule, 'com_vikappointments') || !$user->authorise('core.access.taxes', 'com_vikappointments'))
161 {
162 // back to main list, not authorised to create/edit records
163 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
164 $this->cancel();
165
166 return false;
167 }
168
169 // get db model
170 $langtax = $this->getModel();
171
172 // try to save arguments
173 $id = $langtax->save($args);
174
175 if (!$id)
176 {
177 // get string error
178 $error = $langtax->getError(null, true);
179
180 // display error message
181 $app->enqueueMessage(JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $error), 'error');
182
183 $url = 'index.php?option=com_vikappointments&view=managelangtax';
184
185 if ($args['id'])
186 {
187 $url .= '&cid[]=' . $args['id'];
188 }
189 else
190 {
191 $url .= '&id_tax=' . $args['id_tax'];
192 }
193
194 // redirect to new/edit page
195 $this->setRedirect($url);
196
197 return false;
198 }
199
200 // retrieve rules from request
201 $rule_id = $input->get('rule_id', array(), 'uint');
202 $rule_lang_id = $input->get('rule_lang_id', array(), 'uint');
203 $rule_name = $input->get('rule_name', array(), 'string');
204 $rule_breakdown = $input->get('rule_breakdown', array(), 'array');
205
206 $langrule = $this->getModel('langtaxrule');
207
208 for ($i = 0; $i < count($rule_id); $i++)
209 {
210 $src = array();
211 $src['id'] = $rule_lang_id[$i];
212 $src['id_tax_rule'] = $rule_id[$i];
213 $src['name'] = $rule_name[$i];
214 $src['breakdown'] = '';
215 $src['id_parent'] = $id;
216 $src['tag'] = $args['tag'];
217
218 if (isset($rule_breakdown[$src['id_tax_rule']]))
219 {
220 $src['breakdown'] = json_encode($rule_breakdown[$src['id_tax_rule']]);
221 }
222
223 $langrule->save($src);
224 }
225
226 // display generic successful message
227 $app->enqueueMessage(JText::translate('JLIB_APPLICATION_SAVE_SUCCESS'));
228
229 // redirect to edit page
230 $this->setRedirect('index.php?option=com_vikappointments&task=langtax.edit&cid[]=' . $id);
231
232 return true;
233 }
234
235 /**
236 * Deletes a list of records set in the request.
237 *
238 * @return boolean
239 */
240 public function delete()
241 {
242 $app = JFactory::getApplication();
243 $user = JFactory::getUser();
244
245 /**
246 * Added token validation.
247 * Both GET and POST are supported.
248 *
249 * @since 1.7
250 */
251 if (!JSession::checkToken() && !JSession::checkToken('get'))
252 {
253 // back to main list, missing CSRF-proof token
254 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
255 $this->cancel();
256
257 return false;
258 }
259
260 $cid = $app->input->get('cid', array(), 'uint');
261
262 // check user permissions
263 if (!$user->authorise('core.delete', 'com_vikappointments') || !$user->authorise('core.access.taxes', 'com_vikappointments'))
264 {
265 // back to main list, not authorised to delete records
266 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
267 $this->cancel();
268
269 return false;
270 }
271
272 // delete selected records
273 $this->getModel()->delete($cid);
274
275 // back to main list
276 $this->cancel();
277
278 return true;
279 }
280
281 /**
282 * Redirects the users to the main records list.
283 *
284 * @return void
285 */
286 public function cancel()
287 {
288 $input = JFactory::getApplication()->input;
289
290 // recover tax ID from request
291 $id_tax = $input->getUint('id_tax');
292
293 $url = 'index.php?option=com_vikappointments&view=langtaxes';
294
295 if ($id_tax)
296 {
297 $url .= '&id_tax=' . $id_tax;
298 }
299
300 $this->setRedirect($url);
301 }
302 }
303