<?php

if (!isset($_SESSION['ID'])) { die ('Sie haben keine Rechte diese Seite zu bearbeiten!'); }

if (!isset($_POST['formaction'])) { die ('Benutzen sie nur Formulare von der Homepage.'); }

if ('Anlegen' == ($_POST['formaction']))
	{
		$sql = 'INSERT INTO objekte (ID, TID, KAT, O_TYP, V_TYP, Datum, Akt_Datum) VALUES (NULL, "'.$_SESSION['TID'].'", "wohnen", "'.$O_TYP.'", "'.$V_TYP.'", now(), now())';
		$stmt = $db->prepare($sql);
		if (!$stmt)
			{
				die ('Datensatz konnte nicht angelegt werden: '.$db->error);
			}
		if (!$stmt->execute())
			{
				die ('Datensatz konnte nicht angelegt werden: '.$stmt->error);
			}
		$sql = 'SELECT last_insert_id() AS last';
		$result = $db->query($sql);
		$nt = $result->fetch_assoc();
		$id = $nt['last'];
	}
elseif ('Bearbeiten' == ($_POST['formaction']))
	{
		$id = $_POST['ID'];
	}

$sql2		= "SELECT Typ FROM Haus_Typ ORDER BY Typ ";
$result2	= $db->query($sql2);
$sql3		= "SELECT Zustand FROM O_Zustand ORDER BY ID ";
$result3	= $db->query($sql3);
$sql4		= "SELECT Quali FROM Ausstattung_Qualitaet ORDER BY ID ";
$result4	= $db->query($sql4);
$sql5		= "SELECT Haustiere FROM Haustiere ORDER BY ID ";
$result5	= $db->query($sql5);
$sql6		= "SELECT Renovierung FROM Renovierung ORDER BY ID ";
$result6	= $db->query($sql6);
$sql7		= "SELECT Heiz_Typ FROM Heizung_Typ ORDER BY ID ";
$result7	= $db->query($sql7);
$sql8		= "SELECT Befeuerung FROM Befeuerung ORDER BY ID ";
$result8	= $db->query($sql8);
$sql9		= "SELECT ID, Vorname, Nachname FROM Team ORDER BY ID ASC";
$result9	= $db->query($sql9);
$sql10		= "SELECT Energieausweis FROM Energieausweis_Typ ORDER BY ID ASC";
$result10	= $db->query($sql10);
$sql11		= "SELECT Wert FROM US WHERE ID = \"9\";";
$result11	= $db->query($sql11);
$nt11		= $result11->fetch_assoc();
$sqlob		= 'SELECT * FROM objekte WHERE ID = "'.$id.'" ';
$resultob	= $db->query($sqlob);
$ntob		= $resultob->fetch_assoc();

?>

<div id="objektErrors">
</div>
<h1>Kaufobjekt <i><?php echo $ntob['ID']." - ".$ntob['Kurz']; ?></i> bearbeiten</h1>
<form id="objekt" action="index.php?<?php echo $_SERVER['QUERY_STRING']; ?>" method="post" enctype="multipart/form-data">
	<input type="hidden" name="VVID" value="0" />
	<input type="hidden" name="Aktiv" value="0" />
	<input type="hidden" name="Deaktiv" value="0" />
	<input type="hidden" name="Highlight" value="0" />
	<fieldset>
		<legend>Eigenschaften</legend>
		<input type="hidden" name="ID" value="<?php echo $id; ?>" />
		<label>Neu Eingetroffen</label><input type="radio" name="Neu" value="1" <?php if ('1' == $ntob['Neu']) {echo "checked=\"checked\" ";} ?>/>ja<input type="radio" name="Neu" value="0" <?php if ('0' == $ntob['Neu']) {echo "checked=\"checked\" ";} ?>/>nein
		<img src="../img/help.gif" title="Dieses Objekt darf unter Neu Eingetroffen auf der Startseite erscheinen" />
		<br />
		<label>Foto auf Startseite</label><input type="radio" name="FotoStart" value="1" <?php if ('1' == $ntob['FotoStart']) {echo "checked=\"checked\" ";} ?>/>ja<input type="radio" name="FotoStart" value="0" <?php if ('0' == $ntob['FotoStart']) {echo "checked=\"checked\" ";} ?>/>nein
		<img src="../img/help.gif" title="Das erste Foto dieses Objekts darf in der Bilderleiste auf der Startseite erscheinen" />
		<br />
		<label>Überschrift</label><input onkeypress="checkForValidChar ( this , arguments[0] || window.event , 100 );" onkeyup="deleteCharsFromTextarea ( this , 100 );" class="lang" type="text" name="Kurz" <?php echo 'value="'.$ntob['Kurz'].'"'; ?>/><img src="../img/help.gif" title="Dieses Feld erlaubt zwischen 1 und 100 Zeichen" /><br />

