/
csv_export.php
86 lines (70 loc) · 2.54 KB
/
csv_export.php
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
<?php
# Mantis - a php based bugtracking system
# Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
# Copyright (C) 2002 - 2004 Mantis Team - mantisbt-dev@lists.sourceforge.net
# This program is distributed under the terms and conditions of the GPL
# See the README and LICENSE files for details
# --------------------------------------------------------
# $Id: csv_export.php,v 1.19 2004-05-30 01:49:31 vboctor Exp $
# --------------------------------------------------------
?>
<?php
require_once( 'core.php' );
$t_core_path = config_get( 'core_path' );
require_once( $t_core_path . 'filter_api.php' );
require_once( $t_core_path . 'csv_api.php' );
?>
<?php auth_ensure_user_authenticated() ?>
<?php
# check to see if the cookie does not exist
if ( !filter_is_cookie_valid() ) {
print_header_redirect( 'view_all_set.php?type=0' );
}
$t_page_number = 1;
$t_per_page = -1;
$t_bug_count = null;
$t_page_count = null;
$t_nl = csv_get_newline();
$t_sep = csv_get_separator();
# Get bug rows according to the current filter
$rows = filter_get_bug_rows( $t_page_number, $t_per_page, $t_page_count, $t_bug_count );
if ( $rows === false ) {
print_header_redirect( 'view_all_set.php?type=0' );
}
$t_filename = csv_get_default_filename();
# Send headers to browser to activate mime loading
header( 'Content-Type: text/plain; name=' . $t_filename );
header( 'Content-Transfer-Encoding: BASE64;' );
header( 'Content-Disposition: attachment; filename=' . $t_filename );
# Get columns to be exported
$t_columns = csv_get_columns();
# export the titles
$t_titles = array();
foreach ( $t_columns as $column => $title ) {
$t_titles[] = lang_get( $title );
}
$t_header = implode( $t_sep, $t_titles ) . $t_nl;
# Fixed for a problem in Excel where it prompts error message "SYLK: File Format Is Not Valid"
# See Microsoft Knowledge Base Article - 323626
# http://support.microsoft.com/default.aspx?scid=kb;en-us;323626&Product=xlw
$t_first_two_chars = substr( $t_header, 0, 2 );
if ( strcmp( $t_first_two_chars, 'ID' ) == 0 ) {
$t_header = str_replace( 'ID,', 'Id,', $t_header );
}
# end of fix
echo $t_header;
# export the rows
foreach ( $rows as $row ) {
$t_values = array();
foreach ( $t_columns as $key => $title ) {
# check if column should be visible
if ( !isset( $row[$key] ) ) {
$t_values[] = '';
continue;
}
$t_function = 'csv_format_' . $key;
$t_values[] = $t_function( $row[ $key ] );
}
echo implode( $t_sep, $t_values ) . $t_nl;
}
?>