<!--#include file="../include/Conn.jsp"-->
<!--#include file="../Include/Char.jsp" -->
<!--#include file="Admin_IsLogin.jsp" -->
<%
'Define Variable 
dim i
dim rs,rst
dim mTypeName,mGrade,mSql,mFlag,mBgColor
Set rs=Server.CreateObject("Adodb.RecordSet")

'initialization 
mFlag=true'add

'Display
if Request.Querystring("action")="edit" then 
  ID = Request.QueryString("ModifyID")
  mSql="Select * From T_Template Where F_ID=" & ID
  Set rs=Conn.Execute(mSql)
  If not rs.Eof then
    mTempLateName = rs("F_TemplateName")
    mTemplatePath = rs("F_TemplatePath")
	mTempTemplatPath = Server.MapPath("../Article/Template/NewTemplate/"+rs("F_TemplatePath")+".htm")
	Set fso = CreateObject("Scripting.FileSystemObject") 
	If fso.FileExists(mTempTemplatPath) then
	   Set objStream = fso.OpenTextFile(mTempTemplatPath)
	Else
	   Call Msgbox("对不起，该类别文章的模板文件 "&mTempTemplatPath&"找不到，\n请先创建该类别的模板文件!",1)
	End if
	mTempTemplatPath = ""
	Do While not objStream.AtEndOfStream
	  mTempTemplatPath = mTempTemplatPath&objStream.ReadLine
	Loop
	objStream.close
    rs.Close
  End if
  mFlag=false
