diff --git a/core/csv_api.php b/core/csv_api.php new file mode 100644 index 0000000000..73620b4e84 --- /dev/null +++ b/core/csv_api.php @@ -0,0 +1,215 @@ +.csv, otherwise default to + # .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 ); + } +?> \ No newline at end of file diff --git a/csv_export.php b/csv_export.php index 31c1dafcf5..96d238265b 100644 --- a/csv_export.php +++ b/csv_export.php @@ -6,7 +6,7 @@ # 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 $ # -------------------------------------------------------- ?> $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; + } +?> \ No newline at end of file diff --git a/doc/ChangeLog b/doc/ChangeLog index fe2592d897..310aeae875 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -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.