PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.6.6
VikBooking Hotel Booking Engine & PMS v1.6.6
1.8.16 1.8.15 1.8.14 1.8.13 1.8.12 1.8.11 1.8.10 1.8.9 1.8.6 1.8.7 1.8.8 trunk 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 All 37 releases
vikbooking / libraries / mvc / admin / controllers / override.php

override.php in VikBooking Hotel Booking Engine & PMS 1.6.6, at libraries/mvc/admin/controllers/override.php

334 lines 7.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package VikBooking
4 * @subpackage core
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2023 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 JLoader::import('adapter.mvc.controllers.admin');
15
16 /**
17 * VikBooking plugin Override controller.
18 *
19 * @since 1.6.5
20 */
21 class VikBookingControllerOverride extends JControllerAdmin
22 {
23 /**
24 * Task used to save the record data set in the request.
25 * After saving, the user is redirected to the management
26 * page of the record that has been saved.
27 *
28 * @return boolean
29 */
30 public function save()
31 {
32 $app = JFactory::getApplication();
33
34 $ajax = wp_doing_ajax();
35
36 if (!JSession::checkToken())
37 {
38 // missing CSRF-proof token
39 if ($ajax)
40 {
41 // ajax request
42 VBOHttpDocument::getInstance($app)->close(403, JText::translate('JINVALID_TOKEN'));
43 }
44 else
45 {
46 // post request
47 throw new Exception(JText::translate('JINVALID_TOKEN'), 403);
48 }
49 }
50
51 // make sure the user is authorised to manage overrides
52 if (!JFactory::getUser()->authorise('core.admin', 'com_vikbooking'))
53 {
54 // action denied
55 if ($ajax)
56 {
57 // ajax request
58 VBOHttpDocument::getInstance($app)->close(403, JText::translate('JERROR_ALERTNOAUTHOR'));
59 }
60 else
61 {
62 // post request
63 throw new Exception(JText::translate('JERROR_ALERTNOAUTHOR'), 403);
64 }
65 }
66
67 // get selected file and override
68 $client = $app->input->getString('client', 'site');
69 $status = $app->input->getString('status', '');
70 $file = $app->input->getBase64('selectedfile', '');
71 $override = $app->input->getBase64('overridefile', '');
72
73 // build return URL
74 $url = sprintf(
75 'admin.php?page=vikbooking&view=overrides&client=%s&selectedfile=%s&overridefile=%s',
76 $client,
77 $file,
78 $override
79 );
80
81 if ($status !== '')
82 {
83 $url .= '&status=' . (int) $status;
84 }
85
86 // register redirect URL
87 $this->setRedirect($url);
88
89 // build save data
90 $data = [];
91 $data['file'] = base64_decode($override);
92 $data['code'] = $app->input->get('code', '', 'raw');
93
94 if (empty($data['code']))
95 {
96 $error = __('No code received', 'vikbooking');
97
98 // missing code data
99 if ($ajax)
100 {
101 // ajax request
102 VBOHttpDocument::getInstance($app)->close(400, $error);
103 }
104 else
105 {
106 // post request, enqueue message and do redirect
107 $app->enqueueMessage($error, 'error');
108
109 return false;
110 }
111 }
112
113 // load overrides model
114 $overridesModel = $this->getModel('overrides', 'VikBookingModel');
115
116 // make sure the override we are going to create/update is supported
117 $supported = $overridesModel->isSupported($client, $data['file']);
118
119 if (!$supported)
120 {
121 $error = sprintf(__('Cannot use the file as destination: [%s]', 'vikbooking'), $data['file']);
122
123 // path not supported
124 if ($ajax)
125 {
126 // ajax request
127 VBOHttpDocument::getInstance($app)->close(500, $error);
128 }
129 else
130 {
131 // post request, enqueue message and do redirect
132 $app->enqueueMessage($error, 'error');
133
134 return false;
135 }
136 }
137
138 // dispatch model to save the item
139 if (!$this->model->save($data))
140 {
141 // get string error
142 $error = $this->model->getError(null, false);
143
144 if (!$error instanceof Exception)
145 {
146 $error = new Exception($error ?: 'Unknown', 500);
147 }
148
149 $string = JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $error->getMessage());
150
151 if ($ajax)
152 {
153 // ajax request
154 VBOHttpDocument::getInstance($app)->close($error->getCode() ?: 500, $string);
155 }
156 else
157 {
158 // post request, enqueue message and do redirect
159 $app->enqueueMessage($string, 'error');
160
161 return false;
162 }
163 }
164
165 if ($ajax)
166 {
167 // exit in case of AJAX request
168 VBOHttpDocument::getInstance($app)->json(1);
169 }
170
171 // display generic successful message
172 $app->enqueueMessage(JText::translate('JLIB_APPLICATION_SAVE_SUCCESS'));
173
174 return true;
175 }
176
177 /**
178 * Deletes a list of records set in the request.
179 *
180 * @return boolean
181 */
182 public function delete()
183 {
184 $app = JFactory::getApplication();
185
186 if (!JSession::checkToken() && !JSession::checkToken('get'))
187 {
188 // missing CSRF-proof token
189 throw new Exception(JText::translate('JINVALID_TOKEN'), 403);
190 }
191
192 // make sure the user is authorised to manage overrides
193 if (!JFactory::getUser()->authorise('core.admin', 'com_vikbooking'))
194 {
195 // action denied
196 throw new Exception(JText::translate('JERROR_ALERTNOAUTHOR', 403));
197 }
198
199 // get selected file and override
200 $client = $app->input->getString('client', 'site');
201 $status = $app->input->getString('status', '');
202 $file = $app->input->getBase64('selectedfile', '');
203 $override = $app->input->getBase64('overridefile', '');
204
205 // build return URL
206 $url = sprintf(
207 'admin.php?page=vikbooking&view=overrides&client=%s&selectedfile=%s&overridefile=%s',
208 $client,
209 $file,
210 $override
211 );
212
213 if ($status !== '')
214 {
215 $url .= '&status=' . (int) $status;
216 }
217
218 // register redirect URL
219 $this->setRedirect($url);
220
221 // fetch file PK
222 $pk = base64_decode($override);
223
224 // load overrides model
225 $overridesModel = $this->getModel('overrides', 'VikBookingModel');
226
227 // make sure the override we are going to delete is supported
228 $supported = $overridesModel->isSupported($client, $pk);
229
230 if (!$supported)
231 {
232 // invalid file
233 $app->enqueueMessage(sprintf('The file to remove is not an override: [%s]', $pk), 'error');
234
235 return false;
236 }
237
238 // dispatch model to delete the item
239 if ($this->model->delete($pk))
240 {
241 $app->enqueueMessage(__('1 item deleted.', 'vikbooking'));
242 }
243
244 return true;
245 }
246
247 /**
248 * Task used to publish/unpublish an existing override.
249 *
250 * @return boolean
251 */
252 public function publish()
253 {
254 $app = JFactory::getApplication();
255
256 if (!JSession::checkToken() && !JSession::checkToken('get'))
257 {
258 // missing CSRF-proof token
259 throw new Exception(JText::translate('JINVALID_TOKEN'), 403);
260 }
261
262 $state = $app->input->get('task') == 'unpublish' ? false : true;
263
264 // make sure the user is authorised to manage overrides
265 if (!JFactory::getUser()->authorise('core.admin', 'com_vikbooking'))
266 {
267 // action denied
268 throw new Exception(JText::translate('JERROR_ALERTNOAUTHOR', 403));
269 }
270
271 // get selected file and override
272 $client = $app->input->getString('client', 'site');
273 $status = $app->input->getString('status', '');
274 $file = $app->input->getBase64('selectedfile', '');
275 $override = $app->input->getBase64('overridefile', '');
276
277 // build return URL
278 $url = sprintf(
279 'admin.php?page=vikbooking&view=overrides&client=%s&selectedfile=%s&overridefile=%s',
280 $client,
281 $file,
282 $override
283 );
284
285 if ($status !== '')
286 {
287 $url .= '&status=' . (int) $status;
288 }
289
290 // register redirect URL
291 $this->setRedirect($url);
292
293 // fetch file PK
294 $pk = base64_decode($override);
295
296 // load overrides model
297 $overridesModel = $this->getModel('overrides', 'VikBookingModel');
298
299 // make sure the override we are going to toggle is supported
300 $supported = $overridesModel->isSupported($client, $pk);
301
302 if (!$supported)
303 {
304 // invalid file
305 $app->enqueueMessage(sprintf('The file to publish is not an override: [%s]', $pk), 'error');
306
307 return false;
308 }
309
310 // dispatch model to toggle the item
311 $this->model->publish($pk, $state);
312
313 return true;
314 }
315
316 /**
317 * AJAX end-point used to dismiss the breaking changes.
318 *
319 * @return void
320 */
321 public function dismissbc()
322 {
323 $app = JFactory::getApplication();
324
325 // get a list of specified files, if any
326 $files = $app->input->get('files', null, 'string');
327
328 // unregister breaking changes
329 VikBookingInstaller::unregisterBreakingChanges($files);
330
331 $this->sendJSON(1);
332 }
333 }
334