Location: PHPKode > scripts > Cwfm > cwfm/php/FileEditMain.php
<?
//////////////////////////////////////////////////////////////////////
//
// FileEditMain.php - Cwfm
//
// By Vincenzo Valvano - hide@address.com
//
// This program is free software; you can redistribute it and/or 
// modify it under the terms of the GNU General Public License as 
// published by the Free Software Foundation; either version 2 of 
// the License, or (at your option) any later version. This program 
// is distributed in the hope that it will be useful, but WITHOUT 
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 
// License for more details. You should have received a copy of the 
// GNU General Public License along with this program; if not, write 
// to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
// Boston, MA  02111-1307  USA
//////////////////////////////////////////////////////////////////////
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
session_start();
include_once("Global.php");
if( !ValidSession() )
{
	IntrusionNotify();
	exit;
}
include_once("lang/$Language.php");
include_once("data/Cwfmini.php");
global $command, $action;
if( isset($file) ) 
	$file = DecodeFilename($file);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel=stylesheet href="Css.php" type="text/css">
<title><?echo $T8_L?></title>
<? if( $action != "save" ) { ?>
<script language="JavaScript">
function SetWrap()
{
	if( document.form1.wrap.checked  )
		document.form1.text.wrap="soft";
	else
		document.form1.text.wrap="off";
}
function Save(d, c)
{
	var f1 = document.form1;
	
//	alert('Escaped = '+escape(f1.filename.value));
	if( f1.text.value == "" )
	{
		if( !confirm('<? echo $A37_L?>') )
		{
			f1.text.focus();
			return;
		}
	}
	if( f1.filename.value == "" )
	{
		alert('<? echo $A38_L?>');
		f1.filename.focus();
		return;
	}

	window.open('FileEditSave.php?command='+c+'&dir='+d+'&filename='+f1.filename.value+'&oldfilename='+f1.oldfilename.value, 'FETop', 'width=1,heigth=1');
}
function Clear()
{
	document.form1.text.value = "";
	document.form1.text.focus();
}

function Revert()
{
	document.location = 'FileEditMain.php?command=<?echo $command?>&dir=<?echo $dir?>&file=<?echo EncodeFilename($file)?>';
}
</script>
<? } ?>
</head>
<?
if( $action == "save" )
{
	global $wrap, $crlf;
	
	$f = CanonicalPath($iPath, $dir, $filename);
	if( !($fp=@fopen($f, "wb")) )
	{
		echo "<script language=\"JavaScript\">\n";
		echo "alert('$A36_L');\n";
		echo "parent.close();\n";
		echo "</script>\n";
	}
	if( get_magic_quotes_gpc() )
		$text = stripslashes($text);
	$t = explode("\n", $text);
	if( $crlf )
	{
		foreach( $t as $te )
		{
			if( $te == "" )
				continue;
			if( $te == "\r" || $te == "\n" || $te == "\r\n" )
				$s = "\r\n";
			else
			{
				if( Last($te) == "\r" )
					$s = $te."\n";
				else
					$s = $te."\r\n";
			}
			fwrite($fp, $s, strlen($s));
		}
	}
	else
	{
		foreach( $t as $te )
		{
			if( $te == "" )
				continue;
			if( $te == "\r" || $te == "\n" || $te == "\r\n" )
				$s = "\n";
			else
			{
				if( Last($te) == "\r" )
					$s = substr($te, 0, -1)."\n";
				else
					$s = $te."\n";
			}
			fwrite($fp, $s, strlen($s));
		}
	}
	fclose($fp);
	echo "<script language=\"JavaScript\">\n";
	echo "window.open('File.php?command=goto&dir=$dir', 'mainFrame', '');\n";
	echo "parent.close();\n";
	echo "</script>\n";
	exit;
}
?>
<body>
<form name="form1" method="post" action="FileEditMain.php?action=save&dir=<?echo $dir?>">
  <input type="hidden" name="oldfilename" >
  <table width="100%">
    <tr>
      <td> 
        <div align="center">
          <textarea name="text" cols="81" rows="25" wrap="OFF" class=edit>
<?
if( $command == "open" )
	echo htmlspecialchars(implode("", @file(LastSelected())));
//	@readfile(LastSelected());
?>
</textarea>
        </div>
      </td>
    </tr>
  </table>
  <table cellspacing="5" >
    <tr> 
      <td nowrap> 
        <?echo $L36_L?>
      </td>
      <td nowrap> 
        <input type="text" name="filename" size="40">
        <a href="#" class=menu onClick="Clear()"> 
        <?
if( $ShowIcons )
	echo "<img src=\"img/small/Clear.png\" align=\"absmiddle\" border=\"0\">";
echo HiMenu($F56_L,1)
?>
        <? 
if( $command == "open" ) 
	echo "<a href=\"FileEditMain.php?command=$command&dir=$dir&file=$file\" class=menu >";
else 
	echo "<a href=\"#\" class=disabled>";
if( $ShowIcons )
	echo "<img src=\"img/small/Revert.png\" border=\"0\" align=\"absmiddle\">";
echo HiMenu($F57_L,$command=="open")."</a>";
?>
        </a><a href="#" class=menu onClick="Save('<?echo $dir?>', '<?echo $command?>')"> 
        <?
if( $ShowIcons )
	echo "<img src=\"img/small/Save.png\" align=\"absmiddle\" border=\"0\">";
echo HiMenu($F58_L,1)
?>
        </a></td>
    </tr>
    <tr> 
      <td nowrap> 
        <?echo $L37_L?>
      </td>
      <td nowrap> 
        <div align="left"> 
          <input type="checkbox" name="wrap" value="1" onClick="SetWrap()" class=cb>
          &nbsp;&nbsp;&nbsp; 
          <?echo $L38_L?>
          <input type="checkbox" name="crlf" value="1" class=cb>
        </div>
      </td>
    </tr>
  </table>
</form>
<? 
if( $command == "open" ) 
{
	echo "<script language=\"JavaScript\">\n";
	echo "file = String.fromCharCode(";
	for($i=0; $i < strlen($file); $i++)
	{
		echo ord($file[$i]);
		if( $i != strlen($file) -1 )
			echo ",";
	}
	echo ");\n";
	echo "document.form1.filename.value=file;\n";
	echo "document.form1.oldfilename.value=file;\n";
	echo "</script>\n";
}
 ?>
<script language="JavaScript">
document.form1.text.focus();
</script>
</body>
</html>
Return current item: Cwfm