<?php
if ("1" == $_POST['search'])
{
	if (("" == $_POST['name']) AND ("" == $_POST['Nr']) AND ("" == $_POST['year']) AND ("" == $_POST['month']))
	{
		$Abfrage = "";
	}
	else
	{
		$Abfrage = " WHERE (";
		$i = 0;
		if ("" != $_POST['name'])
		{
			if ("artikel" == $_GET['section'])
			{
				$Abfrage .= " (" . $table . ".Bezeichnung LIKE \"%" . $_POST['name'] . "%\")";
			}
			elseif ("kfz" == $_GET['section'])
			{
				$Abfrage .= " (" . $table . ".Marke LIKE \"%" . $_POST['name'] . "%\" OR " . $table . ".Modell LIKE \"%" . $_POST['name'] . "%\" OR " . $table . ".Modellvariante LIKE \"%" . $_POST['name'] . "%\")";
			}
			else
			{
				$Abfrage .= " (" . PREFIX . "_Kontakte.Firma LIKE \"%" . $_POST['name'] . "%\" OR " . PREFIX . "_Kontakte.Nachname LIKE \"%" . $_POST['name'] . "%\")";
			}
			$i = 1;
		}
		if ("" != $_POST['Nr'])
		{
			if (1 == $i)
			{
				$Abfrage .= " AND";
			}
			if ("kfz" == $_GET['section'])
			{
				$Abfrage .= " " . $table . ".Kennzeichen LIKE \"%" . $_POST['Nr'] . "%\"";
			}
			else
			{
				$Abfrage .= " " . $table . ".ID = \"" . $_POST['Nr'] . "\"";
			}
			$i = 1;
		}
		if ("" != $_POST['year'])
		{
			if (1 == $i)
			{
				$Abfrage .= " AND";
			}
			if (("kontakt" == $_GET['section']) OR ("artikel" == $_GET['section']))
			{
				$Abfrage .= " YEAR(" . $table . ".Datum) = \"" . $_POST['year'] . "\"";
			}
			elseif ("kfz" == $_GET['section'])
			{
				$Abfrage .= " YEAR(" . $table . ".Erstzulassung) = \"" . $_POST['year'] . "\"";
			}
			else
			{
				$Abfrage .= " " . $table . ".Jahr = \"" . $_POST['year'] . "\"";
			}
			$i = 1;
		}
		if ("" != $_POST['month'])
		{
			if (1 == $i)
			{
				$Abfrage .= " AND";
			}
			$Abfrage .= " MONTH(" . $table . ".Datum) = \"" . $_POST['month'] . "\"";
			$i = 1;
		}
		$Abfrage .= ")";
	}
}

echo "<div class=\"search_right\">\n";
echo "	<fieldset>\n";
echo "		<legend>Hinweis!</legend>\n";
echo "		<p>Das Suchergebnis finden Sie in der unten stehenden Auswahlbox.</p>\n";
echo "		<p>Falls Ihre Suche kein Ergebnis liefert, bleibt die Auswahlbox leer!</p>\n";
echo "	</fieldset>\n";
echo "</div>\n";
echo "<fieldset>\n";
echo "	<legend>Suche " . $Typ . "</legend>\n";
echo "	<form action=\"index.php?" . $_SERVER['QUERY_STRING'] . "\" method=\"post\">\n";
if ("artikel" == $_GET['section'])
{
	echo "		<label>Artikelbezeichnung</label>\n";
	echo "		<input type=\"text\" name=\"name\" />\n";
	echo "		<br style=\"clear: left;\" />\n";
}
elseif ("kfz" == $_GET['section'])
{
	echo "		<label>Fahrzeugbezeichnung</label>\n";
	echo "		<input type=\"text\" name=\"name\" />\n";
	echo "		<br style=\"clear: left;\" />\n";
}
else
{
	echo "		<label>Firma oder Nachname</label>\n";
	echo "		<input type=\"text\" name=\"name\" />\n";
	echo "		<br />\n";
}
if ("kfz" == $_GET['section'])
{
	echo "		<label>Kennzeichen</label>\n";
	echo "		<input type=\"text\" name=\"Nr\" />\n";
	echo "		<br style=\"clear: left;\" />\n";
}
else
{
	echo "		<label>" . $Typ . " - Nr.</label>\n";
	echo "		<input type=\"text\" name=\"Nr\" />\n";
	echo "		<br />\n";
}
echo "		<span class=\"right\">\n";
echo "			<input type=\"submit\" name=\"search\" value=\"1\" title=\"Suchen\" class=\"button_search\" />\n";
echo "		</span>\n";
echo "		<h2>" . $Text . "</h2>\n";
echo "		<label>Jahr</label>\n";
echo "		<input type=\"text\" name=\"year\" />\n";
echo "		<br />\n";
echo "		<label>Monat</label>\n";
echo "		<input type=\"text\" name=\"month\" />\n";
echo "		<img src=\"img/small_info.png\" title=\"Monatszahl verwenden, z.B. Oktober = 10\" alt=\"Monatszahl verwenden, z.B. Oktober = 10\" />\n";
echo "		<br />&nbsp;<br />\n";
echo "	</form>\n";
echo "</fieldset>\n";