<!--#include file="../../fy.Function.asp"-->
<!--#include file="../../fycms.asp"-->
<!doctype html>
<html>
<head>
<meta charset="gb2312">
<title>添加/修改文章</title>
<link rel="stylesheet" type="text/css" href="../../css/base.css">
<link rel="stylesheet" type="text/css" href="../../css/content.css">
</head>
<body>
<%
 If Not fycms.ChkAdmin() Then '超级管理员检测
	Call fycms.fycmsErr("")
 End If 
Dim Rs1,path,tempfile,Action,a
tempfile=request("File")
path=request("Dir")
A=request("A")
Action=request("Action")
Select Case  Action
	Case "Add"
		Call Add()
	Case "Addsave"
		Call Addsave()
	Case "Save"
		Call Save()
	Case Else
		Call AddEdit()
End Select 

	Function save()
	Dim Content,FileFSO
		Content=request("content")
		Path=request("Path")
		Path=rep(Path,".html","")
		Path=rep(Path,".","")
		Path=rep(Path,";","")
		 Set FileFSO = Server.CreateObject("ADODB.Stream")
			With FileFSO
			.Type = 2
			.Mode = 3
			.Open
			.Charset = "gb2312"
			.Position = FileFSO.Size
			.WriteText  Content
			.SaveToFile Server.MapPath(Path&".html"),2
			.Close
			End With
		Set FileFSO = Nothing
 		Call fycms.Alert("模板修改成功!","index.asp"):Exit Function
	End Function 

	Function Addsave()
	Dim Content,FileFSO,File,PhysicalPath,fs
		Content=request("content")
		File=request("File")
		Path=request("Path")
		File=rep(File,".","")
		File=rep(File,";","")
 		 Set fs = Server.CreateObject("scripting.filesystemobject")
		  PhysicalPath=Server.Mappath(Path&File)
	      if fs.FileExists(PhysicalPath) = False Then
			 Set FileFSO = Server.CreateObject("ADODB.Stream")
			With FileFSO
			.Type = 2
			.Mode = 3
			.Open
			.Charset = "gb2312"
			.Position = FileFSO.Size
			.WriteText  Content
			.SaveToFile Server.MapPath(Path&File&".html"),2
			.Close
			End With
			Set FileFSO = Nothing
 			Call fycms.Alert("模板增加成功!","index.asp"):Exit Function
		  Else 
			  Call fycms.Alert("文件名已经存在,请另取一个名称!","")
		  End  If 
		
	
	
	End Function 


	Function  LoadTemplate(TempString) 
		On Error Resume Next
		Dim  Str,A_W
		set A_W=server.CreateObject("adodb.Stream")
		A_W.Type=2 
		A_W.mode=3 
		A_W.charset="gb2312"
		A_W.open
		A_W.loadfromfile server.MapPath(TempString)
		If Err.Number<>0 Then Err.Clear:LoadTemplate="模板没有找到 <br> by fycms":Exit Function
		Str=A_W.readtext
		A_W.Close
		Set  A_W=nothing
		LoadTemplate=Str
	End  function

Function AddEdit()
%>
 <div class="breadnav">当前位置：<a href="#">后台中心</a> >> 模板修改</div>
 <table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" class="table">
    <form id="form" name="form" method="post" action="?Action=Save&Path=<%=path&"/"&tempfile%>">
 
    <tr>
      <td colspan="2">文件名：<STRONG><%=tempfile%></STRONG> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	  完整路径 ：<STRONG><font size=5 color=red><%=path&"/"&tempfile%></font></STRONG>&nbsp;&nbsp;&nbsp;&nbsp;</td>
    </tr>
 
    <tr>
      <td colspan="2">
	<div>
	<textarea name="content"  rows="28" style="width:100%"><%=server.HTMLEncode(LoadTemplate(path&"/"&tempfile))  %></textarea>	
						  </div>
     
	  </td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input type=button onclick=CheckForm() class="btn btn_primary" name=Submit value="  保存  " />
      <input type="reset" name="Submit2"  class="btn btn_primary" value="  重置  " /></td></td>
    </tr></form>
  </table>
  <% End Function 



Function Add()
  Dim tcontent
  tcontent = "<html>" & vbcrlf &"<head>" & vbcrlf & "<meta http-equiv=""Content-Type"" content=""text/html; charset=gb2312"">" & vbcrlf
  tcontent = tcontent & "<title>默认文档-By www.fycms.com</title>" & vbcrlf & "</head>" & vbcrlf & "<body>" & vbcrlf &"Hello Word!"& vbcrlf & "</body>" & vbcrlf & "</html>"
%>
 <div class="breadnav">当前位置：<a href="#">后台中心</a> >> 模板修改</div>
  <table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" class="table">
    <form id="form" name="form" method="post" action="?Action=Addsave&Path=<%=path&"/"&tempfile%>">
     <tr>
      <td colspan="2"> 
	   文件名：<input name="File" type="text"  size="20" maxlength="255" id="File" value="Untitled"> 路径：<STRONG><font size=5 color=red><%=path%></font></STRONG></td>
    </tr>
 
    <tr>
      <td colspan="2">
	<div>
	<textarea name="content"  rows="28" style="width:100%"><%=tcontent%></textarea>	
						  </div>
     
	  </td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input type=button onclick=CheckForm() class="btn btn_primary" name=Submit value="  保存  " />
      <input type="reset" name="Submit2"  class="btn btn_primary" value="  重置  " /></td></td>
    </tr></form>
  </table>
  <% End Function %>
  <script language="javascript">
 
  function CheckForm()
{
  		var form=document.form;
	    form.Submit.value="正在提交数据,请稍等...";
		form.Submit.disabled=true;	
		form.Submit2.disabled=true;	
	    form.submit();
        return true;
	}
	</script>

</body>
</html>