<?php @include("passwort.php"); if ($HTTP_COOKIE_VARS["loginadmin"] == md5($Passwort)){ 
if( !isset( $HTTP_POST_VARS ) )
$HTTP_POST_VARS =& $_POST;
if( !isset( $HTTP_GET_VARS ) )
$HTTP_GET_VARS =& $_GET;
if( isset( $HTTP_GET_VARS['file'] ) )$file=$HTTP_GET_VARS['file'];
if( isset( $HTTP_GET_VARS['setup'] ) )$setup=$HTTP_GET_VARS['setup'];

@include($wobinich."functions.php");
ini_set("memory_limit","64M");
ini_set("memory_limit","128M");
ini_set("memory_limit","256M");
ini_set("memory_limit","512M");
error_reporting(0);
if (substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,2)=="de")@include("de.php");else @include("en.php");


?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
   <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
<title>Seite bearbeiten</title>

<!-- TinyMCE -->
<script type="text/javascript" src="tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
	tinyMCE.init({
		// General options
		mode : "exact",
        	elements : "mce",
		theme : "advanced",
		plugins : "autolink,lists,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,wordcount,advlist,autosave",
		<?php if (substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,2)=="de") echo "language : \"de\",";?>

		// Theme options
		theme_advanced_buttons1 : "newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
		theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl",
		theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,|,visualchars,nonbreaking,pagebreak,restoredraft",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,

		// Example content CSS (should be your site CSS)
		content_css : "../<?php @include("../layout.php");echo $templatedir; ?>tinymce.css",

		// Style formats
		style_formats : [
			{title : 'Bold text', inline : 'b'},
			{title : 'Red text', inline : 'span', styles : {color : '#ff0000'}},
			{title : 'Red header', block : 'h1', styles : {color : '#ff0000'}},
			{title : 'Example 1', inline : 'span', classes : 'example1'},
			{title : 'Example 2', inline : 'span', classes : 'example2'},
			{title : 'Table styles'},
			{title : 'Table row 1', selector : 'tr', classes : 'tablerow1'}
		],

		// Replace values for the template plugin
		template_replace_values : {
			username : "Some User",
			staffid : "991234"
		}
	});
</script>
<!-- /TinyMCE -->
<link rel="stylesheet" href="main.css" type="text/css" media="screen" />
</head>
<body>

<?php
//check if folder and files are writeable:
if (!is_writable('../layout.php')) echo $lang_txt_023, "<hr>";
if (!is_writable('../image')) echo $lang_txt_024, "<hr>";
if (!is_writable('../daten')) echo $lang_txt_025, "<hr>";
if (!is_writable('../download')) echo $lang_txt_030, "<hr>";
if (!is_writable('../daten/dat_menu_file.dat')) echo $lang_txt_027, "<hr>";

$dir = "../daten/";
	if (is_dir($dir)) {
	    if ($dh = opendir($dir)) 
		{
		while (($filex = readdir($dh)) !== false) 
			{  
			if (!is_writable("../daten/".$filex) and $filex!="." and $filex!=".txt" and $filex!="..") echo "/daten/", $filex, " ",$lang_txt_026, "<hr>";
			}
		closedir($dh);
	    	}
	}

//check for default Password:
if ($Passwort=="password") echo $lang_txt_028, "<hr>";
?>

<?php

//menu
if (!empty($file) or (!empty($setup))) echo "<div id='navi'><a href=\"admin.php\">", $lang_txt_005,"</a></div>";
if (empty($file)) echo "<div id='navi'><a href=\"admin.php?file=dat_menu_file\">",$lang_txt_008, "</a> <small><a href=\"admin.php?setup=layout\">",$lang_txt_009,"</a> <a href=\"../\">",$lang_txt_021,"</a></small>  </div>";
?>

