<?php
$a = true;
$b = true;
$filter = "(O_TYP = \"Büro\" OR O_TYP = \"Praxis\") AND Aktiv = 1 ";

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";
		}
	}
	echo "<h1>Büros und Praxen</h1>\n";
	
	$sql = 'SELECT ID, O_TYP, V_TYP, Count, Kurz, Zimmer, WohnF, Ort, Mkalt, Garage, StellPl, Terrasse, Balkon, Garten FROM objekte WHERE '.$filter.' ORDER BY ID ASC';
	$result = $db->query($sql);
	$anzahl = $result->num_rows;

	echo "<form class=\"suche\" action=\"index.php?section=gewerbe&amp;t=bp\" method=\"post\">\n";
	echo "<table>\n";
	echo "    <colgroup>\n";
	echo "        <col width=\"97px\" />\n";
	echo "        <col width=\"80px\" />\n";
	echo "        <col width=\"37px\" />\n";
	echo "        <col width=\"80px\" />\n";
	echo "        <col width=\"154px\" />\n";
	echo "        <col width=\"234px\" />\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=\"4\" /></td>\n";
	echo "        <td>bis</td>\n";
	echo "        <td><input type=\"text\" name=\"Zbis\" size=\"4\" /></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>Nutzfläche:</td>\n";
	echo "        <td><input type=\"text\" name=\"Wvon\" size=\"4\" /></td>\n";
	echo "        <td>bis</td>\n";
	echo "        <td><input type=\"text\" name=\"Wbis\" size=\"4\" /></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 span=\"6\" width=\"117\" />\n";
	echo "    </colgroup>\n";
	echo "    <tr>\n";
	echo "        <th style=\"-moz-border-radius-topleft: 3px; -moz-border-radius-bottomleft: 3px; -khtml-border-radius-topleft: 3px; -khtml-border-radius-bottomleft: 3px;\" >&nbsp;</th>\n";
	echo "        <th>Zimmer</th>\n";
	echo "        <th>Nutzfläche</th>\n";
	echo "        <th>Kaltmiete /<br />Kaufpreis</th>\n";
	echo "        <th style=\"-moz-border-radius-topright: 3px; -moz-border-radius-bottomright: 3px; -khtml-border-radius-topright: 3px; -khtml-border-radius-bottomright: 3px;\" colspan=\"2\">Ausstattung</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()) {
//	var_dump($nt);
	echo "<br />\n";
		if ('Kauf' == $nt['V_TYP']) {
			$form = "<form action=\"index.php?section=gewerbe&t=bpk&obj=".$nt['ID']."\" method=\"post\">\n";
		}
		else {
			$form = "<form action=\"index.php?section=gewerbe&t=bpm&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=\"3\"><input class=\"overview\" type=\"submit\" value=\"".$nt['Kurz']."\" /></td>\n";
		echo "    <tr>\n";
		if ('1' == $nt[Balkon]) {
			echo "        <td><img src=\"img/balkon.png\" alt=\"Balkon\" /></td>\n";
		}
		else {
			echo "<td>&nbsp;</td>\n";
		}
		if ('1' == $nt[Terrasse]) {
			echo "        <td><img src=\"img/terrasse.png\" alt=\"Terrasse\" /></td>\n";
		}
		else {
			echo "<td>&nbsp;</td>\n";
		}

		echo "    </tr>\n";
		echo "    <tr>\n";
		echo "    </tr>\n";
		echo "    <tr>\n";
		echo "        <td>$nt[Zimmer]</td>\n";
		echo "        <td>$nt[WohnF] m&sup2;</td>\n";
		echo "        <td>$nt[Mkalt] &euro;</td>\n";
		if ('1' == $nt[Garten]) {
			echo "        <td><img src=\"img/garten.png\" alt=\"Garten\" /></td>\n";
		}
		else {
			echo "<td>&nbsp;</td>\n";
		}
		if ('1' == $nt[Garage]) {
			echo "        <td><img src=\"img/garage.png\" alt=\"Garage\" /></td>\n";
		}
		else {
			echo "<td>&nbsp;</td>\n";
		}
		echo "    </tr>\n";
		echo "    <tr>\n";
		echo "        <td colspan=\"2\">$nt[Ort]</td>\n";
		if ('Kauf' ==$nt['V_TYP']) {
			echo "        <td class=\"highlighted\">Kauf</td>\n";
		}
		else {
			echo "        <td class=\"highlighted\">Miete</td>\n";
		}
		if ('1' == $nt[StellPl]) {
			echo "        <td><img src=\"img/ebk.png\" alt=\"Balkon\" /></td>\n";
		}
		else {
			echo "<td>&nbsp;</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'])) {
		echo "bin da";
		$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/gewerbe/bpobj.php";
}

?>