PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / trunk
VikAppointments Services Booking Calendar vtrunk
trunk 1.2.17 1.2.18 1.2.19
vikappointments / admin / controllers / subscrorder.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 5 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 5 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 5 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 5 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
subscrorder.php
350 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 subscription order controller.
18 *
19 * @since 1.7
20 */
21 class VikAppointmentsControllerSubscrorder 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 $data = array();
34 $group = $app->input->getUint('group', null);
35
36 if (!is_null($group))
37 {
38 $data['group'] = $group;
39 }
40
41 // unset user state for being recovered again
42 $app->setUserState('vap.subscrorder.data', $data);
43
44 // check user permissions
45 if (!$user->authorise('core.create', 'com_vikappointments') || !$user->authorise('core.access.subscriptions', 'com_vikappointments'))
46 {
47 // back to main list, not authorised to create records
48 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
49 $this->cancel();
50
51 return false;
52 }
53
54 $this->setRedirect('index.php?option=com_vikappointments&view=managesubscrorder');
55
56 return true;
57 }
58
59 /**
60 * Task used to access the management page of an existing record.
61 *
62 * @return boolean
63 */
64 public function edit()
65 {
66 $app = JFactory::getApplication();
67 $user = JFactory::getUser();
68
69 // unset user state for being recovered again
70 $app->setUserState('vap.subscrorder.data', array());
71
72 // check user permissions
73 if (!$user->authorise('core.edit', 'com_vikappointments') || !$user->authorise('core.access.subscriptions', 'com_vikappointments'))
74 {
75 // back to main list, not authorised to edit records
76 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
77 $this->cancel();
78
79 return false;
80 }
81
82 $cid = $app->input->getUint('cid', array(0));
83
84 $this->setRedirect('index.php?option=com_vikappointments&view=managesubscrorder&cid[]=' . $cid[0]);
85
86 return true;
87 }
88
89 /**
90 * Task used to save the record data set in the request.
91 * After saving, the user is redirected to the main list.
92 *
93 * @return void
94 */
95 public function saveclose()
96 {
97 if ($this->save())
98 {
99 $this->cancel();
100 }
101 }
102
103 /**
104 * Task used to save the record data set in the request.
105 * After saving, the user is redirected to the creation
106 * page of a new record.
107 *
108 * @return void
109 */
110 public function savenew()
111 {
112 if ($this->save())
113 {
114 $input = JFactory::getApplication()->input;
115
116 $url = 'index.php?option=com_vikappointments&task=subscrorder.add';
117
118 $group = $input->getUint('group', null);
119
120 if (!is_null($group))
121 {
122 // preserve group for the next record
123 $url .= '&group=' . $group;
124 }
125
126 $this->setRedirect($url);
127 }
128 }
129
130 /**
131 * Task used to save the record data set in the request.
132 * After saving, the user is redirected to the management
133 * page of the record that has been saved.
134 *
135 * @return boolean
136 */
137 public function save()
138 {
139 $app = JFactory::getApplication();
140 $input = $app->input;
141 $user = JFactory::getUser();
142
143 /**
144 * Added token validation.
145 *
146 * @since 1.7
147 */
148 if (!JSession::checkToken())
149 {
150 // back to main list, missing CSRF-proof token
151 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
152 $this->cancel();
153
154 return false;
155 }
156
157 $args = array();
158 $args['id_subscr'] = $input->getUint('id_subscr', 0);
159 $args['id_user'] = $input->getUint('id_user', 0);
160 $args['id_employee'] = $input->getUint('id_employee', 0);
161 $args['id_payment'] = $input->getUint('id_payment', 0);
162 $args['total_cost'] = $input->getFloat('total_cost', 0.0);
163 $args['total_net'] = $input->getFloat('total_net', 0.0);
164 $args['total_tax'] = $input->getFloat('total_tax', 0.0);
165 $args['payment_charge'] = $input->getFloat('payment_charge', 0.0);
166 $args['payment_tax'] = $input->getFloat('payment_tax', 0.0);
167 $args['add_discount'] = $input->getString('add_discount', '');
168 $args['remove_discount'] = $input->getBool('remove_discount', false);
169 $args['status'] = $input->getString('status', '');
170 $args['id'] = $input->getUint('id', 0);
171
172 if ($args['add_discount'] === 'manual')
173 {
174 // fetch manual discount from request
175 $args['add_discount'] = $input->get('manual_discount', [], 'array');
176 }
177
178 $rule = 'core.' . ($args['id'] > 0 ? 'edit' : 'create');
179
180 // check user permissions
181 if (!$user->authorise($rule, 'com_vikappointments') || !$user->authorise('core.access.subscriptions', 'com_vikappointments'))
182 {
183 // back to main list, not authorised to create/edit records
184 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
185 $this->cancel();
186
187 return false;
188 }
189
190 // get db model
191 $order = $this->getModel();
192
193 // try to save arguments
194 $id = $order->save($args);
195
196 if (!$id)
197 {
198 // get string error
199 $error = $order->getError(null, true);
200
201 // display error message
202 $app->enqueueMessage(JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $error), 'error');
203
204 $url = 'index.php?option=com_vikappointments&view=managesubscrorder';
205
206 if ($args['id'])
207 {
208 $url .= '&cid[]=' . $args['id'];
209 }
210
211 // redirect to new/edit page
212 $this->setRedirect($url);
213
214 return false;
215 }
216
217 // display generic successful message
218 $app->enqueueMessage(JText::translate('JLIB_APPLICATION_SAVE_SUCCESS'));
219
220 // redirect to edit page
221 $this->setRedirect('index.php?option=com_vikappointments&task=subscrorder.edit&cid[]=' . $id);
222
223 return true;
224 }
225
226 /**
227 * Deletes a list of records set in the request.
228 *
229 * @return boolean
230 */
231 public function delete()
232 {
233 $app = JFactory::getApplication();
234 $user = JFactory::getUser();
235
236 /**
237 * Added token validation.
238 * Both GET and POST are supported.
239 *
240 * @since 1.7
241 */
242 if (!JSession::checkToken() && !JSession::checkToken('get'))
243 {
244 // back to main list, missing CSRF-proof token
245 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
246 $this->cancel();
247
248 return false;
249 }
250
251 $cid = $app->input->get('cid', array(), 'uint');
252
253 // check user permissions
254 if (!$user->authorise('core.delete', 'com_vikappointments') || !$user->authorise('core.access.subscriptions', 'com_vikappointments'))
255 {
256 // back to main list, not authorised to delete records
257 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
258 $this->cancel();
259
260 return false;
261 }
262
263 // delete selected records
264 $this->getModel()->delete($cid);
265
266 // back to main list
267 $this->cancel();
268
269 return true;
270 }
271
272 /**
273 * Redirects the users to the main records list.
274 *
275 * @return void
276 */
277 public function cancel()
278 {
279 $input = JFactory::getApplication()->input;
280
281 $url = 'index.php?option=com_vikappointments&view=subscrorders';
282
283 $group = $input->getUint('group', null);
284
285 if (!is_null($group))
286 {
287 // preserve group to change list filtering
288 $url .= '&group=' . $group;
289 }
290
291 $this->setRedirect($url);
292 }
293
294 /**
295 * AJAX end-point used to change the status code.
296 * The task expects the following arguments to be set in request.
297 *
298 * @param integer id The subscription order ID.
299 * @param string status The new status code.
300 * @param string layout The layout to use (for return).
301 *
302 * @return void
303 */
304 public function changestatusajax()
305 {
306 $input = JFactory::getApplication()->input;
307 $user = JFactory::getUser();
308
309 /**
310 * Added token validation.
311 *
312 * @since 1.7
313 */
314 if (!JSession::checkToken())
315 {
316 // missing CSRF-proof token
317 UIErrorFactory::raiseError(403, JText::translate('JINVALID_TOKEN'));
318 }
319
320 $data = array();
321 $data['id'] = $input->getUint('id');
322 $data['status'] = $input->getString('status');
323
324 // check user permissions
325 if (!$data['id'] || !$user->authorise('core.edit.state', 'com_vikappointments') || !$user->authorise('core.access.subscriptions', 'com_vikappointments'))
326 {
327 // not authorised to edit records
328 UIErrorFactory::raiseError(403, JText::translate('JERROR_ALERTNOAUTHOR'));
329 }
330
331 // get status code details
332 $code = JHtml::fetch('vaphtml.status.find', '*', array('code' => $data['status']), $limit = true);
333
334 if (!$code)
335 {
336 // code not found
337 UIErrorFactory::raiseError(404, JText::translate('JGLOBAL_NO_MATCHING_RESULTS'));
338 }
339
340 // update status
341 $this->getModel()->save($data);
342
343 // render HTML
344 $code->html = JHtml::fetch('vaphtml.status.display', $code, $input->getString('layout'));
345
346 // send code to caller
347 $this->sendJSON($code);
348 }
349 }
350