Fix #11417: Allow EVENT_MENU_MAIN plugin events to return null
[mantis/radio.git] / changelog_page.php
blob36f536e21d5bc1a484f0d91b5455cec455c4f491
1 <?php
2 # MantisBT - A PHP based bugtracking system
4 # MantisBT is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 2 of the License, or
7 # (at your option) any later version.
9 # MantisBT is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with MantisBT. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * @package MantisBT
19 * @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
20 * @copyright Copyright (C) 2002 - 2010 MantisBT Team - mantisbt-dev@lists.sourceforge.net
21 * @link http://www.mantisbt.org
23 * @uses core.php
24 * @uses access_api.php
25 * @uses authentication_api.php
26 * @uses bug_api.php
27 * @uses category_api.php
28 * @uses config_api.php
29 * @uses constant_inc.php
30 * @uses database_api.php
31 * @uses error_api.php
32 * @uses filter_api.php
33 * @uses filter_constants_inc.php
34 * @uses gpc_api.php
35 * @uses helper_api.php
36 * @uses html_api.php
37 * @uses lang_api.php
38 * @uses print_api.php
39 * @uses project_api.php
40 * @uses string_api.php
41 * @uses user_api.php
42 * @uses utility_api.php
43 * @uses version_api.php
46 require_once( 'core.php' );
47 require_api( 'access_api.php' );
48 require_api( 'authentication_api.php' );
49 require_api( 'bug_api.php' );
50 require_api( 'category_api.php' );
51 require_api( 'config_api.php' );
52 require_api( 'constant_inc.php' );
53 require_api( 'database_api.php' );
54 require_api( 'error_api.php' );
55 require_api( 'filter_api.php' );
56 require_api( 'filter_constants_inc.php' );
57 require_api( 'gpc_api.php' );
58 require_api( 'helper_api.php' );
59 require_api( 'html_api.php' );
60 require_api( 'lang_api.php' );
61 require_api( 'print_api.php' );
62 require_api( 'project_api.php' );
63 require_api( 'string_api.php' );
64 require_api( 'user_api.php' );
65 require_api( 'utility_api.php' );
66 require_api( 'version_api.php' );
68 /**
69 * Print header for the specified project version.
70 * @param int $p_version_id a valid version id
71 * @return null
73 function print_version_header( $p_version_id ) {
74 $t_project_id = version_get_field( $p_version_id, 'project_id' );
75 $t_version_name = version_get_field( $p_version_id, 'version' );
76 $t_project_name = project_get_field( $t_project_id, 'name' );
78 $t_release_title_without_hyperlinks = string_display_line( $t_project_name ) . ' - ' . string_display_line( $t_version_name );
79 $t_release_title = '<a href="changelog_page.php?project_id=' . $t_project_id . '">' . string_display_line( $t_project_name ) . '</a> - <a href="changelog_page.php?version_id=' . $p_version_id . '">' . string_display_line( $t_version_name ) . '</a>';
81 if ( config_get( 'show_changelog_dates' ) ) {
82 $t_version_released = version_get_field( $p_version_id, 'released' );
83 $t_release_timestamp = version_get_field( $p_version_id, 'date_order' );
85 if ( (bool) $t_version_released ) {
86 $t_release_date = ' (' . lang_get('released') . ' ' . string_display_line( date( config_get( 'short_date_format' ), $t_release_timestamp ) ) . ')';
87 } else {
88 $t_release_date = ' (' . lang_get( 'not_released' ) . ')';
90 } else {
91 $t_release_date = '';
94 echo '<br />', $t_release_title, $t_release_date, lang_get( 'word_separator' ), print_bracket_link( 'view_all_set.php?type=1&temporary=y&' . FILTER_PROPERTY_PROJECT_ID . '=' . $t_project_id . '&' . filter_encode_field_and_value( FILTER_PROPERTY_FIXED_IN_VERSION, $t_version_name ), lang_get( 'view_bugs_link' ) ), '<br />';
96 $t_release_title_without_hyperlinks .= $t_release_date;
97 echo utf8_str_pad( '', utf8_strlen( $t_release_title_without_hyperlinks ), '=' ), '<br />';
101 * Print header for the specified project
102 * @param string $p_project_name project name to display
103 * @return null
105 function print_project_header_changelog ( $p_project_name ) {
106 echo '<br /><span class="pagetitle">', string_display_line( $p_project_name ), ' - ', lang_get( 'changelog' ), '</span><br />';
107 echo '<tt>';
110 $t_user_id = auth_get_current_user_id();
112 $f_project = gpc_get_string( 'project', '' );
113 if ( is_blank( $f_project ) ) {
114 $f_project_id = gpc_get_int( 'project_id', -1 );
115 } else {
116 $f_project_id = project_get_id_by_name( $f_project );
118 if ( $f_project_id === 0 ) {
119 trigger_error( ERROR_PROJECT_NOT_FOUND, ERROR );
123 $f_version = gpc_get_string( 'version', '' );
125 if ( is_blank( $f_version ) ) {
126 $f_version_id = gpc_get_int( 'version_id', -1 );
128 # If both version_id and project_id parameters are supplied, then version_id take precedence.
129 if ( $f_version_id == -1 ) {
130 if ( $f_project_id == -1 ) {
131 $t_project_id = helper_get_current_project();
132 } else {
133 $t_project_id = $f_project_id;
135 } else {
136 $t_project_id = version_get_field( $f_version_id, 'project_id' );
138 } else {
139 if ( $f_project_id == -1 ) {
140 $t_project_id = helper_get_current_project();
141 } else {
142 $t_project_id = $f_project_id;
145 $f_version_id = version_get_id( $f_version, $t_project_id );
147 if ( $f_version_id === false ) {
148 error_parameters( $f_version );
149 trigger_error( ERROR_VERSION_NOT_FOUND, ERROR );
153 if ( ALL_PROJECTS == $t_project_id ) {
154 $t_topprojects = $t_project_ids = user_get_accessible_projects( $t_user_id );
155 foreach ( $t_topprojects as $t_project ) {
156 $t_project_ids = array_merge( $t_project_ids, user_get_all_accessible_subprojects( $t_user_id, $t_project ) );
159 $t_project_ids_to_check = array_unique( $t_project_ids );
160 $t_project_ids = array();
162 foreach ( $t_project_ids_to_check as $t_project_id ) {
163 $t_changelog_view_access_level = config_get( 'view_changelog_threshold', null, null, $t_project_id );
164 if ( access_has_project_level( $t_changelog_view_access_level, $t_project_id ) ) {
165 $t_project_ids[] = $t_project_id;
168 } else {
169 access_ensure_project_level( config_get( 'view_changelog_threshold' ), $t_project_id );
170 $t_project_ids = user_get_all_accessible_subprojects( $t_user_id, $t_project_id );
171 array_unshift( $t_project_ids, $t_project_id );
174 html_page_top( lang_get( 'changelog' ) );
176 $t_project_index = 0;
178 version_cache_array_rows( $t_project_ids );
179 category_cache_array_rows_by_project( $t_project_ids );
181 foreach( $t_project_ids as $t_project_id ) {
182 $t_project_name = project_get_field( $t_project_id, 'name' );
183 $t_can_view_private = access_has_project_level( config_get( 'private_bug_threshold' ), $t_project_id );
185 $t_limit_reporters = config_get( 'limit_reporters' );
186 $t_user_access_level_is_reporter = ( REPORTER == access_get_project_level( $t_project_id ) );
188 $t_resolved = config_get( 'bug_resolved_status_threshold' );
189 $t_bug_table = db_get_table( 'bug' );
190 $t_relation_table = db_get_table( 'bug_relationship' );
192 # grab version info for later use
193 $t_version_rows = version_get_all_rows( $t_project_id, /* released */ null, /* obsolete */ false );
195 # cache category info, but ignore the results for now
196 category_get_all_rows( $t_project_id );
198 $t_project_header_printed = false;
200 foreach( $t_version_rows as $t_version_row ) {
201 $t_issues_planned = 0;
202 $t_issues_resolved = 0;
204 $t_version_header_printed = false;
206 $t_version = $t_version_row['version'];
208 $t_version_id = $t_version_row['id'];
210 # Skip all versions except the specified one (if any).
211 if ( $f_version_id != -1 && $f_version_id != $t_version_id ) {
212 continue;
215 $query = "SELECT sbt.*, dbt.target_version AS parent_version, $t_relation_table.source_bug_id FROM $t_bug_table sbt
216 LEFT JOIN $t_relation_table ON sbt.id=$t_relation_table.destination_bug_id AND $t_relation_table.relationship_type=2
217 LEFT JOIN $t_bug_table dbt ON dbt.id=$t_relation_table.source_bug_id
218 WHERE sbt.project_id=" . db_param() . " AND sbt.fixed_in_version=" . db_param() . " ORDER BY sbt.status ASC, sbt.last_updated DESC";
220 $t_description = version_get_field( $t_version_id, 'description' );
222 $t_first_entry = true;
223 $t_issue_ids = array();
224 $t_issue_parents = array();
225 $t_issue_handlers = array();
227 $t_result = db_query_bound( $query, Array( $t_project_id, $t_version ) );
229 while ( $t_row = db_fetch_array( $t_result ) ) {
230 # hide private bugs if user doesn't have access to view them.
231 if ( !$t_can_view_private && ( $t_row['view_state'] == VS_PRIVATE ) ) {
232 continue;
235 bug_cache_database_result( $t_row );
237 # check limit_Reporter (Issue #4770)
238 # reporters can view just issues they reported
239 if ( ON === $t_limit_reporters && $t_user_access_level_is_reporter &&
240 !bug_is_user_reporter( $t_row['id'], $t_user_id )) {
241 continue;
244 $t_issue_id = $t_row['id'];
245 $t_issue_parent = $t_row['source_bug_id'];
246 $t_parent_version = $t_row['parent_version'];
248 if ( !helper_call_custom_function( 'changelog_include_issue', array( $t_issue_id ) ) ) {
249 continue;
252 $t_issues_resolved++;
254 if ( 0 === strcasecmp( $t_parent_version, $t_version ) ) {
255 $t_issue_ids[] = $t_issue_id;
256 $t_issue_parents[] = $t_issue_parent;
257 } else if ( !in_array( $t_issue_id, $t_issue_ids ) ) {
258 $t_issue_ids[] = $t_issue_id;
259 $t_issue_parents[] = null;
262 $t_issue_handlers[] = $t_row['handler_id'];
265 user_cache_array_rows( array_unique( $t_issue_handlers ) );
267 if ( $t_issues_resolved > 0 ) {
268 if ( !$t_project_header_printed ) {
269 print_project_header_changelog( $t_project_name );
270 $t_project_header_printed = true;
273 if ( !$t_version_header_printed ) {
274 print_version_header( $t_version_id );
275 $t_version_header_printed = true;
278 if ( !is_blank( $t_description ) ) {
279 echo string_display( "<br />$t_description<br /><br />" );
283 $t_issue_set_ids = array();
284 $t_issue_set_levels = array();
285 $k = 0;
287 $t_cycle = false;
288 $t_cycle_ids = array();
290 while ( !empty( $t_issue_ids ) ) {
291 $t_issue_id = $t_issue_ids[$k];
292 $t_issue_parent = $t_issue_parents[$k];
294 if ( in_array( $t_issue_id, $t_cycle_ids ) && in_array( $t_issue_parent, $t_cycle_ids ) ) {
295 $t_cycle = true;
296 } else {
297 $t_cycle = false;
298 $t_cycle_ids[] = $t_issue_id;
301 if ( $t_cycle || !in_array( $t_issue_parent, $t_issue_ids ) ) {
302 $l = array_search( $t_issue_parent, $t_issue_set_ids );
303 if ( $l !== false ) {
304 for ( $m = $l+1; $m < count( $t_issue_set_ids ) && $t_issue_set_levels[$m] > $t_issue_set_levels[$l]; $m++ ) {
305 #do nothing
307 $t_issue_set_ids_end = array_splice( $t_issue_set_ids, $m );
308 $t_issue_set_levels_end = array_splice( $t_issue_set_levels, $m );
309 $t_issue_set_ids[] = $t_issue_id;
310 $t_issue_set_levels[] = $t_issue_set_levels[$l] + 1;
311 $t_issue_set_ids = array_merge( $t_issue_set_ids, $t_issue_set_ids_end );
312 $t_issue_set_levels = array_merge( $t_issue_set_levels, $t_issue_set_levels_end );
313 } else {
314 $t_issue_set_ids[] = $t_issue_id;
315 $t_issue_set_levels[] = 0;
317 array_splice( $t_issue_ids, $k, 1 );
318 array_splice( $t_issue_parents, $k, 1 );
320 $t_cycle_ids = array();
321 } else {
322 $k++;
324 if ( count( $t_issue_ids ) <= $k ) {
325 $k = 0;
329 for ( $j = 0; $j < count( $t_issue_set_ids ); $j++ ) {
330 $t_issue_set_id = $t_issue_set_ids[$j];
331 $t_issue_set_level = $t_issue_set_levels[$j];
333 helper_call_custom_function( 'changelog_print_issue', array( $t_issue_set_id, $t_issue_set_level ) );
336 if ( $t_issues_resolved == 1 ) {
337 echo "[{$t_issues_resolved} " . lang_get( 'bug' ) . ']';
338 echo "<br />";
339 } else if ( $t_issues_resolved > 1 ) {
340 echo "[{$t_issues_resolved} " . lang_get( 'bugs' ) . ']';
341 echo "<br />";
345 if ( $t_project_header_printed ) {
346 echo '</tt>';
349 $t_project_index++;
352 if ( $t_project_index == 0 ) {
353 echo '<br /><span class="pagetitle">' . lang_get('changelog_empty') . '</span>';
355 html_page_bottom();