<?php

if (!isset($_GET['obj'])) {
	if (isset($_POST['formaction'])) {
		if (("" == $_POST['Zvon']) AND ("" == $_POST['Zbis'])) {
			}
			elseif (("" !== $_POST['Zvon']) AND ("" == $_POST['Zbis'])) {
				$filter = $filter. "AND Zimmer >= ".$_POST['Zvon']." ";
				$zimmer = "mehr als ".$_POST['Zvon']." Zimmer";
			}
			elseif (("" == $_POST['Zvon']) AND ("" !== $_POST['Zbis'])) {
				$filter = $filter. "AND Zimmer <= ".$_POST['Zbis']." ";
				$zimmer = "bis ".$_POST['Zbis']." Zimmer";
			}
			else {
				$filter = $filter. "AND Zimmer BETWEEN ".$_POST['Zvon']." AND ".$_POST['Zbis']." ";
				$zimmer = $_POST['Zvon']." bis ".$_POST['Zbis']." Zimmer";
			}
			if (("" == $_POST['Wvon']) AND ("" == $_POST['Wbis'])) {
			}
			elseif (("" !== $_POST['Wvon']) AND ("" == $_POST['Wbis'])) {
				$filter = $filter. "AND WohnF >= ".$_POST['Wvon']." ";
				$wohn = "mehr als ".$_POST['Wvon']." m&sup2;";
			}
			elseif (("" == $_POST['Wvon']) AND ("" !== $_POST['Wbis'])) {
				$filter = $filter. "AND WohnF <= ".$_POST['Wbis']." ";
				$wohn = "bis ".$_POST['Wbis']." m&sup2;";
			}
			else {
				$filter = $filter. "AND WohnF BETWEEN ".$_POST['Wvon']." AND ".$_POST['Wbis']." ";
				$wohn = $_POST['Wvon']." bis ".$_POST['Wbis']." m&sup2;";
			}
			if (("" == $_POST['Kvon']) AND ("" == $_POST['Kbis'])) {
			}
			elseif (("" !== $_POST['Kvon']) AND ("" == $_POST['Kbis'])) {
				$filter = $filter. "AND Mkalt >= ".$_POST['Kvon']." ";
				$kalt = "mehr als ".$_POST['Kvon']." EUR";
			}
			elseif (("" == $_POST['Kvon']) AND ("" !== $_POST['Kbis'])) {
				$filter = $filter. "AND Mkalt <= ".$_POST['Kbis']." ";
				$kalt = "bis ".$_POST['Kbis']." EUR";
			}
			else {
				$filter = $filter. "AND Mkalt BETWEEN ".$_POST['Kvon']." AND ".$_POST['Kbis']." ";
				$kalt = $_POST['Kvon']." bis ".$_POST['Kbis']." EUR";
			}
		}
	else
		{
			$zimmer = '';
			$wohn = '';
			$kalt = '';
			$filter = '';
		}
	echo "<h1>Sonstige Objekte</h1>\n";
	
	$sql = 'SELECT * FROM objekte WHERE Aktiv = "1" AND Deaktiv = "0" AND Kat != "wohnen" '.$filter.' ORDER BY Akt_Datum DESC';
	$result = $db->query($sql);
	$anzahl = $result->num_rows;

	echo "<form class=\"suche\" action=\"index.php?section=immobilien&topic=sonstige_objekte\" method=\"post\">\n";
	echo "<table>\n";
	echo "    <colgroup>\n";
	echo "        <col width=\"105px\" />\n";
	echo "        <col width=\"75px\" />\n";
	echo "        <col width=\"42px\" />\n";
	echo "        <col width=\"80px\" />\n";
	echo "        <col width=\"152px\" />\n";
	echo "        <col width=\"232px\" />\n";
	echo "    </colgroup>\n";
	echo "    <tr>\n";
	echo "        <th colspan=\"5\">Suchkriterien</th>\n";
	if (1 !== $anzahl) {
		echo "        <th>$anzahl Objekte im Angebot</th>\n";
	}
	else {
		echo "        <th>$anzahl Objekt im Angebot</th>\n";
	}
	echo "    </tr>\n";
	echo "    <tr>\n";
	echo "        <td>Zimmer:</td>\n";
	echo "        <td><input type=\"text\" name=\"Zvon\" size=\"5\" /></td>\n";
	echo "        <td>bis</td>\n";
	echo "        <td><input type=\"text\" name=\"Zbis\" size=\"5\" /></td>\n";
	echo "        <td></td>\n";
	if (isset($_POST['formaction'])) {
		echo "        <td>mit folgenden Kriterien:</td>\n";
	}
	echo "    </tr>\n";
	echo "    <tr>\n";
	echo "        <td>Fläche:</td>\n";
	echo "        <td><input type=\"text\" name=\"Wvon\" size=\"5\" /></td>\n";
	echo "        <td>bis</td>\n";
	echo "        <td><input type=\"text\" name=\"Wbis\" size=\"5\" /></td>\n";
	echo "        <td>m&sup2;</td>\n";
	echo "        <td>$zimmer</td>\n";
	echo "    </tr>\n";
	echo "    <tr>\n";
	echo "        <td colspan=\"5\"><input type=\"submit\" name=\"formaction\" value=\"Suchen\" /></td>\n";
	echo "        <td>$wohn</td>\n";
	echo "    </tr>\n";
	echo "</table>\n";
	echo "<br />\n";
	echo "</form>\n";
	echo "<br />\n";

	echo "<table class=\"overview\">\n";
	echo "	<colgroup>\n";
	echo "		<col width=\"125\" />\n";
	echo "		<col span=\"5\" width=\"117\" />\n";
	echo "	</colgroup>\n";
	echo "	<tr>\n";
	echo "		<th>&nbsp;</th>\n";
	echo "		<th>&nbsp;</th>\n";
	echo "		<th>Nutzfläche</th>\n";
	echo "		<th>Kaltmiete</th>\n";
	echo "		<th>Kaufpreis</th>\n";
	echo "		<th style=\"text-align:right;padding-right:10px;\">Objekt-Typ</th>\n";
	echo "	</tr>\n";
	echo "	<tr>\n";
	echo "		<td colspan=\"6\"><hr class=\"noDisplay\" /> &nbsp;</td>\n";
	echo "	<tr>\n";
	while ($nt = $result->fetch_assoc()) {
		if ( "anlage" == $nt['KAT'] )
			{
				$form = "<form action=\"index.php?section=immobilien&topic=anlage&obj=".$nt['ID']."\" method=\"post\">\n";
			}
		if ( "gewerbe" == $nt['KAT'] )
			{
				if ('Kauf' == $nt['V_TYP']) {
					$form = "<form action=\"index.php?section=immobilien&topic=gewerbe_kauf&obj=".$nt['ID']."\" method=\"post\">\n";
				}
				else {
					$form = "<form action=\"index.php?section=immobilien&topic=gewerbe_miete&obj=".$nt['ID']."\" method=\"post\">\n";
				}
			}
		echo $form;
		echo "<input type=\"hidden\" name=\"ID\" value=\"".$nt['ID']."\" />\n";
		echo "<input type=\"hidden\" name=\"Count\" value=\"".$nt['Count']."\" />\n";
		echo "    <tr>\n";
		echo "        <td rowspan=\"4\"><input type=\"image\" value=\"Zum Objekt\" src=\"img/objekte/".$nt['ID']."_1.jpg\" width=\"80px\" height=\"60px\" /></td>\n";
		echo "        <td colspan=\"5\"><input class=\"overview\" type=\"submit\" value=\"".$nt['Kurz']."\" /></td>\n";
		echo "    </tr>\n";
		echo "    <tr>\n";
		echo "    </tr>\n";
		echo "    <tr>\n";
		echo "        <td>" . strtoupper(substr($nt['KAT'], 0,1)).substr($nt['KAT'], 1) . "</td>\n";
		echo "        <td>" . $nt['WohnF'] . " m&sup2;</td>\n";
		if ('Kauf' == $nt['V_TYP']) {
			echo "        <td>&nbsp;</td>\n";
			echo "        <td>" . number_format ( $nt['Mkalt'], 0, '', '.') . " &euro;</td>\n";
			echo "        <td style=\"text-align:right;padding-right:10px;color:#660000;\">Kauf</td>\n";
		}
		else {
			echo "        <td>&nbsp;</td>\n";
			echo "        <td>" . number_format ( $nt['Mkalt'], 0, '', '.') . " &euro;</td>\n";
			echo "        <td style=\"text-align:right;padding-right:10px;color:#660000;\">Miete</td>\n";
		}
		echo "    </tr>\n";
		echo "    <tr>\n";
		echo "        <td colspan=\"3\">" . $nt['Ort'] . "</td>\n";
		echo "        <td colspan=\"2\" style=\"text-align:right;padding-right:10px;\">" . $nt['O_TYP'] . "</td>\n";
		echo "    </tr>\n";
		echo "    <tr>\n";
		echo "        <td colspan=\"6\"><hr /></td>\n";
		echo "    </tr>\n";
		echo "</form>\n";
	}
	echo "</table>\n";
} else {
	if (isset($_POST['ID'])) {
		$Zaehler =	(int)($_POST['Count']) + 1;
		$sqlu =		"UPDATE objekte SET Count = \"".$Zaehler."\" WHERE ID = \"".$_POST['ID']."\";";
		$stmtu = $db->prepare($sqlu);
		if ($stmtu) {
			if ($stmtu->execute()) {
			}
		}
		unset($_POST);
	}
	include "inhalte/wohn/wmobj.php";
}

?>
