<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="../Conn/conn.asp"-->
<!--#include file="../Global/oftenMeasures.asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<link rel="stylesheet" href="../css/indexTwo.css" type="text/css">
<title>网站后台</title>
</head>
<body>
<script type="text/javascript">
function CheckForm()
{
	if(document.form.Title.value=="")
	{
		alert("请输入信息标题！");
		document.form.Title.focus();
		return false;
	}
}
 function getFileExp(str){//文件名,取得文件的扩展名
	var reg=/([^.]+)$/.exec(str);
	return RegExp.$1;
 }
 function doChange(objText, objUrl, objDrop){
 	if (!objDrop) return;
 	var aExt = "gif|jpg|jpeg|bmp|png";//图片扩展名
 	var arr = objText.value.split("|");
 	var vrr = objUrl.value.split("|");
 	var nIndex = objDrop.selectedIndex;

 	aExt=aExt.split("|");
 	objDrop.length=1;
 	for (var i=0; i<arr.length; i++){
 		checbool=false;
 		for(var j=0; j<aExt.length; j++){
			if (getFileExp(vrr[i])==aExt[j]) checbool=true;
		}
 		if (checbool) objDrop.options[objDrop.length] = new Option(arr[i], vrr[i]);
 	}
 	objDrop.selectedIndex = nIndex;
 }

 function doChangePic(objUrl, objDrop){
 	if(objUrl.value=="") objDrop.src="../images/nopic.gif";
 	else objDrop.src="../../"+objUrl.value;
 }
//-->
</script>
<%
NewsID=request("NewsID")
SortID=0
sql="select id,sort,title from TbNews where id="&NewsID
rs.open sql,conn,1,1
if not rs.eof then
	SortID=rs("sort")
	NewsTitle=rs("title")
end if
rs.close
sql="select * from TbNewsSet where id=3"
rs.open sql,conn,1,1
if not rs.eof then
	colorMode=rs("mode")
end if
rs.close

sql="select * from TbNewsSet where id=4"
rs.open sql,conn,1,1
if not rs.eof then
	TopsignMode=rs("mode")
end if
rs.close

sql="select * from TbNewsSet where id=5"
rs.open sql,conn,1,1
if not rs.eof then
	PicMode=rs("mode")
end if
rs.close

sql="select * from TbNewsSet where id=6"
rs.open sql,conn,1,1
if not rs.eof then
	contentMode=rs("mode")
end if
rs.close



