<?php
if (!isset($_SESSION['ID'])) {
} else {
	echo "<h1>Interessenten</h1>";
	if (in_array("Eigene_Interessenten", $_SESSION['Rechte'])) {
		$in_abfrage = "WHERE TID = \"".$_SESSION['TID']."\" ";
	}
	if ("Suchen..." == $_POST['action']) {
		if ("" == $in_abfrage) {
			if (("" == $_POST['Nachname']) AND ("" == $_POST['Telefon'])) {
			} elseif (("" !== $_POST['Nachname']) AND ("" !== $_POST['Telefon'])) {
				$in_abfrage = "WHERE Nachname = \"".$_POST['Nachname']."\" AND Telefon LIKE \"%".$_POST['Telefon']."%\" ";
			} elseif ("" == $_POST['Nachname']) {
				$in_abfrage = "WHERE Telefon LIKE \"%".$_POST['Telefon']."%\" ";
			} else {
				$in_abfrage = "WHERE Nachname = \"".$_POST['Nachname']."\" ";
			}
		} else {
			if (("" == $_POST['Nachname']) AND ("" == $_POST['Telefon'])) {
			} elseif (("" !== $_POST['Nachname']) AND ("" !== $_POST['Telefon'])) {
				$in_abfrage .= "AND Nachname = \"".$_POST['Nachname']."\" AND Telefon LIKE \"%".$_POST['Telefon']."%\" ";
			} elseif ("" == $_POST['Nachname']) {
				$in_abfrage .= "AND Telefon LIKE \"%".$_POST['Telefon']."%\" ";
			} else {
				$in_abfrage .= "AND Nachname = \"".$_POST['Nachname']."\" ";
			}
		}
	}
	$sql = "SELECT ID, Vorname, Nachname FROM inter ".$in_abfrage." ORDER BY Nachname ASC";
	$result = $db->query($sql);
?>
<!-- Das Formular zur Einschränkung der Suche -->
<form action="index.php?section=Personen&t=in" method="post">
	<fieldset>
		<legend>Ergebnisse einschränken</legend>
		<label>Nachname</label>
		<input type="text" name="Nachname" />
		<img src="../img/help.gif" title="Bitte den Nachnamen exakt angeben" />
		<br />
		<label>Telefon</label>
		<input type="text" name="Telefon" />
		<img src="../img/help.gif" title="Ein Teil der Telefonnummer ist ausreichend" />
		<br />&nbsp;<br />
		<input type="submit" name="action" value="Suchen..." />
	</fieldset>
</form>

<!-- Das Formular für eine neue Person -->
<form action="index.php?section=Personen&t=in" method="post">
	<fieldset>
		<legend>neuen Interessenten anlegen</legend>
		<input type="submit" name="action" value="Anlegen" />
	</fieldset>
</form>

<!-- Das Formular für eine bestehende Person -->
<form action="index.php?section=Personen&t=in" method="post">
	<fieldset>
		<legend>bestehenden Interessenten ...</legend>
		<select name="ID">
<?php
	while ($nt = $result->fetch_assoc()) {
		echo "			<option value=\"".$nt['ID']."\">".$nt['Nachname'].", ".$nt['Vorname']." - ".$nt['ID']."</option>\n";
	}
?>	
		</select>
		<br />&nbsp;<br />
		<input type="submit" name="action" value="Anzeigen" />
		<br />
		<input type="submit" name="action" value="Bearbeiten" />
		<br />
		<input type="submit" name="action" value="Löschen" />
		<br />
	</fieldset>
</form>
<?php
}
?>