<?
	//  Copyright (c) 2004-2006 randshop
	//  http://www.randshop.com
	//
	//  Unter Lizenz von randshop
	//	
	//	Letzte Bearbeitung: 09.04.2006

	session_start(); 

	// PHP-Includes
	include_once("../../config.inc.php");
	include_once("../../db.inc.php");
	include_once(DATEIPFAD . "includes/functions.kunden.inc.php");
	include_once(DATEIPFAD . "includes/functions.land.inc.php");
	include_once(DATEIPFAD . "includes/functions.mail.inc.php");
	include_once(DATEIPFAD . "includes/htmlMimeMail/htmlMimeMail.php");
	//include_once(DATEIPFAD . "includes/functions.artikel.inc.php");
	include_once(DATEIPFAD . "includes/functions.kategorie.inc.php");
	if(RECHNUNGSWESEN) {
		include_once(DATEIPFAD . "includes/functions.mod.bestellungen.inc.php");
	} else {
		include_once(DATEIPFAD . "includes/functions.bestellungen.inc.php");
	}
	include_once(DATEIPFAD . "includes/global.inc.php");
	include_once(DATEIPFAD . "includes/session_register.inc.php");
	include_once(DATEIPFAD . "includes/global_off.inc.php");
	include_once("../../includes/language/langu_" . $_SESSION["langu"] . ".inc.php");
	
	if (KUNDENGRUPPEN) {
		include_once(DATEIPFAD . "includes/functions.mod.kundengruppen.inc.php");
	} else {
		include_once(DATEIPFAD . "includes/functions.kundengruppen.inc.php");
	}

	if (ARTIKELDOWNLOAD) {
		include_once(DATEIPFAD . "includes/functions.mod.download.inc.php");
	}

	// Action ermitteln
	if ($_POST["action"]) { $Action = $_POST["action"]; };
	if ($_GET["action"]) { $Action = $_GET["action"]; };

	// Ursprung ermitteln
	if ($_POST["location"]) { $Location = $_POST["location"]; };
	if ($_GET["location"]) { $Location = $_GET["location"]; };

	// Source
	if ($_POST["sourceid"]) { $tpl_sourceid = $_POST["sourceid"]; };
	if ($_GET["sourceid"]) { $tpl_sourceid = $_GET["sourceid"]; };

	if (!$tpl_sourceid) {
		$tpl_sourceid = 1;
	}
	
	//Wenn falsche Action
	if($Action != "registrieren" || $Action != "passwortvergessen" || $Action != "kundenseite" || $Action != "passwortaendern" || $Action != "lieferadresse" || $Action != "grunddaten" || $Action != "bestellungen" || $Action != "bestellungdetail" || $Action != "artikeldownload") {
	include(DATEIPFAD . "themes/user/grunddaten.inc.php");
}


	// ********************************************************************************
	// ** Login
	// ********************************************************************************
	if ($_POST["formaction"] == "login") {
		
		// Kunde einlesen
		$KundenLoginArray = SetKundenLogin($_POST["email"], $_POST["passwort"]);

		// Fehler ausgeben
		if ($KundenLoginArray["login_msg"] != "") {

			$FormError = true;
			$FormErrorMessage = $KundenLoginArray["login_msg"];
			
		
		}

		// Kundendaten speichern
		if (!$FormError) {

			// Session registrieren			
			$_SESSION['com'] = "true";
			$_SESSION['mail'] = $email;

			// Umleitung auf die Ursprungseite
			if ($Location == "warenkorb") {
				header("Location: " . URLPFAD . "themes/bestellen/index.php?formaction=s0");
			} elseif ($Location == "wunschzettel") {
				header("Location: " . URLPFAD . "themes/wunschzettel/index.php");
			} elseif ($Location == "grunddaten") {
				header("Location: " . URLPFAD . "themes/user/index.php?action=grunddaten");
			} else {
				
				if ($_POST["sourceid"]) {
					header("Location: " . URLPFAD . $SourceArray[$_POST["sourceid"]]);
				} else {				
					header("Location: " . URLPFAD . "index.php");
				}
				
			}
			exit;

		}

	}


	$abfrageTemp = "SELECT * FROM " . TABLE_TEMPLATES . " where aktiv = '1'"; 
	$ergebnisTemp = mysql_query($abfrageTemp);
	$rowTemp = mysql_fetch_object($ergebnisTemp);


	// ********************************************************************************
	// ** Aktionen auswerten
	// ********************************************************************************

	// noch nicht angemeldet
	if ($_SESSION["com"] == "false") {
		
		// Passwort vergessen	
		if ($Action == "passwortvergessen") {
			include(DATEIPFAD . "themes/user/passwortvergessen.inc.php");
		// Registrieren	
		} elseif ($Action == "registrieren") {
			include(DATEIPFAD . "themes/user/registrieren.inc.php");
		// Login
		} else {
			if ($FormError) {
				$logHeadline = $s_k_headline_loginfehler;
				$logText = $s_k_msg_loginfehler;
				$contentFile = DATEIPFAD . "templates/" . $rowTemp->name . "/user/login.tpl";
			// normales Login-Template
			} else {
				$logHeadline = $s_k_headline_registrierung;
				$logText = $s_k_msg_registrierung;
				$contentFile = DATEIPFAD . "templates/" . $rowTemp->name . "/user/login.tpl";
			}
		}
		
	}
	
	// angemeldet, aber keine Aktion ausgewählt
	if (($_SESSION["com"] == "true") && ($Action == "")) {
		$Action = "grunddaten"; 
	}
	
	// Passwort ändern
	if (($Action == "kundenseite") && ($_SESSION["com"] == "true")) {
		$contentFile = DATEIPFAD . "templates/" . $rowTemp->name . "/user/kundenseite.tpl";
	}


	// Passwort ändern
	if (($Action == "passwortaendern") && ($_SESSION["com"] == "true")) {
		include(DATEIPFAD . "themes/user/passwortaendern.inc.php");
	}

	// Lieferadresse
	if (($Action == "lieferadresse") && ($_SESSION["com"] == "true")) {
		include(DATEIPFAD . "themes/user/lieferadresse.inc.php");
	}

	// Grunddaten
	if (($Action == "grunddaten") && ($_SESSION["com"] == "true")) {
		include(DATEIPFAD . "themes/user/grunddaten.inc.php");
	}

	// Bestelluebersicht anzeigen
	if (($Action == "bestellungen") && ($_SESSION["com"] == "true")) {
		include(DATEIPFAD . "themes/user/bestelluebersicht.inc.php");
	}
		
	// Bestelldetail anzeigen
	if (($Action == "bestellungdetail") && ($_SESSION["com"] == "true")) {
		include(DATEIPFAD . "themes/user/bestelldetail.inc.php");
	}

	// Artikeldownload anzeigen
	if (($Action == "artikeldownload") && ($_SESSION["com"] == "true")) {
		include(DATEIPFAD . "themes/user/artikeldownload.inc.php");
	}
	
	// Header
	include(DATEIPFAD . "includes/header.inc.php");

	// Letzte globale Zusammenfassung z.B. fuer Warenkorbanzeige, bevor das Template geladen wird.
	include(DATEIPFAD . "includes/footer.inc.php");
	
	
	// Template
	include(DATEIPFAD . "templates/" . $rowTemp->name . "/index.tpl");
	
	@mysql_close($db);

?>
