<?php

if($_GET["shopid"]) {
    $sessionID = $_GET['shopid'];
    session_id($sessionID);
}

	session_start();

	// SourceID = 7

	// PHP-Includes
	include_once("../../conf/config.inc.php");
	include_once(DATEIPFAD . "conf/db.inc.php");
	include_once(DATEIPFAD . "includes/shopinitialize.inc.php");
	include_once(DATEIPFAD . "includes/functions.warenkorb.inc.php");
	include_once(DATEIPFAD . "includes/functions.shopeinstellung.inc.php");
	include_once(DATEIPFAD . "includes/functions.kunden.inc.php");
	include_once(DATEIPFAD . "includes/functions.artikel.inc.php");
	include_once(DATEIPFAD . "includes/session_register.inc.php");
	include_once(DATEIPFAD . "includes/functions.global.inc.php");

    if(RECHNUNGSWESEN) {
        include_once(DATEIPFAD . "includes/functions.mod.bestellungen.inc.php");
    } else {
        include_once(DATEIPFAD . "includes/functions.bestellungen.inc.php");
    }

	// Spracheninclude
	if (@fopen(DATEIPFAD . "includes/language/langu_" . $_SESSION["languageisocode"] . ".inc.php",r)) {
		include_once(DATEIPFAD . "includes/language/langu_" . $_SESSION["languageisocode"] . ".inc.php");
	} else {
		include_once(DATEIPFAD . "includes/language/langu_de.inc.php");
	}	
	
	//if ($_POST["warenkorbid"]) { $WarenkorbID = $_POST["warenkorbid"]; };
	//if ($_GET["warenkorbid"]) { $WarenkorbID = $_GET["warenkorbid"]; };
	
	if (isset($_POST["warenkorbid"]) && (is_numeric($_POST["warenkorbid"]))) { $WarenkorbID = $_POST["warenkorbid"]; } else  
	if (isset($_GET["warenkorbid"]) && (is_numeric($_GET["warenkorbid"]))) { $WarenkorbID = $_GET["warenkorbid"]; } else { $WarenkorbID = 0; }
	

	if ($_POST["menge"]) { $Menge = $_POST["menge"]; };
	if ($_GET["menge"]) { $Menge = $_GET["menge"]; };
	
	unset($_SESSION["gutscheincode"]);

	unset($_SESSION["gast_mail"]);
	
	// ********************************************************************************
	// ** Aktionen auswerten
	// ********************************************************************************

	// 	Artikel hinzufügen
    if ($FormAction == "session_reset") {
    
        unset($_SESSION["cs_referer"]);
        
    } elseif ($FormAction == "speichern") {
		AddWarenkorb($ArtikelID, $_POST["menge"], $_POST["variante1"], $_POST["variante2"], $_POST["variante3"], $_POST["variante4"], $_SESSION["mail"], $_SESSION["sessionId"],"","",$_SESSION["languageid"],$_POST['refertype'], $_POST['referid']);
        $_SESSION["cs_referer"] = $_SERVER["HTTP_REFERER"];
		header("Location: " . URLPFAD . "themes/warenkorb/index.php");
	
	// 	Warenkorbeintrag l�schen
	} elseif ($FormAction == "loeschen") {
		DeleteWarenkorb($WarenkorbID, "", true);
		
	// 	Warenkorbeintrag �ndern
	} elseif ($FormAction == "aendern") {
		
		if (is_numeric($Menge) && ($Menge > 0)) {
			ChangeWarenkorb($WarenkorbID, $Menge, true, $_SESSION["mail"]);
		} elseif ((is_numeric($Menge) && ($Menge <= 0)) || ($Menge == 0)) {
			DeleteWarenkorb($WarenkorbID, "", true);
		}
		
	}

    if ($FormAction == "saveshirt") {
        AddShirtWarenkorb();
        header("Location: " . URLPFAD . "/themes/warenkorb/index.php");
    }

//	echo "<pre>";
//	var_dump($_SESSION);
//	echo "</pre>";
	
	// Header
	include_once(DATEIPFAD . "includes/header.inc.php");

	// ********************************************************************************
	// ** Warenkorb einlesen
	// ********************************************************************************
	
	$tpl_warenkorbdataarray = GetWarenkorbDataArray($_SESSION["sessionId"], $_SESSION["mail"]);
	
	$tpl_refertype = VERWEIS_QUELLE_WARENKORB;

    //var_dump($tpl_warenkorbdataarray["warenkorbarray"]);

	// Warenkorb ausgeben
	if (!empty($tpl_warenkorbdataarray["warenkorbarray"])) {
        if($mobilestyle) {
            $contentFile = DATEIPFAD . "templates/" . $rowTemp->name . "/mobile/warenkorb.phtml";
        } else {
            $contentFile = DATEIPFAD . "templates/" . $rowTemp->name . "/website/warenkorb/warenkorb.tpl";
        }
	// leere Warenkorb
	} else {
		$contentFile = DATEIPFAD . "templates/" . $rowTemp->name . "/website/warenkorb/warenkorb_leer.tpl";
		
	}

	// Letzte globale Zusammenfassung z.B. fuer Warenkorbanzeige, bevor das Template geladen wird.
	include_once(DATEIPFAD . "includes/footer.inc.php");

	// Template
    if($mobilestyle) {
        include_once(DATEIPFAD . "templates/" . $rowTemp->name . "/mobile/layout.phtml");
    } else {
        include_once(DATEIPFAD . "templates/" . $rowTemp->name . "/website/index.tpl");
    }
		
	@mysql_close($db);

?>
