PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / 1.2.17
VikAppointments Services Booking Calendar v1.2.17
trunk 1.2.17 1.2.18 1.2.19
vikappointments / admin / controllers / wizard.php
vikappointments / admin / controllers Last commit date
analytics.php 5 months ago apiban.php 5 months ago apilog.php 5 months ago apiplugin.php 5 months ago apiuser.php 5 months ago backup.php 5 months ago calendar.php 5 months ago city.php 5 months ago closure.php 5 months ago configapp.php 5 months ago configcldays.php 5 months ago configcron.php 5 months ago configemp.php 5 months ago configsmsapi.php 5 months ago configuration.php 5 months ago conversion.php 5 months ago country.php 5 months ago coupon.php 5 months ago coupongroup.php 5 months ago cronjob.php 5 months ago cronjoblog.php 5 months ago customer.php 5 months ago customf.php 5 months ago dashboard.php 5 months ago emplocwdays.php 5 months ago employee.php 5 months ago emprates.php 5 months ago export.php 5 months ago exportres.php 5 months ago file.php 5 months ago findreservation.php 5 months ago group.php 5 months ago import.php 5 months ago index.html 5 months ago invoice.php 5 months ago langcustomf.php 5 months ago langemployee.php 5 months ago langgroup.php 5 months ago langmedia.php 5 months ago langoption.php 5 months ago langoptiongroup.php 5 months ago langpackage.php 5 months ago langpackgroup.php 5 months ago langpayment.php 5 months ago langservice.php 5 months ago langstatuscode.php 5 months ago langsubscr.php 5 months ago langtax.php 5 months ago location.php 5 months ago mailtext.php 5 months ago makerecurrence.php 5 months ago media.php 5 months ago multiorder.php 5 months ago option.php 5 months ago optiongroup.php 5 months ago package.php 5 months ago packgroup.php 5 months ago packorder.php 5 months ago payment.php 5 months ago rate.php 5 months ago reportsemp.php 5 months ago reportsser.php 5 months ago reservation.php 5 months ago restriction.php 5 months ago review.php 5 months ago service.php 5 months ago serworkday.php 5 months ago state.php 5 months ago statuscode.php 5 months ago subscription.php 5 months ago subscrorder.php 5 months ago tag.php 5 months ago tax.php 5 months ago usernote.php 5 months ago waitinglist.php 5 months ago webhook.php 5 months ago wizard.php 5 months 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