forked from mantisbt/mantisbt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
changelog_page.php
433 lines (365 loc) · 13.5 KB
/
changelog_page.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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
<?php
# MantisBT - A PHP based bugtracking system
# MantisBT is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# MantisBT is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with MantisBT. If not, see <http://www.gnu.org/licenses/>.
/**
* Display Project Changelog
*
* @package MantisBT
* @copyright Copyright 2000 - 2002 Kenzaburo Ito - [email protected]
* @copyright Copyright 2002 MantisBT Team - [email protected]
* @link http://www.mantisbt.org
*
* @uses core.php
* @uses access_api.php
* @uses authentication_api.php
* @uses bug_api.php
* @uses category_api.php
* @uses config_api.php
* @uses constant_inc.php
* @uses database_api.php
* @uses error_api.php
* @uses filter_api.php
* @uses filter_constants_inc.php
* @uses gpc_api.php
* @uses helper_api.php
* @uses html_api.php
* @uses lang_api.php
* @uses print_api.php
* @uses project_api.php
* @uses string_api.php
* @uses user_api.php
* @uses utility_api.php
* @uses version_api.php
*/
require_once( 'core.php' );
require_api( 'access_api.php' );
require_api( 'authentication_api.php' );
require_api( 'bug_api.php' );
require_api( 'category_api.php' );
require_api( 'config_api.php' );
require_api( 'constant_inc.php' );
require_api( 'database_api.php' );
require_api( 'error_api.php' );
require_api( 'filter_api.php' );
require_api( 'filter_constants_inc.php' );
require_api( 'gpc_api.php' );
require_api( 'helper_api.php' );
require_api( 'html_api.php' );
require_api( 'lang_api.php' );
require_api( 'print_api.php' );
require_api( 'project_api.php' );
require_api( 'string_api.php' );
require_api( 'user_api.php' );
require_api( 'utility_api.php' );
require_api( 'version_api.php' );
require_css( 'status_config.php' );
/**
* Print header for the specified project version.
* @param integer $p_version_id A valid version identifier.
* @return void
*/
function print_version_header( $p_version_id ) {
$t_project_id = version_get_field( $p_version_id, 'project_id' );
$t_version_name = version_get_field( $p_version_id, 'version' );
$t_project_name = project_get_field( $t_project_id, 'name' );
$t_release_title = '<a class="white" href="changelog_page.php?project_id=' . $t_project_id . '">' . string_display_line( $t_project_name ) . '</a>';
$t_release_title .= ' - <a class="white" href="changelog_page.php?version_id=' . $p_version_id . '">' . string_display_line( $t_version_name ) . '</a>';
if( config_get( 'show_changelog_dates' ) ) {
$t_version_released = version_get_field( $p_version_id, 'released' );
$t_release_timestamp = version_get_field( $p_version_id, 'date_order' );
if( (bool)$t_version_released ) {
$t_release_date = lang_get( 'released' ) . ' ' . string_display_line( date( config_get( 'short_date_format' ), $t_release_timestamp ) );
} else {
$t_release_date = lang_get( 'not_released' );
}
} else {
$t_release_date = '';
}
$t_block_id = 'changelog_' . $p_version_id;
$t_collapse_block = is_collapsed( $t_block_id );
$t_block_css = $t_collapse_block ? 'collapsed' : '';
$t_block_icon = $t_collapse_block ? 'fa-chevron-down' : 'fa-chevron-up';
echo '<div id="' . $t_block_id . '" class="widget-box widget-color-blue2 ' . $t_block_css . '">';
echo '<div class="widget-header widget-header-small">';
echo PHP_EOL;
echo '<h4 class="widget-title lighter">';
print_icon( 'fa-retweet', 'ace-icon' );
echo $t_release_title, lang_get( 'word_separator' );
echo '</h4>';
echo PHP_EOL;
echo '<div class="widget-toolbar">';
echo '<a data-action="collapse" href="#">';
print_icon( $t_block_icon, '1 ace-icon bigger-125' );
echo '</a>';
echo '</div>';
echo '</div>';
echo PHP_EOL;
echo '<div class="widget-body">';
echo '<div class="widget-toolbox padding-8 clearfix">';
echo '<div class="pull-left">' . icon_get( 'fa-calendar-o', 'fa-lg' ) . ' ' . $t_release_date . '</div>';
echo PHP_EOL;
echo '<div class="btn-toolbar pull-right">';
print_extra_small_button(
'view_all_set.php?type=' . FILTER_ACTION_PARSE_NEW
. '&temporary=y&' . FILTER_PROPERTY_PROJECT_ID . '=' . $t_project_id
. '&' . filter_encode_field_and_value( FILTER_PROPERTY_FIXED_IN_VERSION, $t_version_name )
. '&' . FILTER_PROPERTY_HIDE_STATUS . '=' . META_FILTER_NONE,
lang_get( 'view_bugs_link' )
);
print_extra_small_button(
'changelog_page.php?version_id=' . $p_version_id,
string_display_line( $t_version_name )
);
print_extra_small_button(
'changelog_page.php?project_id=' . $t_project_id,
string_display_line( $t_project_name )
);
echo '</div>';
echo PHP_EOL;
echo '</div>';
echo PHP_EOL;
echo '<div class="widget-main">';
}
/**
* Print footer for the specified project version.
* @param int $p_version_id a valid version id
* @param int $p_issues_resolved number of issues in resolved state
* @return void
*/
function print_version_footer( $p_version_id, $p_issues_resolved ) {
$t_project_id = version_get_field( $p_version_id, 'project_id' );
$t_bug_string = $p_issues_resolved == 1 ? 'bug' : 'bugs';
$t_version_name = version_get_field( $p_version_id, 'version' );
echo '</div>';
echo '<div class="widget-toolbox padding-8 clearfix">';
echo ' ' . $p_issues_resolved . ' ' . lang_get( $t_bug_string ) . ' ';
print_extra_small_button(
'view_all_set.php?type=' . FILTER_ACTION_PARSE_NEW
. '&temporary=y&' . FILTER_PROPERTY_PROJECT_ID . '=' . $t_project_id
. '&' . filter_encode_field_and_value( FILTER_PROPERTY_FIXED_IN_VERSION, $t_version_name )
. '&' . FILTER_PROPERTY_HIDE_STATUS . '=' . META_FILTER_NONE,
lang_get( 'view_bugs_link' )
);
echo '</div></div></div>';
echo '<div class="space-10"></div>';
echo PHP_EOL;
}
/**
* Print header for the specified project
* @param string $p_project_name Project name to display.
* @return void
*/
function print_project_header_changelog( $p_project_name ) {
echo '<div class="page-header">';
echo '<h1><strong>' . string_display_line( $p_project_name ), '</strong> - ', lang_get( 'changelog' ) . '</h1>';
echo '</div>';
echo PHP_EOL;
}
$t_issues_found = false;
$t_user_id = auth_get_current_user_id();
$f_project = gpc_get_string( 'project', '' );
if( is_blank( $f_project ) ) {
$f_project_id = gpc_get_int( 'project_id', -1 );
} else {
$f_project_id = project_get_id_by_name( $f_project );
if( $f_project_id === 0 ) {
error_parameters( $f_project );
trigger_error( ERROR_PROJECT_NOT_FOUND, ERROR );
}
}
$f_version = gpc_get_string( 'version', '' );
if( is_blank( $f_version ) ) {
$f_version_id = gpc_get_int( 'version_id', -1 );
# If both version_id and project_id parameters are supplied, then version_id take precedence.
if( $f_version_id == -1 ) {
if( $f_project_id == -1 ) {
$t_project_id = helper_get_current_project();
} else {
$t_project_id = $f_project_id;
}
} else {
$t_project_id = version_get_field( $f_version_id, 'project_id' );
}
} else {
if( $f_project_id == -1 ) {
$t_project_id = helper_get_current_project();
} else {
$t_project_id = $f_project_id;
}
$f_version_id = version_get_id( $f_version, $t_project_id );
if( $f_version_id === false ) {
error_parameters( $f_version );
trigger_error( ERROR_VERSION_NOT_FOUND, ERROR );
}
}
if( ALL_PROJECTS == $t_project_id ) {
$t_project_ids_to_check = user_get_all_accessible_projects( $t_user_id, ALL_PROJECTS );
$t_project_ids = array();
foreach ( $t_project_ids_to_check as $t_project_id ) {
$t_changelog_view_access_level = config_get( 'view_changelog_threshold', null, null, $t_project_id );
if( access_has_project_level( $t_changelog_view_access_level, $t_project_id ) ) {
$t_project_ids[] = $t_project_id;
}
}
} else {
access_ensure_project_level( config_get( 'view_changelog_threshold' ), $t_project_id );
$t_project_ids = user_get_all_accessible_subprojects( $t_user_id, $t_project_id );
array_unshift( $t_project_ids, $t_project_id );
}
$t_project_id_for_access_check = $t_project_id;
layout_page_header( lang_get( 'changelog' ) );
layout_page_begin( __FILE__ );
echo '<div class="col-md-12 col-xs-12">';
$t_project_index = 0;
version_cache_array_rows( $t_project_ids );
category_cache_array_rows_by_project( $t_project_ids );
foreach( $t_project_ids as $t_project_id ) {
$t_project_name = project_get_field( $t_project_id, 'name' );
$t_resolved = config_get( 'bug_resolved_status_threshold' );
# grab versions info for later use, excluding obsolete ones
$t_version_rows = version_get_all_rows( $t_project_id, VERSION_ALL, false );
# cache category info, but ignore the results for now
category_get_all_rows( $t_project_id );
$t_project_header_printed = false;
$t_view_bug_threshold = config_get( 'view_bug_threshold', null, $t_user_id, $t_project_id );
foreach( $t_version_rows as $t_version_row ) {
$t_version_header_printed = false;
$t_version = $t_version_row['version'];
$t_version_id = $t_version_row['id'];
# Skip all versions except the specified one (if any).
if( $f_version_id != -1 && $f_version_id != $t_version_id ) {
continue;
}
$t_query = 'SELECT sbt.*, dbt.fixed_in_version AS parent_version, rt.source_bug_id
FROM {bug} sbt
LEFT JOIN {bug_relationship} rt
ON sbt.id=rt.destination_bug_id AND rt.relationship_type=' . BUG_DEPENDANT . '
LEFT JOIN {bug} dbt ON dbt.id=rt.source_bug_id
WHERE sbt.project_id=' . db_param() . '
AND sbt.fixed_in_version=' . db_param() . '
ORDER BY sbt.status ASC, sbt.last_updated DESC';
$t_description = version_get_field( $t_version_id, 'description' );
$t_first_entry = true;
$t_issue_ids = array();
$t_issue_parents = array();
$t_issue_handlers = array();
$t_result = db_query( $t_query, array( $t_project_id, $t_version ) );
while( $t_row = db_fetch_array( $t_result ) ) {
bug_cache_database_result( $t_row );
# verify the user can view this issue
if( !access_has_bug_level( $t_view_bug_threshold, $t_row['id'] ) ) {
continue;
}
$t_issue_id = $t_row['id'];
$t_issue_parent = $t_row['source_bug_id'];
$t_parent_version = (string)$t_row['parent_version'];
if( !helper_call_custom_function( 'changelog_include_issue', array( $t_issue_id ) ) ) {
continue;
}
if( 0 === strcasecmp( $t_parent_version, $t_version ) ) {
$t_issue_ids[] = $t_issue_id;
$t_issue_parents[] = $t_issue_parent;
} else if( !in_array( $t_issue_id, $t_issue_ids ) ) {
$t_issue_ids[] = $t_issue_id;
$t_issue_parents[] = null;
}
$t_issue_handlers[] = $t_row['handler_id'];
}
user_cache_array_rows( array_unique( $t_issue_handlers ) );
$t_issues_resolved = count( array_unique( $t_issue_ids ) );
if( $t_issues_resolved > 0 ) {
if( !$t_project_header_printed ) {
echo PHP_EOL;
print_project_header_changelog( $t_project_name );
$t_project_header_printed = true;
}
if( !$t_version_header_printed ) {
print_version_header( $t_version_id );
$t_version_header_printed = true;
}
if( !is_blank( $t_description ) ) {
echo '<div class="alert alert-warning">',
string_display_links( $t_description ),
'</div>';
}
} else {
continue;
}
$t_issue_set_ids = array();
$t_issue_set_levels = array();
$k = 0;
$t_cycle = false;
$t_cycle_ids = array();
while( !empty( $t_issue_ids ) ) {
$t_issue_id = $t_issue_ids[$k];
$t_issue_parent = $t_issue_parents[$k];
if( in_array( $t_issue_id, $t_cycle_ids ) && in_array( $t_issue_parent, $t_cycle_ids ) ) {
$t_cycle = true;
} else {
$t_cycle = false;
$t_cycle_ids[] = $t_issue_id;
}
if( $t_cycle || !in_array( $t_issue_parent, $t_issue_ids ) ) {
$l = array_search( $t_issue_parent, $t_issue_set_ids );
if( $l !== false ) {
for( $m = $l+1; $m < count( $t_issue_set_ids ) && $t_issue_set_levels[$m] > $t_issue_set_levels[$l]; $m++ ) {
#do nothing
}
$t_issue_set_ids_end = array_splice( $t_issue_set_ids, $m );
$t_issue_set_levels_end = array_splice( $t_issue_set_levels, $m );
$t_issue_set_ids[] = $t_issue_id;
$t_issue_set_levels[] = $t_issue_set_levels[$l] + 1;
$t_issue_set_ids = array_merge( $t_issue_set_ids, $t_issue_set_ids_end );
$t_issue_set_levels = array_merge( $t_issue_set_levels, $t_issue_set_levels_end );
} else {
$t_issue_set_ids[] = $t_issue_id;
$t_issue_set_levels[] = 0;
}
array_splice( $t_issue_ids, $k, 1 );
array_splice( $t_issue_parents, $k, 1 );
$t_cycle_ids = array();
} else {
$k++;
}
if( count( $t_issue_ids ) <= $k ) {
$k = 0;
}
}
echo '<ul class="changelog">' . PHP_EOL;
for( $j = 0; $j < count( $t_issue_set_ids ); $j++ ) {
$t_issue_set_id = $t_issue_set_ids[$j];
$t_issue_set_level = $t_issue_set_levels[$j];
echo '<li>';
helper_call_custom_function( 'changelog_print_issue', array( $t_issue_set_id, $t_issue_set_level ) );
echo '</li>' . PHP_EOL;
$t_issues_found = true;
}
echo '</ul>' . PHP_EOL;
if( $t_version_header_printed ) {
print_version_footer( $t_version_id, $t_issues_resolved);
}
}
$t_project_index++;
}
if( !$t_issues_found ) {
if( access_has_project_level( config_get( 'manage_project_threshold' ), $t_project_id_for_access_check ) ) {
$t_string = 'changelog_empty_manager';
} else {
$t_string = 'changelog_empty';
}
echo '<br />';
echo '<p class="lead">' . lang_get( $t_string ) . '</p>';
}
echo '</div>';
layout_page_end();