<?php
if ("1" == $_POST['art_take'])
{
	include __DIR__ . "/art_save.php";
}
if ("1" == $_POST['pos_save'])
{
	include __DIR__ . "/pos_save.php";
}
if ("1" == $_POST['art_pos_save'])
{
	include __DIR__ . "/pos_save.php";
	include __DIR__ . "/art_pos_save.php";
}
if ("1" == $_POST['art_pos_change'])
{
	include __DIR__ . "/pos_change.php";
	include __DIR__ . "/art_pos_save.php";
}
if ("1" == $_POST['pos_change'])
{
	include __DIR__ . "/pos_change.php";
}
if ("1" == $_POST['pos_delete'])
{
	include __DIR__ . "/pos_delete.php";
}

if ("settings" == $_POST['action'])
{
	$sql = 'UPDATE ' . PREFIX . '_Angebote SET
		Kontakt_ID	= "' . $_POST['Kontakt_ID'] . '",
		Admin_ID	= "' . $_POST['Admin_ID'] . '",
		KfZ_ID		= "' . $_POST['KfZ_ID'] . '",
		MwSt		= "' . $_POST['MwSt'] . '"
	WHERE
		(Jahr 		= "' . $Jahr . '"
	AND
		ID 			= "' . $ID . '");';
	$stmt = $db->prepare($sql);
	if (!$stmt)
	{
		die ('Datensatz konnte nicht gespeichert werden: ' . $db->error);
	}
	if (!$stmt->execute())
	{
		die ('Datensatz konnte nicht gespeichert werden: ' . $stmt->error);
	}
}

$Max_Pos = 0;

$sql = "SELECT *, DATE_FORMAT(Datum, '%d.%m.%Y') AS Datum FROM " . PREFIX . "_Angebote WHERE (Jahr = \"" . $Jahr . "\" AND ID = \"" . $ID . "\");";
$result = $db->query($sql);
$nt = $result->fetch_assoc();
$sqlp = "SELECT * FROM " . PREFIX . "_Angebot_Pos WHERE (Jahr = \"" . $Jahr . "\" AND Angebot_ID =\"" . $ID . "\") ORDER BY Position ASC;";
$resultp = $db->query($sqlp);

$sqlkn = "SELECT * FROM " . PREFIX . "_Kontakte ORDER BY Nachname ASC, Firma ASC";
$resultkn = $db->query($sqlkn);
$sqlan = "SELECT ID, Vorname, Nachname FROM Admin WHERE Firma_ID = \"" . PREFIX . "\" ORDER BY ID ASC";
$resultan = $db->query($sqlan);

$Text = $nt['Text'];

include __DIR__ . "/settings.php";

include __DIR__ . "/positions.php";
echo "	</table>\n";
echo "	<br />\n";
echo "<h2>Alle Preise verstehen sich zzgl. " . $nt['MwSt'] . "% gesetzlicher MwSt.</h2>\n";
echo "</fieldset>\n";

include __DIR__ . "/art_take.php";

include __DIR__ . "/sv_save.php";