Skip to content

Commit

Permalink
Re-implemented exporting of csv to include the following:
Browse files Browse the repository at this point in the history
Fixed #3259: Saving CSV file of bugs containning double quotes causes invalid csv.
Fixed #3262: CSV export does not export the category column.
Fixed #3264: CSV export should export the resolution.
Fixed #3287: Projectname on CSV export.
Fixed #3346: CSV extract should output more data, e.g., Date Submitted, other data that would allow better analysis of data trends.

A core/csv_api.php
- Implemented APIs to be used in the new csv implementation.

M csv_export.php
- Re-implemented the csv exporting using the new API.


git-svn-id: http://mantisbt.svn.sourceforge.net/svnroot/mantisbt/trunk@2454 f5dc347c-c33d-0410-90a0-b07cc1902cb9
  • Loading branch information
vboctor committed Mar 23, 2004
1 parent 59cb876 commit 92b07e0
Show file tree
Hide file tree
Showing 3 changed files with 254 additions and 28 deletions.
215 changes: 215 additions & 0 deletions core/csv_api.php
@@ -0,0 +1,215 @@
<?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_api.php,v 1.1 2004-03-23 14:00:35 vboctor Exp $
# --------------------------------------------------------

###########################################################################
# CSV API
###########################################################################

# --------------------
# get the csv file new line, can be moved to config in the future
function csv_get_newline() {
return "\r\n";
}

# --------------------
# get the csv file separator, can be moved to config in the future
function csv_get_separator() {
return ',';
}

# --------------------
# if all projects selected, default to <username>.csv, otherwise default to
# <projectname>.csv.
function csv_get_default_filename() {
$t_current_project_id = helper_get_current_project();

if ( ALL_PROJECTS == $t_current_project_id ) {
$t_filename = user_get_name( auth_get_current_user_id() );
} else {
$t_filename = project_get_field( $t_current_project_id, 'name' );
}

return $t_filename . '.csv';
}

# --------------------
# escape a string before writing it to csv file.
function csv_escape_string( $p_str ) {
if ( strpos( $p_str, csv_get_separator() ) !== false ) {
$p_str = '"' . str_replace( '"', '""', $p_str ) . '"';
}

return $p_str;
}

# --------------------
# Identified which fields to include, in which order, and the string to
# pass to lang_get() to retrieve the title.
# array ( 'column_internal_name' => 'lang str for column title', ... )
function csv_get_columns() {
# @@@ Support configuration in the future
$t_columns = array( 'id' => 'id',
'project_id' => 'email_project',
'reporter_id' => 'reporter',
'handler_id' => 'assigned_to',
'priority' => 'priority',
'severity' => 'severity',
'reproducibility' => 'reproducibility',
'version' => 'version',
'projection' => 'projection',
'category' => 'category',
'date_submitted' => 'date_submitted',
'eta' => 'eta',
'os' => 'os',
'os_build' => 'os_version',
'platform' => 'platform',
'view_state' => 'view_status',
'last_updated' => 'last_update',
'summary' => 'summary',
'status' => 'status',
'resolution' => 'resolution',
'duplicate_id' => 'duplicate_id' );
return $t_columns;
}

#
# Formatting Functions
#
# Names for formatting functions are csv_format_*, where * corresponds to the
# field name as return get csv_get_columns() and by the filter api.
#

# --------------------
# format bug id
function csv_format_id( $p_bug_id ) {
return bug_format_id( $p_bug_id );
}

# --------------------
# returns the project name corresponding to the supplied project id.
function csv_format_project_id( $p_project_id ) {
return csv_escape_string( project_get_name( $p_project_id ) );
}

# --------------------
# returns the reporter name corresponding to the supplied id.
function csv_format_reporter_id( $p_reporter_id ) {
return csv_escape_string( user_get_name( $p_reporter_id ) );
}

# --------------------
# returns the handler name corresponding to the supplied id
function csv_format_handler_id( $p_handler_id ) {
return csv_escape_string( user_get_name( $p_handler_id ) );
}

# --------------------
# return the priority string
function csv_format_priority( $p_priority ) {
return csv_escape_string( get_enum_element( 'priority', $p_priority ) );
}

# --------------------
# return the severity string
function csv_format_severity( $p_severity ) {
return csv_escape_string( get_enum_element( 'severity', $p_severity ) );
}

# --------------------
# return the reproducability string
function csv_format_reproducibility( $p_reproducibility ) {
return csv_escape_string( get_enum_element( 'reproducibility', $p_reproducibility ) );
}

# --------------------
# return the version
function csv_format_version( $p_version ) {
return csv_escape_string( $p_version );
}

# --------------------
# return the projection
function csv_format_projection( $p_projection ) {
return csv_escape_string( get_enum_element( 'projection', $p_projection ) );
}

# --------------------
# return the category
function csv_format_category( $p_category ) {
return csv_escape_string( $p_category );
}

# --------------------
# return the date submitted
function csv_format_date_submitted( $p_date_submitted ) {
return date( config_get( 'short_date_format' ), $p_date_submitted );
}

# --------------------
# return the eta
function csv_format_eta( $p_eta ) {
return csv_escape_string( get_enum_element( 'eta', $p_eta ) );
}

