<?php require_once('../../../../wp-config.php'); require_once('../opt.php'); require_once('../includes/dwpc_start.php'); require_once('../includes/opt_apptop.php'); $export_key = opt_settings('lead_export_key'); if(!array_key_exists('key',$_GET) && $export_key != $_GET['$key']){ echo 'Permission Denied'; } header('Content-type: text/csv'); header('Content-disposition: attachment;filename=OptinLinks_Leads_'.$_GET['date'].'.csv'); $campaign_sql = '1=1'; $link_sql = '1=1'; $date_range_sql = '1=1'; if(array_key_exists('date_since_last',$_REQUEST)){ $last_export = opt_settings('last_export'); if($last_export != ''){ $date_range_sql = "time_created > '".$last_export."'"; } }else{ $date_range_sql = opt_calculate_date_range('time_created',true); } opt_settings('last_export',current_time('mysql')); if(!array_key_exists('export_all',$_REQUEST)){ $campaigns = array(); $links = array(); foreach($_REQUEST as $key=>$value){ if(strpos($key,'export_camp_') !== false && is_numeric($value)){ $campaigns[] = $value; }else if(strpos($key,'export_link_') !== false && is_numeric($value)){ $links[] = $value; } } if(!empty($campaigns)){ $campaign_sql = ''; $i=0; $count = count($campaigns); foreach($campaigns as $camp){ $campaign_sql .= 'campaign_id='.$camp; $i++; if($i<$count){ $campaign_sql .= ' OR '; } } } if(!empty($links)){ $link_sql = ''; $i=0; $count = count($links); foreach($links as $lin){ $link_sql .= 'opt_optin_link_id='.$lin; $i++; if($i<$count){ $link_sql .= ' OR '; } } } } $sql = 'SELECT email_text_id,name FROM '.OPT_DB_PREFIX.'opt_leads WHERE '.$campaign_sql.' AND '.$link_sql.' AND '.$date_range_sql; $leads = $wpdb->get_results($sql,ARRAY_A); foreach($leads as $val){ echo $val['email_text_id'].','.$val['name'].PHP_EOL; } ?>