analytics.php
4 years ago
apiban.php
4 years ago
apilog.php
4 years ago
apiplugin.php
4 years ago
apiuser.php
4 years ago
backup.php
4 years ago
calendar.php
4 years ago
city.php
4 years ago
closure.php
1 month ago
configapp.php
4 years ago
configcldays.php
2 years ago
configcron.php
4 years ago
configemp.php
4 years ago
configsmsapi.php
4 years ago
configuration.php
1 month ago
conversion.php
1 year ago
country.php
4 years ago
coupon.php
4 years ago
coupongroup.php
4 years ago
cronjob.php
2 years ago
cronjoblog.php
4 years ago
customer.php
4 months ago
customf.php
1 year ago
dashboard.php
4 years ago
emplocwdays.php
4 years ago
employee.php
1 year ago
emprates.php
4 years ago
export.php
4 years ago
exportres.php
4 years ago
file.php
4 months ago
findreservation.php
1 month ago
group.php
4 years ago
import.php
4 years ago
index.html
4 years ago
invoice.php
1 month ago
langcustomf.php
4 years ago
langemployee.php
4 years ago
langgroup.php
4 years ago
langmedia.php
4 years ago
langoption.php
4 years ago
langoptiongroup.php
4 years ago
langpackage.php
4 years ago
langpackgroup.php
4 years ago
langpayment.php
4 years ago
langservice.php
4 years ago
langstatuscode.php
4 years ago
langsubscr.php
4 years ago
langtax.php
4 years ago
location.php
4 years ago
mailtext.php
2 years ago
makerecurrence.php
1 month ago
media.php
4 years ago
multiorder.php
4 years ago
option.php
4 months ago
optiongroup.php
4 years ago
package.php
2 years ago
packgroup.php
4 years ago
packorder.php
1 year ago
payment.php
4 years ago
rate.php
4 years ago
reportsemp.php
4 years ago
reportsser.php
4 years ago
reservation.php
1 month ago
restriction.php
4 years ago
review.php
4 years ago
service.php
1 year ago
serworkday.php
4 months ago
state.php
4 years ago
statuscode.php
4 years ago
subscription.php
4 years ago
subscrorder.php
4 years ago
tag.php
4 years ago
tax.php
4 years ago
usernote.php
4 years ago
waitinglist.php
4 years ago
webhook.php
4 years ago
wizard.php
1 year ago
wizard.php
237 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 wizard controller. |
| 18 | * |
| 19 | * @since 1.7.1 |
| 20 | */ |
| 21 | class VikAppointmentsControllerWizard extends VAPControllerAdmin |
| 22 | { |
| 23 | /** |
| 24 | * Task used to dismiss the wizard. |
| 25 | * |
| 26 | * @return void |
| 27 | */ |
| 28 | public function done() |
| 29 | { |
| 30 | // check user permissions |
| 31 | if (JFactory::getUser()->authorise('core.admin', 'com_vikappointments')) |
| 32 | { |
| 33 | // get wizard instance |
| 34 | $wizard = VAPFactory::getWizard(); |
| 35 | |
| 36 | // dismiss the wizard |
| 37 | $wizard->done(); |
| 38 | } |
| 39 | else |
| 40 | { |
| 41 | // not authorised to dismiss the wizard |
| 42 | $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error'); |
| 43 | } |
| 44 | |
| 45 | // back to dashboard |
| 46 | $this->cancel(); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Task used to restore the wizard. |
| 51 | * |
| 52 | * @return void |
| 53 | */ |
| 54 | public function restore() |
| 55 | { |
| 56 | // check user permissions |
| 57 | if (JFactory::getUser()->authorise('core.admin', 'com_vikappointments')) |
| 58 | { |
| 59 | // get wizard instance |
| 60 | $wizard = VAPFactory::getWizard(); |
| 61 | |
| 62 | // restore the wizard |
| 63 | $wizard->restore(); |
| 64 | } |
| 65 | else |
| 66 | { |
| 67 | // not authorised to dismiss the wizard |
| 68 | $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error'); |
| 69 | } |
| 70 | |
| 71 | // back to dashboard |
| 72 | $this->cancel(); |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Redirects the users to the main records list. |
| 77 | * |
| 78 | * @return void |
| 79 | */ |
| 80 | public function cancel() |
| 81 | { |
| 82 | $this->setRedirect('index.php?option=com_vikappointments'); |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * AJAX end-point used to process the wizard step. |
| 87 | * |
| 88 | * @return void |
| 89 | */ |
| 90 | public function process() |
| 91 | { |
| 92 | $this->executeRole('process'); |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * AJAX end-point used to dismiss a step. |
| 97 | * |
| 98 | * @return void |
| 99 | */ |
| 100 | public function dismiss() |
| 101 | { |
| 102 | $this->executeRole('dismiss'); |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * AJAX end-point used to ignore a step. |
| 107 | * |
| 108 | * @return void |
| 109 | */ |
| 110 | public function ignore() |
| 111 | { |
| 112 | $this->executeRole('ignore'); |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Helper method used to execute the given role. |
| 117 | * |
| 118 | * @return void |
| 119 | */ |
| 120 | protected function executeRole($role) |
| 121 | { |
| 122 | $input = JFactory::getApplication()->input; |
| 123 | $user = JFactory::getUser(); |
| 124 | |
| 125 | // check user permissions |
| 126 | if (!$user->authorise('core.admin', 'com_vikappointments')) |
| 127 | { |
| 128 | // not authorised, raise AJAX error |
| 129 | UIErrorFactory::raiseError(403, JText::translate('JERROR_ALERTNOAUTHOR')); |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * Added token validation. |
| 134 | * |
| 135 | * @since 1.7.8 |
| 136 | */ |
| 137 | if (!JSession::checkToken()) |
| 138 | { |
| 139 | // missing CSRF-proof token |
| 140 | UIErrorFactory::raiseError(403, JText::translate('JINVALID_TOKEN')); |
| 141 | } |
| 142 | |
| 143 | // instantiate wizard |
| 144 | $wizard = VAPFactory::getWizard(); |
| 145 | |
| 146 | // recover step from request |
| 147 | $id = $input->get('id', '', 'string'); |
| 148 | |
| 149 | // find registered step |
| 150 | $index = $wizard->indexOf($id); |
| 151 | |
| 152 | if ($index === false) |
| 153 | { |
| 154 | // step not found, raise AJAX error |
| 155 | UIErrorFactory::raiseError(404, sprintf('Wizard step [%s] not found.', $id)); |
| 156 | } |
| 157 | |
| 158 | // get step at index |
| 159 | $step = $wizard->getStep($index); |
| 160 | |
| 161 | // recover step configuration |
| 162 | $config = $input->get('wizard', array(), 'array'); |
| 163 | |
| 164 | // take only the parameters related to this step |
| 165 | $params = isset($config[$id]) ? $config[$id] : array(); |
| 166 | |
| 167 | try |
| 168 | { |
| 169 | if ($role == 'process') |
| 170 | { |
| 171 | // try to execute the step |
| 172 | $step->execute($params); |
| 173 | } |
| 174 | else if ($role == 'ignore') |
| 175 | { |
| 176 | // ignore the step |
| 177 | $step->ignore(); |
| 178 | } |
| 179 | else if ($role == 'dismiss') |
| 180 | { |
| 181 | // dismiss the step |
| 182 | $step->dismiss(); |
| 183 | } |
| 184 | } |
| 185 | catch (Exception $e) |
| 186 | { |
| 187 | // raise AJAX error |
| 188 | UIErrorFactory::raiseError($e->getCode(), $e->getMessage()); |
| 189 | } |
| 190 | |
| 191 | // prepare response |
| 192 | $response = array(); |
| 193 | $response['steps'] = array(); |
| 194 | |
| 195 | // create step layout file |
| 196 | $layout = new JLayoutFile('wizard.step'); |
| 197 | |
| 198 | if ($step->isVisible()) |
| 199 | { |
| 200 | // reload the layout of the step |
| 201 | $response['steps'][$id] = $layout->render(array('step' => $step)); |
| 202 | } |
| 203 | else |
| 204 | { |
| 205 | // hide step |
| 206 | $response['steps'][$id] = false; |
| 207 | } |
| 208 | |
| 209 | // check whether all the visible steps should be reloaded |
| 210 | $reload_all = $input->getBool('reload_all', false); |
| 211 | |
| 212 | // iterate all the steps |
| 213 | foreach ($wizard as $dep) |
| 214 | { |
| 215 | // check if this step depends on the previous one |
| 216 | if (($dep !== $step && $dep->hasDependency($step)) || $reload_all) |
| 217 | { |
| 218 | if ($dep->isVisible()) |
| 219 | { |
| 220 | // reload the layout of the dependency too |
| 221 | $response['steps'][$dep->getID()] = $layout->render(array('step' => $dep)); |
| 222 | } |
| 223 | else |
| 224 | { |
| 225 | // dependency not visible |
| 226 | $response['steps'][$dep->getID()] = false; |
| 227 | } |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | // calculate overall progress |
| 232 | $response['progress'] = $wizard->getProgress(); |
| 233 | |
| 234 | $this->sendJSON($response); |
| 235 | } |
| 236 | } |
| 237 |