<?php
/*
++++++++++++++++++++++++++++++++++++++++++++++++++++++
| LightNEasy Content Management System
| Copyright 2007 - 2008 Fernando Baptista
| http://LightNEasy.org
++++++++++++++++++++++++++++++++++++++++++++++++++++++
| admin.php admin functions module
| no database Version 2.2.1
++++++++++++++++++++++++++++++++++++++++++++++++++++++
| Released under the terms & conditions of v2 of the
| GNU General Public License. For details refer to
| the included gpl.txt file or visit http://gnu.org
++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/

function treat_posts() {
	global $message, $edit, $editextra, $langmessage, $set, $pagenum, $menu;

	if(isset($_POST['return'])) {
		unset($_GET['do']);
		unset($_POST['submit']);
		$edit=0;
		$editextra=0;
	}

	switch($_POST['submit']) {
		case "Create Gallery":
			if(!is_dir("galeries/".$_POST['galeryname'])) mkdir("galeries/".$_POST['galeryname'], 0777) or die($langmessage[63]);
			else $message=$langmessage[65];
			break;
		case "Save":
			$fp=fopen("data/".$_POST['pagenum'].".html","w");
			fwrite($fp,$_POST['mycontent']);
			fclose($fp);
			@chmod("data/".$_POST['pagenum'].".html", 0777);
			$pages=readdata("pages");
			$count=0;
			while($pages[$count][0] != "") {
				if($pages[$count][0] == $pagenum) {
					if($_POST['description'] != "")
						$pages[$count][1] = $_POST['description'];
					else
						$pages[$count][1] = "-";
					if($_POST['template'] != "")
						$pages[$count][2] = $_POST['template'];
					else
						$pages[$count][2] = "-";
					break;
				}
				$count++;
			}
			$fp=fopen("data/pages.dat","w");
			$count=0;
			while($pages[$count][0] != "") {
				fwrite($fp,$pages[$count][0]."|".$pages[$count][1]."|".$pages[$count][2]."||");
				$count++;
			}
			fclose($fp);
			unset($_GET['do']);
			$message=$langmessage[102];
			readmenu();
			break;
		case "Save Extra":
			$fp=fopen("data/extra.htm","w");
			fwrite($fp,$_POST['mycontent']);
			fclose($fp);
			unset($_GET['do']);
			$message=$langmessage[102];
			break;
		case "Save Menu":
			$fp=fopen("data/menu.dat","w");
			fwrite($fp,encode($_POST['content']));
			fclose($fp);
			unset($_GET['do']);
			$message=$langmessage[134];
			readmenu();
			break;
		case "Delete Page":
			$count=0;
			$fp=fopen("data/menu.dat","w");
			while($menu[$count][0] != "") {
				if($menu[$count][3] != $pagenum)
					fwrite($fp,$menu[$count][0]."|".$menu[$count][1]."|".$menu[$count][2]."|".$menu[$count][3]."|".encode($menu[$count][4])."||\n");
				$count++;
			}
			fclose($fp);
			unlink("./data/$pagenum.html");
			unset($_GET['do']);
			$pagenum="index";
			readmenu();
			$message=$langmessage[104];
			break;
		case "Save Setup":
			$fp=fopen("data/config.php","w");
			fwrite($fp,"<?php\n");
			if($_POST['password']!="")
				fwrite($fp,"\$set['password']=\"".sha1($_POST['password'])."\";\n");
			else
				fwrite($fp,"\$set['password']=\"".$_POST['oldpassword']."\";\n");
			fwrite($fp,"\$set[\"homepath\"]=\"".$_POST['homepath']."\";\n");
			fwrite($fp,'$set[\'template\']="'.$_POST['template'].'";'."\n");
			fwrite($fp,'$set[\'title\']="'.encode($_POST['title']).'";'."\n");
			fwrite($fp,'$set[\'subtitle\']="'.encode($_POST['subtitle']).'";'."\n");
			fwrite($fp,'$set[\'keywords\']="'.encode($_POST['keywords']).'";'."\n");
			fwrite($fp,'$set[\'description\']="'.encode($_POST['description']).'";'."\n");
			fwrite($fp,'$set[\'author\']="'.encode($_POST['author']).'";'."\n");
			fwrite($fp,'$set[\'footer\']="'.encode($_POST['footer']).'";'."\n");
			fwrite($fp,'$set[\'openfield\']="'.$_POST['openfield'].'";'."\n");
			fwrite($fp,'$set[\'closefield\']="'.$_POST['closefield'].'";'."\n");
			fwrite($fp,'$set[\'gzip\']="'.$_POST['gzip'].'";'."\n");
			fwrite($fp,'$set[\'timeoffset\']="'.$_POST['timeoffset'].'";'."\n");
			fwrite($fp,'$set[\'extension\']="'.$_POST['extension'].'";'."\n");
			fwrite($fp,'$set[\'indexfile\']="'.$_POST['indexfile'].'";'."\n");
			fwrite($fp,'$set[\'fromname\']="'.$_POST['fromname'].'";'."\n");
			fwrite($fp,'$set[\'fromemail\']="'.$_POST['fromemail'].'";'."\n");
			fwrite($fp,'$set[\'toemail\']="'.$_POST['toemail'].'";'."\n");
			fwrite($fp,'$set[\'language\']="'.$_POST['language'].'";'."\n");
			fwrite($fp,'$set[\'langeditor\']="'.$_POST['langeditor'].'";'."\n");
			fwrite($fp,'$set[\'dateformat\']="'.$_POST['dateformat'].'";'."\n");
			fwrite($fp,"?>\n");
			fclose($fp);
			unset($_GET['do']);
			readsetup();
			break;
		case "Add Download":
			$succeded=false;
			if($_POST['filename']=="upload") { // upload file to folder downloads
				if($_FILES['uploadedfile']['name'] != "") {
					$target_path = "downloads/";
					$target_path .= basename( $_FILES['uploadedfile']['name']);
					if(file_exists($target_path)) unlink($target_path);
					if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
						$succeded=true;
						@chmod($target_path, 0644);
					} else {
						$message=$langmessage[123];
					}
				} else $message=$langmessage[97];
			}
			if(!$succeded) break;
		case "Edit Download":
			$aaa=trim(@file_get_contents("data/downloads.dat"));
			unset($download);
			$download=explode("||",$aaa);
			$count=0;
			$maxid=0;
			while($download[$count] != "") {
				$downloads[$count]=explode("|",$download[$count]);
				if($downloads[$count][0]>$maxid) $maxid=$downloads[$count][0];
				$count++;
			}
			$maxid++;
			if($succeded) $filenam=$_FILES['uploadedfile']['name'];
			else $filenam=htmlentities($_POST['link']);
			if($_POST['descr']=="") $_POST['descr']="-";
			if(($_POST['link']!="" || $succeded) && $_POST['linkname']!="") {
				if($_POST['submit'] == "Add Download") {
					if(!$fp=fopen("data/downloads.dat","a")) die($langmessage[3]);
					fwrite($fp,$maxid."|".encode($_POST['linkname'])."|".$filenam."|".encode($_POST['descr'])."|".$_POST['cat']."||");
				} else {
					if(!$fp=fopen("data/downloads.dat","w")) die($langmessage[3]);
					$count=0;
					while($downloads[$count][0]!="") {
						if($downloads[$count][0]==$_POST['id'])
							fwrite($fp,$maxid."|".encode($_POST['linkname'])."|".$filenam."|".encode($_POST['descr'])."|".$_POST['cat']."||");
						else
							fwrite($fp,$downloads[$count][0]."|".$downloads[$count][1]."|".$downloads[$count][2]."|".$downloads[$count][3]."|".$downloads[$count][4]."||");
						$count++;
					}
				}
				fclose($fp);
				unset($_GET['action']);
			}
			break;
		case "Add News":
		case "Edit News":
			$autor = encode($_POST["autor"]);
			$email= encode($_POST["email"]);
			$titulo = encode($_POST["titulo"]);
			$texto = htmlentities(stripslashes($_POST["mycontent"]));
			if($email=="") $email="-";
			if($titulo=="") $titulo="-";
			if($autor=="") $autor="-";
			if($texto=="") $texto="-";
			$cat=$_POST['cat'];
			$data = time();
			$array=readdata("news");
			if($_POST['submit'] == "Add News") {
				$i=0;
				$maxid=0;
				while($array[$i][0] != "") {
					if(strval($array[$i][0])>$maxid) $maxid=strval($array[$i][0]);
					$i++;
				}
				$maxid++;
				if(!$fp=fopen("data/news.dat","a")) die ($langmessage[76]);
				fwrite($fp,"$maxid|$autor|$email|$titulo|$texto|$data|1|$cat||");
			} else {
				if(!$fp=fopen("data/news.dat","w")) die ($langmessage[76]);
				$i=0;
				while($array[$i][0] != "") {
					if($_POST['reg']==$array[$i][0])
						fwrite($fp,$array[$i][0]."|$autor|$email|$titulo|$texto|$data|1|$cat||");
					else
						fwrite($fp,$array[$i][0]."|".$array[$i][1]."|".$array[$i][2]."|".$array[$i][3]."|".$array[$i][4]."|".$array[$i][5]."|".$array[$i][6]."|".$array[$i][7]."||");
					$i++;
				}
			}
			fclose($fp);
			$message=$langmessage[75];
			unset($_GET['action']);
			break;
		case "Add Link":
		case "Edit Link":
			$links=readdata("links");
			if($_POST['link']!="" && $_POST['linkname']!="") {
				if($_POST['submit'] == "Add Link") {
					$count=0;
					$maxid=0;
					while($links[$count][0]!="") {
						if($links[$count][0]>$maxid) $maxid=$links[$count][0];
						$count++;
					}
					$maxid++;
					if(!$fp=fopen("data/links.dat","a")) die($langmessage[5]);
					fwrite($fp,$maxid."|".encode($_POST['linkname'])."|".htmlentities($_POST['link'])."|".encode($_POST['descr'])."|".$_POST['cat']."||");
				} else { // edit link
					if(!$fp=fopen("data/links.dat","w")) die($langmessage[5]);
					$count=0;
					while($links[$count][0]!="") {
						if($links[$count][0]==$_POST['id'])
							fwrite($fp,$_POST['id']."|".encode($_POST['linkname'])."|".htmlentities($_POST['link'])."|".encode($_POST['descr'])."|".$_POST['cat']."||");
						else
							fwrite($fp,$links[$count][0]."|".$links[$count][1]."|".$links[$count][2]."|".$links[$count][3]."|".$links[$count][4]."||");
						$count++;
					}
				}
				fclose($fp);
				unset($_GET['action']);
			}
			break;
		case "Upload image":
			$message="";
			if($_FILES['uploadedfile']['name'] != "" && $_POST['gal']!="") {
				$target_path = "galeries/".$_POST['gal']."/";
				$target_path = $target_path.basename( $_FILES['uploadedfile']['name']);
				$_FILES['uploadedfile']['tmp_name'];
			} else $message=$langmessage[97];
			if($message=="") {
				if(file_exists($target_path)) unlink($target_path);
				if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
					chmod($target_path, 0644);
    				$message=$langmessage[124].  basename( $_FILES['uploadedfile']['name']).$langmessage[125];
				} else $message=$langmessage[123];
			}
			break;
		case "Create Page":
			$aaa=decode(file_get_contents("./data/menu.dat"));
			unset($mmenu);
			$mmenu=explode("||",$aaa);
			$count=0;
			foreach($mmenu as $mmmenu) {
				$menu[$count]=explode("|",trim($mmmenu));
				$count++;
			}
			$count=0;
			$fp=fopen("./data/menu.dat","w");
			$inc=0;
			while($menu[$count][0] != "") {
				$aa=$menu[$count][0]."|".$menu[$count][1]."|".$menu[$count][2]."|".$menu[$count][3]."|".encode($menu[$count][4])."||\n";
				if($count == strval($_POST['count'])) {
					fwrite($fp,$aa);
					switch($_POST['level']) {
						case "1": {
							$bb=strval($menu[$count][0])+1;
							$aa=$bb."|0|0|".$_POST['filename']."|".encode($_POST['label'])."||\n";
							$inc=1;
							break;
						}
						case "2": {
							$bb=strval($menu[$count][1])+1;
							$aa=$menu[$count][0]."|".$bb."|0|".$_POST['filename']."|".encode($_POST['label'])."||\n";
							$inc=2;
							break;
						}
						case "3": {
							$bb=strval($menu[$count][2])+1;
							$aa=$menu[$count][0]."|".$menu[$count][1]."|".$bb."|".$_POST['filename']."|".encode($_POST['label'])."||\n";
							$inc=3;
							break;
						}
					}
					fwrite($fp,$aa);
				} else {
					if($inc) {
						switch($inc) {
							case 1: {
								if($menu[$count][0]>=$bb)
									$aa=strval($menu[$count][0]+1)."|".$menu[$count][1]."|".$menu[$count][2]."|".$menu[$count][3]."|".encode($menu[$count][4])."||\n";
								break;
							}
							case 2: {
								if($menu[$count][0]==$a && $menu[$count][1]>=$bb)
									$aa=$menu[$count][0]."|".strval($menu[$count][1]+1)."|".$menu[$count][2]."|".$menu[$count][3]."|".encode($menu[$count][4])."||\n";
								break;
							}
							case 3: {
								if($menu[$count][0]==$a && $menu[$count][1]==$b && $menu[$count][2]>=$bb)
									$aa=$menu[$count][0]."|".$menu[$count][1]."|".strval($menu[$count][2]+1)."|".$menu[$count][3]."|".encode($menu[$count][4])."||\n";
								break;
							}
						}
					}
					fwrite($fp,$aa);
				}
				$count++;
			}
			fclose($fp);
			$fp=fopen("./data/pages.dat","a");
			fwrite($fp,$_POST['filename']."|-|-||");
			fclose($fp);
			readmenu();
			$message=$langmessage[87];
			unset($_GET['do']);
			break;
	}
	if(isset($_POST['downloadcat']) || isset($_POST['linkcat']) || isset($_POST['newscat'])) {
		if($_POST['downloadcat']=="Add Category" || $_POST['downloadcat']=="Edit Category") $type="download";
		elseif($_POST['newscat']=="Add Category" || $_POST['newscat']=="Edit Category") $type="news";
		else $type="link";
		$filename="data/".$type."cat.dat";
		$aaa=trim(@file_get_contents($filename));
		unset($downloadcat);
		$downloadcat=explode("||",$aaa);
		$count=0;
		$maxid=0;
		while($downloadcat[$count] != "") {
			$downloadscat[$count]=explode("|",$downloadcat[$count]);
			if($downloadscat[$count][0]>$maxid) $maxid=$downloadscat[$count][0];
			$count++;
		}
		$maxid++;
		if($_POST['downloadcat']=="Add Category" || $_POST['linkcat']=="Add Category" || $_POST['newscat']=="Add Category") { // add
			if(!$fp=fopen($filename,"a")) die($langmessage[106]);
			fwrite($fp,$maxid."|".htmlentities($_POST['name'])."|".encode($_POST['descr'])."||");
		} else {
			if(!$fp=fopen($filename,"w")) die($langmessage[106]);
			$count=0;
			while($downloadscat[$count][0]!="") {
				if($downloadscat[$count][0]==$_POST['id'])
					fwrite($fp,$_POST['id']."|".encode($_POST['name'])."|".encode($_POST['descr'])."||");
				else
					fwrite($fp,$downloadscat[$count][0]."|".$downloadscat[$count][1]."|".$downloadscat[$count][2]."||");
				$count++;
			}
		}
		fclose($fp);
		unset($_GET['action']);
	}

	switch($_GET['do']) {
		case "edit":
			$edit=0;
			if($_SESSION[$set['password']]=="1") $edit=1;
			else unset($_GET['do']);
			break;
		case "editextra":
			$editextra=0;
			if($_SESSION[$set['password']]=="1") $editextra=1;
			else unset($_GET['do']);
			break;
		case "logout":
			unset($_SESSION[$set['password']]);
			session_destroy();
			unset($_GET['do']);
			$saida="Location: ".$set['homepath'];
			header($saida);
	}
}

function generate() {
	global $edit, $langmessage, $set, $pagenum, $menu, $templatepath, $selected, $LNEversion;
	$edit=0;
	$count=0;
	readmenu();
	while($menu[$count][0]!="") {
		$out="";
		$pagenum=$menu[$count][3];
		if(strval(strstr($pagenum, "#")))
			$pagenum=str_replace("#", "",$pagenum);
		if($set['extension']=="php")
			$templ="<?php\n\t\$pagenum=\"$pagenum\";\n\tinclude(\"LightNEasy/runtime.php\");\n?>\n";
		if($menu[$count][6] != "-")
			$templ.=file_get_contents("templates/".$menu[$count][6]."/template.php");
		else
			$templ.=file_get_contents($templatepath);
		if(!strval(strstr($menu[$count][3], "*"))) {
			$page=$templ;
			$selected['index']=$menu[$count][0];
			$selected['name']=$menu[$count][4];
			$selected['descr']=$menu[$count][5];
			while($page != "") {
				if($pagearray=explode($set['openfield'],$page,2)) {
					$out.=$pagearray[0];
					$page=$pagearray[1];
					if($pagearray=explode($set['closefield'],$page,2)) {
						$command=trim($pagearray[0]);
						$page=$pagearray[1];
						switch($command) {
							case "content": {
								$cntnt=stripslashes(file_get_contents("data/".$pagenum.".html"));
								if(strpos($cntnt, '%!$galery')!==false || strpos($cntnt, '%!$lyteframe')!==false) {
									$out=str_replace("</head>","<link rel=\"stylesheet\" href=\"css/lytebox.css\" type=\"text/css\" media=\"screen\" />\n<script type=\"text/javascript\" src=\"js/lytebox.js\"></script>\n</head>",$out);
								}
								if(strpos($cntnt, '%!$wrapper')!==false) {
									$out=str_replace("</head>","<script language=\"JavaScript\">\n<!--\nfunction calcHeight()\n{\n\t//find the height of the internal page\n\tvar the_height=document.getElementById('the_iframe').contentWindow.document.body.scrollHeight+20;\n\t//change the height of the iframe\n\tdocument.getElementById('the_iframe').height=the_height;\n}\n//-->\n</script>\n</head>",$out);
								}
								if(strpos($cntnt, '%!$plugin')!==false) {
									$one=explode('%!$plugin',$cntnt,2);
									$two=explode('$!%',$one[1],2);
									$pluginame="./plugins/".trim($two[0]);
									if(file_exists($pluginame."/header.mod")) {
										$three=file_get_contents($pluginame."/header.mod")."\n</head>";
										$out=str_replace("</head>",$three,$out);
									}
									if(file_exists($pluginame."/first.mod")) {
										$out="<?php include \"".$pluginame."/first.mod\"; ?>".$out;
									}
								}
								if($set['extension']=="php")
									$out.="<?php content(); ?>";
								else showcontent(1);
								break;
							}
							case "extra": {
								if($set['extension']=="php")
									$out.="<?php extra(); ?>";
								else
									extra(1);
								break;
							}
							case "mainmenu": $out.= mainmenu(1); break;
							case "mainmenus": $out.= mainmenu(1,1); break;
							case "smainmenus": $out.= mainmenu(1,2); break;
							case "fullmenu": $out.=fullmenu(1); break;
							case "expmenu": $out.= expmenu(1); break;
							case "submenu": $out.= submenu(1); break;
							case "selected": $out.=$selected['name']; break;
							case "footer": $out.= $set['footer']." - <a href=\"http://lightneasy.org\">LightNEasy ".$LNEversion."</a>"; break;
							case "header": $out.= printheader(1,$menu[$count][6]); break;
							case "homelink": $out.='<a href="'.$set['homepath'].'">'.$langmessage[111].'</a>'; break;
							case "image": $out.="templates/".$set['template']."/images/"; break;
							case "subtitle": $out.= $set['subtitle']; break;
							case "sitemap": $out.= sitemap(1); break;
							case "title": $out.='<a href="'.$set['homepath'].'">'.$set['title'].'</a>'; break;
							case "login": if($set['extension']=="php") $out.="<a href=\"?do=login\">Login</a>"; break;
							case "downloads": $out.="<?php print show(0,\"download\"); ?>"; break;
							case "links": $out.="<?php print show(0,\"link\"); ?>"; break;
							case "lastnews": {
								if($set['extension']=="html")
									$out.=lastnews();
								else
									$out.='<?php print lastnews(); ?>';
								break;
							}
							default: 
								if(strpos($command, "lastnews")!== false) {
									$aa=explode(" ",$command,2);
									$out.="<?php print lastnews(".$aa[1]."); ?>";
								} elseif(strpos($command, "downloads")!== false) {
									$aa=explode(" ",$command,2);
									$out.="<?php print show(".$aa[1].",\"download\"); ?>";
								} elseif(strpos($command, "links")!== false) {
									$aa=explode(" ",$command,2);
									$out.="<?php print show(".$aa[1].",\"link\"); ?>";
								} else $out.=$command;
						}
					}
				}
			}
			if(!$fp=fopen($pagenum.".".$set['extension'],"w")) die ($langmessage[135].$menu[$count][3].".".$set['extension']);
			fwrite($fp,$out);
			if($page != "") fwrite($fp,$page);
			fclose($fp);
			@chmod($menu[$count][3].".".$set['extension'], 0755);
			if($set['extension'] == "php") {
				if(file_exists($menu[$count][3].".html")) unlink($menu[$count][3].".html");
			} else {
				if($menu[$count][3]!="index") {
					if(file_exists($menu[$count][3].".php")) unlink($menu[$count][3].".php");
				}
			}
		}
		$count++;
	}
	unset($_GET['do']);
	header("Location: ".$set['homepath']);
}

function adminnews() {
	global $langmessage, $message;
	$row_cat=readdata("newscat");
	$row_db=readdata("news");
	$noticia_numero = $_GET['id'];
	switch($_GET['action']) {
	case "deletec":
		if(!$fp=fopen("data/newscat.dat","w")) die ($langmessage[127]);
		$i=0;
		while($row_cat[$i][0]!="") {
			if(strval($row_cat[$i][0])!=$noticia_numero)
				fwrite($fp,$row_cat[$i][0]."|".$row_cat[$i][0]."|".$row_cat[$i][0]."||");
			$i++;
		}
		fclose($fp);
		unset($row_cat);
		$row_cat=readdata("news");
		$message=$langmessage[126];
		break;
	case "delete":
		if(!$fp=fopen("data/news.dat","w")) die ($langmessage[76]);
		$i=0;
		while($row_db[$i][0] != "") {
			if(strval($row_db[$i][0])!=$noticia_numero)
				fwrite($fp,$row_db[$i][0]."|".$row_db[$i][1]."|".$row_db[$i][2]."|".$row_db[$i][3]."|".$row_db[$i][4]."|".$row_db[$i][5]."|".$row_db[$i][6]."|".$row_db[$i][7]."||");
			$i++;
		}
		fclose($fp);
		unset($row_db);
		$row_db=readdata("news");
		$message=$langmessage[128];
		break;
	case "edit":
		$i=0;
		while($row_db[$i][0] != "") {
			if(strval($row_db[$i][0])==$noticia_numero) break;
			$i++;
		}
		break;
	case "editc":
		$i=0;
		while($row_cat[$i][0]!="") {
			if(strval($row_cat[$i][0])==$noticia_numero) break;
			$i++;
		}
	}
	$out.="<h2 class=\"LNE_title\">$langmessage[72]</h2>\n";
	if($message!="") $out.="<h3 class=\"LNE_message\">$message</h3>\n";
	$out.="<div style=\"text-align: center;\">";
	$out.="<form name=\"adicionar\" method=\"post\" action=\"\">\n
	<fieldset style=\"border: 0;\">\n<table style=\"border: 0;\">
	<tr><td>$langmessage[16]:</td><td><input type='text' name='autor' value=\"";
	if($_GET['action']=="edit") $out.=decode($row_db[$i][1]);
	$out.="\" /></td></tr>\n
	<tr><td>$langmessage[73]:</td><td><input type='text' name='email' value=\"";
	if($_GET['action']=="edit") $out.=decode($row_db[$i][2]);
	$out.="\" /></td></tr>\n
	<tr><td>$langmessage[12]:</td><td><input type='text' name='titulo' value=\"".decode($row_db[$i][3])."\" /></td></tr>\n";
	$out.="<tr><td>$langmessage[52]:</td><td><select name=\"cat\" >\n";
	$count=0;
	while($row_cat[$count][0]!="") {
		$out.='<option value="'.$row_cat[$count][0].'"';
		if($_GET['action']=="edit" && $row_db[$i][7]==$row_cat[$count][0]) $out.=' SELECTED';
		$out.='>'.$row_cat[$count][1]."&nbsp;</option>\n";
		$count++;
	}
	$out.="</select></td></tr>\n</table>\n";
	print $out;
	$out="";
	editor(decode($row_db[$i][4]));
	if($_GET['action']=="edit") {
		$out.="<input type='hidden' name='reg' value='".$row_db[$i][0]."' />";
		$out.="<input type='hidden' name='submit' value='Edit News' />";
		$out.="<input type='submit' name=\"aa\" value='$langmessage[77]' />\n";
	} else {
		$out.="<input type='hidden' name='submit' value='Add News' />";
		$out.="<input type='submit' name=\"aa\" value='$langmessage[74]' />\n";
	}
	$out.="</fieldset></form>";
	$out.="<h3>$langmessage[80]</h3>\n<table>\n";
	$i=0;
	while($row_db[$i][0] != "") {
		$out.="<tr><td><a href='".$_SERVER["SCRIPT_NAME"]."?do=adminnews&amp;action=edit&amp;id=".$row_db[$i][0]."'><img src=\"images/edit.png\" alt=\"edit\" style=\"align: left; border: 0;\" /></a></td><td><a href='".$_SERVER["SCRIPT_NAME"]."?do=adminnews&amp;action=delete&amp;id=".$row_db[$i][0]."'><img src=\"images/editdelete.png\" alt=\"delete\" style=\"align: left; border: 0;\" /></a></td><td><b>".decode($row_db[$i][3])."</b></td><td>".strftime("%d/%m/%y - %I:%M %p", $row_db[$i][5] + $fuso_s)."</td><td>$langmessage[79]: ".$row_db[$i][7]."</td></tr>\n";
		$i++;
	}
	$out.="</table></div>\n";
	$out.="<br /><h2>$langmessage[78]</h2>\n";
	$out.="<div align=\"center\"><form name=\"form1\" method=\"post\" action=\"\"><fieldset style=\"border: 0;\"><table>\n";
	$out.="<tr><td>$langmessage[50]</td><td><input type=\"text\" name=\"name\"";
	if($_GET['action']=="editc") $out.=" value=\"".decode($row_cat[$i][1])."\"";
	$out.=" /></td></tr>\n<tr><td>$langmessage[67]</td><td><input type=\"text\" name=\"descr\"";
	if($_GET['action']=="editc") $out.=" value=\"".decode($row_cat[$i][2])."\"";
	$out.=" /></td></tr>\n";
	if($_GET['action']=="editc") $out.="<tr><td>$langmessage[79]</td><td><input type=\"text\" name=\"newid\" value=\"".$row_cat[$i][0]."\" /></td></tr>";
	$out.="<tr><td></td><td>";
	$out.="<input type=\"hidden\" name=\"id\" value=\"".$_GET['id']."\" />\n";
	if($_GET['action']=="editc") {
		$out.="<input type=\"hidden\" name=\"newscat\" value=\"Edit Category\" />\n";
		$out.="<input type=\"submit\" name=\"aa\" value=\"$langmessage[54]\" />\n";
	} else {
		$out.="<input type=\"hidden\" name=\"newscat\" value=\"Add Category\" />\n";
		$out.="<input type=\"submit\" name=\"aa\" value=\"$langmessage[53]\" />\n";
	}
	$out.="</td></tr>\n</table></fieldset></form>\n";
	$out.="<h3>$langmessage[78]</h3>\n";
	$out.="<table>\n";
	$i=0;
	while($row_cat[$i][0]!="") {
		$out.="<tr><td><a href='".$_SERVER["SCRIPT_NAME"]."?do=adminnews&amp;action=editc&amp;id=".$row_cat[$i][0]."'><img src=\"images/edit.png\" alt=\"edit\" style=\"align: left; border: 0;\" /></a></td><td><a href='".$_SERVER["SCRIPT_NAME"]."?do=adminnews&amp;action=deletec&amp;id=".$row_cat[$i][0]."'><img src=\"images/editdelete.png\" alt=\"delete\" style=\"align: left; border: 0;\" /></a></td><td><b>".decode($row_cat[$i][1])."</b></td><td>".decode($row_cat[$i][2])."</td><td>Id: ".$row_cat[$i][0]."</td></tr>\n";
		$i++;
	}
	$out.="</table>\n</div><br />";
	print $out;
}

function createform() {
	global $langmessage, $menu;
	$out='<br /><br /><div align="center"><form method="post" action=""><h2>'.$langmessage[86].'</h2>';
	$out.='<table><tr><td align="right"><b>'.$langmessage[83].':</b></td><td><select name="level"><OPTION VALUE="1">1&nbsp;</OPTION>';
	$out.='<OPTION VALUE="2">2&nbsp;</OPTION><OPTION VALUE="3">3&nbsp;</OPTION></td></tr>';
	$out.='<tr><td align="right"><b>'.$langmessage[140].':</b></td><td><select name="count">';
	$count=0;
	while($menu[$count][0] != "") {
		$out.='<OPTION VALUE="'.$count.'"';
		$out.=' SELECTED >'.$menu[$count][4].'&nbsp;</OPTION>';
		$count++;
	}
	$out.='</select></td></tr>';
	$out.='<tr><td align="right"><b>'.$langmessage[84].':</b></td><td><input name="filename" type="text" /></td></tr>';
	$out.='<tr><td align="right"><b>'.$langmessage[85].':</b></td><td><input name="label" type="text" /></td></tr>';
	$out.='<tr><td></td><td>';
	$out.='<input type="hidden" name="submit" value="Create Page" />';
	$out.='<input type="submit" name=\"aa\" value="'.$langmessage[86].'" />';
	$out.='</td></tr></table></form></div>';
	return $out;
}

function setup() {
	global $set, $langmessage;
	$out="<h2 class=\"LNE_title\">$langmessage[130]</h2>\n";
	$out.="<form method=\"post\" action=\"\">\n<div align=\"center\"><fieldset>\n<table>\n";
	$out.="<tr><td align=\"right\">$langmessage[6]:</td>\n";
	$out.="<td><input type=\"text\" name=\"password\" value=\"\" /></td></tr>\n";
	$out.="<tr><td align=\"right\">$langmessage[10]:</td>\n";
	$out.="<td><input type=\"text\" name=\"homepath\" value=\"".$set['homepath']."\" /></td></tr>\n";
	$out.="<tr><td align=\"right\">$langmessage[11]:</td>\n<td><select name=\"template\">\n";
	$folder="templates";
	$files=preg_find('/./',$folder,PREG_FIND_DIRONLY | PREG_FIND_SORTBASENAME);
	foreach( $files as $file) {
		$file=substr($file,10);
		if($file != ".." && $file != ".") {
		    $out.='<OPTION VALUE="'.$file.'"';
		    if($file == $set['template']) $out.=' SELECTED';
		    $out.='>'.$file."&nbsp;</OPTION>\n";
		}
	}
	$out.="</select>\n</td></tr>\n";
	$out.="<tr><td align=\"right\">$langmessage[12]:</td><td><input type=\"text\" name=\"title\" value=\"".$set['title']."\" /></td></tr>\n";
	$out.="<tr><td align=\"right\">$langmessage[13]:</td><td><input type=\"text\" name=\"subtitle\" value=\"".$set['subtitle']."\" /></td></tr>\n";
	$out.="<tr><td align=\"right\">$langmessage[14]:</td><td><input type=\"text\" name=\"keywords\" value=\"".$set['keywords']."\" /></td></tr>\n";
	$out.="<tr><td align=\"right\">$langmessage[15]:</td><td><input type=\"text\" name=\"description\" value=\"".$set['description']."\" /></td></tr>\n";
	$out.="<tr><td align=\"right\">$langmessage[16]:</td><td><input type=\"text\" name=\"author\" value=\"".$set['author']."\" /></td></tr>\n";
	$out.="<tr><td align=\"right\">$langmessage[17]:</td><td><input type=\"text\" name=\"footer\" value=\"".$set['footer']."\" /></td></tr>\n";
	$out.="<tr><td align=\"right\">$langmessage[145]:</td><td><input type=\"text\" name=\"timeoffset\" value=\"".$set['timeoffset']."\" /></td></tr>\n";
	$out.="<tr><td align=\"right\">$langmessage[151]:</td><td><input type=\"text\" name=\"dateformat\" value=\"";
		if($set['dateformat']!="")
			$out.=$set['dateformat'];
		else
			$out.="%m/%d/%y - %I:%M %p";
	$out.="\" /></td></tr>\n";
	$out.="<tr><td align=\"right\">Open tag:</td><td><input type=\"text\" name=\"openfield\" value=\"".$set['openfield']."\" /></td></tr>\n";
	$out.="<tr><td align=\"right\">Close tag:</td><td><input type=\"text\" name=\"closefield\" value=\"".$set['closefield']."\" /></td></tr>\n";
	$out.="<tr><td align=\"right\">$langmessage[19]:</td><td><input type=\"text\" name=\"indexfile\" value=\"".$set['indexfile']."\" /></td></tr>\n";
	$out.="<tr><td align=\"right\">From Name:</td><td><input type=\"text\" name=\"fromname\" value=\"".$set['fromname']."\" /></td></tr>\n";
	$out.="<tr><td align=\"right\">From Email:</td><td><input type=\"text\" name=\"fromemail\" value=\"".$set['fromemail']."\" /></td></tr>\n";
	$out.="<tr><td align=\"right\">To email:</td><td><input type=\"text\" name=\"toemail\" value=\"".$set['toemail']."\" /></td></tr>\n";
	$out.="<tr><td align=\"right\">$langmessage[20]:</td>\n<td><select name=\"language\">\n";
	$folder="languages";
	$files=preg_find('/./',$folder,PREG_FIND_SORTBASENAME);
	foreach( $files as $file) {
		if(!is_dir($file) && strpos($file,".php")) {
			$file=substr($file,10);
			$out.='<OPTION VALUE="'.substr($file,5,5).'"';
			if(substr($file,5,5) == $set['language']) $out.=' SELECTED';
			$out.='>'.$file."&nbsp;</OPTION>\n";
		}
	}
	$out.="</select>\n</td></tr>\n";
	$out.="<tr><td align=\"right\">$langmessage[21]:</td>\n<td><select name=\"langeditor\">\n";
	$folder="fckeditor/editor/lang";
	$files=preg_find('/./',$folder,PREG_FIND_SORTBASENAME);
	foreach( $files as $file) {
		if(!is_dir($folder."/".$file) && strpos($file,".js")) {
			$file=substr($file,22);
			$out.='<OPTION VALUE="'.substr($file,0,2).'"';
			if(substr($file,0,2) == $set['langeditor']) $out.=' SELECTED';
			$out.='>'.$file."&nbsp;</OPTION>\n";
		}
	}
	$out.="</select>\n</td></tr>\n";
	$out.="</table>\n<input type=\"hidden\" name=\"submit\" value=\"Save Setup\" />\n";
	$out.="<input type=\"hidden\" name=\"gzip\" value=\"0\" />";
	$out.="<input type=\"hidden\" name=\"oldpassword\" value=\"".$set['password']."\" />";
	$out.="<input type=\"submit\" name=\"aa\" value=\"$langmessage[25]\" />\n</div>\n</fieldset></form>\n";
	return $out;
}

function deleteform() {
	global $langmessage, $selected, $pagenum, $out;
	$out.='<div align="center"><form method="post" action=""><h2>'.$langmessage[131].$selected['name'].'?</h2>';
	$out.="<fieldset><input type=\"hidden\" name=\"submit\" value=\"Delete Page\" />\n";
	$out.="<input type=\"submit\" name=\"aa\" value=\"$langmessage[136]\" />";
	$out.="</fieldset></form></div>";
	$out.=showcontent($pagenum);
}

function editmenu() {
	global $langmessage;
	$out="<br /><br /><div align=\"center\">\n";
	$out.="<form method=\"post\" action=\"\">\n<h2 class=\"LNE_title\">$langmessage[91]</h2>\n";
	$out.="<textarea id=\"content\" name=\"content\" rows=\"15\" cols=\"50\">\n";
	$out.=decode(file_get_contents("data/menu.dat"))."</textarea>\n";
	$out.="<input type=\"hidden\" name=\"submit\" value=\"Save Menu\" />\n";
	$out.="<input type=\"submit\" name=\"aa\" value=\"$langmessage[133]\" />\n";
	$out.="</form></div>\n";
	return $out;
}

function settings() {
	global $set, $langmessage, $pagenum;
	$out.="<h2 class=\"LNE_title\">$langmessage[34]</h2><br /><br />\n";
	$out.="<div align=\"center\"><table width=\"270\" cellspacing=\"2\">\n<tr>";
	$out.="<td style=\" width: 50; text-align: center; \"><a href=\"".$set['homepath'].$set['indexfile']."?do=create\"><img src=\"images/addpage.png\" alt=\"New Page\" style=\"border: 0;\" /></a></td>\n";
	$out.="<td style=\" width: 50; text-align: center; \"><a href=\"".$set['homepath'].$set['indexfile']."?do=editextra\"><img src=\"images/extra.png\" alt=\"Extra Content\" style=\"border: 0;\" /></a></td>\n";
	$out.="<td style=\" width: 50; text-align: center;\" ><a href=\"".$set['homepath'].$set['indexfile']."?do=adminnews\"><img src=\"images/news.png\" alt=\"$langmessage[37]\" style=\"border: 0;\" /></a></td>\n";
	$out.="<td style=\" width: 50; text-align: center;\" ><a href=\"".$set['homepath'].$set['indexfile']."?page=".$pagenum."&amp;do=image\"><img src=\"images/images.png\" alt=\"Upload Image\" style=\"border: 0;\" /></a></td>\n";
	$out.="<td style=\" width: 50; text-align: center;\" ><a href=\"".$set['homepath'].$set['indexfile']."?page=".$pagenum."&amp;do=download\"><img src=\"images/downloads.png\" alt=\"$langmessage[39]\" style=\"border: 0;\" /></a></td></tr>\n";
	$out.="<tr><td style=\" text-align: center; \">$langmessage[35]</td><td style=\" text-align: center; \">$langmessage[36]</td><td style=\" text-align: center; \">$langmessage[37]</td><td style=\" text-align: center; \">$langmessage[38]</td><td style=\" text-align: center; \">$langmessage[39]</td></tr>\n";
	$out.="<tr><td style=\" text-align: center; \"><a href=\"".$set['homepath'].$set['indexfile']."?do=editlinks\"><img src=\"images/gowebsite.png\" alt=\"$langmessage[40]\" style=\"border: 0;\" /></td>";
	$out.="<td style=\"text-align: center; \"><a href=\"".$set['homepath'].$set['indexfile']."?do=editmenu\"><img src=\"images/menu.png\" alt=\"Edit Menu\" style=\"border: 0;\" /></a></td>\n";
	$out.="<td style=\" text-align: center; \"><a href=\"".$set['homepath'].$set['indexfile']."?do=generate\"><img src=\"images/generate.png\" alt=\"Generate pages\" style=\"border: 0;\" /></a>&nbsp;</td>\n";
	$out.="<td style=\"text-align: center;\"><a href=\"".$set['homepath'].$set['indexfile']."?do=setup\"><img src=\"images/setup.png\" alt=\"Setup\" style=\"border: 0;\" /></a></td><td></td></tr>\n";
	$out.="<tr><td style=\" text-align: center; \">$langmessage[40]</td><td style=\" text-align: center; \">$langmessage[41]</td><td style=\" text-align: center; \">$langmessage[42]</td><td style=\" text-align: center; \">$langmessage[44]</td></tr>";
	$out.="</table></div>";
	return $out;
}

function images() {
	global $langmessage, $max_upload_image_size;
	$out.="<div align=\"center\">\n";
	if($_GET['action']=="delete" && $_GET['file']!="") {
		if(@unlink($_GET['file']))
			$out.="<h2 class=\"LNE_message\">".$langmessage[149]."</h2>\n";
		else
			$out.="<h2 class=\"LNE_message\">Error deleting image</h2>\n";
	}
	$out.="<form enctype=\"multipart/form-data\" method=\"post\" action=\"\">\n<fieldset style=\"border: 0;\">\n";
	$out.="<h2 class=\"LNE_title\">$langmessage[57]</h2>\n";
	$out.="<h3>$langmessage[58]</h3>\n";
	$out.="<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"$max_upload_image_size\" />\n";
	$out.="<table>\n<tr><td></td><td>$langmessage[59]:</td><td><input name=\"uploadedfile\" type=\"file\" />\n</td></tr>\n";
	$out.="<tr><td>&nbsp;</td><td>$langmessage[61]:</td><td>";
	$out.="<select name=\"gal\">\n";
	$folder="galeries";
	$files=preg_find('/./',$folder,PREG_FIND_DIRONLY | PREG_FIND_SORTBASENAME);
	foreach($files as $file) {
		$file=substr($file,9);
		if($file != ".." && $file != ".") {
		    $out.='<option value="'.$file."\">".$file."&nbsp;</option>\n";
		}
	}
	$out.="</select>\n</td></tr>\n";
	$out.="<tr><td></td>\n<td></td><td>";
	$out.="<input type=\"hidden\" name=\"submit\" value=\"Upload image\" />";
	$out.="<input type=\"submit\" value=\"$langmessage[58]\" /></td>";
	$out.="</tr>\n</table>\n</fieldset>\n</form>\n<br /><h3>$langmessage[62]</h3>\n";
	$out.="<form method=\"post\" action=\"\">\n<fieldset style=\"border: 0;\">\n";
	$out.="<table>\n<tr><td>$langmessage[117]:</td>\n<td>";
	$out.="<input name=\"galeryname\" type=\"text\" value=\"\" />\n</td></tr>\n";
	$out.="<tr><td><input type=\"hidden\" name=\"submit\" value=\"Create Gallery\" /></td>\n<td>";
	$out.="<input type=\"submit\" name=\"aa\" value=\"$langmessage[62]\" /></td>";
	$out.="</tr></table>\n</fieldset>\n</form>\n";
	$out.="<br /><h3>".$langmessage[148]." ".$langmessage[38]."</h3>\n";
	$out.="<table>\n";
	$folder="galeries";
	$files=preg_find('/./',$folder,PREG_FIND_RECURSIVE | PREG_FIND_SORTBASENAME);
	foreach($files as $file) {
		$out.="<tr><td><a href=\"".$_SERVER["SCRIPT_NAME"]."?do=image&amp;action=delete&amp;file=$file\">";
		$out.="<img src=\"images/editdelete.png\" alt=\"delete\" title=\"Delete ".substr($file,9)."\" align=\"left\" border=\"0\" /></a></td>";
		$out.="<td align=\"center\" >";
		$out.="<img src=\"LightNEasy/thumbsup.php?image=../".$file."&amp;width=60&amp;height=60\"  alt=\"".substr($file,9)."\" /></td></tr>\n";
	}
	$out.="</table>\n</div>\n";
	return $out;
}

function editextra() {
	global $langmessage;
	print "<h2 class=\"LNE_title\">$langmessage[89]</h2>\n<form method=\"post\" action=\"\">\n";
	if(!file_exists("data/extra.htm")) {
	    $fp=fopen("data/extra.htm","w");
	    fclose($fp);
	}
	editor(stripslashes(file_get_contents("data/extra.htm")));
	print savereturn("Save Extra");
}

function editpage($pagenum) {
	global $langmessage,$selected;
	print "<form method=\"post\" action=\"\"\">\n<fieldset style=\"border: none; background: transparent;\">\n";
	editor(stripslashes(file_get_contents("./data/".$pagenum.".html")));
	print "<input  type=\"hidden\" name=\"pagenum\" value=\"$pagenum\" />\n";
	print "<b>".$langmessage[67]."</b>: <input style=\"width: 95%\" type=\"text\" name=\"description\" value=\"";
	if($selected['descr'] !="-")
		print $selected['descr'];
	print "\" />\n";
	print "<table><tr><td align=\"right\"><b>$langmessage[11]:</b></td><td><select name=\"template\">\n";
	$folder="templates";
	print "<OPTION VALUE=\"\">Default</OPTION>\n";
	$dir=opendir($folder);
	while($file=readdir($dir)) {
		if($file != ".." && $file != "." && is_dir($folder."/".$file)) {
		    print '<OPTION VALUE="'.$file.'">'.$file."&nbsp;</OPTION>\n";
		}
	}
	closedir($dir);
	print "</select></td></tr></table>\n";
	print savereturn("Save");
}

/* invoques the FCK editor */
function editor($out) {
	global $set;
	include_once("fckeditor/fckeditor.php") ;
	$oFCKeditor = new FCKeditor('mycontent') ;
	$oFCKeditor->BasePath = "./fckeditor/";
	$oFCKeditor->Height = 400 ;
	$oFCKeditor->Config['AutoDetectLanguage'] = false ;
	$oFCKeditor->Config['DefaultLanguage'] = $set['langeditor'];
//comment out the next line for using the FCK editor default skin
	$oFCKeditor->Config['SkinPath'] = "skins/silver/";
	$oFCKeditor->Value = $out;
	$oFCKeditor->Create() ;
}

