File: /home/httpd/html/baretube.com/admin/export_paysites.php
<?php
require "db.php";
if ($_POST['paysitesData'] && $_POST['delimiter'] && $_POST['export_format']) {
$_POST = mysql_real_escape_array($_POST);
if ($_POST['export_format'] === 'csv') {
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=paysites_export-'.date('Y-m-d-H-i-s').'.csv');
$output = fopen('php://output', 'w');
$csv_values = explode(',', implode(',', $_POST['paysitesData']));
$csv_columns = array();
foreach ($csv_values as $value) {
$csv_columns[] = $value;
$mysql_fields .= $value . ', ';
}
$mysql_fields = substr($mysql_fields, 0, -2);
fputcsv($output, array_map('strtoupper', $csv_columns), $_POST['delimiter']);
$rows = dbQuery("SELECT * FROM paysites",false);
foreach($rows as $row) {
$csv_fields = array();
$link = generateUrl('paysite', $row['name'], $row['record_num']);
$row['url'] = $link;
foreach ($csv_columns as $value) {
$csv_fields[] = $row[$value];
}
fputcsv($output, $csv_fields, $_POST['delimiter']);
}
fclose($output);
exit();
}
}
?>
<? require "header.php"; ?>
<div class="content-page">
<div class="header-area">
<div class="breadcrumbs">
<a href="index.php">Admin Home</a>
<span><a href="export_paysites.php">Export Paysites</a></span>
</div>
</div>
<div class="content-outer">
<h2>Export<strong>Paysites</strong></h2>
<div class="content-inner">
<form action="" method="POST" enctype="multipart/form-data" class="form" novalidate autocomplete="off">
<table class="pagetable">
<thead>
<tr>
<th colspan="2">Export Criteria</th>
</tr>
</thead>
<tr>
<td>Paysites Data</td>
<td>
<?
$paysitesData = array('name', 'description', 'user', 'ad0', 'ad1', 'ad2', 'ad3', 'ad4', 'ad5', 'ad6', 'ad7', 'ad8', 'ad9', 'inline_xml_url', 'pre_xml_url', 'pause_xml_url', 'post_xml_url', 'postroll', 'enabled', 'belowplayertext', 'record_num', 'url');
?>
<select name="paysitesData[]" multiple="multiple">
<? foreach ($paysitesData as $prow) { ?>
<option value="<? echo $prow; ?>" selected="selected"><? echo $prow; ?></option>
<? } ?>
</select>
<p class="hint">(Hold CTRL to make multiple selections)</p>
</td>
</tr>
<tr>
<td>Field Delimiter</td>
<td>
<select name="delimiter">
<option value="|">|</option>
</select>
</td>
</tr>
<tr>
<td>Export format</td>
<td>
<select name="export_format">
<option value="csv">CSV</option>
</select>
</td>
</tr>
<tr class="item submit">
<td colspan="2">
<button type="submit" class="btn action-save no-process">Export</button>
</td>
</tr>
</table>
</form>
</div>
</div>
</div>
<?php require "footer.php"; ?>