<?php

if ("Tags" == $nt11['Wert'])
	{
		echo "				<label>SEO-Schlagworte</label><input class=\"lang\" type=\"text\" name=\"Tags\" value=\"".$ntob['Tags']."\" /><img src=\"../img/help.gif\" title=\"Hier können Sie die Schlagworte für die Suchmaschinen eingeben.\" /><br />\n";
	}
else
	{
		echo "				<input type=\"hidden\" name=\"Tags\" value=\"".$ntob['Tags']."\" />\n";
	}

?>

		<br />
		<label>Art</label><select size="1" name="Art">

<?php

while($nt2 = $result2->fetch_assoc())
	{
		echo "            <option value=\"".$nt2['Typ']."\" ";
		if ($nt2['Typ'] == $ntob['Art'])
			{
				echo "selected=\"selected\" ";
			}
		echo ">".$nt2['Typ']."</option>\n ";
	}

?>

		</select>
		<br />
		<label>Zustand</label><select size="1" name="Zustand"><br />

<?php

while($nt3 = $result3->fetch_assoc())
	{
		echo "            <option value=\"".$nt3['Zustand']."\" ";
		if ($nt3['Zustand'] == $ntob['Zustand'])
			{
				echo "selected=\"selected\" ";
			}
		echo ">".$nt3['Zustand']."</option>\n ";
	}

?>

		</select><br />
		<label>Qualität der Ausstattung</label><select size="1" name="Quali"><br />

<?php

while($nt4 = $result4->fetch_assoc())
	{
		echo "            <option value=\"".$nt4['Quali']."\" ";
		if ($nt4['Quali'] == $ntob['Quali'])
			{
				echo "selected=\"selected\" ";
			}
		echo ">".$nt4['Quali']."</option>\n ";
	}

?>

		</select><br />
		<label>Baujahr</label><input class="kurz" type="text" name="Baujahr" <?php echo 'value="'.$ntob['Baujahr'].'"'; ?>/><br />
		<label>letzte Modernisierung</label><input class="kurz" type="text" name="Modern" <?php echo 'value="'.$ntob['Modern'].'"'; ?>/><img src="../img/help.gif" title="nur das Jahr der letzten Modernisierung!" /><br />
		<label>Zimmer</label><input class="kurz" type="text" name="Zimmer" <?php echo 'value="'.$ntob['Zimmer'].'"'; ?>/><img src="../img/help.gif" title="Dezimaltrennzeichen ist der Punkt,z.B.: 4.5 Zimmer" /><br />
		<label>Etagen</label><input class="kurz" type="text" name="Etagen" <?php echo 'value="'.$ntob['Etagen'].'"'; ?>/><br />
		<label>Wohnfl&auml;che</label><input class="kurz" type="text" name="WohnF" <?php echo 'value="'.$ntob['WohnF'].'"'; ?>/><br />
		<label>Grundfl&auml;che</label><input class="kurz" type="text" name="GrundF" <?php echo 'value="'.$ntob['GrundF'].'"'; ?>/><br />
		<label>Heizart</label><select size="1" name="Heizart"><br />

<?php

while($nt7 = $result7->fetch_assoc())
	{
		echo "            <option value=\"".$nt7['Heiz_Typ']."\" ";
		if ($nt7['Heiz_Typ'] == $ntob['Heizart'])
			{
				echo "selected=\"selected\" ";
			}
		echo ">".$nt7['Heiz_Typ']."</option>\n ";
	}

?>

		</select><br />
		<label>Befeuerungsart</label><select size="1" name="Befeuerung"><br />

<?php

while($nt8 = $result8->fetch_assoc())
	{
		echo "            <option value=\"".$nt8['Befeuerung']."\" ";
		if ($nt8['Befeuerung'] == $ntob['Befeuerung'])
			{
				echo "selected=\"selected\" ";
			}
		echo ">".$nt8['Befeuerung']."</option>\n ";
	}

