www.gusucode.com > 掌柜网店购物系统 4.0码程序 > admin/editfile.asp

    <%OPTION EXPLICIT%>
<%if session("admin")="" then
response.Write "<script language='javascript'>alert('网络超时或您还没有登陆!');window.location.href='login.asp';</script>"
response.End
else
if session("flag")>1 then
response.Write "<p align=center><font color=red>您没有此项目管理权限!</font></p>"
response.End
end if
end if%>
<!--#include file="include.asp"-->
<html><head><title>Web Edit</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" href="../img/css.css" type="text/css">
<style>
BODY {
SCROLLBAR-FACE-COLOR: #e7e7e7;  
SCROLLBAR-HIGHLIGHT-COLOR: #ffffff;
SCROLLBAR-SHADOW-COLOR: #d4d0c8;
SCROLLBAR-3DLIGHT-COLOR: #FFFFFF;
SCROLLBAR-ARROW-COLOR:  #ffffff;
SCROLLBAR-TRACK-COLOR: #f7f7f7;
SCROLLBAR-DARKSHADOW-COLOR: #e7e7e7; 
}
.style3 {color: #FF6600}
</style>
</head>
<body>
<%
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="80%" border="1" cellspacing="0" cellpadding="0" bordercolordark="#CCCCCC" bordercolorlight="#000000" align="center">
    <tr>
      <td>
        <table width="100%" border="0" height="468" align="center" cellspacing="0" cellpadding="0" bordercolorlight="#FFFAF4" bordercolordark="#CC9933" bgcolor="#dddddd">
          <tr align="left" valign="middle"> 
            <td height="54" colspan="2"><font color="#000000"><br>
              文件位置: 
              <input type="text" name="filepath" style="width:495;height:21" maxlength="50" size="1" class="tx" value="<%=gPath%>">
              <input type="button" name="Button" value="读文件" onclick="readit();" class="bt">
              </font></td>
          </tr>
          <tr align="left" valign="middle"> 
            <td width="610" height="335" rowspan="2"> 
              <textarea name="content" style="width:600;height:400" wrap="OFF" class="tx"><%=Server.HtmlEncode(gcontent)%></textarea>
            </td>
            <td height="326" width="202"> 
              <li><font color="#000000">正文替换</font></li>
              <font color="#000000">,将正文中:<br>
              <textarea name="repLeft" id="repLeft" style="width:160;height:70"  class="tx"></textarea>
              <br>
              (与<input type="text" name="repRight" id="repRight" style="width:70" class="tx">
              间内容)替为 
              <textarea name="repMid" id="repMid" style="width:160;height:110" class="tx"></textarea>
              <br>
              ( 
              <input type="checkbox" name="isRemove" id="isRemove" value="y" checked>
              删除定界符)<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%">
            </td>
          </tr>
          <tr align="left" valign="middle"> 
            <td align="center" valign="middle" width="202" height="43"> <font color="#000000"> 
              <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">
              </font></td>
          </tr>
          <tr align="center" valign="middle"> 
            <td colspan="2" height="14">&nbsp; </td>
          </tr>
        </table>
      </td>
    </tr>
  </table>
  </form>
</body>
</html>
<%htmend "",0,""%>