<?php
class Gaming
{
	//==================================================================================================================================
	// Artikel
	//==================================================================================================================================
	function DelRatingArticles($id)
	{	
		$GLOBALS['db']->Query("DELETE FROM " . PREFIX . "_wertung WHERE Bereich='articles' AND Objekt_Id='{$id}'");
		Logger('User ' . $_SESSION['user_name'] . ' delete Article-Rating', '3', $_SESSION['benutzer_id']);
		echo "<script>window.opener.location.reload(); window.close();</script>";
	}
	
	//=================================================================
	// Artikel-Kategorie bearbeiten
	//=================================================================
	function EditArticleCateg($id)
	{
		if(perm('articles_category'))
		{
			// Speichern
			if(isset($_POST['save']) && $_POST['save']==1)
			{
				$Name_1 = $_POST['Name_1'];
				$Name_2 = (isset($_POST['Name_2']) && $_POST['Name_2']!='') ? $_POST['Name_2'] : $_POST['Name_1'];
				$Name_3 = (isset($_POST['Name_3']) && $_POST['Name_3']!='') ? $_POST['Name_3'] : $_POST['Name_1'];
				
				$GLOBALS['db']->Query("UPDATE " . PREFIX . "_artikel_kategorie 
				SET 
					Name_1 = '$Name_1',
					Name_2 = '$Name_2',
					Name_3 = '$Name_3' 
				WHERE Id='$id'");
				
				echo "<script>window.opener.location.reload(); window.close();</script>";
			}
			
			$res = $GLOBALS['db']->RowQuery("SELECT * FROM " . PREFIX . "_artikel_kategorie  WHERE Id='$id'");
			$GLOBALS['tmpl']->assign('res', $res);
			$GLOBALS['tmpl']->assign('newscategs', $this->ACategs());
			$GLOBALS['tmpl']->assign('title', $GLOBALS['config_vars']['Global_CategEdit']); 
			$GLOBALS['tmpl']->assign('content', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/gaming/article_categ.tpl'));
		} else {
			no_perm();
		}
	}
	
	//=================================================================
	// Artikel-Kategorie anlegen
	//=================================================================
	function AddArticleCateg()
	{
		if(perm('articles_category'))
		{
			// Speichern
			if(isset($_POST['save']) && $_POST['save']==1)
			{
				$Name_1 = $_POST['Name_1'];
				$Name_2 = (isset($_POST['Name_2']) && $_POST['Name_2']!='') ? $_POST['Name_2'] : $_POST['Name_1'];
				$Name_3 = (isset($_POST['Name_3']) && $_POST['Name_3']!='') ? $_POST['Name_3'] : $_POST['Name_1'];
				
				$GLOBALS['db']->Query("INSERT INTO " . PREFIX . "_artikel_kategorie 
				(
					Id,
					Parent_Id,
					Name_1,
					Name_2,
					Name_3,
					Sektion
				) VALUES (
					'',
					'$_POST[categ]',
					'$Name_1',
					'$Name_2',
					'$Name_3',
					'$_SESSION[a_area]'
				)");
				
				echo "<script>window.opener.location.reload(); window.close();</script>";
			}
			
			$GLOBALS['tmpl']->assign('new', 1);
			$GLOBALS['tmpl']->assign('newscategs', $this->ACategs());
			$GLOBALS['tmpl']->assign('title', $GLOBALS['config_vars']['Global_CategEdit']); 
			$GLOBALS['tmpl']->assign('content', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/gaming/article_categ.tpl'));
		} else {
			no_perm();
		}
	}
	
	//=================================================================
	// Artikel-Kategorie loeschen
	//================================================================
	function DelArticleCateg($id)
	{
		$query = $GLOBALS['db']->Query("SELECT Id, Parent_Id FROM " . PREFIX . "_artikel_kategorie  WHERE Parent_Id=$id");
		while ($item = $query->fetchrow()) 
		{
			// News-kommentare loschen
			$sql = $GLOBALS['db']->Query("SELECT Id FROM " . PREFIX . "_artikel WHERE Kategorie='$id'");	
			while($row = $sql->fetchrow())
			{
				$GLOBALS['db']->Query("DELETE FROM " . PREFIX . "_kommentare WHERE Bereich='articles' AND Objekt_Id='$row->Id'");	
			}
			// News loschen
			$GLOBALS['db']->Query("DELETE FROM " . PREFIX . "_artikel WHERE Kategorie='$id'");		
			// <<--Rekursion -->>
			$this->DelArticleCateg($item->Id);
		}
		
		// News loeschen
		
		$GLOBALS['db']->Query("DELETE FROM " . PREFIX . "_artikel_kategorie WHERE Id='$id'");			
		$GLOBALS['db']->Query("DELETE FROM " . PREFIX . "_artikel WHERE Kategorie='$id'");
	}
	
	function ArticleCategs()
	{
		if(perm('news_category'))
		{
			$GLOBALS['tmpl']->assign('newscategs', $this->ACategs());
			$GLOBALS['tmpl']->assign('title', $GLOBALS['config_vars']['Gaming_articles_category']); 
			$GLOBALS['tmpl']->assign('content', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/gaming/article_categs.tpl'));
		} else {
			no_perm();
		}
	}
	//=================================================================
	// Alle Artikel anzeigen
	//=================================================================
	function showArticles()
	{
		$def_order    = 'ORDER BY Id DESC';
		$def_order_n  = '';
		$def_search   = '';
		$def_status   = '';
		$def_status_n = '';
		$def_categ    = '';
		$def_categ_n  = '';
		$def_search_n = '';
		$def_datetill = '';
		$def_datetill_n = '';
		$def_top      = '';
		$def_top_n    = '';
		$def_typ      = '';
		$def_typ_n    = '';
		$def_hits     = '';
		$def_hits_n   = '';
		$news         = array();
		$area         = $_SESSION['a_area'];
		$limit        = GetLimit();
		
		// Schnellspeichern
		if(isset($_POST['quicksave']) && $_POST['quicksave']==1)
		{
			foreach($_POST['nid'] as $cat => $nid)
			{
				 $GLOBALS['db']->Query("UPDATE " . PREFIX . "_artikel 
				 SET 
				 	Topartikel = '" . $_POST['Topartikel'][$nid] . "', 
					Kategorie = '" . $_POST['Kategorie'][$nid] . "',
					Typ = '" . $_POST['Typ'][$nid] . "' 
				WHERE Id='$nid'");
			}
			Logger('User ' . $_SESSION['user_name'] . ' update Articles', '3', $_SESSION['benutzer_id']);
		}
		
		
		// Multiaktionen
		if(isset($_POST['multi']) && $_POST['multi']!='' && isset($_SESSION['ArticlesSearch']) && perm('articles_multioptions'))
		{
			switch($_POST['multiaction'])
			{
				case 'movecateg':$GLOBALS['db']->Query("UPDATE " . PREFIX . "_artikel SET Kategorie='" . $_POST['newcateg'] . "' " . $_SESSION['ArticlesSearch'] . " AND Sektion='{$area}'");break;
				case 'open': $GLOBALS['db']->Query("UPDATE " . PREFIX . "_artikel SET Aktiv='1' " . $_SESSION['ArticlesSearch'] . " AND Sektion='{$area}'");break;
				case 'close':$GLOBALS['db']->Query("UPDATE " . PREFIX . "_artikel SET Aktiv='0' " . $_SESSION['ArticlesSearch'] . " AND Sektion='{$area}'");break;
				case 'delete':$GLOBALS['db']->Query("DELETE FROM " . PREFIX . "_artikel " . $_SESSION['ArticlesSearch'] . " AND Sektion='{$area}'");break;
			}
			$GLOBALS['tmpl']->assign('multi_done',1);
		} else {
			unset($_SESSION['ArticlesSearch']);
		}
		
		// Typ
		if(isset($_REQUEST['typ']) && $_REQUEST['typ']!='' && ($_REQUEST['typ']=='special' || $_REQUEST['typ']=='review' || $_REQUEST['typ']=='preview'))
		{
			$def_typ = "AND Typ = '" . $_REQUEST['typ'] . "'";
			$def_typ_n = "&amp;typ=" . $_REQUEST['typ'];
		}
		
		// Topartikel?
		if(isset($_REQUEST['top']) && $_REQUEST['top']!='')
		{
			$def_top = "AND Topartikel = '" . abs((int)$_REQUEST['top']) . "'";
			$def_top_n = "&amp;categ=" . abs((int)$_REQUEST['top']);
		}
		
		// Kategorie
		if(isset($_REQUEST['categ']) && $_REQUEST['categ']!='0')
		{
			$def_categ = "AND Kategorie = '" . abs((int)$_REQUEST['categ']) . "'";
			$def_categ_n = "&amp;categ=" . abs((int)$_REQUEST['categ']);
		}
		
		// Hits
		if(isset($_REQUEST['hits_from']) && isset($_REQUEST['hits_to']) && $_REQUEST['hits_from']<$_REQUEST['hits_to'])
		{
			$def_hits = "AND (Hits BETWEEN '" . abs((int)$_REQUEST['hits_from']) . "' AND '" . abs((int)$_REQUEST['hits_to']) . "')";
			$def_hits_n = "&amp;hits_from=" . abs((int)$_REQUEST['hits_from']) . "&amp;hits_to=" . abs((int)$_REQUEST['hits_to']);
		}
		
		// Status
		if(isset($_REQUEST['aktiv']) && $_REQUEST['aktiv']!='')
		{
			$def_status = "AND Aktiv = '" . abs((int)$_REQUEST['aktiv']) . "'";
			$def_status_n = "&amp;aktiv=" . abs((int)$_REQUEST['aktiv']);
		}
		
		// Datum erstellt bis
		if(!empty($_REQUEST['date_till']) && !empty($_REQUEST['date_till']))
		{
			$lafrom = @explode('.',$_REQUEST['date_till']);
			$lafrom = @mktime(23,59,59,$lafrom[1],$lafrom[0],$lafrom[2]);
			
			if($lafrom)
			{
				$def_datetill = " AND (Zeit <= $lafrom) ";
				$def_datetill_n = "&amp;date_till=" . $_REQUEST['date_till'];
			}
		}
		
		
		// Suche wurde gestartet...
		if(isset($_REQUEST['q']) && !empty($_REQUEST['q']) && strlen($_REQUEST['q'])>=1)
		{
			$q = trim(preg_replace('/([^-A-Za-zÀ-ÖØ-öø-ÿ0-9.@ ]*)/', '', $_REQUEST['q']));
			$_REQUEST['q'] = $q;
			
			$def_search = " 
			AND (
				Titel1 LIKE '%$q%' OR 
				Titel2 LIKE '%$q%' OR 
				Titel3 LIKE '%$q%' 
			)";
			$def_search_n = "&amp;q={$q}";
		}
		
		// Sortierungen
		if(isset($_REQUEST['sort']))
		{
			$curr_page = ((isset($_REQUEST['page'])) ? '&page=' . abs((int)($_REQUEST['page'])) : '&amp;page=1');
			
			switch($_REQUEST['sort'])
			{
				case 'name_asc' : 
					$def_order    = ' ORDER BY Titel_1 ASC';
					$def_order_n  = '&sort=name_asc' . $curr_page;
					$def_order_ns = '&sort=name_desc' . $curr_page;
					$GLOBALS['tmpl']->assign('name_s',$def_order_ns);
				break;
				
				case 'name_desc': 
					$def_order    = ' ORDER BY Titel_1 DESC'; 
					$def_order_n  = '&sort=name_desc' . $curr_page;
					$def_order_ns = '&sort=name_asc' . $curr_page;
					$GLOBALS['tmpl']->assign('name_s',$def_order_ns);
				break;
				
				case 'username_asc' : 
					$def_order    = ' ORDER BY Autor ASC';
					$def_order_n  = '&sort=username_asc' . $curr_page;
					$def_order_ns = '&sort=username_desc' . $curr_page;
					$GLOBALS['tmpl']->assign('username_s',$def_order_ns);
				break;
				
				case 'username_desc' : 
					$def_order    = ' ORDER BY Autor DESC';
					$def_order_n  = '&sort=username_desc' . $curr_page;
					$def_order_ns = '&sort=username_asc' . $curr_page;
					$GLOBALS['tmpl']->assign('username_s',$def_order_ns);
				break;
				
				
				case 'date_asc' : 
					$def_order    = ' ORDER BY Zeit ASC';
					$def_order_n  = '&sort=date_asc' . $curr_page;
					$def_order_ns = '&sort=date_desc' . $curr_page;
					$GLOBALS['tmpl']->assign('date_s',$def_order_ns);
				break;
				
				case 'date_desc' : 
					$def_order    = ' ORDER BY Zeit DESC';
					$def_order_n  = '&sort=date_desc' . $curr_page;
					$def_order_ns = '&sort=date_asc' . $curr_page;
					$GLOBALS['tmpl']->assign('date_s',$def_order_ns);
				break;
				
				
				case 'start_asc' : 
					$def_order    = ' ORDER BY ZeitStart ASC';
					$def_order_n  = '&sort=start_asc' . $curr_page;
					$def_order_ns = '&sort=start_desc' . $curr_page;
					$GLOBALS['tmpl']->assign('start_s',$def_order_ns);
				break;
				
				case 'start_desc' : 
					$def_order    = ' ORDER BY ZeitStart DESC';
					$def_order_n  = '&sort=start_desc' . $curr_page;
					$def_order_ns = '&sort=start_asc' . $curr_page;
					$GLOBALS['tmpl']->assign('start_s',$def_order_ns);
				break;
				
				case 'end_asc' : 
					$def_order    = ' ORDER BY ZeitEnde ASC';
					$def_order_n  = '&sort=end_asc' . $curr_page;
					$def_order_ns = '&sort=end_desc' . $curr_page;
					$GLOBALS['tmpl']->assign('end_s',$def_order_ns);
				break;
				
				case 'end_desc' : 
					$def_order    = ' ORDER BY ZeitEnde DESC';
					$def_order_n  = '&sort=end_desc' . $curr_page;
					$def_order_ns = '&sort=end_asc' . $curr_page;
					$GLOBALS['tmpl']->assign('end_s',$def_order_ns);
				break;
				
				case 'hits_asc' : 
					$def_order    = ' ORDER BY Hits ASC';
					$def_order_n  = '&sort=hits_asc' . $curr_page;
					$def_order_ns = '&sort=hits_desc' . $curr_page;
					$GLOBALS['tmpl']->assign('hits_s',$def_order_ns);
				break;
				
				case 'hits_desc' : 
					$def_order    = ' ORDER BY Hits DESC';
					$def_order_n  = '&sort=hits_desc' . $curr_page;
					$def_order_ns = '&sort=hits_asc' . $curr_page;
					$GLOBALS['tmpl']->assign('hits_s',$def_order_ns);
				break;
				
			}
		}
		
		$sql = $GLOBALS['db']->Query("SELECT Id FROM " . PREFIX . "_artikel WHERE Sektion='{$area}' {$def_search} {$def_categ} {$def_status} {$def_top} {$def_hits} {$def_typ} {$def_datetill}");
		
		$num = $sql->numrows();
		$seiten = ceil($num / $limit);
		$a = prepage() * $limit - $limit;
		$q = "SELECT *,Titel_1 AS Titel1 FROM " . PREFIX . "_artikel WHERE Sektion='{$area}' {$def_search} {$def_status} {$def_categ} {$def_top}  {$def_hits} {$def_typ} {$def_datetill} {$def_order} LIMIT $a,$limit";
		$sql = $GLOBALS['db']->Query($q);
		while($row=$sql->fetchrow())
		{
			$row->Comments = getCommentCount('articles', $row->Id);
			$row->User = getUsername($row->Autor);
			$row->Wertung = getRating($row->Id,'articles');
			array_push($news,$row);
		}
		
		$ordstr = "index.php?do=gaming&amp;sub=articles{$def_search_n}{$def_status_n}{$def_categ_n}&amp;pp={$limit}{$def_hits_n}{$def_datetill_n}{$def_typ_n}{$def_top_n}";
		$nastr = "{$def_order_n}{$def_search_n}{$def_status_n}{$def_categ_n}&amp;pp={$limit}{$def_hits_n}{$def_datetill_n}{$def_typ_n}{$def_top_n}";
		
		if(isset($_POST['startsearch']) && $_POST['startsearch']==1) 
		{
			$_SESSION['ArticlesSearch'] = "WHERE Id!='0' {$def_search} {$def_status} {$def_categ} {$def_hits} {$def_datetill}";
		}
	
		$GLOBALS['tmpl']->assign('ordstr',$ordstr);
		$GLOBALS['tmpl']->assign('news', $news); 
		$GLOBALS['tmpl']->assign('newscategs', $this->ACategs());
		$GLOBALS['tmpl']->assign('title', $GLOBALS['config_vars']['Gaming_articles']); 
		$GLOBALS['tmpl']->assign('limit',$limit);
		if($num>$limit)$GLOBALS['tmpl']->assign('Navi', pagenav($seiten, '', "<a class=\"page_navigation\" href=\"index.php?do=gaming&amp;sub=articles{$nastr}&pp={$limit}&page={s}\">{t}</a> "));
		
		$GLOBALS['tmpl']->assign('content', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/gaming/articles.tpl'));
	}
	
	//=================================================================
	// Artikel kopieren
	//=================================================================
	function copyArticle($id)
	{
		
		$res = $GLOBALS['db']->RowQuery("SELECT * FROM " . PREFIX . "_artikel WHERE Id='$id'");
		$GLOBALS['db']->Query("INSERT INTO ".PREFIX."_artikel 
		(
			Id, 	
			Kategorie, 	
			Titel_1, 	
			Titel_2, 	
			Titel_3, 	
			Untertitel_1, 	
			Untertitel_2, 	
			Untertitel_3, 	
			Inhalt_1, 	
			Inhalt_2, 	
			Inhalt_3, 	
			Textbilder_1, 	
			Textbilder_2, 	
			Textbilder_3, 	
			WertungsDaten, 	
			Genre, 	
			Hersteller, 	
			Vertrieb, 	
			Wertung, 	
			Kommentare, 	
			Plattform, 	
			Veroeffentlichung, 	
			Preis, 
			Shop, 	
			Bild_1, 	
			Bild_2, 	
			Bild_3, 	
			Links, 	
			Galerien,	
			Autor, 	
			Zeit, 	
			Hits, 	
			Typ, 	
			Sektion, 	
			Druck, 	
			Aktiv, 	
			Top, 	
			Flop, 	
			Minimum, 	
			Optimum, 	
			ZeitStart, 	
			ZeitEnde, 	
			Suche, 	
			Topartikel, 	
			TopartikelBild_1, 	
			TopartikelBild_2, 	
			TopartikelBild_3, 	
			AlleSektionen, 	
			Bildausrichtung, 	
			Tags, 	
			ShopArtikel, 	
			Kennwort
		) VALUES (
			'', 	
			'".$res->Kategorie."', 	
			'".addslashes($res->Titel_1 . $GLOBALS['config_vars']['DbCopy'])."', 	
			'".addslashes($res->Titel_2 . $GLOBALS['config_vars']['DbCopy'])."', 	
			'".addslashes($res->Titel_3 . $GLOBALS['config_vars']['DbCopy'])."', 	
			'".addslashes($res->Untertitel_1)."', 	
			'".addslashes($res->Untertitel_2)."', 	
			'".addslashes($res->Untertitel_3)."', 	
			'".addslashes($res->Inhalt_1)."', 	
			'".addslashes($res->Inhalt_2)."', 	
			'".addslashes($res->Inhalt_3)."', 	
			'".$res->Textbilder_1."', 	
			'".$res->Textbilder_2."', 	
			'".$res->Textbilder_3."', 	
			'".addslashes($res->WertungsDaten)."', 	
			'".$res->Genre."', 	
			'".$res->Hersteller."', 	
			'".$res->Vertrieb."', 	
			'".$res->Wertung."', 	
			'".$res->Kommentare."', 	
			'".$res->Plattform."', 	
			'".addslashes($res->Veroeffentlichung)."', 	
			'".addslashes($res->Preis)."', 
			'".addslashes($res->Shop)."', 	
			'".$res->Bild_1."', 	
			'".$res->Bild_2."', 	
			'".$res->Bild_3."', 	
			'".$res->Links."', 	
			'".$res->Galerien."',	
			'".$_SESSION['benutzer_id']."', 	
			'".stime()."', 	
			'0', 	
			'".$res->Typ."', 	
			'".$res->Sektion."', 	
			'0', 	
			'0', 	
			'".$res->Top."', 	
			'".$res->Flop."', 	
			'".$res->Minimum."', 	
			'".$res->Optimum."', 	
			'".$res->ZeitStart."', 	
			'".$res->ZeitEnde."', 	
			'".$res->Suche."', 	
			'".$res->Topartikel."', 	
			'".$res->TopartikelBild_1."', 	
			'".$res->TopartikelBild_2."', 	
			'".$res->TopartikelBild_3."', 	
			'".$res->AlleSektionen."', 	
			'".$res->Bildausrichtung."', 	
			'".$res->Tags."', 	
			'".$res->ShopArtikel."', 	
			'".$res->Kennwort."'
		)");
		$newid=$GLOBALS['db']->InsertId();
		Logger('User ' . $_SESSION['user_name'] . ' copy Article (' . addslashes($res->Titel_1)  . ')', '3', $_SESSION['benutzer_id']);
		echo "<script>window.opener.location.reload(); window.close()</script>";
	}
	
	//=================================================================
	// Artikel loeschen
	//=================================================================
	function deleteArticle($id)
	{
		$check =  $GLOBALS['db']->RowQuery("SELECT Autor FROM " . PREFIX . "_artikel  WHERE Id='$id'");
		if($check->Autor != $_SESSION['benutzer_id'] && (perm('articles_delete_all')))
		{
			$GLOBALS['db']->RowQuery("DELETE FROM " . PREFIX . "_artikel  WHERE Id='$id'");
			$GLOBALS['db']->Query("DELETE FROM " . PREFIX . "_kommentare WHERE Bereich='articles' AND Objekt_Id='$row->Id'");	
		} else {
			if(perm('articles_delete'))
			{
				$GLOBALS['db']->RowQuery("DELETE FROM " . PREFIX . "_artikel  WHERE Id='$id'");
				$GLOBALS['db']->Query("DELETE FROM " . PREFIX . "_kommentare WHERE Bereich='newss' AND Objekt_Id='$row->Id'");
			}	
		}
		Logger('User ' . $_SESSION['user_name'] . ' delete Article (' . $id . ')', '3', $_SESSION['benutzer_id']);
		echo '<script>window.opener.location.reload(); window.close();</script>';
	}
	
	//=================================================================
	// Oeffnen / Schliessen
	//=================================================================
	function ArticleOpenclose($openclose,$id)
	{
		if(perm('articles_openclose'))
		{
			$GLOBALS['db']->Query("UPDATE " . PREFIX . "_artikel SET Aktiv='{$openclose}' WHERE Id='{$id}'");
		}
		echo '<script>window.opener.location.reload(); window.close();</script>';
	}
	
	//=================================================================
	// Neuer Artikel
	//=================================================================
	function addArticle()
	{
		$LC = 1;
		// Speichern
		if(isset($_POST['save']) && $_POST['save']==1)
		{	
			$end = '0';
				
			$start = @explode('.',$_POST['ZeitStart']);
			$start = @mktime(0,0,1,$start[1],$start[0],$start[2]);
			
			if(isset($_POST['ZeitEnde']) && $_POST['ZeitEnde']>1)
			{
				$end = @explode('.',$_POST['ZeitEnde']);
				$end = @mktime(23,59,49,$end[1],$end[0],$end[2]);
			}
			
			
			if(!empty($_POST['WertungsDaten']))
			{
				$datas = explode("\r\n", $_POST['WertungsDaten']);
				foreach($datas as $m)
				{
					$det = explode(";",$m);
					if(!empty($det[1]))
					{
						$Wert = $det[1];
						
						switch(@$det[1])
						{
							case ($det[1] < 1):
								$Wert = 1;
							break;
							
							case ($det[1] > 5):
								$Wert = 5;
							break;
						}
						if(!empty($det[0])) @$data_res_all[] = $det[0] . ';' . $Wert;
					}
				}
				$data_res_all_f = implode("\r\n", $data_res_all);
			}
			
			$GLOBALS['db']->Query("INSERT INTO ".PREFIX."_artikel 
			(
				Id, 	
				Kategorie, 	
				Titel_1, 	
				Titel_2, 	
				Titel_3, 	
				Untertitel_1, 	
				Untertitel_2, 	
				Untertitel_3, 	
				Inhalt_1, 	
				Inhalt_2, 	
				Inhalt_3, 	
				Textbilder_1, 	
				Textbilder_2, 	
				Textbilder_3, 	
				WertungsDaten, 	
				Genre, 	
				Hersteller, 	
				Vertrieb, 	
				Wertung, 	
				Kommentare, 	
				Plattform, 	
				Veroeffentlichung, 	
				Preis, 
				Shop, 	
				Bild_1, 	
				Bild_2, 	
				Bild_3, 	
				Links, 	
				Galerien,	
				Autor, 	
				Zeit, 	
				Hits, 	
				Typ, 	
				Sektion, 	
				Druck, 	
				Aktiv, 	
				Top, 	
				Flop, 	
				Minimum, 	
				Optimum, 	
				ZeitStart, 	
				ZeitEnde, 	
				Suche, 	
				Topartikel, 	
				TopartikelBild_1, 	
				TopartikelBild_2, 	
				TopartikelBild_3, 	
				AlleSektionen, 	
				Bildausrichtung, 	
				Tags, 	
				ShopArtikel, 	
				Kennwort
			) VALUES (
				'', 	
				'".$_POST['categ']."', 	
				'".$_POST['Titel']."', 	
				'".$_POST['Titel']."', 		
				'".$_POST['Titel']."', 	
				'".@$_POST['Untertitel']."', 		
				'".@$_POST['Untertitel']."', 	
				'".@$_POST['Untertitel']."', 	
				'".@$_POST['Inhalt']."', 	
				'".@$_POST['Inhalt']."', 	 	
				'".@$_POST['Inhalt']."', 	
				'".@addslashes(base64_decode($_POST['inline_screens']))."', 	
				'', 	
				'', 	
				'".@$data_res_all_f."', 	
				'".@$_POST['Genre']."', 	
				'".@$_POST['Hersteller']."', 	
				'".@$_POST['Vertrieb']."', 	
				'".@$_POST['Wertung']."', 	
				'".@$_POST['Kommentare']."', 	
				'".@$_POST['Plattform']."', 	
				'".@$_POST['Veroeffentlichung']."', 	
				'".@$_POST['Preis']."', 
				'".@$_POST['Shop']."', 	
				'".@$_POST['Bild_1']."', 	
				'".@$_POST['Bild_1']."', 	
				'".@$_POST['Bild_1']."', 	
				'".@$_POST['Links']."', 	
				'".@implode(',',$_POST['Gallery'])."',	
				'".$_SESSION['benutzer_id']."', 	
				'".stime()."', 	
				'0', 	
				'".@$_POST['Typ']."', 	
				'".AREA."', 	
				'0', 	
				'1', 	
				'".@$_POST['Top']."', 	
				'".@$_POST['Flop']."', 	
				'".@$_POST['Minimum']."', 	
				'".@$_POST['Optimum']."', 	
				'".$start."', 	
				'".$end."', 	
				'".@$_POST['Suche']."', 	
				'".@$_POST['Topartikel']."', 	
				'".@$_POST['Bild_2']."', 	
				'".@$_POST['Bild_2']."', 
				'".@$_POST['Bild_2']."', 
				'".@$_POST['AlleSektionen']."', 	
				'".@$_POST['Bildausrichtung']."', 	
				'".@$_POST['Tags']."', 	
				'".@$_POST['ShopArtikel']."', 	
				'".@$_POST['Kennwort']."'
			)");
			Logger('User ' . $_SESSION['user_name'] . ' add new Article (' . addslashes($_POST['Titel']) . ')', '3', $_SESSION['benutzer_id']);
			echo '<script>window.opener.location.reload(); window.close();</script>';
		}
		
		$GLOBALS['tmpl']->assign('cforms',getInlineForms());
		$GLOBALS['tmpl']->assign('ContentLinks',getContentLinks(AREA));
		$GLOBALS['tmpl']->assign('Gallery', $this->galCategs($_SESSION['a_area'])); 
		$GLOBALS['tmpl']->assign('Inhalt', fckInit(' ', 'Inhalt', 350, 'Content'));
		$GLOBALS['tmpl']->assign('field_inline', "Textbilder_{$LC}"); 
		$GLOBALS['tmpl']->assign('articlecategs', $this->ACategs());
		$GLOBALS['tmpl']->assign('genres', $this->Genres());
		$GLOBALS['tmpl']->assign('mf', $this->Manufacturer());
		$GLOBALS['tmpl']->assign('pf', $this->Plattforms());
		$GLOBALS['tmpl']->assign('title', $GLOBALS['config_vars']['Gaming_articles_new']); 
		$GLOBALS['tmpl']->assign('content', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/gaming/article_new.tpl'));
	}
	
	//=================================================================
	// News bearbeiten
	//=================================================================
	function editArticle($id)
	{
		if(perm('articles_edit'))
		{
			$check =  $GLOBALS['db']->RowQuery("SELECT Autor FROM " . PREFIX . "_artikel  WHERE Id='$id'");
			if($check->Autor != $_SESSION['benutzer_id'] && (!perm('articles_edit_all')))
			{
				$this->nopermDoc();
			} else {
				$LC = (isset($_REQUEST['langcode']) && !empty($_REQUEST['langcode'])) ? abs((int)$_REQUEST['langcode']) : 1;
				$isdb = '';
				$start = '';
				$end = '';
				$categ = '';
				$Bild = '';
				$TopnewsBild = '';
				$Gallery = '';
				$BildAusr = '';
				$Sonstiges = '';
				$SetAll = '';
				
				// Speichern
				if(isset($_POST['save']) && $_POST['save']==1)
				{	
					if(perm('gallery_inlineshots') && isset($_POST['inline_screens']))
					{
						$isdb = ",Textbilder_{$LC} = '" . addslashes(base64_decode($_POST['inline_screens'])) . "' ";
					}
					
					$Bild        = (isset($_POST['NoImg']) && $_POST['NoImg']==1) ? ",Bild_{$LC} = ''" : ((isset($_POST['Bild_1']) && !empty($_POST['Bild_1'])) ? ",Bild_{$LC} = '" . @textToPrefix($_POST['Bild_1']) . "'" : "");
					$TopnewsBild = (isset($_POST['NoTopnewsImg']) && $_POST['NoTopnewsImg']==1) ? ",TopartikelBild_{$LC} = ''" : ((isset($_POST['Bild_2']) && !empty($_POST['Bild_2'])) ? ",TopartikelBild_{$LC} = '" . @textToPrefix($_POST['Bild_2']) . "'" : "");
					
					// Nur speichern, wenn 1. Sprache gewaehlt. Sonst nur Titel, Intro und Text
					if(isset($_POST['langcode']) && $_POST['langcode']==1)
					{
						$categ = ",Kategorie='" . $_POST['categ'] . "'";
						$Gallery = ",Galerien='" . @implode(',',@$_POST['Gallery']) . "'"; 
						
						// Veroeffentlichung
						if(!empty($_POST['ZeitStart']))
						{
							$start = @explode('.',$_POST['ZeitStart']);
							$start = @mktime(0,0,1,$start[1],$start[0],$start[2]);
							$start = ",ZeitStart='{$start}'";
						}
						
						if(!empty($_POST['WertungsDaten']))
						{
							$datas = explode("\r\n", $_POST['WertungsDaten']);
							foreach($datas as $m)
							{
								$det = explode(";",$m);
								if(!empty($det[1]))
								{
									$Wert = $det[1];
									
									switch(@$det[1])
									{
										case ($det[1] < 1):
											$Wert = 1;
										break;
										
										case ($det[1] > 5):
											$Wert = 5;
										break;
									}
									if(!empty($det[0])) @$data_res_all[] = $det[0] . ';' . $Wert;
								}
							}
							$data_res_all_f = implode("\r\n", $data_res_all);
						}
						
						if(isset($_POST['saveAllLang']) && $_POST['saveAllLang']==1)
						{
							$SetAll = "
								,Titel_2 = '" . $_POST['Titel'] . "'
								,Untertitel_2 = '" . imgToPrefix($_POST['Untertitel']) . "'
								,Inhalt_2 = '" . imgToPrefix($_POST['Inhalt']) . "'
								,Titel_3 = '" . $_POST['Titel'] . "'
								,Untertitel_3 = '" . imgToPrefix($_POST['Untertitel']) . "'
								,Inhalt_3 = '" . imgToPrefix($_POST['Inhalt']) . "'
								";
						}
						
						
						$Sonstiges = "
							{$SetAll}
							,Links = '" .  @trim($_POST['Links']) . "'
							,Preis = '" .  @$_POST['Preis'] . "'
							,Kennwort = '" .  @$_POST['Kennwort'] . "'
							,Shop = '" .  @$_POST['Shop'] . "'
							,ShopArtikel = '" .  @$_POST['ShopArtikel'] . "'
							,Veroeffentlichung = '" .  @$_POST['Veroeffentlichung'] . "'
							,Plattform = '" .  @$_POST['Plattform'] . "'
							,Genre = '" .  @$_POST['Genre'] . "'
							,Hersteller = '" .  @$_POST['Hersteller'] . "'
							,Vertrieb = '" .  @$_POST['Vertrieb'] . "'
							,Top = '" .  @trim($_POST['Top']) . "'
							,Flop = '" .  @trim($_POST['Flop']) . "'
							,Minimum = '" .  @trim($_POST['Minimum']) . "'
							,Optimum = '" .  @trim($_POST['Optimum']) . "'
							,WertungsDaten = '" .  @$data_res_all_f . "'
							,Typ = '" . @trim($_POST['Typ']) . "'
							,Tags = '" . @trim($_POST['Tags']) . "'
							,BildAusrichtung = '" . $_POST['BildAusrichtung'] . "'
							,Suche = '" . $_POST['Suche'] . "'
							,Wertung = '" . $_POST['Wertung'] . "'
							,Kommentare = '" . $_POST['Kommentare'] . "'
							,Aktiv = '" . $_POST['Aktiv'] . "'
							,AlleSektionen = '" . $_POST['AlleSektionen'] . "'
						";
						// Ablauf
						if(!empty($_POST['ZeitEnde']))
						{
							$end = @explode('.',$_POST['ZeitEnde']);
							$end = @mktime(23,59,49,$end[1],$end[0],$end[2]);
							$end = ",ZeitEnde='{$end}'";
						} else {
							$end = ",ZeitEnde='0'";
						}
					}
					
					$q ="UPDATE " . PREFIX . "_artikel 
					SET
						Topartikel  = '" . $_POST['Topartikel'] . "',
						Titel_{$LC} = '" . $_POST['Titel'] . "',
						Untertitel_{$LC} = '" . imgToPrefix($_POST['Untertitel']) . "',
						Inhalt_{$LC} = '" . imgToPrefix($_POST['Inhalt']) . "'
						{$categ}
						{$end}
						{$Bild}
						{$TopnewsBild}
						{$Sonstiges}
						{$start}
						{$Gallery}
						{$isdb} 
					WHERE Id='$id'";
					$GLOBALS['db']->Query($q);
					Logger('User ' . $_SESSION['user_name'] . ' edit Article (' . addslashes($_POST['Titel']) . ')', '3', $_SESSION['benutzer_id']);
					header('Location:index.php?do=gaming&sub=editarticle&id='.$id.'&noframes=1&langcode='.$_REQUEST['langcode']);
					exit;
					
				}
				
				$LC = (isset($_REQUEST['langcode']) && !empty($_REQUEST['langcode'])) ? abs((int)$_REQUEST['langcode']) : 1;
				$article =  $GLOBALS['db']->RowQuery("SELECT 
					*, 
					Bild_{$LC} as Bild,
					Textbilder_{$LC} as Textbilder,
					Titel_{$LC} as Titel,
					TopartikelBild_{$LC} as TopartikelBild,
					Untertitel_{$LC} as  Untertitel,
					Inhalt_{$LC} as Inhalt
				FROM " . PREFIX . "_artikel  WHERE Id='$id'");
				
				$article->Galerien = explode(',', $article->Galerien);
				$article->Bild = imgPrefix($article->Bild);
				$article->TopartikelBild = imgPrefix($article->TopartikelBild);
				
				$GLOBALS['tmpl']->assign('cforms',getInlineForms());
				$GLOBALS['tmpl']->assign('ContentLinks',getContentLinks(AREA));
				$GLOBALS['tmpl']->assign('Gallery', $this->galCategs($_SESSION['a_area'])); 
				$GLOBALS['tmpl']->assign('Inhalt', fckInit(imgPrefix($article->Inhalt) . ' ', 'Inhalt', 350, 'Content'));
				$GLOBALS['tmpl']->assign('InlineShots', unserialize($article->Textbilder)); 
				$GLOBALS['tmpl']->assign('article', $article); 
				$GLOBALS['tmpl']->assign('field_inline', "Textbilder_{$LC}"); 
				$GLOBALS['tmpl']->assign('articlecategs', $this->ACategs());
				$GLOBALS['tmpl']->assign('genres', $this->Genres());
				$GLOBALS['tmpl']->assign('mf', $this->Manufacturer());
				$GLOBALS['tmpl']->assign('pf', $this->Plattforms());
				$GLOBALS['tmpl']->assign('title', $GLOBALS['config_vars']['Gaming_articles_edit']); 
				$GLOBALS['tmpl']->assign('content', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/gaming/article_edit.tpl'));
			}
		} else {
			no_perm();
		}
	}
	
	
	
	//==================================================================================================================================
	// Plattformen
	//==================================================================================================================================
	function showPlattforms()
	{
		//=================================================================
		// Neu
		//=================================================================
		if(isset($_POST['new']) && $_POST['new']==1)
		{
			foreach($_POST['Name'] as $nn => $nid)
			{
				if(!empty($_POST['Name'][$nn])) $GLOBALS['db']->Query("INSERT INTO " . PREFIX . "_plattformen (Id,Name,Sektion) VALUES ('','" . $_POST['Name'][$nn] . "','" . AREA . "')");
			}
		}
		
		//=================================================================
		// Speichern
		//=================================================================
		if(isset($_POST['save']) && $_POST['save']==1)
		{
			foreach($_POST['Name'] as $cat => $nid)
			{
				 if(!empty($_POST['Name'][$cat])) $GLOBALS['db']->Query("UPDATE " . PREFIX . "_plattformen SET Name='" . $_POST['Name'][$cat] . "' WHERE Id='$cat'");
				// Loeschen?
				if(isset($_POST['del'][$cat]) && $_POST['del'][$cat]==1 && perm('plattforms'))
				{
					$GLOBALS['db']->Query("DELETE FROM " . PREFIX . "_plattformen WHERE Id='$cat'");
					Logger('User ' . $_SESSION['user_name'] . ' delete Plattform (' . $_POST['Name'][$cat]  . ')', '3', $_SESSION['benutzer_id']);
				}
			}
		}
		
		
		$pf = array();
		$sql = $GLOBALS['db']->Query("SELECT * FROM " . PREFIX . "_plattformen WHERE Sektion='" . AREA . "' ORDER BY Name ASC");
		while($row=$sql->fetchrow())
		{
			array_push($pf,$row);
		}
		$GLOBALS['tmpl']->assign('plattforms',$pf);
		$GLOBALS['tmpl']->assign('title', $GLOBALS['config_vars']['Gaming_plattforms']); 
		$GLOBALS['tmpl']->assign('content', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/gaming/plattforms.tpl'));
	}
	
	
	//==================================================================================================================================
	// Cheats
	//==================================================================================================================================
	function CheatsSettings()
	{
		// Speichern
		if(isset($_POST['save']) && $_POST['save']==1)
		{
			$GLOBALS['db']->Query("UPDATE " . PREFIX . "_cheats_einstellungen 
			SET 
				Kommentare = '" . $_POST['Kommentare'] . "',
				Wertung = '" . $_POST['Wertung'] . "',	
				Flaggen = '" . $_POST['Flaggen'] . "'
			");
		}
		
		$GLOBALS['tmpl']->assign('res', $GLOBALS['db']->RowQuery("SELECT * FROM " . PREFIX . "_cheats_einstellungen ")); 
		$GLOBALS['tmpl']->assign('title', $GLOBALS['config_vars']['Gaming_cheatsSettings']); 
		$GLOBALS['tmpl']->assign('content', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/gaming/cheats_settings.tpl'));
	}
	
	//=================================================================
	// Bearbeiten
	//=================================================================
	function EditCheat($id)
	{
		$LC = (isset($_REQUEST['langcode']) && $_REQUEST['langcode']!='') ? $_REQUEST['langcode'] : 1;
		$SetAll = '';
		
		// Speichern
		if(isset($_POST['save']) && $_POST['save']==1)
		{
			$db_extra = '';
			
			if($LC==1)
			{
				$Bild = '';
				
				if(isset($_POST['newImg_1']) && !empty($_POST['newImg_1']))
				{
					$Bild = "Bild='" . $_POST['newImg_1'] . "',";
				}
				
				$_POST['FileManual'] = trim(@$_POST['q']);
				
				$Url   = (!empty($_POST['newImg_2'])) ? "Download = '" . $_POST['newImg_2'] . "'," : "";
				$Url   = (!empty($_POST['FileManual']) && file_exists(BASE_DIR . '/uploads/cheats_files/' . $_POST['FileManual']) && $_POST['FileManual'] != '.htaccess') ? "Download = '" . $_POST['FileManual'] . "'," : $Url;
				$Url   = (isset($_POST['deldl']) && $_POST['deldl']==1) ? "Download = ''," : $Url;
				$Bild  = (isset($_POST['NoImg']) && $_POST['NoImg']==1  && empty($_POST['newImg_1'])) ? "Bild = ''," : $Bild;
				$db_extra = "
					{$Url} 
					{$Bild} 
					Galerien = '" . @implode(',',@$_POST['Galerien']) . "',
					CheatProdukt = '" . @$_POST['CheatProdukt'] . "',
					Webseite = '" . @$_POST['Webseite'] . "',
					Hersteller = '" . @$_POST['Hersteller'] . "',
					CheatLinks = '" . @$_POST['CheatLinks'] . "',
					DownloadLink = '" . @$_POST['Url_Direct'] . "',
					Sprache ='" . @$_POST['Sprache']. "', 
					Plattform ='" . $_POST['Plattform']. "',
					Aktiv='" . $_POST['Aktiv']. "',  ";
			}
			
			if(isset($_POST['saveAllLang']) && $_POST['saveAllLang']==1)
			{
				$SetAll = "
					,Name_2 = '" . imgToPrefix($_POST['Name']) . "'
					,Beschreibung_2 = '" . imgToPrefix($_POST['Beschreibung']) . "'
					,Name_3 = '" . imgToPrefix($_POST['Name']) . "'
					,Beschreibung_3 = '" . imgToPrefix($_POST['Beschreibung']) . "'
					";
			}
			
			$db_in = "UPDATE " . PREFIX . "_cheats
			SET 
				{$db_extra} 
				Name_{$LC} = '" . $_POST['Name'] . "', 
				Beschreibung_{$LC} = '" . imgToPrefix($_POST['Beschreibung']) . "' 
				{$SetAll} 
			WHERE Id='$id'";
			
			$GLOBALS['db']->Query($db_in);
			Logger('User ' . $_SESSION['user_name'] . ' edit Cheat(' . $_POST['Name']. ')', '3', $_SESSION['benutzer_id']);
			
		}
		
		$id = abs((int)$id);
		$res = $GLOBALS['db']->RowQuery("SELECT *, Beschreibung_{$LC} as Beschreibung, Name_{$LC} as Name FROM " . PREFIX . "_cheats WHERE Id='$id'");
		$categs = array();
		$area = AREA; 
		
		$res->Galerien = explode(',',$res->Galerien);
		
		$GLOBALS['tmpl']->assign('post_maxMb', post_maxMb());
		$GLOBALS['tmpl']->assign('wrietable_img',((is_writable(BASE_DIR . '/uploads/cheats/')) ? 1 : 0)); 
		$GLOBALS['tmpl']->assign('wrietable',((is_writable(BASE_DIR . '/uploads/cheats_files/')) ? 1 : 0)); 
		$GLOBALS['tmpl']->assign('res',$res); 
		$GLOBALS['tmpl']->assign('manuf',$this->Manufacturer());
		$GLOBALS['tmpl']->assign('products',$this->Products());
		$GLOBALS['tmpl']->assign('Categs', $this->ListCategsSimple('', '', $categs, $area));
		$GLOBALS['tmpl']->assign('Gallery', fetchGalleryCategs($_SESSION['a_area'])); 
		$GLOBALS['tmpl']->assign('Beschreibung', fckInit(imgPrefix($res->Beschreibung) . ' ', 'Beschreibung', 350, 'Content'));
		$GLOBALS['tmpl']->assign('title', $GLOBALS['config_vars']['Gaming_cheats_edit']); 
		$GLOBALS['tmpl']->assign('content', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/gaming/cheat_edit.tpl'));
	}
	
	//=================================================================
	// Neu
	//=================================================================
	function newCheat()
	{
		$categs = array();
		$area = AREA; 
		
		// Speichern
		if(isset($_POST['save']) && $_POST['save']==1)
		{
			$_POST['FileManual'] = trim(@$_POST['q']);
			$Url   = (!empty($_POST['newImg_2'])) ? $_POST['newImg_2'] : "";
			$Url   = (!empty($_POST['FileManual']) && file_exists(BASE_DIR . '/uploads/cheats_files/' . $_POST['FileManual']) && $_POST['FileManual'] != '.htaccess') ? $_POST['FileManual'] : $Url;
			
			$q = "INSERT INTO " . PREFIX . "_cheats 
			(
				Id, 	
				Plattform, 	
				Sprache, 	
				Typ, 	
				Benutzer, 	
				Hits, 	
				DatumUpdate, 	
				Name_1, 	
				Name_2, 	
				Name_3, 	
				Beschreibung_1, 	
				Beschreibung_2, 	
				Beschreibung_3, 	
				Bild, 	
				Download, 	
				DownloadHits, 	
				DownloadLink, 	
				Hersteller, 	
				Webseite, 	
				Galerien, 	
				CheatLinks, 	
				CheatProdukt, 	
				Sektion, 	
				Aktiv
			) VALUES (
				'', 	
				'" . @$_POST['Plattform'] . "', 	
				'" . @$_POST['Sprache'] . "', 	 	
				'cheat', 		
				'" . $_SESSION['benutzer_id'] . "', 	 	
				'0', 		
				'" . stime() . "', 		
				'" . $_POST['Name'] . "', 	 	
				'" . $_POST['Name'] . "', 	 	
				'" . $_POST['Name'] . "', 	 	
				'" . imgToPrefix($_POST['Beschreibung']) . "', 	 	
				'" . imgToPrefix($_POST['Beschreibung']) . "', 	 	
				'" . imgToPrefix($_POST['Beschreibung']) . "', 	 	
				'" . @$_POST['newImg_1'] . "', 		
				'" . $Url . "', 		
				'0', 	 	
				'" . @$_POST['Url_Direct'] . "', 	 	
				'" . @$_POST['Hersteller'] . "', 		
				'" . @$_POST['Webseite'] . "', 	 	
				'" . @implode(',',$_POST['Galerien']) . "', 		
				'" . @$_POST['CheatLinks'] . "', 		
				'" . @$_POST['CheatProdukt'] . "', 		
				'" . AREA . "', 		
				'1'
			)";
			$GLOBALS['db']->Query($q);
			Logger('User ' . $_SESSION['user_name'] . ' add new Cheat (' . $_POST['Name']  . ')', '3', $_SESSION['benutzer_id']);
			echo "<script>window.opener.location.reload(); window.close();</script>";
		}
		
		$GLOBALS['tmpl']->assign('post_maxMb', post_maxMb());
		$GLOBALS['tmpl']->assign('wrietable_img',((is_writable(BASE_DIR . '/uploads/cheats/')) ? 1 : 0)); 
		$GLOBALS['tmpl']->assign('wrietable',((is_writable(BASE_DIR . '/uploads/cheats_files/')) ? 1 : 0)); 
		$GLOBALS['tmpl']->assign('manuf',$this->Manufacturer());
		$GLOBALS['tmpl']->assign('products',$this->Products());
		$GLOBALS['tmpl']->assign('Categs', $this->ListCategsSimple('', '', $categs, $area));
		$GLOBALS['tmpl']->assign('Gallery', fetchGalleryCategs($_SESSION['a_area'])); 
		$GLOBALS['tmpl']->assign('Beschreibung', fckInit(' ', 'Beschreibung', 350, 'Content'));
		$GLOBALS['tmpl']->assign('title', $GLOBALS['config_vars']['Gaming_cheats_new']); 
		$GLOBALS['tmpl']->assign('content', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/gaming/cheat_new.tpl'));
	}
	
	//=================================================================
	// Kopieren
	//=================================================================
	function copyCheat($id)
	{
		$res = $GLOBALS['db']->RowQuery("SELECT * FROM " . PREFIX . "_cheats  WHERE Id='$id'");
		if(is_object($res))
		{
			$q = "INSERT INTO " . PREFIX . "_cheats 
			(
				Id, 	
				Plattform, 	
				Sprache, 	
				Typ, 	
				Benutzer, 	
				Hits, 	
				DatumUpdate, 	
				Name_1, 	
				Name_2, 	
				Name_3, 	
				Beschreibung_1, 	
				Beschreibung_2, 	
				Beschreibung_3, 	
				Bild, 	
				Download, 	
				DownloadHits, 	
				DownloadLink, 	
				Hersteller, 	
				Webseite, 	
				Galerien, 	
				CheatLinks, 	
				CheatProdukt, 	
				Sektion, 	
				Aktiv
			) VALUES (
				'', 	
				'" . $res->Plattform . "', 	
				'" . $res->Sprache . "', 	 	
				'" . $res->Typ . "', 		
				'" . $_SESSION['benutzer_id'] . "', 	 	
				'0', 		
				'" . stime() . "', 		
				'" . addslashes($res->Name_1 . $GLOBALS['config_vars']['DbCopy']) . "', 	 	
				'" . addslashes($res->Name_2 . $GLOBALS['config_vars']['DbCopy']) . "', 	 	
				'" . addslashes($res->Name_3 . $GLOBALS['config_vars']['DbCopy']) . "', 	 	
				'" . addslashes($res->Beschreibung_1) . "', 	 	
				'" . addslashes($res->Beschreibung_2) . "', 	 	
				'" . addslashes($res->Beschreibung_3) . "', 	 	
				'" . $res->Bild . "', 		
				'" . $res->Download . "', 		
				'" . $res->DownloadHits . "', 	 	
				'" . $res->DownloadLink . "', 	 	
				'" . $res->Hersteller . "', 		
				'" . $res->Webseite . "', 	 	
				'" . $res->Galerien . "', 		
				'" . $res->CheatLinks . "', 		
				'" . $res->CheatProdukt . "', 		
				'" . $res->Sektion . "', 		
				'0'
			)";
			$GLOBALS['db']->Query($q);
			Logger('User ' . $_SESSION['user_name'] . ' copy Cheat (' . $res->Name_1  . ')', '3', $_SESSION['benutzer_id']);
			echo "<script>window.opener.location.reload(); window.close();</script>";
		}
	
	}
	
	//=================================================================
	// Uebersicht
	//=================================================================
	function showCheats()
	{
		$db_sort      = " ORDER BY Name ASC";
		$nav_sort   = "&amp;sort=name_asc";
		$datesort = '';
		$def_search_n = '';
		$def_search = '';
		$namesort = '';
		$hitssort='';
		$usersort='';
		$categsort='';
		$activesort='';
		$scq='';
		$sc='';
		$pattern='';
		$pattern2='';
		$brokenq='';
		$brokenq_n='';
		$toplinksort='';
		
		if(isset($_POST['save']) && $_POST['save']==1 && isset($_POST['Aktiv']))
		{
			foreach($_POST['Aktiv'] as $lid => $li)
			{
				$GLOBALS['db']->Query("UPDATE " . PREFIX . "_cheats 
				SET 
					Plattform = '" . @$_POST['Plattform'][$lid] . "',
					Aktiv = '" . $_POST['Aktiv'][$lid] . "',
					Hits = '" . $_POST['Hits'][$lid] . "' 
				WHERE Id = '$lid'");
				
				if(@$_POST['del'][$lid]==1)
				{
					$GLOBALS['db']->Query("DELETE FROM " . PREFIX . "_cheats  WHERE Id='$lid'");
					$GLOBALS['db']->Query("DELETE FROM " . PREFIX . "_kommentare WHERE Bereich='cheats' AND Objekt_Id='$lid'");
				}
			}
		}
		
		if(isset($_REQUEST['q']) && !empty($_REQUEST['q']) && $_REQUEST['q'] != 'empty' && strlen($_REQUEST['q'])>=3)
		{
			$pattern = preg_replace('/([^-A-Za-zÀ-ÖØ-öø-ÿ0-9,_.:\/&=? ]*)/', '', $_REQUEST['q']);
			$pattern2 = koobispecialchars($pattern);
		}
		
		if(@$_REQUEST['categ']!='')
		{
			$scq = "AND (Plattform='" . abs((int)$_REQUEST['categ']) . "') ";
			$sc = "&amp;categ=" . $_REQUEST['categ'];
		}
		
		
		$_REQUEST['q']  = $pattern;
		$def_search_n   = "&amp;q=" . urlencode($pattern) . $sc;
		$def_search     = "{$scq} {$brokenq} AND (
		(Name_1 LIKE '%{$pattern}%' OR Beschreibung_1 LIKE '%{$pattern}%') OR 
		(Name_1 LIKE '%{$pattern2}%' OR Beschreibung_1 LIKE '%{$pattern2}%'))";
		
		
		switch(@$_REQUEST['sort'])
		{
			case '': default:
			case'date_desc':$db_sort='ORDER BY DatumUpdate DESC';$nav_sort='&amp;sort=date_desc';$datesort='date_asc';break;
			case'date_asc':$db_sort='ORDER BY DatumUpdate ASC';$nav_sort='&amp;sort=date_asc';$datesort='date_desc';break;
			
			case'name_asc':$db_sort = 'ORDER BY Name_1 ASC';$nav_sort = '&amp;sort=name_asc';$namesort = 'name_desc';break;
			case'name_desc':$db_sort='ORDER BY Name_1 DESC';$nav_sort='&amp;sort=name_desc';$namesort='name_asc';break;
			
			case'hits_desc':$db_sort='ORDER BY Hits DESC';$nav_sort='&amp;sort=hits_desc';$hitssort='hits_asc';break;
			case'hits_asc':$db_sort='ORDER BY Hits ASC';$nav_sort='&amp;sort=hits_asc';$hitssort='hits_desc';break;
			
			case'user_desc':$db_sort='ORDER BY Benutzer DESC';$nav_sort='&amp;sort=user_desc';$usersort='hits_asc';break;
			case'user_asc':$db_sort='ORDER BY Benutzer ASC';$nav_sort='&amp;sort=user_asc';$usersort='hits_desc';break;
			
			case'categ_desc':$db_sort='ORDER BY Plattform DESC';$nav_sort='&amp;sort=categ_desc';$categsort='categ_asc';break;
			case'categ_asc':$db_sort='ORDER BY Plattform ASC';$nav_sort='&amp;sort=categ_asc';$categsort='categ_desc';break;
			
			case'active_desc':$db_sort='ORDER BY Aktiv DESC';$nav_sort='&amp;sort=active_desc';$activesort='active_asc';break;
			case'active_asc':$db_sort='ORDER BY Aktiv ASC';$nav_sort='&amp;sort=active_asc';$activesort='active_desc';break;
		}
		
		
		$check = $GLOBALS['db']->RowQuery("SELECT COUNT(Id) AS ResCount FROM " . PREFIX . "_cheats  WHERE Sektion = '" . AREA . "' {$def_search} {$db_sort}");
		
		$num = $check->ResCount;
		$limit = GetLimit(15);
		$seiten = ceil($num / $limit);
		$a = prepage() * $limit - $limit;
			
		// Such-Abfrage
		$entries = array();
		$query_items = $GLOBALS['db']->Query("SELECT 
			*,
			Plattform, 
			Name_1 AS Name,
			Beschreibung_1 AS Beschreibung 
		FROM 
			" . PREFIX . "_cheats 
		WHERE 
			Sektion = '" . AREA . "' 
			{$def_search} {$db_sort} LIMIT $a,$limit");
		
		
		while($row_items = $query_items->fetchrow())
		{
			// Wertung
			$row_items->User = getUsername($row_items->Benutzer);
			$row_items->Comments = getCommentCount('cheats', $row_items->Id);
			$row_items->CCount = getPageCommentCount($row_items->Id,'cheats');
			$row_items->Wertung = getRating($row_items->Id,'cheats');
			array_push($entries, $row_items);
		}
		
		// Navi
		if ($num > $limit) 
		{
			$GLOBALS['tmpl']->assign('Navi', pagenav($seiten, '', " <a class=\"page_navigation\" href=\"index.php?do=gaming&sub=cheats&categ=".@$_REQUEST['categ']."{$def_search_n}{$nav_sort}{$brokenq_n}&amp;pp={$limit}&amp;page={s}\">{t}</a> "));
		}
		
		$news_categ = array();
		$area = AREA;
		
		$GLOBALS['tmpl']->assign('Categs', $this->ListCategsSimple('', '', $news_categ, $area));
		$GLOBALS['tmpl']->assign('activesort', $activesort);
		$GLOBALS['tmpl']->assign('categsort', $categsort);
		$GLOBALS['tmpl']->assign('usersort', $usersort);
		$GLOBALS['tmpl']->assign('hitssort', $hitssort);
		$GLOBALS['tmpl']->assign('namesort', $namesort);
		$GLOBALS['tmpl']->assign('datesort', $datesort);
		$GLOBALS['tmpl']->assign('limit', $limit);
		$GLOBALS['tmpl']->assign('Entries', $entries);
		$GLOBALS['tmpl']->assign('title', $GLOBALS['config_vars']['Gaming_cheats']); 
		$GLOBALS['tmpl']->assign('content', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/gaming/cheats.tpl'));
	}
	
	//=================================================================
	// Kategorien fuer Dropdown holen
	//=================================================================
	function ListCategsSimple($id, $prefix, &$news_categ, &$area)
	{
		$query = $GLOBALS['db']->Query("SELECT Id, Name FROM " . PREFIX . "_plattformen WHERE Sektion = '$area' ORDER BY Name ASC");
		while ($item = $query->fetchrow())
		{
			array_push($news_categ, $item);
		} 
		return $news_categ;
	}
	
	function ACategs($prefix='')
	{
		$area   = $_SESSION['a_area'];
		$categs = array();
		return $this->getArticleCategs(0, $prefix,$categs, $area);
	}
	
	function getArticleCategs($id, $prefix, &$news_categ, &$area)
	{
		$query = $GLOBALS['db']->Query("SELECT *, Name_1 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;
			array_push($news_categ, $item);
			$this->getArticleCategs($item->Id, $prefix . " - ", $news_categ, $area);
		} 
		return $news_categ;
	}
	
	
	//=================================================================
	// Bild-Kategorien holen
	//=================================================================
	function galCategs($area)
	{
		$categs = array();
		$query = $GLOBALS['db']->Query("SELECT Id,Name_1 AS CategName FROM " . PREFIX . "_galerie_kategorien WHERE Sektion = '" . $area . "' ORDER BY Name_1 ASC ");
		while($row = $query->fetchrow())
		{
			$gals = array();
			$qg = $GLOBALS['db']->Query("SELECT Id AS GalId,Name_1 AS GalName FROM " . PREFIX . "_galerie WHERE Kategorie = '$row->Id' ORDER BY Name_1 ASC ");
			while($rowg = $qg->fetchrow())
			{
				array_push($gals, $rowg);
			}
			
			$row->Gals = $gals;
			array_push($categs, $row);
		}
		
		return $categs;
	}
	
	function Manufacturer()
	{
		$items = array();
		$query = $GLOBALS['db']->Query("SELECT Id, Name FROM " . PREFIX . "_hersteller WHERE Sektion = '" . AREA . "' ORDER BY Name ASC");
		while ($row = $query->fetchrow())
		{
			array_push($items, $row);
		} 
		return $items;
	}
	
	function Plattforms()
	{
		$items = array();
		$query = $GLOBALS['db']->Query("SELECT Id, Name FROM " . PREFIX . "_plattformen WHERE Sektion = '" . AREA . "' ORDER BY Name ASC");
		while ($row = $query->fetchrow())
		{
			array_push($items, $row);
		} 
		return $items;
	}
	
	function Products()
	{
		$items = array();
		$query = $GLOBALS['db']->Query("SELECT Id, Name1 AS Name FROM " . PREFIX . "_produkte WHERE Sektion = '" . AREA . "' ORDER BY Name1 ASC");
		while ($row = $query->fetchrow())
		{
			array_push($items, $row);
		} 
		return $items;
	}
	
	function Genres()
	{
		$genres = array();
		$query = $GLOBALS['db']->Query("SELECT Name,Id FROM " . PREFIX . "_genre WHERE Sektion='" . AREA . "' ORDER BY Name ASC");
		while($row = $query->fetchrow())
		{
			array_push($genres,$row);
		}
		return $genres;
	}
	
	
	function nopermDoc()
	{
		$GLOBALS['tmpl']->assign('content', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/error/no_perm_document.tpl'));
	}
	
}
?>