# --------------------
# return the operating system
function csv_format_os( $p_os ) {
return csv_escape_string( $p_os );
}

# --------------------
# return the os build (os version)
function csv_format_os_build( $p_os_build ) {
return csv_escape_string( $p_os_build );
}

# --------------------
# return the platform
function csv_format_platform( $p_platform ) {
return csv_escape_string( $p_platform );
}

# --------------------
# return the view state (eg: private / public)
function csv_format_view_state( $p_view_state ) {
return csv_escape_string( get_enum_element( 'view_state', $p_view_state ) );
}

# --------------------
# return the last updated date
function csv_format_last_updated( $p_last_updated ) {
return date( config_get( 'short_date_format' ), $p_last_updated );
}

# --------------------
# return the summary
function csv_format_summary( $p_summary ) {
return csv_escape_string( $p_summary );
}

# --------------------
# return the status string
function csv_format_status( $p_status ) {
return csv_escape_string( get_enum_element( 'status', $p_status ) );
}

# --------------------
# return the resolution string
function csv_format_resolution( $p_resolution ) {
return csv_escape_string( get_enum_element( 'resolution', $p_resolution ) );
}

# --------------------
# return the duplicate bug id
function csv_format_duplicate_id( $p_duplicate_id ) {
return bug_format_id( $p_duplicate_id );
}
?>
62 changes: 34 additions & 28 deletions csv_export.php
Expand Up @@ -6,15 +6,16 @@
# See the README and LICENSE files for details

# --------------------------------------------------------
# $Id: csv_export.php,v 1.16 2004-01-11 07:16:06 vboctor Exp $
# $Id: csv_export.php,v 1.17 2004-03-23 14:00:35 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 . 'filter_api.php' );
require_once( $t_core_path . 'csv_api.php' );
?>
<?php auth_ensure_user_authenticated() ?>
<?php
Expand All @@ -23,43 +24,48 @@
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=' . config_get( 'page_title' ) . '.csv' );
header( 'Content-Type: text/plain; name=' . $t_filename );
header( 'Content-Transfer-Encoding: BASE64;' );
header( 'Content-Disposition: attachment; filename=' . config_get( 'page_title' ) . '.csv' );
header( 'Content-Disposition: attachment; filename=' . $t_filename );

$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 );

echo lang_get('email_project') . ',' . config_get('page_title') . "\r\n\r\n";
echo lang_get( 'priority' ) . ',' .
lang_get( 'id' ) . ',' .
lang_get( 'severity' ) . ',' .
lang_get( 'status' ) . ',' .
lang_get( 'version' ) . ',' .
lang_get( 'assigned_to' ) . ',' .
lang_get( 'reporter' ) . ',' .
lang_get( 'updated' ) . ',' .
lang_get( 'summary' ) . "\r\n";
# Get columns to be exported
$t_columns = csv_get_columns();

for ( $i=0 ; $i < sizeof($rows) ; $i++ ) {
extract( $rows[$i], EXTR_PREFIX_ALL, 'v' );
# export the titles
$t_titles = array();
foreach ( $t_columns as $column => $title ) {
$t_titles[] = lang_get( $title );
}
echo implode( $t_sep, $t_titles ) . $t_nl;

$t_last_updated = date( config_get( 'short_date_format' ), $v_last_updated );
$t_priority = get_enum_element( 'priority', $v_priority );
$t_severity = get_enum_element( 'severity', $v_severity );
$t_status = get_enum_element( 'status', $v_status );
$t_hander_name = user_get_name( $v_handler_id );
$t_reporter_name = user_get_name( $v_reporter_id );
$v_summary = string_display_links( $v_summary );
# 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;
}

echo "$t_priority,$v_id,$t_severity,$t_status,$v_version,$t_hander_name,$t_reporter_name,$t_last_updated,\"$v_summary\"\r\n";
}

exit;
$t_function = 'csv_format_' . $key;
$t_values[] = $t_function( $row[ $key ] );
}

?>
echo implode( $t_sep, $t_values ) . $t_nl;
}
?>
5 changes: 5 additions & 0 deletions doc/ChangeLog
Expand Up @@ -3,11 +3,16 @@ Mantis ChangeLog
2004.xx.xx - 0.19.0

* Enh #0000: Generate one email per user. Stage #1 (no send mail optimization).
* Enh #3262: CSV export does not export the category column.
* Enh #3264: CSV export should export the resolution.
* Enh #3287: Projectname on CSV export.
* Enh #3300: Add global defaults for priotity and severity of new bugs.
* Enh #3302: Add global defaults for view state.
* Enh #3346: CSV extract should output more data, e.g., Date Submitted, other data that would allow better analysis of data trends.
* Enh #3620: Redesigned filter interface.
* Enh #3633: Experimental support for MSSQL, PgSQL and other databases using ADODB.
* Enh #3662: Provide more config vars to control viewing/downloading/deleting bug attachments.
* Fix #3259: Saving CSV file of bugs containning double quotes causes invalid csv.
* Fix #3622: Tweak attachment SQL in print bug pages.
* Fix #3629: Duplicate Error ID.
* Fix #3635: status_resolved in email_api should be resolved.
Expand Down

0 comments on commit 92b07e0

Please sign in to comment.