<%@ codepage ="936" %>
<%charset="gb2312"%>
<%Session.CodePage=936%>
<!--#include file="Admin.asp"-->
<!--#include file="Conn.asp"-->
<!--#include file="../Inc/Config.asp"-->
<!--#include file="../Inc/Ubbcode.asp"-->
<!--#include file="Inc/Function.asp"-->
<%
dim rs,sql,ErrMsg,FoundErr
dim ArticleID,BigClassID,SmallClassID,Title,Content,admin,UpdateTime,Hits
dim IncludePic,DefaultPicUrl,UploadFiles,Passed,Elite,arrUploadFiles
dim ObjInstalled
ObjInstalled=IsObjInstalled("Scripting.FileSystemObject")
FoundErr=false
ArticleID=Trim(Request.Form("ArticleID"))
BigClassID=trim(request.form("BigClassID"))
SmallClassID=trim(request.form("SmallClassID"))
Title=trim(request.form("Title"))
color=request("post[style]")
admin=trim(request.form("admin"))
Content=trim(request.form("Content"))
UpdateTime=trim(request.form("UpdateTime"))
IncludePic=trim(request.form("IncludePic"))
DefaultPicUrl=trim(request.form("DefaultPicUrl"))
UploadFiles=trim(request.form("UploadFiles"))
if left(trim(UploadFiles),1)="|" then UploadFiles=right(UploadFiles,len(UploadFiles)-1)
Passed=trim(request.form("Passed"))
Elite=trim(request.form("Elite"))
Hits=trim(request.form("Hits"))


dim sql_chk,rs_chk
if request("action")="Modify" then
	sql_chk="select ArticleID from conews where BigClassID=" & BigClassID & " and SmallClassID=" & SmallClassID & " and title='" & title & "' and not(ArticleID=" & ArticleID & ")"
elseif request("action")="add" then
	sql_chk="select ArticleID from conews where BigClassID=" & BigClassID & " and SmallClassID=" & SmallClassID & " and title='" & title & "'"
end if
set rs_chk= Server.CreateObject("ADODB.Recordset")
rs_chk.open sql_chk,conn,1,1
if rs_chk.eof=false and rs_chk.bof=false then
	founderr=true
	errmsg=errmsg+"<li>该信息已经存在</li>"
end if
if BigClassID="" 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)
	Content=Content
	if UpdateTime<>"" and IsDate(UpdateTime)=true then
		UpdateTime=CDate(UpdateTime)
	else
		UpdateTime=now()
	end if
	if Hits<>"" then
		Hits=CLng(Hits)
	else
		Hits=0
	end if
	set rs=server.createobject("adodb.recordset")
	if request("action")="add" then
		sql="select top 1 * from conews" 
		rs.open sql,conn,1,3
		rs.addnew
		call SaveData()
		rs.update
		ArticleID=rs("ArticleID")
		rs.close
		set rs=Nothing
	elseif request("action")="Modify" then
  		if ArticleID<>"" then
			sql="select * from conews where articleid=" & ArticleID
			rs.open sql,conn,1,3
			if not (rs.bof and rs.eof) then
				call SaveData()
				rs.update
				rs.close
				set rs=nothing
 			else
				founderr=true
				errmsg=errmsg+"<li>找不到此信息，可能已经被其他人删除。</li>"
				call WriteErrMsg()
			end if
		else
			founderr=true
			errmsg=errmsg+"<li>不能确定ArticleID的值</li>"
			call WriteErrMsg()
		end if
	else
		founderr=true
		errmsg=errmsg+"<li>没有选定参数</li>"
		call WriteErrMsg()
	end if
%>
<!-- #include file="Inc/Head.asp" -->
<div align=center>
<TABLE class=tableBorder1 style="WIDTH: 100%" cellSpacing=0 cellPadding=3 
align=center border=0>
  <TBODY>
  <TR>
    <TD height=50></TD></TR></TBODY></TABLE>