<?php
if (!empty($setup))
{	
	if ($setup=="layout"){
	unset($file);
	$dir = "../template/";
	echo "<h1>",$lang_txt_022, "</h1>";
	// Open a known directory, and proceed to read its contents
	if (is_dir($dir)) {
	    if ($dh = opendir($dir)) {

		while (($file = readdir($dh)) !== false) {    
		    if (!is_dir($file)) $file_array[$file]=$file;
		}
		closedir($dh);
	    }
	}

	asort($file_array, SORT_STRING);

	foreach($file_array as $key => $value)
	{
	  //display results
	  //echo $key;    // is $file
	  //echo $value;  //is $tfile
	$file=$key;
	echo "<hr><a href=\"admin.php?setup=change_layout&layout=$file\"><img src=\"", $dir,$file, "/template_mini.png\" border=\"0\" alt=\"",$file,"\"> $file</a>";

	}

unset($file);
}
if ($setup=="change_layout")
{
//save the layout
$layout=$HTTP_GET_VARS['layout'];
if (get_magic_quotes_gpc()==1) $layout=stripslashes($layout);

$dateieix = fopen("../layout.php", "w+");
$write = array("<", "?php ", 
"$", "templatedir =\"", "template/", $layout,"/\"", ";", 
"$", "index =\"", "index.php\"", ";", 
"?", ">");echo "Layout ", $layout, " ", $lang_txt_029,"<br>";
for ($i = 0; $i <= sizeof($write); $i++) fwrite($dateieix, "$write[$i]");fclose($dateieix);
}
}

//anfang Bild abspeichern

						//http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php
						   if(!empty($_FILES['uploaded_image']['tmp_name'])) 
							{
							include('SimpleImage.php');
							$image = new SimpleImage();
							$image->load($_FILES['uploaded_image']['tmp_name']);


							$imgname= "../image/" .$file. "-1";
							for( $xf = 2; $xf < 99; $xf++ )
							{
								if(file_exists($imgname .".jpg") or file_exists($imgname .".png") or file_exists($imgname .".gif")) 
								{
									$imgname= "../image/" .$file. "-". $xf;
								}else break;
							}

							$endung=substr($_FILES["uploaded_image"]["name"], strripos($_FILES["uploaded_image"]["name"],"."));
							if (strtolower($endung)==".jpeg" or strtolower($endung)==".jpg" or strtolower($endung)==".gif" or strtolower($endung)==".png")$fileinfo="Image"; else $fileinfo="Datei";

							if ($fileinfo!="Datei")
								{
								$image_info = getimagesize($_FILES['uploaded_image']['tmp_name']);
								$myimageinfo=explode("height=", $image_info[3]);$endung="jpg";if ($image_info[2]=="3") $endung="png";if ($image_info[2]=="1") $endung="gif";						
								$x=str_replace("\"", "", str_replace("width=\"", "", trim($myimageinfo[0])));
								$y=str_replace("\"", "", str_replace("height=\"", "", trim($myimageinfo[1])));					
								if ($endung=="jpg")
									{
									if ($x > $y) $image->resizeToWidth(150);else $image->resizeToHeight(150);
								      	$image->save($imgname. "-150.". $endung);
									$image->load($_FILES['uploaded_image']['tmp_name']);					
									if ($x > 500 or $y > 500) {if ($x>$y) $image->resizeToWidth(500);else $image->resizeToHeight(500);}
									$image->save($imgname. ".".$endung);
									$image->load($_FILES['uploaded_image']['tmp_name']);					
									if ($x > 799 or $y > 799) {if ($x>$y) $image->resizeToWidth(800);else $image->resizeToHeight(800);
								      	$image->save($imgname. "-800.".$endung);}
									}
									else
									{
									$copied = copy($_FILES['uploaded_image']['tmp_name'], $imgname. ".".$endung);
										if (!$copied) 
										{
											echo '<h1>', $lang_txt_002, '</h1>';
											$errors=1;
										}
									}
								}
							else
							{
							//hier Upload von Dateien
							$filename= encodeurl(str_replace($endung, "",$_FILES["uploaded_image"]["name"])).$endung;
							$copied = copy($_FILES['uploaded_image']['tmp_name'], "../download/". $filename);
							echo " <a href=\"javascript:;\" onmousedown=\"tinyMCE.execCommand('mceInsertContent',false,'<a href=../download/$filename>$filename</a>');\">$lang_txt_031: $filename</a>";
							}
	
							}
//ende Bild abspeichern



