PageRenderTime 54ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/changelog_page.php

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