<?

session_start();

require 'authenticate.user.php';



require 'configuration.php';

require_once 'includes/common.functions.php';

require_once ('classes/database.php');

require_once ('classes/functions.php');

$sqlObj = new mysqlClass;

$funcObj = new funcClass;



## EXPORT ADDRESS BOOKS

if ($_POST['formtype'] == 'export')

{

	if (count($_POST['chkExport']))

	{

		$expIDs = implode("," ,$_POST['chkExport']);

		

		header("Content-type: application/x-msdownload");

		header("Content-Disposition: attachment; filename=export.csv");

		header("Pragma: no-cache");

		header("Expires: 0");



		 $query = "SELECT * FROM smlr_contacts WHERE ADDR_ID IN ($expIDs) AND IS_DELETED = 0 ORDER BY ADDR_ID, EMAIL";

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

		 echo "EMAIL,FIRSTNAME,LASTNAME,MISC_1,MISC_2,MISC_3\r\n"; //header

		while($row = mysql_fetch_array($result))

		{

			echo "\"$row[EMAIL]\",\"$row[FIRSTNAME]\",\"$row[LASTNAME]\",\"$row[MISC_1]\",\"$row[MISC_2]\",\"$row[MISC_3]\"\r\n"; //data  

		} 		

		//$query = "DELETE FROM ##contacts WHERE ID IN ($delIDs)";

		//$funcObj->CustomDelete($query);	

	}

	else

	{

		header ("location: contacts.php");

	}	

}

?>