<!--#include file="admin_start.asp" -->
<!--#include file="admin_safe_files_include.asp"-->
<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" rightmargin="0" topmargin="0">
<%
dim gContent,gStr
select case gAct
 case "read"
  Readit
 case "write"
  Writeit
end select

Sub ReadIt
  dim i1,i2,hf
  if gPath="" then exit sub
  gStr=procCheckFile(gPath,1)
  if gStr<>"ok" then htmEnd gStr,1,""
  set hf=fo.OpenTextFile(Server.mappath(gPath))
  gcontent=hf.readall
  hf.Close
  set hf=nothing
End Sub

Sub WriteIt
 dim hf
  if Request.form("filepath")="" then  HtmEnd "请输入路径!",1,""
  gStr=procCheckFile(gPath,2)
  if gStr<>"ok" then htmEnd gStr,1,""
  gContent=Request.form("content")
  gStr=gContent
 set hf=fo.CreateTextFile(Server.mappath(gPath),true)
 hf.write gstr
 hf.Close
 set hf=nothing
 set fo=nothing
End Sub


function setcode(gstr)
 dim str1,str2,i1,i2
 i1=1
 i2=2
 gstr=Server.HtmlEncode(gstr)
 gstr=Replace(gstr,"  "," &nbsp;")
 do while i1>0 and i2>i1
  i1=instr(i1,gstr,"![")
  if i1<1 then
   exit do
  end if
  i2=instr(i1+2,gstr,"!]")
  if i2<i1 then
   exit do
  end if
  str1=mid(gstr,i1,i2-i1+2)
  str2=mid(gstr,i1+2,i2-i1-2)
  str2=replace(str2,"&gt;",">")
  str2=replace(str2,"&lt;","<")
  str2=replace(str2,"&quot;","""")
  str2=replace(str2,"&nbsp;"," ")
  str2=replace(str2,"&amp;","&")
  str2=Replace(str2,vbcrlf,"<!---->")
  gstr=replace(gstr,str1,str2)
loop
 gstr=replace(gstr,vbCrLf,"<BR>"&vbCrLf)
 gstr=replace(gstr,"<!---->",vbcrlf)
 setcode=gstr
end function
%>
<form name="form2" method="post" action="<%=Request.Servervariables("SCRIPT_NAME")%>" onsubmit="return checkit();">
  <script language="JavaScript">
var lg_strback;
lg_strback='';
function readit()
{
 if(!document.form2.filepath.value)
  {
   alert('请输入文件路径!');
   return;
  }
 document.form2.action='<%=gFileName%>?act=read&path='+document.form2.filepath.value;
 document.form2.submit();
}

function writeit()
{
 if(!document.form2.filepath.value)
  {
   alert('请输入文件路径!');
   return;
  }
 document.form2.action='<%=gFileName%>?act=write&path='+document.form2.filepath.value;
 document.form2.submit();
}

function proc_back()
{
 document.form2.action=geturl(document.form2);
 document.form2.act.value='none';
 document.form2.submit();
}

function proc_editok()
{
 document.form2.action=geturl(document.form2);
 document.form2.submit();
}

function setdir()
{
 window.open('getdir.asp','_blank','width=500 height=350 scrollbars=1 resizable=1');
}

function proc_undo()
{
var str;
if(lg_strback=='')
 alert('不能回到上一步');
str=window.form2.content.innerText;
window.form2.content.innerText=lg_strback;
lg_strback=str;
}

function repit(mstr,sstr,tstr)
{
 var i;
 i=0;
 if(mstr==''||sstr=='')
  return '';
 while(1)
  {
   i=mstr.indexOf(sstr,i);
   if(i<0)break;
   mstr=mstr.replace(sstr,tstr);
   i+=tstr.length;
  }
return mstr;
}

function proc_replace()
{
var i1,i2,str,strLeft,strRight,strMid;
strLeft=window.form2.repLeft.innerText;
strRight=window.form2.repRight.value;
strMid=window.form2.repMid.innerText;
str=window.form2.content.innerText;
lg_strback=str;
i1=0;
i2=0;
if(strLeft=='')
 return;

if(strRight=='')
 {
  strMid=repit(strMid,'[$]',strLeft);
  str=repit(str,strLeft,strMid);
 }
else
while(1)
{
 i1=str.indexOf(strLeft,i1);
 if(i1<0)
    break;
 i2=str.indexOf(strRight,i1+strLeft.length);
 if(i2<0)
   break;
 str1=str.substring(i1+strLeft.length,i2);
 str2=repit(strMid,'[$]',str1);
 str1=strLeft+str1+strRight;
 if(!window.form2.isRemove.checked)
  {
  str2=strLeft+str2;
  str=str.replace(str1,str2+strRight);
  }
 else
  str=str.replace(str1,str2);
 i1+=str2.length;
 }
window.form2.content.innerText=str;
}
</script>
  <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
    <tr>
      <td>
        <table width="100%" border="0" height="468" align="center" cellspacing="0" cellpadding="0" bgcolor="#f7f7f7">
          <tr align="left" valign="middle"> 
            <td height="54" colspan="2"><font color="#000000"><br>
              ·文件位置: 
              <input type="text" name="filepath" size=76  size="1" class="tx" value="<%=gPath%>">
              <input type="button" name="Button" value="读文件" onclick="readit();" class="bt">
              </font></td>
          </tr>
          <tr align="center" valign="top"> 
            <td width="610" rowspan="2"> 
              <textarea name="content" style="width:600;height:400" wrap="OFF" class="tx"><%=Server.HtmlEncode(gcontent)%></textarea>
            </td>
            <td width="202"> 
              <li><font color="#000000">正文替换</font></li>
              <font color="#000000">,将正文中:<br><br>
              <textarea name="repLeft" id="repLeft" style="width:160;height:70"  class="tx"></textarea>
              <br><br>
              (与<input type="text" name="repRight" id="repRight" style="width:70" class="tx">间内容)替为 
              <br><br>
			  <textarea name="repMid" id="repMid" style="width:160;height:70" class="tx"></textarea>
              <br><br>
              ( 
              <input type="checkbox" name="isRemove" id="isRemove" value="y" checked>
              删除定界符)<br><br>
              <input type="button" name="Submit322" value="开始替换" onClick="proc_replace();" style="width:60" class="bt">
              <input type="button" name="Submit3222" value="撤销替换" onClick="proc_undo();" style="width:60" class="bt">
              </font> 
              <hr noshade size="1" width="100%"><br><br>
              <input type="button" name="Submit2" value="保存文件" onClick="writeit();" class="bt">
              <input type="reset" name="Submit222" value="重执" class="bt">
              <input type="button" name="Submit22" value="关闭" onClick="window.close();" class="bt">
            </td>
          </tr>
        </table>
      </td>
    </tr>
  </table>
  </form>
</body>
<%htmend "",0,""%>
<!--#include file="admin_end.asp" -->