<?php 
@include("passwort.php");


if ($_COOKIE["loginadmin"] == md5($Passwort)){ 
if( isset( $_GET['file'] ) )$file=$_GET['file'];
if( isset( $_GET['setup'] ) )$setup=$_GET['setup'];else $setup="";
@include($wobinich."functions.php");

ini_set("memory_limit","-1");
error_reporting(0);
//error_reporting(E_ERROR);
if ($language=="de") $inclanguage="de"; else $inclanguage="en"; 
if ($language=="auto") $inclanguage=substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,2);
if ($inclanguage=="de")@include("de.php");else @include("en.php");
if (empty($language)) $language="auto";
?>

<!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>



<?php if ($file!="dat_menu_file")  if (!empty($file) or !empty($_GET['loadmce'])) {?>
<!-- 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",
		skin : "o2k7",
   		gecko_spellcheck : true,
		plugins : "autolink,template,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",
		<?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,template",
		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,
		
		template_templates : [


	<?php 
			$Pfad= "../daten/dat_menu_file.dat";
			$readmenuentries = file_get_contents($Pfad); 
			$arraymenues = explode ("---///___", $readmenuentries);
			$menues= $arraymenues[2];
			$menues= str_replace("\r", "\n", $arraymenues[2]);
			$menuentries=explode ("\n",$menues);
			for ($i=0; $i<count($menuentries);$i++)
			{
			if (strlen($menuentries[$i])>0)echo	"
			{title : \"$menuentries[$i]\",
			 src: \"tinymce-article.php?article=$menuentries[$i]\",
			 description: \"Newsarticle: $menuentries[$i]\"},";
			}?>
			],

		// Example content CSS (should be your site CSS)
		content_css : "../<?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 pluginhttp://demo.libe.net/#&panel1-2
		template_replace_values : {
			username : "Some User",
			staffid : "991234"
		},
	});
</script>
<!-- /TinyMCE -->
<?php }?>
<link rel="stylesheet" href="main.css" type="text/css" media="screen" />
<?php 
if (empty($setup)) echo "<link rel=\"stylesheet\" href=\"nestable-style.css\" type=\"text/css\" media=\"screen\" />";
?>

<?php if ($file=="dat_menu_file") echo "<style> textarea{color:#cc0000;}</style>";?>

<!--[if IE 9]>
<style>
.nestable-menu input{margin:14px;padding:1px;float:left;}
</style>
<![endif]-->

</head>
<body>
<br><br>
<?php
//save Konfig changes to var.php File:
if (!empty($setup) and $setup!="settings" and $setup!="layout")
{
if ($setup=="maintenance_on")$maintenance="on";
if ($setup=="maintenance_off")$maintenance="off";
if ($setup=="modrewrite_on")$modrewrite="on";
if ($setup=="modrewrite_off")$modrewrite="off";
if ($setup=="expand_all")$expand_all="all";
if ($setup=="collapse_all")$expand_all="collapse";
if ($setup=="feedback"){
	$email=encodeurl(str_replace(";", "0SEMI0",str_replace(".", "0DOT0",str_replace("@", "0AT0", $_POST['email']))));
	$sendermail=encodeurl(str_replace(".", "0DOT0",str_replace("@", "0AT0", $_POST['sendermail'])));
	$badwords=encodeurl(str_replace("=", "0EQUAL0",str_replace(":", "0COLON0",str_replace(";", "0SEMI0",str_replace(".", "0DOT0",str_replace("@", "0AT0",str_replace("/", "0SLASH0", $_POST['badwords'])))))));
	$feedbackformular=encodeurl(str_replace("|", "0AREA0",str_replace("*", "0STAR0",str_replace(":", "0COLON0",str_replace(";", "0SEMI0",str_replace(".", "0DOT0",str_replace("@", "0AT0",str_replace("/", "0SLASH0", $_POST['feedbackformular']))))))));
	$feedbackapprove=$_POST['feedbackapprove'];}
if ($setup=="template"){
	$page_title=encodeurl(str_replace(" ", "0SPACE0",str_replace("=", "0EQUAL0",str_replace(":", "0COLON0",str_replace(";", "0SEMI0",str_replace(".", "0DOT0",str_replace("@", "0AT0",str_replace("/", "0SLASH0", $_POST['page_title']))))))));
	$page_description=encodeurl(str_replace(" ", "0SPACE0",str_replace("=", "0EQUAL0",str_replace(":", "0COLON0",str_replace(";", "0SEMI0",str_replace(".", "0DOT0",str_replace("@", "0AT0",str_replace("/", "0SLASH0", $_POST['page_description']))))))));

}

if ($setup=="password")
{
if ($_POST['password1']==encodeurl($_POST['password1']) and strlen($_POST['password1'])>5)
	{
	if ($_POST['password1']==$_POST['password2'])
		{
		$Passwort=encodeurl($_POST['password1']);echo $lang_txt_098;
		}else 
		{echo "<div class=\"warning\">$lang_txt_099 </div>";$setup=settings;}	
	}else echo "<div class=\"warning\">$lang_txt_100 </div>";
}
if ($setup=="language") $language=$_POST['language'];


if ($setup=="change_layout"){$layout=$_GET['layout'];
if (get_magic_quotes_gpc()==1) $layout=stripslashes($layout);$templatedir ="template/". $layout. "/"; echo "layout changed to: $templatedir";}

$dateieix = fopen("../var.php", "w+");
$write = array("<", "?php ", 
"$", "templatedir =\"", $templatedir,"\"", ";", 
"$", "feedbackapprove =\"", $feedbackapprove,"\"", ";", 
"$", "email =\"", $email,"\"", ";", 
"$", "sendermail =\"",$sendermail,"\"", ";", 
"$", "language =\"",$language,"\"", ";",
"$", "expand_all =\"",$expand_all,"\"", ";",
"$", "page_title =\"",$page_title,"\"", ";",
"$", "page_description =\"",$page_description,"\"", ";",
"$", "badwords =\"", $badwords,"\"", ";",
"$", "feedbackformular =\"", $feedbackformular,"\"", ";",
"$", "index =\"", "index.php\"", ";", 
"$", "maintenance =\"",$maintenance,"\"", ";", 
"$", "modrewrite =\"", $modrewrite, "\"", ";", 
"$", "Passwort =\"", $Passwort, "\"", ";", 
"?", ">");
for ($i = 0; $i <= sizeof($write); $i++) fwrite($dateieix, "$write[$i]");fclose($dateieix);
}



//check if folder and files are writeable:
if (!is_writable('../var.php')) echo "<div class=\"warning\">",$lang_txt_023, "</div>";
if (!is_writable('../image')) echo "<div class=\"warning\">",$lang_txt_024, "</div>";
if (!is_writable('../daten')) echo "<div class=\"warning\">",$lang_txt_025, "</div>";
if (!is_writable('../download')) echo "<div class=\"warning\">",$lang_txt_030, "</div>";
if (!is_writable('../daten/dat_menu_file.dat')) echo "<div class=\"warning\">",$lang_txt_027, "</div>";
if (file_exists("../.htaccess") and $modrewrite=="on" and !is_writable('../.htaccess')) echo "<div class=\"warning\">",$lang_txt_053, "</div>";
$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 "<div class=\"warning\">/daten/", $filex, " ",$lang_txt_026, "</div>>";
			}
		closedir($dh);
	    	}
	}

