PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/MantisBT/roadmap_page.php

https://bitbucket.org/crypticrod/sr_wp_code
PHP | 316 lines | 216 code | 68 blank | 32 comment | 58 complexity | 8018f50755b5aa83bb5a17544594059d MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1, GPL-3.0, LGPL-2.0, AGPL-3.0
  1. <?php
  2. # MantisBT - a php based bugtracking system
  3. # MantisBT is free software: you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation, either version 2 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # MantisBT is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with MantisBT. If not, see <http://www.gnu.org/licenses/>.
  15. /**
  16. * @package MantisBT
  17. * @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
  18. * @copyright Copyright (C) 2002 - 2011 MantisBT Team - mantisbt-dev@lists.sourceforge.net
  19. * @link http://www.mantisbt.org
  20. */
  21. /**
  22. * MantisBT Core API's
  23. */
  24. require_once( 'core.php' );
  25. require_once( 'bug_api.php' );
  26. # Print header for the specified project version.
  27. function print_version_header( $p_version_row ) {
  28. $t_project_id = $p_version_row['project_id'];
  29. $t_version_id = $p_version_row['id'];
  30. $t_version_name = $p_version_row['version'];
  31. $t_project_name = project_get_field( $t_project_id, 'name' );
  32. $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>';
  33. if ( config_get( 'show_roadmap_dates' ) ) {
  34. $t_version_timestamp = $p_version_row['date_order'];
  35. $t_scheduled_release_date = ' (' . lang_get( 'scheduled_release' ) . ' ' . string_display_line( date( config_get( 'short_date_format' ), $t_version_timestamp ) ) . ')';
  36. } else {
  37. $t_scheduled_release_date = '';
  38. }
  39. echo '<tt>';
  40. 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 />';
  41. $t_release_title_without_hyperlinks = $t_project_name . ' - ' . $t_version_name . $t_scheduled_release_date;
  42. echo utf8_str_pad( '', utf8_strlen( $t_release_title_without_hyperlinks ), '=' ), '<br />';
  43. }
  44. # print project header
  45. function print_project_header_roadmap( $p_project_name ) {
  46. echo '<br /><span class="pagetitle">', string_display( $p_project_name ), ' - ', lang_get( 'roadmap' ), '</span><br />';
  47. }
  48. $t_user_id = auth_get_current_user_id();
  49. $f_project = gpc_get_string( 'project', '' );
  50. if ( is_blank( $f_project ) ) {
  51. $f_project_id = gpc_get_int( 'project_id', -1 );
  52. } else {
  53. $f_project_id = project_get_id_by_name( $f_project );
  54. if ( $f_project_id === 0 ) {
  55. trigger_error( ERROR_PROJECT_NOT_FOUND, ERROR );
  56. }
  57. }
  58. $f_version = gpc_get_string( 'version', '' );
  59. if ( is_blank( $f_version ) ) {
  60. $f_version_id = gpc_get_int( 'version_id', -1 );
  61. # If both version_id and project_id parameters are supplied, then version_id take precedence.
  62. if ( $f_version_id == -1 ) {
  63. if ( $f_project_id == -1 ) {
  64. $t_project_id = helper_get_current_project();
  65. } else {
  66. $t_project_id = $f_project_id;
  67. }
  68. } else {
  69. $t_project_id = version_get_field( $f_version_id, 'project_id' );
  70. }
  71. } else {
  72. if ( $f_project_id == -1 ) {
  73. $t_project_id = helper_get_current_project();
  74. } else {
  75. $t_project_id = $f_project_id;
  76. }
  77. $f_version_id = version_get_id( $f_version, $t_project_id );
  78. if ( $f_version_id === false ) {
  79. error_parameters( $f_version );
  80. trigger_error( ERROR_VERSION_NOT_FOUND, ERROR );
  81. }
  82. }
  83. if ( ALL_PROJECTS == $t_project_id ) {
  84. $t_topprojects = $t_project_ids = user_get_accessible_projects( $t_user_id );
  85. foreach ( $t_topprojects as $t_project ) {
  86. $t_project_ids = array_merge( $t_project_ids, user_get_all_accessible_subprojects( $t_user_id, $t_project ) );
  87. }
  88. $t_project_ids_to_check = array_unique( $t_project_ids );
  89. $t_project_ids = array();
  90. foreach ( $t_project_ids_to_check as $t_project_id ) {
  91. $t_roadmap_view_access_level = config_get( 'roadmap_view_threshold', null, null, $t_project_id );
  92. if ( access_has_project_level( $t_roadmap_view_access_level, $t_project_id ) ) {
  93. $t_project_ids[] = $t_project_id;
  94. }
  95. }
  96. } else {
  97. access_ensure_project_level( config_get( 'roadmap_view_threshold' ), $t_project_id );
  98. $t_project_ids = user_get_all_accessible_subprojects( $t_user_id, $t_project_id );
  99. array_unshift( $t_project_ids, $t_project_id );
  100. }
  101. html_page_top( lang_get( 'roadmap' ) );
  102. $t_project_index = 0;
  103. version_cache_array_rows( $t_project_ids );
  104. category_cache_array_rows_by_project( $t_project_ids );
  105. foreach( $t_project_ids as $t_project_id ) {
  106. $t_project_name = project_get_field( $t_project_id, 'name' );
  107. $t_can_view_private = access_has_project_level( config_get( 'private_bug_threshold' ), $t_project_id );
  108. $t_limit_reporters = config_get( 'limit_reporters' );
  109. $t_user_access_level_is_reporter = ( REPORTER == access_get_project_level( $t_project_id ) );
  110. $t_resolved = config_get( 'bug_resolved_status_threshold' );
  111. $t_bug_table = db_get_table( 'mantis_bug_table' );
  112. $t_relation_table = db_get_table( 'mantis_bug_relationship_table' );
  113. $t_version_rows = array_reverse( version_get_all_rows( $t_project_id ) );
  114. # cache category info, but ignore the results for now
  115. category_get_all_rows( $t_project_id );
  116. $t_project_header_printed = false;
  117. foreach( $t_version_rows as $t_version_row ) {
  118. if ( $t_version_row['released'] == 1 ) {
  119. continue;
  120. }
  121. # Skip all versions except the specified one (if any).
  122. if ( $f_version_id != -1 && $f_version_id != $t_version_row['id'] ) {
  123. continue;
  124. }
  125. $t_issues_planned = 0;
  126. $t_issues_resolved = 0;
  127. $t_issues_counted = array();
  128. $t_version_header_printed = false;
  129. $t_version = $t_version_row['version'];
  130. $query = "SELECT sbt.*, $t_relation_table.source_bug_id, dbt.target_version as parent_version FROM $t_bug_table AS sbt
  131. LEFT JOIN $t_relation_table ON sbt.id=$t_relation_table.destination_bug_id AND $t_relation_table.relationship_type=2
  132. LEFT JOIN $t_bug_table AS dbt ON dbt.id=$t_relation_table.source_bug_id
  133. WHERE sbt.project_id=" . db_param() . " AND sbt.target_version=" . db_param() . " ORDER BY sbt.status ASC, sbt.last_updated DESC";
  134. $t_description = $t_version_row['description'];
  135. $t_first_entry = true;
  136. $t_result = db_query_bound( $query, Array( $t_project_id, $t_version ) );
  137. $t_issue_ids = array();
  138. $t_issue_parents = array();
  139. $t_issue_handlers = array();
  140. while ( $t_row = db_fetch_array( $t_result ) ) {
  141. # hide private bugs if user doesn't have access to view them.
  142. if ( !$t_can_view_private && ( $t_row['view_state'] == VS_PRIVATE ) ) {
  143. continue;
  144. }
  145. bug_cache_database_result( $t_row );
  146. # check limit_Reporter (Issue #4770)
  147. # reporters can view just issues they reported
  148. if ( ON === $t_limit_reporters && $t_user_access_level_is_reporter &&
  149. !bug_is_user_reporter( $t_row['id'], $t_user_id )) {
  150. continue;
  151. }
  152. $t_issue_id = $t_row['id'];
  153. $t_issue_parent = $t_row['source_bug_id'];
  154. $t_parent_version = $t_row['parent_version'];
  155. if ( !helper_call_custom_function( 'roadmap_include_issue', array( $t_issue_id ) ) ) {
  156. continue;
  157. }
  158. if ( !isset( $t_issues_counted[$t_issue_id] ) ) {
  159. $t_issues_planned++;
  160. if ( bug_is_resolved( $t_issue_id ) ) {
  161. $t_issues_resolved++;
  162. }
  163. $t_issues_counted[$t_issue_id] = true;
  164. }
  165. if ( 0 === strcasecmp( $t_parent_version, $t_version ) ) {
  166. $t_issue_ids[] = $t_issue_id;
  167. $t_issue_parents[] = $t_issue_parent;
  168. } else if ( !in_array( $t_issue_id, $t_issue_ids ) ) {
  169. $t_issue_ids[] = $t_issue_id;
  170. $t_issue_parents[] = null;
  171. }
  172. $t_issue_handlers[] = $t_row['handler_id'];
  173. }
  174. user_cache_array_rows( array_unique( $t_issue_handlers ) );
  175. $t_progress = $t_issues_planned > 0 ? ( (integer) ( $t_issues_resolved * 100 / $t_issues_planned ) ) : 0;
  176. if ( $t_issues_planned > 0 ) {
  177. $t_progress = (integer) ( $t_issues_resolved * 100 / $t_issues_planned );
  178. if ( !$t_project_header_printed ) {
  179. print_project_header_roadmap( $t_project_name );
  180. $t_project_header_printed = true;
  181. }
  182. if ( !$t_version_header_printed ) {
  183. print_version_header( $t_version_row );
  184. $t_version_header_printed = true;
  185. }
  186. if ( !is_blank( $t_description ) ) {
  187. echo string_display( '<br />' .$t_description . '<br />' );
  188. }
  189. // show progress bar
  190. echo '<div class="progress400">';
  191. echo ' <span class="bar" style="width: ' . $t_progress . '%;">' . $t_progress . '%</span>';
  192. echo '</div>';
  193. }
  194. $t_issue_set_ids = array();
  195. $t_issue_set_levels = array();
  196. $k = 0;
  197. $t_cycle = false;
  198. $t_cycle_ids = array();
  199. while ( 0 < count( $t_issue_ids ) ) {
  200. $t_issue_id = $t_issue_ids[$k];
  201. $t_issue_parent = $t_issue_parents[$k];
  202. if ( in_array( $t_issue_id, $t_cycle_ids ) && in_array( $t_issue_parent, $t_cycle_ids ) ) {
  203. $t_cycle = true;
  204. } else {
  205. $t_cycle = false;
  206. $t_cycle_ids[] = $t_issue_id;
  207. }
  208. if ( $t_cycle || !in_array( $t_issue_parent, $t_issue_ids ) ) {
  209. $l = array_search( $t_issue_parent, $t_issue_set_ids );
  210. if ( $l !== false ) {
  211. for ( $m = $l+1; $m < count( $t_issue_set_ids ) && $t_issue_set_levels[$m] > $t_issue_set_levels[$l]; $m++ ) {
  212. #do nothing
  213. }
  214. $t_issue_set_ids_end = array_splice( $t_issue_set_ids, $m );
  215. $t_issue_set_levels_end = array_splice( $t_issue_set_levels, $m );
  216. $t_issue_set_ids[] = $t_issue_id;
  217. $t_issue_set_levels[] = $t_issue_set_levels[$l] + 1;
  218. $t_issue_set_ids = array_merge( $t_issue_set_ids, $t_issue_set_ids_end );
  219. $t_issue_set_levels = array_merge( $t_issue_set_levels, $t_issue_set_levels_end );
  220. } else {
  221. $t_issue_set_ids[] = $t_issue_id;
  222. $t_issue_set_levels[] = 0;
  223. }
  224. array_splice( $t_issue_ids, $k, 1 );
  225. array_splice( $t_issue_parents, $k, 1 );
  226. $t_cycle_ids = array();
  227. } else {
  228. $k++;
  229. }
  230. if ( count( $t_issue_ids ) <= $k ) {
  231. $k = 0;
  232. }
  233. }
  234. $t_count_ids = count( $t_issue_set_ids );
  235. for ( $j = 0; $j < $t_count_ids; $j++ ) {
  236. $t_issue_set_id = $t_issue_set_ids[$j];
  237. $t_issue_set_level = $t_issue_set_levels[$j];
  238. helper_call_custom_function( 'roadmap_print_issue', array( $t_issue_set_id, $t_issue_set_level ) );
  239. }
  240. if ( $t_issues_planned > 0 ) {
  241. echo '<br />';
  242. echo sprintf( lang_get( 'resolved_progress' ), $t_issues_resolved, $t_issues_planned, $t_progress );
  243. echo '<br /></tt>';
  244. }
  245. }
  246. $t_project_index++;
  247. }
  248. html_page_bottom();