<TABLE class=tableBorder cellSpacing=0 cellPadding=0 width="85%" align=center border=0>
	<tr> 
		<TH align=left height=23 class="tableHeaderText"><div align="center"><font color=white>频 道 信 息 设 置</font></div></TH>
	</tr>
	<tr> 
	  <td height="25" class=forumrow>
      <table width="100%" border="0" align="center" cellpadding="1" cellspacing="2">
        <tr> 
          <td class=forumRow_shui  height="25" colspan="2"><b> 
            <%if request("action")="add" then%>
            添加 
            <%else%>
            修改 
            <%end if%>
            信息成功</b></td>
        </tr>
        <tr> 
          <td width="19%" height="22" bgcolor="#C0C0C0" class="tdbg"> <p align="right">信息序号：</p></td>
          <td width="81%" bgcolor="#E3E3E3" class="tdbg"><%=ArticleID%></td>
        </tr>
        <tr> 
          <td height="22" bgcolor="#C0C0C0" class="tdbg"><div align="right">信息标题：</div></td>
          <td bgcolor="#E3E3E3" class="tdbg"><%=Title%></td>
        </tr>
        <tr> 
          <td height="22" bgcolor="#C0C0C0" class="tdbg"><div align="right">所属类别：</div></td>
          <td bgcolor="#E3E3E3" class="tdbg"> <%
			set rst=server.CreateObject("adodb.recordset")
			rst.open "Select BigClassName From NewsBigClass where BigClassID="&CLng(BigClassID),conn,1,1
			If Not(rst.bof And rst.eof) Then response.write rst(0)
			rst.close
			Set rst=nothing
			if SmallClassID<>"" then response.write " &gt;&gt; " & conn.execute("select Smallclassname from NewsSmallClass where smallClassID="&CLng(smallClassID))(0)
		 %> </td>
        </tr>
        <tr> 
          <td height="22" colspan="2" bgcolor="#E3E3E3" class="tdbg"> <p align="center"> 
              【<a href="News_Modify.asp?ArticleID=<%=ArticleID%>">修改信息</a>】&nbsp;【<a href="News_Add.asp?BigClassID=<%=BigClassID%>&SmallClassID=<%=SmallClassID%>">继续添加信息</a>】&nbsp;【<a href="News_Manage.asp">信息管理</a>】&nbsp;【<a href="../NewsMore.asp?<%=ArticleID%>.html" target="_blank">预览信息内容</a>】</p></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<!-- #include file="Inc/Foot.asp" -->
</div>
<%
else
	WriteErrMsg
end if

sub SaveData()
	rs("BigClassID")=BigClassID
	rs("SmallClassID")=SmallClassID
	rs("Title")=Title
	rs("admin")=admin
	rs("Content")=Content
	rs("Hits")=Hits
	rs("tcolor")=color
	if IncludePic="yes" then
		rs("IncludePic")=True
	else
		rs("IncludePic")=False
	end if
	if Passed="yes" then
		rs("Passed")=True
	else
		rs("Passed")=False
	end If
	if Elite="yes" then
		rs("Elite")=True
	else
		rs("Elite")=False
	end if
	rs("UpdateTime")=UpdateTime

	'***************************************
	'删除无用的上传文件
	if  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(lcase(Content),lcase(arrUploadFiles(intTemp)))<=0 and arrUploadFiles(intTemp)<>DefaultPicUrl 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(lcase(Content),lcase(UploadFiles))<=0 and UploadFiles<>DefaultPicUrl 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("DefaultPicUrl")=DefaultPicUrl
	rs("UploadFiles")=UploadFiles
	rs("html")=0

	conn.execute("update NewsBigClass set html=0 where BigClassID=" & CLng(BigClassID) & "")
	conn.execute("update NewsSmallClass set html=0 where SmallClassID=" & CLng(SmallClassID) & "")
end sub

call CloseConn()
%>