function mailing_list_export in Mailing List 6
Same name and namespace in other branches
- 7 mailing_list.admin.inc \mailing_list_export()
Menu callback; exports a mailing list directly to the user as a CSV file.
1 string reference to 'mailing_list_export'
- mailing_list_menu in ./
mailing_list.module - Implementation of hook_menu().
File
- ./
mailing_list.admin.inc, line 385 - Mailing list admin UI.
Code
function mailing_list_export($list) {
$path = file_directory_path();
// create file to hold email list
$filename = drupal_strtolower(str_replace(' ', '_', $list->name)) . '.csv';
$full_path = $path . '/' . $filename;
$query = "SELECT * FROM {mailing_list_emails} WHERE mlid = '%d'";
$result = db_query($query, $list->mlid);
// create string with all the emails
$emails = array();
while ($row = db_fetch_object($result)) {
$emails[] = '"' . trim($row->mail) . '","' . trim($row->name) . '"';
}
$emails = implode("\n", $emails) . "\n";
// write resultant string to file
file_save_data($emails, $full_path, FILE_EXISTS_REPLACE);
// set headers for file transfer
$headers = array(
'Content-Type: application/octet-stream',
'Content-Disposition: attachment; filename="' . basename($full_path) . '";',
'Content-Length: ' . sprintf('%u', filesize($full_path)),
);
file_transfer($full_path, $headers);
}