<?php
if (!in_array("Rechte", $_SESSION['Rechte'])) {
	exit(ZUGRIFF_ERROR);
}
if (!isset($_SESSION['ID'])) {
} else {
	echo "<h2>Wohnimmobilien</h2>\n";
	echo "<form action=\"index.php?".$_SERVER['QUERY_STRING']."\" method=\"post\" />\n";
	echo "	<label>Sortierung nach</label>\n";
	echo "	<select name=\"Sortierung\">\n";
	echo "		<option value=\"ID ASC\">Objekt-ID aufsteigend</option>\n";
	echo "		<option value=\"ID DESC\">Objekt-ID absteigend</option>\n";
	echo "		<option value=\"TID ASC\">Mitarbeiter aufsteigend</option>\n";
	echo "		<option value=\"TID DESC\">Mitarbeiter absteigend</option>\n";
	echo "		<option value=\"WohnF ASC\">Wohnfläche aufsteigend</option>\n";
	echo "		<option value=\"WohnF DESC\">Wohnfläche absteigend</option>\n";
	echo "		<option value=\"Mkalt ASC\">Kaltmiete / Kaufpreis aufsteigend</option>\n";
	echo "		<option value=\"Mkalt DESC\">Kaltmiete / Kaufpreis absteigend</option>\n";
	echo "		<option value=\"Datum ASC\">Erstelldatum aufsteigend</option>\n";
	echo "		<option value=\"Datum DESC\">Erstelldatum absteigend</option>\n";
	echo "		<option value=\"Akt_Datum ASC\">Änderungsdatum aufsteigend</option>\n";
	echo "		<option value=\"Akt_Datum DESC\">Änderungsdatum absteigend</option>\n";
	echo "		<option value=\"Count ASC\">Homepage-Zugriffe aufsteigend</option>\n";
	echo "		<option value=\"Count DESC\">Homepage-Zugriffe absteigend</option>\n";
	echo "	</select>\n";
	echo "	<br />\n";
	echo "	<label>&nbsp;</label>\n";
	echo "	<input type=\"submit\" name=\"action\" value=\"Sortieren\" />\n";
	echo "</form>\n";
	if (isset($_POST['action'])) {
		$order = "ORDER BY ".$_POST['Sortierung'];
	}

// Wohnimmobilien - Abfrage
	$sql1 =		"SELECT ID, TID, Kurz, Art, WohnF, Mkalt, Count, DATE_FORMAT(Datum, \"%d.%m.%Y\") AS Datum, DATE_FORMAT(Akt_Datum, \"%d.%m.%Y\") AS Akt_Datum FROM objekte WHERE O_TYP = \"Wohnung\" AND V_TYP = \"Miete\" AND Aktiv = \"1\" ".$order.";";
	$result1 =	$db->query($sql1);
	$sql2 =		"SELECT ID, TID, Kurz, Art, WohnF, Mkalt, Count, DATE_FORMAT(Datum, \"%d.%m.%Y\") AS Datum, DATE_FORMAT(Akt_Datum, \"%d.%m.%Y\") AS Akt_Datum FROM objekte WHERE O_TYP = \"Wohnung\" AND V_TYP = \"Miete\" AND Aktiv = \"0\" ".$order.";";
	$result2 =	$db->query($sql2);
	$sql3 =		"SELECT ID, TID, Kurz, Art, WohnF, Mkalt, Count, DATE_FORMAT(Datum, \"%d.%m.%Y\") AS Datum, DATE_FORMAT(Akt_Datum, \"%d.%m.%Y\") AS Akt_Datum FROM objekte WHERE O_TYP = \"Wohnung\" AND V_TYP = \"Kauf\" AND Aktiv = \"1\" ".$order.";";
	$result3 =	$db->query($sql3);
	$sql4 =		"SELECT ID, TID, Kurz, Art, WohnF, Mkalt, Count, DATE_FORMAT(Datum, \"%d.%m.%Y\") AS Datum, DATE_FORMAT(Akt_Datum, \"%d.%m.%Y\") AS Akt_Datum FROM objekte WHERE O_TYP = \"Wohnung\" AND V_TYP = \"Kauf\" AND Aktiv = \"0\" ".$order.";";
	$result4 =	$db->query($sql4);
	$sql5 =		"SELECT ID, TID, Kurz, Art, WohnF, Mkalt, Count, DATE_FORMAT(Datum, \"%d.%m.%Y\") AS Datum, DATE_FORMAT(Akt_Datum, \"%d.%m.%Y\") AS Akt_Datum FROM objekte WHERE O_TYP = \"Haus\" AND V_TYP = \"Miete\" AND Aktiv = \"1\" ".$order.";";
	$result5 =	$db->query($sql5);
	$sql6 =		"SELECT ID, TID, Kurz, Art, WohnF, Mkalt, Count, DATE_FORMAT(Datum, \"%d.%m.%Y\") AS Datum, DATE_FORMAT(Akt_Datum, \"%d.%m.%Y\") AS Akt_Datum FROM objekte WHERE O_TYP = \"Haus\" AND V_TYP = \"Miete\" AND Aktiv = \"0\" ".$order.";";
	$result6 =	$db->query($sql6);
	$sql7 =		"SELECT ID, TID, Kurz, Art, WohnF, Mkalt, Count, DATE_FORMAT(Datum, \"%d.%m.%Y\") AS Datum, DATE_FORMAT(Akt_Datum, \"%d.%m.%Y\") AS Akt_Datum FROM objekte WHERE O_TYP = \"Haus\" AND V_TYP = \"Kauf\" AND Aktiv = \"1\" ".$order.";";
	$result7 =	$db->query($sql7);
	$sql8 =		"SELECT ID, TID, Kurz, Art, WohnF, Mkalt, Count, DATE_FORMAT(Datum, \"%d.%m.%Y\") AS Datum, DATE_FORMAT(Akt_Datum, \"%d.%m.%Y\") AS Akt_Datum FROM objekte WHERE O_TYP = \"Haus\" AND V_TYP = \"Kauf\" AND Aktiv = \"0\" ".$order.";";
	$result8 =	$db->query($sql8);
	
	echo "<table class=\"Objekt\">\n";
	echo "	<colgroup>\n";
	echo "		<col span=\"2\" width=\"30px\" />\n";
	echo "		<col width=\"230px\" />\n";
	echo "		<col width=\"100px\" />\n";
	echo "		<col span=\"4\" width=\"75px\" />\n";
	echo "		<col width=\"50px\" />\n";
	echo "	</colgroup>\n";
	
	echo "	<tr>\n";
	echo "		<td colspan=\"9\"><h3>aktive Wohnimmobilien</h3></td>\n";
	echo "	</tr>\n";
	echo "	<tr>\n";
	echo "		<th colspan=\"9\">Wohnungen - Miete</th>\n";
	echo "	</tr>\n";
	echo "	<tr class=\"underline\">\n";
	echo "		<td>ID</td>\n";
	echo "		<td>TID</td>\n";
	echo "		<td>Kurzbeschreibung</td>\n";
	echo "		<td>Typ</td>\n";
	echo "		<td>Fläche</td>\n";
	echo "		<td>KM</td>\n";
	echo "		<td>Erstellt</td>\n";
	echo "		<td>Geändert</td>\n";
	echo "		<td>Zugriffe</td>\n";
	echo "	</tr>\n";
	while ($wma = $result1->fetch_assoc()) {
		echo "	<tr>\n";
		echo "		<td>".$wma['ID']."</td>\n";
		echo "		<td>".$wma['TID']."</td>\n";
		echo "		<td>".substr($wma['Kurz'],0,30)."</td>\n";
		echo "		<td>".$wma['Art']."</td>\n";
		echo "		<td>".$wma['WohnF']." qm</td>\n";
		echo "		<td>".$wma['Mkalt']." &euro;</td>\n";
		echo "		<td>".$wma['Datum']."</td>\n";
		echo "		<td>".$wma['Akt_Datum']."</td>\n";
		echo "		<td>".$wma['Count']."</td>\n";
		echo "	</tr>\n";
	}

	echo "	<tr>\n";
	echo "		<th colspan=\"9\">Wohnungen - Kauf</th>\n";
	echo "	</tr>\n";
	echo "	<tr class=\"underline\">\n";
	echo "		<td>ID</td>\n";
	echo "		<td>TID</td>\n";
	echo "		<td>Kurzbeschreibung</td>\n";
	echo "		<td>Typ</td>\n";
	echo "		<td>Fläche</td>\n";
	echo "		<td>KP</td>\n";
	echo "		<td>Erstellt</td>\n";
	echo "		<td>Geändert</td>\n";
	echo "		<td>Zugriffe</td>\n";
	echo "	</tr>\n";
	while ($wka = $result3->fetch_assoc()) {
		echo "	<tr>\n";
		echo "		<td>".$wka['ID']."</td>\n";
		echo "		<td>".$wka['TID']."</td>\n";
		echo "		<td>".substr($wka['Kurz'],0,30)."</td>\n";
		echo "		<td>".$wka['Art']."</td>\n";
		echo "		<td>".$wka['WohnF']." qm</td>\n";
		echo "		<td>".$wka['Mkalt']." &euro;</td>\n";
		echo "		<td>".$wka['Datum']."</td>\n";
		echo "		<td>".$wka['Akt_Datum']."</td>\n";
		echo "		<td>".$wka['Count']."</td>\n";
		echo "	</tr>\n";
	}

	echo "	<tr>\n";
	echo "		<th colspan=\"9\">Häuser - Miete</th>\n";
	echo "	</tr>\n";
	echo "	<tr class=\"underline\">\n";
	echo "		<td>ID</td>\n";
	echo "		<td>TID</td>\n";
	echo "		<td>Kurzbeschreibung</td>\n";
	echo "		<td>Typ</td>\n";
	echo "		<td>Fläche</td>\n";
	echo "		<td>KM</td>\n";
	echo "		<td>Erstellt</td>\n";
	echo "		<td>Geändert</td>\n";
	echo "		<td>Zugriffe</td>\n";
	echo "	</tr>\n";
	while ($hma = $result5->fetch_assoc()) {
		echo "	<tr>\n";
		echo "		<td>".$hma['ID']."</td>\n";
		echo "		<td>".$hma['TID']."</td>\n";
		echo "		<td>".substr($hma['Kurz'],0,30)."</td>\n";
		echo "		<td>".$hma['Art']."</td>\n";
		echo "		<td>".$hma['WohnF']." qm</td>\n";
		echo "		<td>".$hma['Mkalt']." &euro;</td>\n";
		echo "		<td>".$hma['Datum']."</td>\n";
		echo "		<td>".$hma['Akt_Datum']."</td>\n";
		echo "		<td>".$hma['Count']."</td>\n";
		echo "	</tr>\n";
	}

	echo "	<tr>\n";
	echo "		<th colspan=\"9\">Häuser - Kauf</th>\n";
	echo "	</tr>\n";
	echo "	<tr class=\"underline\">\n";
	echo "		<td>ID</td>\n";
	echo "		<td>TID</td>\n";
	echo "		<td>Kurzbeschreibung</td>\n";
	echo "		<td>Typ</td>\n";
	echo "		<td>Fläche</td>\n";
	echo "		<td>KP</td>\n";
	echo "		<td>Erstellt</td>\n";
	echo "		<td>Geändert</td>\n";
	echo "		<td>Zugriffe</td>\n";
	echo "	</tr>\n";
	while ($hka = $result7->fetch_assoc()) {
		echo "	<tr>\n";
		echo "		<td>".$hka['ID']."</td>\n";
		echo "		<td>".$hka['TID']."</td>\n";
		echo "		<td>".substr($hka['Kurz'],0,30)."</td>\n";
		echo "		<td>".$hka['Art']."</td>\n";
		echo "		<td>".$hka['WohnF']." qm</td>\n";
		echo "		<td>".$hka['Mkalt']." &euro;</td>\n";
		echo "		<td>".$hka['Datum']."</td>\n";
		echo "		<td>".$hka['Akt_Datum']."</td>\n";
		echo "		<td>".$hka['Count']."</td>\n";
		echo "	</tr>\n";
	}

	echo "	<tr>\n";
	echo "		<td colspan=\"9\"><h3>inaktive Wohnimmobilien</h3></td>\n";
	echo "	</tr>\n";
	echo "	<tr>\n";
	echo "		<th colspan=\"9\">Wohnungen - Miete</th>\n";
	echo "	</tr>\n";
	echo "	<tr class=\"underline\">\n";
	echo "		<td>ID</td>\n";
	echo "		<td>TID</td>\n";
	echo "		<td>Kurzbeschreibung</td>\n";
	echo "		<td>Typ</td>\n";
	echo "		<td>Fläche</td>\n";
	echo "		<td>KM</td>\n";
	echo "		<td>Erstellt</td>\n";
	echo "		<td>Geändert</td>\n";
	echo "		<td>Zugriffe</td>\n";
	echo "	</tr>\n";
	while ($wmi = $result2->fetch_assoc()) {
		echo "	<tr>\n";
		echo "		<td>".$wmi['ID']."</td>\n";
		echo "		<td>".$wmi['TID']."</td>\n";
		echo "		<td>".substr($wmi['Kurz'],0,30)."</td>\n";
		echo "		<td>".$wmi['Art']."</td>\n";
		echo "		<td>".$wmi['WohnF']." qm</td>\n";
		echo "		<td>".$wmi['Mkalt']." &euro;</td>\n";
		echo "		<td>".$wmi['Datum']."</td>\n";
		echo "		<td>".$wmi['Akt_Datum']."</td>\n";
		echo "		<td>".$wmi['Count']."</td>\n";
		echo "	</tr>\n";
	}

	echo "	<tr>\n";
	echo "		<th colspan=\"9\">Wohnungen - Kauf</th>\n";
	echo "	</tr>\n";
	echo "	<tr class=\"underline\">\n";
	echo "		<td>ID</td>\n";
	echo "		<td>TID</td>\n";
	echo "		<td>Kurzbeschreibung</td>\n";
	echo "		<td>Typ</td>\n";
	echo "		<td>Fläche</td>\n";
	echo "		<td>KP</td>\n";
	echo "		<td>Erstellt</td>\n";
	echo "		<td>Geändert</td>\n";
	echo "		<td>Zugriffe</td>\n";
	echo "	</tr>\n";
	while ($wki = $result2->fetch_assoc()) {
		echo "	<tr>\n";
		echo "		<td>".$wki['ID']."</td>\n";
		echo "		<td>".$wki['TID']."</td>\n";
		echo "		<td>".substr($wki['Kurz'],0,30)."</td>\n";
		echo "		<td>".$wki['Art']."</td>\n";
		echo "		<td>".$wki['WohnF']." qm</td>\n";
		echo "		<td>".$wki['Mkalt']." &euro;</td>\n";
		echo "		<td>".$wki['Datum']."</td>\n";
		echo "		<td>".$wki['Akt_Datum']."</td>\n";
		echo "		<td>".$wki['Count']."</td>\n";
		echo "	</tr>\n";
	}

	echo "	<tr>\n";
	echo "		<th colspan=\"9\">Häuser - Miete</th>\n";
	echo "	</tr>\n";
	echo "	<tr class=\"underline\">\n";
	echo "		<td>ID</td>\n";
	echo "		<td>TID</td>\n";
	echo "		<td>Kurzbeschreibung</td>\n";
	echo "		<td>Typ</td>\n";
	echo "		<td>Fläche</td>\n";
	echo "		<td>KM</td>\n";
	echo "		<td>Erstellt</td>\n";
	echo "		<td>Geändert</td>\n";
	echo "		<td>Zugriffe</td>\n";
	echo "	</tr>\n";
	while ($hmi = $result6->fetch_assoc()) {
		echo "	<tr>\n";
		echo "		<td>".$hmi['ID']."</td>\n";
		echo "		<td>".$hmi['TID']."</td>\n";
		echo "		<td>".substr($hmi['Kurz'],0,30)."</td>\n";
		echo "		<td>".$hmi['Art']."</td>\n";
		echo "		<td>".$hmi['WohnF']." qm</td>\n";
		echo "		<td>".$hmi['Mkalt']." &euro;</td>\n";
		echo "		<td>".$hmi['Datum']."</td>\n";
		echo "		<td>".$hmi['Akt_Datum']."</td>\n";
		echo "		<td>".$hmi['Count']."</td>\n";
		echo "	</tr>\n";
	}

	echo "	<tr>\n";
	echo "		<th colspan=\"9\">Häuser - Kauf</th>\n";
	echo "	</tr>\n";
	echo "	<tr class=\"underline\">\n";
	echo "		<td>ID</td>\n";
	echo "		<td>TID</td>\n";
	echo "		<td>Kurzbeschreibung</td>\n";
	echo "		<td>Typ</td>\n";
	echo "		<td>Fläche</td>\n";
	echo "		<td>KP</td>\n";
	echo "		<td>Erstellt</td>\n";
	echo "		<td>Geändert</td>\n";
	echo "		<td>Zugriffe</td>\n";
	echo "	</tr>\n";
	while ($hki = $result8->fetch_assoc()) {
		echo "	<tr>\n";
		echo "		<td>".$hki['ID']."</td>\n";
		echo "		<td>".$hki['TID']."</td>\n";
		echo "		<td>".substr($hki['Kurz'],0,30)."</td>\n";
		echo "		<td>".$hki['Art']."</td>\n";
		echo "		<td>".$hki['WohnF']." qm</td>\n";
		echo "		<td>".$hki['Mkalt']." &euro;</td>\n";
		echo "		<td>".$hki['Datum']."</td>\n";
		echo "		<td>".$hki['Akt_Datum']."</td>\n";
		echo "		<td>".$hki['Count']."</td>\n";
		echo "	</tr>\n";
	}

	echo "</table>\n";

}
?>