/** * Emits the headers and byte order marker. This must be called at the beginning * of scripts that export CSV file before any other content is called. * * @param string $p_filename The csv filename and extension. * @return void */ function csv_start($p_filename) { $t_filename = urlencode(file_clean_name($p_filename)); header('Pragma: public'); header('Content-Encoding: UTF-8'); header('Content-Type: text/csv; name=' . $t_filename . ';charset=UTF-8'); header('Content-Transfer-Encoding: BASE64;'); header('Content-Disposition: attachment; filename="' . $t_filename . '"'); echo UTF8_BOM; }
include dirname(__FILE__) . DIRECTORY_SEPARATOR . 'print_all_bug_options_inc.php'; auth_ensure_user_authenticated(); $f_export = gpc_get_string('export', ''); helper_begin_long_process(); $t_export_title = excel_get_default_filename(); $t_short_date_format = config_get('short_date_format'); # This is where we used to do the entire actual filter ourselves $t_page_number = gpc_get_int('page_number', 1); $t_per_page = 100; $t_result = filter_get_bug_rows($t_page_number, $t_per_page, $t_page_count, $t_bug_count); if ($t_result === false) { print_header_redirect('view_all_set.php?type=0&print=1'); } header('Content-Type: application/vnd.ms-excel; charset=UTF-8'); header('Pragma: public'); header('Content-Disposition: attachment; filename="' . urlencode(file_clean_name($t_export_title)) . '.xml"'); echo excel_get_header($t_export_title); echo excel_get_titles_row(); $f_bug_arr = explode(',', $f_export); $t_columns = excel_get_columns(); do { # pre-cache custom column data columns_plugin_cache_issue_data($t_result); foreach ($t_result as $t_row) { if (is_blank($f_export) || in_array($t_row->id, $f_bug_arr)) { echo excel_get_start_row(); foreach ($t_columns as $t_column) { $t_custom_field = column_get_custom_field_name($t_column); if ($t_custom_field !== null) { echo excel_format_custom_field($t_row->id, $t_row->project_id, $t_custom_field); } else {
helper_begin_long_process(); $t_filename = csv_get_default_filename(); $t_date_format = config_get('normal_date_format'); $f_project_id = gpc_get_int('project_id'); $f_cost = gpc_get_int('cost'); $f_from = gpc_get_string('from'); $f_to = gpc_get_string('to'); $t_separator = ','; billing_ensure_reporting_access($f_project_id); $t_show_cost = ON == config_get('time_tracking_with_billing') && $f_cost != 0; $t_billing_rows = billing_get_for_project($f_project_id, $f_from, $f_to, $f_cost); $t_show_realname = config_get('show_realname') == ON; header('Pragma: public'); header('Content-Type: text/csv; name=' . urlencode(file_clean_name($t_filename))); header('Content-Transfer-Encoding: BASE64;'); header('Content-Disposition: attachment; filename="' . urlencode(file_clean_name($t_filename)) . '"'); echo csv_escape_string(lang_get('issue_id')) . $t_separator; echo csv_escape_string(lang_get('project_name')) . $t_separator; echo csv_escape_string(lang_get('summary')) . $t_separator; if ($t_show_realname) { echo csv_escape_string(lang_get('realname')) . $t_separator; } else { echo csv_escape_string(lang_get('username')) . $t_separator; } echo csv_escape_string(lang_get('timestamp')) . $t_separator; echo csv_escape_string(lang_get('minutes')) . $t_separator; echo csv_escape_string(lang_get('time_tracking_time_spent')) . $t_separator; if ($t_show_cost) { echo csv_escape_string('cost') . $t_separator; } echo csv_escape_string('note');
function upgrade_move_att2disk( $p_source ) { # $p_source is the string "attachment" or "project" if( $p_source == 'attachment' ) { $t_file_table = db_get_table( 'bug_file' ); $t_bug_label = "Bug"; } if( $p_source == 'project' ) { $t_file_table = db_get_table( 'project_file' ); $t_bug_label = "Project"; } # check that the source was valid if( !isset( $t_file_table ) ) { echo 'Failure: Internal Error: File source not set'; return; } # check that the destination is set up properly $t_upload_method = config_get_global( 'file_upload_method' ); if( $t_upload_method <> DISK ) { echo 'Failure: Upload Method is not DISK'; return; } $query = 'SELECT * FROM ' . $t_file_table . ' WHERE content <> \'\''; $result = @db_query_bound( $query ); if( false == $result ) { echo '<p>No attachments need to be moved.</p>'; return; } $count = db_num_rows( $result ); echo '<p>Found ' . $count . ' attachments to be moved.</p>'; $t_failures = 0; if( $count > 0 ) { echo '<table width="80%" bgcolor="#222222" cellpadding="10" cellspacing="1">'; # Headings echo '<tr bgcolor="#ffffff"><th width="10%">' . $t_bug_label . '</th><th width="20%">Attachment</th><th width="70%">Status</th></tr>'; } for( $i = 0;$i < $count;$i++ ) { $t_row = db_fetch_array( $result ); // trace bug id back to project to determine the proper file path if( $p_source == 'attachment' ) { $t_project_id = bug_get_field( $t_row['bug_id'], 'project_id' ); $t_bug_id = $t_row['bug_id']; } else { $t_project_id = (int) $t_row['project_id']; $t_bug_id = $t_project_id; } $t_file_path = project_get_field( $t_project_id, 'file_path' ); $prefix = get_prefix( $t_file_path ); $t_real_file_path = $prefix . $t_file_path; $c_filename = file_clean_name( $t_row['filename'] ); printf( "\n<tr %s><td>%8d</td><td>%s</td><td>", helper_alternate_class(), $t_bug_id, $t_row['filename'] ); if( is_blank( $t_real_file_path ) || !file_exists( $t_real_file_path ) || !is_dir( $t_real_file_path ) || !is_writable( $t_real_file_path ) ) { echo 'Destination ' . $t_real_file_path . ' not writable'; $t_failures++; } else { $t_file_name = $t_real_file_path . $c_filename; // write file to disk store after adjusting the path if( file_put_contents( $t_file_name, $t_row['content'] ) ) { // successful, update database /** @todo do we want to check the size of data transfer matches here? */ $c_new_file_name = $t_file_path . $c_filename; $query2 = "UPDATE $t_file_table SET diskfile = " . db_param() . ", folder = " . db_param() . ", content = '' WHERE id = " . db_param(); $update = @db_query_bound( $query2, Array( $c_new_file_name, $t_file_path, $t_row['id'] ) ); if( !$update ) { echo 'database update failed'; $t_failures++; } else { echo 'moved to ' . $t_file_name; } } else { echo 'copy to ' . $t_file_name . ' failed'; $t_failures++; } } echo '</td></tr>'; } echo '</table><br />' . $count . ' attachments processed, ' . $t_failures . ' failures'; }