/
stats.php
222 lines (189 loc) · 4.97 KB
/
stats.php
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
217
218
219
220
221
222
<?php
use App\Repository\BugRepository;
session_start();
// Obtain common includes
require_once '../include/prepend.php';
// Authenticate
bugs_authenticate($user, $pw, $logged_in, $user_flags);
response_header('Bugs Stats');
$titles = [
'Closed' => 'Closed',
'Open' => 'Open',
'Critical' => 'Crit',
'Verified' => 'Verified',
'Analyzed' => 'Analyzed',
'Assigned' => 'Assigned',
'Feedback' => 'Fdbk',
'No Feedback' => 'No Fdbk',
'Suspended' => 'Susp',
'Not a bug' => 'Not a bug',
'Duplicate' => 'Dupe',
'Wont fix' => 'Wont Fix',
];
$rev = isset($_GET['rev']) ? $_GET['rev'] : 1;
$sort_by = isset($_GET['sort_by']) ? $_GET['sort_by'] : 'Open';
$total = 0;
$row = [];
$pkg = [];
$pkg_tmp = [];
$pkg_total = [];
$pkg_names = [];
$all = [];
$pseudo = true;
if (!array_key_exists($sort_by, $titles)) {
$sort_by = 'Open';
}
$bug_type = $_GET['bug_type'] ?? 'All';
$bugRepository = new BugRepository($dbh);
foreach ($bugRepository->findAllByBugType($bug_type) as $row) {
$pkg_tmp[$row['status']][$row['package_name']] = $row['quant'];
@$pkg_total[$row['package_name']] += $row['quant'];
@$all[$row['status']] += $row['quant'];
@$total += $row['quant'];
$pkg_names[$row['package_name']] = 0;
}
if (count($pkg_tmp)) {
foreach ($titles as $key => $val) {
if (isset($pkg_tmp[$key]) && is_array($pkg_tmp[$key])) {
$pkg[$key] = array_merge($pkg_names, $pkg_tmp[$key]);
} else {
$pkg[$key] = $pkg_names;
}
}
}
if ($total > 0) {
if ($rev == 1) {
arsort($pkg[$sort_by]);
} else {
asort($pkg[$sort_by]);
}
}
?>
<form method="get" action="stats.php">
<table>
<tr>
<td style="white-space: nowrap">
<strong>Bug Type:</strong>
<select class="small" id="bug_type" name="bug_type" onchange="this.form.submit(); return false;">
<?php show_type_options($bug_type, true) ?>
</select>
<input class="small" type="submit" name="submitStats" value="Search">
</td>
</tr>
</table>
</form>
<table style="width: 100%; margin-top: 1em;" class="stats-table">
<?php // Exit if there are no bugs for this version
if ($total == 0) {
echo '<tr><td>No bugs found</td></tr></table>' . "\n";
response_footer();
exit;
}
echo display_stat_header($total, true);
echo <<< OUTPUT
<tr>
<td class="bug_head">All</td>
<td class="bug_bg0">{$total}</td>
OUTPUT;
$i = 1;
foreach ($titles as $key => $val) {
echo ' <td class="bug_bg' , $i++ % 2 , '">';
echo bugstats($key, 'all') , "</td>\n";
}
echo " </tr>\n";
$stat_row = 1;
foreach ($pkg[$sort_by] as $name => $value) {
if ($name != 'all') {
// Output a new header row every 40 lines
if (($stat_row++ % 40) == 0) {
echo display_stat_header($total, false);
}
echo <<< OUTPUT
<tr>
<td class="bug_head">{$name}</td>
<td class="bug_bg0">{$pkg_total[$name]}</td>
OUTPUT;
$i = 1;
foreach ($titles as $key => $val) {
echo ' <td class="bug_bg', $i++ % 2, '">';
echo bugstats($key, $name), "</td>\n";
}
echo " </tr>\n";
}
}
echo "</table>\n<hr>\n<p><b>PHP Versions for recent bug reports:</b></p><div>";
$last_date = null;
foreach ($bugRepository->findPhpVersions($bug_type) as $row) {
if ($row['d'] != $last_date) {
if ($last_date !== null) {
echo "</table>\n\n";
}
echo "<table style='float:left; margin-right:20px'>\n".
"<tr class='bug_header'><th colspan='2'>{$row["d"]}</th></tr>\n";
$last_date = $row['d'];
}
$version = htmlentities($row["formatted_version"], ENT_QUOTES, 'UTF-8');
echo "<tr><td class='bug_head'>{$version}</td><td class='bug_bg1'>{$row["quant"]}</td></tr>\n";
}
if ($last_date) {
echo "</table>\n";
}
echo "</div>\n";
response_footer();
// Helper functions
function bugstats($status, $name)
{
global $pkg, $all, $bug_type;
if ($name == 'all') {
if (isset($all[$status])) {
return '<a href="search.php?cmd=display&' .
'bug_type='.$bug_type.'&status=' .$status .
'&by=Any&limit=30">' .
$all[$status] . "</a>\n";
}
} else {
if (empty($pkg[$status][$name])) {
return ' ';
} else {
return '<a href="search.php?cmd=display&'.
'bug_type='.$bug_type.'&status=' .
$status .
'&package_name%5B%5D=' . urlencode($name) .
'&by=Any&limit=30">' .
$pkg[$status][$name] . "</a>\n";
}
}
}
function sort_url($name)
{
global $sort_by, $rev, $titles;
if ($name == $sort_by) {
$reve = (int) !$rev;
} else {
$reve = 1;
}
if ($sort_by != $name) {
$attr = 'class="bug_stats"';
} else {
$attr = 'class="bug_stats_choosen"';
}
return '<a href="stats.php?sort_by=' . urlencode($name) .
'&rev=' . $reve . '" ' . $attr . '>' .
$titles[$name] . '</a>';
}
function display_stat_header($total, $grandtotal = true)
{
global $titles;
$stat_head = " <tr class='bug_header'>\n";
if ($grandtotal) {
$stat_head .= " <th>Name</th>\n";
} else {
$stat_head .= " <th> </th>\n";
}
$stat_head .= " <th> </th>\n";
foreach ($titles as $key => $val) {
$stat_head .= ' <th>' . sort_url($key) . "</th>\n";
}
$stat_head .= '</tr>' . "\n";
return $stat_head;
}