1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* You may not change or alter any portion of this comment or credits |
5
|
|
|
* of supporting developers from this source code or any supporting source code |
6
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
7
|
|
|
* |
8
|
|
|
* This program is distributed in the hope that it will be useful, |
9
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
10
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @copyright {@link https://xoops.org/ XOOPS Project} |
15
|
|
|
* @license {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later} |
16
|
|
|
* @author Brian Wahoff <[email protected]> |
17
|
|
|
* @author Eric Juden <[email protected]> |
18
|
|
|
* @author XOOPS Development Team |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
use Xmf\Request; |
22
|
|
|
use XoopsModules\Xhelp; |
23
|
|
|
use Amenadiel\JpGraph\Plot; |
24
|
|
|
|
25
|
|
|
require_once __DIR__ . '/header.php'; |
26
|
|
|
require_once XHELP_INCLUDE_PATH . '/events.php'; |
27
|
|
|
|
28
|
|
|
//if (!file_exists(XHELP_JPGRAPH_PATH . '/jpgraph.php')) { |
29
|
|
|
// $helper->redirect('index.php', 5, _XHELP_TEXT_NO_JPGRAPH); |
30
|
|
|
//} |
31
|
|
|
|
32
|
|
|
// require_once XHELP_CLASS_PATH . '/reportFactory.php'; |
33
|
|
|
// require_once XHELP_CLASS_PATH . '/ReportRendererFactory.php'; |
34
|
|
|
|
35
|
|
|
if (!$xhelp_isStaff) { // Is user a staff member? |
36
|
|
|
$helper->redirect('index.php', 3, _AM_XHELP_NO_PERM); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
$op = 'default'; |
40
|
|
|
if (Request::hasVar('op', 'GET')) { |
41
|
|
|
$op = $_GET['op']; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
switch ($op) { |
45
|
|
|
case 'run': |
46
|
|
|
if (!isset($_REQUEST['name']) && '' == \Xmf\Request::getString('name', '', 'REQUEST')) { |
47
|
|
|
$helper->redirect('report.php', 3, _XHELP_MSG_NO_REPORT); |
48
|
|
|
} |
49
|
|
|
$reportName = \Xmf\Request::getString('name', '', 'REQUEST'); |
50
|
|
|
/* |
51
|
|
|
if (!array_key_exists($reportName, $reports)) { // If the report name is not in the acceptable names array |
52
|
|
|
redirect_header(XHELP_BASE_URL .'/report.php', 3, _XHELP_MSG_NO_REPORT_LOAD); |
53
|
|
|
} |
54
|
|
|
*/ |
55
|
|
|
runReport($reportName); |
56
|
|
|
break; |
57
|
|
|
case 'graph': |
58
|
|
|
if (!isset($_GET['name']) && '' == \Xmf\Request::getString('name', '', 'GET')) { |
59
|
|
|
$helper->redirect('report.php', 3, _XHELP_MSG_NO_REPORT); |
60
|
|
|
} |
61
|
|
|
$reportName = \Xmf\Request::getString('name', '', 'REQUEST'); |
62
|
|
|
/*if (!array_key_exists($reportName, $reports)) { // If the report name is not in the acceptable names array |
63
|
|
|
redirect_header(XHELP_BASE_URL .'/report.php', 3, _XHELP_MSG_NO_REPORT_LOAD); |
64
|
|
|
}*/ |
65
|
|
|
makeGraph($reportName); |
66
|
|
|
break; |
67
|
|
|
default: // Display list of reports |
68
|
|
|
$reports = Xhelp\ReportFactory::getReports(); |
69
|
|
|
|
70
|
|
|
$rptNames = []; |
71
|
|
|
foreach ($reports as $rpt => $obj) { |
72
|
|
|
$rptNames[] = $rpt; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
displayReports(); |
76
|
|
|
break; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
function displayReports() |
80
|
|
|
{ |
81
|
|
|
global $xoopsOption, $xoopsTpl, $xoopsConfig, $xoopsUser; |
82
|
|
|
|
83
|
|
|
$GLOBALS['xoopsOption']['template_main'] = 'xhelp_report.tpl'; // Set template |
84
|
|
|
require_once XOOPS_ROOT_PATH . '/header.php'; // Include page header |
85
|
|
|
|
86
|
|
|
$aReports = getReportsMeta(); |
87
|
|
|
|
88
|
|
|
$xoopsTpl->assign('xhelp_imagePath', XHELP_IMAGE_URL . '/'); |
89
|
|
|
$xoopsTpl->assign('xhelp_reports', $aReports); |
90
|
|
|
$xoopsTpl->assign('xhelp_baseURL', XHELP_BASE_URL); |
91
|
|
|
|
92
|
|
|
require_once XOOPS_ROOT_PATH . '/footer.php'; // Include page footer |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @return array |
97
|
|
|
*/ |
98
|
|
|
function getReportsMeta(): array |
99
|
|
|
{ |
100
|
|
|
global $reports; |
101
|
|
|
|
102
|
|
|
$aMeta = []; |
103
|
|
|
foreach ($reports as $name => $report) { |
104
|
|
|
$aMeta[$name] = $report->meta; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
return $aMeta; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @param string $reportName |
112
|
|
|
*/ |
113
|
|
|
function runReport(string $reportName) |
114
|
|
|
{ |
115
|
|
|
global $xoopsOption, $xoopsTpl, $xoopsConfig, $xoopsUser, $xhelp_module_header, $paramVals; |
116
|
|
|
|
117
|
|
|
// $classname = 'xhelp' . $reportName . 'Report'; |
118
|
|
|
// require_once XHELP_REPORT_PATH . '/' . $reportName . '.php'; |
119
|
|
|
// if( strpos($filename,'Report') !== false ) { |
120
|
|
|
// $classname = 'XoopsModules\Xhelp\Reports\\' . \ucfirst($reportName). 'Report'; |
121
|
|
|
$classname = 'XoopsModules\Xhelp\Reports\\' . \ucfirst($reportName); |
122
|
|
|
if (!\class_exists($classname)) { |
123
|
|
|
throw new \RuntimeException("Class '$classname' not found"); |
124
|
|
|
} |
125
|
|
|
$report = new $classname(); |
126
|
|
|
|
127
|
|
|
// Get any parameters for report |
128
|
|
|
$reportParams = $report->getParams(); |
129
|
|
|
|
130
|
|
|
// Fill reportParameters with updated information |
131
|
|
|
if (is_countable($reportParams) && count($reportParams) > 0) { |
132
|
|
|
foreach ($reportParams as $param) { |
133
|
|
|
if (isset($_REQUEST[$param->fieldname])) { |
134
|
|
|
if (XHELP_CONTROL_DATETIME == $param->controltype) { |
135
|
|
|
$param->value = strtotime($_REQUEST[$param->fieldname]); |
136
|
|
|
} else { |
137
|
|
|
$param->value = $_REQUEST[$param->fieldname]; |
138
|
|
|
} |
139
|
|
|
} else { |
140
|
|
|
if (isset($paramVals[$param->fieldname])) { |
141
|
|
|
if (XHELP_CONTROL_DATETIME == $param->controltype) { |
142
|
|
|
$param->value = strtotime($paramVals[$param->fieldname]); |
143
|
|
|
} else { |
144
|
|
|
if (is_array($paramVals[$param->fieldname])) { |
145
|
|
|
$param->values = $paramVals[$param->fieldname]; |
146
|
|
|
} else { |
147
|
|
|
$param->value = $paramVals[$param->fieldname]; |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
$report->extraWhere = $report->makeWhere($reportParams); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
//$GLOBALS['xoopsOption']['template_main'] = 'xhelp_report.tpl'; // Set template |
157
|
|
|
require_once XOOPS_ROOT_PATH . '/header.php'; // Include page header |
158
|
|
|
|
159
|
|
|
generateHeader($report); |
160
|
|
|
|
161
|
|
|
/** @var \XoopsModules\Xhelp\ReportRenderer\HtmlReportRenderer $oRenderer */ |
162
|
|
|
$oRenderer = Xhelp\ReportRendererFactory::getRenderer('html', $report); |
|
|
|
|
163
|
|
|
echo $oRenderer->render(); |
164
|
|
|
|
165
|
|
|
$xoopsTpl->assign('xhelp_imagePath', XHELP_IMAGE_URL . '/'); |
166
|
|
|
$xoopsTpl->assign('xoops_module_header', $xhelp_module_header); |
167
|
|
|
|
168
|
|
|
require_once XOOPS_ROOT_PATH . '/footer.php'; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @param string $reportName |
173
|
|
|
*/ |
174
|
|
|
function makeGraph(string $reportName) |
175
|
|
|
{ |
176
|
|
|
// $classname = 'xhelp' . $reportName . 'Report'; |
177
|
|
|
// require_once XHELP_REPORT_PATH . '/' . $reportName . '.php'; |
178
|
|
|
$classname = 'XoopsModules\Xhelp\Reports\\' . \ucfirst($reportName); |
179
|
|
|
if (!\class_exists($classname)) { |
180
|
|
|
throw new \RuntimeException("Class '$classname' not found"); |
181
|
|
|
} |
182
|
|
|
$report = new $classname(); |
183
|
|
|
|
184
|
|
|
// Get any parameters for report |
185
|
|
|
$reportParams = $report->getParams(); |
186
|
|
|
|
187
|
|
|
// Fill reportParameters with updated information |
188
|
|
|
foreach ($reportParams as $param) { |
189
|
|
|
if (isset($_REQUEST[$param->fieldname])) { |
190
|
|
|
if (XHELP_CONTROL_DATETIME == $param->controltype) { |
191
|
|
|
$param->value = strtotime(\Xmf\Request::getString($param->fieldname, '', 'REQUEST')); |
192
|
|
|
} else { |
193
|
|
|
$param->value = \Xmf\Request::getString($param->fieldname, '', 'REQUEST'); |
194
|
|
|
} |
195
|
|
|
} |
196
|
|
|
} |
197
|
|
|
$report->extraWhere = $report->makeWhere($reportParams); |
198
|
|
|
|
199
|
|
|
$report->generateGraph(); // Display graph |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* @param Report $report |
204
|
|
|
*/ |
205
|
|
|
function generateHeader(Report $report) |
|
|
|
|
206
|
|
|
{ |
207
|
|
|
global $paramVals; |
208
|
|
|
|
209
|
|
|
// Get any parameters for report |
210
|
|
|
$reportParams = $report->getParams(); |
211
|
|
|
|
212
|
|
|
if (is_countable($reportParams) && count($reportParams) > 0) { |
213
|
|
|
echo "<div id='xhelp_reportParams'>"; |
214
|
|
|
echo "<form method='post' action='" . XHELP_BASE_URL . '/report.php?op=run&name=' . $report->name . "'>"; |
215
|
|
|
|
216
|
|
|
foreach ($reportParams as $param) { |
217
|
|
|
echo $param->displayParam($paramVals); |
218
|
|
|
} |
219
|
|
|
echo "<input type='submit' name='updateReport' id='updateReport' value='" . _XHELP_TEXT_VIEW_REPORT . "'>"; |
220
|
|
|
echo '</div>'; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
// display report name |
224
|
|
|
echo "<div id='xhelp_reportHeader'>"; |
225
|
|
|
echo '<h2>' . $report->meta['name'] . '</h2>'; |
226
|
|
|
echo '</div>'; |
227
|
|
|
} |
228
|
|
|
|