public static function createFile($arrays, $filename = 'chat_emails.csv') { $string = ''; $b = 0; foreach ($arrays as $array) { $val_array = array(); $key_array = array(); foreach ($array as $key => $val) { $key_array[] = $key; $val = str_replace('"', '""', $val); $val_array[] = "\"{$val}\""; } if ($b == 0) { $string .= implode(",", $key_array) . "\n"; } $string .= implode(",", $val_array) . "\n"; $b++; } emailExport::downloadFile($string, $filename); }
} // The DB connections data require_once '../class/class.export.php'; // All the tables we need for this plugin $errors = array(); $lstable = DB_PREFIX . 'jrc_sessions'; switch ($page1) { case 'export': $sql = 'SELECT name, email FROM ' . $lstable . ' WHERE email REGEXP "^[A-Z0-9._%-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}$" GROUP BY email ORDER BY id DESC'; $result = $lsdb->query($sql); if ($lsdb->affected_rows > 0) { while ($row = $result->fetch_assoc()) { // collect each record into $_data $lsdata[] = $row; } } emailExport::createFile($lsdata); break; default: $sql = 'SELECT id, name, email FROM ' . $lstable . ' WHERE email REGEXP "^[A-Z0-9._%-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}$" GROUP BY email ORDER BY id DESC'; $result = $lsdb->query($sql); if ($lsdb->affected_rows > 0) { while ($row = $result->fetch_assoc()) { // collect each record into $_data $lsdata[] = $row; } } $CEMAILS_ALL = $lsdata; // Call the template $template = 'emails.php'; }