<!--------MetInfo 网站管理系统------->
<!--这是一个免费开源程序，您可以在不用于商业目的的前提下对程序进行修改和再发布-->
<!--版权所有：www.MetInfo.com.cn-->

<!--#include file="../inc/conn.asp"-->
<!--#include file="../admin.asp"-->
<!--#include file="../../Inc/Config.asp"-->
<!--#include file="../../Inc/Ubbcode.asp"-->
<!--#include file="../Inc/Function.asp"-->
<!--#include file="../htm/createproducts.asp"-->
<%
ID=Request.Form("ID")
Title=Trim(request.form("Title"))
class1=trim(request.form("class1"))
class2=trim(request.form("bigclass"))
class3=trim(request.form("bigclass1"))
keyword=trim(request.form("keywords"))
description=trim(request.form("description"))
Content=request.form("Content")
User=Trim(request.form("User"))
newspic=trim(request.form("DefaultPicUrl"))
tpnews=Trim(request.form("tpnews"))
tjnews=Trim(request.form("tjnews"))
Infotime=trim(request.form("Infotime"))
Hits=trim(request.form("Hits"))
Action=trim(request("Action"))
dim web,id1,webfile
set rs=server.createobject("adodb.recordset")
sql="select * from lanmu where id="&cint(class1)
		rs.open sql,conn,1,1
		webfile=rs("webname")		
		rs.close
set rs=nothing
web="Shownews"
if class2="" then
	founderr=true
	errmsg=errmsg+"<li>未指定文章所属大类</li>"
end if
if Title="" then
	founderr=true
	errmsg="<li>文章标题不能为空</li>"
end if
if Content="" then
	founderr=true
	errmsg=errmsg+"<li>文章内容不能为空</li>"
end if

if founderr=false then
	Title=dvhtmlencode(Title)	
	if Infotime<>"" and IsDate(Infotime)=true then
		Infotime=CDate(Infotime)
	else
		Infotime=now()
	end if
	
	if Hits<>"" then
		Hits=CLng(Hits)
	else
		Hits=0
	end if
	
	set rs=server.createobject("adodb.recordset")
	select case Action
	  case "Add"	
		sql="select * from News where (id is null)" 
		rs.open sql,conn,1,3
		rs.addnew
		call SaveData()		
		rs.update	
		rs.close
		set rs=nothing
		if create=True then
		set rss=server.createobject("adodb.recordset")
		sql="select top 1 * from News order by id desc" 
		rss.open sql,conn,1,1
		id1=rss("id")		
		call createproducts(web,id1,webfile)
		
		rss.close
		set rss=nothing
		end if
		call createindex()
		response.redirect "News_Manage.asp?id="&class1
	 case "Modify"	
  		if ID<>"" then
			sql="select * from News where id="&ID
			rs.open sql,conn,1,3
			if not (rs.bof and rs.eof) then
			    
				call SaveData()				
				rs.update
				if create=True then 
				id1=ID
				call createproducts(web,id1,webfile)
				
			 end if
				rs.close
				set rs=nothing
				call createindex()
	            response.redirect "News_Manage.asp?id="&class1
 			else
				founderr=true
				errmsg=errmsg+"<li>找不到此文章，可能已经被删除。</li>"
				call WriteErrMsg()
			end if
		else
			founderr=true
			errmsg=errmsg+"<li>不能确定ID的值</li>"
			call WriteErrMsg()
		end if
	 Case else
		founderr=true
		errmsg=errmsg+"<li>没有选定参数</li>"
		call WriteErrMsg()
	end select
	call CloseConn()
else
	WriteErrMsg
end if
%>

<%
sub SaveData() 
  if class1="" then 
     class1=0
  end if 
  if class2="" then 
     class2=0
  end if
  if class3="" then 
     class3=0
  end if 
  rs("Title")=Title
  rs("Content")=Content
  rs("User")=User 
  rs("class1")=CLng(class1)
  rs("class2")=CLng(class2)
  rs("class3")=CLng(class3)
  rs("keywords")=keyword
  rs("description")=description 
  rs("Infotime")=Infotime
  rs("Hits")=Hits
  if tpnews="yes" then
	rs("tpnews")=True
  else
	rs("tpnews")=False
  end if 
   
 if tjnews="yes" then
	rs("tjnews")=True
  else
	rs("tjnews")=False
  end if 
  '***************************************
	'删除无用的上传文件
	if ObjInstalled=True and UploadFiles<>"" then
		dim fso,strRubbishFile
		Set fso = Server.CreateObject("Scripting.FileSystemObject")
		if instr(UploadFiles,"|")>1 then
			dim arrUploadFiles,intTemp
			arrUploadFiles=split(UploadFiles,"|")
			UploadFiles=""
			for intTemp=0 to ubound(arrUploadFiles)
				if instr(Content,arrUploadFiles(intTemp))<=0 and arrUploadFiles(intTemp)<>FirstImageName then
					strRubbishFile=server.MapPath("../" & arrUploadFiles(intTemp))
					if fso.FileExists(strRubbishFile) then
						fso.DeleteFile(strRubbishFile)
						response.write "<br><li>" & arrUploadFiles(intTemp) & "在文章中没有用到，也没有被设为首页图片，所以已经被删除！</li>"
					end if
				else
					if intTemp=0 then
						UploadFiles=arrUploadFiles(intTemp)
					else
						UploadFiles=UploadFiles & "|" & arrUploadFiles(intTemp)
					end if
				end if
			next
		else
			if instr(Content,UploadFiles)<=0 and UploadFiles<>FirstImageName then
				strRubbishFile=server.MapPath("../" & UploadFiles)
				if fso.FileExists(strRubbishFile) then
					fso.DeleteFile(strRubbishFile)
					response.write "<br><li>" & UploadFiles & "在文章中没有用到，也没有被设为首页图片，所以已经被删除！</li>"
				end if
				UploadFiles=""
			end if
		end if
		set fso=nothing
	end If
	'结束
	'***************************************
  rs("newspic")=newspic    
end sub
%>

