<?php
// ======================================================================== //
//                                                                          //
//   KooBI- Webportalsystem                                                 //
//   SCRiPTMAFiA 2005 - THE DiRTY HANDS ON YOUR SCRiPTS                     //
//                                                                          //
//   ====================================================================   //
//                                                                          //   
//   dream4 | webservices - Am Michelsgrund 7 - 69469 Weinheim - Germany    //    
//   tel. +49(0) 6201 - 980442 / fax. +49(0) 6201 - 64809                   //
//                                                                          //
// ======================================================================== //
$tmpl->assign('lang',$lang);
$tmpl->assign('area',$area);

if(!checkactive('guestbook')) include(dirname(__FILE__)."/lib/notactive.php" );
$sname = simpletitle($lang['guestbook']);

$sql = new dbc("SELECT * FROM " . PREFIX . "_guestbook_settings");
$row_spam = $sql->fetchrow();
$tmpl->assign('maxpostlength', $row_spam->maxpostlength);
	
$limit = ($_REQUEST['pp']!='') ? $_REQUEST['pp'] : '10';
$sort = ($_REQUEST['sort']!='') ? escs($_REQUEST['sort']) : 'desc';

// ===========================================
// <<-- AKTIONEN -->>
// ===========================================
switch ($_REQUEST['action']){
	case '' :
	case 'showentries' :
	
	$path = dirname(__FILE__);
	require_once($path ."/lib/pagesobjects.php" );
	require_once($path ."/lib/commentobjects.php" );
	
	// Alle Eintraege auslesen...
	$inserts = array();
	
	$sql = new dbc("SELECT id FROM " . PREFIX . "_guestbook");
	$num = $sql->numrows();
	
	$seiten = ceil($num / $limit);
	$a = prepage() * $limit - $limit;
	
	// Navi 
	if($num > $limit){
		$tmpl->assign('navi', pagenav($seiten, $lang['aktpos'], " <a class=\"page_navigation\" href=\"index.php?p=guestbook&amp;area=$area&amp;pp=$limit&amp;sort=$_REQUEST[sort]&amp;page={s}\">{t}</a> "));
	}
			
	$sql = new dbc("SELECT * FROM " . PREFIX . "_guestbook order by id $sort limit $a,$limit");
	$erg = $sql->numrows();
	
	while ( $row = $sql->fetchrow()){
		$row->ctime = mygmt($row->ctime);
		$text = $row->comment;
	
	// Sind Smilies und BB- Code erlaubt?
	if(COMMENTSMILEYS == 1) {
		$text = kcodes_comments($text);
		$text = dosmilies($text);
	} else {
		$text = kcodes_comments($text);
	}
		$row->comment = badwordreplace($text);
		array_push($inserts, $row);
	}
	
	$tmpl->assign('comments_array', $inserts);
	break;
	
	// Neuer Eintrag
	case 'new' :
	$error = false;
	
	// Spamschutz aktiv?
	if($row_spam->spamprotect==1){
		$sql = new dbc("SELECT ip,ctime FROM ".PREFIX."_guestbook WHERE ip='".$_SERVER['REMOTE_ADDR']."' ORDER BY id DESC limit 1");
		
		$row = $sql->fetchrow();
		if($row){
			if( ($row->ctime) + (60*$row_spam->spamprotect_time) > time()){
				
				$EOUT = msg("spamprotect","spamprotect_text", str_replace("__URL__", "index.php?p=guestbook&area=$_REQUEST[area]", $lang['redirect']), "index.php?p=guestbook&area=$_REQUEST[area]");
				$NOOUT = 1;
				$error = true;
			} 
		}
	}
	
	// Eintrag in db
	if(!$error){
	$text = formtext($_POST['text'], $row_spam->maxpostlength);
	$sql = new dbc("INSERT INTO " . PREFIX . "_guestbook
	(
		id,
		ctime,
		author,
		comment,
		email,
		web,
		ip,
		authfrom
	) VALUES (
		'',
		'".time()."',
		'".escs(strip_tags(substr($_REQUEST['author'],0,25)))."',
		'$text',
		'".escs(strip_tags(substr($_REQUEST['email'],0,100)))."',
		'".escs(strip_tags(substr($_REQUEST['http'],0,100)))."',
		'".$_SERVER['REMOTE_ADDR']."',
		'".escs(strip_tags(substr($_REQUEST['from'],0,100)))."'
	)
	");
	
	// Mail an Admin
	if($row_spam->mailbycomment==1){
	@mail($pref['sendemail'], $lang['emailsubject_by_gbcomment'], str_replace("\n","\n\n",stripslashes($_POST['text'])),
     "From: $pref[sendemail]\r\n"
    ."Reply-To: $pref[sendemail]\r\n"
	."X-Mailer: PHP/" . phpversion());
	}
	
	// Dankeseite + Weiterleitung
	$EOUT = msg('thankyou', 'gbentry_thanks', str_replace("__URL__", "index.php?p=guestbook&area=$_REQUEST[area]", $lang['redirect']), "index.php?p=guestbook&area=$_REQUEST[area]");
	$NOOUT = 1;
	}
	break;
} // ENDE AKTIONEN


// Smilies und BB- Code erlaubt?


if(COMMENTSMILEYS == 1){
	$tmpl->assign('smilie', 1);
	$tmpl->assign('listemos', $smilies);
}
	
if (COMMENTSBBCODE == 1){
	$tmpl->assign('bbcodes', 1);
}

$tmpl->assign('comments', 
	parsetrue('container/'.container('comments'), $lang['entriesoverall'] . $num . " | <a href=\"#new\">$lang[newentry]</a>", $tmpl->fetch('guestbook/comments.tpl')));

$tmpl->assign('commentform', 
	parsetrue('container/'.container('comments'), $lang['guestbookentrynew'], $tmpl->fetch('guestbook/commentform.tpl')));

$tmpl->assign('content', 
	parsetrue('container/'.container('guestbook_in'),  $lang['guestbook'] , $tmpl->fetch('guestbook/guestbook.tpl')));
?>