//check for default Password:
if ($Passwort=="password") echo "<div class=\"warning\">", $lang_txt_028, "</div><br>";

if ($setup=="settings")
{	echo "<h1>$lang_txt_050</h1>";
	//echo "<div style=\"position:absolute;left:00px;top:0px;margin-left:470px;float:left;\">";
	
	
if (function_exists('apache_get_modules')) {
   $modules = apache_get_modules();
   $mod_rewrite_enabled = in_array('mod_rewrite', $modules);
 } else {
   $mod_rewrite_enabled =  getenv('HTTP_MOD_REWRITE')=='On' ? true : false ;
 }


	if ($mod_rewrite_enabled==1){
	if  ($modrewrite=="on") echo "<div class=\"settings\"><a href=\"admin.php?setup=modrewrite_off\" style=\"color: #666;\">$lang_txt_043</a> </div></div><br>";
	else echo "<div  class=\"settings\"><a href=\"admin.php?setup=modrewrite_on\" style=\"color: #666;\">$lang_txt_044</a></div></div> <br>";
	//echo "</div>";
	} else {
	    echo "<div class=\"settings\">$lang_txt_045</div></div><br>";
	}
if ($maintenance=="on") echo "<div class=\"settings\">$lang_txt_038<a href=\"admin.php?setup=maintenance_off\" title=\"$lang_txt_094\" style=\"color: #F00;\">$lang_txt_037</a> </div></div><br>";
else if (empty($file)) echo "<div class=\"settings\">$lang_txt_035 <a href=\"admin.php?setup=maintenance_on\" title=\"$lang_txt_093\">$lang_txt_036</a></div></div> <br>";

echo $lang_txt_134;
if ($expand_all=="collapse") echo "<div class=\"settings\"><a href=\"admin.php?setup=expand_all\" title=\"default expand\">$lang_txt_135</a> </div></div><br>";
else echo "<div class=\"settings\"><a href=\"admin.php?setup=collapse_all\" title=\"default collapse\">$lang_txt_136</a></div></div> <br>";


echo "<div class=\"settings\"><a href=\"admin.php?setup=layout\" title=\"$lang_txt_095\">",$lang_txt_009,"</a>";
if (empty($_GET['layout'])) echo " <small>(",str_replace("/", "", str_replace("template/", "", $templatedir)), ")</small>"; else echo " <small>(",$_GET['layout'], ")</small>";
echo "</div> <br />"; 

echo "Language / Sprache: <div class=\"settings\"><form action=\"admin.php?setup=language\" enctype=\"multipart/form-data\" method=\"post\">";
echo "Deutsch<input type=\"radio\" name=\"language\" value=\"de\" ";
if ($language=="de") echo "checked=\"checked\"";
echo "><br>";
echo "English<input type=\"radio\" name=\"language\" value=\"en\"";
if ($language=="en") echo "checked=\"checked\"";
echo "\"><br>";
echo "auto<input type=\"radio\" name=\"language\" value=\"auto\"";
if ($language=="auto") echo "checked=\"checked\"";
echo "\">";
echo "<input type=\"submit\" value=\"change\">"; 
echo "</form></div></div>";

echo "<form action=\"admin.php?setup=password\" enctype=\"multipart/form-data\" method=\"post\">";
echo "<br><div class=\"settings\">$lang_txt_097<br>";
echo "<input type=\"password\" title=\"$lang_txt_097\" autocomplete=\"off\" name=\"password1\" value=\"\"><br>";
echo "<input type=\"password\" title=\"$lang_txt_097\" autocomplete=\"off\" name=\"password2\" value=\"\">";


echo "<input type=\"submit\" value=\"save\">"; 
echo "</form></div><br><br>";

echo "<h1>Template $lang_txt_050</h1><div  class=\"settings\">";
echo "<form action=\"admin.php?setup=template\" enctype=\"multipart/form-data\" method=\"post\">";
$page_title=str_replace("0SPACE0", " ", str_replace("0EQUAL0", "=",str_replace("0SLASH0", "/",str_replace("0COLON0", ":",str_replace("0SEMI0", ";",str_replace("0DOT0", ".",str_replace("0AT0", "@", $page_title)))))));
$page_description=str_replace("0SPACE0", " ", str_replace("0EQUAL0", "=",str_replace("0SLASH0", "/",str_replace("0COLON0", ":",str_replace("0SEMI0", ";",str_replace("0DOT0", ".",str_replace("0AT0", "@", $page_description)))))));

echo "Page Title: <textarea style=\"color: #000000;background-color: #fff;\" type=\"text\" title=\"$lang_txt_113\" name=\"page_title\" ROWS=1 COLS=40 WRAP='virtual'>",$page_title, "</textarea>";
echo "<br>Page description: <textarea style=\"color: #000000;background-color: #fff;\" type=\"text\" title=\"$lang_txt_114\" name=\"page_description\" ROWS=1 COLS=40 WRAP='virtual'>",$page_description, "</textarea>";

echo "<input type=\"submit\" value=\"save\">"; 
echo "</form></div><br><br>";


echo "<form action=\"admin.php?setup=feedback\" enctype=\"multipart/form-data\" method=\"post\">";
$email=str_replace("0SEMI0", ";",str_replace("0DOT0", ".",str_replace("0AT0", "@", $email)));
echo "<h1>Feedback $lang_txt_050</h1><div  class=\"settings\">";
echo "$lang_txt_103 <input type=\"checkbox\" title=\"$lang_txt_102\" name=\"feedbackapprove\" value=\"later\" ";if ($feedbackapprove=="later") echo "checked"; echo "><br>";

echo "Email: <textarea style=\"color: #000000;background-color: #fff;\" type=\"text\" title=\"$lang_txt_092\" name=\"email\" ROWS=1 COLS=40 WRAP='virtual'>",$email, "</textarea>";
$feedbackformular=str_replace("0AREA0", "|",str_replace("0STAR0", "*",str_replace("0SLASH0", "/",str_replace("0COLON0", ":",str_replace("0SEMI0", ";",str_replace("0DOT0", ".",str_replace("0AT0", "@", $feedbackformular)))))));
echo "<br>Formular: <textarea style=\"color: #000000;background-color: #fff;\" type=\"text\" title=\"$lang_txt_101\" name=\"feedbackformular\" ROWS=1 COLS=40 WRAP='virtual'>",$feedbackformular, "</textarea>";
$sendermail=str_replace("0SEMI0", ";",str_replace("0DOT0", ".",str_replace("0AT0", "@", $sendermail)));
echo "<br>Sender Email: <textarea style=\"color: #000000;background-color: #fff;\" type=\"text\" title=\"$lang_txt_092\" name=\"sendermail\" ROWS=1 COLS=40 WRAP='virtual'>",$sendermail, "</textarea>";

$badwords=str_replace("0EQUAL0", "=",str_replace("0SLASH0", "/",str_replace("0COLON0", ":",str_replace("0SEMI0", ";",str_replace("0DOT0", ".",str_replace("0AT0", "@", $badwords))))));
echo "<br>Bad Words: <textarea style=\"color: #000000;background-color: #fff;\" type=\"text\" title=\"$lang_txt_093\" name=\"badwords\" ROWS=1 COLS=40 WRAP='virtual'>",$badwords, "</textarea>";

echo "<input type=\"submit\" value=\"save\">"; 
echo "</form></div>";



}
?>

