File: changelog_page.php

package info (click to toggle)
mantis 1.1.6+dfsg-2lenny6
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 9,576 kB
  • ctags: 14,851
  • sloc: php: 54,817; sql: 348; sh: 181; makefile: 56
file content (232 lines) | stat: -rw-r--r-- 8,051 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
<?php
# Mantis - a php based bugtracking system

# Copyright (C) 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
# Copyright (C) 2002 - 2007  Mantis Team   - mantisbt-dev@lists.sourceforge.net

# Mantis is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# Mantis is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Mantis.  If not, see <http://www.gnu.org/licenses/>.

	# --------------------------------------------------------
	# $Id: changelog_page.php,v 1.23.2.1 2007-10-13 22:33:11 giallu Exp $
	# --------------------------------------------------------

	require_once( 'core.php' );

	$t_core_path = config_get( 'core_path' );

	require_once( $t_core_path.'bug_api.php' );

	# Print header for the specified project version.
	function print_version_header( $p_version_id ) {
		$t_project_id   = version_get_field( $p_version_id, 'project_id' );
		$t_version_name = version_get_field( $p_version_id, 'version' );
		$t_project_name = project_get_field( $t_project_id, 'name' );

		$t_release_title = string_display( $t_project_name ) . ' - ' . string_display( $t_version_name );
		echo '<tt>';
		echo '<br />', $t_release_title, '<br />';
		echo str_pad( '', strlen( $t_release_title ), '=' ), '<br />';
	}
	
	function print_project_header ( $p_project_name ) {
		echo '<br /><span class="pagetitle">', string_display( $p_project_name ), ' - ', lang_get( 'changelog' ), '</span><br />';
	}

	$t_user_id = auth_get_current_user_id();
	$f_project_id = gpc_get_int( 'project_id', helper_get_current_project() );

	if ( ALL_PROJECTS == $f_project_id ) {
		$t_topprojects = $t_project_ids = user_get_accessible_projects( $t_user_id );
		foreach ( $t_topprojects as $t_project ) {
			$t_project_ids = array_merge( $t_project_ids, user_get_all_accessible_subprojects( $t_user_id, $t_project ) );
		}

		$t_project_ids_to_check = array_unique( $t_project_ids );
		$t_project_ids = array();

		foreach ( $t_project_ids_to_check as $t_project_id ) {
			$t_changelog_view_access_level = config_get( 'view_changelog_threshold', null, null, $t_project_id );
			if ( access_has_project_level( $t_changelog_view_access_level, $t_project_id ) ) {
				$t_project_ids[] = $t_project_id;
			}
		}
	} else {
		access_ensure_project_level( config_get( 'view_changelog_threshold' ), $f_project_id );
		$t_project_ids = user_get_all_accessible_subprojects( $t_user_id, $f_project_id );
		array_unshift( $t_project_ids, $f_project_id );
	}

	html_page_top1( lang_get( 'changelog' ) );  // title
	html_page_top2();

	$t_project_index = 0;

	foreach( $t_project_ids as $t_project_id ) {
		$c_project_id   = db_prepare_int( $t_project_id );
		$t_project_name = project_get_field( $t_project_id, 'name' );
		$t_can_view_private = access_has_project_level( config_get( 'private_bug_threshold' ), $t_project_id );

		$t_limit_reporters = config_get( 'limit_reporters' );
		$t_user_access_level_is_reporter = ( REPORTER == access_get_project_level( $t_project_id ) );

		$t_resolved = config_get( 'bug_resolved_status_threshold' );
		$t_bug_table	= config_get( 'mantis_bug_table' );
		$t_relation_table = config_get( 'mantis_bug_relationship_table' );

		$t_version_rows = version_get_all_rows( $t_project_id );
				
		$t_project_header_printed = false;

		foreach( $t_version_rows as $t_version_row ) {
			$t_issues_planned = 0;
			$t_issues_resolved = 0;

			$t_version_header_printed = false;
		
			$t_version = $t_version_row['version'];
			$c_version = db_prepare_string( $t_version );

			$t_version_id = version_get_id( $t_version, $t_project_id );

			$query = "SELECT sbt.*, dbt.target_version AS parent_version, $t_relation_table.source_bug_id FROM $t_bug_table AS sbt
					LEFT JOIN $t_relation_table ON sbt.id=$t_relation_table.destination_bug_id AND $t_relation_table.relationship_type=2
					LEFT JOIN $t_bug_table AS dbt ON dbt.id=$t_relation_table.source_bug_id
					WHERE sbt.project_id='$c_project_id' AND sbt.fixed_in_version='$c_version' ORDER BY sbt.status ASC, sbt.last_updated DESC";

			$t_description = version_get_field( $t_version_id, 'description' );
					
			$t_first_entry = true;
			$t_issue_ids = array();
			$t_issue_parents = array();

			$t_result = db_query( $query );

			while ( $t_row = db_fetch_array( $t_result ) ) {
				# hide private bugs if user doesn't have access to view them.
				if ( !$t_can_view_private && ( $t_row['view_state'] == VS_PRIVATE ) ) {
					continue;
				}

				bug_cache_database_result( $t_row );

				# check limit_Reporter (Issue #4770)
				# reporters can view just issues they reported
				if ( ON === $t_limit_reporters && $t_user_access_level_is_reporter &&
				!bug_is_user_reporter( $t_row['id'], $t_user_id )) {
					continue;
				}

				$t_issue_id = $t_row['id'];
				$t_issue_parent = $t_row['source_bug_id'];
				$t_parent_version = $t_row['parent_version'];

				if ( !helper_call_custom_function( 'changelog_include_issue', array( $t_issue_id ) ) ) {
					continue;
				}

				$t_issues_resolved++;
				
				if ( 0 === strcasecmp( $t_parent_version, $t_version ) ) {
					$t_issue_ids[] = $t_issue_id;
					$t_issue_parents[] = $t_issue_parent;
				} else if ( !in_array( $t_issue_id, $t_issue_ids ) ) {
					$t_issue_ids[] = $t_issue_id;
					$t_issue_parents[] = null;
				}
			} 

			if ( $t_issues_resolved > 0 ) {
				if ( !$t_project_header_printed ) {
					print_project_header( $t_project_name );
					$t_project_header_printed = true;
				}

				if ( !$t_version_header_printed ) {
					print_version_header( $t_version_id );
 					$t_version_header_printed = true;
				}

				if ( !is_blank( $t_description ) ) {
					echo string_display( "<br />$t_description<br /><br />" );
				}
			}


			$t_issue_set_ids = array();
			$t_issue_set_levels = array();
			$k = 0;
			
			$t_cycle = false;
			$t_cycle_ids = array();

			while ( 0 < count( $t_issue_ids ) ) {
				$t_issue_id = $t_issue_ids[$k];
				$t_issue_parent = $t_issue_parents[$k];
				
				if ( in_array( $t_issue_id, $t_cycle_ids ) || in_array( $t_issue_parent, $t_cycle_ids ) ) {
					$t_cycle = true;
				} else {
					$t_cycle = false;
					$t_cycle_ids[] = $t_issue_id;
				}

				if ( $t_cycle || !in_array( $t_issue_parent, $t_issue_ids ) ) {
					$l = array_search( $t_issue_parent, $t_issue_set_ids );
					if ( $l !== false ) {
						for ( $m = $l+1; $m < count( $t_issue_set_ids ) && $t_issue_set_levels[$m] > $t_issue_set_levels[$l]; $m++ ) {
							#do nothing
						}
						$t_issue_set_ids_end = array_splice( $t_issue_set_ids, $m );
						$t_issue_set_levels_end = array_splice( $t_issue_set_levels, $m );
						$t_issue_set_ids[] = $t_issue_id;
						$t_issue_set_levels[] = $t_issue_set_levels[$l] + 1;
						$t_issue_set_ids = array_merge( $t_issue_set_ids, $t_issue_set_ids_end );
						$t_issue_set_levels = array_merge( $t_issue_set_levels, $t_issue_set_levels_end );
					}
					else {
						$t_issue_set_ids[] = $t_issue_id;
						$t_issue_set_levels[] = 0;
					}
					array_splice( $t_issue_ids, $k, 1 );
					array_splice( $t_issue_parents, $k, 1 );

					$t_cycle_ids = array();
				}
				else {
					$k++;
				}
				if ( count( $t_issue_ids ) <= $k ) {
					$k = 0;
				}
 			}
 
			for ( $j = 0; $j < count( $t_issue_set_ids ); $j++ ) {
				$t_issue_set_id = $t_issue_set_ids[$j];
				$t_issue_set_level = $t_issue_set_levels[$j];
				 
				helper_call_custom_function( 'changelog_print_issue', array( $t_issue_set_id, $t_issue_set_level ) );
			}

			echo '</tt>';
 		}			


		$t_project_index++;
	}

	if ( $t_project_index == 0 ) {
		echo '<br /><span class="pagetitle">' . lang_get('changelog_empty') . '</span>';
	}
	html_page_bottom1( __FILE__ );
?>