Fix #11417: Allow EVENT_MENU_MAIN plugin events to return null
[mantis/radio.git] / csv_export.php
blob7a62f737da2b58f43fada105018da5614f8850f4
1 <?php
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/>.
17 /**
18 * @package MantisBT
19 * @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
20 * @copyright Copyright (C) 2002 - 2010 MantisBT Team - mantisbt-dev@lists.sourceforge.net
21 * @link http://www.mantisbt.org
23 * @uses core.php
24 * @uses authentication_api.php
25 * @uses columns_api.php
26 * @uses constant_inc.php
27 * @uses csv_api.php
28 * @uses file_api.php
29 * @uses filter_api.php
30 * @uses helper_api.php
31 * @uses print_api.php
34 require_once( 'core.php' );
35 require_api( 'authentication_api.php' );
36 require_api( 'columns_api.php' );
37 require_api( 'constant_inc.php' );
38 require_api( 'csv_api.php' );
39 require_api( 'file_api.php' );
40 require_api( 'filter_api.php' );
41 require_api( 'helper_api.php' );
42 require_api( 'print_api.php' );
44 auth_ensure_user_authenticated();
46 helper_begin_long_process();
48 $t_page_number = 1;
49 $t_per_page = -1;
50 $t_bug_count = null;
51 $t_page_count = null;
53 $t_nl = csv_get_newline();
54 $t_sep = csv_get_separator();
56 # Get bug rows according to the current filter
57 $t_rows = filter_get_bug_rows( $t_page_number, $t_per_page, $t_page_count, $t_bug_count );
58 if ( $t_rows === false ) {
59 print_header_redirect( 'view_all_set.php?type=0' );
62 $t_filename = csv_get_default_filename();
64 # Send headers to browser to activate mime loading
66 # Make sure that IE can download the attachments under https.
67 header( 'Pragma: public' );
69 header( 'Content-Type: text/plain; name=' . urlencode( file_clean_name( $t_filename ) ) );
70 header( 'Content-Transfer-Encoding: BASE64;' );
72 # Added Quotes (") around file name.
73 header( 'Content-Disposition: attachment; filename="' . urlencode( file_clean_name( $t_filename ) ) . '"' );
75 # Get columns to be exported
76 $t_columns = csv_get_columns();
78 # export the titles
79 $t_first_column = true;
80 ob_start();
81 $t_titles = array();
82 foreach ( $t_columns as $t_column ) {
83 if ( !$t_first_column ) {
84 echo $t_sep;
85 } else {
86 $t_first_column = false;
89 echo column_get_title( $t_column );
92 echo $t_nl;
94 $t_header = ob_get_clean();
96 # Fixed for a problem in Excel where it prompts error message "SYLK: File Format Is Not Valid"
97 # See Microsoft Knowledge Base Article - 323626
98 # http://support.microsoft.com/default.aspx?scid=kb;en-us;323626&Product=xlw
99 $t_first_three_chars = utf8_substr( $t_header, 0, 3 );
100 if ( strcmp( $t_first_three_chars, 'ID' . $t_sep ) == 0 ) {
101 $t_header = str_replace( 'ID' . $t_sep, 'Id' . $t_sep, $t_header );
103 # end of fix
105 echo $t_header;
107 # export the rows
108 foreach ( $t_rows as $t_row ) {
109 $t_first_column = true;
111 foreach ( $t_columns as $t_column ) {
112 if ( !$t_first_column ) {
113 echo $t_sep;
114 } else {
115 $t_first_column = false;
118 $t_custom_field = column_get_custom_field_name( $t_column );
119 if ( $t_custom_field !== null ) {
120 ob_start();
121 $t_column_value_function = 'print_column_value';
122 helper_call_custom_function( $t_column_value_function, array( $t_column, $t_row, COLUMNS_TARGET_CSV_PAGE ) );
123 $t_value = ob_get_clean();
125 echo csv_escape_string($t_value);
126 } else {
127 $t_function = 'csv_format_' . $t_column;
128 echo $t_function( $t_row->$t_column );
132 echo $t_nl;