codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
<?php include('../functions.php');?> <?php include('../login/auth.php');?> <?php /********************************/ $table = 'subscribers'; // table to export $userID = get_app_info('main_userID'); $campaign_id = isset($_GET['c']) ? mysqli_real_escape_string($mysqli, $_GET['c']) : ''; $link_id = isset($_GET['l']) ? mysqli_real_escape_string($mysqli, $_GET['l']) : ''; $action = isset($_GET['a']) ? $_GET['a'] : ''; $additional_query = ''; /********************************/ if($action == 'userclicks') { //file name $filename = 'clicked.csv'; $additional_query = 'AND unsubscribed = 0 AND bounced = 0 AND complaint = 0'; //get $clicks_join = ''; $clicks_array = array(); $clicks_array_count = array(); $clicks_unique = 0; $q = 'SELECT id, clicks FROM links WHERE campaign_id = '.$campaign_id; $r = mysqli_query($mysqli, $q); if ($r && mysqli_num_rows($r) > 0) { while($row = mysqli_fetch_array($r)) { $id = stripslashes($row['id']); $clicks = stripslashes($row['clicks']); if($clicks!='') $clicks_join .= $clicks.','; } } $clicks_array = explode(',', $clicks_join); $clicks_array_count = array_count_values($clicks_array); $clicks_unique = array_unique($clicks_array); $subscribers = substr(implode(',', $clicks_unique), 0, -1); } //Export $select = 'SELECT id, name, email,0 as clickcount FROM '.$table.' where id IN ('.$subscribers.') '.$additional_query; $export = mysqli_query($mysqli, $select); $fields = mysqli_num_fields ( $export ); $data = '"id","name","email","clickcount"' . "\n"; $currId = 0; while( $row = mysqli_fetch_row( $export ) ) { $line = ''; $i = 1; foreach( $row as $value ) { if ( ( !isset( $value ) ) || ( $value == "" ) ) { if($i<$fields) $value = ","; } else { //set the current User Id to lookup if we are on a new row if ($i==1) {$currId = $value;} if ($i==4) // The clickcount value will be replaced with data from the clicks_array_count { $value = '"'.$clicks_array_count[$currId] . '",'; } else { // this will escape existing quotes before hand $value = str_replace( '"' , '""' , $value ); if($i<$fields) { $value = '"'.$value . '",';} } } $line .= $value.''; $i++; } $data .= trim( $line ) . "\n"; } $data = str_replace( "\r" , "" , $data ); if ( $data == "" ) { $data = "\n(0) Records Found!\n"; } header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=$filename"); header("Pragma: no-cache"); header("Expires: 0"); print "$data"; ?>
Private
[
?
]
Run code
Submit