<?php
if ("settings" == $_POST['action'])
{
	$sql = 'UPDATE ' . PREFIX . '_Schrift SET
		Kontakt_ID	= "' . $_POST['Kontakt_ID'] . '",
		Admin_ID	= "' . $_POST['Admin_ID'] . '"
	WHERE
		(Jahr 		= "' . $Jahr . '"
	AND
		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);
	}
}

$sql = "SELECT * FROM " . PREFIX . "_Schrift WHERE (Jahr = \"" . $Jahr . "\" AND ID = \"" . $ID . "\");";
$result = $db->query($sql);
$nt = $result->fetch_assoc();

$sqlkn = "SELECT * FROM " . PREFIX . "_Kontakte ORDER BY Nachname ASC, Firma ASC";
$resultkn = $db->query($sqlkn);
$sqlan = "SELECT ID, Vorname, Nachname FROM Admin WHERE Firma_ID = \"" . PREFIX . "\" ORDER BY ID ASC";
$resultan = $db->query($sqlan);

include __DIR__ . "/settings.php";
?>
<form action="index.php?<?php echo $_SERVER['QUERY_STRING']; ?>" method="post">
	<label>Betreff</label>
	<br/>
	<input type="text" name="Betreff" value="<?php echo $nt['Betreff']; ?>"/>
	<br class="fix"/>&nbsp;<br/>
	<textarea name="editor1"><?php echo $nt['Text']; ?></textarea>
	<br class="fix"/>
	<script type="text/javascript">
		CKEDITOR.replace('editor1',
			{
				toolbar: [
					['tokens_schrift'],
					['Bold', 'Italic'],
					['Cut', 'Copy', 'Paste', '-', '-', 'Scayt'],
					['Undo', 'Redo', '-', 'Find', 'Replace', '-', 'SelectAll', 'RemoveFormat']
				],
				extraPlugins: 'tokens_schrift'
			}
		);
	</script>
	<input type="hidden" name="ID" value="<?php echo $Jahr . "_" . $ID; ?>"/>
	<input type="submit" class="button_save" name="formaction" value="save"/>
</form>
<br class="fix"/>