?>

		</select><br />
		<label>Aufstellort Waschmaschine</label><input type="text" name="WaschOrt"<?php echo 'value="'.$ntob[WaschOrt].'"'; ?> /><br />
		<label>TV-Anschluss</label><input type="text" name="TV" <?php echo 'value="'.$ntob[TV].'"'; ?>/><br />
		<label>Bezug</label><input type="text" name="Bezug" <?php echo 'value="'.$ntob['Bezug'].'"'; ?>/><br />
	</fieldset><br />
	<fieldset>
		<legend>Objektbeschreibung</legend>
		<textarea name="OBeschreibung" rows="15" onkeypress="checkForValidChar ( this , arguments[0] || window.event , 2000 );" onkeyup="deleteCharsFromTextarea ( this , 2000 );"><?php echo $ntob['OBeschreibung']; ?></textarea>
	</fieldset><br />
	<fieldset>
		<legend>Ausstattung</legend>
		<textarea name="Ausstatt" rows="15" onkeypress="checkForValidChar ( this , arguments[0] || window.event , 2000 );" onkeyup="deleteCharsFromTextarea ( this , 2000 );"><?php echo $ntob['Ausstatt']; ?></textarea><br />&nbsp;<br />
		<fieldset>
			<legend>innen</legend>
			<label>Anzahl Schlafzimmer</label><input class="kurz" type="text" name="AnzSchlaf" <?php echo 'value="'.$ntob['AnzSchlaf'].'"'; ?> /><br />
			<label>Abstellraum</label><input type="radio" name="Abstell" value="1" <?php if ('1' == $ntob['Abstell']) {echo "checked=\"checked\" ";} ?>/>ja<input type="radio" name="Abstell" value="0" <?php if ('0' == $ntob['Abstell']) {echo "checked=\"checked\" ";} ?>/>nein<br />
			<label>Dachboden</label><input type="radio" name="DachB" value="1" <?php if ('1' == $ntob['DachB']) {echo "checked=\"checked\" ";} ?>/>ja<input type="radio" name="DachB" value="0" <?php if ('0' == $ntob['DachB']) {echo "checked=\"checked\" ";} ?>/>nein<br />
			<label>Keller</label><input type="radio" name="Keller" value="1" <?php if ('1' == $ntob['Keller']) {echo "checked=\"checked\" ";} ?>/>ja<input type="radio" name="Keller" value="0" <?php if ('0' == $ntob['Keller']) {echo "checked=\"checked\" ";} ?>/>nein<br />
			<label>Aufzug</label><input type="radio" name="Aufzug" value="1" <?php if ('1' == $ntob['Aufzug']) {echo "checked=\"checked\" ";} ?>/>ja<input type="radio" name="Aufzug" value="0" <?php if ('0' == $ntob['Aufzug']) {echo "checked=\"checked\" ";} ?>/>nein<br />
			<label>Betreutes Wohnen</label><input type="radio" name="Betreut" value="1" <?php if ('1' == $ntob['Betreut']) {echo "checked=\"checked\" ";} ?>/>ja<input type="radio" name="Betreut" value="0" <?php if ('0' == $ntob['Betreut']) {echo "checked=\"checked\" ";} ?>/>nein<br />
			<label>Barrierefrei</label><input type="radio" name="Barrierefrei" value="1" <?php if ('1' == $ntob['Barrierefrei']) {echo "checked=\"checked\" ";} ?>/>ja<input type="radio" name="Barrierefrei" value="0" <?php if ('0' == $ntob['Barrierefrei']) {echo "checked=\"checked\" ";} ?>/>nein<br />
		</fieldset><br />
		<fieldset>
			<legend>K&uuml;che</legend>
			<label>Einbauk&uuml;che</label><input type="radio" name="EinbauK" value="1" <?php if ('1' == $ntob['EinbauK']) {echo "checked=\"checked\" ";} ?>/>ja<input type="radio" name="EinbauK" value="0" <?php if ('0' == $ntob['EinbauK']) {echo "checked=\"checked\" ";} ?>/>nein<br />
			<label>Speisekammer</label><input type="radio" name="Speise" value="1" <?php if ('1' == $ntob['Speise']) {echo "checked=\"checked\" ";} ?>/>ja<input type="radio" name="Speise" value="0" <?php if ('0' == $ntob['Speise']) {echo "checked=\"checked\" ";} ?>/>nein<br />
		</fieldset><br />
		<fieldset>
			<legend>Badezimmer</legend>
			<label>Anzahl Badezimmer</label><input class="kurz" type="text" name="AnzBad" <?php echo 'value="'.$ntob['AnzBad'].'"'; ?> /><br />
			<label>Badewanne</label><input type="radio" name="BadeW" value="1" <?php if ('1' == $ntob['BadeW']) {echo "checked=\"checked\" ";} ?>/>ja<input type="radio" name="BadeW" value="0" <?php if ('0' == $ntob['BadeW']) {echo "checked=\"checked\" ";} ?>/>nein<br />
			<label>Duschkabine</label><input type="radio" name="DuschK" value="1" <?php if ('1' == $ntob['DuschK']) {echo "checked=\"checked\" ";} ?>/>ja<input type="radio" name="DuschK" value="0" <?php if ('0' == $ntob['DuschK']) {echo "checked=\"checked\" ";} ?>/>nein<br />
			<label>WC im Bad</label><input type="radio" name="WCbad" value="1" <?php if ('1' == $ntob['WCbad']) {echo "checked=\"checked\" ";} ?>/>ja<input type="radio" name="WCbad" value="0" <?php if ('0' == $ntob['WCbad']) {echo "checked=\"checked\" ";} ?>/>nein<br />
			<label>Gäste-WC</label><input type="radio" name="WCsep" value="1" <?php if ('1' == $ntob['WCsep']) {echo "checked=\"checked\" ";} ?>/>ja<input type="radio" name="WCsep" value="0" <?php if ('0' == $ntob['WCsep']) {echo "checked=\"checked\" ";} ?>/>nein<br />
		</fieldset><br />
		<fieldset>
			<legend>au&szlig;en</legend>
			<label>Anzahl Garagen/Stellplätze</label><input class="kurz" type="text" name="AnzGarStell" <?php echo 'value="'.$ntob['AnzGarStell'].'"'; ?> /><br />
			<label>Garage</label><input type="radio" name="Garage" value="1" <?php if ('1' == $ntob['Garage']) {echo "checked=\"checked\" ";} ?>/>ja<input type="radio" name="Garage" value="0" <?php if ('0' == $ntob['Garage']) {echo "checked=\"checked\" ";} ?>/>nein<br />
			<label>Stellplatz</label><input type="radio" name="StellPl" value="1" <?php if ('1' == $ntob['StellPl']) {echo "checked=\"checked\" ";} ?>/>ja<input type="radio" name="StellPl" value="0" <?php if ('0' == $ntob['StellPl']) {echo "checked=\"checked\" ";} ?>/>nein<br />
			<label>Terrasse</label><input type="radio" name="Terrasse" value="1" <?php if ('1' == $ntob['Terrasse']) {echo "checked=\"checked\" ";} ?>/>ja<input type="radio" name="Terrasse" value="0" <?php if ('0' == $ntob['Terrasse']) {echo "checked=\"checked\" ";} ?>/>nein<br />
			<label>Balkon</label><input type="radio" name="Balkon" value="1" <?php if ('1' == $ntob['Balkon']) {echo "checked=\"checked\" ";} ?>/>ja<input type="radio" name="Balkon" value="0" <?php if ('0' == $ntob['Balkon']) {echo "checked=\"checked\" ";} ?>/>nein<br />
			<label>Gartenbenutzung</label><input type="radio" name="Garten" value="1" <?php if ('1' == $ntob['Garten']) {echo "checked=\"checked\" ";} ?>/>ja<input type="radio" name="Garten" value="0" <?php if ('0' == $ntob['Garten']) {echo "checked=\"checked\" ";} ?>/>nein<br />
		</fieldset><br />
		<fieldset>
			<legend>Energieausweis</legend>
			<label>Energieausweistyp</label><select size="1" name="EnerTyp"><br />

