<?php 
// ======================================================================== //
//   KOOBI - CMS                                                            //
//   2003-2005 DREAM4 - HTTP://WWW.DREAM4.DE                              //
//   REMOVING THIS INFO WITHOUT PERMISSION BREAKS YOUR LICENSE.             //
//   PLEASE NOTE: KOOBI IS NO FREEWARE! ANY PART OF THE SOFTWARE IS  BY    //
//   THEIR OWNER.                                                           //
//                                                                          //
//   DREAM4 - AM MICHELSGRUND 7 - 69469 WEINHEIM - GERMANY                  //    
//   TEL. +49(0) 6201 - 980442 / FAX. +49(0) 6201 - 64809                   //
// ======================================================================== //
ob_start();
error_reporting(E_ALL ^ E_NOTICE);
define("BASEDIR", dirname(__FILE__));

require(BASEDIR . "/inc/init.php");
define("HPURL", "http://" . $_SERVER['HTTP_HOST'] . str_replace("/index.php", "", $_SERVER['PHP_SELF']) . "/");

$expire = time() + (60 * 10);
$sql = new dbc("DELETE FROM " . PREFIX . "_useronline WHERE expire <= '" . time() . "'");
$sql = new dbc("SELECT ip FROM " . PREFIX . "_useronline WHERE ip='" . $_SERVER['REMOTE_ADDR'] . "' limit 1");
$num = $sql->numrows();
if ($num < 1) {
    $sql = new dbc("INSERT INTO " . PREFIX . "_useronline (ip,expire,uname,invisible) 
	VALUES (
	'" . $_SERVER['REMOTE_ADDR'] . "',
	'$expire',
	'" . UNAME . "',
	'" . INVISIBLE . "'
	)");
} else {
    $sql = new dbc("UPDATE " . PREFIX . "_useronline set uname='" . UNAME . "' WHERE ip='" . $_SERVER['REMOTE_ADDR'] . "'");
} 




if (!isset($_REQUEST['p'])) {
    $_REQUEST['p'] = "index";
    $loader = "?";
} 


$buffer = str_replace(array(":", "/", "..", ".", ";", "\\", "http", "ftp"), "", $_REQUEST['p']);

$sql = new dbc("SELECT area_template,active FROM " . PREFIX . "_areas WHERE area_id='".escs($area)."'");
$row = $sql->fetchrow();
// =================================================================
// <<-- Wenn Sektion nicht aktiv ist und ein Passwort gesetzt wurde,
// wird hier nun überprüft, ob das Passwort gültig ist. Wenn ja,
// hat der Besucher Zugriff. -->>
// =================================================================
if ($row->active != 1) {
    if (!($HTTP_SESSION_VARS['secpass' . $area])) {
        $HTTP_SESSION_VARS['secpass' . $area] = $_GET['pass'];
    } 
    $sql = new dbc("SELECT pass,tmpl FROM " . PREFIX . "_areas WHERE area_id='".escs($area)."'");
    $row = $sql->fetchrow();

    if (($row->pass == "") || ($row->pass != $HTTP_SESSION_VARS['secpass' . $area])) {
        $HTTP_SESSION_VARS['secpass' . $area] = "";
        echo $row->tmpl;
        exit();
    } 
} 

$tmpl = new Koobi("templates/$THEME/");
$tmpl->assign('theme', $THEME);
$tmpl->assign('pref', $pref);

if (@!include("system/$buffer.php")) {
    $EOUT = msg("error_once", "modulenotfound", str_replace("__URL__", "index.php", $lang['redirect']), "index.php");
    $NOOUT = 1;
} 
// =================================================================
// <<-- HIER WERDEN DIE EINZELNEN BEREICHE DEM JEWEILIGEN
// TEMPLATE ZUGEWIESEN (ADMIN->Container (Seite)) -->>
// =================================================================
switch ($_REQUEST['p']) {
    case "pic" :
    //case "gallerypic" : $template = fetchmaintemplate("16"); break;
	case "gallerypic" : $template = fetchmaintemplate("27"); break;
    case "misc" : $template = fetchmaintemplate("13"); break;
    case "userlist" : $template = fetchmaintemplate("14"); break;
    case "manufacturer" : $template = fetchmaintemplate("22"); break;
    case "tell" : $template = fetchmaintemplate("23"); break;
    case "static" : $template = fetchmaintemplate("24"); break;
    case "poll" : $template = fetchmaintemplate("25"); break;
    case "faq" : $template = fetchmaintemplate("26"); break;
    case "gallery" : $template = fetchmaintemplate("27"); break;
    case "register" : $template = fetchmaintemplate("28"); break;
    case "pwlost" : $template = fetchmaintemplate("29"); break;
    case "ignorelist" : $template = fetchmaintemplate("30"); break;
    case "changedetails" : $template = fetchmaintemplate("31"); break;
    case "changepw" : $template = fetchmaintemplate("32");  break;
    case "pn" : $template = fetchmaintemplate("33"); break;
    case "news" : $template = fetchmaintemplate("34"); break;
    case "index" : $template = fetchmaintemplate("12"); break;
    case "product": $template = fetchmaintemplate("36");break;
    case "downloads": $template = fetchmaintemplate("40");break;
    case "links": $template = fetchmaintemplate("43");break;
    case "downloadfile": $template = fetchmaintemplate("42");break;
    case "contact" : $template = fetchmaintemplate("45"); break;
    case "articles" : $template = fetchmaintemplate("38"); break;
	case "guestbook" : $template = fetchmaintemplate("47"); break;
	case "calendar" : $template = fetchmaintemplate("50"); break;
    case "showforums" :
    case "showforum" :
    case "showtopic" :
    case "newpost" :
    case "addpost" :
    case "move" :
    case "deltopic" :
    case "newcategory" :
    case "newforum" :
    case "forum";
    case "newtopic" :
    case "addpost" :
    case "addtopic" : $template = fetchmaintemplate("35");
        break;
    default : $template = fetchmaintemplate("12");
} 

if (!$template) $template = fetchmaintemplate("12");
// =================================================================
// <<-- WENN USER NICHT ANGEMELDET IST, LOGINBOX ANZEIGEN -->>
// =================================================================
if ($islogged == 1) {
    $tmpl->assign("login", 1);
    $tmpl->assign("name", $BENUTZER);
} else {
    $tmpl->assign("login", 0);
    $tmpl->assign("gast", $GROUPSINGLE);
} 
// =================================================================
// <<-- BERECHTIGUNG FÜR PN UND ADMINLINK -->>
// =================================================================
if (permission("canpn")) {
    $tmpl->assign('pn', 1);
} else {
    $tmpl->assign('pn', 0);
} 
if (permission("adminpanel")) {
    $tmpl->assign('adminlink', 1);
} 
// =================================================================
// <<-- Drucklink -->>
// =================================================================
switch ($_REQUEST['p']) {
    case "index" :
    case "" :
        $printlink = "?area=$area&amp;print=1";
        break;
    default :
        $printlink = redir() . "&amp;print=1";
} 
// =================================================================
// <<-- Shortnews -->>
// =================================================================
$position2 = strpos($_COOKIE["news"], "toggle_h2");
if (is_numeric($position2)) {
    $disp_shortnews = "none";
    $plusminus = "plus.gif";
} else {
    $plusminus = "minus.gif";
} 

$toggleimage_shortnews = "<img border=\"0\" id=\"img_toggle_h2\" src=\"templates/" . $THEME . "/img/page/" . $plusminus . "\" onmouseover=\"this.style.cursor = 'pointer'\" onclick=\"MWJ_changeDisplay('toggle_h2', MWJ_getStyle( 'toggle_h2', 'display' ) ? '' : 'none'); koobi4_toggleImage('img_toggle_h2', this.src); koobi4_setCookie('news', 'toggle_h2');\" alt=\"\" />";
$toggletd_shortnews = "onmouseover=\"this.style.cursor = 'pointer'\" onclick=\"MWJ_changeDisplay('toggle_h2', MWJ_getStyle( 'toggle_h2', 'display' ) ? '' : 'none'); koobi4_toggleImage('img_toggle_h2', this.src); koobi4_setCookie('news', 'toggle_h2');\"";
$shortnews = array();
fetchNews($area, $shortnews);

$tmpl->assign('maxattachment', MAXATTACHMENT);
$tmpl->assign('disp_shortnews', $disp_shortnews);
$tmpl->assign('toggleimage_shortnews', $toggleimage_shortnews);
$tmpl->assign('toggletd_shortnews', $toggletd_shortnews);
$tmpl->assign('shortnews', $shortnews);
$tmpl->assign('homelink', "index.php?p=index&amp;area=" . $area . "");
$tmpl->assign('forumlink', "index.php?area=" . $area . "&amp;p=showforums");
$tmpl->assign('koobiversion', KVERSION);
$tmpl->assign('redir', redir());
$tmpl->assign('titel', $pref['hpname']);
$tmpl->assign('aktuelleseite', $sname);
$tmpl->assign('index.php?', "index.php?area=$area&amp;");
$tmpl->assign('area', $area);
$tmpl->assign('lang', $lang);
$tmpl->assign('navigation', getStaticNavigation(getDocument(), $area, UGROUP));
$tmpl->assign('document', getDocument());
$tmpl->assign('speedbar', speedbar($area));
$tmpl->assign('printlink', redir() . "&amp;print=1");
$tmpl->assign('telllink', "index.php?area=" . $area . "&amp;p=tell&amp;action=form");
$tmpl->register_function('printpanel', 'printpanel');

if ((isset($NOOUT) && $NOOUT == 1) || (isset($MISC) && $MISC == 1)) {
    $tmpl->assign("content", $EOUT);
} 
// =================================================================
// <<-- SEITENSTATISTIKEN AKTUALISIEREN -->>
// =================================================================
@setcookie ("real", 1);

$today = date("d-m-Y");
$sql = new dbc("SELECT datum FROM " . PREFIX . "_sitestats WHERE datum='$today' LIMIT 1");
$isda = $sql->numrows();

if ($_SERVER['HTTP_REFERER'] != "") {
    define("HOST", "http://" . $HTTP_SERVER_VARS['HTTP_HOST']);
    include_once ("inc/browser.php");

    $host_1 = explode("//", HOST);
    $host_1_1 = $host_1[1];
    $host_1_1 = explode("/", $host_1_1);
    $host_1_1 = $host_1_1[0];

    $host_2 = explode("//", $_SERVER['HTTP_REFERER']);
    $host_2_2 = $host_2[1];
    $host_2_2 = explode("/", $host_2_2);
    $host_2_2 = $host_2_2[0];

    $referer = $_SERVER['HTTP_REFERER'];
    $clientInfo = new Browser;
    if ($host_1_1 != $host_2_2) {
        $query_ref = "INSERT INTO " . PREFIX . "_referer (
		id,
		user_os,
		user_ua,
		user_referer,
		datum
		) VALUES (
		'', 
		'" . $clientInfo->Platform . "', 
		'" . $clientInfo->Name . " " . $clientInfo->Version . "', 
		'$referer', 
		NOW()
		)";
    } 
} 
if ($isda<1) {
    $sql = new dbc("INSERT INTO " . PREFIX . "_sitestats (datum,hits,tag,monat,jahr) VALUES ('$today','1','" . date("d") . "','" . date("m") . "','" . date("Y") . "')");
    if ($query_ref) $sql = new dbc($query_ref);
} 

