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


	session_start();

	// Hauptkonfigurationsdatei
	include_once("../../conf/config.inc.php");
	include_once(DATEIPFAD . "conf/db.inc.php");
	include_once(DATEIPFAD . "includes/shopinitialize.inc.php");
	if(KUNDENGRUPPEN) {
		include_once(DATEIPFAD . "includes/functions.mod.kundengruppen.inc.php");
	} else {
		include_once(DATEIPFAD . "includes/functions.kundengruppen.inc.php");
	}
	include_once(DATEIPFAD . "includes/functions.artikel.inc.php");
  include_once(DATEIPFAD . "includes/functions.merkmale.inc.php");
	include_once(DATEIPFAD . "includes/functions.kategorie.inc.php");
	//Sessionregister
	include_once(DATEIPFAD . "includes/session_register.inc.php");
	include_once(DATEIPFAD . "includes/functions.global.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($katId == "")
{
	$_SESSION['kat'] = "";
}
	// Header
	include_once(DATEIPFAD . "includes/header.inc.php");
	
if(!$_GET["menueId"]) {
	$_GET["menueId"] = $_POST["menueId"];
}

if($_GET["vonEg"]) { $vonEg = $_GET["vonEg"]; }

$tpl_menueId = $_GET["menueId"];

$GetMenueObject = GetMenueDetails($_GET["menueId"], $_SESSION["languageid"]);

// Abfrage nach Online Status
if($GetMenueObject->aktiv == "1") {

$tpl_topnaviName = $GetMenueObject->headline;
if($GetMenueObject->bigImage != "") {
	if(file_exists("../../images/dbimages/" . $GetMenueObject->bigImage)) 	{
		$imageSize = getimagesize("../../images/dbimages/" . $GetMenueObject->bigImage);
		$tpl_topImage =  "<img src=\"../../images/dbimages/" . $GetMenueObject->bigImage . "\" width=\"" . $imageSize[0] . "\" height=\"" . $imageSize[1] . "\" border=\"0\" align=\"left\" />\n";
	}
}

        $shopeinstellungenObject = GetShopeinstellungDetail();

        if ($shopeinstellungenObject->fck_aktiv) {
            $tpl_topEintrag = stripslashes($GetMenueObject->textEintrag) . "<br /><br />\n";
        } else {
            $tpl_topEintrag = nl2br(stripslashes($GetMenueObject->textEintrag)) . "<br /><br />\n";
        }   
	
if($_GET["dat"] == "update") {
	
	include_once(DATEIPFAD . "data/spamfilter.txt.php");
	
	$badwordfound = false;
   
  //Durchsuchen nach Bad-Words
	if($BadWords) { 
		foreach($BadWords as $BadWord){
	  	if(stristr(str_replace("'", "\"", htmlspecialchars($_POST["text"])),$BadWord)){
	    	$BadFound = true;
	   	}
	  }
	}
      
  //Durchsuchen nach Bad-Emails
  if($BadEmails) {
  	foreach($BadEmails as $BadEmail){
    	if(stristr(str_replace("'", "\"", htmlspecialchars($_POST["email"])),$BadEmail)){
      	$BadFound = true;
      }
   	}
  }
      
  //Wenn keine Bad-Words oder aehnliches gefunden(badfound==false)->eintragen
  if(!$BadFound){
  	if(($_POST["autor"] =="") || ($_POST["text"] ==""))  {
			$_GET["act"] = "eintragen";
  		$tpl_formFehlerText = $u_sternFelder;
  	} else {
  		$datum = date("Y-m-d H:i:s"); #aktuelles Datum
    	$eintrag = "INSERT INTO " . TABLE_GAESTEBUCH . " (datum, autor, text, email) VALUES ('".$datum."', '".$_POST["autor"]."', '".$_POST["text"]."', '".$_POST["email"]."')";
    	$eintragen = errorlogged_mysql_query($eintrag);
  	}
  } else {
    $_GET["act"] = "eintragen";
    $tpl_formFehlerText = "Tut uns leid, unser Spam-Filter verhinderte die Eintragung Ihrer Nachricht.\n";
  }

}
 



if((!$_GET["act"]) || (!$_POST["act"])) {



if (!$_GET["vonEg"]) {
	$_GET["vonEg"] = "0";
}




	
$abfrage = "SELECT * FROM " . TABLE_GAESTEBUCH . " ORDER BY datum DESC LIMIT " . $_GET["vonEg"] .", ". $wievielEintraege .""; #DESC sortiert anders rum
#Um das Ergebnis ausfuehren zu koennen, wird errorlogged_mysql_query verwendet
$ergebnis = errorlogged_mysql_query($abfrage);
#Zur &Uuml;bernahme der Datens&auml;tze wird der Befehl mysql_fetch_array verwendet
while($row = mysql_fetch_object($ergebnis)) {
	
	$datum = $row->datum; #Datum in eine Variable
	list ($jahr, $monat, $tag, $stunde, $min, $sec) = preg_split ('/[-: ]/', $datum);
	$datumsAusgabe = $tag . "." . $monat . "." . $jahr;
	
	if($row->email != "") {
		$_email = "<a href=\"mailto:" . $row->email . "\">" . $row->autor . "</a>\n";
	}
	else {
		$_email = $row->autor . "\n";
	}
	$gbText = nl2br($row->text) . "\n";
	
	$gaestebuchAusgabe[] = array('datumsAusgabe'=>$datumsAusgabe,
															'e_mail'=>$_email,
															'gbText'=>$gbText);
	
	
} // End While

/************************************************************************************
									hier wird der Zurueckbutton geschrieben
************************************************************************************/

$zurueck = $vonEg - $wievielEintraege;
if (($zurueck == "-" . $wievielEintraege) || ($zurueck <= "-" . $wievielEintraege)) {
	#echo "geht nicht weiter zurueck";
} else {
$zurueckLink = "<a href='index.php?vonEg=$zurueck&wievielEintraege=$wievielEintraege&menueId=".$tpl_menueId."'>&lt;&lt; " . $lang_zurueck . "</a>";
}	


/************************************************************************************
									hier wird der Weiterbutton geschrieben
************************************************************************************/

$von = $vonEg + $wievielEintraege;
# leerkontrolle zaehlt die Eintraege ab, die in der Datenbank sind
$leerkontrolle = "SELECT count(*) as anzahl FROM " . TABLE_GAESTEBUCH . "";
$wasdrin = errorlogged_mysql_query($leerkontrolle);
$anzahl = mysql_fetch_object($wasdrin);
# wenn anzahl < von ist, dann gibt's keine weiteren Eintaege mehr.
if ($anzahl->anzahl <= $von) {
	#echo "geht nich weiter vor";
} else {
$vorLink = "<a href='index.php?vonEg=$von&wievielEintraege=$wievielEintraege&menueId=".$tpl_menueId."'>" . $lang_aeltere_eintraege . " &gt;&gt;</a>";
}	


$contentFile = DATEIPFAD . "templates/" . $rowTemp->name . "/website/gaestebuch/ausgabe.tpl";

}
//--->

if($_GET["act"] == "eintragen")
{
	$contentFile = DATEIPFAD . "templates/" . $rowTemp->name . "/website/gaestebuch/formular.tpl";
}
	
	
} // Ende Abfrage onlinestatus
else {
	$contentFile = DATEIPFAD . "templates/" . $rowTemp->name . "/website/kein_inhalt.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);
?>
