PageRenderTime 35ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/changelog_page.php

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