// =================================================================
// <<-- Hits nur erhöhen, wenn Cookie gesetzt werden kann -->>
// =================================================================
if ( ($isda>0) && ($_COOKIE['real']==1) ) {
    $sql = new dbc("UPDATE " . PREFIX . "_sitestats SET hits=hits+1 WHERE datum='$today'");
    if ($query_ref) $sql = new dbc($query_ref);
} 


// =================================================================
// <<-- Visits nur erhöhen, wenn Cookie gesetzt werden kann -->>
// =================================================================
if ( ($_COOKIE['real']==1) && ($_COOKIE['besucht'] != $today) ) {
    $sql = new dbc("UPDATE " . PREFIX . "_sitestats SET visits=visits+1 WHERE datum='$today'");
    setcookie ("besucht", $today , time() + (3600 * 24));
} 




// =================================================================
// <<-- Ausgeben -->>
// =================================================================
if ((isset($NOOUT) && $NOOUT == 1) || (isset($nometa) && $nometa == 1)) {
    $tmpl->display('page/noheader.tpl');
} elseif ($_REQUEST['print'] == 1) {
    printupdate();
    $tmpl->assign('url', str_replace("&amp;print=1", "", redir()));
    $tmpl->assign('print', $lang['printpage']);
    $prepage = $tmpl->fetch('page/print.tpl');
} else {
    $prepage = $tmpl->fetch($template);
} 
// =================================================================
// <<-- MOD_REWRITE VORBEREITEN -->>
// =================================================================
if(MRWRITE==1){
	$prepage = preg_replace("/index.php([?])area=([0-9]*)&amp;p=index/","index_\\2.htm",$prepage);
	$prepage = preg_replace("/index.php([?])p=index&amp;area=([0-9]*)&amp;categ=([a-zA-Z0-9]*)&amp;ud=([a-zA-Z0-9]*)&amp;selby=([a-zA-Z0-9]*)&amp;show=([0-9]*)&amp;pp=([0-9]*)&amp;page=([a-zA-Z0-9]*)&amp;start=([0-9]*)&amp;end=([0-9]*)/", "index_\\2_\\3_\\4_\\6_\\7_\\8_\\9_\\10.htm", $prepage);
	$prepage = preg_replace("/index.php([?])p=index&amp;page=([0-9]*)&amp;start=([0-9]*)&amp;end=([0-9]*)/", "index_\\2_\\3_\\4.htm", $prepage);
	//
	// ARTIKEL
	$prepage = preg_replace("/index.php([?])p=articles&amp;area=([0-9]*)/", "articles_\\2.htm", $prepage);
	$prepage = preg_replace("/index.php([?])type=([a-zA-Z0-9]*)&amp;area=([0-9]*)&amp;p=articles&amp;id=([0-9]*)&amp;high=([ _a-zA-Z0-9]*)/", "articles_\\2_\\3_\\4_\\5.htm", $prepage);
	$prepage = preg_replace("/index.php([?])p=articles&amp;categ=([0-9]*)&amp;area=([0-9]*)&amp;type=([ _a-zA-Z0-9]*)/", "articlescat_\\2_\\3_\\4.htm", $prepage);
	$prepage = preg_replace("/index.php([?])p=articles&amp;categ=([0-9]*)&amp;area=([0-9]*)/", "articlescat_\\2_\\3_\\4.htm", $prepage);
	$prepage = preg_replace("/index.php([?])p=articles&amp;categ=([0-9]*)&amp;area=([0-9]*)/", "articlescat_\\2_\\3.htm", $prepage);
	$prepage = preg_replace("/index.php([?])nav=1&amp;area=([0-9]*)&amp;p=product&amp;action=showdetails&amp;id=([0-9]*)&amp;artpage=([0-9]*)/", "articlepage_\\2_\\3_\\4.htm", $prepage);
	// STATISCHE DOKUMENTE
	$prepage = preg_replace("/index.php([?])area=([0-9]*)&amp;p=static&amp;page=([a-zA-Z0-9]*)/", "static_\\3_\\2.htm", $prepage);
	
	// FAQ
	$prepage = preg_replace("/index.php([?])p=faq&amp;area=([0-9]*)/","faq_\\2.htm",$prepage);
	$prepage = preg_replace("/index.php([?])p=faq&amp;faq_id=([0-9]*)&amp;area=([0-9]*)/", "faq_\\2_\\3.htm", $prepage);
	
	// PRODUKTE
	$prepage = preg_replace("/index.php([?])p=product&amp;area=([0-9]*)&amp;action=platforms&amp;platform=([0-9]*)/", "products_platform_\\2_\\3.htm", $prepage);
	$prepage = preg_replace("/index.php([?])area=([0-9]*)&amp;p=product&amp;action=showdetails&amp;id=([0-9]*)/", "showproduct_\\2_\\3.htm", $prepage);
	$prepage = preg_replace("/index.php([?])p=product&amp;action=([a-zA-Z0-9]*)&amp;area=([0-9]*)/", "products_\\2_\\3.htm", $prepage);
	$prepage = preg_replace("/index.php([?])p=product&amp;action=([a-zA-Z0-9]*)&amp;platform=([0-9]*)&amp;area=([0-9]*)/", "productspf_\\2_\\3_\\4.htm", $prepage);
	//$prepage = preg_replace("/index.php([?])p=product&amp;area=([0-9]*)&amp;action=platforms&amp;charakter=([a-zA-Z0-9]*)&amp;platform=([a-zA-Z0-9]*)/", "products_choice_\\2_\\3_\\4.htm", $prepage);
	
	// NEWSARCHIV
	$prepage = preg_replace("/index.php([?])p=newsarchive&amp;categ=([a-zA-Z0-9]*)&amp;area=([0-9]*)/", "newsarchive_\\2_\\3.htm", $prepage);
	$prepage = preg_replace("/index.php([?])p=newsarchive&amp;area=([0-9]*)/", "newsarchive_\\2.htm", $prepage);
	$prepage = preg_replace("/index.php([?])arc=1&amp;p=newsarchive&amp;area=([0-9]*)&amp;categ=([a-zA-Z0-9]*)&amp;ud=([a-zA-Z0-9]*)&amp;selby=([a-zA-Z0-9]*)&amp;show=([0-9]*)&amp;pp=([0-9]*)&amp;page=([a-zA-Z0-9]*)&amp;start=([0-9]*)&amp;end=([0-9]*)/", "news_\\2_\\3_\\4_\\6_\\7_\\8_\\9_\\10.htm", $prepage);
	
	// NEWS
	$prepage = preg_replace("/index.php([?])p=index&amp;categ=([0-9]*)&amp;area=([0-9]*)/", "newsshow_\\2_\\3.htm", $prepage);
	$prepage = preg_replace("/index.php([?])area=([0-9]*)&amp;p=news&amp;newsid=([0-9]*)&amp;high=([ _a-zA-Z0-9]*)/", "news_\\2_\\3_\\4.htm", $prepage);
	$prepage = preg_replace("/index.php([?])area=([0-9]*)&amp;p=news&amp;newsid=([0-9]*)/", "news_\\2_\\3.htm", $prepage);
	$prepage = preg_replace("/index.php([?])p=news&amp;area=([0-9]*)&amp;newsid=([0-9]*)&amp;print=1/", "news_\\2_\\3_print.htm", $prepage);
	$prepage = preg_replace("/index.php([?])categ=all&amp;area=([0-9]*)/", "newsshow_all_\\2.htm", $prepage);
	$prepage = preg_replace("/index.php([?])nav=1&amp;area=([0-9]*)&amp;p=news&amp;newsid=([0-9]*)&amp;artpage=([0-9]*)/", "news_page_\\2_\\3_\\4.htm", $prepage);
	
	// HERSTELLER
	$prepage = preg_replace("/index.php([?])p=manufacturer&amp;action=showdetails&amp;area=([0-9]*)&amp;id=([0-9]*)/", "showmanufacturer_\\2_\\3.htm", $prepage);
	$prepage = preg_replace("/index.php([?])do=sort&amp;p=manufacturer&amp;area=([0-9]*)&amp;charakter=([a-zA-Z0-9]*)/", "showmanufacturer_sorted_\\2_\\3.htm", $prepage);
	$prepage = preg_replace("/index.php([?])p=manufacturer&amp;area=([0-9]*)/", "manufacturer_\\2.htm", $prepage);
	
	// USER 
	// $prepage = preg_replace("/index.php([?])area=([0-9]*)&amp;p=user&amp;id=([0-9]*)/", "user_\\2_\\3.htm", $prepage);
	
	// GALERIE
	$prepage = preg_replace("/index.php([?])p=gallery&amp;area=([0-9]*)/","gallery_\\2.htm",$prepage);
	$prepage = preg_replace("/index.php([?])p=gallery&amp;action=showimages&amp;galid=([a-zA-Z0-9]*)&amp;area=([a-zA-Z0-9]*)/", "galleryshow_\\3_\\2.htm", $prepage);
	$prepage = preg_replace("/index.php([?])area=([0-9]*)&amp;p=gallery&amp;action=showimages&amp;galid=([a-zA-Z0-9]*)/", "galleryshow_\\2_\\3.htm", $prepage);
	$prepage = preg_replace("/index.php([?])nav=1&amp;p=gallery&amp;action=showimages&amp;galid=([0-9]*)&amp;area=([0-9]*)&amp;pp=([0-9]*)&amp;ascdesc=([a-zA-Z0-9]*)&amp;page=([0-9]*)/",   "galleryshow_\\2_\\3_\\4_\\5_\\6.htm", $prepage);
	
	
	/* AUF WUNSCH EINKOMMENTIEREN. ACHTUNG! JEDER AUSDRUCK BENÖTIGT RECHENZEIT !
	$prepage = preg_replace("/index.php([?])area=([0-9]*)&amp;p=pn/", "pn_\\2.htm", $prepage);
	$prepage = preg_replace("/index.php([?])area=([0-9]*)&amp;p=ignorelist/", "ignorelist_\\2.htm", $prepage);
	$prepage = preg_replace("/index.php([?])area=([0-9]*)&amp;p=changepw/", "changepassword_\\2.htm", $prepage);
	$prepage = preg_replace("/index.php([?])area=([0-9]*)&amp;p=changedetails/", "changedetails_\\2.htm", $prepage);
	$prepage = preg_replace("/index.php([?])p=manufacturer&amp;area=([0-9]*)/", "manufacturer_\\2.htm", $prepage);
	*/
	
	// FORUM
	$prepage = preg_replace("/index.php([?])p=showforum&amp;fid=([0-9]*)&amp;sortby=([_a-zA-Z0-9]*)&amp;sort=([_a-zA-Z0-9]*)/", "showforums_sort_\\2_\\3_\\4.htm", $prepage);
	$prepage = preg_replace("/index.php([?])p=showforums&amp;cid=([0-9]*)/", "forum_\\2.htm", $prepage);
	$prepage = preg_replace("/index.php([?])p=showforum&amp;fid=([0-9]*)/", "showforums_\\2.htm", $prepage);
	
	$prepage = preg_replace("/index.php([?])p=showtopic&amp;toid=([0-9]*)&amp;pp=([0-9]*)&amp;page=([0-9]*)/", "topic_jump_\\2_\\3_\\4.htm", $prepage);
	$prepage = preg_replace("/index.php([?])p=showtopic&amp;toid=([0-9]*)&amp;fid=([0-9]*)/", "topic_\\2_\\3.htm", $prepage);
	$prepage = preg_replace("/index.php([?])p=showtopic&amp;toid=([0-9]*)/", "showtopic_\\2.htm", $prepage);
	$prepage = str_replace("index.php?p=showforums","forum.htm",$prepage);
	
	$prepage = preg_replace("/index.php([?])area=([0-9]*)&amp;p=tell&amp;action=form/", "tellfriend_\\2.htm", $prepage);
	$prepage = str_replace(".htm&amp;print=1", "_print.htm", $prepage);
}

echo htmlpretty($prepage);
?>