forked from timschofield/webERP
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAuditScripts.php
More file actions
217 lines (189 loc) · 7.54 KB
/
AuditScripts.php
File metadata and controls
217 lines (189 loc) · 7.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<?php
require(__DIR__ . '/includes/session.php');
$Title = __('Audit Scripts');
include(__DIR__ . '/includes/header.php');
include(__DIR__ . '/includes/UIGeneralFunctions.php');
echo '<p class="page_title_text"><img src="' . $RootPath . '/css/' . $Theme . '/images/maintenance.png" title="'
. __('Search') . '" alt="" />' . ' ' . $Title . '</p>';
if (!isset($_POST['FromDate'])) {
$_POST['FromDate'] = date($_SESSION['DefaultDateFormat']);
}
if (!isset($_POST['ToDate'])) {
$_POST['ToDate'] = date($_SESSION['DefaultDateFormat']);
}
if (isset($_POST['ContainingText'])) {
$ContainingText = trim(mb_strtoupper($_POST['ContainingText']));
} elseif (isset($_GET['ContainingText'])) {
$ContainingText = trim(mb_strtoupper($_GET['ContainingText']));
}
if (!isset($_POST['ContainingText'])) {
$_POST['ContainingText'] = '';
}
if (!isset($_POST['DetailedReport'])) {
$_POST['DetailedReport'] = 'No';
}
echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '" method="post">';
echo '<div>';
echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
echo '<fieldset>
<legend>' . __('Audit Script Selection Criteria') . '</legend>';
echo FieldToSelectOneDate('FromDate', FormatDateForSQL($_POST['FromDate']), __('From Date'), '', '', '1', true, true);
echo FieldToSelectOneDate('ToDate', FormatDateForSQL($_POST['ToDate']), __('To Date'), '', '', '2', true, false);
echo FieldToSelectOneUser('SelectedUser', isset($_POST['SelectedUser']) ? $_POST['SelectedUser'] : 'All', __('User ID'), '', '', '3', true, false);
echo FieldToSelectOneText('ContainingText', $_POST['ContainingText'], 80, 80, __('Containing text'), '', '', '4', false, false);
echo FieldToSelectFromTwoOptions('No', __('Summary Report'),
'Yes', __('Detailed Report'),
'DetailedReport', $_POST['DetailedReport'], __('Summary or detailed report'), '', '', '5', true, false);
echo '</fieldset>';
echo OneButtonCenteredForm('View', __('View'));
echo '</div>
</form>';
// View the audit trail
if (isset($_POST['View'])) {
$FromDate = str_replace('/', '-', FormatDateForSQL($_POST['FromDate']) . ' 00:00:00');
$ToDate = str_replace('/', '-', FormatDateForSQL($_POST['ToDate']) . ' 23:59:59');
if (mb_strlen($ContainingText) > 0) {
$ContainingText = " AND scripttitle LIKE '%" . $ContainingText . "%' ";
} else {
$ContainingText = "";
}
if ($_POST['SelectedUser'] == 'All') {
$UserSQL = " ";
} else {
$UserSQL = " AND userid='" . $_POST['SelectedUser'] . "'";
}
/**************************************************************
SCRIPT USAGE
***************************************************************/
$SQL = "SELECT scripttitle,
COUNT(scripttitle) AS numscripts,
SUM(secondsrunning) AS sumseconds
FROM auditscripts
WHERE executiondate BETWEEN '" . $FromDate . "' AND '" . $ToDate . "'"
. $UserSQL
. $ContainingText
. ' GROUP BY scripttitle';
$Result = DB_query($SQL);
echo '<p class="page_title_text" align="center"><strong>' . 'General Script Usage' . '</strong></p>';
echo '<div>';
echo '<table class="selection">';
echo '<thead>
<tr>
<th class="SortedColumn">' . __('Script') . '</th>
<th class="SortedColumn">' . __('# Executions') . '</th>
<th class="SortedColumn">' . __('Seconds Needed') . '</th>
<th class="SortedColumn">' . __('Secs/Execution') . '</th>
</tr>
</thead>';
echo '<tbody>';
$TotalScripts = 0;
$TotalSeconds = 0;
while ($MyRow = DB_fetch_array($Result)) {
$SecsPerExecution = $MyRow['numscripts'] > 0 ? $MyRow['sumseconds'] / $MyRow['numscripts'] : 0;
echo '<tr class="striped_row">
<td>' . $MyRow['scripttitle'] . '</td>
<td class="number">' . locale_number_format($MyRow['numscripts'], 0) . '</td>
<td class="number">' . locale_number_format($MyRow['sumseconds'], 5) . '</td>
<td class="number">' . locale_number_format($SecsPerExecution, 5) . '</td>
</tr>';
$TotalScripts += $MyRow['numscripts'];
$TotalSeconds += $MyRow['sumseconds'];
}
echo '</tbody>';
echo '<tfooter>';
$AvgSecsPerExecution = $TotalScripts > 0 ? $TotalSeconds / $TotalScripts : 0;
echo '<tr class="striped_row">
<td>TOTALS</td>
<td class="number">' . locale_number_format($TotalScripts, 0) . '</td>
<td class="number">' . locale_number_format($TotalSeconds, 5) . '</td>
<td class="number">' . locale_number_format($AvgSecsPerExecution, 5) . '</td>
</tr>';
echo '</tfooter>';
echo '</table></div>';
/**************************************************************
USERS USAGE
***************************************************************/
$SQL = "SELECT userid,
COUNT(scripttitle) AS numscripts,
SUM(secondsrunning) AS sumseconds
FROM auditscripts
WHERE executiondate BETWEEN '" . $FromDate . "' AND '" . $ToDate . "'"
. $UserSQL
. $ContainingText
. ' GROUP BY userid';
$Result = DB_query($SQL);
echo '<p class="page_title_text" align="center"><strong>' . 'General Users Usage' . '</strong></p>';
echo '<div>';
echo '<table class="selection">';
echo '<thead>
<tr>
<th class="SortedColumn">' . __('User') . '</th>
<th class="SortedColumn">' . __('# Executions') . '</th>
<th class="SortedColumn">' . __('Seconds Needed') . '</th>
<th class="SortedColumn">' . __('Secs/Execution') . '</th>
</tr>
</thead>';
echo '<tbody>';
$TotalScripts = 0;
$TotalSeconds = 0;
while ($MyRow = DB_fetch_array($Result)) {
$SecsPerExecution = $MyRow['numscripts'] > 0 ? $MyRow['sumseconds'] / $MyRow['numscripts'] : 0;
echo '<tr class="striped_row">
<td>' . $MyRow['userid'] . '</td>
<td class="number">' . locale_number_format($MyRow['numscripts'], 0) . '</td>
<td class="number">' . locale_number_format($MyRow['sumseconds'], 5) . '</td>
<td class="number">' . locale_number_format($SecsPerExecution, 5) . '</td>
</tr>';
$TotalScripts += $MyRow['numscripts'];
$TotalSeconds += $MyRow['sumseconds'];
}
echo '</tbody>
<tfooter>';
$AvgSecsPerExecution = $TotalScripts > 0 ? $TotalSeconds / $TotalScripts : 0;
echo '<tr class="striped_row">
<td>TOTALS</td>
<td class="number">' . locale_number_format($TotalScripts, 0) . '</td>
<td class="number">' . locale_number_format($TotalSeconds, 5) . '</td>
<td class="number">' . locale_number_format($AvgSecsPerExecution, 5) . '</td>
</tr>';
echo '</tfooter>
</table>
</div>';
/**************************************************************
QUERY DETAILED
***************************************************************/
if ($_POST['DetailedReport'] == "Yes") {
$SQL = "SELECT executiondate,
userid,
secondsrunning,
scripttitle
FROM auditscripts
WHERE executiondate BETWEEN '" . $FromDate . "' AND '" . $ToDate . "'"
. $UserSQL
. $ContainingText;
$Result = DB_query($SQL);
echo '<p class="page_title_text" align="center"><strong>' . 'Detailed Script usage' . '</strong></p>';
echo '<div>';
echo '<table class="selection">';
echo '<thead>
<tr>
<th class="SortedColumn">' . __('Date/Time') . '</th>
<th class="SortedColumn">' . __('User') . '</th>
<th class="SortedColumn">' . __('Seconds') . '</th>
<th class="SortedColumn">' . __('Script') . '</th>
</tr>';
echo '</thead>';
echo '<tbody>';
while ($MyRow = DB_fetch_array($Result)) {
echo '<tr class="striped_row">
<td>' . $MyRow['executiondate'] . '</td>
<td>' . $MyRow['userid'] . '</td>
<td class="number">' . locale_number_format($MyRow['secondsrunning'], 5) . '</td>
<td>' . $MyRow['scripttitle'] . '</td>
</tr>';
}
echo '</tbody>';
echo '</table></div>';
}
}
include(__DIR__ . '/includes/footer.php');