PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.7.2
VikBooking Hotel Booking Engine & PMS v1.7.2
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 / admin / controllers / report.php

report.php in VikBooking Hotel Booking Engine & PMS 1.7.2, at admin/controllers/report.php

138 lines 4.3 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) 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 /**
15 * VikBooking report controller.
16 *
17 * @since 1.17.1 (J) - 1.7.1 (WP)
18 */
19 class VikBookingControllerReport extends JControllerAdmin
20 {
21 /**
22 * AJAX endpoint to render the custom settings of a report.
23 *
24 * @return void
25 */
26 public function renderSettings()
27 {
28 $app = JFactory::getApplication();
29
30 if (!JSession::checkToken()) {
31 // missing CSRF-proof token
32 VBOHttpDocument::getInstance($app)->close(403, JText::translate('JINVALID_TOKEN'));
33 }
34
35 $report = $app->input->getString('report', '');
36
37 $report_obj = VikBooking::getReportInstance($report);
38
39 if (!$report_obj) {
40 // invalid report requested
41 VBOHttpDocument::getInstance($app)->close(404, sprintf('Could not find the report [%s] to load the settings from.', $report));
42 }
43
44 // fetch the report form settings
45 $layout_data = [
46 'report' => $report,
47 'fields' => $report_obj->getSettingFields(),
48 'settings' => $report_obj->loadSettings(),
49 'instance' => $report_obj,
50 ];
51
52 $form_html = JLayoutHelper::render('reports.report.settings', $layout_data, null, [
53 'component' => 'com_vikbooking',
54 'client' => 'administrator',
55 ]);
56
57 // send the response to output
58 VBOHttpDocument::getInstance($app)->json([
59 'html' => $form_html,
60 ]);
61 }
62
63 /**
64 * AJAX endpoint to save the custom settings of a report.
65 *
66 * @return void
67 */
68 public function saveSettings()
69 {
70 $app = JFactory::getApplication();
71
72 if (!JSession::checkToken()) {
73 // missing CSRF-proof token
74 VBOHttpDocument::getInstance($app)->close(403, JText::translate('JINVALID_TOKEN'));
75 }
76
77 $report = $app->input->getString('report', '');
78 $data = $app->input->get('data', [], 'array');
79
80 $report_obj = VikBooking::getReportInstance($report);
81
82 if (!$report_obj) {
83 // invalid report requested
84 VBOHttpDocument::getInstance($app)->close(404, sprintf('Could not find the report [%s] to save the settings for.', $report));
85 }
86
87 $report_obj->saveSettings($data, $merge = true);
88
89 // send the response to output
90 VBOHttpDocument::getInstance($app)->json([
91 'success' => 1,
92 ]);
93 }
94
95 /**
96 * AJAX endpoint to execute a custom scoped action of a report.
97 *
98 * @return void
99 */
100 public function executeCustomAction()
101 {
102 $app = JFactory::getApplication();
103
104 if (!JSession::checkToken()) {
105 // missing CSRF-proof token
106 VBOHttpDocument::getInstance($app)->close(403, JText::translate('JINVALID_TOKEN'));
107 }
108
109 $report = $app->input->getString('report_file', '');
110 $action = $app->input->getString('report_action', '');
111 $scope = $app->input->getString('report_scope', '');
112 $data = $app->input->get('report_data', [], 'array');
113
114 $report_obj = VikBooking::getReportInstance($report);
115
116 if (!$report_obj) {
117 // invalid report requested
118 VBOHttpDocument::getInstance($app)->close(404, sprintf('Could not find the report [%s] for executing the action.', $report));
119 }
120
121 // get all the available scoped actions, hidden and visible
122 $actions = $report_obj->getScopedActions($scope, $visible = false);
123 if (!in_array($action, array_column($actions, 'id'))) {
124 // unsupported action
125 VBOHttpDocument::getInstance($app)->close(403, sprintf('Unsupported report action [%s].', $action));
126 }
127
128 try {
129 $result = $report_obj->executeAction($action, $scope, $data);
130 } catch (Exception $e) {
131 VBOHttpDocument::getInstance($app)->close($e->getCode(), $e->getMessage());
132 }
133
134 // send the response to output
135 VBOHttpDocument::getInstance($app)->json($result);
136 }
137 }
138