/* outputs the icons for save/return */
function savereturn($value) {
	$out.="<input type=\"hidden\" name=\"submit\" value=\"$value\" />\n";
	$out.="<table><tr><td valign=\"top\">";
	$out.="<input type=\"image\" name=\"aa\" value=\"\" src=\"images/accept.png\" style=\"width: 32px; height: 32px;\" />\n</fieldset></form>";
	$out.="<form method=\"post\" action=\"\">\n<fieldset style=\"border: none; background: transparent;\">\n</td>";
	$out.="<td valign=\"top\"><input type=\"hidden\" name=\"return\" value=\"Return\" />\n";
	$out.="<input type=\"image\" name=\"aa\" value=\"Return\" src=\"images/back.png\" value=\"\" style=\"width: 32px; height: 32px;\" />\n</fieldset>\n</form>\n</td>";
	$out.="</tr></table>";
	return $out;
}

function edit($type) {
	global $out,$langmessage,$max_upload_file_size;
	$downloadscat=readdata($type."cat");
	//read links id,nome,link, descricao,cat
	$downloads=readdata($type."s");
	if(substr($_GET['action'],0,4)=="edit") { // edit or editc
		$count=0;
		while($downloads[$count][0] !="") {
			if($downloads[$count][0]==$_GET['id']) {
				$record=$count;
				break;
			}
			$count++;
		}
	}
	switch($_GET['action']) {
		case "delete":
			$downloads=deletedata($downloads,$type."s",0,$_GET['id'],5);
			unset($_GET['action']);
			break;
		case "deletec":
			$downloadscat=deletedata($downloadscat,$type."cat",0,$_GET['id'],3);
			unset($_GET['action']);
	}
	$out.="<form method=\"post\" action=\"\"><fieldset style=\"border: 0;\"><table>\n";
	$out.="<tr><td>$langmessage[50]</td><td><input type=\"text\" name=\"name\"";
	if($_GET['action']=="editc") $out.=" value=\"".decode($downloadscat[$record][1])."\"";
	$out.=" /></td></tr>\n";
	$out.="<tr><td>$langmessage[15]</td><td><input type=\"text\" name=\"descr\"";
	if($_GET['action']=="editc") $out.=" value=\"".decode($downloadscat[$record][2])."\"";
	$out.=" /></td></tr>\n<tr><td>";
	if($_GET['action']=="editc") $out.="<input type=\"hidden\" name=\"id\" value=".$downloadscat[$record][0]." />";
	$out.="</td><td><input type=\"hidden\" ";
	if($type=="download")
		$out.="name=\"downloadcat\" ";
	else
		$out.="name=\"linkcat\" ";
	if($_GET['action']=="editc") {
		$out.="value=\"Edit Category\" />\n";
		$out.="<input type=\"submit\" name=\"aa\" value=\"$langmessage[54]\" />\n";
	} else {
		$out.="value=\"Add Category\" />\n";
		$out.="<input type=\"submit\" name=\"aa\" value=\"$langmessage[53]\" />\n";
	}
	$out.="</td></tr>\n</table></div>\n";
	$out.="<table cellspacing=\"5\">";
	$GETarray=$_GET;
	$count=0;
	while ($downloadscat[$count][0]!="") {
		$out.="<tr><td><a href=\"".$_SERVER['SCRIPT_NAME']."?";
		if($_GET['do']!="") $out.="do=".$_GET['do']."&amp;";
		$out.="id=".$downloadscat[$count][0]."&amp;action=editc\"><img src=\"images/edit.png\" style=\"align: left; border: 0;\" ></a></td>\n";
		$out.="<td><a href=\"".$_SERVER['SCRIPT_NAME']."?";
		if($_GET['do']!="") $out.="do=".$_GET['do']."&amp;";
		$out.="id=".$downloadscat[$count][0]."&amp;action=deletec\"><img src=\"images/editdelete.png\" style=\"align: left; border: 0;\" ></a></td>\n";
		$out.="<td>".$downloadscat[$count][0]."</td><td>".decode($downloadscat[$count][1])."</td><td>".decode($downloadscat[$count][2])."</td></tr>\n";
		$count++;
	}
	$out.="</table>\n</form>\n";
	$out.="<div align=\"center\"><h3>";
	if($type=="link") $out.=$langmessage[40];
	else $out.=$langmessage[48];
	$out.="<form enctype=\"multipart/form-data\" method=\"post\" action=\"\"><fieldset style=\"border: 0;\"><table>\n<tr>";
	if($type=="download")
		$out.="<td></td>";
	$out.="<td>$langmessage[50]</td><td><input type=\"text\" name=\"linkname\"";
	if($_GET['action']=="edit") $out.=" value=\"".decode($downloads[$record][1])."\"";
	$out.=" /></td></tr>\n<tr><td>";
	if($type=="download")
		$out.="<input style=\"width: 14px;\" type=\"radio\" checked=\"checked\" name=\"filename\" value=\"upload\" /></td><td>$langmessage[122]</td><td><input style=\" text-align: left;\" name=\"uploadedfile\" type=\"file\" name=\"uploadfile\" />\n</td></tr>";
	$out.="\n<tr>";
	if($type=="download")
		$out.="<td><input style=\"width: 14px;\" type=\"radio\" name=\"filename\" value=\"filename\" /></td>";
	$out.="<td>";
	if($type=="link") $out.=$langmessage[69];
	else $out.=$langmessage[51]; //filename
	$out.="</td><td><input type=\"text\" name=\"link\"";
	if($_GET['action']=="edit") $out.=" value=\"".$downloads[$record][2]."\"";
	$out.=" /></td></tr>\n<tr>";
	if($type=="download") $out.="<td><input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"$max_upload_file_size\" /></td>";
	$out.="<td valign=\"top\" >$langmessage[67]</td><td><textarea style=\"width: 180px;\" name=\"descr\">";
	if($_GET['action']=="edit") $out.=decode($downloads[$record][3]);
	$out.="</textarea></td></tr>\n<tr>";
	if($type=="download")
		$out.="<td></td>";
	$out.="<td>$langmessage[52]</td><td align=\"right\"><select name=\"cat\" >\n";
	$count=0;
	while($downloadscat[$count][0]!="") {
		$out.='<option value="'.$downloadscat[$count][0].'"';
		if($_GET['action']=="edit" && $downloadscat[$count][0]==$_GET['id']) $out.=' SELECTED';
		$out.='>'.decode($downloadscat[$count][1])."&nbsp;</option>\n";
		$count++;
	}
	$out.="</select></tr>\n<tr>";
	if($type=="download")
		$out.="<td></td>";
	$out.="<td>";
	if($_GET['action']=="edit") $out.="<input type=\"hidden\" name=\"id\" value=\"".$downloads[$record][0]."\" />";
	$out.="</td><td>";
	if($type=="download") {
		if($_GET['action']=="edit") {
			$out.="<input type=\"hidden\" name=\"submit\" value=\"Edit Download\" />";
			$out.="<input type=\"submit\" name=\"aa\" value=\"$langmessage[56]\" />";
		} else {
			$out.="<input type=\"hidden\" name=\"submit\" value=\"Add Download\" />";
			$out.="<input type=\"submit\" name=\"aa\" value=\"$langmessage[55]\" />";
		}
	} else {
		if($_GET['action']=="edit") {
			$out.="<input type=\"hidden\" name=\"submit\" value=\"Edit Link\" />";
			$out.="<input type=\"submit\" name=\"aa\" value=\"$langmessage[70]\" />";
		} else {
			$out.="<input type=\"hidden\" name=\"submit\" value=\"Add Link\" />";
			$out.="<input type=\"submit\" name=\"aa\" value=\"$langmessage[71]\" />";
		}
	}
	$out.="</td></tr></table></fieldset></form></div>\n";
	$out.="<table cellspacing=\"5\">";
	$count=0;
	while ($downloads[$count][0]!="") {
		$out.="<tr><td><a href=\"".$_SERVER['SCRIPT_NAME']."?";
		if($_GET['do']!="") $out.="do=".$_GET['do']."&amp;";
		$out.="id=".$downloads[$count][0]."&amp;action=edit\"><img src=\"images/edit.png\" style=\"align: left; border: 0;\" ></a></td>\n";
		$out.="<td><a href=\"".$_SERVER['SCRIPT_NAME']."?";
		if($_GET['do']!="") $out.="do=".$_GET['do']."&amp;";
			$out.="id=".$downloads[$count][0]."&amp;action=delete\"><img src=\"images/editdelete.png\" style=\"align: left; border: 0;\" ></a></td>\n";
		$out.="<td>".decode($downloads[$count][1])."</td><td>".decode($downloads[$count][2])."</td></tr>\n";
		$count++;
	}
	$out.="</table>\n";
}

function adminmenu() {
	global $set,$pagenum;
	$aa="";
	if($_SESSION[$set['password']]=="1") {
		$aa.="\n<div id=\"LNE_admin\">\n<table>\n<tr>\n";
		$aa.="<td><a href=\"".$set['homepath'].$set['indexfile']."?page=".$pagenum."&amp;do=edit\">\n";
		$aa.="<img src=\"images/edit.png\" alt=\"edit\" align=\"left\" border=\"0\" /></a></td>\n";
		$aa.="<td><a href=\"".$set['homepath'].$set['indexfile']."?page=".$pagenum."&amp;do=delete\">";
		$aa.="<img src=\"images/editdelete.png\" alt=\"delete\" align=\"left\" border=\"0\" /></a></td>\n";
		$aa.="<td><a href=\"".$set['homepath'].$set['indexfile']."?do=settings\">";
		$aa.="<img src=\"images/tools.png\" alt=\"Settings\" align=\"left\" border=\"0\" /></a></td>\n";
		$aa.="</tr>\n</table>\n</div>\n";
	}
	return $aa;
}
?>