<?php
//menu
echo "<div id='navi'><div id='navi2'></div>";
echo " <div style=\"position:absolute;width:200;text-align:left;left:0px;top:0px;margin:0px;float:left;\">";
//if (!empty($file) or (!empty($setup))) echo "<a href=\"admin.php#", $file,"\" title=\"$lang_txt_073 $lang_txt_089\">", $lang_txt_005,"</a> ";
if (!empty($file) or (!empty($setup))) echo "<a href=\"admin.php\" title=\"$lang_txt_073 $lang_txt_089\">", $lang_txt_005,"</a> ";
if (!empty($file)) if ($file!="dat_menu_file") if ($setup!="layout") echo "<a href=\"../index.php/", $file,"\" title=\"$lang_txt_079 $lang_txt_089\">", $lang_txt_049,"</a> ";
if (empty($setup) and empty($file)) echo "<a href=\"admin.php?file=dat_menu_file\" title=\"$lang_txt_070 $lang_txt_069\">",$lang_txt_008, "</a> ";
if ($setup=="layout") echo "<a href=\"edit.php\" title=\"Editor\">edit</a> ";

echo "</div>";
if (empty($file)) {
echo " <div style=\"position:absolute;width:200;text-align:right;right:0px;top:0px;margin:0px;float:right;\">";
if ($setup!="settings" and empty($file)){
echo " <a href=\"admin.php?setup=settings\" title=\"$lang_txt_075\">$lang_txt_050</a> ";
}
if(file_exists("../feedback/check")) {$datelast =file_get_contents("../feedback/check"); $datelast="new Feedback(s):". date("d.m.Y H:i",$datelast);}else $datelast="Feedback(s)";

if(file_exists("feedback.php")) {echo "<a href=\"feedback.php\""; if ($datelast!="Feedback(s)")echo " style=\"background-color:#F00\""; echo " title=\"$lang_txt_076\">$datelast</a> ";}
if(file_exists("anmeldeformular.php")) echo "<a href=\"anmeldeformular.php\">Anmeldungen</a> ";
echo "<a href=\"../index.php?login=logoff\" title=\"$lang_txt_077\">$lang_txt_039</a> <a href=\"../\" title=\"$lang_txt_078\">",$lang_txt_021," [x]</a></div> </div>";
}
echo "</div>";
?>

<?php



if (!empty($setup))
{	
	if ($setup=="layout")
	{
	unset($file);
	$dir = "../template/";$current_template= str_replace("/", "", str_replace("template/", "", $templatedir));
	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;
		if ($current_template!=$file) {echo "<table><tr><td width=300px><a href=\"admin.php?setup=change_layout&layout=$file\"><img src=\"", $dir,$file, "/template_mini.png\" border=\"0\" alt=\"",$file,"\"></a></td><td width=400px style=\"background:#fff;vertical-align:top;\"><b><a href=\"admin.php?setup=change_layout&layout=$file\">$file</a></b><br>";@include($dir.$file. "/template_describtion.htm");echo "</td></tr></table>";}
		else {echo "<br><div style=\"border-style:solid;width:700px;\"><table><tr><td width=300px><a href=\"admin.php?setup=change_layout&layout=$file\"><img src=\"", $dir,$file, "/template_mini.png\" border=\"0\" alt=\"",$file,"\"></a></td><td width=400px style=\"background:#fff;vertical-align:top;\"><b><a href=\"admin.php?setup=change_layout&layout=$file\">$file</a></b><br>";@include($dir.$file. "/template_describtion.htm");echo "</td></tr></table></div>";}

		}
	unset($file);
	}
}

//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 < 999; $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);

								if ($endung==".zip")
								{


									//try to unzip and look if there are Images in the file:
									echo " try to Unzip and look if there are Images in the Archive:";
									 $jpgsinzip=0;
								     $zip = new ZipArchive;
								     $res = $zip->open("../download/". $filename);
								     if ($res === TRUE) {	
									 for($i = 0; $i < $zip->numFiles; $i++) 
										 {$filename2 = $zip->getNameIndex($i);
										 
										 $outputFile="../download/temp/". $filename2;
										 $zip->extractTo("../download/temp/");

										 $endung=substr($filename2, strripos($filename2,"."));
										 if (strtolower($endung)==".jpg")
											{$jpgsinzip++;
												
												$imgname= "../image/" .$file. "-1";$imgname2="-1";
												for( $xf = 2; $xf < 999; $xf++ )
												{
													if(file_exists($imgname .".jpg") or file_exists($imgname .".png") or file_exists($imgname .".gif")) 
													{
													$imgname= "../image/" .$file. "-". $xf;
													}else break;
												}
											//*resize	
												$image = new SimpleImage();
												$image->load($outputFile);
													$image_info = getimagesize($outputFile);
													echo "<br>load", $outputFile," imagetag:", $imgname;
													$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])));
														$image->load($outputFile);
														if ($x > 799 or $y > 799) {if ($x>$y) $image->resizeToWidth(800);else $image->resizeToHeight(800);
															$image->save($imgname. "-800.jpg");}
														if ($x > $y) $image->resizeToWidth(150);else $image->resizeToHeight(150);
															$image->save($imgname. "-150.jpg");
														$image->load($outputFile);					
														if ($x > 500 or $y > 500) {if ($x>$y) $image->resizeToWidth(500);else $image->resizeToHeight(500);}
														$image->save($imgname. ".jpg");
											//resize
											}
											
										 }
									 $zip->close();
									 echo "Unzip ok<br>";
								     } else {
									 echo ‘failed’;
								     }

								}
									//cleanup:
									 		foreach (scandir("../download/temp/") as $item) {
												if ($item == '.' || $item == '..') continue;unlink("../download/temp/".$item);
											}
											if ($jpgsinzip==$i) {unlink("../download/". $filename);echo "<br>all jpgs extracted: deleted:", $filename;}
											else echo " <a href=\"javascript:;\" onmousedown=\"tinyMCE.execCommand('mceInsertContent',false,'<a href=../download/$filename>$filename</a>');\">$lang_txt_031: $filename</a>";

									//..cleanup

							}
							unlink($_FILES['uploaded_image']['tmp_name']); //temp löschen
							}
