<?php
//=================================================================
// KOOBI R7 - CMS - PORTALSOFTWARE(c) DREAM4(r) 
// HTTP://WWW.DREAM4.DE
//=================================================================
// ACHTUNG!
// DIESER PROGRAMMCODE IST URHERRECHTLICH GESCHUETZT
// DIE URHEBERRECHTE LIEGEN BEI DEN JEWEILIGEN AUTOREN.
// AENDERUNGEN IN DIESER DATEI ERFOLGEN AUF EIGENE GEFAHR!
// ES IST NICHT GESTATTET, DEN COPYRIGHTHINWEIS ZU AENDERN ODER ZU
// ENTFERNEN. NUR WENN SIE EINE COPYRIGHTHINWEIS-ENTFERNUNG BESTELLT
// HABEN, DUERFEN SIE DIESEN ENTFERNEN.
//================================================================
// BEI FRAGEN WENDEN SIE SICH BITTE AN: KONTAKT@DREAM4.DE
//=================================================================
if(!defined('START_PATH')) exit;

if($GLOBALS['settings']['shop_is_startpage']==1 && $_REQUEST['p']=='index' && VERSION == 'PRO' && @$_SESSION['shop_visit']!=1) 
{	
	refer("index.php?p=shop");
}

//=================================================================
// Config
//=================================================================
$GLOBALS['config_new']['NewLinks']    = 3; // Anzahl neuester Links
$GLOBALS['config_new']['Downloads']   = 3; // Anzahl neuester Downloads
$GLOBALS['config_new']['NewProducts'] = 3; // Anzahl neuester Produkte (nicht Shop-Produkte!)
$GLOBALS['config_new']['Cheats']      = 3; // Anzahl neuester Cheats
$GLOBALS['config_new']['Galleries']   = 3; // Anzahl neuester Galerien
$GLOBALS['config_new']['Lastposts']   = 3; // Anzahl letzte Posts des Forums

//=================================================================
// News (start.tpl / {$topnews})
//=================================================================
if(get_active('News'))
{
	$News = new News;
	
	$News->displayAllNews('','',1);
	$GLOBALS['tmpl']->assign('topnews', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] .  '/news/topnews.tpl'));
	
	$News->displayAllNews();
	$GLOBALS['tmpl']->assign('news', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] .  '/news/newsticker.tpl'));
}

//=================================================================
// Top-Content (start.tpl / {$topcontent})
//=================================================================
if(get_active('content') && file_exists(BASE_DIR . '/class/Class.Content.php'))
{
	include_once(BASE_DIR . '/class/Class.Content.php');
	$Content = new Content;
	$Content->getTopContent();
	$GLOBALS['tmpl']->assign('topcontent', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] .  '/content/topcontent.tpl'));
}

//=================================================================
// Top-Artikel (start.tpl / {$toparticle})
//=================================================================
if(get_active('articles') && file_exists(BASE_DIR . '/class/Class.Gaming.php'))
{
	include_once(BASE_DIR . '/class/Class.Gaming.php');
	$Article = new Gaming;
	$Article->getTopArticles();
	$GLOBALS['tmpl']->assign('toparticle', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] .  '/gaming/articles_toparticles.tpl'));
}

//=================================================================
// Neueste Downloads + Links (start.tpl / {NewDownloads} + {NewLinks})
//=================================================================
if(get_active('downloads') && @file_exists(BASE_DIR . '/class/Class.Downloads.php'))
{
	include_once(BASE_DIR . '/class/Class.Downloads.php');
	function newDownloads()
	{
		$Downloads = new Downloads;
		$Downloads->Settings();
		$GLOBALS['tmpl']->assign('NewDownloadsEntries', $Downloads->newEntries('',abs((int)$GLOBALS['config_new']['Downloads']),1));
		return $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/downloads/entries_new_start.tpl');
	}
	$GLOBALS['tmpl']->assign('NewDownloads',newDownloads());
}

//=================================================================
// Neueste Links (start.tpl / {$NewLinks})
//=================================================================
if(get_active('links') && @file_exists(BASE_DIR . '/class/Class.Links.php'))
{
	include_once(BASE_DIR . '/class/Class.Links.php');
	function newLinks()
	{
		$Links = new Links;
		$Links->Settings();
		$GLOBALS['tmpl']->assign('NewLinksEntries', $Links->newEntries('',abs((int)$GLOBALS['config_new']['NewLinks']),1));
		return $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/links/entries_new_start.tpl');
	}
	$GLOBALS['tmpl']->assign('NewLinks',newLinks());
}