if (!empty($HTTP_GET_VARS['deleteimg']))
{echo "../image/" .$file. "-". $HTTP_GET_VARS['deleteimg'].".jpg ", $lang_txt_004,"<br />";
unlink("../image/" .$file. "-". $HTTP_GET_VARS['deleteimg'].".jpg");
unlink("../image/" .$file. "-". $HTTP_GET_VARS['deleteimg']."-150.jpg");
unlink("../image/" .$file. "-". $HTTP_GET_VARS['deleteimg']."-800.jpg");
unlink("../image/" .$file. "-". $HTTP_GET_VARS['deleteimg'].".png");
unlink("../image/" .$file. "-". $HTTP_GET_VARS['deleteimg']."-150.png");
unlink("../image/" .$file. "-". $HTTP_GET_VARS['deleteimg']."-800.png");
unlink("../image/" .$file. "-". $HTTP_GET_VARS['deleteimg'].".gif");
unlink("../image/" .$file. "-". $HTTP_GET_VARS['deleteimg']."-150.gif");
unlink("../image/" .$file. "-". $HTTP_GET_VARS['deleteimg']."-800.gif");
}
//ende bild löschen


if (!empty($file))
	{
	$Pfad= "$Pfaddaten/$file.dat";

	/*** update entry***/
	if ($_POST['submit']=="update")
	{

	$warning="";
	
	//check for valid menu entries
	if ($file=="dat_menu_file")
		{
			
			$readmenuentries = file_get_contents($Pfad); 
			$arraymenues = explode ("---///___", $readmenuentries);
			$menues= $arraymenues[2];
			$menuentries=explode ("\n",$menues);
			$menuentriesnew=explode ("\n",$HTTP_POST_VARS['text']);
			//alt
			for ($i=0; $i<count($menuentries);$i++)
			{ $is_old_entry_still_there="0";
				if (strlen(trim($menuentries[$i]))>1) 
				{
					
					for ($j=0; $j<count($menuentriesnew);$j++){ if (str_replace("'","",str_replace("\'","",trim($menuentriesnew[$j])))==str_replace("'","",str_replace("\'","",trim($menuentries[$i]))))$is_old_entry_still_there="found_it";}
					if ($is_old_entry_still_there=="0") $warning="$warning $menuentries[$i]<br />";
				} 
			}
		}
	if( isset( $HTTP_POST_VARS['i_know_what_i_do'] ) ) if ($HTTP_POST_VARS['i_know_what_i_do']=="yes") $warning="";
	//ende check
	
	$savethetext=$HTTP_POST_VARS['titel'] ."---///___". $HTTP_POST_VARS['meta']."---///___". $HTTP_POST_VARS['text'];
	if (get_magic_quotes_gpc()==1) $savethetext=stripslashes($savethetext);
	
	if ($warning=="") 
		{

			if (!empty($savethetext))
			{
			$datei = fopen($Pfad, "w+");
			fwrite($datei, $savethetext);
			fclose($datei);
			}
		}

	}
	/*** read entry***/
	if (empty($savethetext)) $savethetext= file_get_contents($Pfad);
	$arrayseite = explode ("---///___", $savethetext);
	$titel= $arrayseite[0];if (empty($titel))$titel=decodeurl($file);
	$meta= $arrayseite[1];
	$text= $arrayseite[2];
	echo "<form action=\"admin.php?file=",$file, "\" enctype=\"multipart/form-data\" method=\"post\">";

	if ($file=="dat_menu_file") {echo "<br>", $lang_txt_006;
		if ($warning!="") echo "<div style=\"color:red;background:white;\"> $lang_txt_032 <blockquote>$warning</blockquote></div> $lang_txt_033<input type=\"checkbox\" name=\"i_know_what_i_do\" value=\"yes\"><br />";}


	if ($file!="dat_menu_file")echo "<br />", $lang_txt_019, "<textarea style=\"color: #000000;background-color: #ffffff;\" type=\"text\" name=\"titel\" ROWS=1 COLS=25 WRAP='virtual'>",$titel, "</textarea>";
	if ($file!="dat_menu_file")echo $lang_txt_020, "<textarea style=\"color: #000000;background-color: #ffffff;\" type=\"text\" name=\"meta\" ROWS=1 COLS=25 WRAP='virtual'>",$meta, "</textarea>";
	echo "<INPUT TYPE='HIDDEN' NAME='submit' VALUE='update'>";
	echo "<br /><textarea type=\"text\"";
	if ($file!="dat_menu_file") echo " id=\"mce\""; 
	echo " name=\"text\" ROWS=30 COLS=100>",htmlentities($text), "</textarea>";
	if ($file!="dat_menu_file") echo " $lang_txt_012 <input type=\"file\" name=\"uploaded_image\" />";
	echo "<br />", $lang_txt_007, "<input type=\"submit\" value=\"update\">";
	echo "</form>";
}else
{
if (empty($setup))
{
		/*** read entry***/
		$file="dat_menu_file";
		$Pfad= "$Pfaddaten/$file.dat";
		$datei = fopen($Pfad, "r");
		$savethetext=fread($datei, filesize($Pfad));
		fclose($datei);
		$arrayseite = explode ("---///___", $savethetext);
		$titel= $arrayseite[0];
		$meta= $arrayseite[1];
		$text= $arrayseite[2];
	$menuarray=explode ("\n",$text);

	echo "<h1>", $lang_txt_010,"</h1><a href=admin.php?file=Startseite>", $lang_txt_011,"</a> ";
	echo "<br /><br />";



	for ($i=0; $i<count($menuarray);$i++){

	$ebene=strlen(str_replace(trim($menuarray[$i]), "",chop($menuarray[$i])));
	echo str_repeat("&nbsp;-", $ebene);

	echo "<a href=admin.php?file=", encodeurl($menuarray[$i]),">",$menuarray[$i], "</a>";
	echo"<br>";}
}

}

