<?php
/*header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="newsletter-subscribers.csv"');*/
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");;
header("Content-Disposition: attachment;filename=member_report.xls ");
header("Content-Transfer-Encoding: binary ");
$keys = $wpdb->get_results("select distinct name from " . $wpdb->prefix . "newsletter_profiles order by name");
?>
<style type="text/css">
.border1
{
border-left:#000000 solid 1px;
border-top:#000000 solid 1px;
border-bottom:#000000 solid 1px;
}
.border2
{
border-left:#000000 solid 1px;
border-bottom:#000000 solid 1px;
}
.border3
{
border-left:#000000 solid 1px;
border-bottom:#000000 solid 1px;
border-right:#000000 solid 1px;
}
.border4
{
border:#000000 solid 1px;
}
</style>
<table width="500" cellpadding="0" cellspacing="0">
<tr>
<th colspan="2"> </th>
</tr>
<tr>
<th colspan="2">Newsletter Subscribers Report</th>
</tr>
<tr>
<th width="200">Email</th>
<th width="200">Name</th>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<?php
$page = 0;
while (true) {
$query = "select * from " . $wpdb->prefix . "newsletter";
if (!empty($_POST['options']['list'])) {
$query .= " where list_" . $_POST['options']['list'] . "=1";
}
$recipients = $wpdb->get_results($query . " order by email limit " . $page * 500 . ",500");
for ($i = 0; $i < count($recipients); $i++) {
echo '<tr><td align="left">' . $recipients[$i]->email . '</td> <td align="left">' . newsletter_sanitize_csv($recipients[$i]->name).'</td>';
echo "</tr>";
flush();
}
if (count($recipients) < 500) break;
$page++;
}
die();
function newsletter_sanitize_csv($text) {
$text = str_replace('"', "'", $text);
$text = str_replace("\n", ' ', $text);
$text = str_replace("\r", ' ', $text);
$text = str_replace(";", ' ', $text);
return $text;
}
?>
<tr>
<th colspan="2"> </th>
</tr>
</table>