<?php

while($nt10 = $result10->fetch_assoc())
	{
		echo "            <option value=\"".$nt10['Energieausweis']."\" ";
		if ($nt10['Energieausweis'] == $ntob['EnerTyp'])
			{
				echo "selected=\"selected\" ";
			}
		echo ">".$nt10['Energieausweis']."</option>\n ";
	}

?>

			</select><br />
			<label>Verbrauchskennwert</label><input class="kurz" type="text" name="EnerVKW" <?php echo 'value="'.$ntob['EnerVKW'].'"'; ?>/><br />
			<label>Warmwasser enthalten</label><input type="radio" name="EnerWWEnt" value="1" <?php if ('1' == $ntob['EnerWWEnt']) {echo "checked=\"checked\" ";} ?>/>ja<input type="radio" name="EnerWWEnt" value="0" <?php if ('0' == $ntob['EnerWWEnt']) {echo "checked=\"checked\" ";} ?>/>nein<br />
		</fieldset><br />
	</fieldset><br />
	<fieldset>
		<legend>Lage</legend>
		<label>Strasse / Nr</label><input type="text" name="Strasse" <?php echo 'value="'.$ntob['Strasse'].'"'; ?>/> / <input class="kurz" type="text" name="StraNr" <?php echo 'value="'.$ntob['StraNr'].'"'; ?>/><br />
		<label>PLZ / Ort</label><input class="kurz" type="text" name="PLZ" <?php echo 'value="'.$ntob['PLZ'].'"'; ?>/> / <input type="text" name="Ort" <?php echo 'value="'.$ntob['Ort'].'"'; ?>/><br />
		<label>Lage</label>
		<textarea name="Lage" rows="15" onkeypress="checkForValidChar ( this , arguments[0] || window.event , 2000 );" onkeyup="deleteCharsFromTextarea ( this , 2000 );"><?php echo $ntob['Lage']; ?></textarea>
	</fieldset><br />
	<fieldset>
		<legend>Kosten</legend>
		<label>Kaufpreis</label><input class="kurz" type="text" name="Mkalt" <?php echo 'value="'.$ntob['Mkalt'].'"'; ?>/><br />
		<label>Wohngeld</label><input class="kurz" type="text" name="Mwarm" <?php echo 'value="'.$ntob['Mwarm'].'"'; ?>/><br />
		<label>Kaufpreis Garage</label><input class="kurz" type="text" name="GaraK" <?php echo 'value="'.$ntob['GaraK'].'"'; ?>/><br />
		<label>Kaufpreis Stellplatz</label><input class="kurz" type="text" name="StellK" <?php echo 'value="'.$ntob['StellK'].'"'; ?>/><br />
		<label>Mieteinnahmen / Monat</label><input class="kurz" type="text" name="SonK" <?php echo 'value="'.$ntob['SonK'].'"'; ?>/><br />
		<label>Provisionspflichtig</label><input type="radio" name="ProvisionsPflichtig" value="1" <?php if ('1' == $ntob['ProvisionsPflichtig']) {echo "checked=\"checked\" ";} ?>/>ja<input type="radio" name="ProvisionsPflichtig" value="0" <?php if ('0' == $ntob['ProvisionsPflichtig']) {echo "checked=\"checked\" ";} ?>/>nein<br />
		<label>Provision</label><input type="text" name="Provision" <?php echo 'value="'.$ntob['Provision'].'"'; ?>/><br />
	</fieldset><br />
	<fieldset>
		<legend>Sonstiges</legend>
		<textarea name="Sonstiges" rows="15" onkeypress="checkForValidChar ( this , arguments[0] || window.event , 2000 );" onkeyup="deleteCharsFromTextarea ( this , 2000 );"><?php echo $ntob['Sonstiges']; ?></textarea>
	</fieldset><br />
	<fieldset>
		<legend>Interne Info</legend>
		<textarea name="Intern" rows="5"><?php echo $ntob['Intern']; ?></textarea>
	</fieldset><br />
	<img id="editButton" onclick="checkInputs();" style="float:left;margin:1px 10px 0px 0px;cursor:pointer" src="./img/check.jpg" />

<?php

if ("Anlegen" == $_POST['formaction'])
	{
		echo "	<input type=\"submit\" name=\"formaction\" value=\"Abbrechen\" />\n";
	}
else
	{
		echo "	<input type=\"reset\" value=\"Rücksetzen\" />\n";
	}

?>

	<input style="float:right;" id="saveButton" type="submit" name="formaction" value="Speichern" disabled="disabled" />
</form>
<script>
if (document.getElementById('objekt').addEventListener) {  
	document.getElementById('objekt').addEventListener('change', function() {
		document.getElementById('saveButton').disabled=true;
	}, false);
    } else if (document.getElementById('objekt').attachEvent)  {  
      document.getElementById('objekt').attachEvent('change', function() {
			document.getElementById('saveButton').disabled=true;
		} );  
    }  
</script>
