12005 Hwy 64
Eads, TN 38028 USA

Sponsors Report Handler

[insert_php] $authUser = FALSE;

$yourId = wp_get_current_user()->user_login;
$allowed_users = array( “[email protected]”, “[email protected]”, “[email protected]”, “balajivalmiki”, “nkoka”, “[email protected]”);

if ( (is_user_logged_in() && current_user_can(‘administrator’) ) ||
(is_user_logged_in() && in_array($yourId, $allowed_users) )
)
$authUser = TRUE;

if($authUser == FALSE)
{
wp_redirect( site_url() ); exit;
}
[/insert_php] [insert_php]

$fileName = ‘sponsors_report.csv’;
$query = “”;

header(“Content-type: application/vnd.ms-excel”);
header(“Content-Disposition: attachment; filename=”.$fileName);
header(“Pragma: no-cache”);
header(“Expires: 0”);

$fh = @fopen( ‘php://output’, ‘w’ );

global $wpdb;

if (isset($_SESSION[‘sponsors_query’]) && !empty($_SESSION[‘sponsors_query’])) {

if (isset($_POST[‘familDetails’]))
$query = $_SESSION[‘sponsors_query_family’];
else
$query = $_SESSION[‘sponsors_query’];

}

$results = $wpdb->get_results( $query, ARRAY_A );

$headerDisplayed = false;
while(ob_get_level() > 0){
ob_end_clean();
}

foreach ( $results as $data ) {
// Add a header row if it hasn’t been added yet
if ( !$headerDisplayed ) {
// Use the keys from $data as the titles
fputcsv($fh, array_keys($data));
$headerDisplayed = true;
}

// Put the data into the stream
fputcsv($fh, $data);
}
// Close the file
fclose($fh);
// Make sure nothing else is sent, our file is done
exit(0);

[/insert_php]
Facebook4k
YouTube2k
YouTube
WhatsApp