dim NewsTexti,NewsFilei,NewsCheckboxi
if request.Form("action")="edit" then
	Title=request.Form("Title")
	NewsTexti=clng(request.Form("NewsTexti"))
	NewsCheckboxi=clng(request.Form("NewsCheckboxi"))
	NewsFilei=clng(request.Form("NewsFilei"))
	input_Color=request.Form("input_Color")
	input_Topsign=request.Form("input_Topsign")
	d_picture=Request.Form("d_picture")
	d_originalfilename=Request.Form("d_originalfilename")
	d_savefilename=Request.Form("d_savefilename")
	d_savepathfilename=Request.Form("d_savepathfilename")
	DownLoadFileiSum=request.Form("DownLoadFileiSum")
	Dim sContent1, i
	For i = 1 To Request.Form("content1").Count 
		sContent1 = sContent1 & Request.Form("content1")(i) 
	Next 
	
	'----------------------------------删除未使用的上传文件-------------------开始----------------------------'
		originalfilename=Split(d_originalfilename, "|")
		savefilename=Split(d_savefilename, "|")
		savepathfilename=Split(d_savepathfilename, "|")
		delednum=0
		for i=0 to UBound(savepathfilename)
			if instr(sContent1&d_picture,savepathfilename(i))=0 then
				if delednum=0 then response.write "<meta http-equiv='Content-Type' content='text/html; charset=gb2312'><link rel='stylesheet' href='../css/indexTwo.css' type='text/css'><b>你上传的以下文件在该文中没有使用，已被系统自动删除：</b><br><br>"
				response.write "“"&savepathfilename(i)&"”　-> 未使用，已删除！<br>"
				call DeleteOneFile(savepathfilename(i))
				delednum=delednum+1
				originalfilename(i)="|":savefilename(i)="|":savepathfilename(i)="|"
			end if
		Next
		d_originalfilename=replace(join(originalfilename,"|"),"||",""):if d_originalfilename="|" then d_originalfilename=""
		d_savefilename=replace(join(savefilename,"|"),"||",""):if d_savefilename="|" then d_savefilename=""
		d_savepathfilename=replace(join(savepathfilename,"|"),"||",""):if d_savepathfilename="|" then d_savepathfilename=""
	'----------------------------------删除未使用的上传文件-------------------结束----------------------------'
	
	
	
	sql="select * from TbNews where id="&NewsID
	rs.open sql,conn,1,3

	rs("title")=Title
	rs("UserID")=session("login_id")
	rs("Color")=input_Color
	if input_Topsign=1 then
		rs("Topsign")=1
	else
		rs("Topsign")=0
	end if	
	rs("Picture")=d_picture
	rs("originalfilename")=d_originalfilename
	rs("savefilename")=d_savefilename
	rs("savepathfilename")=d_savepathfilename
	rs("content")=sContent1
	if DownLoadFileiSum=rs("file") then
	else
		call DeleteOneFile(rs("file"))
		rs("file")=DownLoadFileiSum
	end if
	rs.update
	rs.close
	
	if NewsTexti>0 then
		dim TextPropertyValue()
		dim TextPropertyID()
		redim TextPropertyValue(clng(NewsTexti))
		redim TextPropertyID(clng(NewsTexti))
		for NewsTextii=1 to NewsTexti
			TextPropertyID(NewsTextii)=request.Form("NewsTextID"&NewsTextii)			
			TextPropertyValue(NewsTextii)=request.Form("NewsText"&NewsTextii)
		next
	end if
	
	
	if NewsTexti>0 then
		for NewsTextii=1 to NewsTexti
			sql2="select * from TbNewsValue where NewsID="&NewsID&" and PropertyID="&clng(TextPropertyID(NewsTextii))&""
			rs2.open sql2,conn,1,3
			if not rs2.eof then
				rs2("PropertyValue")=TextPropertyValue(NewsTextii)
				rs2.update
			else
				rs2.addnew
				rs2("NewsID")=NewsID
				rs2("PropertyID")=TextPropertyID(NewsTextii)
				rs2("PropertyValue")=TextPropertyValue(NewsTextii)
				rs2.update
			end if
			rs2.close
		next
	end if
	
	
	if NewsCheckboxi>0 then
		dim NewsCheckboxValue()
		dim NewsCheckboxID()
		redim NewsCheckboxValue(clng(NewsCheckboxi))
		redim NewsCheckboxID(clng(NewsCheckboxi))
		for NewsCheckboxii=1 to NewsCheckboxi
			NewsCheckboxID(NewsCheckboxii)=request.Form("checkbox1ID"&NewsCheckboxii)			
			NewsCheckboxValue(NewsCheckboxii)=request.Form("checkbox1"&NewsCheckboxii)
		next
	end if
	
	
	if NewsCheckboxi>0 then
		for NewsCheckboxii=1 to NewsCheckboxi
			sql2="select * from TbNewsValue where NewsID="&NewsID&" and PropertyID="&clng(NewsCheckboxID(NewsCheckboxii))&""
			rs2.open sql2,conn,1,3
			if not rs2.eof then
				rs2("PropertyValue")=NewsCheckboxValue(NewsCheckboxii)
				rs2.update
			else
				rs2.addnew
				rs2("NewsID")=NewsID
				rs2("PropertyID")=NewsCheckboxID(NewsCheckboxii)
				if NewsCheckboxValue(NewsCheckboxii)=1 then
					rs2("PropertyValue")=1
				else
					rs2("PropertyValue")=0
				end if
				rs2.update
			end if
			rs2.close
		next
	end if
	
	
	if NewsFilei>0 then
		dim NewsFileValue()
		dim NewsFileID()
		redim NewsFileValue(clng(NewsFilei))
		redim NewsFileID(clng(NewsFilei))
		for NewsFileii=1 to NewsFilei
			NewsFileID(NewsFileii)=request.Form("NewsFileiID"&NewsFileii)			
			NewsFileValue(NewsFileii)=request.Form("NewsFilei"&NewsFileii)
		next
	end if
	
	
	if NewsFilei>0 then
		for NewsFileii=1 to NewsFilei
			sql2="select * from TbNewsValue where NewsID="&NewsID&" and PropertyID="&clng(NewsFileID(NewsFileii))&""
			rs2.open sql2,conn,1,3
			if not rs2.eof then
				if rs2("PropertyValue")=NewsFileValue(NewsFileii) then
				else
					call DeleteOneFile(rs2("PropertyValue"))
				end if
				rs2("PropertyValue")=NewsFileValue(NewsFileii)
				rs2.update
			else
				rs2.addnew
				rs2("NewsID")=NewsID
				rs2("PropertyID")=NewsFileID(NewsFileii)
				rs2("PropertyValue")=NewsFileValue(NewsFileii)
				rs2.update
			end if
			rs2.close
		next
	end if
	
	response.write "<script> alert('修改成功');window.document.location.href='News_Edit.asp?NewsID="&NewsID&"';   </script>"
	response.End()	
