<?php
error_reporting(E_ERROR | E_WARNING);
session_start();
if (isset($_SESSION['Firma']['ID']))
{
	define('PREFIX', $_SESSION['Firma']['ID']);
	define('GUELTIG', $_SESSION['Firma']['A_Bis']);
	define('ZAHLBAR', $_SESSION['Firma']['Z_Bis']);
}
if ('Test' == PREFIX)
{
	exit();
}
include "inc/config.php"; // die Konfigurationsdateien lesen
require_once(__DIR__ . '/vendor/autoload.php');

ini_set('session.gc_maxlifetime', 7200);
// Verbindung zu MySQL Aufbauen
$db = @new MySQLi(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DATABASE);
$db->set_charset('utf8');
if (mysqli_connect_errno())
{
	die('Konnte keine Verbindung zu Datenbank aufbauen, MySQL meldete: ' . mysqli_connect_error());
}

if (isset($_POST['formaction']))
{
	if ("view" == $_POST['formaction'])
	{
		if (isset($_POST['from']))
		{
			$from = "&from=" . $_POST['from'];
		}
		else
		{
			$from = "";
		}
		if ("lv" == $_GET['section'])
		{
			include "pdf/lv_pdf.php";
			header('Location: index.php?section=lv&pdf=LV_' . $nt['Jahr'] . '_' . $nt['ID'] . $from);
		}
		elseif ("angebot" == $_GET['section'])
		{
			include "pdf/ang_pdf.php";
			header('Location: index.php?section=angebot&pdf=A_' . $nt['Jahr'] . '_' . $nt['ID'] . $from);
		}
		elseif ("bestaet" == $_GET['section'])
		{
			include "pdf/best_pdf.php";
			header('Location: index.php?section=bestaet&pdf=B_' . $nt['Jahr'] . '_' . $nt['ID'] . $from);
		}
		elseif ("rechnung" == $_GET['section'])
		{
			include "pdf/rech_pdf.php";
			header('Location: index.php?section=rechnung&pdf=R_' . $nt['Jahr'] . '_' . $nt['ID'] . $from);
		}
		elseif ("liefer" == $_GET['section'])
		{
			include "pdf/liefer_pdf.php";
			header('Location: index.php?section=liefer&pdf=L_' . $nt['Jahr'] . '_' . $nt['ID'] . $from);
		}
		elseif ("gut" == $_GET['section'])
		{
			include "pdf/gut_pdf.php";
			header('Location: index.php?section=gut&pdf=G_' . $nt['Jahr'] . '_' . $nt['ID'] . $from);
		}
		elseif ("oposten" == $_GET['section'])
		{
			if (!isset($_POST['mahnung']))
			{
				include "pdf/opost_pdf.php";
				header('Location: index.php?section=oposten&pdf=O_' . date('Ymd'));
			}
			else
			{
				if ("1" == $_POST['mahnung'])
				{
					include "pdf/mahn1_pdf.php";
					header('Location: index.php?section=oposten&pdf=M1_' . $nt['Jahr'] . '_' . $nt['ID']);
				}
				else
				{
					include "pdf/mahn2_pdf.php";
					header('Location: index.php?section=oposten&pdf=M2_' . $nt['Jahr'] . '_' . $nt['ID']);
				}
			}
		}
		elseif ("tracking" == $_GET['section'])
		{
			include "pdf/track_pdf.php";
			header('Location: index.php?section=tracking&pdf=T_' . date('Ymd'));
		}
		elseif ("eur" == $_GET['section'])
		{
			if ("aus_ist" == $_POST['type'])
			{
				include "pdf/ausist_pdf.php";
				header('Location: index.php?section=eur&pdf=A_' . date('Ymd'));
			}
			elseif ("aus_soll" == $_POST['type'])
			{
				include "pdf/aussoll_pdf.php";
				header('Location: index.php?section=eur&pdf=A_' . date('Ymd'));
			}
			elseif ("ein_ist" == $_POST['type'])
			{
				include "pdf/einist_pdf.php";
				header('Location: index.php?section=eur&pdf=E_' . date('Ymd'));
			}
			elseif ("ein_soll" == $_POST['type'])
			{
				include "pdf/einsoll_pdf.php";
				header('Location: index.php?section=eur&pdf=E_' . date('Ymd'));
			}
		}
		elseif ("schrift" == $_GET['section'])
		{
			include "pdf/schrift_pdf.php";
			header('Location: index.php?section=schrift&pdf=S_' . $nt['File_Name']);
		}
		elseif ("kontakt" == $_GET['section'])
		{
			include "pdf/kontakt_pdf.php";
			header('Location: index.php?section=kontakt&pdf=K_' . $nt['ID']);
		}
	}
	elseif ("email" == $_POST['formaction'])
	{
		if ("lv" == $_GET['section'])
		{
			include "pdf/lv_pdf.php";
		}
		elseif ("angebot" == $_GET['section'])
		{
			include "pdf/ang_pdf.php";
		}
		elseif ("bestaet" == $_GET['section'])
		{
			include "pdf/best_pdf.php";
		}
		elseif ("rechnung" == $_GET['section'])
		{
			include "pdf/rech_pdf.php";
		}
		elseif ("liefer" == $_GET['section'])
		{
			include "pdf/liefer_pdf.php";
		}
		elseif ("gut" == $_GET['section'])
		{
			include "pdf/gut_pdf.php";
		}
		elseif ("schrift" == $_GET['section'])
		{
			include "pdf/schrift_pdf.php";
		}
	}

}
echo "<!DOCTYPE html>";
echo "<html>\n";
echo "	<head>\n";
echo "		<title>R!ST - start-up!</title>\n";
echo "		<link rel=\"stylesheet\" media=\"all\" type=\"text/css\" href=\"css/page.css\" />\n";
echo "<!--[if lte IE 7]>\n";
echo "		<link rel=\"stylesheet\" href=\"css/ie6.css\" type=\"text/css\" />\n";
echo "<![endif]-->\n";
echo "		<meta name=\"description\" content=\"RIST - CS medien- und kommunikationssysteme\" /> \n";
echo "		<meta name=\"keywords\" content=\"RIST\" /> \n";
echo "		<meta name=\"Generator\" content=\"RIST (C) 2010. All rights reserved.\" /> \n";
echo "		<meta name=\"robots\" content=\"index, follow\" /> \n";
echo "		<link rel=\"shortcut icon\" href=\"favicon.ico\" /> \n";
echo "		<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /> \n";
echo "		<meta http-equiv=\"expires\" content=\"0\">\n";
echo "		<meta http-equiv=\"cache-control\" content=\"no-cache\">\n";
echo "		<meta http-equiv=\"pragma\" content=\"no-cache\">\n";
echo "		<script type=\"text/javascript\">\n";
?>
	var sv = '<?php echo $arr_suContent['dropbox']['sv']; ?>';
	var vt = '<?php echo $arr_suContent['dropbox']['vt']; ?>';
	var st = '<?php echo $arr_suContent['dropbox']['st']; ?>';
	var ie = '<?php echo $arr_suContent['dropbox']['ie']; ?>';
	function show_tooltip (section)
	{
	document.getElementById('tooltip').style.border = "2px solid black";
	document.getElementById('tooltip').style.padding = "10px";
	document.getElementById('tooltip').style.margin = "0px 50px";
	document.getElementById('tooltip').style.display = "block";
	document.getElementById('tooltip').style.position = "absolute";
	document.getElementById('tooltip').style.opacity = "0.9";
	document.getElementById('tooltip').style.visibility = "visible";
	document.getElementById('tooltip').style.background = "#FFFFFF";
	document.getElementById('tooltip').innerHTML = section;
	document.getElementById('inhalt').style.opacity = "0.1";
	}
	function hide_tooltip ()
	{
	document.getElementById('tooltip').style.display = "none";
	document.getElementById('tooltip').style.visibility = "hidden";
	document.getElementById('inhalt').style.opacity = "1";
	}
