<?php
class Content
{
	function DelRating($id)
	{
		$GLOBALS['db']->Query("DELETE FROM " . PREFIX . "_wertung WHERE Bereich='content' AND Objekt_Id='{$id}'");
		echo "<script>window.opener.location.reload(); window.close();</script>";
	}
	
	//=================================================================
	// Kategorie loeschen
	//=================================================================
	function delCateg($id)
	{
		if(perm('content_category'))
		{
			if($id!=1) $GLOBALS['db']->Query("DELETE FROM " . PREFIX . "_content_kategorien WHERE Id='{$id}'");
		}
		header('Location:index.php?do=content&sub=categories');
		exit;
	}
	
	
	//=================================================================
	// Kategorien
	//=================================================================
	function Categs()
	{
		$categs = array();
		$query = $GLOBALS['db']->Query("SELECT * FROM " . PREFIX . "_content_kategorien WHERE Sektion = '" . AREA . "' ORDER BY Name ASC");
		while($row = $query->fetchrow())
		{
			array_push($categs,$row);
		}
		return $categs;
	}
	
	function displayCategs()
	{
		if(perm('content_category'))
		{
			// Speichern
			if(isset($_POST['save']) && $_POST['save']==1)
			{
				foreach($_POST['Name'] as $cid => $c)
				{
					if(!empty($_POST['Name'][$cid])) $GLOBALS['db']->Query("UPDATE " . PREFIX . "_content_kategorien SET Name = '" . @$_POST['Name'][$cid] . "' WHERE Id='$cid'");
				}
			}
			
			// Neu
			if(isset($_POST['new']) && $_POST['new']==1 && !empty($_POST['Name']))
			{
				$GLOBALS['db']->Query("INSERT INTO " . PREFIX . "_content_kategorien (Id,Name,Sektion) VALUES ('','" . $_POST['Name'] . "','" . AREA . "')");
			}
			
			$GLOBALS['tmpl']->assign('categs', $this->Categs());
			$GLOBALS['tmpl']->assign('title', $GLOBALS['config_vars']['Content_Categs']); 
			$GLOBALS['tmpl']->assign('content', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/content/categs.tpl'));
		} else {
			no_perm();
		}
	}
	
	//=================================================================
	// Seite loeschen
	//=================================================================
	function deleteContent($id)
	{
		$check =  $GLOBALS['db']->RowQuery("SELECT Autor,Titel1 FROM " . PREFIX . "_content  WHERE Id='$id'");
		if($check->Autor != $_SESSION['benutzer_id'] && (perm('content_delete_all')))
		{
			$GLOBALS['db']->RowQuery("DELETE FROM " . PREFIX . "_content  WHERE Id='$id'");
			$GLOBALS['db']->Query("DELETE FROM " . PREFIX . "_content WHERE Bereich='content' AND Objekt_Id='$row->Id'");	
			Logger('User ' . $_SESSION['user_name'] . ' delete Content-Page ('.$check->Titel1.')', '3', $_SESSION['benutzer_id']);
		} else {
			if(perm('content_delete'))
			{
				$GLOBALS['db']->RowQuery("DELETE FROM " . PREFIX . "_content  WHERE Id='$id'");
				$GLOBALS['db']->Query("DELETE FROM " . PREFIX . "_content WHERE Bereich='content' AND Objekt_Id='$row->Id'");	
				Logger('User ' . $_SESSION['user_name'] . ' delete Content-Page ('.$check->Titel1.')', '3', $_SESSION['benutzer_id']);
			}
		}
		
		echo '<script>window.opener.location.reload(); window.close();</script>';
	}
	
	
	//=================================================================
	// Uebersicht
	//=================================================================
	function showContent()
	{
		$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_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 . "_content SET Topcontent = '" . $_POST['Topcontent'][$nid] . "', Kategorie='" . $_POST['Kategorie'][$nid] . "' WHERE Id='$nid'");
			}
		}
		
		
		// Multiaktionen
		if(isset($_POST['multi']) && $_POST['multi']!='' && isset($_SESSION['ContentSearch']) && perm('content_multioptions'))
		{
			switch($_POST['multiaction'])
			{
				case 'movecateg':$GLOBALS['db']->Query("UPDATE " . PREFIX . "_content SET Kategorie='" . $_POST['newcateg'] . "' " . $_SESSION['ContentSearch'] . "");break;
				case 'open':$GLOBALS['db']->Query("UPDATE " . PREFIX . "_content SET Aktiv='1' " . $_SESSION['ContentSearch'] . "");break;
				case 'close':$GLOBALS['db']->Query("UPDATE " . PREFIX . "_content SET Aktiv='0' " . $_SESSION['ContentSearch'] . "");break;
				case 'delete':$GLOBALS['db']->Query("DELETE FROM " . PREFIX . "_content " . $_SESSION['ContentSearch'] . "");break;
			}
			
			$GLOBALS['tmpl']->assign('multi_done',1);
			
		} else {
			unset($_SESSION['ContentSearch']);
		}
		
		// 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 (Datum <= $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 Titel1 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 Titel1 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 Datum 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 Datum 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 '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 . "_content WHERE Sektion='" . AREA . "' {$def_search} {$def_categ} {$def_status} {$def_hits} {$def_datetill}");
		
		$num = $sql->numrows();
		$seiten = ceil($num / $limit);
		$a = prepage() * $limit - $limit;
		
		$q = "SELECT * FROM " . PREFIX . "_content WHERE Sektion='" . AREA . "'  {$def_search} {$def_status} {$def_categ} {$def_hits} {$def_datetill} {$def_order} LIMIT $a,$limit";
		
		$sql = $GLOBALS['db']->Query($q);
		while($row=$sql->fetchrow())
		{
			$row->Comments = getCommentCount('content', $row->Id);
			$row->User = getUsername($row->Autor);
			$row->Wertung = getRating($row->Id,'content');
			array_push($news,$row);
		}
		
		$ordstr = "index.php?do=content&amp;sub=overview{$def_search_n}{$def_status_n}{$def_categ_n}&amp;pp={$limit}{$def_hits_n}{$def_datetill_n}";
		$nastr = "{$def_order_n}{$def_search_n}{$def_status_n}{$def_categ_n}&amp;pp={$limit}{$def_hits_n}{$def_datetill_n}";
		
		
		if(isset($_POST['startsearch']) && $_POST['startsearch']==1) 
		{
			$_SESSION['ContentSearch'] = "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->Categs());
		$GLOBALS['tmpl']->assign('title', $GLOBALS['config_vars']['Content']); 
		$GLOBALS['tmpl']->assign('limit',$limit);
		if($num>$limit)$GLOBALS['tmpl']->assign('Navi', pagenav($seiten, '', "<a class=\"page_navigation\" href=\"index.php?do=content&amp;sub=overview{$nastr}&pp={$limit}&page={s}\">{t}</a> "));
		
		$GLOBALS['tmpl']->assign('content', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/content/content.tpl'));
	}
	
	//=================================================================
	// Neu erstellen
	//=================================================================
	function addContent()
	{
		if(perm('content_new'))
		{
			// Speichern
			if(isset($_POST['save']) && $_POST['save']==1)
			{
				$_POST['Bild_1'] = @textToPrefix($_POST['Bild_1']);
				$_POST['Bild_2'] = @textToPrefix($_POST['Bild_2']);
				
				$gr = @implode(',', $_POST['Gruppen']);
				
				$query = "INSERT INTO " . PREFIX . "_content 
				(
					Id,
					Sektion, 	
					Datum, 	
					Kennwort, 	
					Autor, 	
					Aktiv, 	
					Kategorie, 	
					Titel1, 	
					Titel2, 	
					Titel3, 	
					Topcontent_Bild_1, 	
					Topcontent_Bild_2, 	
					Topcontent_Bild_3, 	
					Inhalt1, 	
					Inhalt2, 	
					Inhalt3, 	
					Bild1, 	
					Bild2, 	
					Bild3, 	
					Textbilder1, 	
					BildAusrichtung, 	
					Bewertung, 	
					Kommentare, 	
					Tags, 	
					Galerien,	
					Topcontent,	
					Suche,
					Gruppen
				) VALUES (
					'',
					'" . AREA . "',
					'" . stime() . "',
					'" . @$_POST['Kennwort'] . "', 	
					'" . $_SESSION['benutzer_id'] . "', 	 	
					'" . $_POST['Aktiv'] . "',
					'" . $_POST['categ'] . "',
					'" . $_POST['Titel'] . "',
					'" . $_POST['Titel'] . "',
					'" . $_POST['Titel'] . "',
					'" . @$_POST['Bild_2'] . "',
					'" . @$_POST['Bild_2'] . "',
					'" . @$_POST['Bild_2'] . "',
					'" . $_POST['Content'] . "',
					'" . $_POST['Content'] . "',
					'" . $_POST['Content'] . "',
					'" . @$_POST['Bild_1'] . "',
					'" . @$_POST['Bild_1'] . "',
					'" . @$_POST['Bild_1'] . "',
					'" . addslashes(base64_decode($_POST['inline_screens'])) . "',
					'" . @$_POST['BildAusrichtung'] . "',
					'" . $_POST['Bewertung'] . "',	
					'" . $_POST['Kommentare'] . "',	
					'" . $_POST['Tags'] . "',	
					'" . @implode(',',@$_POST['Gallery']) . "',
					'" . $_POST['Topcontent'] . "',	
					'" . $_POST['Suche'] . "',
					'" . $gr  . "'
				)";
				$GLOBALS['db']->Query($query);
				$new_id = $GLOBALS['db']->InsertId();
				
				// Navi-Eigenschaften
				$doc_s = "index.php?p=content&id=$new_id";
				$doc = "index.php?p=content&id=$new_id&name=" . seotitle($_POST['Titel']) . "&area=" . AREA;
				
				// Navi-Eintrag?
				if(isset($_POST['ToNavi']) && $_POST['ToNavi']==1)
				{
					$na = explode('|', $_POST['NaviCat2']);
					$ParentId = $na[1];
					$NaCat = $na[0];
					
					$GLOBALS['db']->Query("INSERT INTO " . PREFIX . "_navi 
					(
						Id,
						ParentId,
						NaviCat,
						Sektion,
						Titel_1,
						Titel_2,
						Titel_3,
						Dokument,
						group_id,
						Ziel,
						Position
					) VALUES (
						'',
						'"  . $ParentId . "',
						'" . $NaCat . "',
						'" . AREA . "',
						'" . $_POST['Titel'] . "',
						'" . $_POST['Titel'] . "',
						'" . $_POST['Titel'] . "',
						'" . $doc . "',
						'" . ((strlen($gr)>=1) ? '1,' . $gr : (implode(',', $_POST['Groups']))) . "',
						'_self',
						'" . abs((int)$_POST['PosN']) . "'
					)");
				}
				
				// QuickNavi-Eintrag?
				if(isset($_POST['ToQuickNavi']) && $_POST['ToQuickNavi']==1)
				{
					$GLOBALS['db']->Query("INSERT INTO " . PREFIX . "_quicknavi 
					(
						Id,
						Sektion,
						Name_1,
						Name_2,
						Name_3,
						Dokument,
						Aktiv,
						Ziel,
						Position
					) VALUES (
						'',
						'" . AREA . "',
						'" . $_POST['Titel'] . "',
						'" . $_POST['Titel'] . "',
						'" . $_POST['Titel'] . "',
						'" . $doc . "',
						'1',
						'_self',
						'" . abs((int)$_POST['PosQN']) . "'
					)");
				}
				Logger('User ' . $_SESSION['user_name'] . ' create Content-Page ('.$_POST['Titel'].')', '3', $_SESSION['benutzer_id']);
				echo '<script>window.opener.location.reload(); window.close()</script>';
			}
			
			
			$GLOBALS['tmpl']->assign('ContentLinks',getContentLinks(AREA));
			$GLOBALS['tmpl']->assign('cforms',getInlineForms());
			$GLOBALS['tmpl']->assign('UserGroups',UserGroups());
			$GLOBALS['tmpl']->assign('Navis',getNavisWithEntries(AREA));
			$GLOBALS['tmpl']->assign('Gallery', fetchGalleryCategs($_SESSION['a_area'])); 
			$GLOBALS['tmpl']->assign('Content', fckInit(' ', 'Content', 350, 'Content'));
			$GLOBALS['tmpl']->assign('newscategs', $this->Categs());
			$GLOBALS['tmpl']->assign('title', $GLOBALS['config_vars']['Content_new']); 
			$GLOBALS['tmpl']->assign('content', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/content/content_new.tpl'));
		} else {
			no_perm();
		}
	}
	
	
	//=================================================================
	// Content bearbeiten
	//=================================================================
	function editContent($id)
	{
		if(perm('content_edit'))
		{
			$check =  $GLOBALS['db']->RowQuery("SELECT Autor FROM " . PREFIX . "_content  WHERE Id='$id'");

			if($check->Autor != $_SESSION['benutzer_id'] && (!perm('content_edit_all')))
			{
				nopermDoc();
			} else {
				$LC = (isset($_REQUEST['langcode']) && !empty($_REQUEST['langcode'])) ? abs((int)$_REQUEST['langcode']) : 1;
				$isdb = '';
				$start = '';
				$end = '';
				$categ = '';
				$Bild = '';
				$TopContentBild = '';
				$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']) . "'" : "");
					$TopContentBild = (isset($_POST['NoContentImg']) && $_POST['NoContentImg']==1) ? ",Topcontent_Bild_{$LC} = ''" : ((isset($_POST['Bild_2']) && !empty($_POST['Bild_2'])) ? ",Topcontent_Bild_{$LC} = '" . @textToPrefix($_POST['Bild_2']) . "'" : "");
		
					
					// Nur speichern, wenn 1. Sprache gewaehlt
					if(isset($_POST['langcode']) && $_POST['langcode']==1)
					{
						$categ = ",Kategorie='" . $_POST['categ'] . "'";
						$Gallery = ",Galerien='" . @implode(',',@$_POST['Gallery']) . "'"; 
						
						if(isset($_POST['saveAllLang']) && $_POST['saveAllLang']==1)
						{
							$SetAll = "
								,Titel2 = '" . $_POST['Titel'] . "'
								,Inhalt2 = '" . imgToPrefix($_POST['Content']) . "'
								,Titel3 = '" . $_POST['Titel'] . "'
								,Inhalt3 = '" . imgToPrefix($_POST['Content']) . "'
								";
						}
						
						$Sonstiges = "
							{$SetAll}
							,Kennwort = '" . @trim($_POST['Kennwort']) . "'
							,Tags = '" . @trim($_POST['Tags']) . "'
							,BildAusrichtung = '" . $_POST['BildAusrichtung'] . "'
							,Suche = '" . $_POST['Suche'] . "'
							,Bewertung = '" . $_POST['Bewertung'] . "'
							,Kommentare = '" . $_POST['Kommentare'] . "'
							,Aktiv = '" . $_POST['Aktiv'] . "'
						";
					}
					
					$gr = @implode(',', $_POST['Gruppen']);
					
					$q = "UPDATE " . PREFIX . "_content 
					SET
						Gruppen = '" . $gr . "',
						Topcontent  = '" . $_POST['Topcontent'] . "',
						Titel{$LC} = '" . $_POST['Titel'] . "',
						Inhalt{$LC} = '" . imgToPrefix($_POST['Content']) . "'
						{$categ}
						{$Bild}
						{$TopContentBild}
						{$Sonstiges}
						{$Gallery}
						{$isdb} 
					WHERE Id='$id'";
					
					$GLOBALS['db']->RowQuery($q);
					
					// Navi-Eigenschaften
					$doc_s = "index.php?p=content&id=$id";
					$doc = "index.php?p=content&id=$id&name=" . seotitle($_POST['Titel']) . "&area=" . AREA;
					
					// Navi-Eintrag?
					if(isset($_POST['ToNavi']) && $_POST['ToNavi']==1)
					{
						$na = explode('|', $_POST['NaviCat2']);
						$ParentId = $na[1];
						$NaCat = $na[0];
					
						$GLOBALS['db']->Query("INSERT INTO " . PREFIX . "_navi 
						(
							Id,
							ParentId,
							NaviCat,
							Sektion,
							Titel_1,
							Titel_2,
							Titel_3,
							Dokument,
							group_id,
							Ziel,
							Position
						) VALUES (
							'',
							'"  . $ParentId . "',
							'" . $NaCat . "',
							'" . AREA . "',
							'" . $_POST['Titel'] . "',
							'" . $_POST['Titel'] . "',
							'" . $_POST['Titel'] . "',
							'" . $doc . "',
							'" . ((strlen($gr)>=1) ? '1,' . $gr : (implode(',', $_POST['Groups']))) . " ',
							'_self',
							'" . abs((int)$_POST['PosN']) . "'
						)");
					}
					
					// Neu
					if(isset($_POST['ToQuickNavi']) && $_POST['ToQuickNavi']==1)
					{
						$GLOBALS['db']->Query("INSERT INTO " . PREFIX . "_quicknavi 
						(
							Id,
							Sektion,
							Name_1,
							Name_2,
							Name_3,
							Dokument,
							Aktiv,
							Ziel,
							Position
						) VALUES (
							'',
							'" . AREA . "',
							'" . $_POST['Titel'] . "',
							'" . $_POST['Titel'] . "',
							'" . $_POST['Titel'] . "',
							'" . $doc . "',
							'1',
							'_self',
							'" . abs((int)$_POST['PosQN']) . "'
						)");
					}
					
					Logger('User ' . $_SESSION['user_name'] . ' update Content-Page ('.$_POST['Titel'].')', '3', $_SESSION['benutzer_id']);
					header("Location:index.php?do=content&sub=editcontent&id=$id&noframes=1&langcode=" . $_POST['langcode']);
					exit;
				}
				
				$LC = (isset($_REQUEST['langcode']) && !empty($_REQUEST['langcode'])) ? abs((int)$_REQUEST['langcode']) : 1;
				$content =  $GLOBALS['db']->RowQuery("SELECT 
					*, 
					Bild{$LC} as Bild,
					Textbilder{$LC} as Textbilder,
					Titel{$LC} as Titel,
					Topcontent_Bild_{$LC} as Topcontent_Bild,
					Inhalt{$LC} as Inhalt 
				FROM " . PREFIX . "_content  WHERE Id='$id'");
				
				// Ist Dokument in QuickNavi vorhanden?
				$doc_s = "index.php?p=content&id=$id&name=". seotitle($content->Titel);
				$res_qn = $GLOBALS['db']->RowQuery("SELECT Id FROM " . PREFIX . "_quicknavi WHERE Dokument LIKE '" . $doc_s . "%' AND Sektion='" . AREA . "'");
				$res_n = $GLOBALS['db']->RowQuery("SELECT Id FROM " . PREFIX . "_navi WHERE Dokument LIKE '" . $doc_s . "%' AND Sektion='" . AREA . "'");
				
				$content->Gruppe_Perms = explode(',',$content->Gruppen);
				$content->inQuicknavi = @$res_qn->Id;
				$content->inNavi = @$res_n->Id;
				$content->Galerien = explode(',', $content->Galerien);
				$content->Bild = imgPrefix($content->Bild);
				$content->Topcontent_Bild = imgPrefix($content->Topcontent_Bild);
				
				$GLOBALS['tmpl']->assign('ContentLinks',getContentLinks(AREA));
				$GLOBALS['tmpl']->assign('cforms',getInlineForms());
				$GLOBALS['tmpl']->assign('UserGroups',UserGroups());
				$GLOBALS['tmpl']->assign('Navis',getNavisWithEntries(AREA));
				$GLOBALS['tmpl']->assign('Gallery', fetchGalleryCategs($_SESSION['a_area'])); 
				$GLOBALS['tmpl']->assign('Content', fckInit(imgPrefix($content->Inhalt) . ' ', 'Content', 350, 'Content'));
				$GLOBALS['tmpl']->assign('InlineShots', unserialize($content->Textbilder)); 
				$GLOBALS['tmpl']->assign('content', $content); 
				$GLOBALS['tmpl']->assign('field_inline', "Textbilder{$LC}"); 
				$GLOBALS['tmpl']->assign('newscategs', $this->Categs());
				$GLOBALS['tmpl']->assign('title', $GLOBALS['config_vars']['Content_edit']); 
				$GLOBALS['tmpl']->assign('content', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/content/content_edit.tpl'));
			}
		} else {
			no_perm();
		}
	}
	
	//=================================================================
	// Oeffnen / Schliessen
	//=================================================================
	function Openclose($openclose,$id)
	{
		if(perm('news_openclose'))
		{
			$GLOBALS['db']->Query("UPDATE " . PREFIX . "_content SET Aktiv='{$openclose}' WHERE Id='{$id}'");
		}
		
		echo '<script>window.opener.location.reload(); window.close();</script>';
	}
}
?>