<?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
//=================================================================
class Gaming
{
	var $_allowed_html = '<br /><br>';
	
	function CheatSettings()
	{
		$res = $GLOBALS['db']->RowQuery("SELECT * FROM " . PREFIX . "_cheats_einstellungen");
		$GLOBALS['CheatSettings'] = $res;
		$GLOBALS['tmpl']->assign('CheatSettings', $GLOBALS['CheatSettings']);
	}
	
	function getGenre($id)
	{
		$res = $GLOBALS['db']->RowQuery("SELECT Name,Id FROM " . PREFIX . "_genre  WHERE Id='{$id}'");
		if(!is_object($res)) return;
		$name = koobispecialchars($res->Name);
		return $name;
	}
	
	function getPlattform($id)
	{
		$res = $GLOBALS['db']->RowQuery("SELECT Name,Id FROM " . PREFIX . "_plattformen WHERE Id='{$id}'");
		if(!is_object($res)) return;
		$name = koobispecialchars($res->Name);
		return $name;
	}
	
	function getManufacturer($id)
	{
		$res = $GLOBALS['db']->RowQuery("SELECT Id,Name FROM " . PREFIX . "_hersteller WHERE Id='$id'");
		if(is_object($res))
		{
			$link = '<a href="index.php?p=manufacturer&amp;area=' . AREA . '&amp;action=showdetails&amp;id=' . $res->Id. '&amp;name=' . seotitle($res->Name) . '">' . koobispecialchars($res->Name) . '</a>';
			return $link;
		}
	}
	
	function getShopArticle($id)
	{
		$res = $GLOBALS['db']->RowQuery("SELECT Id,Titel_1,Kategorie FROM " . PREFIX . "_shop_produkte WHERE Artikelnummer='$id'");
		if(is_object($res)) return '<a href="index.php?p=shop&amp;action=showproduct&amp;id='.$id.'&amp;cid='.$res->Kategorie.'&amp;pname='.seotitle($res->Titel_1).'">'.koobispecialchars($res->Titel_1).'</a>';
	}
	
	function getCurrentPf($id)
	{
		$res = $GLOBALS['db']->RowQuery("SELECT Id,Name FROM " . PREFIX . "_plattformen WHERE Id='$id'");
		if(is_object($res))
		{
			$link = '<a href="index.php?p=cheats&amp;area=' . AREA . '&amp;plattform=' . $res->Id. '&amp;name=' . seotitle($res->Name) . '">' . koobispecialchars($res->Name) . '</a>';
			return $link;
		}
	}
	
