PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / trunk
VikAppointments Services Booking Calendar vtrunk
trunk 1.2.17 1.2.18 1.2.19
vikappointments / site / controllers / empeditpay.php
vikappointments / site / controllers Last commit date
calendarweek.php 3 years ago cart.php 1 month ago confirmapp.php 2 years ago empattachser.php 4 years ago empeditcoupon.php 4 years ago empeditcustfield.php 4 years ago empeditlocation.php 4 years ago empeditpay.php 4 years ago empeditprofile.php 5 months ago empeditservice.php 4 years ago empeditwdays.php 4 years ago emplocwdays.php 4 years ago emplogin.php 2 years ago employeesearch.php 2 years ago employeeslist.php 4 years ago empmakerecur.php 1 month ago empmanres.php 1 month ago empsettings.php 2 years ago empsubscr.php 4 years ago empsubscrorder.php 1 year ago index.html 6 years ago modules.php 1 year ago order.php 5 months ago packages.php 4 years ago packagesconfirm.php 4 years ago packagesorder.php 1 year ago servicesearch.php 2 years ago subscriptions.php 4 years ago subscrpayment.php 1 year ago userprofile.php 5 months ago waitinglist.php 4 years ago
empeditpay.php
401 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.employee.area.controller');
15
16 /**
17 * Employee area edit payment controller.
18 *
19 * @since 1.6
20 */
21 class VikAppointmentsControllerEmpeditpay extends VAPEmployeeAreaController
22 {
23 /**
24 * Task used to access the creation page of a new record.
25 *
26 * @return boolean
27 *
28 * @since 1.7
29 */
30 public function add()
31 {
32 $app = JFactory::getApplication();
33 $auth = VAPEmployeeAuth::getInstance();
34
35 // unset user state for being recovered again
36 $app->setUserState('vap.emparea.payment.data', array());
37
38 // check user permissions
39 if (!$auth->managePayments())
40 {
41 // back to main list, not authorised to edit records
42 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
43 $this->cancel();
44
45 return false;
46 }
47
48 $this->setRedirect('index.php?option=com_vikappointments&view=empeditpay');
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 * @since 1.7
59 */
60 public function edit()
61 {
62 $app = JFactory::getApplication();
63 $auth = VAPEmployeeAuth::getInstance();
64
65 // unset user state for being recovered again
66 $app->setUserState('vap.emparea.payment.data', array());
67
68 $cid = $app->input->getUint('cid', array(0));
69
70 // check user permissions
71 if (!$auth->managePayments($cid[0]))
72 {
73 // back to main list, not authorised to edit records
74 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
75 $this->cancel();
76
77 return false;
78 }
79
80 $this->setRedirect('index.php?option=com_vikappointments&view=empeditpay&cid[]=' . $cid[0]);
81
82 return true;
83 }
84
85 /**
86 * Task used to save the record data set in the request.
87 * After saving, the user is redirected to the main list.
88 *
89 * @return void
90 *
91 * @since 1.7
92 */
93 public function saveclose()
94 {
95 if ($this->save())
96 {
97 $this->cancel();
98 }
99 }
100
101 /**
102 * Save employee payments.
103 *
104 * @return void
105 */
106 public function save()
107 {
108 $app = JFactory::getApplication();
109 $input = $app->input;
110 $auth = VAPEmployeeAuth::getInstance();
111
112 /**
113 * Added token validation.
114 *
115 * @since 1.7
116 */
117 if (!JSession::checkToken())
118 {
119 // back to main list, missing CSRF-proof token
120 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
121 $this->cancel();
122
123 return false;
124 }
125
126 $id_payment = $input->getUint('id', 0);
127
128 // check user permissions
129 if (!$auth->managePayments($id_payment))
130 {
131 // back to main list, not authorised to edit records
132 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
133 $this->cancel();
134
135 return false;
136 }
137
138 // get args
139 $args = array();
140 $args['name'] = $input->getString('name');
141 $args['file'] = $input->getString('file');
142 $args['published'] = $input->getUint('published', 0);
143 $args['trust'] = $input->getUint('trust', 0);
144 $args['charge'] = $input->getFloat('charge', 0);
145 $args['setconfirmed'] = $input->getUint('setconfirmed', 0);
146 $args['selfconfirm'] = $input->getUint('selfconfirm', 0);
147 $args['icon'] = $input->getString('icon', '');
148 $args['prenote'] = JComponentHelper::filterText($input->getRaw('prenote'));
149 $args['note'] = JComponentHelper::filterText($input->getRaw('note'));
150 $args['id'] = $id_payment;
151
152 if ($args['selfconfirm'])
153 {
154 // always unset auto-confirmation in case of self-confirmation
155 // in order to avoid backward compatibility issues
156 $args['setconfirmed'] = 0;
157 }
158
159 // get payment model
160 $model = $this->getModel();
161
162 // try to save arguments
163 $id = $model->save($args);
164
165 if (!$id)
166 {
167 // get string error
168 $error = $model->getError(null, true);
169
170 // display error message
171 $app->enqueueMessage(JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $error), 'error');
172
173 $url = 'index.php?option=com_vikappointments&view=empeditpay';
174
175 if ($id_payment)
176 {
177 $url .= '&cid[]=' . $id_payment;
178 }
179
180 // redirect to edit page
181 $this->setRedirect($url);
182
183 return false;
184 }
185
186 // display generic successful message
187 $app->enqueueMessage(JText::translate('JLIB_APPLICATION_SAVE_SUCCESS'));
188
189 // redirect to edit page
190 $this->setRedirect('index.php?option=com_vikappointments&task=empeditpay.edit&cid[]=' . $id);
191
192 return true;
193 }
194
195 /**
196 * Deletes a list of selected payments.
197 *
198 * @return void
199 */
200 public function delete()
201 {
202 $app = JFactory::getApplication();
203 $cid = $app->input->get('cid', array(), 'uint');
204
205 if ($id = $app->input->getUint('id'))
206 {
207 $cid[] = $id;
208 }
209
210 /**
211 * Added token validation.
212 * Both GET and POST are supported.
213 *
214 * @since 1.7
215 */
216 if (!JSession::checkToken() && !JSession::checkToken('get'))
217 {
218 // back to main list, missing CSRF-proof token
219 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
220 $this->cancel();
221
222 return false;
223 }
224
225 try
226 {
227 // delete selected records
228 if ($this->getModel()->delete($cid))
229 {
230 $app->enqueueMessage(JText::translate('VAPEMPPAYREMOVED1'));
231 }
232 }
233 catch (Exception $e)
234 {
235 // an error occurred
236 $app->enqueueMessage($e->getMessage(), 'error');
237 $this->cancel();
238
239 return false;
240 }
241
242 // back to main list (reset list limit)
243 $this->cancel(['listlimit' => 0]);
244
245 return true;
246 }
247
248 /**
249 * Publishes the payment.
250 *
251 * @return void
252 */
253 public function publish()
254 {
255 $app = JFactory::getApplication();
256
257 $cid = $app->input->get('cid', array(), 'uint');
258 $task = $app->input->get('task', null);
259
260 $state = $task == 'unpublish' ? 0 : 1;
261
262 /**
263 * Added token validation.
264 * Both GET and POST are supported.
265 *
266 * @since 1.7
267 */
268 if (!JSession::checkToken() && !JSession::checkToken('get'))
269 {
270 // back to main list, missing CSRF-proof token
271 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
272 $this->cancel();
273
274 return false;
275 }
276
277 // publish selected records
278 $this->getModel()->publish($cid, $state);
279
280 // back to main list
281 $this->cancel();
282
283 return true;
284 }
285
286 /**
287 * Redirects the users to the main records list.
288 *
289 * @param array $query An array of query arguments.
290 *
291 * @return void
292 *
293 * @since 1.7
294 */
295 public function cancel(array $query = array())
296 {
297 $url = 'index.php?option=com_vikappointments&view=emppaylist';
298
299 if ($query)
300 {
301 $url .= '&' . http_build_query($query);
302 }
303
304 $this->setRedirect($url);
305 }
306
307 /**
308 * AJAX end-point used to retrieve the configuration
309 * of the selected driver.
310 *
311 * @return void
312 *
313 * @since 1.7
314 */
315 public function driverfields()
316 {
317 $input = JFactory::getApplication()->input;
318
319 /**
320 * Added token validation.
321 *
322 * @since 1.7
323 */
324 if (!JSession::checkToken())
325 {
326 // missing CSRF-proof token
327 UIErrorFactory::raiseError(403, JText::translate('JINVALID_TOKEN'));
328 }
329
330 $driver = $input->getString('driver');
331 $id = $input->getUint('id', 0);
332
333 $auth = VAPEmployeeAuth::getInstance();
334
335 // check user permissions
336 if (!$auth->managePayments($id))
337 {
338 // back to main list, not authorised to edit records
339 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
340 $this->cancel();
341
342 return false;
343 }
344
345 // access payment config through platform handler
346 $form = VAPApplication::getInstance()->getPaymentConfig($driver);
347
348 $params = array();
349
350 if ($id)
351 {
352 // load payment details
353 $payment = $this->getModel('payment')->getItem($id);
354
355 if ($payment)
356 {
357 // use found parameters
358 $params = $payment->params;
359 }
360 }
361
362 // build display data
363 $data = array(
364 'fields' => $form,
365 'params' => $params,
366 'prefix' => 'gp_',
367 );
368
369 // render payment form (use back-end layout)
370 $html = JLayoutHelper::render('form.fields', $data, VAPADMIN . DIRECTORY_SEPARATOR . 'layouts');
371
372 // send HTML form to caller
373 $this->sendJSON(json_encode($html));
374 }
375
376 /**
377 * Method to save the submitted ordering values for records via AJAX.
378 *
379 * @return void
380 */
381 public function saveOrderAjax()
382 {
383 $app = JFactory::getApplication();
384 $auth = VAPEmployeeAuth::getInstance();
385
386 // get filters set in request
387 $filters = $app->input->get('filters', array(), 'array');
388
389 // register employee ID within the filters array to apply
390 // the rearrangement of the records only to those payments
391 // that are currently assigned to this employee
392 $filters['id_employee'] = $auth->id;
393
394 // inject updated filters within the request
395 $app->input->set('filters', $filters);
396
397 // invoke parent to commit the new ordering
398 parent::saveOrderAjax();
399 }
400 }
401