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
4 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
4 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
4 months ago
waitinglist.php
4 years ago
userprofile.php
268 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 user profile view controller. |
| 18 | * |
| 19 | * @since 1.7 |
| 20 | */ |
| 21 | class VikAppointmentsControllerUserprofile extends VAPControllerAdmin |
| 22 | { |
| 23 | /** |
| 24 | * Task used to create a new user through the registration form |
| 25 | * used by VikAppointments. |
| 26 | * |
| 27 | * @return boolean |
| 28 | */ |
| 29 | public function register() |
| 30 | { |
| 31 | $app = JFactory::getApplication(); |
| 32 | $input = $app->input; |
| 33 | |
| 34 | $return = base64_decode($input->getBase64('return')); |
| 35 | |
| 36 | if (empty($return)) |
| 37 | { |
| 38 | $return = 'index.php'; |
| 39 | } |
| 40 | |
| 41 | // create successful return URL |
| 42 | $okReturn = JRoute::rewrite($return, false); |
| 43 | |
| 44 | // create failure return URL |
| 45 | $failReturn = JUri::getInstance($return); |
| 46 | $failReturn->setVar('tab', 'registration'); |
| 47 | |
| 48 | // set error redirect URL by default |
| 49 | $this->setRedirect(JRoute::rewrite($failReturn, false)); |
| 50 | |
| 51 | if (!JSession::checkToken()) |
| 52 | { |
| 53 | // invalid session token |
| 54 | $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error'); |
| 55 | return false; |
| 56 | } |
| 57 | |
| 58 | $vik = VAPApplication::getInstance(); |
| 59 | |
| 60 | if ($vik->isCaptcha() && !$vik->reCaptcha('check')) |
| 61 | { |
| 62 | // invalid captcha |
| 63 | $app->enqueueMessage(JText::translate('PLG_RECAPTCHA_ERROR_EMPTY_SOLUTION'), 'error'); |
| 64 | return false; |
| 65 | } |
| 66 | |
| 67 | $args = array(); |
| 68 | $args['firstname'] = $input->getString('fname'); |
| 69 | $args['lastname'] = $input->getString('lname'); |
| 70 | $args['email'] = $input->getString('email'); |
| 71 | $args['username'] = $input->getString('reg_username'); |
| 72 | $args['password'] = $input->getString('reg_password'); |
| 73 | $args['confpassword'] = $input->getString('confpassword'); |
| 74 | |
| 75 | if (!VikAppointments::checkUserArguments($args)) |
| 76 | { |
| 77 | // missing required field (or the user was already logged in) |
| 78 | $app->enqueueMessage(JText::translate('VAPREGISTRATIONFAILED2'), 'error'); |
| 79 | return false; |
| 80 | } |
| 81 | |
| 82 | // try to register a new user account |
| 83 | $userid = VikAppointments::createNewUserAccount($args); |
| 84 | |
| 85 | if (!$userid) |
| 86 | { |
| 87 | // an error occurred... |
| 88 | return false; |
| 89 | } |
| 90 | |
| 91 | // switch redirect URL on success |
| 92 | $this->setRedirect($okReturn); |
| 93 | |
| 94 | if ($userid == 'useractivate' || $userid == 'adminactivate') |
| 95 | { |
| 96 | // registration requires a manual activation |
| 97 | return true; |
| 98 | } |
| 99 | |
| 100 | // successful registration, auto log-in |
| 101 | $credentials = array( |
| 102 | 'username' => $args['username'], |
| 103 | 'password' => $args['password'], |
| 104 | 'remember' => true, |
| 105 | ); |
| 106 | |
| 107 | $app->login($credentials); |
| 108 | |
| 109 | $user = JFactory::getUser(); |
| 110 | $user->setLastVisit(); |
| 111 | $user->set('guest', 0); |
| 112 | |
| 113 | return true; |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Save and close task. |
| 118 | * |
| 119 | * @return void |
| 120 | */ |
| 121 | public function saveclose() |
| 122 | { |
| 123 | if ($this->save()) |
| 124 | { |
| 125 | $this->cancel(); |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Task used to save the billing details of the logged-in user. |
| 131 | * If the task is reached by a guest user, it will be redirected |
| 132 | * to the "allorders" page. |
| 133 | * |
| 134 | * @return boolean |
| 135 | */ |
| 136 | public function save() |
| 137 | { |
| 138 | $app = JFactory::getApplication(); |
| 139 | $input = $app->input; |
| 140 | $user = JFactory::getUser(); |
| 141 | |
| 142 | $itemid = $input->getInt('Itemid', 0); |
| 143 | |
| 144 | if ($user->guest) |
| 145 | { |
| 146 | // back to all orders view |
| 147 | $this->cancel(); |
| 148 | return false; |
| 149 | } |
| 150 | |
| 151 | // get customer details from request |
| 152 | $args = array(); |
| 153 | $args['jid'] = $user->id; |
| 154 | $args['billing_name'] = $input->getString('billing_name'); |
| 155 | $args['billing_mail'] = $input->getString('billing_mail'); |
| 156 | $args['billing_phone'] = $input->getString('billing_phone'); |
| 157 | $args['country_code'] = $input->getString('country_code'); |
| 158 | $args['billing_state'] = $input->getString('billing_state'); |
| 159 | $args['billing_city'] = $input->getString('billing_city'); |
| 160 | $args['billing_address'] = $input->getString('billing_address'); |
| 161 | $args['billing_address_2'] = $input->getString('billing_address_2'); |
| 162 | $args['billing_zip'] = $input->getString('billing_zip'); |
| 163 | $args['company'] = $input->getString('company'); |
| 164 | $args['vatnum'] = $input->getString('vatnum'); |
| 165 | $args['ssn'] = $input->getString('ssn'); |
| 166 | $args['pec'] = $input->getString('pec'); |
| 167 | |
| 168 | // get customer model |
| 169 | $model = $this->getModel('customer'); |
| 170 | |
| 171 | // load current user profile |
| 172 | $data = $model->getItem(array('jid' => $user->id)); |
| 173 | |
| 174 | $old_image = false; |
| 175 | |
| 176 | if ($data) |
| 177 | { |
| 178 | // set ID for direct update |
| 179 | $args['id'] = $data->id; |
| 180 | // check if we have an image to delete after the upload |
| 181 | $old_image = $data->image; |
| 182 | } |
| 183 | |
| 184 | // get uploaded image, if any |
| 185 | $img = $input->files->get('image', null, 'array'); |
| 186 | |
| 187 | // upload image |
| 188 | $result = VikAppointments::uploadImage($img, VAPCUSTOMERS_AVATAR . DIRECTORY_SEPARATOR); |
| 189 | |
| 190 | if ($result->status) |
| 191 | { |
| 192 | // successful upload |
| 193 | $args['image'] = $result->name; |
| 194 | |
| 195 | // unlink old customer image |
| 196 | if ($old_image) |
| 197 | { |
| 198 | unlink(VAPCUSTOMERS_AVATAR . DIRECTORY_SEPARATOR . $old_image); |
| 199 | } |
| 200 | } |
| 201 | else |
| 202 | { |
| 203 | if ($result->errno == 1) |
| 204 | { |
| 205 | // invalid file tyoe |
| 206 | $app->enqueueMessage(JText::translate('VAPCONFIGFILETYPEERROR'), 'error'); |
| 207 | } |
| 208 | else if ($result->errno == 2) |
| 209 | { |
| 210 | // upload error |
| 211 | $app->enqueueMessage(JText::translate('VAPCONFIGUPLOADERROR'), 'error'); |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | // if the country code doesn't exist, make it empty |
| 216 | if (VAPLocations::getCountryFromCode($args['country_code']) === false) |
| 217 | { |
| 218 | /** |
| 219 | * Use an empty value instead of "US". |
| 220 | * |
| 221 | * @since 1.6.3 |
| 222 | */ |
| 223 | $args['country_code'] = ''; |
| 224 | } |
| 225 | |
| 226 | // set return URL |
| 227 | $this->setRedirect(JRoute::rewrite('index.php?option=com_vikappointments&view=userprofile' . ($itemid ? '&Itemid=' . $itemid : ''), false)); |
| 228 | |
| 229 | // try to save the customer data |
| 230 | if (!$model->save($args)) |
| 231 | { |
| 232 | // an error occurred, back to edit page |
| 233 | $app->enqueueMessage(JText::translate('VAPERRINSUFFCUSTF'), 'error'); |
| 234 | |
| 235 | return false; |
| 236 | } |
| 237 | |
| 238 | // update/insert successful |
| 239 | $app->enqueueMessage(JText::translate('VAPUSERPROFILEDATASTORED')); |
| 240 | |
| 241 | return true; |
| 242 | } |
| 243 | |
| 244 | /** |
| 245 | * Task used to go back to the all orders view. |
| 246 | * |
| 247 | * @return void |
| 248 | */ |
| 249 | public function cancel() |
| 250 | { |
| 251 | $itemid = JFactory::getApplication()->input->getUint('Itemid', 0); |
| 252 | $this->setRedirect(JRoute::rewrite('index.php?option=com_vikappointments&view=allorders' . ($itemid ? '&Itemid=' . $itemid : ''), false)); |
| 253 | } |
| 254 | |
| 255 | /** |
| 256 | * Task used to perform the logout of the current user. |
| 257 | * The user will be redirected to the "allorders" page. |
| 258 | * |
| 259 | * @return void |
| 260 | */ |
| 261 | public function logout() |
| 262 | { |
| 263 | $app = JFactory::getApplication(); |
| 264 | $app->logout(JFactory::getUser()->id); |
| 265 | $this->cancel(); |
| 266 | } |
| 267 | } |
| 268 |