	function CheatsSearch()
	{
		$LC = $_SESSION['Langcode'];
		$Search = preg_replace('/([^-A-Za-zÀ-ÖØ-öø-ÿ0-9_)( ]*)/', '', @$_REQUEST['ql']);
		$Search2 = koobispecialchars($Search);
		$_REQUEST['ql'] = $Search;
		
		if(strlen($Search) < 3) 
		{
			$Search = '';
			$Search2 = '';
		}
		
		$entries = array();
		
		$check = $GLOBALS['db']->RowQuery("SELECT 
			COUNT(Id) AS ResCount 
		FROM 
			" . PREFIX . "_cheats 
		WHERE 
			Aktiv='1' 
		AND
			((Name_{$LC} LIKE '%{$Search}%' OR Beschreibung_{$LC} LIKE '%{$Search}%') OR 
			(Name_{$LC} LIKE '%{$Search2}%' OR Beschreibung_{$LC} LIKE '%{$Search2}%'))
		AND 
			Sektion = '" . AREA . "' 
		ORDER BY Name_{$LC} ASC");
		
		$num = $check->ResCount;
		$limit = GetLim(15);
		$seiten = ceil($num / $limit);
		$a = prepage() * $limit - $limit;
			
		// Such-Abfrage
		$query_items = $GLOBALS['db']->Query("SELECT 
			*, 
			Name_{$LC} AS Name,
			Beschreibung_{$LC} AS Beschreibung 
		FROM 
			" . PREFIX . "_cheats 
		WHERE 
			Aktiv='1' 
		AND
			((Name_{$LC} LIKE '%{$Search}%' OR Beschreibung_{$LC} LIKE '%{$Search}%') OR 
			(Name_{$LC} LIKE '%{$Search2}%' OR Beschreibung_{$LC} LIKE '%{$Search2}%'))
		AND 
			Sektion = '" . AREA . "'  
		ORDER BY Name_{$LC} ASC LIMIT $a,$limit");
		
		
		
		while($row_items = $query_items->fetchrow())
		{
			// Wertung
			if($GLOBALS['CheatSettings']->Wertung==1)
			{
				$row_items->Wertung = getRating($row_items->Id,'cheats');
			}
			
			$res_name = $GLOBALS['db']->RowQuery("SELECT Id,Name FROM " . PREFIX . "_plattformen WHERE Id='$row_items->Plattform'");
			$row_items->KategName = $res_name->Name;
			$row_items->Link_Categ   = "index.php?p=cheats&amp;area=" . AREA . "&amp;plattform=" . $row_items->Plattform . "&amp;name=" . seotitle($res_name->Name);
			$row_items->CCount = getPageCommentCount($row_items->Id,'cheats');
			$row_items->Beschreibung = (strlen($Search) >= 3) ? high(strip_tags($row_items->Beschreibung,'<span>'),$_REQUEST['ql']) : strip_tags($row_items->Beschreibung,$this->_allowed_html);
			$row_items->Beschreibung = (strlen($Search) >= 3) ? high(strip_tags($row_items->Beschreibung,'<span>'),$Search2) : strip_tags($row_items->Beschreibung,$this->_allowed_html);
			$row_items->Link_Details = "index.php?p=cheats&amp;action=showcheat&amp;area=" . AREA . "&amp;plattform=" . $row_items->Plattform . "&amp;id=" . $row_items->Id . "&amp;name=" . seotitle($row_items->Name);
			array_push($entries, $row_items);
		}
		
		// Seiten-Navigation
		$headernav = '<a href="index.php?p=cheats&amp;area=' . AREA . '">' . $GLOBALS['config_vars']['Gaming_cheats'] . '</a> ';
		
		// Navi
		if($num>$limit)
		{
			$Search = ($Search=='') ? '-' : $Search;
			$GLOBALS['tmpl']->assign('Navi', pagenav($seiten, "", "<a class=\"page_navigation\" href=\"index.php?ql=" . urlencode($Search) . "&amp;action=search&amp;p=cheats&amp;area=".AREA."&amp;page={s}\">{t}</a> "));
		}
			
		$GLOBALS['tmpl']->assign('Entries', $entries);
		$GLOBALS['tmpl']->assign('pagetitle_html', clean_page_title($headernav));
		$GLOBALS['tmpl']->assign('headernav', $headernav);
		$GLOBALS['tmpl']->assign('Results', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/gaming/cheat_items.tpl')); 
		$GLOBALS['tmpl']->assign('content', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/gaming/cheat_search_results.tpl')); 
	}
	
	function CheatDetails($id)
	{
		$LC = $_SESSION['Langcode'];
		$res = $GLOBALS['db']->RowQuery("SELECT *, Name_{$LC} AS Name,Beschreibung_{$LC} AS Beschreibung FROM " . PREFIX . "_cheats WHERE Id='$id' AND Aktiv='1'");
		if(!is_object($res))
		{
			refer('index.php?p=cheats&area=1');
		}
		
		// Hits ggf. erhoehen
		if(@$_SESSION["cheat_read_$id"] != 1)
		{
			$GLOBALS['db']->Query("UPDATE " . PREFIX . "_cheats SET Hits=Hits+1 WHERE Id='{$id}'");
			$_SESSION["cheat_read_$id"] = 1;
		}
		
		$gc = $this->getCurrentPf($res->Plattform);
		$headernav = '<a href="index.php?p=cheats&amp;area=' . AREA . '">' . $GLOBALS['config_vars']['Gaming_cheats'] . '</a>'  . $GLOBALS['config_vars']['PageSep'] . $gc;
		$res->UserName = fetchusername($res->Benutzer);
			
		//=================================================================
		// Galerien enthalten?
		//=================================================================
		if($res->Galerien!='')
		{
			if(file_exists(BASE_DIR . '/class/Class.Gallery.php') && get_active('gallery'))
			{
				include_once(BASE_DIR . '/class/Class.Gallery.php');
				$Gallery = new Gallery;
				$GLOBALS['tmpl']->assign('IncludedGalleries', $Gallery->getExtenGallery($res->Galerien));
			}
		}
		
		//=================================================================
		// Kommentare
		//=================================================================
		if($GLOBALS['CheatSettings']->Kommentare == 1)
		{
			$comment = new Comments;
			// Kommentar bearbeiten
			if(isset($_POST['comment_action']) && $_POST['comment_action'] == 'edit' && permission('edit_comments')) $comment->EditComment('cheats',$_POST['comment_id']);
			
			// Neuer Kommentar
			if(permission('comments'))
			{
				$comment->NewComment('cheats', @$_POST['Redir'],$id);
			}
			
			// Kommentare holen
			$Comments = $comment->GetComments('cheats',$id,'index.php?p=cheats&amp;action=showcheat&amp;plattform=' . $res->Plattform . '&amp;id=' . $id . '&amp;name=' . seotitle($res->Name));
			$GLOBALS['tmpl']->assign('GetComments',$GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/comments/comments.tpl'));
		}
		
		// Wertung
		if($GLOBALS['CheatSettings']->Wertung==1)
		{
			$GLOBALS['tmpl']->assign('RatingUrl', 'index.php?p=rating&action=rate&id=' . $id. '&where=cheats');
			$GLOBALS['tmpl']->assign('RatingForm', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/other/rating.tpl')); 
		}
		
		// Seiten-Info
		setMeta($GLOBALS['config_vars']['Gaming_cheats'],$res->Beschreibung);
		
		$res->Beschreibung = autowords($res->Beschreibung);
		$res->Pf = $this->getCurrentPf($res->Plattform);
		$res->Wertung = getRating($res->Id,'cheats');
		$res->Mf = $this->getManufacturer($res->Hersteller);
		
		// Mirrors
		if($res->CheatLinks!='')
		{
			$alternatives = array();
			$mirrors = explode("\r\n", $res->CheatLinks);
			$i=1;
			foreach($mirrors as $m)
			{
				$mi = '';
				$det = explode(";",$m);
				$mi->Id = $i++;
				$mi->Link = $det[0];
				$mi->Name = $det[1];
				array_push($alternatives, $mi);
			}
			$GLOBALS['tmpl']->assign('alternatives', $alternatives);
		}
		
		$GLOBALS['tmpl']->assign('BrokenLinkSubmit', 'index.php?action=brokenlink&p=downloads&id=' . $id);
		$GLOBALS['tmpl']->assign('cheat_res', $res);
		$GLOBALS['tmpl']->assign('pagetitle_html', clean_page_title($headernav) . $GLOBALS['config_vars']['PageSep'] . koobispecialchars($res->Name));
		$GLOBALS['tmpl']->assign('headernav', $headernav);
		$GLOBALS['tmpl']->assign('content', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/gaming/cheat_display.tpl')); 
	}
	
	//=================================================================
	// Cheats anzeigen
	//=================================================================
	function CheatDisplayAll()
	{
		$LC = $_SESSION['Langcode'];
		$id = 0;
		$getid = (isset($_REQUEST['plattform']) && !empty($_REQUEST['plattform'])) ? abs((int)$_REQUEST['plattform']) : 0 ;
		
		
		switch(@$_REQUEST['sort'])
		{
			case '':
			default:
			case 'datedesc':
				$req = 'datedesc';
				$defsort = "ORDER BY DatumUpdate DESC";
				$defsort_n = "&amp;sort=datedesc";
				$GLOBALS['tmpl']->assign('img_date', 'sorter_down');
				$GLOBALS['tmpl']->assign('datesort', 'dateasc');
			break;
			
			case 'dateasc':
				$req = 'dateasc';
				$defsort = "ORDER BY DatumUpdate ASC";
				$defsort_n = "&amp;sort=dateasc";
				$GLOBALS['tmpl']->assign('img_date', 'sorter_up');
				$GLOBALS['tmpl']->assign('datesort', 'datedesc');
			break;
			
			case 'namedesc':
				$req = 'namedesc';
				$defsort = "ORDER BY Name_1 DESC";
				$defsort_n = "&amp;sort=namedesc";
				$GLOBALS['tmpl']->assign('img_name', 'sorter_down');
				$GLOBALS['tmpl']->assign('namesort', 'nameasc');
			break;
			
			case 'nameasc':
				$req = 'nameasc';
				$defsort = "ORDER BY Name_1 ASC";
				$defsort_n = "&amp;sort=nameasc";
				$GLOBALS['tmpl']->assign('img_name', 'sorter_up');
				$GLOBALS['tmpl']->assign('namesort', 'namedesc');
			break;
			
			
			case 'hitsdesc':
				$req = 'hitsdesc';
				$defsort = "ORDER BY Hits DESC";
				$defsort_n = "&amp;sort=hitsdesc";
				$GLOBALS['tmpl']->assign('img_hits', 'sorter_down');
				$GLOBALS['tmpl']->assign('hitssort', 'hitsasc');
			break;
			
			case 'hitsasc':
				$req = 'hitsasc';
				$defsort = "ORDER BY Hits ASC";
				$defsort_n = "&amp;sort=hitsasc";
				$GLOBALS['tmpl']->assign('img_hits', 'sorter_up');
				$GLOBALS['tmpl']->assign('hitssort', 'hitsdesc');
			break;
		}
		
		$_REQUEST['sort'] = $req;
		
		$prefix = '';
		$news_categ = '';
		$area = AREA;
		$news_categ = array();
		
		$Categs = $this->ListCategs($getid, $prefix, $news_categ, $area);
		
		if(isset($_REQUEST['plattform']) && !empty($_REQUEST['plattform']))
		{
			// Eintraege
			$entries = array();
			$cid = abs((int)$_REQUEST['plattform']);
			$items = array();
			
			$res_name = $GLOBALS['db']->RowQuery("SELECT  Id, Name FROM " . PREFIX . "_plattformen  WHERE Id='$cid'");
			
			$res = $GLOBALS['db']->RowQuery("SELECT COUNT(Id) AS Gesamt FROM " . PREFIX . "_cheats WHERE Plattform='$cid' AND Aktiv='1' {$defsort}");
			
			$num = $res->Gesamt;
			$limit = GetLim(15);
			$seiten = ceil($num / $limit);
			$a = prepage() * $limit - $limit;
			
			$query_items = $GLOBALS['db']->Query("SELECT *,Plattform, Name_{$LC} AS Name, Beschreibung_{$LC} AS Beschreibung FROM " . PREFIX . "_cheats WHERE Plattform='$cid' AND Aktiv='1' {$defsort} LIMIT $a,$limit");
			
			while($row_items = $query_items->fetchrow())
			{
				// Wertung
				if($GLOBALS['CheatSettings']->Wertung==1)
				{
					$row_items->Wertung = getRating($row_items->Id,'cheats');
				}
				
				$row_items->CCount = getPageCommentCount($row_items->Id,'cheats');
				$row_items->KategName = $res_name->Name;
				$row_items->Beschreibung = strip_tags($row_items->Beschreibung,$this->_allowed_html);
				$row_items->Link_Details = "index.php?p=cheats&amp;action=showcheat&amp;area=" . AREA . "&amp;plattform=" . $getid . "&amp;id=" . $row_items->Id . "&amp;name=" . seotitle($row_items->Name);
				array_push($entries, $row_items);
			}
			
			// Navi
			if($num>$limit)
			{
				$GLOBALS['tmpl']->assign('Navi', pagenav($seiten, "", "<a class=\"page_navigation\" href=\"index.php?p=cheats&amp;area=".AREA."&amp;plattform=".$getid."&amp;name=".seotitle($res_name->Name)."&amp;page={s}{$defsort_n}\">{t}</a> "));
			}
			
			// Uebergeben
			$GLOBALS['tmpl']->assign('Entries',$entries);
		}
		
		// Seiten-Navigation
		
		$headernav = '<a href="index.php?p=cheats&amp;area=' . AREA . '">' . $GLOBALS['config_vars']['Gaming_cheats'] . '</a>' . (($getid>0) ? $GLOBALS['config_vars']['PageSep'] . $this->getCurrentPf($getid) : '');
		
		// Seiten-Info
		$hinf = clean_page_title($headernav);
		setMeta($GLOBALS['config_vars']['Gaming_cheats'],$hinf);
		
		if(!isset($_REQUEST['plattform'])) $GLOBALS['tmpl']->assign('Entries', $this->CheatnewEntries());
		$GLOBALS['tmpl']->assign('pagetitle_html', $hinf);
		$GLOBALS['tmpl']->assign('headernav', $headernav);
		$GLOBALS['tmpl']->assign('Categs',$Categs);
		$GLOBALS['tmpl']->assign('CategName',@seotitle($res_name->Name));
		$GLOBALS['tmpl']->assign('content', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/gaming/cheat_plattforms.tpl')); 
	}
	
	//=================================================================
	// Neueste
	//=================================================================
	function CheatnewEntries($search='',$limit=10,$ext=0)
	{
		$this->CheatSettings();
		$LC = $_SESSION['Langcode'];
		$entries = array();
		$query_items = $GLOBALS['db']->Query("SELECT *, Plattform, Name_{$LC} AS Name,Beschreibung_{$LC} AS Beschreibung FROM " . PREFIX . "_cheats WHERE Sektion='" . AREA . "' AND Aktiv='1' ORDER BY Id DESC LIMIT {$limit}");
		while($row_items = $query_items->fetchrow())
		{
			if($ext!=1) $res_name = $GLOBALS['db']->RowQuery("SELECT Id,Name FROM " . PREFIX . "_plattformen WHERE Id='$row_items->Plattform'");
			
			// Wertung
			if($GLOBALS['CheatSettings']->Wertung==1 && $ext!=1)
			{
				$row_items->Wertung = getRating($row_items->Id,'cheats');
			}
			if($ext==1) $this->_allowed_html = '';
			if($ext!=1) $row_items->CCount = getPageCommentCount($row_items->Id,'cheats');
			if($ext!=1) $row_items->KategName = $res_name->Name;
			$row_items->Beschreibung = strip_tags($row_items->Beschreibung,$this->_allowed_html);
			if($ext!=1) $row_items->Link_Categ   = "index.php?p=cheats&amp;area=" . AREA . "&amp;plattform=" . $row_items->Plattform . "&amp;name=" . seotitle($row_items->KategName);
			$row_items->Link_Details = "index.php?p=cheats&amp;action=showcheat&amp;area=" . AREA . "&amp;plattform=" . $row_items->Plattform . "&amp;id=" . $row_items->Id . "&amp;name=" . seotitle($row_items->Name);
			array_push($entries, $row_items);
		}
		return $entries;
	}
	
	//=================================================================
	// Kategorien fuer Seite holen
	//=================================================================
	function ListCategs($id, $prefix, &$news_categ, &$area)
	{
		$LC = $_SESSION['Langcode'];
		$query = $GLOBALS['db']->Query("SELECT Id, Name FROM " . PREFIX . "_plattformen WHERE Sektion = '$area' ORDER BY Name ASC");
		if (!$query->numrows()) 
		{
			return;
		} 
		
		while ($item = $query->fetchrow())
		{
			$res = $GLOBALS['db']->RowQuery("SELECT COUNT(Id) AS LinkCount FROM " . PREFIX . "_cheats WHERE Plattform='$item->Id' AND Aktiv='1'");
			$item->visible_title = $prefix . " " . $item->Name;
			$item->HLink = "index.php?p=cheats&amp;area=" . AREA . "&amp;plattform=$item->Id&amp;name=" . seotitle($item->Name);
			$item->LinkCount = $res->LinkCount;
			
			array_push($news_categ, $item);
		} 
		return $news_categ;
	}
	
	
	
	//=================================================================
	// Artilkel
	//=================================================================
	
	function getTopArticles()
	{
		$Lc = $_SESSION['Langcode'];
		
		$show_start = mktime(0,0,0,1,1,2000);
		$show_end   = stime();
		$tbetween   = "(ZeitStart BETWEEN " .$show_start. " AND  " .$show_end. ") AND ";
		
		
		$toparticleitems = array();
		$sql = $GLOBALS['db']->Query("SELECT 
			Id,
			Zeit AS Datum,
			Sektion,
			Titel_{$Lc} as Titel,
			Titel_1 as DefTitel,
			Inhalt_{$Lc} as Inhalt,
			Inhalt_1 as DefInhalt,
			Bild_1 as Bild,
			TopartikelBild_{$Lc} as TopcontentBild,
			BildAusrichtung 
		FROM 
			" . PREFIX . "_artikel 
		WHERE 
			{$tbetween} 
			(ZeitEnde >= " . stime() . " OR ZeitEnde = 0) AND 
			Sektion='" . AREA . "' AND Topartikel='1' AND Kennwort='' ORDER BY Id DESC LIMIT 10");
		while($row = $sql->fetcharray())
		{
			
			$row['Inhalt']  = ($row['Inhalt']=='') ? $row['DefInhalt'] : $row['Inhalt'];
			$row['Inhalt'] = eregi_replace("\[SCREEN:([a-zA-Z0-9\\\/\_\.\]*)\]", "", $row['Inhalt']);
			$row['Inhalt'] = eregi_replace("\[CONTACT:([a-zA-Z0-9\\\/\_\.\]*)\]", "", $row['Inhalt']);
			$row['Inhalt'] = eregi_replace("\[--NEU--\]", "", $row['Inhalt']);
			$row['Inhalt'] = strip_tags($row['Inhalt'],'');
			
			array_push($toparticleitems,$row);
		}
		$GLOBALS['tmpl']->assign('toparticleitems', $toparticleitems);
	}
	
	
	
	function displayAllArticles($archive=0,$rss=0)
	{
		if(isset($_REQUEST['mode']) && $_REQUEST['mode'] == 'rss')
		{
			$rss=1;
		}
		
		$this->Limit = (!empty($_REQUEST['limit'])) ? abs((int)$_REQUEST['limit']) :  $GLOBALS['section']['LimitNewsArchive'];
		
		switch(@$_REQUEST['type'])
		{
			case '':
			default:
				$db_type = '';
			break;
			
			case 'reviews':
				$db_type = " AND (Typ='review')";
				$GLOBALS['tmpl']->assign('TypArchive', '&amp;type=reviews');
			break;
			
			case 'previews':
				$db_type = " AND (Typ='preview')";
				$GLOBALS['tmpl']->assign('TypArchive', '&amp;type=previews');
			break;
			
			case 'specials':
				$db_type = " AND (Typ='special')";
				$GLOBALS['tmpl']->assign('TypArchive', '&amp;type=specials');
			break;
		}
		
		$db_categ = (isset($_REQUEST['catid']) && !empty($_REQUEST['catid']) && $_REQUEST['catid'] != '0') ? "AND Kategorie = '" . abs((int)$_REQUEST['catid']) . "'" : "";
		
		//=================================================================
		// HIER WIRD UEBERPRUEFT, OB EIN START UND END-DATUM ANGEGEBEN 
		// WURDE. WURDE KEIN DATUM ANGEGEBEN, WIRD DER STARTPUNKT AUF DEN 
		// 1.1.2000 UND DER ENDPUNKT AUF DAS AKTUELLE DATUM GELEGT
		//=================================================================
		$show_start = (isset($_REQUEST['s_year']) && !empty($_REQUEST['s_year']) && isset($_REQUEST['s_month']) && !empty($_REQUEST['s_month']) && isset($_REQUEST['s_day']) && !empty($_REQUEST['s_day'])) ? mktime(0, 0, 1, $_REQUEST['s_month'], $_REQUEST['s_day'], $_REQUEST['s_year']) : mktime(0,0,0,1,1,2000);
		$show_end   = (isset($_REQUEST['e_year']) && !empty($_REQUEST['e_year']) && isset($_REQUEST['e_month']) && !empty($_REQUEST['e_month']) && isset($_REQUEST['e_day']) && !empty($_REQUEST['e_day'])) ? mktime(23, 59, 59, $_REQUEST['e_month'], $_REQUEST['e_day'], $_REQUEST['e_year']) : stime();
		$tbetween   = ((isset($_REQUEST['s_year']) && $_REQUEST['s_year']>1) && ($_REQUEST['e_year'] && $_REQUEST['e_year']>1) || ( ($show_start>1) && ($show_end>1))) ? "(ZeitStart BETWEEN " . mysql_escape_string($show_start) . " AND  " . mysql_escape_string($show_end) . ") AND " : '';
		
		//=================================================================
		// Wir muessen unterscheiden, welche Sprache gesucht werden soll
		// Also nur News anzeigen, die auch in der angeforderten Sprache
		// vorhanden sind.
		//=================================================================
		$Lc = $_SESSION['Langcode'];
		$news = array();
		
		if(isset($_REQUEST['q_news']) && !empty($_REQUEST['q_news']))
		{
			$search_and = "";
			$search_or  = "";
			
			$search_request   =  substr(eregi_replace('[^ %+A-Za-zÀ-ÖØ-öø-ÿ0-9]', '', $_REQUEST['q_news']),0,25);
			
			if(isset($_REQUEST['st']) && !empty($_REQUEST['st']) && $_REQUEST['st'] == 'and')
			{
				$_REQUEST['st'] = "and";
				$and = explode(' ',  $search_request);
				foreach($and as $a) $search_and .= " AND (Titel_{$Lc} LIKE '%" . $a . "%' OR Inhalt_{$Lc} LIKE '%" . $a . "%') \n";
			} else {
				$_REQUEST['st'] = "or";
				$or  = explode(' ',  $search_request);
				$search_or = "AND (Titel_{$Lc} LIKE '%" . $search_request . "%' OR Inhalt_{$Lc} LIKE '%" . $search_request . "%')";
				foreach($or as $o) $search_or .= " OR (Titel_{$Lc} LIKE '%" . $o . "%' OR Inhalt_{$Lc} LIKE '%" . $o . "%') \n";
			}
			
			
			$db_title_search  = " AND ((Suche = 1) $search_and $search_or)";
			$nav_search_title = "&amp;q_news=" . urlencode($search_request);
		} else { 
			$db_title_search = '';
			$nav_search_title = '';
		}
		
		
		
		$q = "SELECT Id FROM " . PREFIX . "_artikel 
		WHERE 
			{$tbetween} 
			(ZeitEnde >= " . stime() . " OR ZeitEnde = 0) AND 
			
			(Sektion = '". AREA . "' OR AlleSektionen = 1) AND
			Aktiv = '1' 
			{$db_type} 
			$db_categ 
			$db_title_search 
		ORDER 
			BY Id DESC ";
		
		$sql = $GLOBALS['db']->Query($q);
		$num = $sql->numrows();
		
		//=================================================================
		// Wie viele Seiten gibt das System zurueck?
		//=================================================================
		$seiten = ceil($num / $this->Limit);
		$a = prepage() * $this->Limit - $this->Limit;
		$GLOBALS['tmpl']->assign("news_limit", $this->Limit);
					
		//=================================================================
		// Seiten-Navigation
		//=================================================================
		if($num > $this->Limit)
		{
			$nav_categ = (isset($_REQUEST['catid'] ) && !empty($_REQUEST['catid'])) ? "&amp;catid=" . @$_REQUEST['catid'] : '&amp;catid=0';
			$nav_t     = '';
			$GLOBALS['tmpl']->assign('pages', pagenav($seiten, '', 
			"<a class=\"page_navigation\" href=\"index.php?p=articles&amp;area=".AREA."{$nav_categ}{$nav_t}&amp;page={s}{$nav_search_title}&amp;limit=" . $this->Limit . "\">{t}</a> "));
		}
		
		//=================================================================
		// Die eigentliche Abfrage der News
		//=================================================================
		$q = "SELECT 
			Id,
			Kategorie,
			Typ,
			Wertung,
			Kennwort,
			Zeit,
			ZeitStart,
			Autor,
			Hits,
			Sektion,
			Topartikel,
			BildAusrichtung,
			Bild_{$Lc} AS Bild,
			Titel_{$Lc} AS Titel,
			Untertitel_{$Lc} AS Intro,
			Inhalt_{$Lc} AS News,
			Titel_1 AS DefTitel,
			Inhalt_1 AS DefNews,
			Untertitel_1 AS DefIntro 
		FROM " . PREFIX . "_artikel 
		WHERE 
			{$tbetween}  
			(ZeitEnde >= " . stime() . " OR ZeitEnde = 0) AND 
			(Sektion = '". AREA . "' OR AlleSektionen = 1) AND 
			Aktiv = '1'  
			{$db_type} 
			{$db_categ}  
			{$db_title_search} 
		ORDER 
			BY Id DESC 
		LIMIT 
			$a, " . $this->Limit;
		$sql = $GLOBALS['db']->Query($q);
		
		$User = new User;
		
		while($row = $sql->fetcharray())
		{
			switch($row['Typ'])
			{
				case 'review':
					$row['TypLink'] = "index.php?p=articles&amp;area=".$row['Sektion']."&amp;type=reviews";
					$row['TypName'] = $GLOBALS['config_vars']['Gaming_articles_reviews'];
				break;
				
				case 'preview':
					$row['TypLink'] = "index.php?p=articles&amp;area=".$row['Sektion']."&amp;type=previews";
					$row['TypName'] = $GLOBALS['config_vars']['Gaming_articles_previews'];
				break;
				
				case 'special':
					$row['TypLink'] = "index.php?p=articles&amp;area=".$row['Sektion']."&amp;type=specials";
					$row['TypName'] = $GLOBALS['config_vars']['Gaming_articles_specials'];
				break;
			}
			
			$row['Thumb'] = '';
			if($row['Bild']!='')
			{
				$row['Thumb'] = str_replace('%%ECRUOS_GMI_IBOOK%%','',$row['Bild']);
				if(file_exists(BASE_DIR . '/' . $row['Thumb'])) 
				{
					$endg = substr($row['Thumb'],-4);
					$name = substr($row['Thumb'],0,-4);
					$row['Thumb'] = (file_exists(BASE_DIR . '/cache/' . md5('content_' . $row['Thumb']) . $endg)) ? "cache/" . md5('content_' . $row['Thumb']) . $endg :  "system/content_thumb.php?img=" . $row['Thumb'];
				}
			}
			
			$row['Titel'] = ($row['Titel']=='') ? $row['DefTitel'] : $row['Titel'];
			$row['Intro'] = ($row['Intro']=='') ? $row['DefIntro'] : $row['Intro'];
			$row['News']  = ($row['News']=='') ? $row['DefNews'] : $row['News'];
			$row['News'] = eregi_replace("\[SCREEN:([a-zA-Z0-9\\\/\_\.\]*)\]", "", $row['News']);
			$row['News'] = eregi_replace("\[CONTACT:([a-zA-Z0-9\\\/\_\.\]*)\]", "", $row['News']);
			$row['News'] = eregi_replace("\[--NEU--\]", "", $row['News']);
			$row['News'] = strip_tags($row['News'],$this->_allowed_html);
			$row['LinkTitle'] = seotitle($row['Titel']);
			$row['User'] = $User->getNameById($row['Autor']);
			array_push($news, $row);
		}
		
		$news_categs = array();
		$dropdown = $this->getArticleCategs(0, "", $news_categs, $_SESSION['Area']);
		$GLOBALS['tmpl']->assign("dropdown", $dropdown);
		
		
		//=================================================================
		// Seitenkopf-Navigationsbaum
		//=================================================================  
		if(isset($_REQUEST['categ']) && !empty($_REQUEST['categ']))
		{
			$headernav = getNavigationPath($_REQUEST['categ'], 'news_kategorie', 'newsarchive', 'categ', 'Id', 'Name_1', '', '', '', '', 'Parent_Id',$GLOBALS['config_vars']['Newsarchive']);
			$pagetitle = clean_page_title($headernav, $row['Titel']);
			
		} else {
			$headernav = ($archive==1) ? $GLOBALS['config_vars']['Newsarchive'] : '';
			$pagetitle = ($archive==1) ? $GLOBALS['config_vars']['Newsarchive'] : '';
		}
		
		if($rss==1)
		{
			if(permission('news_rss'))
			{

				header("Content-Type: text/xml");
				header("Cache-Control: no-cache");
				header("Pragma: no-cache");
				
				$rss = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n";
				$rss .= "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\" xmlns:wfw=\"http://wellformedweb.org/CommentAPI/\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\">";
				$rss .= "<channel>";
				$rss .= "<title>" . $pagetitle . "</title>\n";
				$rss .= "<link>" . redir() . "</link>\n";
				$rss .= "<description>powered by koobi-rss / http://".$_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . "</description>\n";
				$rss .= "<generator>http://www.koobi.de/</generator>\n";
				$rss .= "<language></language>\n";
				
				
				foreach($news as $n)
				{
					if($n['Kennwort']=='')
					{
						$rss .= "<item>\n";
						$rss .= "<title>" . specialchars_for_rss(stripslashes($n['Titel'])) . "</title>\n";
						$rss .= "<link>http://".$_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . "?p=articles&amp;area=$n[Sektion]&amp;action=displayarticle&amp;id=$n[Id]&amp;name=" . seotitle($n['Titel']) . "</link>\n";
						$rss .= "<description><![CDATA[" . substr(specialchars_for_rss(stripslashes($n['News'])),0,400) . "...]]></description>\n";
						$rss .= "<content:encoded><![CDATA[" . specialchars_for_rss(stripslashes($n['News'])) . "]]></content:encoded>\n";
						$rss .= "</item>\n";
					}
				}
				$rss .= " </channel>\n";
				$rss .= "</rss>\n";
				
				header("Content-Length: " . strlen($rss));
			
				
				define("NOOUT", 1);
				define("OUTPUT", $rss);
				if($GLOBALS['settings']['use_seo'] == 1)
				{
					//include_once('functions/Func.Rewrite.php');
					//$rss = Seo($rss);
				}
				echo $rss;
				exit;
			} else {
				noperm();
			}
		} else {
			setMeta($GLOBALS['config_vars']['Gaming_articles'],$GLOBALS['config_vars']['Gaming_articles']);
			$GLOBALS['tmpl']->assign('rssfeed_link', 'index.php?p=articles&amp;area='.AREA.'&amp;mode=rss');
			$GLOBALS['tmpl']->assign('rssfeed_title', $GLOBALS['config_vars']['Gaming_articles']);
			$GLOBALS['tmpl']->assign('pagetitle_html', $GLOBALS['config_vars']['Gaming_articles']);
			$GLOBALS['tmpl']->assign('headernav', $GLOBALS['config_vars']['Gaming_articles']);
			$GLOBALS['tmpl']->assign('articlesitems', $news);
			$GLOBALS['tmpl']->assign('content', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/gaming/articles_archive.tpl')); 	
		}
	}
	
	function displayArticle($artid,$noout=0)
	{
		if(permission('articles'))
		{
			$Lc = $_SESSION['Langcode'];
			$sql = $GLOBALS['db']->Query("
			SELECT 
				*,
				Bild_{$Lc} AS Bild,
				Titel_{$Lc} AS Titel,
				Untertitel_{$Lc} AS Intro,
				Inhalt_{$Lc} AS News,
				Titel_1 AS DefTitel,
				Inhalt_1 AS DefNews,
				Untertitel_1 AS DefIntro 
			FROM 
				" . PREFIX . "_artikel 
			WHERE
				Id = '$artid' AND 
				Aktiv = '1' AND
				Sektion = '" . $_SESSION['area'] . "' AND 
				ZeitStart <= '" . stime() . "'");
			$row = $sql->fetcharray();
			
			$Abgelaufen = ($row['ZeitEnde'] > 1 && $row['ZeitEnde'] < stime()) ? 1 : 0;
			
			if(is_array($row) && $Abgelaufen!=1)
			{
				
				//=================================================================
				// Ist Dokument kennwortgeschuetzt?
				//=================================================================
				if(isset($_POST['Artikel_Kennwort_' . $row['Id']]) && $_POST['Artikel_Kennwort_' . $row['Id']] == $row['Kennwort'])
				{
					$_SESSION['Artikel_Kennwort_' . $row['Id']] = $row['Kennwort'];
				}
				
				// Login?
				if($row['Kennwort']!='' && (@$_SESSION['Artikel_Kennwort_' . $row['Id']] != $row['Kennwort']))
				{
					$GLOBALS['tmpl']->assign('res', $row);
					$GLOBALS['tmpl']->assign('content', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/gaming/article_login.tpl'));
				} else {
					$row['Titel']     = ($row['Titel']=='') ? $row['DefTitel'] : $row['Titel'];
					$row['Intro']     = ($row['Intro']=='') ? $row['DefIntro'] : $row['Intro'];
					$row['News']      = ($row['News']=='') ? $row['DefNews'] : $row['News'];
					$row['News']      = (!empty($row['Textbilder_' . $_SESSION['Langcode']])) ? inlinescreens($row['Textbilder_' . $_SESSION['Langcode']], $row['News']) : $row['News'];
					$row['News']      = inlineContactform($row['News']);
					$row['News']      = cleanEmptyTags($row['News']);
					$row['News']      = autowords($row['News']);
					$row['LinkTitel'] = seotitle($row['Titel']);
					$row['User']      = getUsername($row['Autor']);
					$row['Top']       = ($row['Top']!='') ? explode("\r\n",strip_tags($row['Top'])) : '';
					$row['Flop']      = ($row['Flop']!='') ? explode("\r\n",strip_tags($row['Flop'])) : '';
					$row['Minimum']   = ($row['Minimum']!='') ? explode("\r\n",strip_tags($row['Minimum'])) : '';
					$row['Optimum']   = ($row['Optimum']!='') ? explode("\r\n",strip_tags($row['Optimum'])) : '';
					$row['Genre']     = ($row['Genre']!='') ? $this->getGenre($row['Genre'] ) : '';
					$row['Plattform'] = ($row['Plattform']!='') ? $this->getPlattform($row['Plattform']) : '';
					$row['ManLink']   = $this->GetManufacturer($row['Hersteller']);
					$row['PubLink']   = $this->GetManufacturer($row['Vertrieb']);
					$row['ShopArtikel'] = ($row['ShopArtikel']!='') ? $this->getShopArticle($row['ShopArtikel']) : '';
					
					switch($row['Typ'])
					{
						case 'review':
							$row['TypName'] = $GLOBALS['config_vars']['Gaming_articles_reviews'];
						break;
						
						case 'preview':
							$row['TypName'] = $GLOBALS['config_vars']['Gaming_articles_previews'];
						break;
						
						case 'special':
							$row['TypName'] = $GLOBALS['config_vars']['Gaming_articles_specials'];
						break;
					}
				
					// Wertungs-Daten
					if($row['WertungsDaten'])
					{
						$datas = array();
						$dataval = explode("\r\n", $row['WertungsDaten']);
						$i=1;
						foreach($dataval as $m)
						{
							$mi = '';
							$det = explode(";",$m);
							
							if(!empty($det[1]))
							{
								$mi->Wert = $det[1];
								$mi->Name = $det[0];
								$mi->Id = $i++;
								array_push($datas, $mi);
								@$all = $det[1]+=$all;
							}
						}
						
						$all_datas = $i-1;
						$max_points = $all_datas * 5;
						$erg_ges = number_format(round($all/$all_datas,2),1,'.','');
					
						$GLOBALS['tmpl']->assign('Ges', (($all*100) / $max_points));
						$GLOBALS['tmpl']->assign('DataVal', $datas);
					}
					
					// Links 
					if($row['Links']!='')
					{
						$alternatives = array();
						$links = explode("\r\n", $row['Links']);
						$i=1;
						foreach($links as $m)
						{
							$mi = '';
							$det = explode(";",$m);
							$mi->Id = $i++;
							$mi->Link = $det[0];
							$mi->Name = $det[1];
							array_push($alternatives, $mi);
						}
						$GLOBALS['tmpl']->assign('LinksExtern', $alternatives);
					}
					
					//=================================================================
					// Interne Seiten
					//=================================================================
					$_REQUEST['artpage'] = (isset($_REQUEST['artpage']) && $_REQUEST['artpage'] != '' && $_REQUEST['artpage'] >= 1) ? cleanInt($_REQUEST['artpage']) : 1;
					$seite_anzeigen = explode("[--NEU--]", $row['News']);
					$anzahl_seiten = count($seite_anzeigen);
					
					if($_REQUEST['artpage'] > $anzahl_seiten)
					{
						$_REQUEST['artpage'] = $anzahl_seiten;
						$row['News'] = $seite_anzeigen[$anzahl_seiten-1];
					} else {
						$row['News'] = $seite_anzeigen[@$_REQUEST['artpage']-1];
					}
					
					//=================================================================
					// Galerien enthalten?
					//=================================================================
					if($row['Galerien']!='')
					{
						if(file_exists(BASE_DIR . '/class/Class.Gallery.php') && get_active('gallery'))
						{
							include_once(BASE_DIR . '/class/Class.Gallery.php');
							$Gallery = new Gallery;
							$GLOBALS['tmpl']->assign('IncludedGalleries', $Gallery->getExtenGallery($row['Galerien'],'galleries_included_1row.tpl'));
						}
					}
					
					
					//=================================================================
					// Eventuelle News verknuepfen
					//=================================================================
					if($row['Tags']!='' && get_active('News'))
					{
						$news = new News;
						$GLOBALS['tmpl']->assign('IncludedNews', $news->includedNews($row['Tags']));
					}
					
					//=================================================================
					// Moegliche Artikel verknuepfen
					//=================================================================
					$GLOBALS['tmpl']->assign('IncludedArticles', $this->includedArticles($row['Tags'],$row['Id']));
					
					//=================================================================
					// Moegliche Dokumente verknuepfen
					//=================================================================
					if(file_exists(BASE_DIR . '/class/Class.Content.php') && get_active('content'))
					{
						include_once(BASE_DIR . '/class/Class.Content.php');
						$Content = new Content;
						$GLOBALS['tmpl']->assign('IncludedContent', $Content->includedContent($row['Tags']));
					}
					
					//=================================================================
					// Wenn mehrere Seiten vorhanden sind, Navi erzeugen
					//=================================================================
					if($anzahl_seiten>1)
					{
						$article_pages = artpage($anzahl_seiten, $_REQUEST['artpage'], " <a class=\"page_navigation\" href=\"index.php?p=articles&amp;area=" . AREA . "&amp;action=displayarticle&amp;id={$artid}&amp;name="  . $row['LinkTitel'] . "&amp;artpage={s}\">{t}</a> ");
						$GLOBALS['tmpl']->assign('article_pages', $article_pages);
					}
					
				
				
					//=================================================================
					// Kommentare
					//=================================================================
					if($row['Kommentare'] == 1)
					{
						$comment = new Comments;
						// Kommentar bearbeiten
						if(isset($_POST['comment_action']) && $_POST['comment_action'] == 'edit' && permission('edit_comments')) $comment->EditComment('articles',$_POST['comment_id']);
						
						// Neuer Kommentar
						if(permission('comments'))
						{
							$comment->NewComment('articles', @$_POST['Redir'],$row['Id']);
						}
						
						// Kommentare holen
						$Comments = $comment->GetComments('articles',$row['Id'],'index.php?p=articles&amp;area='.AREA.'&amp;id=' . $row['Id'] . '&amp;name=' . seotitle($row['Titel']));
						$GLOBALS['tmpl']->assign('GetComments',$GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/comments/comments.tpl'));
					}
					
					// Wertung
					if($row['Wertung']==1)
					{
						$row['Bewertung'] = 1;
						$row['Wertung'] = getRating($row['Id'],'articles');
						$GLOBALS['tmpl']->assign('RatingUrl', 'index.php?p=rating&action=rate&id=' . $row['Id'] . '&where=articles');
						$GLOBALS['tmpl']->assign('RatingForm', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/other/rating.tpl')); 
					}
					//=================================================================
					// Seitenkopf-Navigationsbaum
					//=================================================================
					$headernav = (!is_array($row)) ? '' : $headernav = '<a href="index.php?p=articles&amp;area=' . AREA . '">' . $GLOBALS['config_vars']['Gaming_articles'] . '</a>' . getNavigationPath($row['Kategorie'], 'artikel_kategorie', 'articles&amp;area=' . AREA, 'catid', 'Id', 'Name_' . $_SESSION['Langcode'], '', '', '', '', 'Parent_Id');
					
					setMeta($row['Titel'],$row['News']);
					$GLOBALS['tmpl']->assign('row', $row);
					$GLOBALS['tmpl']->assign('pagetitle_html', clean_page_title($headernav, $row['Titel']));
					$GLOBALS['tmpl']->assign('pagetitle', stripslashes($row['Titel']));
					$GLOBALS['tmpl']->assign('headernav', $headernav);
					$GLOBALS['tmpl']->assign('row', $row);
					$GLOBALS['tmpl']->assign('content', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/gaming/article_show.tpl'));
					
					if(!isset($_SESSION['nr'][$artid]))
					{
						$GLOBALS['db']->Query("UPDATE " . PREFIX . "_artikel SET Hits = Hits+1 WHERE Id = '{$artid}'");
						$_SESSION['nr'][$artid] = 1;
					}
				} 
			} else {
				refer('index.php?p=articles&area=' . AREA);
			}
		} else {
			noperm();
		}
	}
	
	function includedArticles($tags='',$artid=0)
	{
		$tagcheck = $tags;
		
		$Lc = $_SESSION['Langcode'];
		$tags = explode(',', $tags);
		$found_news = array();
		
		$tags = array_unique($tags);
		$where_not = ($artid!=0) ? "AND Id != '$artid'" : "";
		
		if($tagcheck!='')
		{
			foreach($tags as $tag=>$word)
			{
				$row = '';
				$res_q = $GLOBALS['db']->Query("
				SELECT 
					Id,
					ZeitStart,
					Kategorie,
					Autor,
					Inhalt_{$Lc} as News,
					Titel_{$Lc} as Titel 
				FROM 
					" . PREFIX . "_artikel
				WHERE
					Aktiv = '1' AND
					Sektion = '" . $_SESSION['area'] . "' AND 
					ZeitStart <= '" . stime() . "'  AND 
					(Tags LIKE '%$word%') {$where_not} ORDER BY Id DESC LIMIT 15
				");
				
				while($row = $res_q->fetcharray())
				{
					$row['Titel'] = ($row['Titel']=='') ? $row['DefTitel'] : $row['Titel'];
					$row['News']  = ($row['News']=='') ? $row['DefNews'] : $row['News'];
					$row['News'] = eregi_replace("\[SCREEN:([a-zA-Z0-9\\\/\_\.\]*)\]", "", $row['News']);
					$row['User'] = getUsername($row['Autor']);
					if(!in_array($row,$found_news)) array_push($found_news, $row);
				}
			}
			
			$GLOBALS['tmpl']->assign('externArticles',$found_news);
			return $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/gaming/articles_extern.tpl');
		}
	}
	
	
	function getArticleCategs($id, $prefix, &$news_categ, &$area)
	{
		switch(@$_REQUEST['type'])
		{
			case '':
			default:
				$TypArchive = '';
			break;
			
			case 'reviews':
				$TypArchive = '&amp;type=reviews';
			break;
			
			case 'previews':
				$TypArchive = '&amp;type=previews';
			break;
			
			case 'specials':
				$TypArchive = '&amp;type=specials';
			break;
		}
		$query = $GLOBALS['db']->Query("SELECT *, Name_" . $_SESSION['Langcode'] . " AS Name FROM " . PREFIX . "_artikel_kategorie WHERE Parent_Id = '$id' AND Sektion = '$area' ORDER BY POSI ASC");
		if (!$query->numrows()) 
		{
			return;
		} 
		
		while ($item = $query->fetchrow())
		{
			$item->visible_title = $prefix . " " . $item->Name;
			$item->HLink = "index.php?p=articles&amp;area={$item->Sektion}{$TypArchive}&amp;catid={$item->Id}&amp;name=" . seotitle($item->Name);
			array_push($news_categ, $item);
			$this->getArticleCategs($item->Id, $prefix . " - ", $news_categ, $area);
		} 
		return $news_categ;
	}
	
	
	
	
	function CheatGetFile($id)
	{
		if(strpos(@$_SERVER['HTTP_REFERER'], HOME_PATH)!==false && permission('cheats_candownload'))
		{
			$res = $GLOBALS['db']->RowQuery("SELECT Download AS Url FROM " . PREFIX . "_cheats WHERE Id='$id' AND Aktiv='1'");
			if(!is_object($res) || !@file_exists(BASE_DIR . '/uploads/cheats_files/' . $res->Url))
			{
				
				$GLOBALS['tmpl']->assign('jumpback', @$_SERVER['HTTP_REFERER']);
				$GLOBALS['tmpl']->assign('content', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/downloads/notfound.tpl')); 
			} else {
				$GLOBALS['db']->Query("UPDATE " . PREFIX . "_cheats SET DownloadHits=DownloadHits+1 WHERE Id='$id' AND Aktiv='1'");
				ob_start();
				header("Cache-control: private");
				header("Content-type: application/octet-stream"); 
				header("Content-disposition:attachment; filename=" . $res->Url);
				@$this->DL_ReadFile(BASE_DIR . '/uploads/cheats_files/' . $res->Url);
				exit;
			}
		} else {
			refer('index.php?p=cheats&area=' . AREA);
		}
	}
	
	
	function DL_ReadFile($filename,$retbytes=true)
	{
		$chunksize = 1*(1024*1024); 
		$buffer = '';
		$cnt =0;
		
		$handle = fopen($filename, 'rb');
		if ($handle === false)
		{
		   return false;
		}
		while (!feof($handle))
		{
		   $buffer = fread($handle, $chunksize);
		   echo $buffer;
		   flush();
		   if ($retbytes) {
			   $cnt += strlen($buffer);
		   }
		}
		   $status = fclose($handle);
		if ($retbytes && $status)
		{
		   return $cnt; 
		}
		return $status;
	}
	
	//=================================================================
	// Hitcount erhoehen
	//=================================================================
	function Updatehitcount($id)
	{
		// Nur erhoehen, wenn Click von gleicher Seite
		if(strpos(@$_SERVER['HTTP_REFERER'], HOME_PATH)!==false)
		{
			$GLOBALS['db']->Query("UPDATE " . PREFIX . "_downloads Set Hits=Hits+1 WHERE Id='" . abs((int)$id) . "'");
		}
	}
	
	
	
	
	
	
	
	
	
	
}

?>