//ende Bild abspeichern

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


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

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

		$warning="";
		if (empty($text))$text=$_POST['text'];

		//check for valid menu entries
		if ($file=="dat_menu_file")
			{
			
				//translate for nestable:
				if (!empty($_POST['menusaved']))
				{
					//echo $_POST['menusaved'];
				
					if (get_magic_quotes_gpc()) {
					    $menusaved = stripslashes($_POST['menusaved']);
					}
					else {
					    $menusaved = $_POST['menusaved'];
					}
					//echo $menusaved;
					
					$menusaved=str_replace('"id":', '', $menusaved);
					
					if (!empty($_POST['new'])) {
					$menusaved=str_replace('new----entry', $_POST['newentry'],$menusaved , $wasitreplaced);
					if ($wasitreplaced==0) $menusaved="---+1---{---+1---{".$_POST['newentry']."----1-------1---".$menusaved;
								}
					$menusaved=str_replace('"children":', '', $menusaved);
					$menusaved=str_replace('\n', '', $menusaved);
					$menusaved=str_replace('not-used-in-menu', '', $menusaved);
					$menusaved=str_replace('"', "", $menusaved);
					$menusaved=str_replace('}', '', $menusaved);
					$menusaved=str_replace('",', '', $menusaved);
					$menusaved=str_replace(',', '', $menusaved);
					$menusaved=str_replace('[', '---+1---', $menusaved);
					$menusaved=str_replace(']', '----1---', $menusaved);
					$menusaved=str_replace('new----entry', '', $menusaved);
					
					
					//echo "<br>", $menusaved;
					$array = explode ('{', $menusaved);
		
					$ebene=0;//echo count($array);
						for ($i=1; $i<(count($array));$i++)
						{
						 	if ($array[$i]!="" and $array[$i]!=" " and $array[$i]!="\n" and (!empty($array[$i])))
							{
							if ($i>2 and $array[$i]!="---+1---" and $array[$i]!="----1---") $text=  $text."\n";
							if ($i==2 and leftspaces($array[$i-1])==0 and $array[$i-1]!="---+1---" and $array[$i-1]!="----1---" and $array[$i-1]!="") $text=  $text."\n";
							if (leftspaces($array[$i])==0 and strlen($array[$i]>0) and $i==1) $text=  $text."\n";

							$text= $text.str_repeat(" ", $ebene).trim(str_replace('----1---', '',str_replace('---+1---', '', $array[$i])));
							if (leftspaces($array[1])==0 and $i==1) $text=trim($text);	//remove linebreaks at the Beginn
							$ebene=$ebene+substr_count($array[$i], '---+1---');
							$ebene=$ebene-substr_count($array[$i], '----1---');
							}	
						}
				}
				$text=rtrim($text);//remove linebreaks at the End	
				//echo $array[0];
				
				//...translate for nestable
				 //if (substr($myStr, $text, 1)=="\n") echo "fistlinebreak";
				$readmenuentries = file_get_contents($Pfad); 
				$arraymenues = explode ("---///___", $readmenuentries);
				$menues= $arraymenues[2];
				$menuentries=explode ("\n",$menues);
				if (count($menuentries)==1) $text=trim($text); //first entries should not be disabled
				$menuentriesnew=explode ("\n",$text);
				//alt
				for ($i=0; $i<count($menuentries);$i++)
				{ $is_old_entry_still_there="0";
					if (strlen(trim($menuentries[$i]))>1) 
					{$found=0;
					
						for ($j=0; $j<count($menuentriesnew);$j++){ if (trim(str_replace(",","",str_replace("\"","",str_replace("'","",str_replace("\'","",trim($menuentriesnew[$j]))))))==trim(str_replace(",","",str_replace("\"","",str_replace("'","",str_replace("\'","",trim($menuentries[$i]))))))){$is_old_entry_still_there="found_it";$found++;}}
						if ($is_old_entry_still_there=="0") $warning="$warning $menuentries[$i]<br />";
						if ($found>1) $warning="$menuentries[$i] $lang_txt_048<br />";
					} 
				}
			}
		if( isset( $_POST['i_know_what_i_do'] ) ) if ($_POST['i_know_what_i_do']=="yes") $warning="";
		//ende check

		$datum=to_unixtime($_POST['datum']);
		$savethetext=str_replace("\r","",str_replace("\n","",$_POST['titel'])) ."---///___". str_replace("\r","",str_replace("\n","",$_POST['meta']))."---xxx___". str_replace("\r","",str_replace("\n","",$datum))."---xxx___". str_replace("\r","",str_replace("\n","",ltrim($_POST['fileandpathname'],'/')))."---xxx___". str_replace("\r","",str_replace("\n","",$_POST['titelmenu']))."---xxx___". str_replace("\r","",str_replace("\n","",$_POST['smalldescription']))."---xxx___". str_replace("\r","",str_replace("\n","",$_POST['newsentry']))."---xxx___". str_replace("\r","",str_replace("\n","",$_POST['preview']))."---xxx___". time()."---xxx___". $_POST['addfeedback']."---///___". $text;
		if (get_magic_quotes_gpc()==1) $savethetext=stripslashes($savethetext);
	
		if ($warning=="") 
			{

				if (!empty($savethetext))
				{

							//old Versions...
							if ($_POST['reload_backup']=="save article and RestorePoint RP")
							{
							for( $xf = 100; $xf >= 0; $xf-- )
							{ 
								$Pfadbu= "../daten/xxbu_".$xf."_$file.dat";
								if(file_exists("../daten/xxbu_last_rp_$file.dat"))$xfp1=$xf+2;else $xfp1=$xf+1;
								$Pfadbup1="../daten/xxbu_". $xfp1 ."_$file.dat";
								if ($xf==0) $Pfadbu=$Pfad;
								if(file_exists($Pfadbu)){copy($Pfadbu, $Pfadbup1);}	
							}
							if(file_exists("../daten/xxbu_last_rp_$file.dat")){copy("../daten/xxbu_last_rp_".$file.".dat", "../daten/xxbu_1_".$file.".dat");unlink("../daten/xxbu_last_rp_$file.dat");}
							//...old Versions
							}else {if(!file_exists("../daten/xxbu_last_rp_$file.dat")){copy($Pfad, "../daten/xxbu_last_rp_$file.dat");;}}

				$datei = fopen($Pfad, "w+");
				fwrite($datei, $savethetext);
				fclose($datei);
				

				}
			}




		/*** save additional Infos write file dat_menu_file2.dat ***/
			/*** read entry***/
			$fileadd="dat_menu_file";
			$Pfadadd= "../daten/$fileadd.dat";
			$dateiadd = fopen($Pfadadd, "r");if (filesize($Pfadadd)>10000) $filesize=10000;else $filesize=filesize($Pfadadd);
			$savethetextadd=fread($dateiadd, $filesize);
			fclose($dateiadd);
			$arrayseiteadd = explode ("---///___", $savethetextadd);
			$textadd= $arrayseiteadd[2];
			$menuarrayadd=explode ("\n",$textadd);


		for ($i=0; $i<count($menuarrayadd);$i++)
		{
			$fileadd=encodeurl(trim($menuarrayadd[$i]));
			
			$Pfadadd= "../daten/$fileadd.dat";
			$dateiadd = fopen($Pfadadd, "r");
			$savethetextadd=fread($dateiadd, filesize($Pfadadd));
			fclose($dateiadd);unset ($arrayseiteadd);unset($datumadd);unset($titeladd);unset($metaadd);unset($fileandpathnameadd);
			$arrayseiteadd = explode ("---///___", str_replace("\n", "",$savethetextadd));
			$titeladd= trim(str_replace("\n", "",$arrayseiteadd[0]));
			$arrayseiteaddd = explode ("---xxx___", str_replace("\n", "",$arrayseiteadd[1]));
			$metaadd= str_replace("\n", "",$arrayseiteaddd[0]);
			$datumadd= str_replace("\n", "",$arrayseiteaddd[1]);
			if ($fileadd==encodeurl(trim($_POST['newentry']))) $datumadd=999999999;
			$titelmenuadd = str_replace("\n", "",$arrayseiteaddd[3]); if (empty($titelmenu))$titelmenu=decodeurl($file);
			$fileandpathnameadd= trim(str_replace("\n", "",$arrayseiteaddd[2]));$trimit=trim($menuarrayadd[$i]);
			$smalldescriptionadd =str_replace("\n", "",$arrayseiteaddd[4]);
			$newsentryadd =$arrayseiteaddd[5];
			$preview =$arrayseiteaddd[6];
			if (!empty($menuarrayadd[$i]) and !empty($datumadd)){$savethetextremember="$savethetextremember".$datumadd ."---///___". $titeladd."---///___". $metaadd."---///___". $fileandpathnameadd."---///___". $fileadd."---///___". $titelmenuadd."---///___". $smalldescriptionadd."---///___". $newsentryadd."---///___". $preview. "\n";
			//$savethetextremember=str_replace("\n", "",str_replace("\n", "",$savethetextremember));
			if (!empty($fileandpathnameadd))$savethetextmodrewrite=$savethetextmodrewrite. " RewriteRule ". $fileandpathnameadd."$ index.php/".$fileadd." [L]\n";
			}else $savethetextremember="$savethetextremember"."\n";



		}
			/*** write dat_menu_file2.dat ...***/
			if (!empty($savethetextremember))
			{$Pfadadd="../daten/dat_menu_file2.dat";
			$dateiadd = fopen($Pfadadd, "w");
			fwrite($dateiadd, $savethetextremember);
			fclose($dateiadd);
			}
			/***... write dat_menu_file2.dat ***/

			if (function_exists('apache_get_modules')) {
				   $modules = apache_get_modules();
				   $mod_rewrite_enabled = in_array('mod_rewrite', $modules);
				 } else {
				   $mod_rewrite_enabled =  getenv('HTTP_MOD_REWRITE')=='On' ? true : false ;
			 }
			 if ($mod_rewrite_enabled==1)
			 {
			/*** write Mod Rewrite file ...***/
			$Pfadhto= "../htaccess";
			$dateihto = fopen($Pfadhto, "r");
			$savethetexthto=fread($dateihto, filesize($Pfadhto));
			fclose($dateihto);
			$Pfadhtotemp= "../$templatedir"."htaccess";
			$dateihtotemp = fopen($Pfadhtotemp, "r");
			$savethetexthtotemp=fread($dateihtotemp, filesize($Pfadhtotemp));
			fclose($dateihtotemp);
			$Pfadht="../.htaccess";
			$dateiht = fopen($Pfadht, "w");
			fwrite($dateiht, "RewriteEngine on\n");

			fwrite($dateiht, $savethetextmodrewrite);
			fwrite($dateiht, $savethetexthto);
			fwrite($dateiht, $savethetexthtotemp);
			fclose($dateiht);
			}
			//RewriteRule themen/help.php$ index.php/help [L]
			/*** ...write Mod Rewrite file 

		/***... save additional Infos***/

		if ($file=="dat_menu_file" and $warning==""){ if (!empty($_POST['new'])) {
				echo "<script language=\"javascript\">window.location.href = \"",$Pfadadmin,"/admin.php?file=", encodeurl($_POST['newentry']), "&title=",urlencode($_POST['newentry']),"\"</script>";}
				else echo "<script language=\"javascript\">window.location.href = \"",$Pfadadmin,"/admin.php\"</script>";}
		}



	/*** read entry***/
	if ($_POST['reload_backup']!="save article and RestorePoint RP" and !empty($_POST['reload_backup'])){ $versiontoload= explode ("-",$_POST['reload_backup']); $savethetext= file_get_contents("../daten/xxbu_".$versiontoload[1]."_$file.dat"); echo "reloaded saved Version: ", $versiontoload[1];}
	if ($_POST['reload_backup']=="undo last restore") $savethetext= file_get_contents("../daten/xxbu_last_rp_$file.dat");
	if (empty($savethetext)) $savethetext= file_get_contents($Pfad);
	$arrayseite = explode ("---///___", $savethetext);
	if (empty($titel))$titel= $arrayseite[0];if (empty($titel))$titel=trim(urldecode($_GET['title']));
	$text= $arrayseite[2];
	$arrayseiteadd = explode ("---xxx___", $arrayseite[1]);
	$meta= $arrayseiteadd[0];
	$titelmenu =$arrayseiteadd[3]; if (empty($titelmenu))$titelmenu=trim(urldecode($_GET['title']));if (empty($titelmenu))$titelmenu=$titel;
	$smalldescription =$arrayseiteadd[4];
	$newsentry =$arrayseiteadd[5];
	if( isset( $arrayseiteadd[6] ) )$preview =$arrayseiteadd[6];else $preview="";
	$addfeedback=$arrayseiteadd[8];
	$datum= $arrayseiteadd[1];
	$fileandpathname= $arrayseiteadd[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 />";}

	echo "<div class=\"editor\">";	if ($file=="dat_menu_file") echo "<h1>$lang_txt_008</h1>";
	echo "<div style=\"float:left;width:250px\">";

	if (empty($datum)) $datum= @date("d.m.Y H:i",time());else $datum=@date("d.m.Y H:i",$datum);
	//zurückwandeln: $datum=mktime($datum);
	if ($file!="dat_menu_file")echo "", $lang_txt_019, "<br /><textarea class=\"input1\" type=\"text\" title=\"$lang_txt_081\" name=\"titel\" ROWS=2 COLS=28 WRAP='virtual'>",$titel, "</textarea>";
	if ($file!="dat_menu_file" and $file!="Startseite")echo "<small>", $lang_txt_046, "<br /><textarea class=\"input1\" type=\"text\" name=\"smalldescription\" title=\"$lang_txt_084\" ROWS=2 COLS=28 WRAP='virtual'>",$smalldescription, "</textarea></small>";
	echo "</div><div style=\"margin:0px;float:left;\">";
	if ($file!="dat_menu_file" and $file!="Startseite")echo "<small>", $lang_txt_042, "</small><br /><textarea class=\"input2\" type=\"text\" title=\"$lang_txt_085\" name=\"titelmenu\" ROWS=2 COLS=28 WRAP='virtual'>",$titelmenu, "</textarea>";	

	if ($file!="dat_menu_file" and $file!="Startseite")echo "<br /><small>", $lang_txt_040, "</small><br /><textarea class=\"input2\" title=\"$lang_txt_083\" type=\"text\" name=\"datum\" ROWS=1 COLS=28 WRAP='virtual'>",$datum, "</textarea>";
	echo "</div><div style=\"margin-left:10px;float:left;\">";
	if ($file!="dat_menu_file")echo "<small>", $lang_txt_020, "<br /><textarea class=\"input2\" title=\"$lang_txt_082\" type=\"text\" name=\"meta\" ROWS=2 COLS=28 WRAP='virtual'>",$meta, "</textarea></small>";
	if ($modrewrite=="on") if ($file!="dat_menu_file" and $file!="Startseite")echo "<br /><small>", $lang_txt_041, "</small><br /><textarea class=\"input2\" type=\"text\" name=\"fileandpathname\" ROWS=2 COLS=28 WRAP='virtual'>",$fileandpathname, "</textarea>";
	if ($file!="dat_menu_file" and $file!="Startseite"){echo "<br /> <small>", $lang_txt_047, "<input type=\"checkbox\" title=\"$lang_txt_086\" name=\"newsentry\" value=\"1\" ";if ($newsentry==1) echo "checked"; echo ">";}
	if ($file!="dat_menu_file" and $file!="Startseite"){echo "<br />", $lang_txt_090, "<input type=\"checkbox\" title=\"$lang_txt_091\" name=\"addfeedback\" value=\"1\" ";if ($addfeedback==1) echo "checked"; echo "></small>";}

	echo "</div><div style=\"clear:both;margin:0px;\"></div>";

	echo "<INPUT TYPE='HIDDEN' NAME='submit' VALUE='update'>";
	echo "<textarea type=\"text\"";
	if ($file!="dat_menu_file") echo " id=\"mce\""; 
	echo " name=\"text\"";
	if ($file=="dat_menu_file") echo " title=\"$lang_txt_072\"";
	echo " ROWS=30 COLS=100>",htmlentities($text), "</textarea>";
	echo "<table><tr><td valign=\"top\">";
	if ($file!="dat_menu_file") echo " $lang_txt_012 <input type=\"file\" title=\"$lang_txt_087\" name=\"uploaded_image\" />";
	echo "<br />", $lang_txt_007, "<input type=\"submit\" class=\"submit\" title=\"$lang_txt_080\" value=\"update\">";echo "<div title=\"",$lang_txt_068,"\" style=\"float:right;\"> Server-File-Limit:", (int)(ini_get('upload_max_filesize')) ,"MB</div>";



	echo "</td><td>";

if ($file!="dat_menu_file") {
		echo "<select title=\"$lang_txt_088\" name=\"reload_backup\"><option>save article and RestorePoint RP</option>";
					
 		if ($_POST['reload_backup']!="save article and RestorePoint RP" and !empty($_POST['reload_backup'])) echo "<option>undo last restore</option>";

							for( $xx = 1; $xx < 100; $xx++ )
							{ 
								$Pfadbu= "../daten/xxbu_".$xx."_$file.dat";
								if (file_exists($Pfadbu)) {
										//read
										$datei = fopen($Pfadbu, "r");
										$savethetext=fread($datei, filesize($Pfad));
										fclose($datei);
										$arrayseite = explode ("---///___", $savethetext);
										//$text= $arrayseite[2];
										//$menuarray=explode ("\n",$text);
											//$text= $arrayseite[2];
											$arrayseiteadd = explode ("---xxx___", $arrayseite[1]);
											$moddate= $arrayseiteadd[7];
										echo "<option>load version: ", date("d.m.Y H:i",$moddate);
										echo " RP-",$xx,"</option>";
								}
							}echo "</select><br>";
			}
	if ($file!="dat_menu_file") echo "<iframe src=\"supa/img.php?load=iframe&tag=$file\" frameborder=\"0\" width=\"400\" height=\"55\" scrolling=\"no\"></iframe>";
	echo "</td></tr></table></div>";

					$imageexists="0";
					$imgname= "../image/" .$file;
					for( $xf = 1; $xf < 999; $xf++ )
					{$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 class=\"minibox\">";
						if (!empty($endung)){echo "<div style=\"float:left\"><input type=\"radio\" name=\"preview\" value=\"$xf\"";$imageexists=1;
							if ($_GET['deleteimg']== $preview) $preview=0;
							if ($preview==$xf) echo " checked";
							if ($alreadychecked!=1)if ($preview==0) {echo " checked";$alreadychecked=1;}
							echo " title=\"",$lang_txt_067,"\">";
							if($endung=="jpg")
							{if(file_exists($imgname ."-".$xf."-800.jpg")) $img800present=1;else $img800present=0;
							if ($img800present==1) echo "<a href=\"javascript:;\" onmousedown=\"tinyMCE.execCommand('mceInsertContent',false,'<a href=$imgname-$xf-800.", $endung," rel=lightbox[roadtrip]><img src=$imgname-$xf-150.", $endung,"?cache=", $filetime,"></a>');\" title=\"", $lang_txt_064,"\">S</a> <a href=\"javascript:;\" onmousedown=\"tinyMCE.execCommand('mceInsertContent',false,'<img src=$imgname-$xf-800.", $endung,"?cache=", $filetime,">');\" title=\"", $lang_txt_115,"\">L</a> ";
							else echo "<a href=\"javascript:;\" onmousedown=\"tinyMCE.execCommand('mceInsertContent',false,'<a href=$imgname-$xf.", $endung," rel=lightbox[roadtrip]><img src=$imgname-$xf-150.", $endung,"?cache=", $filetime,"></a>');\" title=\"", $lang_txt_064,"\">S</a> ";
							if ($img800present==0) echo "<a href=\"javascript:;\" onmousedown=\"tinyMCE.execCommand('mceInsertContent',false,'<a href=$imgname-$xf.", $endung," rel=lightbox[roadtrip]><img src=$imgname-$xf.", $endung,"?cache=", $filetime,"></a>');\" title=\"", $lang_txt_065,"\">L</a>";
							}
							echo "</div>";}
						if (!empty($endung))echo "<small><small><a href=\"admin.php?file=",$file,"&deleteimg2=", $xf,"#delete\" title=\"",$lang_txt_018,"\" style=\"float:right\">X</a></small></small>";
						if($endung=="jpg"){$filetime=date ("Y-m-dH-i-s", filemtime($imgname ."-".$xf.".jpg"));
						if ($img800present==1) { echo " <a href=\"javascript:;\" onmousedown=\"tinyMCE.execCommand('mceInsertContent',false,'<a href=$imgname-$xf-800.", $endung," rel=lightbox[roadtrip]><img src=$imgname-$xf.", $endung,"?cache=", $filetime,"></a>');\"><img src=\"", $imgname,"-",$xf,"-150.", $endung,"?cache=", $filetime,"\" title=\"", $lang_txt_015, $endung,"\"/></a>";
						$rememberallimagesforminipictures=$rememberallimagesforminipictures. " <a href=$imgname-$xf-800.". $endung." rel=lightbox[roadtrip]><img src=$imgname-$xf-150.". $endung."?cache=". $filetime."></a>";
						}
						else {echo " <a href=\"javascript:;\" onmousedown=\"tinyMCE.execCommand('mceInsertContent',false,'<img src=$imgname-$xf.", $endung,"?cache=", $filetime,">');\"> <img src=\"", $imgname,"-",$xf,"-150.", $endung,"?cache=", $filetime, "\" title=\"", $lang_txt_016, $endung,"\"/></a>";	
						$rememberallimagesforminipictures=$rememberallimagesforminipictures. " <a href=$imgname-$xf.". $endung." rel=lightbox[roadtrip]><img src=$imgname-$xf-150.". $endung."?cache=". $filetime."></a>";
							}			
						}

						if($endung=="png" or $endung=="gif")
						{if($endung=="png")$filetime=date ("Y-m-dH-i-s", filemtime($imgname ."-".$xf.".png"));else $filetime=date ("Y-m-dH-i-s", filemtime($imgname ."-".$xf.".gif"));
						echo "<a href=\"javascript:;\" onmousedown=\"tinyMCE.execCommand('mceInsertContent',false,'<img src=$imgname-$xf.", $endung,"?cache=", $filetime,">');\"><img src=\"", $imgname,"-",$xf, ".", $endung,"?cache=", $filetime,"\" width=200px title=\"",$lang_txt_017, $endung,"\"/></a>";}
						if (!empty($endung))echo "</div>";
							
					}
if ($imageexists==1) {echo "<div class=\"miniboxall\" style=\"background:#c44;\">",$lang_txt_066,"<a href=\"javascript:;\" onmousedown=\"tinyMCE.execCommand('mceInsertContent',false,'".$rememberallimagesforminipictures. "');\" style=\"color:#fff;\" title=\"", $lang_txt_062,"\">150px</a>";
echo "<br><a href=\"javascript:;\" onmousedown=\"tinyMCE.execCommand('mceInsertContent',false,'".str_replace ("-150", "", $rememberallimagesforminipictures). "');\" style=\"color:#fff;\" title=\"", $lang_txt_063,"\">500px</a></div>";}
//bild löschen:
if (!empty($_GET['deleteimg2']))
{echo "<a name=\"delete\"></a><a href=\"admin.php?file=",$file,"&deleteimg=", $_GET['deleteimg2'],"\">", $lang_txt_003, "</a> <br /><br />";
}							
	echo "</form>";
}else
{
if (empty($setup))
{ 
		/*** read entry***/
		$file="dat_menu_file";
		$Pfad= "../daten/$file.dat";
		$datei = fopen($Pfad, "r");
		$savethetext=fread($datei, filesize($Pfad));
		fclose($datei);
		$arrayseite = explode ("---///___", $savethetext);
		$text= $arrayseite[2];
		$menuarray=explode ("\n",$text);



		/*** read ADDITIONAL***/
		$file="dat_menu_file2";
		$Pfad= "../daten/$file.dat";$datei = fopen($Pfad, "r");$savethetext=fread($datei, filesize($Pfad));fclose($datei);
		$menuarray2=explode ("\n",$savethetext);


	echo "<h1 id=\"scrollUp\" style=\"margin-left:0px;width:400px;\">", $lang_txt_010,"</h1>";
	echo "";


//nestable
?>	    
	<a href=admin.php?file=Startseite title="<?php echo $lang_txt_011." ".$lang_txt_069;?>" style="width:49%;float:left;text-align:left;padding-top:0px;left:0px;" class="startseite"><?php echo $lang_txt_011;?></a>

	<div class="cf nestable-lists">
	<div class="dd" id="nestable" style="width:49%;height:78%;position:absolute;overflow:auto;float:left;">
	 <ol class="dd-list"> 

	<?php 



	//hier angepasste buildmenuul
		
		$mainmenu="";
		for ($i=0; $i<count($menuarray);$i++)
			{ 
							if ($i==0 and leftspaces($menuarray[$i])>0) {$mainmenu= "$mainmenu
							<li class=\"dd-item\" id=\"no-handle\" data-id=\"not-used-in-menu\">  
							<div title=\"$lang_txt_133\" class=\"no-handle\">$lang_txt_132</div>";
							for ($k=0;$k<leftspaces($menuarray[$i]);$k++) $mainmenu= "$mainmenu <ol class=\"dd-list\">";
							}
							
							$arrayseiteadd = explode ("---///___", $menuarray2[$i]);
							$datumarray[$i]= trim($arrayseiteadd[0]);

							$mainmenu= "$mainmenu \n<li class=\"dd-item\" data-id=\"".trim($menuarray[$i])."\"> ";							
							if (!empty($titelmenuarray[$i]))$displaytitle=$titelmenuarray[$i];else $displaytitle=$menuarray[$i];unset ($linkurl);
							if (!empty($fileandpathnamearray[$i]))$linkurl= $fileandpathnamearray[$i] ;else $linkurl=$index. "/".encodeurl($menuarray[$i]);
							$mainmenu= "$mainmenu \n<a name=\"".encodeurl($menuarray[$i])."\"><a href=\"admin.php?file=". encodeurl($menuarray[$i])."&title=".urlencode(str_replace("'","",trim($menuarray[$i])))."\" style=\"float:left;\"";
							$trimit=trim($menuarray[$i]);
							if (empty($ignoreleftspaces)) if (leftspaces($menuarray[$i])<1 and $trimit{0}!="'")$ignoreleftspaces="donotignore";							
							if ($datumarray[$i]>time() or empty($ignoreleftspaces) or $trimit{0}=="'")$mainmenu= "$mainmenu class=\"color1\"";
							elseif (leftspaces($menuarray[$i])!=0)$mainmenu= "$mainmenu class=\"color2\"";
							$mainmenu= "$mainmenu title=\"$lang_txt_071:$menuarray[$i] $lang_txt_069\">".trim($displaytitle). "</a>";
							if ($datumarray[$i]>time())$mainmenu= $mainmenu." <font style=\"font-size:8px;color:#aaa;float:left;\">(".date("d.m.Y H:i",$datumarray[$i]).")</font>";

							$mainmenu= $mainmenu."<div title=\"$lang_txt_116\" class=\"dd-handle\"></div>";



							//if ($i==0) $mainmenu="$mainmenu </li>"; //nicht sicher ob das passt ...
							if (isset($menuarray[$i+1])){$nextmenu=$menuarray[$i+1];}

					
							if (leftspaces($menuarray[$i])==leftspaces($nextmenu)) $mainmenu= "$mainmenu </li>\n";

							for ($k=0;$k<leftspaces($menuarray[$i])-leftspaces($nextmenu);$k++) $mainmenu= "$mainmenu \n</li>\n</ol>";
							//for ($k=0;$k<leftspaces($menuarray[$i])-leftspaces($nextmenu);$k++) $mainmenu= "$mainmenu \n</ol>";
							
						for ($k=0;$k<leftspaces($nextmenu)-leftspaces($menuarray[$i]);$k++) $mainmenu= "$mainmenu \n<ol class=\"dd-list\">";
							


						

			}
	if (count($menuarray)!=1 or strlen($menuarray[0])>1) echo $mainmenu; else echo "<li class=\"dd-item\" data-id=\"not-used-in-menu\"><div title=\"$lang_txt_133\" class=\"no-handle\">$lang_txt_132</div></li>";

	?>

	</ol>


	</div>
	<div id="scrollDown" style="position:absolute; bottom:0; left:0; width:50%;">&nbsp;</div>
	<div class="dd" id="nestable2" style="width:46%;float:right;top:-100px;padding:4px;">
		<div class="nestable-menu">

		<?php 
		if (instr("MSIE 8.0",$_SERVER['HTTP_USER_AGENT']) or instr("MSIE 7.0",$_SERVER['HTTP_USER_AGENT']) or instr("MSIE 6.0",$_SERVER['HTTP_USER_AGENT'])) {
		$support_browser="no";}else {
		echo "<form action=\"admin.php?file=dat_menu_file\" enctype=\"multipart/form-data\" method=\"post\">";
		echo "<input type=\"submit\" class=\"submit\" title=\"$lang_txt_118\" value=\"$lang_txt_117\">";}?>

		<menu id="nestable-menu">
		<button type="button" data-action="expand-all" title="<?php echo $lang_txt_130;?>"><?php echo $lang_txt_119;?></button>
		<button type="button" data-action="collapse-all" title="<?php echo $lang_txt_131;?>"><?php echo $lang_txt_120;?></button>
	    	</menu>
		</div><br>
<?php 
if ($support_browser=="no") echo "<div class=\"warning\">$lang_txt_122</div>";else 
{?>
	<h1 style="margin-left:0px"><?php echo $lang_txt_123;?></h1>
	<div class="newtopic" title="<?php echo $lang_txt_129;?>">

	    <input type="hidden" id="nestable-output" name="menusaved">
	<input type="hidden" value="update" name="submit">
	<?php echo $lang_txt_123;?> <small style="line-height:10px"><?php echo $lang_txt_124;?></small><br>
	<?php echo $lang_txt_125;?><input type="text" value="" size="50" style="line-height:15x;height:15x;" name="newentry" title="<?php echo $lang_txt_126;?>">
	<input type="submit" class="submit" name="new" title="<?php echo $lang_txt_127;?>" value="<?php echo $lang_txt_137;?>">
	</form>
	<li class="dd-item" data-id="new----entry">

	<div class="dd-handle" title="<?php echo $lang_txt_128;?>"><?php echo $lang_txt_121;?></div>
		      </div>

<?php }?>

	    

	<script language="JavaScript" type="text/javascript" src="../plugins/jquery/jquery-1.7.2.min.js"></script>


		<script>
		var scrolling = false;
		$("#scrollUp").bind("mouseover", function(event) {
		    scrolling = true;
		    scrollContent("up");
		});
		$("#nestable").bind("mouseover", function(event) {
		    scrolling = false;
		});
		$("#navi2").bind("mouseover", function(event) {
		    scrolling = false;
		});

		$("#scrollDown").bind("mouseover", function(event) {
		    scrolling = true;
		    scrollContent("down");
		});

		function scrollContent(direction) {
		    var amount = (direction === "up" ? "-=10px" : "+=10px");
		    $("#nestable").animate({
			scrollTop: amount
		    }, 1, function() {
			if (scrolling) {
			    scrollContent(direction);
			}
		    });
		}</script>

	<script src="jquery.nestable.js"></script>
	<script>


	$(document).ready(function()
	{
	     var updateOutput = function(e)
	    {
		var list = e.length ? e : $(e.target),
		    output = list.data('output');
		if (window.JSON) {
		    output.val(window.JSON.stringify(list.nestable('serialize')));//, null, 2));
		} else {
		    output.val('JSON browser support required for this demo.');
		}
	    };

	    // activate Nestable for list 1
	    $('#nestable').nestable({
		group: 1
	    })
	    .on('change', updateOutput);
	    <?php if ($expand_all=="collapse") echo "$('#nestable').nestable('collapseAll');";?>
	    // activate Nestable for list 2
	    $('#nestable2').nestable({
		group: 1
	    })
	    .on('change', updateOutput);

	    // output initial serialised data
	    updateOutput($('#nestable').data('output', $('#nestable-output')));
	    updateOutput($('#nestable2').data('output', $('#nestable2-output')));

	    $('#nestable-menu').on('click', function(e)
	    {
		var target = $(e.target),
		    action = target.data('action');
		if (action === 'expand-all') {
		    $('.dd').nestable('expandAll');
		}
		if (action === 'collapse-all') {
		    $('.dd').nestable('collapseAll');
		}
	    });

	    $('#nestable3').nestable();

	});
	</script>
<?php
//..nestable

/*old working Menu:
	for ($i=0; $i<count($menuarray);$i++){
		$arrayseiteadd = explode ("---///___", $menuarray2[$i]);
		$datumarray[$i]= trim($arrayseiteadd[0]);

	$ebene=strlen(str_replace(trim($menuarray[$i]), "",chop($menuarray[$i])));
	echo str_repeat("&nbsp;-", $ebene);
	echo "<a name=\"",encodeurl($menuarray[$i]),"\"><a href=admin.php?file=", encodeurl($menuarray[$i]), "&title=",urlencode(str_replace("'","",trim($menuarray[$i])));
	$trimit=trim($menuarray[$i]);
	if (empty($ignoreleftspaces)) if (leftspaces($menuarray[$i])<1 and $trimit{0}!="'")$ignoreleftspaces="donotignore";	

	if ($datumarray[$i]>time() or empty($ignoreleftspaces) or $trimit{0}=="'")echo " class=\"color1\"";
	elseif (leftspaces($menuarray[$i])!=0)echo " class=\"color2\"";

	echo " title=\"$lang_txt_071:$menuarray[$i] $lang_txt_069\">",$menuarray[$i],"</a></a>";if ($datumarray[$i]>time())echo "<font style=\"font-size:8px;color:#aaa;\">(",date("d.m.Y H:i",$datumarray[$i]),")</font>";
	echo"<br>";}
old working menu*/



//right admin links ..
//latest ...
//echo "<div style=\"float:right;height:90%;position:absolute;margin-left:50%; overflow:auto;width:47%;\">



echo "<br><div class=\"newsufuture\">
<h1 style=\"margin-left:0px;\">", $lang_txt_052,"</h1>";
@include(getcwd()."../buildpage.php");
arsort($datumarray);$nummer=0;
foreach($datumarray as $key => $value) 
	{
 	if (!empty($menuarray[$key]) and !empty($datumarray[$key])) {if ($datumarray[$key]<time()) {$nummer++; if (empty($onlyonce)) { echo "<h1 style=\"margin-left:0px\">", $lang_txt_051,"</h1>"; $onlyonce=1;}}
	echo date("d.m.Y H:i",$datumarray[$key]). " <a href=\"admin.php?file=", encodeurl(trim($menuarray[$key])), "&title=", urlencode(trim($menuarray[$key])),"\"  title=\"$lang_txt_071:$menuarray[$key] $lang_txt_069\" class=\"color2\">".$menuarray[$key],"</a><br />";}
	if ($nummer>20){break;}
	}
//ende latest

}
	
echo "</div>"; // background
//right admin links
}

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