2 # MantisBT - A PHP based bugtracking system
4 # MantisBT is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 2 of the License, or
7 # (at your option) any later version.
9 # MantisBT is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with MantisBT. If not, see <http://www.gnu.org/licenses/>.
19 * @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
20 * @copyright Copyright (C) 2002 - 2011 MantisBT Team - mantisbt-dev@lists.sourceforge.net
21 * @link http://www.mantisbt.org
24 * @uses authentication_api.php
25 * @uses columns_api.php
26 * @uses constant_inc.php
29 * @uses filter_api.php
30 * @uses helper_api.php
37 require_once( 'core.php' );
38 require_api( 'authentication_api.php' );
39 require_api( 'columns_api.php' );
40 require_api( 'constant_inc.php' );
41 require_api( 'csv_api.php' );
42 require_api( 'file_api.php' );
43 require_api( 'filter_api.php' );
44 require_api( 'helper_api.php' );
45 require_api( 'print_api.php' );
47 auth_ensure_user_authenticated();
49 helper_begin_long_process();
56 $t_nl = csv_get_newline();
57 $t_sep = csv_get_separator();
59 # Get bug rows according to the current filter
60 $t_rows = filter_get_bug_rows( $t_page_number, $t_per_page, $t_page_count, $t_bug_count );
61 if ( $t_rows === false ) {
62 print_header_redirect( 'view_all_set.php?type=0' );
65 $t_filename = csv_get_default_filename();
67 # Send headers to browser to activate mime loading
69 # Make sure that IE can download the attachments under https.
70 header( 'Pragma: public' );
72 header( 'Content-Type: text/plain; name=' . urlencode( file_clean_name( $t_filename ) ) );
73 header( 'Content-Transfer-Encoding: BASE64;' );
75 # Added Quotes (") around file name.
76 header( 'Content-Disposition: attachment; filename="' . urlencode( file_clean_name( $t_filename ) ) . '"' );
78 # Get columns to be exported
79 $t_columns = csv_get_columns();
82 $t_first_column = true;
85 foreach ( $t_columns as $t_column ) {
86 if ( !$t_first_column ) {
89 $t_first_column = false;
92 echo column_get_title( $t_column );
97 $t_header = ob_get_clean();
99 # Fixed for a problem in Excel where it prompts error message "SYLK: File Format Is Not Valid"
100 # See Microsoft Knowledge Base Article - 323626
101 # http://support.microsoft.com/default.aspx?scid=kb;en-us;323626&Product=xlw
102 $t_first_three_chars = utf8_substr( $t_header, 0, 3 );
103 if ( strcmp( $t_first_three_chars, 'ID' . $t_sep ) == 0 ) {
104 $t_header = str_replace( 'ID' . $t_sep, 'Id' . $t_sep, $t_header );
111 foreach ( $t_rows as $t_row ) {
112 $t_first_column = true;
114 foreach ( $t_columns as $t_column ) {
115 if ( !$t_first_column ) {
118 $t_first_column = false;
121 $t_custom_field = column_get_custom_field_name( $t_column );
122 if ( $t_custom_field !== null ) {
124 $t_column_value_function = 'print_column_value';
125 helper_call_custom_function( $t_column_value_function, array( $t_column, $t_row, COLUMNS_TARGET_CSV_PAGE
) );
126 $t_value = ob_get_clean();
128 echo csv_escape_string($t_value);
130 $t_function = 'csv_format_' . $t_column;
131 echo $t_function( $t_row->$t_column );