PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / trunk
VikAppointments Services Booking Calendar vtrunk
trunk 1.2.17 1.2.18 1.2.19
vikappointments / site / controllers / packagesconfirm.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
packagesconfirm.php
131 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 packages confirmation controller.
18 *
19 * @since 1.7
20 */
21 class VikAppointmentsControllerPackagesconfirm extends VAPControllerAdmin
22 {
23 /**
24 * Saves the packages that have been registered within the cart.
25 *
26 * @return boolean
27 */
28 public function saveorder()
29 {
30 $app = JFactory::getApplication();
31 $input = $app->input;
32
33 $itemid = $input->getUint('Itemid');
34
35 // prepare redirect URL
36 $this->setRedirect(JRoute::rewrite('index.php?option=com_vikappointments&view=packagesconfirm' . ($itemid ? '&Itemid=' . $itemid : ''), false));
37
38 /**
39 * Validate session token before to proceed.
40 *
41 * @since 1.7
42 */
43 if (!JSession::checkToken())
44 {
45 // invalid token, back to confirm page
46 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
47 return false;
48 }
49
50 // load arguments from request
51 $args = array();
52 $args['id_payment'] = $input->getUint('id_payment', 0);
53 $args['itemid'] = $itemid;
54
55 // get view model
56 $model = $this->getModel();
57
58 // try to save the packages and get landing page
59 $url = $model->save($args);
60
61 // make sure we haven't faced any errors
62 if (!$url)
63 {
64 // get all registered errors
65 $errors = $model->getErrors();
66
67 foreach ($errors as $err)
68 {
69 // enqueue error message
70 $app->enqueueMessage($err, 'error');
71 }
72
73 return false;
74 }
75
76 // update redirect URL to reach the landing page
77 $this->setRedirect($url);
78 return true;
79 }
80
81 /**
82 * End-point used to redeem the coupon code.
83 *
84 * @return boolean
85 */
86 public function redeemcoupon()
87 {
88 $app = JFactory::getApplication();
89 $input = $app->input;
90
91 $itemid = $input->getUint('Itemid');
92
93 // prepare redirect URL
94 $this->setRedirect(JRoute::rewrite('index.php?option=com_vikappointments&view=packagesconfirm' . ($itemid ? '&Itemid=' . $itemid : ''), false));
95
96 /**
97 * Validate form token to prevent brute force attacks.
98 *
99 * @since 1.6
100 */
101 if (!JSession::checkToken())
102 {
103 // direct access attempt
104 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
105 return false;
106 }
107
108 // get coupon key from POST
109 $coupon = $input->post->getString('couponkey', '');
110
111 // get cart model
112 $model = $this->getModel('packagescart');
113
114 // try to redeem the coupon code
115 $res = $model->redeemCoupon($coupon);
116
117 if (!$res)
118 {
119 // get last error registered by the model
120 $error = $model->getError($index = null, $string = true);
121 // propagate error or use the default one
122 $app->enqueueMessage($error ? $error : JText::translate('VAPCOUPONNOTVALID'), 'error');
123 return false;
124 }
125
126 // coupon applied successfully
127 $app->enqueueMessage(JText::translate('VAPCOUPONFOUND'));
128 return true;
129 }
130 }
131