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
emplogin.php
241 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 profile controller. |
| 18 | * |
| 19 | * @since 1.6 |
| 20 | */ |
| 21 | class VikAppointmentsControllerEmplogin extends VAPEmployeeAreaController |
| 22 | { |
| 23 | /** |
| 24 | * Task used to create a new employee through the registration form |
| 25 | * used by VikAppointments. |
| 26 | * |
| 27 | * @return boolean |
| 28 | * |
| 29 | * @since 1.7 |
| 30 | */ |
| 31 | public function register() |
| 32 | { |
| 33 | $app = JFactory::getApplication(); |
| 34 | $input = $app->input; |
| 35 | |
| 36 | $return = base64_decode($input->getBase64('return')); |
| 37 | |
| 38 | if (empty($return)) |
| 39 | { |
| 40 | $return = 'index.php'; |
| 41 | } |
| 42 | |
| 43 | // create successful return URL |
| 44 | $okReturn = JRoute::rewrite($return, false); |
| 45 | |
| 46 | // create failure return URL |
| 47 | $failReturn = JUri::getInstance($return); |
| 48 | $failReturn->setVar('tab', 'registration'); |
| 49 | |
| 50 | // set error redirect URL by default |
| 51 | $this->setRedirect(JRoute::rewrite($failReturn, false)); |
| 52 | |
| 53 | if (!VAPEmployeeAreaManager::canRegister()) |
| 54 | { |
| 55 | // employee registration not allowed |
| 56 | $app->enqueueMessage(JText::translate('VAPREGISTRATIONFAILED1'), 'error'); |
| 57 | return false; |
| 58 | } |
| 59 | |
| 60 | if (!JSession::checkToken()) |
| 61 | { |
| 62 | // invalid session token |
| 63 | $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error'); |
| 64 | return false; |
| 65 | } |
| 66 | |
| 67 | $vik = VAPApplication::getInstance(); |
| 68 | |
| 69 | if ($vik->isCaptcha() && !$vik->reCaptcha('check')) |
| 70 | { |
| 71 | // invalid captcha |
| 72 | $app->enqueueMessage(JText::translate('PLG_RECAPTCHA_ERROR_EMPTY_SOLUTION'), 'error'); |
| 73 | return false; |
| 74 | } |
| 75 | |
| 76 | $args = array(); |
| 77 | $args['firstname'] = $input->getString('fname'); |
| 78 | $args['lastname'] = $input->getString('lname'); |
| 79 | $args['email'] = $input->getString('email'); |
| 80 | $args['username'] = $input->getString('reg_username'); |
| 81 | $args['password'] = $input->getString('reg_password'); |
| 82 | $args['confpassword'] = $input->getString('confpassword'); |
| 83 | |
| 84 | if (!VikAppointments::checkUserArguments($args)) |
| 85 | { |
| 86 | // missing required field (or the user was already logged in) |
| 87 | $app->enqueueMessage(JText::translate('VAPREGISTRATIONFAILED2'), 'error'); |
| 88 | return false; |
| 89 | } |
| 90 | |
| 91 | // try to register a new user account |
| 92 | $userid = VikAppointments::createNewUserAccount($args, VikAppointments::REGISTER_EMPLOYEE); |
| 93 | |
| 94 | if (!$userid) |
| 95 | { |
| 96 | // an error occurred... |
| 97 | return false; |
| 98 | } |
| 99 | |
| 100 | // switch redirect URL on success |
| 101 | $this->setRedirect($okReturn); |
| 102 | |
| 103 | if (is_numeric($userid)) |
| 104 | { |
| 105 | $args['id'] = $userid; |
| 106 | |
| 107 | // successful registration, auto log-in |
| 108 | $credentials = array( |
| 109 | 'username' => $args['username'], |
| 110 | 'password' => $args['password'], |
| 111 | 'remember' => true, |
| 112 | ); |
| 113 | |
| 114 | $app->login($credentials); |
| 115 | |
| 116 | $user = JFactory::getUser(); |
| 117 | $user->setLastVisit(); |
| 118 | $user->set('guest', 0); |
| 119 | } |
| 120 | |
| 121 | // complete employee registration through model |
| 122 | if (!$this->getModel()->register($args)) |
| 123 | { |
| 124 | // get last registered error |
| 125 | $error = $this->getError($index = null, $string = true); |
| 126 | |
| 127 | if ($error) |
| 128 | { |
| 129 | $app->enqueueMessage($error, 'error'); |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | return true; |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Performs the logout of the employee. |
| 138 | * |
| 139 | * @return void |
| 140 | */ |
| 141 | public function logout() |
| 142 | { |
| 143 | $app = JFactory::getApplication(); |
| 144 | |
| 145 | // do log off |
| 146 | $app->logout(JFactory::getUser()->id); |
| 147 | |
| 148 | // back to the employee area login page |
| 149 | $this->cancel(); |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * AJAX end-point used to load a list of appointments for |
| 154 | * the specified date. |
| 155 | * |
| 156 | * @param string $date The check-in date. |
| 157 | * |
| 158 | * @return void |
| 159 | * |
| 160 | * @since 1.7 |
| 161 | */ |
| 162 | public function appointmentsajax() |
| 163 | { |
| 164 | $input = JFactory::getApplication()->input; |
| 165 | |
| 166 | /** |
| 167 | * Added token validation. |
| 168 | * |
| 169 | * @since 1.7 |
| 170 | */ |
| 171 | if (!JSession::checkToken()) |
| 172 | { |
| 173 | // missing CSRF-proof token |
| 174 | UIErrorFactory::raiseError(403, JText::translate('JINVALID_TOKEN')); |
| 175 | } |
| 176 | |
| 177 | $auth = VAPEmployeeAuth::getInstance(); |
| 178 | |
| 179 | // make sure the user is an employee |
| 180 | if (!$auth->isEmployee()) |
| 181 | { |
| 182 | // not authorised |
| 183 | UIErrorFactory::raiseError(403, JText::translate('JERROR_ALERTNOAUTHOR')); |
| 184 | } |
| 185 | |
| 186 | $date = $input->getString('date', ''); |
| 187 | |
| 188 | // get appointments model |
| 189 | $model = $this->getModel('reservation'); |
| 190 | |
| 191 | // find appointments list |
| 192 | $list = $model->getAppointmentsOn($date, $auth->id); |
| 193 | |
| 194 | // get rid of closures |
| 195 | $list = array_values(array_filter($list, function($elem) |
| 196 | { |
| 197 | return !$elem->closure; |
| 198 | })); |
| 199 | |
| 200 | if (!$list) |
| 201 | { |
| 202 | // do not display anything in case of empty list |
| 203 | $this->sendJSON([]); |
| 204 | } |
| 205 | |
| 206 | $has_cap = false; |
| 207 | |
| 208 | // check if the employee owns at least a service with maximum capacity higher than 1 |
| 209 | foreach ($list as $elem) |
| 210 | { |
| 211 | $has_cap = $has_cap || $elem->people > 1; |
| 212 | } |
| 213 | |
| 214 | // build reservations list |
| 215 | $data = array( |
| 216 | 'auth' => $auth, |
| 217 | 'has_capacity' => $has_cap, |
| 218 | 'orders' => $list, |
| 219 | 'itemid' => $input->getUint('Itemid', null), |
| 220 | ); |
| 221 | |
| 222 | // build appointments HTML table |
| 223 | $html = JLayoutHelper::render('emparea.dayorders', $data); |
| 224 | |
| 225 | // return list to caller |
| 226 | $this->sendJSON(json_encode($html)); |
| 227 | } |
| 228 | |
| 229 | /** |
| 230 | * Redirects the users to the main records list. |
| 231 | * |
| 232 | * @return void |
| 233 | * |
| 234 | * @since 1.7 |
| 235 | */ |
| 236 | public function cancel() |
| 237 | { |
| 238 | $this->setRedirect('index.php?option=com_vikappointments&view=emplogin'); |
| 239 | } |
| 240 | } |
| 241 |