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/>.
19 * @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
20 * @copyright Copyright (C) 2002 - 2011 MantisBT Team - mantisbt-dev@lists.sourceforge.net
21 * @link http://www.mantisbt.org
24 * @uses access_api.php
25 * @uses authentication_api.php
27 * @uses category_api.php
28 * @uses config_api.php
29 * @uses constant_inc.php
30 * @uses database_api.php
32 * @uses filter_api.php
33 * @uses filter_constants_inc.php
35 * @uses helper_api.php
39 * @uses project_api.php
40 * @uses string_api.php
42 * @uses utility_api.php
43 * @uses version_api.php
49 require_once( 'core.php' );
50 require_api( 'access_api.php' );
51 require_api( 'authentication_api.php' );
52 require_api( 'bug_api.php' );
53 require_api( 'category_api.php' );
54 require_api( 'config_api.php' );
55 require_api( 'constant_inc.php' );
56 require_api( 'database_api.php' );
57 require_api( 'error_api.php' );
58 require_api( 'filter_api.php' );
59 require_api( 'filter_constants_inc.php' );
60 require_api( 'gpc_api.php' );
61 require_api( 'helper_api.php' );
62 require_api( 'html_api.php' );
63 require_api( 'lang_api.php' );
64 require_api( 'print_api.php' );
65 require_api( 'project_api.php' );
66 require_api( 'string_api.php' );
67 require_api( 'user_api.php' );
68 require_api( 'utility_api.php' );
69 require_api( 'version_api.php' );
71 # Print header for the specified project version.
72 function print_version_header( $p_version_row ) {
73 $t_project_id = $p_version_row['project_id'];
74 $t_version_id = $p_version_row['id'];
75 $t_version_name = $p_version_row['version'];
76 $t_project_name = project_get_field( $t_project_id, 'name' );
78 $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>';
80 if ( config_get( 'show_roadmap_dates' ) ) {
81 $t_version_timestamp = $p_version_row['date_order'];
83 $t_scheduled_release_date = ' (' . lang_get( 'scheduled_release' ) . ' ' . string_display_line( date( config_get( 'short_date_format' ), $t_version_timestamp ) ) . ')';
85 $t_scheduled_release_date = '';
89 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 />';
91 $t_release_title_without_hyperlinks = $t_project_name . ' - ' . $t_version_name . $t_scheduled_release_date;
92 echo utf8_str_pad( '', utf8_strlen( $t_release_title_without_hyperlinks ), '=' ), '<br />';
95 # print project header
96 function print_project_header_roadmap( $p_project_name ) {
97 echo '<br /><span class="pagetitle">', string_display( $p_project_name ), ' - ', lang_get( 'roadmap' ), '</span><br />';
100 $t_user_id = auth_get_current_user_id();
102 $f_project = gpc_get_string( 'project', '' );
103 if ( is_blank( $f_project ) ) {
104 $f_project_id = gpc_get_int( 'project_id', -1 );
106 $f_project_id = project_get_id_by_name( $f_project );
108 if ( $f_project_id === 0 ) {
109 trigger_error( ERROR_PROJECT_NOT_FOUND
, ERROR
);
113 $f_version = gpc_get_string( 'version', '' );
115 if ( is_blank( $f_version ) ) {
116 $f_version_id = gpc_get_int( 'version_id', -1 );
118 # If both version_id and project_id parameters are supplied, then version_id take precedence.
119 if ( $f_version_id == -1 ) {
120 if ( $f_project_id == -1 ) {
121 $t_project_id = helper_get_current_project();
123 $t_project_id = $f_project_id;
126 $t_project_id = version_get_field( $f_version_id, 'project_id' );
129 if ( $f_project_id == -1 ) {
130 $t_project_id = helper_get_current_project();
132 $t_project_id = $f_project_id;
135 $f_version_id = version_get_id( $f_version, $t_project_id );
137 if ( $f_version_id === false ) {
138 error_parameters( $f_version );
139 trigger_error( ERROR_VERSION_NOT_FOUND
, ERROR
);
143 if ( ALL_PROJECTS
== $t_project_id ) {
144 $t_topprojects = $t_project_ids = user_get_accessible_projects( $t_user_id );
145 foreach ( $t_topprojects as $t_project ) {
146 $t_project_ids = array_merge( $t_project_ids, user_get_all_accessible_subprojects( $t_user_id, $t_project ) );
149 $t_project_ids_to_check = array_unique( $t_project_ids );
150 $t_project_ids = array();
152 foreach ( $t_project_ids_to_check as $t_project_id ) {
153 $t_roadmap_view_access_level = config_get( 'roadmap_view_threshold', null, null, $t_project_id );
154 if ( access_has_project_level( $t_roadmap_view_access_level, $t_project_id ) ) {
155 $t_project_ids[] = $t_project_id;
159 access_ensure_project_level( config_get( 'roadmap_view_threshold' ), $t_project_id );
160 $t_project_ids = user_get_all_accessible_subprojects( $t_user_id, $t_project_id );
161 array_unshift( $t_project_ids, $t_project_id );
164 html_page_top( lang_get( 'roadmap' ) );
166 $t_project_index = 0;
168 version_cache_array_rows( $t_project_ids );
169 category_cache_array_rows_by_project( $t_project_ids );
171 foreach( $t_project_ids as $t_project_id ) {
172 $t_project_name = project_get_field( $t_project_id, 'name' );
173 $t_can_view_private = access_has_project_level( config_get( 'private_bug_threshold' ), $t_project_id );
175 $t_limit_reporters = config_get( 'limit_reporters' );
176 $t_user_access_level_is_reporter = ( REPORTER
== access_get_project_level( $t_project_id ) );
178 $t_resolved = config_get( 'bug_resolved_status_threshold' );
179 $t_bug_table = db_get_table( 'bug' );
180 $t_relation_table = db_get_table( 'bug_relationship' );
182 $t_version_rows = array_reverse( version_get_all_rows( $t_project_id ) );
184 # cache category info, but ignore the results for now
185 category_get_all_rows( $t_project_id );
187 $t_project_header_printed = false;
189 foreach( $t_version_rows as $t_version_row ) {
190 if ( $t_version_row['released'] == 1 ) {
194 # Skip all versions except the specified one (if any).
195 if ( $f_version_id != -1 && $f_version_id != $t_version_row['id'] ) {
199 $t_issues_planned = 0;
200 $t_issues_resolved = 0;
201 $t_issues_counted = array();
203 $t_version_header_printed = false;
205 $t_version = $t_version_row['version'];
207 $query = "SELECT sbt.*, $t_relation_table.source_bug_id, dbt.target_version as parent_version FROM $t_bug_table sbt
208 LEFT JOIN $t_relation_table ON sbt.id=$t_relation_table.destination_bug_id AND $t_relation_table.relationship_type=2
209 LEFT JOIN $t_bug_table dbt ON dbt.id=$t_relation_table.source_bug_id
210 WHERE sbt.project_id=" . db_param() . " AND sbt.target_version=" . db_param() . " ORDER BY sbt.status ASC, sbt.last_updated DESC";
212 $t_description = $t_version_row['description'];
214 $t_first_entry = true;
216 $t_result = db_query_bound( $query, Array( $t_project_id, $t_version ) );
218 $t_issue_ids = array();
219 $t_issue_parents = array();
220 $t_issue_handlers = array();
222 while ( $t_row = db_fetch_array( $t_result ) ) {
223 # hide private bugs if user doesn't have access to view them.
224 if ( !$t_can_view_private && ( $t_row['view_state'] == VS_PRIVATE
) ) {
228 bug_cache_database_result( $t_row );
230 # check limit_Reporter (Issue #4770)
231 # reporters can view just issues they reported
232 if ( ON
=== $t_limit_reporters && $t_user_access_level_is_reporter &&
233 !bug_is_user_reporter( $t_row['id'], $t_user_id )) {
237 $t_issue_id = $t_row['id'];
238 $t_issue_parent = $t_row['source_bug_id'];
239 $t_parent_version = $t_row['parent_version'];
241 if ( !helper_call_custom_function( 'roadmap_include_issue', array( $t_issue_id ) ) ) {
245 if ( !isset( $t_issues_counted[$t_issue_id] ) ) {
248 if ( bug_is_resolved( $t_issue_id ) ) {
249 $t_issues_resolved++
;
252 $t_issues_counted[$t_issue_id] = true;
255 if ( 0 === strcasecmp( $t_parent_version, $t_version ) ) {
256 $t_issue_ids[] = $t_issue_id;
257 $t_issue_parents[] = $t_issue_parent;
258 } else if ( !in_array( $t_issue_id, $t_issue_ids ) ) {
259 $t_issue_ids[] = $t_issue_id;
260 $t_issue_parents[] = null;
263 $t_issue_handlers[] = $t_row['handler_id'];
266 user_cache_array_rows( array_unique( $t_issue_handlers ) );
268 $t_progress = $t_issues_planned > 0 ?
( (integer) ( $t_issues_resolved * 100 / $t_issues_planned ) ) : 0;
270 if ( $t_issues_planned > 0 ) {
271 $t_progress = (integer) ( $t_issues_resolved * 100 / $t_issues_planned );
273 if ( !$t_project_header_printed ) {
274 print_project_header_roadmap( $t_project_name );
275 $t_project_header_printed = true;
278 if ( !$t_version_header_printed ) {
279 print_version_header( $t_version_row );
280 $t_version_header_printed = true;
283 if ( !is_blank( $t_description ) ) {
284 echo string_display( '<br />' .$t_description . '<br />' );
288 echo '<div class="progress400">';
289 echo ' <span class="bar" style="width: ' . $t_progress . '%;">' . $t_progress . '%</span>';
293 $t_issue_set_ids = array();
294 $t_issue_set_levels = array();
298 $t_cycle_ids = array();
300 while ( 0 < count( $t_issue_ids ) ) {
301 $t_issue_id = $t_issue_ids[$k];
302 $t_issue_parent = $t_issue_parents[$k];
304 if ( in_array( $t_issue_id, $t_cycle_ids ) && in_array( $t_issue_parent, $t_cycle_ids ) ) {
308 $t_cycle_ids[] = $t_issue_id;
311 if ( $t_cycle ||
!in_array( $t_issue_parent, $t_issue_ids ) ) {
312 $l = array_search( $t_issue_parent, $t_issue_set_ids );
313 if ( $l !== false ) {
314 for ( $m = $l+
1; $m < count( $t_issue_set_ids ) && $t_issue_set_levels[$m] > $t_issue_set_levels[$l]; $m++
) {
317 $t_issue_set_ids_end = array_splice( $t_issue_set_ids, $m );
318 $t_issue_set_levels_end = array_splice( $t_issue_set_levels, $m );
319 $t_issue_set_ids[] = $t_issue_id;
320 $t_issue_set_levels[] = $t_issue_set_levels[$l] +
1;
321 $t_issue_set_ids = array_merge( $t_issue_set_ids, $t_issue_set_ids_end );
322 $t_issue_set_levels = array_merge( $t_issue_set_levels, $t_issue_set_levels_end );
324 $t_issue_set_ids[] = $t_issue_id;
325 $t_issue_set_levels[] = 0;
327 array_splice( $t_issue_ids, $k, 1 );
328 array_splice( $t_issue_parents, $k, 1 );
330 $t_cycle_ids = array();
334 if ( count( $t_issue_ids ) <= $k ) {
339 $t_count_ids = count( $t_issue_set_ids );
340 for ( $j = 0; $j < $t_count_ids; $j++
) {
341 $t_issue_set_id = $t_issue_set_ids[$j];
342 $t_issue_set_level = $t_issue_set_levels[$j];
344 helper_call_custom_function( 'roadmap_print_issue', array( $t_issue_set_id, $t_issue_set_level ) );
347 if ( $t_issues_planned > 0 ) {
349 echo sprintf( lang_get( 'resolved_progress' ), $t_issues_resolved, $t_issues_planned, $t_progress );