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
confirmapp.php
196 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 appointment confirmation controller. |
| 18 | * |
| 19 | * @since 1.7 |
| 20 | */ |
| 21 | class VikAppointmentsControllerConfirmapp extends VAPControllerAdmin |
| 22 | { |
| 23 | /** |
| 24 | * Saves the appointments 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 | $ajax = $input->getBool('ajax', false); |
| 34 | |
| 35 | $itemid = $input->getUint('Itemid'); |
| 36 | |
| 37 | // prepare redirect URL |
| 38 | $this->setRedirect(JRoute::rewrite('index.php?option=com_vikappointments&view=confirmapp' . ($itemid ? '&Itemid=' . $itemid : ''), false)); |
| 39 | |
| 40 | /** |
| 41 | * Validate session token before to proceed. |
| 42 | * |
| 43 | * @since 1.7 |
| 44 | */ |
| 45 | if (!JSession::checkToken()) |
| 46 | { |
| 47 | if ($ajax) |
| 48 | { |
| 49 | // in case of AJAX, raise HTTP error |
| 50 | UIErrorFactory::raiseError(403, JText::translate('JINVALID_TOKEN')); |
| 51 | } |
| 52 | |
| 53 | // invalid token, back to confirm page |
| 54 | $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error'); |
| 55 | return false; |
| 56 | } |
| 57 | |
| 58 | $vik = VAPApplication::getInstance(); |
| 59 | |
| 60 | /** |
| 61 | * Validate ReCaptcha before processing the reservation request. |
| 62 | * The ReCaptcha is never asked to registered customers. |
| 63 | * |
| 64 | * @since 1.7 |
| 65 | */ |
| 66 | if (JFactory::getUser()->guest && $vik->isGlobalCaptcha() && !$vik->reCaptcha('check')) |
| 67 | { |
| 68 | if ($ajax) |
| 69 | { |
| 70 | // in case of AJAX, raise HTTP error |
| 71 | UIErrorFactory::raiseError(400, JText::translate('PLG_RECAPTCHA_ERROR_EMPTY_SOLUTION')); |
| 72 | } |
| 73 | |
| 74 | // invalid captcha |
| 75 | $app->enqueueMessage(JText::translate('PLG_RECAPTCHA_ERROR_EMPTY_SOLUTION'), 'error'); |
| 76 | return false; |
| 77 | } |
| 78 | |
| 79 | // load arguments from request |
| 80 | $args = array(); |
| 81 | $args['id_payment'] = $input->getUint('id_payment', 0); |
| 82 | $args['itemid'] = $itemid; |
| 83 | |
| 84 | // get view model |
| 85 | $model = $this->getModel(); |
| 86 | |
| 87 | // try to save the appointments and get landing page |
| 88 | $url = $model->save($args); |
| 89 | |
| 90 | // make sure we haven't faced any errors |
| 91 | if (!$url) |
| 92 | { |
| 93 | // get all registered errors |
| 94 | $errors = $model->getErrors(); |
| 95 | |
| 96 | if ($ajax) |
| 97 | { |
| 98 | // in case of AJAX, raise HTTP error |
| 99 | UIErrorFactory::raiseError(500, implode("\n", $errors)); |
| 100 | } |
| 101 | |
| 102 | foreach ($errors as $err) |
| 103 | { |
| 104 | // enqueue error message |
| 105 | $app->enqueueMessage($err, 'error'); |
| 106 | } |
| 107 | |
| 108 | return false; |
| 109 | } |
| 110 | |
| 111 | if ($ajax) |
| 112 | { |
| 113 | // in case of AJAX, return the URL of the landing page |
| 114 | $this->sendJSON(json_encode($url)); |
| 115 | } |
| 116 | |
| 117 | // update redirect URL to reach the landing page |
| 118 | $this->setRedirect($url); |
| 119 | return true; |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * End-point used to redeem the coupon code. |
| 124 | * |
| 125 | * @return boolean |
| 126 | */ |
| 127 | public function redeemcoupon() |
| 128 | { |
| 129 | $app = JFactory::getApplication(); |
| 130 | $input = $app->input; |
| 131 | |
| 132 | $itemid = $input->getUint('Itemid'); |
| 133 | |
| 134 | // prepare redirect URL |
| 135 | $this->setRedirect(JRoute::rewrite('index.php?option=com_vikappointments&view=confirmapp' . ($itemid ? '&Itemid=' . $itemid : ''), false)); |
| 136 | |
| 137 | /** |
| 138 | * Validate form token to prevent brute force attacks. |
| 139 | * |
| 140 | * @since 1.6 |
| 141 | */ |
| 142 | if (!JSession::checkToken()) |
| 143 | { |
| 144 | // direct access attempt |
| 145 | $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error'); |
| 146 | return false; |
| 147 | } |
| 148 | |
| 149 | // get coupon key from POST |
| 150 | $coupon = $input->post->getString('couponkey', ''); |
| 151 | |
| 152 | // get cart model |
| 153 | $model = $this->getModel('cart'); |
| 154 | |
| 155 | // try to redeem the coupon code |
| 156 | $res = $model->redeemCoupon($coupon); |
| 157 | |
| 158 | if (!$res) |
| 159 | { |
| 160 | // get last error registered by the model |
| 161 | $error = $model->getError($index = null, $string = true); |
| 162 | // propagate error or use the default one |
| 163 | $app->enqueueMessage($error ? $error : JText::translate('VAPCOUPONNOTVALID'), 'error'); |
| 164 | return false; |
| 165 | } |
| 166 | |
| 167 | // coupon applied successfully |
| 168 | $app->enqueueMessage(JText::translate('VAPCOUPONFOUND')); |
| 169 | return true; |
| 170 | } |
| 171 | |
| 172 | /** |
| 173 | * AJAX task used to validate the specified zip code against |
| 174 | * the appointments contained within the user cart. |
| 175 | * |
| 176 | * @return void |
| 177 | */ |
| 178 | public function checkzip() |
| 179 | { |
| 180 | // get ZIP code from request |
| 181 | $zip = JFactory::getApplication()->input->getString('zip'); |
| 182 | |
| 183 | // validate the specified ZIP code |
| 184 | $result = $this->getModel()->validateZipCode($zip); |
| 185 | |
| 186 | if (!$result) |
| 187 | { |
| 188 | // raise error in case the ZIP is not accepted |
| 189 | UIErrorFactory::raiseError(500, JText::translate('VAPCONFAPPZIPERROR')); |
| 190 | } |
| 191 | |
| 192 | // ZIP code valid |
| 193 | $this->sendJSON(1); |
| 194 | } |
| 195 | } |
| 196 |