PageRenderTime 53ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/MantisBT/changelog_page.php

https://bitbucket.org/crypticrod/sr_wp_code
PHP | 319 lines | 213 code | 63 blank | 43 comment | 62 complexity | 35ae25420a2eaa178b0589453a56d48e 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. /**
  26. * requires bug_api
  27. */
  28. require_once( 'bug_api.php' );
  29. /**
  30. * Print header for the specified project version.
  31. * @param int $p_version_id a valid version id
  32. * @return null
  33. */
  34. function print_version_header( $p_version_id ) {
  35. $t_project_id = version_get_field( $p_version_id, 'project_id' );
  36. $t_version_name = version_get_field( $p_version_id, 'version' );
  37. $t_project_name = project_get_field( $t_project_id, 'name' );
  38. $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>';
  39. if ( config_get( 'show_changelog_dates' ) ) {
  40. $t_version_released = version_get_field( $p_version_id, 'released' );
  41. $t_release_timestamp = version_get_field( $p_version_id, 'date_order' );
  42. if ( (bool) $t_version_released ) {
  43. $t_release_date = ' (' . lang_get('released') . ' ' . string_display_line( date( config_get( 'short_date_format' ), $t_release_timestamp ) ) . ')';
  44. } else {
  45. $t_release_date = ' (' . lang_get( 'not_released' ) . ')';
  46. }
  47. } else {
  48. $t_release_date = '';
  49. }
  50. 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 />';
  51. $t_release_title_without_hyperlinks = $t_project_name . ' - ' . $t_version_name . $t_release_date;
  52. echo utf8_str_pad( '', utf8_strlen( $t_release_title_without_hyperlinks ), '=' ), '<br />';
  53. }
  54. /**
  55. * Print header for the specified project
  56. * @param string $p_project_name project name to display
  57. * @return null
  58. */
  59. function print_project_header_changelog ( $p_project_name ) {
  60. echo '<br /><span class="pagetitle">', string_display_line( $p_project_name ), ' - ', lang_get( 'changelog' ), '</span><br />';
  61. echo '<tt>';
  62. }
  63. $t_user_id = auth_get_current_user_id();
  64. $f_project = gpc_get_string( 'project', '' );
  65. if ( is_blank( $f_project ) ) {
  66. $f_project_id = gpc_get_int( 'project_id', -1 );
  67. } else {
  68. $f_project_id = project_get_id_by_name( $f_project );
  69. if ( $f_project_id === 0 ) {
  70. trigger_error( ERROR_PROJECT_NOT_FOUND, ERROR );
  71. }
  72. }
  73. $f_version = gpc_get_string( 'version', '' );
  74. if ( is_blank( $f_version ) ) {
  75. $f_version_id = gpc_get_int( 'version_id', -1 );
  76. # If both version_id and project_id parameters are supplied, then version_id take precedence.
  77. if ( $f_version_id == -1 ) {
  78. if ( $f_project_id == -1 ) {
  79. $t_project_id = helper_get_current_project();
  80. } else {
  81. $t_project_id = $f_project_id;
  82. }
  83. } else {
  84. $t_project_id = version_get_field( $f_version_id, 'project_id' );
  85. }
  86. } else {
  87. if ( $f_project_id == -1 ) {
  88. $t_project_id = helper_get_current_project();
  89. } else {
  90. $t_project_id = $f_project_id;
  91. }
  92. $f_version_id = version_get_id( $f_version, $t_project_id );
  93. if ( $f_version_id === false ) {
  94. error_parameters( $f_version );
  95. trigger_error( ERROR_VERSION_NOT_FOUND, ERROR );
  96. }
  97. }
  98. if ( ALL_PROJECTS == $t_project_id ) {
  99. $t_topprojects = $t_project_ids = user_get_accessible_projects( $t_user_id );
  100. foreach ( $t_topprojects as $t_project ) {
  101. $t_project_ids = array_merge( $t_project_ids, user_get_all_accessible_subprojects( $t_user_id, $t_project ) );
  102. }
  103. $t_project_ids_to_check = array_unique( $t_project_ids );
  104. $t_project_ids = array();
  105. foreach ( $t_project_ids_to_check as $t_project_id ) {
  106. $t_changelog_view_access_level = config_get( 'view_changelog_threshold', null, null, $t_project_id );
  107. if ( access_has_project_level( $t_changelog_view_access_level, $t_project_id ) ) {
  108. $t_project_ids[] = $t_project_id;
  109. }
  110. }
  111. } else {
  112. access_ensure_project_level( config_get( 'view_changelog_threshold' ), $t_project_id );
  113. $t_project_ids = user_get_all_accessible_subprojects( $t_user_id, $t_project_id );
  114. array_unshift( $t_project_ids, $t_project_id );
  115. }
  116. html_page_top( lang_get( 'changelog' ) );
  117. $t_project_index = 0;
  118. version_cache_array_rows( $t_project_ids );
  119. category_cache_array_rows_by_project( $t_project_ids );
  120. foreach( $t_project_ids as $t_project_id ) {
  121. $t_project_name = project_get_field( $t_project_id, 'name' );
  122. $t_can_view_private = access_has_project_level( config_get( 'private_bug_threshold' ), $t_project_id );
  123. $t_limit_reporters = config_get( 'limit_reporters' );
  124. $t_user_access_level_is_reporter = ( REPORTER == access_get_project_level( $t_project_id ) );
  125. $t_resolved = config_get( 'bug_resolved_status_threshold' );
  126. $t_bug_table = db_get_table( 'mantis_bug_table' );
  127. $t_relation_table = db_get_table( 'mantis_bug_relationship_table' );
  128. # grab version info for later use
  129. $t_version_rows = version_get_all_rows( $t_project_id, /* released */ null, /* obsolete */ false );
  130. # cache category info, but ignore the results for now
  131. category_get_all_rows( $t_project_id );
  132. $t_project_header_printed = false;
  133. foreach( $t_version_rows as $t_version_row ) {
  134. $t_issues_planned = 0;
  135. $t_issues_resolved = 0;
  136. $t_version_header_printed = false;
  137. $t_version = $t_version_row['version'];
  138. $t_version_id = $t_version_row['id'];
  139. # Skip all versions except the specified one (if any).
  140. if ( $f_version_id != -1 && $f_version_id != $t_version_id ) {
  141. continue;
  142. }
  143. $query = "SELECT sbt.*, dbt.target_version AS parent_version, $t_relation_table.source_bug_id FROM $t_bug_table AS sbt
  144. LEFT JOIN $t_relation_table ON sbt.id=$t_relation_table.destination_bug_id AND $t_relation_table.relationship_type=2
  145. LEFT JOIN $t_bug_table AS dbt ON dbt.id=$t_relation_table.source_bug_id
  146. WHERE sbt.project_id=" . db_param() . " AND sbt.fixed_in_version=" . db_param() . " ORDER BY sbt.status ASC, sbt.last_updated DESC";
  147. $t_description = version_get_field( $t_version_id, 'description' );
  148. $t_first_entry = true;
  149. $t_issue_ids = array();
  150. $t_issue_parents = array();
  151. $t_issue_handlers = array();
  152. $t_result = db_query_bound( $query, Array( $t_project_id, $t_version ) );
  153. while ( $t_row = db_fetch_array( $t_result ) ) {
  154. # hide private bugs if user doesn't have access to view them.
  155. if ( !$t_can_view_private && ( $t_row['view_state'] == VS_PRIVATE ) ) {
  156. continue;
  157. }
  158. bug_cache_database_result( $t_row );
  159. # check limit_Reporter (Issue #4770)
  160. # reporters can view just issues they reported
  161. if ( ON === $t_limit_reporters && $t_user_access_level_is_reporter &&
  162. !bug_is_user_reporter( $t_row['id'], $t_user_id )) {
  163. continue;
  164. }
  165. $t_issue_id = $t_row['id'];
  166. $t_issue_parent = $t_row['source_bug_id'];
  167. $t_parent_version = $t_row['parent_version'];
  168. if ( !helper_call_custom_function( 'changelog_include_issue', array( $t_issue_id ) ) ) {
  169. continue;
  170. }
  171. $t_issues_resolved++;
  172. if ( 0 === strcasecmp( $t_parent_version, $t_version ) ) {
  173. $t_issue_ids[] = $t_issue_id;
  174. $t_issue_parents[] = $t_issue_parent;
  175. } else if ( !in_array( $t_issue_id, $t_issue_ids ) ) {
  176. $t_issue_ids[] = $t_issue_id;
  177. $t_issue_parents[] = null;
  178. }
  179. $t_issue_handlers[] = $t_row['handler_id'];
  180. }
  181. user_cache_array_rows( array_unique( $t_issue_handlers ) );
  182. if ( $t_issues_resolved > 0 ) {
  183. if ( !$t_project_header_printed ) {
  184. print_project_header_changelog( $t_project_name );
  185. $t_project_header_printed = true;
  186. }
  187. if ( !$t_version_header_printed ) {
  188. print_version_header( $t_version_id );
  189. $t_version_header_printed = true;
  190. }
  191. if ( !is_blank( $t_description ) ) {
  192. echo string_display( "<br />$t_description<br /><br />" );
  193. }
  194. }
  195. $t_issue_set_ids = array();
  196. $t_issue_set_levels = array();
  197. $k = 0;
  198. $t_cycle = false;
  199. $t_cycle_ids = array();
  200. while ( !empty( $t_issue_ids ) ) {
  201. $t_issue_id = $t_issue_ids[$k];
  202. $t_issue_parent = $t_issue_parents[$k];
  203. if ( in_array( $t_issue_id, $t_cycle_ids ) && in_array( $t_issue_parent, $t_cycle_ids ) ) {
  204. $t_cycle = true;
  205. } else {
  206. $t_cycle = false;
  207. $t_cycle_ids[] = $t_issue_id;
  208. }
  209. if ( $t_cycle || !in_array( $t_issue_parent, $t_issue_ids ) ) {
  210. $l = array_search( $t_issue_parent, $t_issue_set_ids );
  211. if ( $l !== false ) {
  212. for ( $m = $l+1; $m < count( $t_issue_set_ids ) && $t_issue_set_levels[$m] > $t_issue_set_levels[$l]; $m++ ) {
  213. #do nothing
  214. }
  215. $t_issue_set_ids_end = array_splice( $t_issue_set_ids, $m );
  216. $t_issue_set_levels_end = array_splice( $t_issue_set_levels, $m );
  217. $t_issue_set_ids[] = $t_issue_id;
  218. $t_issue_set_levels[] = $t_issue_set_levels[$l] + 1;
  219. $t_issue_set_ids = array_merge( $t_issue_set_ids, $t_issue_set_ids_end );
  220. $t_issue_set_levels = array_merge( $t_issue_set_levels, $t_issue_set_levels_end );
  221. } else {
  222. $t_issue_set_ids[] = $t_issue_id;
  223. $t_issue_set_levels[] = 0;
  224. }
  225. array_splice( $t_issue_ids, $k, 1 );
  226. array_splice( $t_issue_parents, $k, 1 );
  227. $t_cycle_ids = array();
  228. } else {
  229. $k++;
  230. }
  231. if ( count( $t_issue_ids ) <= $k ) {
  232. $k = 0;
  233. }
  234. }
  235. for ( $j = 0; $j < count( $t_issue_set_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( 'changelog_print_issue', array( $t_issue_set_id, $t_issue_set_level ) );
  239. }
  240. if ( $t_issues_resolved == 1 ) {
  241. echo "[{$t_issues_resolved} " . lang_get( 'bug' ) . ']';
  242. echo "<br />";
  243. } else if ( $t_issues_resolved > 1 ) {
  244. echo "[{$t_issues_resolved} " . lang_get( 'bugs' ) . ']';
  245. echo "<br />";
  246. }
  247. }
  248. if ( $t_project_header_printed ) {
  249. echo '</tt>';
  250. }
  251. $t_project_index++;
  252. }
  253. if ( $t_project_index == 0 ) {
  254. echo '<br /><span class="pagetitle">' . lang_get('changelog_empty') . '</span>';
  255. }
  256. html_page_bottom();