end if

 'Save Records and Create Html
 If Request.ServerVariables("REQUEST_METHOD")="POST" then
    mTemplateName = Trim(Request.Form("txtTemplateName"))
    mTemplatePath = rTrim(Request.Form("txtTemplatePath"))
    mTemplateContent = Trim(Request.Form("txtContent"))

	Set fso = CreateObject("Scripting.FileSystemObject")
	
	gblScriptName= Request.ServerVariables("Script_Name")
	gblScriptName = Mid(gblScriptName,InstrRev(gblScriptName,"/") + 1)
	htmlfilename=mTemplatePath & ".htm"
	folderPath = Server.MapPath("../Article/Template/NewTemplate/" & htmlfilename&" ")
	Set objHtml = fso.CreateTextFile(folderPath)
	objHtml.WriteLine mTemplateContent
	objHtml.close
	set fso=nothing

   'Write Records
   if Request("action") = "Insert" then
      mSql="Select * From T_Template"
   else
      mSql="Select * From T_Template Where F_ID="&Request.QueryString("ModifyID")
   end if
   rs.open mSql,conn,1,3
   if Request("action")="Insert" then rs.AddNew
   rs("F_TemplateName") =  mTemplateName
   rs("F_TemplatePath")= mTemplatePath
   rs("F_TemplateContent")= mTemplateContent
   rs.update
   rs.close
   if Request("action")="Insert" then mFlag = True else mFlag = False
   call MsgBox("模板文件生成成功！\n\n模板名称："& mTemplateName &"\n\n路径：\n"&mTemplatePath&"\n全路径：\n"&replace(Server.MapPath("..\Article\Template\NewTemplate\"+mTemplatePath+".htm"),"\","\\")&"\n","Admin_ArticleTemplateManage.jsp?pageno="&Request("pageno"))
 End if


'Delect Records
if request("action")="delete" then
  mSql = "DELETE FROM T_Template WHERE F_ID=" &Request.QueryString("DeleteID")
  conn.execute mSql
   'Delete Html
  DelFname=Server.MapPath("../Article/Template/NewTemplate/"+Request("TemplatePath"))+".htm"
  Set TestFileObject=Server.Createobject("Scripting.FileSystemObject")
  If TestFileObject.FileExists(DelFname) then
     Set NewFile=TestFileObject.getfile(DelFname)
     Newfile.delete
  End if

  Response.write "<script>location.replace('Admin_ArticleTemplateManage.jsp?action=IsDelete&pageno="&Request.Querystring("pageno")&"')</script>"
end if
%>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="images/Style.css" rel="stylesheet" type="text/css">
<SCRIPT language="JavaScript">
function jDelete(url)
{
  if((confirm(" 警告:请确定是否删除,删除后不能恢复! "))==true) 
	self.location=url+'&action=delete';
}
</SCRIPT>
<script language="javascript">
function CheckData(){
  if (document.LatticeEditorForm.txtTemplateName.value=="")
   {
    alert("模板名称不能为空，请输入！");
	document.LatticeEditorForm.txtTemplateName.focus();
	return false;
   }
  if (document.LatticeEditorForm.txtTemplatePath.value=="")
   {
    alert("路径不能为空，请输入！");
	document.LatticeEditorForm.txtTemplatePath.focus();
	return false;
   }

   
   document.LatticeEditorForm.hidTemplateContent.value=frames.LatticeEditDocument.document.body.innerHTML;
}
</script>
<SCRIPT LANGUAGE="JScript.Encode" src="../latticeeditor/LatticeEditor1.jsp"></SCRIPT>
<SCRIPT LANGUAGE="JScript.Encode" src="../latticeeditor/LatticeEditor2.jsp"></SCRIPT>
<SCRIPT LANGUAGE="JScript.Encode" src="../latticeeditor/LatticeEditor3.jsp"></SCRIPT>
</head>
<body text=#000000 leftmargin=0 topmargin=0 marginheight="0" marginwidth="0" >
<table width="100%" height="1"  border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td></td>
  </tr>
</table>
<TABLE width=100% height=95% border=1 align="center" cellPadding=0 
cellSpacing=0 borderColor=#7c96b8 borderColorDark=#ffffff>
  <TBODY>
    <TR> 
      <TD width="100%" align=center valign="top">
<%
	admin_flag=",1|2|0,"
	if instr(session("flag"),admin_flag)=0 or isnull(session("flag"))=true then
	Response.write "<br><br><br><br><b><font color=red>对不起，您没有管理本页面的权限!</font></B>"
	Response.end
	end if
%>
<table width="100%" border="0" cellspacing="1" cellpadding="0" align="center">
          <tr style="cursor:hand" onMouseOut="this.style.backgroundColor=''" onMouseOver="this.style.backgroundColor='#EBEEF6'"  bgcolor="#dde1ec" align="center"> 
            <td width="8%"><font color="#666666"><b>ID</b></font></td>
            <td><font color="#666666"><b>模板名称</b></font></td>
            <td width="15%"><b><font color="#666666">路径</font></b></td>
            <td width="40%"><b><font color="#666666">全路径</font></b></td>
            <td width="21%"><font color="#666666"><b>管理</b></font></td>
          </tr>
        </table>
        <table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#ebeef6">
          <%  
	Set rs=Server.createobject("Adodb.RecordSet")
    pageno=request.querystring("pageno")
    pmcount=16  
    mSql="select * from T_Template order by F_ID"
	rs.open mSql,conn,1,1
	if rs.eof then
	   'response.write "<br><p  align='center'><font color=red><B> 对不起，数据已清空！</B></font></p>"
    else
    rs.pagesize=pmcount
    mpage=rs.pagecount
    if pageno="" then pageno=1
    if  cint(pageno)<1 or cint(pageno)>mpage then  pageno=1
    rs.absolutepage=pageno

 Dim rc,re
 rc=rs.pagesize
 re=1
 do while not rs.eof and rc>0
 mBgColor=Request.Querystring("BgColor")
 if Trim(rs("F_ID"))=Trim(mBgColor) then mColor= "D6DFFF" else mColor= "ffffff"
%>
          <tr bgcolor="<%=mColor%>"   onmouseout="this.style.backgroundColor=''" onMouseOver="this.style.backgroundColor='#EBEEF6'" > 
            <td  width="8%" align="center"><%=rs("F_ID")%></td>
            <td align="center" ><%=rs("F_TemplateName")%> </td>
            <td width="15%" align="center" ><%=rs("F_TemplatePath")%></td>
            <td width="40%" align="center" ><%Response.write ("NewTemplate/Template/"+rs("F_TemplatePath")+".htm")%></td>
            <td width="21%" align="center" > <a title="添加记录" href='Admin_ArticleTemplateManage.jsp?pageno=<%=mPage%>'><font color="#666666">添加</font></a> 
              |&nbsp;<a title="修改记录" href='Admin_ArticleTemplateManage.jsp?action=edit&ModifyID=<%=rs("F_ID")%>&BgColor=<%=rs("F_ID")%>&pageno=<%=cstr(pageno)%>'><font color="#666666">修改</font></a> 
              |&nbsp;<a title="请确定是否删除,删除后不能恢复!" href="javascript:jDelete('Admin_ArticleTemplateManage.jsp?TemplatePath=<%=rs("F_TemplatePath")%>&DeleteID=<%=rs("F_ID")%>&pageno=<%=cstr(pageno)%>')"><font color="#666666">删除</font></a> 
            </td>
          </tr>
          <%
 rs.movenext
 re=re+1
 rc=rc-1
 loop
 end if
%>
        </table> 
        <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="FFFFFF">
          <tr> 
            <td width="35%" height="22">
			  &nbsp;共
			  <font color=red><strong><% = rs.recordcount%></strong></font>
			  条记录 当前第
			  <font color=red><strong><% = Trim(pageno)%></strong></font>页/共
			  <font color=red><strong><% = Trim(mpage)%></strong></font>页
			  </td>
            <td width="65%" align="right"> 
<%
if pageno>1 then
   response.write "<a href='Admin_ArticleTemplateManage.jsp'> <img alt='首页' src='Images/boqb02.gif' border=0 width='15' height='14'></a>"
else
   response.write "<img alt='首页' src='Images/boqb02.gif' border=0 width='15' height='14'>"
end if

if pageno>1 then
   response.write "<a href='Admin_ArticleTemplateManage.jsp?pageno="&pageno-1&"'><img alt='上一页' src='Images/bob02.gif' border=0 width='15' height='14'></a>"
else
   response.write "<img alt='上一页' src='Images/bob02.gif' border=0 width='15' height='14'>"
end if

add=5'数字分页个数+1
if pageno-int(add/2)<=1 then m=1 else m=pageno-int(add/2)
if m+add>mpage then 
   n=mpage
   if mpage-add<=1 then m=1 else m=mpage-add
else
   n=m+add
end if

for pno=m to n
 if pno=cint(pageno) then
   response.write "&nbsp;<font color=red>"&pno&"</font>"
 else
   response.write "<b>&nbsp;<a href='Admin_ArticleTemplateManage.jsp?pageno="&pno&"'>"&pno&"</a></b>"
 end if
next
response.write "&nbsp"

if int(pageno) < int(rs.pagecount) then
  response.write "<a href='Admin_ArticleTemplateManage.jsp?pageno="&pageno+1&"'><img alt='下一页' src='Images/fbob02.gif' border=0 width='15' height='14'></a>"
else 
  response.write "<img alt='下一页' src='Images/fbob02.gif' border=0 width='15' height='14'>"
end if

if int(pageno) < int(rs.pagecount) then
   response.write "<a href='Admin_ArticleTemplateManage.jsp?pageno="&mpage&"'><img alt='末页' src='Images/fboqb02.gif' border=0 width='15' height='14'></a>"
else
   response.write "<img alt='末页' src='Images/fboqb02.gif' border=0 width='15' height='14'>"
end if
Response.write "&nbsp;&nbsp;"
%>
            </td>
          </tr>
        </table>
        <%if mFlag=true then'add%>
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td height="18" align="center" bgcolor="FFFFFF"><strong><font color=red>
        <%
		  if Request.QueryString("action")="IsInsert" then response.write "提示：记录添加成功！" 
		  if Request.QueryString("action")="IsDelete" then response.write "提示：记录删除成功！" 
		  if Request.QueryString("action")="IsModify" then response.write "提示：记录修改成功！" 
  		  if Trim(Request.QueryString("action"))="" then response.write "提示：当前为添加状态！" 
		%>
              </font></strong></td>
          </tr>
        </table> 
        <strong><font color=red> </font></strong> 
        <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
          <tr> 
            <form name="LatticeEditorForm" method="post" action="Admin_ArticleTemplateManage.jsp?pageno=<%=mpage%>&action=Insert" onSubmit="return CheckData()">
              <td valign="top"> <table width="100%" height="67" border="0" cellpadding="1" cellspacing="0">
                  <tr background="Images/mmTo.gif"> 
                    <td height="6" colspan="3" background="Images/mmTo.gif"> <span style="CURSOR: hand; FILTER: dropshadow(color=#FFFFFF, offx=1, offy=1, positive=1);  WIDTH: 100%">功能：添加记录</span></td>
                  </tr>
                  <tr> 
                    <td width="13%" align="center" valign="top" bgcolor="fcfcfc">模板名称： 
                    </td>
                    <td width="87%" valign="top" bgcolor="fcfcfc"><input class="text" name="txtTemplateName" type="text"  value="" size="30" maxlength="20"></td>
                   
                  </tr>
                  <tr> 
                    <td align="center" valign="top" bgcolor="fcfcfc">模板路径： </td>
                    <td width="87%" bgcolor="fcfcfc"><input name="txtTemplatePath" type="text" class="text"   value="" size="30" maxlength="20">
                      <input type="hidden" name="hidTemplateContent"></td>
                  </tr>
                  <tr> 
                    <td align="center" valign="top" bgcolor="fcfcfc">模板内容：<br>
                    </td>
                    <td width="87%" valign="top" bgcolor="fcfcfc"> 
                      <table width="96%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                          <td>
							<textarea name="txtContent" style="display:none"></textarea> 
                          <IFRAME ID="LatticeEditDocument" SRC="../Editor/eWebEditor.jsp?id=txtContent&style=standard" FRAMEBORDER="0" SCROLLING="no" WIDTH="620" HEIGHT="350"></IFRAME></td>
                        </tr>
                      </table></td>
                  </tr>
                  <tr> 
                    <td height="33" colspan="3" bgcolor="fcfcfc"> 　 
                      <input type="submit" value="提交信息" name="B3" class="button"> 
                      <input type="reset" value="从新来过" name="B3" class="button"> 
                    </td>
                  </tr>
                </table></td>
            </form>
          </tr>
        </table>
        <%else%>
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr> 
            <td height="18" align="center" bgcolor="ffffff"><strong><font color=red> 
       <%
		  if Request.QueryString("action")="IsInsert" then response.write "提示：记录添加成功！" 
		  if Request.QueryString("action")="IsDelete" then response.write "提示：记录删除成功！" 
		  if Request.QueryString("action")="IsModify" then response.write "提示：记录修改成功！" 
		  if Trim(Request.QueryString("action"))="edit" then response.write "提示：当前为修改状态！" 
	   %>
              </font></strong></td>
          </tr>
        </table>
        <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" height="54">
          <tr> 
            <form name="LatticeEditorForm" method="post" action="Admin_ArticleTemplateManage.jsp?pageno=<%=request("pageno")%>&action=EditSave&ModifyID=<%=request("ModifyID")%>" onSubmit="return CheckData()">
              <td> <table width="100%" height="67" border="0" cellpadding="1" cellspacing="0">
                  <tr background="Images/mmTo.gif"> 
                    <td height="6" colspan="3" background="Images/mmTo.gif"> <span style="CURSOR: hand; FILTER: dropshadow(color=#FFFFFF, offx=1, offy=1, positive=1);  WIDTH: 100%">功能：修改记录</span></td>
                  </tr>
                  <tr> 
                    <td width="13%" align="center" valign="top" bgcolor="fcfcfc">模板名称： 
                    </td>
                    <td width="87%" valign="top" bgcolor="fcfcfc"><input class="text" name="txtTemplateName" type="text"  value="<% = mTemplateName %>" size="30" maxlength="20"></td>
                   
                  </tr>
                  <tr> 
                    <td align="center" valign="top" bgcolor="fcfcfc">模板路径： </td>
                    <td width="87%" bgcolor="fcfcfc"><input name="txtTemplatePath" type="text" class="text"   value="<% = mTemplatePath %>" size="30" maxlength="20">
                      <input type="hidden" name="hidTemplateContent"></td>
                  </tr>
                  <tr> 
                    <td align="center" valign="top" bgcolor="fcfcfc">模板内容： </td>
                    <td width="87%" valign="top" bgcolor="fcfcfc"> 
                      <table width="96%" border="0" cellspacing="0" cellpadding="0">
                        <tr> 
                          <td><textarea name="txtContent" style="display:none"><% = mTempTemplatPath %></textarea> 
                          <IFRAME ID="LatticeEditDocument" SRC="../Editor/eWebEditor.jsp?id=txtContent&style=standard" FRAMEBORDER="0" SCROLLING="no" WIDTH="620" HEIGHT="350"></IFRAME> 
                          </td>
                        </tr>
                      </table> </td>
                  </tr>
                  <tr> 
                    <td height="33" colspan="3" bgcolor="fcfcfc"> 　 
                      <input type="submit" value="提交信息" name="B3" class="button"> 
                      <input type="reset" value="从新来过" name="B3" class="button"> 
                    </td>
                  </tr>
                </table></td>
            </form>
          </tr>
        </table>
        <%end if%>
      </TD>
    </TR>
  </TBODY>
</TABLE>
<object id="dlgColHelperTbl" classid="clsid:3050f819-98b5-11cf-bb82-00aa00bdce0b" width="0px" height="0px"></object>
</body>
</html>
<%
 rs.close
 set rs=nothing
 conn.close
 set conn=nothing
%>