end if

set rsnews=server.CreateObject("adodb.recordset")
sqlnews="select * from TbNews where id="&clng(NewsID)
rsnews.open sqlnews,conn,1,1
if not rsnews.eof then
%>
<form name="form" method="post" action="?NewsID=<%=NewsID%>" onsubmit="return CheckForm(this);">
<input type="hidden" name="action" value="edit" />
<table width="100%" border="0" cellspacing="1" class="Navi2">
  <tr>
    <th colspan="2"><%=NewsTitle%></th>
    <th><a href="News_List.asp?SortID=<%=SortID%>" class="link2">返回</a></th>
  </tr>
</table>
<table width="100%" border="0" cellspacing="1" class="Navi2">
	<tr>
      <td style="text-align:right;width:150px; padding-right:8px;">新闻标题</td>
	  <td style="text-align:left;padding-left:8px;">
	  <input type="text" name="Title" value="<%=rsnews("title")%>"  maxlength="250" style="width:180px;"/>
	   &nbsp;&nbsp;
	  
	   <%
	   if colorMode=1 then
	   		response.Write("标题颜色")
	   		response.Write("&nbsp;&nbsp;")
	   		response.Write("<select name='input_Color' onChange='this.form.input_Title.focus()'>")
			response.Write("	<OPTION value=''")
			if rsnews("color")="" then response.Write(" selected ")
			response.Write(">默认</OPTION>")
			response.Write("	<OPTION value='#000000' ")
			if rsnews("color")="#000000" then response.Write(" selected ")
			response.Write("style='background-color:#000000'></OPTION>")
			response.Write("	<OPTION value='#FFFFFF' ")
			if rsnews("color")="#FFFFFF" then response.Write(" selected ")
			response.Write("style='background-color:#FFFFFF'></OPTION>")
			response.Write("	<OPTION value='#008000' ")
			if rsnews("color")="#008000" then response.Write(" selected ")
			response.Write("style='background-color:#008000'></OPTION>")
			response.Write("	<OPTION value='#800000' ")
			if rsnews("color")="#800000" then response.Write(" selected ")
			response.Write("style='background-color:#800000'></OPTION>")
			response.Write("	<OPTION value='#808000' ")
			if rsnews("color")="#808000" then response.Write(" selected ")
			response.Write("style='background-color:#808000'></OPTION>")
			response.Write("	<OPTION value='#000080' ")
			if rsnews("color")="#000080" then response.Write(" selected ")
			response.Write("style='background-color:#000080'></OPTION>")
			response.Write("	<OPTION value='#800080' ")
			if rsnews("color")="#800080" then response.Write(" selected ")
			response.Write("style='background-color:#800080'></OPTION>")
			response.Write("	<OPTION value='#808080'") 
			if rsnews("color")="#808080" then response.Write(" selected ")
			response.Write("style='background-color:#808080'></OPTION>")
			response.Write("	<OPTION value='#FFFF00' ")
			if rsnews("color")="#FFFF00" then response.Write(" selected ")
			response.Write("style='background-color:#FFFF00'></OPTION>")
			response.Write("	<OPTION value='#00FF00' ")
			if rsnews("color")="#00FF00" then response.Write(" selected ")
			response.Write("style='background-color:#00FF00'></OPTION>")
			response.Write("	<OPTION value='#00FFFF' ")
			if rsnews("color")="#00FFFF" then response.Write(" selected ")
			response.Write("style='background-color:#00FFFF'></OPTION>")
			response.Write("	<OPTION value='#FF00FF' ")
			if rsnews("color")="#FF00FF" then response.Write(" selected ")
			response.Write("style='background-color:#FF00FF'></OPTION>")
			response.Write("	<OPTION value='#FF0000' ")
			if rsnews("color")="#FF0000" then response.Write(" selected ")
			response.Write("style='background-color:#FF0000'></OPTION>")
			response.Write("	<OPTION value='#0000FF' ")
			if rsnews("color")="#0000FF" then response.Write(" selected ")
			response.Write("style='background-color:#0000FF'></OPTION>")
			response.Write("	<OPTION value='#008080' ")
			if rsnews("color")="#008080" then response.Write(" selected ")
			response.Write("style='background-color:#008080'></OPTION>")
			response.Write("</select>")
	   end if
	   if TopsignMode=1 then
	   		response.Write("&nbsp;&nbsp;")
			response.Write("<input type='checkbox' name='input_Topsign' value='1'")
			if rsnews("Topsign")=1 then response.Write(" checked ")
			response.Write("> 推荐信息")
	   end if
	   %>
     &nbsp;&nbsp;
	  <input type="submit" name="submit" value="提&nbsp;&nbsp;交"  class="btn"/>
	  &nbsp;&nbsp;&nbsp;&nbsp;
	  <input type="reset" name="reset" value="重&nbsp;&nbsp;填" class="btn"/>
	  </td>
    </tr>
	<%if SortID=17 or SortID=18 or SortID=19 then%>
	<tr>
		<td style="text-align:right;width:150px; padding-right:8px;">下载文件</td>
		<td style="text-align:left;padding-left:8px;">
		<%
		response.Write("<input type='text' name='DownLoadFileiSum' value='"&rsnews("file")&"' />")
		response.Write("&nbsp;&nbsp;&nbsp;&nbsp;")
		response.Write("<iframe width=400 height=25 style='background-color:#E1F4EE'")
		response.Write(" name='upload' scrolling='no' src='Upload_file2.asp?sum=Sum' frameborder='0'></iframe>")
		%>
		</td>
	</tr>
	<%
	end if
	NewsTexti=0
	sql="select * from TbNewsProperty where sortId="&clng(SortID)&" and mode=1 order by [order] asc"
	rs.open sql,conn,1,1
	if not rs.eof then
		do while not rs.eof
				NewsTexti=NewsTexti+1
				response.Write("<tr>")
				response.Write("	<td style='text-align:right;width:150px; padding-right:8px;'>")
				response.Write(rs("name"))
				response.Write("	</td>")
				response.Write("	<td style='text-align:left;padding-left:8px;'>")
				response.Write("<input type='hidden' name='NewsTextID"&NewsTexti&"' value='"&rs("id")&"' />")
				response.Write("<input type='text' name='NewsText"&NewsTexti&"' value='")
				
				set rstext=server.CreateObject("adodb.recordset")
				sqltext="select * from TbNewsValue where PropertyID="&rs("id")&" and NewsID="&NewsID&""
				rstext.open sqltext,conn,1,1
				if not rstext.eof then
					response.Write(rstext("PropertyValue"))
				end if
				rstext.close
				set rstext=nothing
				
				
				response.Write("' />")
				response.Write("	</td>")
				response.Write("</tr>")
				
			rs.movenext
		loop
	end if
	rs.close
	response.Write("<input type='hidden' name='NewsTexti' value='"&NewsTexti&"' />")


	NewsCheckboxi=0
	sql="select * from TbNewsProperty where sortId="&clng(SortID)&" and mode=2 order by [order] asc"
	rs.open sql,conn,1,1
	if not rs.eof then
		response.Write("<tr>")
		response.Write("	<td style='text-align:right;width:150px; padding-right:8px;'>")
		response.Write("</td>")
		response.Write("<td style='text-align:left;padding-left:8px;'>")
		do while not rs.eof
			NewsCheckboxi=NewsCheckboxi+1
			response.Write("<input type='hidden' name='checkbox1ID"&NewsCheckboxi&"' value='"&rs("id")&"' />")
			response.Write(rs("name")&"&nbsp;<input type='checkbox' name='checkbox1"&NewsCheckboxi&"' value='1'")
			
			set rscheck=server.CreateObject("adodb.recordset")
			sqlcheck="select * from TbNewsValue where PropertyID="&rs("id")&" and NewsID="&NewsID&""
			rscheck.open sqlcheck,conn,1,1
			if not rscheck.eof then
				if rscheck("PropertyValue")=1 then
					response.Write(" checked ")
				end if
			end if
			rscheck.close
			set rscheck=nothing
			
			
			response.Write(" />&nbsp;&nbsp;&nbsp;")
			
			rs.movenext
		loop
		response.Write("</td>")
		response.Write("</tr>")
	end if
	rs.close
	response.Write("<input type='hidden' name='NewsCheckboxi' value='"&NewsCheckboxi&"'>")
	
	NewsFilei=0
	sql="select * from TbNewsProperty where sortId="&clng(SortID)&" and mode=3 order by [order] asc"
	rs.open sql,conn,1,1
	if not rs.eof then
		do while not rs.eof
			NewsFilei=NewsFilei+1
			response.Write("<tr>")
			response.Write("	<td style='text-align:right;width:150px;padding-right:8px;'>")
			response.Write(rs("name"))
			response.Write("</td>")
			response.Write("<td style='text-align:left;padding-left:8px;'>")
			
			response.Write("<input type='hidden' name='NewsFileiID"&NewsFilei&"' value='"&rs("id")&"' />")
			response.Write("<input type='text' name='NewsFilei"&NewsFilei&"' value='")
			
			set rsfile=server.CreateObject("adodb.recordset")
			sqlfile="select * from TbNewsValue where PropertyID="&rs("id")&" and NewsID="&NewsID&""
			rsfile.open sqlfile,conn,1,1
			if not rsfile.eof then
				response.Write(rsfile("PropertyValue"))
			end if
			rsfile.close
			set rsfile=nothing
			
			
			response.Write("' />")
			response.Write("&nbsp;&nbsp;&nbsp;&nbsp;")
			response.Write("<iframe width=400 height=25 style='background-color:#E1F4EE'")
			response.Write(" name='upload' scrolling='no' src='Upload_file.asp?sum="&NewsFilei&"' frameborder='0'></iframe>")
			response.Write("</td>")
			response.Write("</tr>")
		rs.movenext
		loop
	end if
	rs.close
	response.Write("<input type='hidden' name='NewsFilei' value='"&NewsFilei&"'>")
	if PicMode=1 or SortID=5 or SortID=6 or SortID=7 or SortID=8 then
		response.Write("<tr>")
    	response.Write("	<td style='text-align:right; padding-right:8px;'>")
		response.Write("	封面图片&nbsp;&nbsp;")
		
		response.Write("<img id='showpic' src='")
		if rsnews("Picture")<>"" then
			response.Write("../../"&rsnews("Picture"))
		else
			response.Write("../images/nopic.gif")		
		end if
		response.Write("' height='20' align='absmiddle'>")
		
		response.Write("</td>")
    	response.Write("	<td style='text-align:left; padding-left:8px;'>")
		response.Write("	<select name='d_picture' size=1 onChange='doChangePic(this, showpic)'>")
		response.Write("<option value=''>无图片</option>")
		if rsnews("originalfilename")="" or rsnews("originalfilename")=null then
			
		else
			originalfilename=Split(rsnews("originalfilename"), "|")
			savefilename=Split(rsnews("savefilename"), "|")
			savepathfilename=Split(rsnews("savepathfilename"), "|")
			for i=0 to UBound(originalfilename)
				if savepathfilename(i)=rsnews("Picture") then
					response.Write("<option value='"&savepathfilename(i)&"' selected>"&originalfilename(i)&"</option>")
				else
					response.Write("<option value='"&savepathfilename(i)&"'>"&originalfilename(i)&"</option>")
				end if
			next
		end if
		response.Write("</select>")
		response.Write("	</td>")
  		response.Write("</tr>")
	end if
	if contentMode=1 then
		response.Write("<tr>")
		response.Write("	<td colspan='2'>")
		response.Write("	<input type=hidden name=d_originalfilename value='"&rsnews("originalfilename")&"'>")
		response.Write("	<input type=hidden name=d_savefilename value='"&rsnews("savefilename")&"'>")
		response.Write("	<input type=hidden name=d_savepathfilename value='"&rsnews("savepathfilename")&"' onChange='doChange(this.form.d_originalfilename,this,this.form.d_picture)'>")
		%>
		<input type="hidden" name="content1" value="<%=Server.HtmlEncode(rsnews("Content"))%>" />	
		<%
		response.Write("	<IFRAME ID='addnewedit' SRC='../../bianji/ewebeditor.asp?id=content1&style=s_popup&originalfilename=d_originalfilename&savefilename=d_savefilename&savepathfilename=d_savepathfilename' FRAMEBORDER='0' SCROLLING='no' WIDTH='100%' HEIGHT='400'></IFRAME>	</td>")
  response.Write("</tr>")
	end if
	%>
	
    <tr>
      <td colspan="2">&nbsp;</td>
    </tr>
  </table>
</form>
<%
end if
rsnews.close
set rsnews=nothing
%>
</body>
</html>
<!--#include file="../Conn/conn_close.asp"-->