<?php
include "../includes/config.php";
include "../includes/session.php";
include "../includes/functions.php";
include "../classes/php-export-data.class.php";
$ipaddress  = $_REQUEST['ip_address'];
$qryopt = "";
if($ipaddress!='')
    {
            $qryopt     =   "WHERE ip_address='".$ipaddress."' ";
      
    }

 $sql = " SELECT u.*
		FROM " . $tableprefix . "users u " . $qryopt . "  order by user_id DESC  ";


 $result = mysql_query($sql) or die(mysql_error());

 $totalRows     =    mysql_num_rows($result);

 $csvName       =   "user_ip_info_".time().".csv";
 
$exporter = new ExportDataCSV('browser', $csvName);

$exporter->initialize(); // starts streaming data to web browser

// pass addRow() an array and it converts it to Excel XML format and sends
// it to the browser
$exporter->addRow(array(NAME, EMAIL, REG_DATE, USER_IP_ADDRESS,USER_IP_LOCATION));

if($totalRows>0){

     while ($row = mysql_fetch_array($result)) {

         $userName          =    generalMethods::html_entity($row["first_name"]) . " " . generalMethods::html_entity($row["last_name"]) . "  "."(".generalMethods::html_entity($row["user_name"]) . ")";
         $email             =   $row["email"];
         $dateRegister      =   dateFormat($row["date_registered"], "Y-m-d", "m/d/Y");
         $ipaddress         =   generalMethods::html_entity($row["ip_address"]);
         $iplocation         =  generalMethods::html_entity($row["ip_location"]);

         $exporter->addRow(array($userName, $email, $dateRegister, $ipaddress,$iplocation));
     }
}
// doesn't care how many columns you give it
//$exporter->addRow(array("foo"));
$exporter->finalize(); // writes the footer, flushes remaining data to browser.

exit(); // all done
