<?php
if (!isset($_SESSION['ID'])) {
} else {
	if ("Anlegen" == $_POST['action']) {
		$sql = 'INSERT INTO Team SET ID = NULL';
		$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'];
		$sql	= 'UPDATE Team SET AnzeigeNr = "'.$id.'" WHERE ID = "'.$id.'";';
		$stmt	= $db->prepare($sql);
		if (!$stmt) {
			die ('Datensatz konnte nicht gespeichert werden: '.$db->error);
		}
		if (!$stmt->execute()) {
			die ('Datensatz konnte nicht gespeichert werden: '.$stmt->error);
		}
	} else {
		$id = $_POST['ID'];
	}
	
	$uploaddir = "../img/team/";
	$filename = "../img/team/".$id.".jpg";
	$newwidth = 200;
	include "inhalte/einfoto.php";

	$sql1 = "SELECT * FROM Team WHERE ID = \"".$id."\" ";
	$result1 = $db->query($sql1);
	$nt1 = $result1->fetch_assoc();
	echo "<br />\n";
	echo "<form action=\"index.php?".$_SERVER['QUERY_STRING']."\" method=\"post\">\n";
	echo "<fieldset>\n";
	echo "	<legend>Teammitglied <i>".$nt1['Vorname']." ".$nt1['Nachname']."</i>:</legend>\n";
	echo "	<input type=\"hidden\" name=\"ID\" value=\"".$id."\" />\n";
	echo "	<label>Sichtbar</label>\n";
	echo "	<input type=\"radio\" name=\"Anzeige\" value=\"on\" ";
	if ("on" == $nt1['Anzeige']) {
		echo "checked=\"checked\" ";
	}
	echo "/>ja\n";
	echo "	<input type=\"radio\" name=\"Anzeige\" value=\"off\" ";
	if ("off" == $nt1['Anzeige']) {
		echo "checked=\"checked\" ";
	}
	echo "/>nein\n";
	echo "<img src=\"../img/help.gif\" title=\"Falls sichtbar wird der Mitarbeiter auf der Teamseite angezeigt!\" />\n";
	echo "	<br />\n";
	echo "	<label>Titel</label>\n";
	echo "	<input type=\"text\" name=\"Titel1\" value=\"".$nt1['Titel1']."\" />\n";
	echo "	<img src=\"../img/help.gif\" title=\"z.B. Dr., Dipl-Ing\" />\n";
	echo "	<br />\n";
	echo "	<label>Anrede</label>\n";
	echo "	<input type=\"text\" name=\"Anrede\" value=\"".$nt1['Anrede']."\" />\n";
	echo "	<br />\n";
	echo "	<label>Vorname</label>\n";
	echo "	<input type=\"text\" name=\"Vorname\" value=\"".$nt1['Vorname']."\" />\n";
	echo "	<br />\n";
	echo "	<label>Nachname</label>\n";
	echo "	<input type=\"text\" name=\"Nachname\" value=\"".$nt1['Nachname']."\" />\n";
	echo "	<br />\n";
	echo "	<label>Position</label>\n";
	echo "	<input type=\"text\" name=\"Titel2\" value=\"".$nt1['Titel2']."\" />\n";
	echo "	<img src=\"../img/help.gif\" title=\"Position bzw. Funktion im Unternehmen\" />\n";
	echo "	<br />\n";
	echo "	<label>Telefon</label>\n";
	echo "	<input type=\"text\" name=\"Telefon\" value=\"".$nt1['Telefon']."\" />\n";
	echo "	<br />\n";
	echo "	<label>Email</label>\n";
	echo "	<input type=\"text\" name=\"EMail\" value=\"".$nt1['EMail']."\" />\n";
	echo "	<br />\n";
	echo "	<label>Bereich</label>\n";
	echo "	<input type=\"text\" name=\"Bereich\" value=\"".$nt1['Bereich']."\" />\n";
	echo "	<br />\n";
	echo "	&nbsp;<br />\n";
	echo "	<input type=\"submit\" name=\"action\" value=\"Speichern\" />\n";
	if ("Anlegen" == $_POST['action']) {
		echo "	<input type=\"submit\" name=\"action\" value=\"Abbrechen\" />\n";
	} else {
		echo "	<input type=\"reset\" value=\"Rücksetzen\" />\n";
	}
	echo "</fieldset>\n";
	echo "</form>\n";

	
}
?>