<?php
if (!isset($_POST['step']))
{
	$sql = "SELECT ID, Firma, Nachname, Vorname, DSchutz FROM " . PREFIX . "_Kontakte ORDER BY Nachname ASC, Vorname ASC;";
	$result = $db->query($sql);
	echo "<fieldset>\n";
	echo "	<legend>Kunde wählen</legend>\n";
	echo "	<form action=\"index.php?" . $_SERVER['QUERY_STRING'] . "\" method=\"post\">\n";
	echo "		<input type=\"hidden\" name=\"step\" value=\"0\" />\n";
	echo "		<input type=\"hidden\" name=\"formaction\" value=\"add\" />\n";
	echo "		<br />\n";
	echo "		<select name=\"Kontakt_ID\">\n";
	while ($nt = $result->fetch_assoc())
	{
		echo "			<option value=\"" . $nt['ID'] . "\">" . $nt['Nachname'] . ", " . $nt['Vorname'] . " - " . $nt['Firma'] . "</option>\n";
	}
	echo "		</select>\n";
	echo "		<br />\n";
	echo "		<input type=\"submit\" class=\"button_ok\" name=\"formaction\" value=\"add\" title=\"Übernehmen\" />\n";
	echo "		<a href=\"index.php?section=" . $_GET['section'] . "\"><img src=\"img/stop.png\" alt=\"Abbrechen\" title=\"Abbrechen\" /></a>\n";
	echo "		<br />\n";
	echo "</fieldset>\n";
}
else
{
	if ("0" == $_POST['step'])
	{
		$sql = "SELECT ID, Vorname, Nachname FROM Admin WHERE Firma_ID = \"" . PREFIX . "\" ORDER BY Nachname ASC;";
		$result = $db->query($sql);
		echo "<fieldset>\n";
		echo "	<legend>Ansprechpartner wählen</legend>\n";
		echo "	<form action=\"index.php?" . $_SERVER['QUERY_STRING'] . "\" method=\"post\">\n";
		echo "		<input type=\"hidden\" name=\"Kontakt_ID\" value=\"" . $_POST['Kontakt_ID'] . "\" />\n";
		if (("schrift" == $_GET['section']) OR ("lv" == $_GET['section']) OR ("liefer" == $_GET['section']))
		{
			echo "		<input type=\"hidden\" name=\"step\" value=\"2\" />\n";
		}
		else
		{
			echo "		<input type=\"hidden\" name=\"step\" value=\"1\" />\n";
		}
		echo "		<input type=\"hidden\" name=\"formaction\" value=\"add\" />\n";
		echo "		<br />\n";
		echo "		<select name=\"Admin_ID\">\n";
		while ($nt = $result->fetch_assoc())
		{
			echo "			<option";
			if ($nt['ID'] == $_SESSION['TID'])
			{
				echo " selected=\"selected\"";
			}
			echo " value=\"" . $nt['ID'] . "\">" . $nt['Vorname'] . " " . $nt['Nachname'] . "</option>\n";
		}
		echo "		</select>\n";
		echo "		<br />\n";
		echo "		<input type=\"submit\" class=\"button_ok\" name=\"formaction\" value=\"add\" title=\"Übernehmen\" />\n";
		echo "		<a href=\"index.php?section=" . $_GET['section'] . "\"><img src=\"img/stop.png\" alt=\"Abbrechen\" title=\"Abbrechen\" /></a>\n";
		echo "		<br />\n";
		echo "</fieldset>\n";
	}
	elseif ("1" == $_POST['step'])
	{
		echo "<fieldset>\n";
		echo "	<legend>MwSt-Satz in % festlegen</legend>\n";
		echo "	<form action=\"index.php?" . $_SERVER['QUERY_STRING'] . "\" method=\"post\">\n";
		echo "		<input type=\"hidden\" name=\"Kontakt_ID\" value=\"" . $_POST['Kontakt_ID'] . "\" />\n";
		echo "		<input type=\"hidden\" name=\"Admin_ID\" value=\"" . $_POST['Admin_ID'] . "\" />\n";
		echo "		<input type=\"hidden\" name=\"step\" value=\"2\" />\n";
		echo "		<input type=\"hidden\" name=\"formaction\" value=\"add\" />\n";
		echo "		<br />\n";
		echo "		<input type=\"text\" name=\"MwSt\" value=\"" . $_SESSION['Firma']['MwSt'] . "\" />\n";
		echo "		<br />\n";
		echo "		<input type=\"submit\" class=\"button_ok\" name=\"formaction\" value=\"add\" title=\"Übernehmen\" />\n";
		echo "		<a href=\"index.php?section=" . $_GET['section'] . "\"><img src=\"img/stop.png\" alt=\"Abbrechen\" title=\"Abbrechen\" /></a>\n";
		echo "		<br />\n";
		echo "</fieldset>\n";
	}
}