<!--#include file="admin_start.asp"-->

<%
dim id
dim ids
dim n_ids

id=request("id")
ids=request("ids")
ids=replace(ids," ","")
n_ids=""

Set fso = CreateObject("Scripting.FileSystemObject")

if not MySys.check.isInteger(id) and request("action")="edit" then
MySys.error.info="请选择您要操作的项目！"
MySys.error.location="back"
MySys.error.err()
end if

select case request("action")
case "delete"

	if ids="" then
		MySys.error.info="请选择你要删除的新闻！"
		MySys.error.location="back"
		MySys.error.err()
	end if		

	set rs_t=conn.execute("select news_id from jins_news_list where news_id in ("&ids&") ")
	do while not rs_t.eof
		if fso.FolderExists(server.mappath("../NEWSPIC/"&rs_t("news_id"))) then fso.deletefolder server.mappath("../NEWSPIC/"&rs_t("news_id")),true
	rs_t.movenext
	loop

	conn.execute("delete from jins_news_list where news_id in ("&ids&") ")
	
	session("FB_EM_1_SQL_uppath")=""

	MySys.error.info="删除新闻成功！"
	MySys.error.location="back"
	MySys.error.suc()
	
case else

	if request("action")="add" then
	    sql="select * from jins_news_list "
	else
	    sql="select * from jins_news_list where news_id="&id&" "
	end if
	
	rs.open sql,conn,1,3
	
	'/////////////////////////////////////////////检测
	
	if request("action")="add" then
	    rs.addnew
		MySys.error.info="新闻添加成功！"
	    MySys.error.location="admin/admin_info_news_list.asp?order_name=news_addtime&order_action=desc&s_n=6,sort_id,0&sort_id="&request("sort_id")
	else
		MySys.error.info="新闻编辑成功！"
	    MySys.error.location="back"
	end if

	if request("action")="edit" and rs.eof then
		MySys.error.info="您选择的新闻不存在！"
		MySys.error.location="back"
		MySys.error.err()
	end if
	
	if conn.execute("select sort_id from jins_news_sort where sort_id="&request("sort_id")&" ").eof and request("sort_id")>0  then
		MySys.error.info="您选择的新闻分类不存在！"
		MySys.error.location="back"
		MySys.error.err()
	end if

	if request("sort_id")="" or request("news_title")="" or request("news_writer")=""  then 	
		MySys.error.info="请完整填写相关项目！"
		MySys.error.location="back"
		MySys.error.err()
	end if
	
	'/////普通项
	rs("sort_id")=int(request("sort_id"))
	if request("news_title")<>"" then rs("news_title")=trim(request("news_title"))
	if request("news_open")<>"" then rs("news_open")=int(request("news_open"))	
	if request("news_summary")<>"" then rs("news_summary")=trim(request("news_summary"))
	if request("news_content")<>"" then rs("news_content")=trim(request("news_content"))
	if request("news_writer")<>"" then rs("news_writer")=trim(request("news_writer"))	
	if request("news_addtime")<>"" then rs("news_addtime")=trim(request("news_addtime")) else rs("news_addtime")=now
	rs("news_clicknum")=request("news_clicknum")
	
	rs.update
	
	if request("action")="add" then
	
		if fso.folderExists(server.mappath("../NEWSPIC/$_TEMP_$")) then
			fso.copyfolder server.mappath("../NEWSPIC/$_TEMP_$"),server.mappath("../NEWSPIC/"&rs("news_id"))
			fso.deletefolder server.mappath("../NEWSPIC/$_TEMP_$"),true
			fso.createfolder server.mappath("../NEWSPIC/$_TEMP_$")
		end if
		
	    if rs("news_content")<>"" then rs("news_content")=replace(rs("news_content"),"NEWSPIC/$_TEMP_$","NEWSPIC/"&rs("news_id"))
					
	    rs.update
		
	end if
	
	rs.close	
	
	session("FB_EM_1_SQL_uppath")=""

	MySys.error.suc()

	'/////////////////////////////////////////////
end select
Set fso = nothing

%>
<!--#include file="admin_end.asp"-->