<?php
echo "		</script>\n";
if (("schrift" == $_GET['section']) OR ("stamm" == $_GET['section']) OR ("texte" == $_GET['section']))
{
	echo "		<script type=\"text/javascript\" src=\"ckeditor/ckeditor.js\"></script>\n";
}
echo "	</head>\n";

echo "	<body>\n";
echo "		<div id=\"frame\">\n";
echo "				<div id=\"header\">\n";
include "inhalte/header.php";
echo "				</div>\n";
echo "				<br class=\"fix\" />\n";
echo "			<div id=\"links\">\n";
include "inhalte/left.php";
echo "				<br class=\"fix\" />\n";
echo "			</div>\n";
echo "			<div id=\"navi2\">\n";
include "inhalte/navi2.php";
echo "				<br class=\"fix\" />\n";
echo "			</div>\n";
echo "			<div id=\"page\">\n";
echo "				<hr />\n";
echo "				<div id=\"tooltip\">\n";
echo "				</div>\n";
echo "				<div id=\"inhalt\">\n";
include "inhalte/inhalt.php";
echo "				</div>\n";
echo "				<br class=\"fix\" />\n";
echo "			</div>\n";
echo "		</div>\n";
echo "				<div id=\"footer\">\n";
include "inhalte/footer.php";
echo "				</div>\n";
echo "	</body>\n";
echo "</html>\n";