<?php
echo "<h1>Artikelexport</h1>\n";
$sql = "SELECT * FROM " . PREFIX . "_Artikel ORDER BY ID ASC;";
$result = $db->query($sql);
chdir('tmp');
unlink($_SESSION['TID'] . "_" . PREFIX . "_art.*");
$datei = fopen($_SESSION['TID'] . "_" . PREFIX . "_art.csv", 'w');
fwrite($datei, "\"Artikelnummer\";\"Bezeichnung\";\"" . $_SESSION['Firma']['Feld1_Name'] . "\";\"" . $_SESSION['Firma']['Feld2_Name'] . "\";\"" . $_SESSION['Firma']['Feld3_Name'] . "\";\"" . $_SESSION['Firma']['Feld4_Name'] . "\";\"" . $_SESSION['Firma']['Feld5_Name'] . "\";\"Preis\";\"Datum\"");
while ($nt = $result->fetch_assoc())
{
	fwrite($datei, "\n\"" . $nt['ID'] . "\";\"" . $nt['Bezeichnung'] . "\";\"" . $nt['Feld1'] . "\";\"" . $nt['Feld2'] . "\";\"" . $nt['Feld3'] . "\";\"" . $nt['Feld4'] . "\";\"" . $nt['Feld5'] . "\";\"" . $nt['Preis'] . "\";\"" . $nt['Datum'] . "\"");
}
fclose($datei);
echo "<p>Die Artikel wurden exportiert</p>\n";

$zip = new ZipArchive();
$A_name = $_SESSION['TID'] . "_" . PREFIX . "_art.zip";
if ($zip->open($A_name, ZipArchive::CREATE) !== true)
{
	exit("cannot open <$zipname>\n");
}
$zip->addFile($_SESSION['TID'] . "_" . PREFIX . "_art.csv");
$zip->close();
echo "<p>Das Zip-Archiv wurde erstellt</p>\n";
echo "<a href=\"tmp/" . $_SESSION['TID'] . "_" . PREFIX . "_art.zip\" type=\"application/zip\">Download</a>\n";