Location: PHPKode > projects > Openology PHP Application Integration > openology/backend/file_edit.php
<?php
/***************************************************************************
 *   copyright            : (C) 2006 The openology Group
 *   email                : hide@address.com
 *
 *   $Id
 *
 *
 ***************************************************************************/

/***************************************************************************
 *
 *   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.
 *
 ***************************************************************************/
 
header('Content-Type: text/html; charset=UTF-8');
require_once(dirname(__FILE__)."/config.php");
require(dirname(__FILE__)."/inc_functions.php");
$activepath = str_replace("..","",$activepath);
$activepath = ereg_replace("^/{1,}","/",$activepath);
if($activepath == "/") $activepath = "";
if($activepath == "") $inpath = $base_dir;
else $inpath = $base_dir.$activepath;

if($action=="edit")
{
	if(!isset($backurl)) $backurl = "";
	$activepath = str_replace("..","",$activepath);
	$filename = str_replace("..","",$filename);
	$file = "$base_dir$bdir/$filename";
	$fp = fopen($file,"r");
	$content = fread($fp,filesize($file));
	fclose($fp);
	$content = eregi_replace("<textarea","< textarea",$content);
	$content = eregi_replace("</textarea","< /textarea",$content);
	$content = eregi_replace("<form","< form",$content);
	$content = eregi_replace("</form","< /form",$content);
	$contentView = "<textarea name='str' style='width:98%;height:500px'>$content</textarea>\r\n";
	$GLOBALS['filename'] = $filename;
}
else if($action=="editview")
{
	if(!isset($backurl)) $backurl = "";
	if(!isset($ishead)) $ishead = "";
	$activepath = str_replace("..","",$activepath);
	$filename = str_replace("./","/",$filename);
	$file = "$base_dir$bdir/$filename";
	$fp = fopen($file,"r");
	$content = fread($fp,filesize($file));
	fclose($fp);
	if((eregi("<html",$content) && eregi("<body",$content)) || $ishead == "yes")
	{ $contentView = GetEditor("str",$content,"500","Default","string","true"); }
	else
	{ $contentView = GetEditor("str",$content,"500","Default","string","false"); }
	$GLOBALS['filename'] = $filename;
}
else if($action == "creat")
{
    if($ct == 1)
	{
	if(!isset($backurl)) $backurl = "";
	if(!isset($ishead)) $ishead = "";
	$activepath = str_replace("..","",$activepath);
	$filename = str_replace("./","/",$filename);
	$file = "newfile/";
	$fp = fopen($file,"w+");
	$content = "";
	fclose($fp);
	}
	if((eregi("<html",$content) && eregi("<body",$content)) || $ishead == "yes")
	{ $contentView = GetEditor("str",$content,"500","Default","string","true"); }
	else
	{ $contentView = GetEditor("str",$content,"500","Default","string","false"); }
	$GLOBALS['filename'] = $filename;
}
else if($action == "creatview")
{
    if($ct == 2)
	{
	if(!isset($backurl)) $backurl = "";
	if(!isset($ishead)) $ishead = "";
	$activepath = str_replace("..","",$activepath);
	$filename = str_replace("./","/",$filename);
	$file = "newfile/";
	$fp = fopen($file,"w+");
	$content = "";
	fclose($fp);
	}
	if((eregi("<html",$content) && eregi("<body",$content)) || $ishead == "yes")
	{ $contentView = GetEditor("str",$content,"500","Default","string","true"); }
	else
	{ $contentView = GetEditor("str",$content,"500","Default","string","false"); }
	$GLOBALS['filename'] = $filename;
}
?>
<?php
if($action == "edit")
{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title><?php echo $TEXT['fileEdit'];?></title>
<link rel="stylesheet" type="text/css" href="css/style.css">
<script>
function Post() {
	if (document.form1.filename.value==""){
		alert("<?php echo $TEXT['warning'];?>");
		document.form1.filename.focus();
		return false;
        }
}	
</script>
</head>
<body>
<form method="POST" action="file_save.php" name=form1 onSubmit="return Post()">
<table id="tt" border="0" cellspacing="0" cellpadding="0" width="90%" height="100%" align="center">
  <tr>
    <td id="tl">&nbsp;</td>
    <td id="tc" width="100%"><h2><?=$TEXT['fileEdit']?></h2></td>
	<td id="tr">&nbsp;</td>
  </tr>
  <tr>
    <td id="l" rowspan="3">&nbsp;</td>
    <td>
      <table border="0" cellspacing="0" cellpadding="0" height="100%" width="100%" align="center">
      <input type="hidden" name="action" value="edit">
      <input type="hidden" name="backurl" value="<? echo $backurl.urlencode($me);?>">
	    <!--<tr bgcolor="#eeeeee"> 
          <td width="12%"><?=$TEXT['workcatalog']?></td>
          <td width="88%"><input name=activepath size=40 value="<?=$activepath?>">
            (空白表示根目录 ,不允许用 “..” 形式的路径)</td>
        </tr>-->
        <tr> 
          <td><?=$TEXT['filename']?></td>
          <td><input name=filename size=40 value="<?=$filename?>">
              <?=$TEXT['warning1']?>
              <input type="button" name="Submit" value="<?=$TEXT['use']?>" onClick="location='file_edit.php?action=editview&activepath=<?=$activepath?>&filename=<?=$filename?>';"> </td>
        </tr>
      </table></td>
	<td id="r" rowspan="3">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top">
	<?=$contentView;?>
	</td>
  </tr>
  <tr>
    <td height="10%"> 
      <p align="center"><br>
      <input type="submit" value="<?=$TEXT['save']?>" name=B1>&nbsp;
	  <input type="reset" value="<?=$TEXT['cancelsave']?>" name=B2>&nbsp;
	  <input type="button" value="<?=$TEXT['goback']?>" name=B4 onClick="javascript:history.go(-1);">
      <br>
    </td>
  </tr>
  <tr>
    <td id="bl">&nbsp;</td>
    <td id="bc">&nbsp;</td>
    <td id="br">&nbsp;</td>
  </tr>
</table>
</form>
</body>
</html>
<?php
}
else if($action=="editview")
{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xml:lang="en-EU" lang="en-EU">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title><?=$TEXT['visualeditor']?></title>
<link rel="stylesheet" type="text/css" href="css/style.css">
<script>
function Post() {
	if (document.form1.filename.value==""){
		alert("<?=$TEXT['warning'];?>");
		document.form1.filename.focus();
		return false;
  }
}	
</script>
</head>
<body>
<form method="POST" action="file_save.php" name=form1 onSubmit="return Post()">
<table id="tt" border="0" cellspacing="0" cellpadding="0" width="90%" height="100%" align="center">
  <tr>
    <td id="tl">&nbsp;</td>
    <td id="tc" width="100%"><h2><?=$TEXT['fileEdit']?></h2></td>
	<td id="tr">&nbsp;</td>
  </tr>
  <tr>
    <td id="l" rowspan="3">&nbsp;</td>
    <td>
      <table border="0" cellspacing="0" cellpadding="0" height="100%" width="100%" align="center">
      <input type="hidden" name="action" value="editview">
      <input type="hidden" name="backurl" value="<?php echo $backurl.urlencode($me);?>">
	   <!-- <tr bgcolor="#eeeeee"> 
          <td width="12%">工作目录:</td>
          <td width="88%"><input name=activepath size=40 value="<?=$me?>">
                          (空白表示根目录 ,不允许用 “..” 形式的路径)</td>
        </tr>-->
        <tr> 
          <td><?=$TEXT['filename']?></td>
          <td><input name=filename size=40 value="<?=$filename?>">
                <?=$TEXT['warning1']?>
                <input type="button" name="Submit" value="<?=$TEXT['use1']?>" onClick="location='file_edit.php?action=edit&activepath=<?=$activepath?>&filename=<?=$filename?>';"></td>
        </tr>
      </table></td>
	<td id="r" rowspan="3">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top">
	<?=$contentView;?>
	</td>
  </tr>
  <tr>
    <td height="10%"> 
      <p align="center"><br>
      <input type="submit" value="<?=$TEXT['save']?>" name=B1>&nbsp;
	  <input type="reset" value="<?=$TEXT['cancelsave']?>" name=B2>&nbsp;
	  <input type="button" value="<?=$TEXT['goback']?>" name=B4 onClick="javascript:history.go(-1);">
      <br>
    </td>
  </tr>
  <tr>
    <td id="bl">&nbsp;</td>
    <td id="bc">&nbsp;</td>
    <td id="br">&nbsp;</td>
  </tr>
</table>
</form>
<div align="center">
<table id="tt" border="0" cellspacing="0" cellpadding="0" width="90%" height="100%" align="center">
    <tr>
        <td id="tl">&nbsp;</td>
        <td id="tc" width="100%"><h2><?=$TEXT['fileview']?></h2></td>
	    <td id="tr">&nbsp;</td>
    </tr>
    <tr>
        <td id="l">&nbsp;</td>
        <td>
            <table border="0" cellspacing="0" cellpadding="0" height="100%" width="100%" align="center">
	            <tr>
		            <td align="center">
                        <iframe src="
	                        <?php
	                            if (substr($filename,-3)=='tpl'){
	                            echo $bdir.'/'.basename($filename, '.tpl') . '.php';
	                            }
	                            else{
	                            echo $bdir.str_replace("./","",$filename);
	                            }
	                        ?>
                        " width="90%" height="600"></iframe>
				    </td>
                </tr>
	        </table>
		</td>
	    <td id="r">&nbsp;</td>
    </tr>
    <tr>
        <td id="bl">&nbsp;</td>
        <td id="bc">&nbsp;</td>
        <td id="br">&nbsp;</td>
    </tr>
</table>
</div>
</body>
</html>
<?php
}
else if($action == "creat")
{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title><?=$TEXT['createfile']?></title>
<link rel="stylesheet" type="text/css" href="css/style.css">
<script>
function Post() {
	if (document.form1.filename.value==""){
		alert("<?=$TEXT['warning'];?>");
		document.form1.filename.focus();
		return false;
        }
}	
</script>
</head>
<body>
<form method="POST" action="file_save.php" name=form1 onSubmit="return Post()">
<table id="tt" border="0" cellspacing="0" cellpadding="0" width="90%" height="100%" align="center">
    <tr>
        <td id="tl">&nbsp;</td>
        <td id="tc" width="100%"><h2><?=$TEXT['fileEdit']?></h2></td>
	    <td id="tr">&nbsp;</td>
    </tr>
    <tr>
        <td id="l" rowspan="3">&nbsp;</td>
        <td>
            <table border="0" cellspacing="0" cellpadding="0" height="100%" width="100%" align="center">
                <input type="hidden" name="action" value="edit">
                <input type="hidden" name="backurl" value="<? echo $backurl.urlencode($me);?>">
	<!--<tr bgcolor="#eeeeee"> 
        <td width="12%">工作目录:</td>
        <td width="88%"><input name=activepath size=40 value="<?=$activepath?>">
            (空白表示根目录 ,不允许用 “..” 形式的路径)</td>
        </tr>-->
        <tr> 
          <td><?=$TEXT['filename']?></td>
          <td><input name=filename size=40 value="<?=$filename?>">
              <?=$TEXT['warning1']?>
              <input type="button" name="Submit" value="<?=$TEXT['use']?>" onClick="location='file_edit.php?action=creatview';"> </td>
        </tr>
      </table></td>
	<td id="r" rowspan="3">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top">
	<?=$contentView;?>
	</td>
  </tr>
  <tr>
    <td height="10%"> 
      <p align="center"><br>
      <input type="submit" value="<?=$TEXT['save']?>" name=B1>&nbsp;
	  <input type="reset" value="<?=$TEXT['cancelsave']?>" name=B2>&nbsp;
	  <input type="button" value="<?=$TEXT['goback']?>" name=B4 onClick="javascript:history.go(-1);">
	  <input type="hidden" value="1" name="ct" />
      <br>
    </td>
  </tr>
  <tr>
    <td id="bl">&nbsp;</td>
    <td id="bc">&nbsp;</td>
    <td id="br">&nbsp;</td>
  </tr>
</table>
</form>

<?php
}
else if($action = "creatview")
{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xml:lang="en-EU" lang="en-EU">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title><?=$TEXT['visualeditor']?></title>
<link rel="stylesheet" type="text/css" href="css/style.css">
<script>
function Post() {
	if (document.form1.filename.value==""){
		alert("<?=$TEXT['warning'];?>");
		document.form1.filename.focus();
		return false;
  }
}	
</script>
</head>
<body>
<form method="POST" action="file_save.php" name=form1 onSubmit="return Post()">
<table id="tt" border="0" cellspacing="0" cellpadding="0" width="90%" height="100%" align="center">
  <tr>
    <td id="tl">&nbsp;</td>
    <td id="tc" width="100%"><h2><?=$TEXT['fileEdit']?></h2></td>
	<td id="tr">&nbsp;</td>
  </tr>
  <tr>
    <td id="l" rowspan="3">&nbsp;</td>
    <td>
      <table border="0" cellspacing="0" cellpadding="0" height="100%" width="100%" align="center">
      <input type="hidden" name="action" value="editview">
      <input type="hidden" name="backurl" value="<?php echo $backurl.urlencode($me);?>">
	   <!-- <tr bgcolor="#eeeeee"> 
          <td width="12%">工作目录:</td>
          <td width="88%"><input name=activepath size=40 value="<?=$activepath?>">
                          (空白表示根目录 ,不允许用 “..” 形式的路径)</td>
        </tr>-->
        <tr> 
          <td><?=$TEXT['filename']?></td>
          <td><input name=filename size=40 value="<?=$filename?>">
                <?=$TEXT['warning1']?>
                <input type="button" name="Submit" value="<?=$TEXT['use1']?>" onClick="location='file_edit.php?action=creat';"></td>
        </tr>
      </table></td>
	<td id="r" rowspan="3">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top">
	<?=$contentView;?>
	</td>
  </tr>
  <tr>
    <td height="10%"> 
      <p align="center"><br>
      <input type="submit" value="<?=$TEXT['save']?>" name=B1>&nbsp;
	  <input type="reset" value="<?=$TEXT['cancelsave']?>" name=B2>&nbsp;
	  <input type="button" value="<?=$TEXT['goback']?>" name=B4 onClick="javascript:history.go(-1);">
	  <input type="hidden" value="2" name="ct" />
      <br>
    </td>
  </tr>
  <tr>
    <td id="bl">&nbsp;</td>
    <td id="bc">&nbsp;</td>
    <td id="br">&nbsp;</td>
  </tr>
</table>
</form>
<div align="center">
<table id="tt" border="0" cellspacing="0" cellpadding="0" width="90%" height="100%" align="center">
  <tr>
    <td id="tl">&nbsp;</td>
    <td id="tc" width="100%"><h2><?=$TEXT['fileview']?></h2></td>
	<td id="tr">&nbsp;</td>
  </tr>
  <tr>
    <td id="l">&nbsp;</td>
    <td>
      <table border="0" cellspacing="0" cellpadding="0" height="100%" width="100%" align="center">
	    <tr>
		  <td align="center">
<iframe src="
	<?php
	    if(isset($filename))  echo $filename;
		else echo $filename;
	?>
" width="95%" height="600"></iframe></td>
        </tr>
	  </table></td>
	<td id="r">&nbsp;</td>
  </tr>
  <tr>
    <td id="bl">&nbsp;</td>
    <td id="bc">&nbsp;</td>
    <td id="br">&nbsp;</td>
  </tr>
</table>
</div>
<?php
}
?>
</body>
</html>
Return current item: Openology PHP Application Integration