Hi, good news.
I manage to solve the CSV file by editing some lines at csv_export.php and columns_api
I want to add few field at csv report so i add the columns at columns_api, such that:
- Code: Select all
function column_get_title( $p_column ) {
/*.... some codes..... Just leave the original codes there, no need to change anything*/
/*Edit at this part*/
switch( $p_column ) {
/*...Leave the original case options...*/
case 'view_state':
return lang_get( 'view_status' );
#Added By Mimie
case 'add_column1':
return 'My column 1';
case 'add_column2':
return 'My column 2';
default:
return lang_get_defaulted( $p_column );
}
}
And at csv_report.php, add the sql queries to call the row by the column value such that:
- Code: Select all
auth_ensure_user_authenticated();
#Added By Mimie
#Copied from csv_api - function csv_escape_string( $p_str )
#This is to make sure the arrangement of chars/long text is wrap in one field and not messed up to other column
function fix_csv ($p_string){
$p_str = '"' . str_replace( '"', '""', $p_string ) . '"';
$p_string = str_replace(",",".",$p_string);
$p_string = str_replace("<br />"," ",$p_string);
$p_string = str_replace(""","\"",$p_string);
$p_string = str_replace("\r\n"," ",$p_string);
$p_string = str_replace("'"," ",$p_string);
return $p_string;
}
helper_begin_long_process();
Then, at csv export also i called the columns, which i added at columns_api, by:
- Code: Select all
# Added Quotes (") around file name.
header( 'Content-Disposition: attachment; filename="' . urlencode( file_clean_name( $t_filename ) ) . '"' );
# Get columns to be exported
#Added By Mimie
$t_my_column_one = column_get_title('add_column1');
$t_my column_two = column_get_title('add_column2');
#This is the array contains value of column details for csv
$t_columns = csv_get_columns();
#Added By Mimie
#I use array_splice function to put my column at specific position in the array.
#Can also use array_push function to simply put the value to the array
#Can refer php tutorial/forum
array_splice($t_columns, -1, 0,array( $t_my_column_one,$t_my_column_two));
array_splice($t_columns, 10, 0, $t_my_column_one);
# export the titles
$t_first_column = true;
Then, i want to put my rows value that belong to the column, such that:
- Code: Select all
# export the rows
foreach ( $t_rows as $t_row ) {
$t_first_column = true;
foreach ( $t_columns as $t_column ) {
if ( !$t_first_column ) {
echo $t_sep;
} else
$t_first_column = false;
$t_custom_field = column_get_custom_field_name( $t_column );
if ( $t_custom_field !== null ) {
ob_start();
$t_column_value_function = 'print_column_value';
helper_call_custom_function( $t_column_value_function, array( $t_column, $t_row, COLUMNS_TARGET_CSV_PAGE ) );
$t_value = ob_get_clean();
echo csv_escape_string($t_value);
} else if ($t_column == 'My column 1'){
$the_bug = $t_row->id;
$query = "select column_one from mantis_project_table
where id = '$the_bug'";
$result = db_query($query);
$row = db_result($result);
echo fix_csv($row);
}else if ($t_column == 'My column 2'){
$the_bug = $t_row->id;
$query = "select column_two from mantis_project_table
where id = '$the_bug'";
$result = db_query($query);
$row = db_result($result);
echo fix_csv($row);
}
else
{
$t_function = 'csv_format_' . $t_column;
echo $t_function( $t_row->$t_column );
}
}echo $t_nl;
}
So there you go, I've successfully added new row to my CSV file.
Thanks alot for jkordani help. His method has given me to this idea.
