<?php

/**
 * 
 * Copyright (C) Die Randgruppe GmbH
 * 
 * http://www.randshop.com
 * http://www.dierandgruppe.com
 * 
 * Unter der Lizenz von Die Randgruppe GmbH:
 * http://www.randshop.com/Lizenz
 *  
 * $Author$
 * $Date$
 * $Revision$
 * 
 */

	session_start();

	// SourceID = 6

	// PHP-Includes
    if (!$SEOCall) {
    	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.artikel.inc.php");
	include_once(DATEIPFAD . "includes/functions.shopeinstellung.inc.php");
	include_once(DATEIPFAD . "includes/session_register.inc.php");
	include_once(DATEIPFAD . "includes/functions.global.inc.php");
	include_once(DATEIPFAD . "includes/functions.statistik.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");
	}	

    unset($_SESSION['artikelliste_shop']['kategorieid']);
	
	// HerstellerID
	if ($_POST["herstellerid"]) { $_SESSION["herstellerid"] = $_POST["herstellerid"]; };
	if ($_GET["herstellerid"]) { $_SESSION["herstellerid"] = $_GET["herstellerid"]; };
	$HerstellerID = $_SESSION["herstellerid"];
	
	if($_GET["unsetDataOffset"]) {
		$DataOffset = 0;
	} 

	// Header
	include_once(DATEIPFAD . "includes/header.inc.php");
	
	// Standardeinstellungen
	if (!$SearchField) { $SearchField = TABLE_ARTIKEL . ".hersteller_id"; };
	if (!$SearchString) { $SearchString = $HerstellerID; };
	if (!$DataOffset) { $DataOffset = 0; };
	if (!$DataCount) { $DataCount = $wievielEintraege; };
	if (!$SortField) { $SortField = TABLE_ARTIKEL . ".artikel_nr"; };
	if (!$SortOrder) { $SortOrder = "asc"; };

	// Artikelanzahl in der Kategorie ermitteln
	$ArtikelAnzahl = GetArtikelAnzahl($SearchField, $SearchString, "", $HerstellerID, "", "", "", 1, 1);
	
	// hersteller einlesen
    $HerstellerObject = GetHerstellerDetail($HerstellerID, $_SESSION['languageid']);
	
	$tpl_refertype = VERWEIS_QUELLE_HERSTELLER;
	$tpl_referid = $HerstellerID;
	
	// ********************************************************************************
	// ** Artikel�bersicht
	// ********************************************************************************
	if ($ArtikelAnzahl > 0) {

		// ********************************************************************************
		// ** Lieferstatus anzeigen
		// ********************************************************************************
	
		// Shopeinstellungen einlesen
		$FeatureObject = GetFeatureDetail();
		$tpl_showstatus = $FeatureObject->statusanzeige;
		$tpl_source = 6;
	
	
		// ********************************************************************************
		// ** Hersteller
		// ********************************************************************************
	
		$tpl_kategoriepfad = $HerstellerObject->name;
		
        $shopeinstellungenObject = GetShopeinstellungDetail();
		
        if ($shopeinstellungenObject->fck_aktiv) {
            $tpl_hersteller_beschreibung = $HerstellerObject->beschreibung;
        } else {
            $tpl_hersteller_beschreibung = nl2br($HerstellerObject->beschreibung);
        }
	
	
		// ********************************************************************************
		// ** Artikeldaten ausgeben
		// ********************************************************************************

        // Sortierung
        $ArtikelSortField = $Einstellungen->artikel_sortierung->sortieren_nach;
        $ArtikelSortOrder = $Einstellungen->artikel_sortierung->absteigend ? 'DESC' : 'ASC';
		
		// Artikel einlesen
		$tpl_artikelarray = GetArtikelDataArray("", "", $ArtikelSortField, $ArtikelSortOrder, $DataOffset, $DataCount, $_SESSION["mail"], $SearchString, "", "", "", "", 1, 1, "", "", 1, 0, 0, $_SESSION["languageid"]);
		
        foreach ($tpl_artikelarray as $Artikel) {
            $HerstellerArtikelIDArray[] = $Artikel['id'];
        }
        
        $SEOURLArray = GetSEOURLArray($HerstellerArtikelIDArray, SEOURL_TYPE_ARTIKEL, $_SESSION["languageid"], $SEOURLArray);
        
		// Daten f�r die Ausgabe aufbereiten
		foreach ($tpl_artikelarray as $tpl_artikel_key => $tpl_artikel) {
			
			
			// Beschreibungskurzausgabe
			if($tpl_artikel["kurz_beschreibung"]) {
				$tpl_artikelarray[$tpl_artikel_key]["beschreibungs_ausgabe"] = $tpl_artikel["kurz_beschreibung"];
			} else {
				$tpl_artikelarray[$tpl_artikel_key]["beschreibungs_ausgabe"] = $tpl_artikel["beschreibung_kurz"];
			}
			
			
			// ID einer Merkmalkombination
            $tpl_artikelarray[$tpl_artikel_key]["hauptartikel_id"] = $tpl_artikel["id"];
			if ($tpl_artikel["merkmalkombination"]) {
				$tpl_artikelarray[$tpl_artikel_key]["id"] = $tpl_artikel["merkmalkombination"];
			}
			
			// Bestellbutton
			if($tpl_artikel["verkaufstop"] == 1 && $tpl_artikel["lager"] < 1 ) {
				$tpl_artikelarray[$tpl_artikel_key]["bestellbutton"] = "verkaufstop";
			} else {
				if ($tpl_artikel["voe_datum_format"]) {
					$tpl_artikelarray[$tpl_artikel_key]["bestellbutton"] = $lang_vorbestellen;
				} else {
					$tpl_artikelarray[$tpl_artikel_key]["bestellbutton"] = $s_kaufen;
				}
			}

            // Varianten
            if (!$tpl_artikel["merkmalkombination"]	&& !$tpl_artikel["merkmalkombinationparentid"]) {
                $tpl_artikelarray[$tpl_artikel_key]["formstart_artikel"] = "<form name=\"form_artikel" . $tpl_artikel["id"] . "\" method=\"post\" action=\"" . URLPFAD . "themes/warenkorb/index.php\">";
            }

            if ($tpl_artikelarray[$tpl_artikel_key]["varianten_array"]) {

                foreach ($tpl_artikelarray[$tpl_artikel_key]["varianten_array"] as $VariantenKey => $VariantenArray) {

                    if ($tpl_artikelarray[$tpl_artikel_key]["merkmalkombination"] || $tpl_artikelarray[$tpl_artikel_key]["merkmalkombinationparentid"]) {
                        $tpl_artikelarray[$tpl_artikel_key]["variante" . $VariantenKey . "_string"] = "<select name=\"variante" . $VariantenKey . "\" class=\"variantenForm\" onchange=\"window.location.href = '" . URLPFAD . "themes/kategorie/detail.php?artikelid=" . $tpl_artikelarray[$tpl_artikel_key]["id"] . "&variante" . $VariantenKey ."='+this.value;\">";
                    } else {
                        $tpl_artikelarray[$tpl_artikel_key]["variante" . $VariantenKey . "_string"] = "<select name=\"variante" . $VariantenKey . "\">";
                    }

                    foreach ($VariantenArray as $MerkmalData) {

                        $tpl_artikelarray[$tpl_artikel_key]["variante" . $VariantenKey . "_string"] .= "<option value=\"" . $MerkmalData["merkmalid"] . "\">" . $MerkmalData["merkmalname"] . "</option>";

                    }

                    $tpl_artikelarray[$tpl_artikel_key]["variante" . $VariantenKey . "_string"] .= "</select>";
                }

            }

            if ($tpl_artikel["merkmalkombination"] || $tpl_artikel["merkmalkombinationparentid"]) {
                $tpl_artikelarray[$tpl_artikel_key]["formstart_merkmalkombination"] = "<form name=\"form_artikel" . $tpl_artikel["merkmalkombination"] . "\" method=\"post\" action=\"" . URLPFAD . "themes/warenkorb/index.php\">";
            }

            if($tpl_gebindepreise_aktiv && $tpl_artikel['einheit_groesse'])
            {
                $tpl_artikelarray[$tpl_artikel_key]['gebindepreis_string'] = '(' . $lang_gebindepreis . ' ' . $tpl_gebinde[$tpl_artikel['einheit_masseinheit']] . $tpl_artikel['einheit_masseinheit'] . ' = ' . number_format($tpl_artikel['preis'] * $tpl_gebinde[$tpl_artikel['einheit_masseinheit']] / $tpl_artikel['einheit_groesse'], 2, ',', '.') . ' ' . $WaehrungObject->symbol . ')';
            }

		}
	
        $SeitenNaviArray = SeitenNavigation(NAVIGATION_TYPE_HERSTELLER, $SEOURLArray, $ArtikelAnzahl, $DataOffset, $DataCount, $HerstellerID);
		
		// Template
		$contentFile = DATEIPFAD . "templates/" . $rowTemp->name . "/website/artikel/artikeluebersicht.tpl";
		
	// ********************************************************************************
	// ** keine Artikel und keine Kategorien
	// ********************************************************************************
	} else {

		// ********************************************************************************
		// ** Hersteller
		// ********************************************************************************

		$tpl_kategoriepfad = $HerstellerObject->name;

		// Template
		$contentFile = DATEIPFAD . "templates/" . $rowTemp->name . "/website/artikel/keinergebnis.tpl";

	}
	

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

	// Template
	include_once(DATEIPFAD . "templates/" . $rowTemp->name . "/website/index.tpl");
	
	@mysql_close($db);
	
?>