?><?php

if ($file!="dat_menu_file") echo "<hr>";

					$imgname= "../image/" .$file;
					for( $xf = 1; $xf < 99; $xf++ )
					{unset($endung);
						if(file_exists($imgname ."-".$xf.".jpg")) $endung="jpg";if(file_exists($imgname ."-".$xf.".png")) $endung="png";if(file_exists($imgname ."-".$xf.".gif")) $endung="gif";
						if (!empty($endung))echo "<div style=\"overflow:hidden; float:left;\">";

						if($endung=="jpg"){
						if(file_exists($imgname ."-".$xf."-800.jpg")) echo " <a href=\"javascript:;\" onmousedown=\"tinyMCE.execCommand('mceInsertContent',false,'<a href=$imgname-$xf-800.", $endung," rel=lightbox[roadtrip]> <img src=$imgname-$xf.", $endung,"></a>');\"><img src=\"", $imgname,"-",$xf,"-150.", $endung,"\" title=\"", $lang_txt_015, $endung,"\"/></a>";
						else echo " <a href=\"javascript:;\" onmousedown=\"tinyMCE.execCommand('mceInsertContent',false,'<img src=$imgname-$xf.", $endung,">');\"> <img src=\"", $imgname,"-",$xf,"-150.", $endung,"\" title=\"", $lang_txt_016, $endung, "\"/></a>";				
						}

						if($endung=="png" or $endung=="gif")
						{echo "<a href=\"javascript:;\" onmousedown=\"tinyMCE.execCommand('mceInsertContent',false,'<img src=$imgname-$xf.", $endung,">');\"><img src=\"", $imgname,"-",$xf, ".", $endung,"\" width=200px title=\"",$lang_txt_017, $endung,"\"/></a>";}
				
						if (!empty($endung))echo "<small><small><a href=\"admin.php?file=",$file,"&deleteimg2=", $xf,"#delete\" title=\"",$lang_txt_018,"\"><-X</a></small></small></div>";	
					}
//bild löschen:
//bild löschen:
if (!empty($HTTP_GET_VARS['deleteimg2']))
{echo "<a name=\"delete\"></a><a href=\"admin.php?file=",$file,"&deleteimg=", $HTTP_GET_VARS['deleteimg2'],"\">", $lang_txt_003, "</a> <br /><br />";
}
?>

<?php }else echo "denied";?>
