function track_da_files_export_csv in Track da files 7
General csv export function.
2 calls to track_da_files_export_csv()
- track_da_files_table_export in includes/
track_da_files.admin.inc - Exports the report table in csv.
- track_da_files_table_export_file_report in includes/
track_da_files.admin.inc - Exports the track da files table in csv for a specific file.
File
- includes/
track_da_files.admin.inc, line 985 - Administrative page callbacks for Track da files module.
Code
function track_da_files_export_csv($variables, $fid = NULL, $pid = NULL) {
$track_da_files_user_report_enabled = variable_get('track_da_files_user_report_enabled', 1);
// Remove file datas links and strip HTML.
if (isset($variables['rows'])) {
foreach ($variables['rows'] as $key => $record) {
foreach ($record as $key2 => $row) {
$rows[$key][$key2] = strip_tags($row);
if ($key2 == 'fid' && !$fid || $key2 == 'view_more') {
unset($rows[$key][$key2]);
}
}
}
$variables['rows'] = $rows;
}
// Remove last column in main report and file report.
array_pop($variables['header']);
$site_name = variable_get('site_name');
$site_name = preg_replace("/[^a-zA-Z0-9\\.\\-_]/", "", $site_name);
drupal_add_http_header('Content-Type', 'text/csv; utf-8');
if ($fid) {
$file = file_load($fid);
$filename = $file->filename;
$path_parts = pathinfo($filename);
$file_export_name = $path_parts['filename'] . '_' . $path_parts['extension'];
drupal_add_http_header('Content-Disposition', 'attachment; filename=' . $file_export_name . '-' . date('Ymd-his') . '-fid' . $fid . 'pid' . $pid . '.csv');
}
else {
drupal_add_http_header('Content-Disposition', 'attachment; filename=' . $site_name . '-tdf-' . date('Ymd-his') . '.csv');
}
$output = '';
$keys = array();
foreach ($variables['header'] as $key => $value) {
$keys[] = $value['data'];
}
if ($keys) {
$output .= implode("\t", $keys) . "\n";
}
foreach ($variables['rows'] as $value) {
$output .= implode("\t", $value) . "\n";
}
print $output;
exit;
}