<?php
include("../include/session.php");
if(!$session->logged_in) {
	header("Location: ../main.php");
}
else {
	 
	include("db.php");

	function cleanData(&$str) {
		$str = preg_replace("/\t/", "\\t", $str);
		$str = preg_replace("/\n/", "\\n", $str);
	}
	# file name for download
	$filename = "website_data_" . date('Ymd') . ".xls";
//	header("Content-Disposition: attachment; filename=\"$filename\"");
//	header("Content-Type: application/vnd.ms-excel");
 header("Content-Type: text/plain"); 
	$flag = false;
	$result = execsql("SELECT * FROM products WHERE category ='Tiles and Accessories' ORDER BY productName ASC");
	while(false !== ($row = pg_fetch_assoc($result))) {
		if(!$flag) {
			# display field/column names as first row
			echo implode("\t", array_keys($row)) . "\n"; $flag = true; }
			array_walk($row, 'cleanData');
			echo implode("\t", array_values($row)) . "\n";
	}
}