<?
if (empty($_SESSION["admin"])) redirect("index.php?e=1");
if (empty($_GET["fl"])) {
	die("no file name provid1ed");
}
$fl = filterdir($_GET["fl"]);

if ($_POST["mode"] == "save") {
	$fl_data = $_POST["finaltxt"];
	$ad = split("/", $fl);
	$ad[count($ad)-1] = "";
	createrdir(filterdir(implode("/", $ad)));
	if (!$handle = fopen("data/" . $fl, "w")) {
		echo "Cannot write to file";
	} elseif (fwrite($handle, $fl_data) === FALSE) {
		echo "Cannot write to file";
	}
} elseif (!empty($fl) && $_POST["mode"] == "edit") {
	if (file_exists("data/" . $fl))
		$fl_data = file_get_contents("data/" . $fl);
	else
		echo("Invalid file");
}

/*
if ($_POST["savefile"]!=''){
	$mypath=realpath("test.php");
				$mypath=str_replace("test.php","",$mypath);
				$mypath=str_replace("\\","/",$mypath);
				
	$upload_folder =  $mypath."data/";
	// the name of the text file
	$filename = $upload_folder.$_POST["file_name"];
	
	// get the variables from flash
	$somecontent = $_POST["finaltxt"];

	// If the file doesn't exist, attempt to create it
	// and open it for writing
	// anything already writen will be replaced
	if (!$handle = fopen($filename, 'w')) {
		 echo "&message=Cannot open file&";
		 exit;
	}

	// Write $somecontent to the opened file.
	if (fwrite($handle, $somecontent) === FALSE) {
		echo "&message=Cannot write to file&";
		exit;
	}
	// close the file
	fclose($handle);

	// send the variable to flash
	//echo "&message=$somecontent&";
	echo "file saved Succefully";

}*/
?>