<?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 ' . $table . ' SET
		Kontakt_ID	= "' . $_POST['Kontakt_ID'] . '",
		Admin_ID	= "' . $_POST['Admin_ID'] . '"
		KfZ_ID		= "' . $_POST['KfZ_ID'] . '",
	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 " . $table . " WHERE (Jahr = \"" . $Jahr . "\" AND ID = \"" . $ID . "\");";
$result = $db->query($sql);
$nt = $result->fetch_assoc();
$sqlp = "SELECT * FROM " . PREFIX . "_liefer_Pos WHERE (Jahr = \"" . $Jahr . "\" AND liefer_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 "</fieldset>\n";

include __DIR__ . "/art_take.php";

include __DIR__ . "/sv_save.php";