Fix #11417: Allow EVENT_MENU_MAIN plugin events to return null
[mantis/radio.git] / roadmap_page.php
blobb13bcba4bd56320069aa0b73f683c59649dd66e7
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 # Print header for the specified project version.
69 function print_version_header( $p_version_row ) {
70 $t_project_id = $p_version_row['project_id'];
71 $t_version_id = $p_version_row['id'];
72 $t_version_name = $p_version_row['version'];
73 $t_project_name = project_get_field( $t_project_id, 'name' );
75 $t_release_title_without_hyperlinks = string_display_line( $t_project_name ) . ' - ' . string_display_line( $t_version_name );
76 $t_release_title = '<a href="roadmap_page.php?project_id=' . $t_project_id . '">' . string_display_line( $t_project_name ) . '</a> - <a href="roadmap_page.php?version_id=' . $t_version_id . '">' . string_display_line( $t_version_name ) . '</a>';
78 if ( config_get( 'show_roadmap_dates' ) ) {
79 $t_version_timestamp = $p_version_row['date_order'];
81 $t_scheduled_release_date = ' (' . lang_get( 'scheduled_release' ) . ' ' . string_display_line( date( config_get( 'short_date_format' ), $t_version_timestamp ) ) . ')';
82 } else {
83 $t_scheduled_release_date = '';
86 echo '<tt>';
87 echo '<br />', $t_release_title, $t_scheduled_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_TARGET_VERSION, $t_version_name ), lang_get( 'view_bugs_link' ) ), '<br />';
89 $t_release_title_without_hyperlinks .= $t_scheduled_release_date;
90 echo utf8_str_pad( '', utf8_strlen( $t_release_title_without_hyperlinks ), '=' ), '<br />';
93 # print project header
94 function print_project_header_roadmap( $p_project_name ) {
95 echo '<br /><span class="pagetitle">', string_display( $p_project_name ), ' - ', lang_get( 'roadmap' ), '</span><br />';
98 $t_user_id = auth_get_current_user_id();
100 $f_project = gpc_get_string( 'project', '' );
101 if ( is_blank( $f_project ) ) {
102 $f_project_id = gpc_get_int( 'project_id', -1 );
103 } else {
104 $f_project_id = project_get_id_by_name( $f_project );
106 if ( $f_project_id === 0 ) {
107 trigger_error( ERROR_PROJECT_NOT_FOUND, ERROR );
111 $f_version = gpc_get_string( 'version', '' );
113 if ( is_blank( $f_version ) ) {
114 $f_version_id = gpc_get_int( 'version_id', -1 );
116 # If both version_id and project_id parameters are supplied, then version_id take precedence.
117 if ( $f_version_id == -1 ) {
118 if ( $f_project_id == -1 ) {
119 $t_project_id = helper_get_current_project();
120 } else {
121 $t_project_id = $f_project_id;
123 } else {
124 $t_project_id = version_get_field( $f_version_id, 'project_id' );
126 } else {
127 if ( $f_project_id == -1 ) {
128 $t_project_id = helper_get_current_project();
129 } else {
130 $t_project_id = $f_project_id;
133 $f_version_id = version_get_id( $f_version, $t_project_id );
135 if ( $f_version_id === false ) {
136 error_parameters( $f_version );
137 trigger_error( ERROR_VERSION_NOT_FOUND, ERROR );
141 if ( ALL_PROJECTS == $t_project_id ) {
142 $t_topprojects = $t_project_ids = user_get_accessible_projects( $t_user_id );
143 foreach ( $t_topprojects as $t_project ) {
144 $t_project_ids = array_merge( $t_project_ids, user_get_all_accessible_subprojects( $t_user_id, $t_project ) );
147 $t_project_ids_to_check = array_unique( $t_project_ids );
148 $t_project_ids = array();
150 foreach ( $t_project_ids_to_check as $t_project_id ) {
151 $t_roadmap_view_access_level = config_get( 'roadmap_view_threshold', null, null, $t_project_id );
152 if ( access_has_project_level( $t_roadmap_view_access_level, $t_project_id ) ) {
153 $t_project_ids[] = $t_project_id;
156 } else {
157 access_ensure_project_level( config_get( 'roadmap_view_threshold' ), $t_project_id );
158 $t_project_ids = user_get_all_accessible_subprojects( $t_user_id, $t_project_id );
159 array_unshift( $t_project_ids, $t_project_id );
162 html_page_top( lang_get( 'roadmap' ) );
164 $t_project_index = 0;
166 version_cache_array_rows( $t_project_ids );
167 category_cache_array_rows_by_project( $t_project_ids );
169 foreach( $t_project_ids as $t_project_id ) {
170 $t_project_name = project_get_field( $t_project_id, 'name' );
171 $t_can_view_private = access_has_project_level( config_get( 'private_bug_threshold' ), $t_project_id );
173 $t_limit_reporters = config_get( 'limit_reporters' );
174 $t_user_access_level_is_reporter = ( REPORTER == access_get_project_level( $t_project_id ) );
176 $t_resolved = config_get( 'bug_resolved_status_threshold' );
177 $t_bug_table = db_get_table( 'bug' );
178 $t_relation_table = db_get_table( 'bug_relationship' );
180 $t_version_rows = array_reverse( version_get_all_rows( $t_project_id ) );
182 # cache category info, but ignore the results for now
183 category_get_all_rows( $t_project_id );
185 $t_project_header_printed = false;
187 foreach( $t_version_rows as $t_version_row ) {
188 if ( $t_version_row['released'] == 1 ) {
189 continue;
192 # Skip all versions except the specified one (if any).
193 if ( $f_version_id != -1 && $f_version_id != $t_version_row['id'] ) {
194 continue;
197 $t_issues_planned = 0;
198 $t_issues_resolved = 0;
199 $t_issues_counted = array();
201 $t_version_header_printed = false;
203 $t_version = $t_version_row['version'];
205 $query = "SELECT sbt.*, $t_relation_table.source_bug_id, dbt.target_version as parent_version FROM $t_bug_table sbt
206 LEFT JOIN $t_relation_table ON sbt.id=$t_relation_table.destination_bug_id AND $t_relation_table.relationship_type=2
207 LEFT JOIN $t_bug_table dbt ON dbt.id=$t_relation_table.source_bug_id
208 WHERE sbt.project_id=" . db_param() . " AND sbt.target_version=" . db_param() . " ORDER BY sbt.status ASC, sbt.last_updated DESC";
210 $t_description = $t_version_row['description'];
212 $t_first_entry = true;
214 $t_result = db_query_bound( $query, Array( $t_project_id, $t_version ) );
216 $t_issue_ids = array();
217 $t_issue_parents = array();
218 $t_issue_handlers = array();
220 while ( $t_row = db_fetch_array( $t_result ) ) {
221 # hide private bugs if user doesn't have access to view them.
222 if ( !$t_can_view_private && ( $t_row['view_state'] == VS_PRIVATE ) ) {
223 continue;
226 bug_cache_database_result( $t_row );
228 # check limit_Reporter (Issue #4770)
229 # reporters can view just issues they reported
230 if ( ON === $t_limit_reporters && $t_user_access_level_is_reporter &&
231 !bug_is_user_reporter( $t_row['id'], $t_user_id )) {
232 continue;
235 $t_issue_id = $t_row['id'];
236 $t_issue_parent = $t_row['source_bug_id'];
237 $t_parent_version = $t_row['parent_version'];
239 if ( !helper_call_custom_function( 'roadmap_include_issue', array( $t_issue_id ) ) ) {
240 continue;
243 if ( !isset( $t_issues_counted[$t_issue_id] ) ) {
244 $t_issues_planned++;
246 if ( bug_is_resolved( $t_issue_id ) ) {
247 $t_issues_resolved++;
250 $t_issues_counted[$t_issue_id] = true;
253 if ( 0 === strcasecmp( $t_parent_version, $t_version ) ) {
254 $t_issue_ids[] = $t_issue_id;
255 $t_issue_parents[] = $t_issue_parent;
256 } else if ( !in_array( $t_issue_id, $t_issue_ids ) ) {
257 $t_issue_ids[] = $t_issue_id;
258 $t_issue_parents[] = null;
261 $t_issue_handlers[] = $t_row['handler_id'];
264 user_cache_array_rows( array_unique( $t_issue_handlers ) );
266 $t_progress = $t_issues_planned > 0 ? ( (integer) ( $t_issues_resolved * 100 / $t_issues_planned ) ) : 0;
268 if ( $t_issues_planned > 0 ) {
269 $t_progress = (integer) ( $t_issues_resolved * 100 / $t_issues_planned );
271 if ( !$t_project_header_printed ) {
272 print_project_header_roadmap( $t_project_name );
273 $t_project_header_printed = true;
276 if ( !$t_version_header_printed ) {
277 print_version_header( $t_version_row );
278 $t_version_header_printed = true;
281 if ( !is_blank( $t_description ) ) {
282 echo string_display( '<br />' .$t_description . '<br />' );
285 // show progress bar
286 echo '<div class="progress400">';
287 echo ' <span class="bar" style="width: ' . $t_progress . '%;">' . $t_progress . '%</span>';
288 echo '</div>';
291 $t_issue_set_ids = array();
292 $t_issue_set_levels = array();
293 $k = 0;
295 $t_cycle = false;
296 $t_cycle_ids = array();
298 while ( 0 < count( $t_issue_ids ) ) {
299 $t_issue_id = $t_issue_ids[$k];
300 $t_issue_parent = $t_issue_parents[$k];
302 if ( in_array( $t_issue_id, $t_cycle_ids ) && in_array( $t_issue_parent, $t_cycle_ids ) ) {
303 $t_cycle = true;
304 } else {
305 $t_cycle = false;
306 $t_cycle_ids[] = $t_issue_id;
309 if ( $t_cycle || !in_array( $t_issue_parent, $t_issue_ids ) ) {
310 $l = array_search( $t_issue_parent, $t_issue_set_ids );
311 if ( $l !== false ) {
312 for ( $m = $l+1; $m < count( $t_issue_set_ids ) && $t_issue_set_levels[$m] > $t_issue_set_levels[$l]; $m++ ) {
313 #do nothing
315 $t_issue_set_ids_end = array_splice( $t_issue_set_ids, $m );
316 $t_issue_set_levels_end = array_splice( $t_issue_set_levels, $m );
317 $t_issue_set_ids[] = $t_issue_id;
318 $t_issue_set_levels[] = $t_issue_set_levels[$l] + 1;
319 $t_issue_set_ids = array_merge( $t_issue_set_ids, $t_issue_set_ids_end );
320 $t_issue_set_levels = array_merge( $t_issue_set_levels, $t_issue_set_levels_end );
321 } else {
322 $t_issue_set_ids[] = $t_issue_id;
323 $t_issue_set_levels[] = 0;
325 array_splice( $t_issue_ids, $k, 1 );
326 array_splice( $t_issue_parents, $k, 1 );
328 $t_cycle_ids = array();
329 } else {
330 $k++;
332 if ( count( $t_issue_ids ) <= $k ) {
333 $k = 0;
337 $t_count_ids = count( $t_issue_set_ids );
338 for ( $j = 0; $j < $t_count_ids; $j++ ) {
339 $t_issue_set_id = $t_issue_set_ids[$j];
340 $t_issue_set_level = $t_issue_set_levels[$j];
342 helper_call_custom_function( 'roadmap_print_issue', array( $t_issue_set_id, $t_issue_set_level ) );
345 if ( $t_issues_planned > 0 ) {
346 echo '<br />';
347 echo sprintf( lang_get( 'resolved_progress' ), $t_issues_resolved, $t_issues_planned, $t_progress );
348 echo '<br /></tt>';
352 $t_project_index++;
355 html_page_bottom();