//=================================================================
// Neueste Produkte (start.tpl / {$NewProducts})
//=================================================================
if(get_active('products') && get_active('products_startpage') && file_exists(BASE_DIR . '/class/Class.Products.php'))
{
	include_once(BASE_DIR . '/class/Class.Products.php');
	function newProducts()
	{
		$Products = new Products;
		$GLOBALS['tmpl']->assign('NewProductEntries', $Products->newProducts(abs((int)$GLOBALS['config_new']['NewProducts'])));
		return $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/products/products_new_start.tpl');
	}
	$GLOBALS['tmpl']->assign('NewProducts',newProducts());
}

//=================================================================
// Neueste Cheats (start.tpl / {$NewCheats})
//=================================================================
if(get_active('cheats') && get_active('cheats_startpage') && file_exists(BASE_DIR . '/class/Class.Gaming.php'))
{
	include_once(BASE_DIR . '/class/Class.Gaming.php');
	function newCheats()
	{
		$Cheats = new Gaming;
		$GLOBALS['tmpl']->assign('NewCheatsEntries', $Cheats->CheatnewEntries('',abs((int)$GLOBALS['config_new']['Cheats']),1));
		return $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/gaming/cheats_new_start.tpl');
	}
	$GLOBALS['tmpl']->assign('NewCheats',newCheats());
}

//=================================================================
// Neueste Galerien (start.tpl / {$NewGalleries})
//=================================================================
if(get_active('gallery') && get_active('gallery_startpage') && file_exists(BASE_DIR . '/class/Class.Gallery.php'))
{
	include_once(BASE_DIR . '/class/Class.Gallery.php');
	function newGalleries()
	{
		$Gallery = new Gallery;
		$GLOBALS['tmpl']->assign('NewGalleryEntries', $Gallery->newGalleries(abs((int)$GLOBALS['config_new']['Galleries'])));
		return $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/gallery/gallery_new_start.tpl');
	}
	$GLOBALS['tmpl']->assign('NewGalleries',newGalleries());
}


//=================================================================
// Neueste Foren-Posts (start.tpl / {$NewForumPosts})
//=================================================================
if(get_active('forums') && get_active('forums_newstartpage') && file_exists(BASE_DIR . '/system/forum.php'))
{
	function getLastPostsStartpage($param='')
	{
		$lastposts_sp = array();
		$sql_fids = $GLOBALS['db']->Query("SELECT title,forum_id,id,last_post_int FROM " . PREFIX . "_f_topic  ORDER BY id DESC LIMIT " . abs((int)$GLOBALS['config_new']['Lastposts']));
		while($row_fids = $sql_fids->fetchrow())
		{
			$sql_lp = $GLOBALS['db']->Query("SELECT 
				p.id,
			
				p.title,
				p.message,
				p.datum,
				p.topic_id,
				p.uid,
				u.Benutzername as uname,
				u.Regdatum as user_regdate
			FROM 
				" . PREFIX . "_f_post AS p, 
				" . PREFIX . "_benutzer AS u 
			WHERE
				p.topic_id = " . $row_fids->id . " AND 
				u.Id = p.uid 
			GROUP BY
				p.id 
			ORDER BY
				datum DESC
			LIMIT 1;");
			$row_lp = $sql_lp->fetchrow();
			
			$perms = getForumPermissionsByUser($row_fids->forum_id, UID);
			if(@$perms[FORUM_PERMISSION_CAN_SEE_TOPIC])
			{
				$q_post = "SELECT COUNT(id) as Antworten FROM " . PREFIX . "_f_post WHERE topic_id = '$row_lp->topic_id'";
				$r_post = $GLOBALS['db']->Query($q_post);
				$post = $r_post->fetchrow();
				
				// Zu welcher Seite muss gesprungen werden?
				$numPages = getPageNum($post->Antworten, 15);
				
				$row_fids->Datum = $row_lp->datum;
				
				$row_fids->LpLink = 'index.php?p=showtopic&amp;toid='.$row_lp->topic_id.'&amp;pp=15&amp;page='.$numPages.'#pid_'.$row_lp->id.'';
				$row_fids->LpTitle =  ($row_lp->title == '') ? $row_lp->message : $row_lp->title;
				array_push($lastposts_sp, $row_fids);
			}
			
		}
	
		$GLOBALS['tmpl']->assign('last_post_array', $lastposts_sp);
		return $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/forums/lastposts.tpl');
	}
	$GLOBALS['tmpl']->assign('NewForumPosts',getLastPostsStartpage());
}

$GLOBALS['tmpl']->assign('pagetitle_html', $GLOBALS['config_vars']['Startpage']);
$GLOBALS['tmpl']->assign('content', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/start/start.tpl')); 
?>