<!--#include file="../Include/Conn.jsp" -->
<!--#include file="../Include/Char.jsp" -->
<!--#include file="Admin_IsLogin.jsp" -->
<%
  dim rs,mSql
  mGrade = Request("Grade")
  mSmallGrade = Request("SmallGrade")
  mSql =  "SELECT * FROM T_Article WHERE F_ID="&Request.QueryString("ID")
  Set rs = conn.Execute(mSql)
  If rs.eof then
    Response.End()
  Else
    ID = rs("F_ID")
	mBigCategoryID = rs("F_BigCategoryID")
    mSmallCategoryID = rs("F_SmallCategoryID")
    mTitle = rs("F_Title")
    mKeyWords = rs("F_KeyWords")
    mAuthor = rs("F_Author")
    mContent = rs("F_Content")
	mLink = rs("F_Link")
	mFilePath = rs("F_FilePath")
    mFileName = mid(mFilePath,instr(instr(1,mFilePath,"/")+1,mFilePath,"/")+1)
	mComeFrom = rs("F_ComeFrom")
    mAddtime = rs("F_Addtime")
	mishtml = rs("F_IsHtml")
	mIsCommend = rs("F_IsCommend")
	mIsPic = rs("F_IsPic")
  End if

    'Read V_ArticlePath
	mSql = "Select top 1 * From V_ArticlePath Where F_SmallCateID=" & mSmallCategoryID
	Set rst = conn.Execute(mSql)
	if rst.Eof then
	   Response.write "对不起，请不要非法操作！"
	   Response.End()
	Else
	   'mBigCateID = rst("F_BigCateID")
	   mBigCateName = rst("F_BigCateName")
	   'mSmallCateID = rst("F_SmallCateID")
	   mSmallCateName = rst("F_SmallCateName")
	   mBigFolder = rst("F_BigFolder")
	   mSmallFolder = rst("F_SmallFolder")
	   mTemplatePath = rst("F_TemplatePath")
	 End if

    'Create Html
	Dim mTemplatePath,mTemplateAllPath
	Dim mNewsContent,mAllPath,mFileName,mPathDir
	Set fso = CreateObject("Scripting.FileSystemObject")
    mTemplateAllPath = Server.MapPath("../Article/Template/NewTemplate/"+mTemplatePath+".htm")
	If fso.FileExists(mTemplateAllPath) then
	   Set objStream = fso.OpenTextFile(mTemplateAllPath)
	Else
	   Call Msgbox("对不起，该类别文章的模板文件 "&mTemplatePath&".htm 找不到，\n请先创建该类别的模板文件!",1)
	End if

	
	Do While not objStream.AtEndOfStream
 	  mNewsContent = mNewsContent & objStream.ReadLine
	  mNewsContent = replace(mNewsContent,"[id]",ID)
	  mNewsContent = replace(mNewsContent,"[bigcategoryid]",mBigCategoryID)
	  mNewsContent = replace(mNewsContent,"[bigcategoryname]",mBigCateName)
	  mNewsContent = replace(mNewsContent,"[smallcategoryid]",mSmallCategoryID)
	  mNewsContent = replace(mNewsContent,"[smallcategoryname]",mSmallCateName)
	  mNewsContent = replace(mNewsContent,"[title]",HTMLEncode2(mTitle))
	  mNewsContent = replace(mNewsContent,"[content]",mContent)
	  mNewsContent = replace(mNewsContent,"[comefrom]",HTMLEncode2(mComeFrom))
	  mNewsContent = replace(mNewsContent,"[addtime]",mAddtime)
  	  mNewsContent = replace(mNewsContent,"[author]",HTMLEncode2(mAuthor))
  	  mNewsContent = replace(mNewsContent,"[keywords]",HTMLEncode2(mKeywords))
	Loop
	objStream.Close

    'Create BigFolder
	folderPath = Server.MapPath("../Htmls")
    mPathDir = folderPath & "\" & mBigFolder

	If Not fso.FolderExists(mPathDir) Then
	  Set f = fso.CreateFolder(mPathDir)
	  Set f = nothing
	end if

    'Create SmallFolder
    mPathDir = folderPath & "\" & mBigFolder&"\"& mSmallFolder
	If Not fso.FolderExists(mPathDir) Then
	  Set f = fso.CreateFolder(mPathDir)
	  Set f=nothing
	end if


	'Create FileName
	Set objHtml = fso.CreateTextFile(mPathDir+"\"+mFileName)
	objHtml.WriteLine mNewsContent
	objHtml.close
	set fso=nothing
	Call CloseDatabase()
	Response.Redirect "Admin_Article.jsp?Grade="&mGrade&"&SmallGrade="&mSmallGrade&"&BigCategoryID="&mBigCategoryID&"&SmallCategoryID="&mSmallCategoryID&"&pageno="&Request("pageno")
   'call MsgBox("文章文件生成成功！\n\n主题：\n"& mTitle1 &"\n\n路径：\n"&Replace(mPathDir+"\"+mFileName,"\","\\")&"\n\n显示：\nhttp://" & Request.ServerVariables("HTTP_HOST")&Replace(mid(request.ServerVariables("URL"),1,instr(2,Request.ServerVariables("URL"),"/")) &"Article/" &mBigFolder +"/"+mSmallFolder+"/"+ mFileName,"\","/")&"\n\n","Admin_Article.jsp?BigCategoryID="&Request("BigCategoryID") &"&pageno="&Request("pageno"))
%>
