<!--#include file="down_conn.asp"-->
<!-- #include file="inc/const.asp" -->
<!--#include file="down_function.asp"-->
<%
dim founerr,FoundErr,filename,filename1,filename2,filename3,filename4,showname,classid,Nclassid,note,hot,system
dim size1,fromurl,order,daydown,softsx,utime,piclink,addu,hots,hide,localdown,guding,downshow2
dim rs1,sql1,mess,makejs,add,edit,Errmsg
Dvbbs.LoadTemplates("index")
Dvbbs.Stats="<a href=down_default.asp>下载中心</a>-保存信息"
Dvbbs.Nav()'输出头
Dvbbs.Head_var 2,0,Dvbbs.Stats,""
if not Dvbbs.founduser then
errmsg=errmsg+"<br>"+"<li>您没有进入下载中心管理的权限，请<a href=login.asp>登陆</a>或者同管理员联系。"

elseif (flagdown<=0 or flagdown="" or flagdown>4 or addflag=0) and not dvbbs.master then
errmsg=errmsg+"<br>"+"<li>您没有添加软件的权限，请<a href=login.asp>登陆</a>或者同管理员联系。"

end if
	founderr=false
	if trim(request.form("txtshowname"))="" then
  		founderr=true
  		errmsg=errmsg+"<li>显示名称不能为空</li><br><br>"
	end if
	if trim(request.form("txtfilename"))="" and trim(request.form("txtfilename1"))="" and trim(request.form("txtfilename2"))="" then
  		founderr=true
  		errmsg=errmsg+ "<li>前3个下载连接地址不能全为空</li><br><br>"
	end if
	if trim(request.form("Content"))="" then
  		founderr=true
  		errmsg=errmsg+ "<li>软件简介不能为空</li><br><br>"
	end if
	if trim(request.form("Classid"))="" then
  		founderr=true
  		errmsg=errmsg+ "<li>软件大分类不能为空</li>"
	end if
	if trim(request.form("NClassid"))="" then
  		founderr=true
  errmsg=errmsg+ "<li>软件小分类不能为空</li>"
	end if
	if request.form("daydown")="" then
	founderr=true
  	errmsg=errmsg+ "<li>当日下载次数限制不能为空！</li>"
	else
  		if not isnumeric(request.form("daydown")) then
  		founderr=true
  		errmsg=errmsg+ "<li>当日下载次数限制只能填整数！</li>"
		end if
	end if
	if founderr=false then
		filename=request("txtfilename")
		filename1=request("txtfilename1")
		filename2=request("txtfilename2")
		filename3=request("txtfilename3")
		filename4=request("txtfilename4")
		showname=dvbbs.htmlencode(request("txtshowname"))
		classid=request("classid")
		Nclassid=request("Nclassid")
		note=dvbbs.Checkstr(trim(request("Content")))
		hot=dvbbs.htmlencode(request("hot"))
		system=dvbbs.htmlencode(request("system"))
		size1=dvbbs.htmlencode(request("size1"))
		fromurl=dvbbs.htmlencode(request("fromurl"))
		order=dvbbs.htmlencode(request("order"))
		downshow2=request("downshow")
		daydown=request("daydown")
		softsx=request("softsx")
		utime=request("usetime")
		piclink=request("pic")
		addu=Dvbbs.membername
		if request.form("hots")="on" then
			hots=1
		else
			hots=0
		end if
                 
              if request.form("guding")="1" then
			guding=1
		else
			guding=0
		end if
		if request.form("hide")="on" then
			hide=1
		else
			hide=0
		end if
		
	set rs=server.createobject("adodb.recordset")
	if request("action")="add" then
		call newsoft()
	elseif request("action")="edit" then
		call editsoft()
	end if
sub newsoft()

	sql="select * from download where (id is null)" 
	rs.open sql,conndown,1,3
	rs.addnew
        if filename<>"" then
	rs("filename")=filename&"#"&request("ldown1")
        end if
	if filename1<>"" then
	rs("filename1")=filename1&"#"&request("ldown2")
	end if
	if filename2<>"" then
	rs("filename2")=filename2&"#"&request("ldown3")
	end if
       if filename3<>"" then
	rs("filename3")=filename3&"#"&request("ldown4")
	end if
	if filename4<>"" then
	rs("filename4")=filename4&"#"&request("ldown5")
	end if
	rs("showname")=showname
	rs("downshow")=downshow2
                         if request("money")<>"" and downshow2=5 then
	rs("point")=request("money")
	end if
           if request("tieshu")<>"" and downshow2=7 then
	rs("tieshu")=request("tieshu")
	end if
	rs("classid")=classid
	rs("Nclassid")=Nclassid
	rs("fromurl")=fromurl
	rs("note")=note
	rs("system")=system
	rs("hot")=hot
	rs("hots")=hots
	rs("stop")=hide
	rs("size")=size1
	rs("softsx")=softsx
	rs("daydown")=daydown
	rs("orders")=order
        rs("gudin")=guding
	rs("lasthits")=date()
        rs("dateandtime")=date()
	rs("dayhits")=0
	rs("weekhits")=0
	rs("hits")=0
	rs("usetime")=utime
	if piclink<>"" then
	rs("pic")=piclink
	end if
       
	rs("adduser")=addu
	rs("ldown")=0
	rs.update
	set rs1=server.createobject("adodb.recordset")
	sql1="select * from events"
	rs1.open sql1,conndown,1,3
	mess=""&Dvbbs.membername&"添加了《"&showname&"》"	
	rs1.addnew
	rs1("event")=mess
	rs1("addtime")=date()
	rs1.update
	rs1.close
end sub
sub editsoft()

	sql="select * from download where id="&request("id")
	rs.open sql,conndown,1,3
        if filename<>"" then
	rs("filename")=filename&"#"&request("ldown1")
        else
	rs("filename")=NULL
        end if
	if filename1<>"" then
	rs("filename1")=filename1&"#"&request("ldown2")
	else
	rs("filename1")=NULL
	end if
	if filename2<>"" then
	rs("filename2")=filename2&"#"&request("ldown3")
	else
	rs("filename2")=NULL
	end if
		if filename3<>"" then
	rs("filename3")=filename3&"#"&request("ldown4")
	else
	rs("filename3")=NULL
	end if
		if filename4<>"" then
	rs("filename4")=filename4&"#"&request("ldown5")
	else
	rs("filename4")=NULL
	end if
	
	rs("daydown")=daydown
	rs("showname")=showname
	rs("classid")=classid
	rs("softsx")=softsx
	rs("Nclassid")=Nclassid
	rs("downshow")=downshow2
                 if request("money")<>"" and downshow2=5 then
	rs("point")=request("money")
	end if
           if request("tieshu")<>"" and downshow2=7 then
	rs("tieshu")=request("tieshu")
	end if
	rs("fromurl")=fromurl
	rs("note")=note
	rs("system")=system
	rs("gudin")=guding
	rs("hots")=hots
	rs("stop")=hide	
	rs("orders")=order
	
	rs("usetime")=utime
	
	if piclink<>"" then
	rs("pic")=piclink
	else
	rs("pic")=NULL
	end if
	rs("ldown")=localdown
	rs("size")=size1
	rs("dateandtime")=date()
	rs.update
	set rs1=server.createobject("adodb.recordset")
	sql1="select * from events"
	rs1.open sql1,conndown,1,3
	mess=""&Dvbbs.membername&"修改了《"&showname&"》"	
	rs1.addnew
	rs1("event")=mess
	rs1("addtime")=date()
	rs1.update
	rs1.close

end sub

	if makejs=1 then
		UpdateJs(news)
	end if
	set rs=nothing
	
%>

<table class="tableborder1" cellspacing=1 width="<%= Dvbbs.mainsetting(0) %>" align=center>
  <tr>
    <th width="100%" height="25"><p align="center"><font color="#FFFFFF"><b>
<%if request("action")="add" then%>添加<%else%>修改<%end if%>程序成功</b></font></td>
  </tr>
  <tr>
    <td width="100%" class=tablebody1>     
    <p align="center"><br><br>
    显示名称为：<%=showname%><br>
    下载1：<%=filename%><br>
    下载2：<%=filename1%><br>
    下载3：<%=filename2%><br>
    下载4：<%=filename3%><br>
    下载5：<%=filename4%><br>
    </p> 
    </td>
  </tr>
  </table>

<%
dim id,rsid
if request("id")="" then
set rsid=conndown.execute("select top 1 * from download order by id desc")
id =rsid("id")
else
id =request("id")
end if

response.write"<SCRIPT language=JavaScript>alert('添加成功，进入该下载页面');"
response.write"this.location.href='down_list.asp?id="&id&"';</SCRIPT>"
else%>
<table class="tableborder1" cellspacing=1 width="<%= Dvbbs.mainsetting(0) %>" align=center>
  <tr>
    <th width="100%" height="25"><p align="center"><font color="#FFFFFF"><b>
<%if request("action")=add then%>添加<%else%>修改<%end if%>程序失败</b></font></td>
  </tr>
<tr>
    <td width="100%" class=tablebody1 align="center"><br>  <%
 response.write "由于以下的原因不能保存数据：<br><br>"
 response.write errmsg
%>
<a href="#" onclick=window.history.back()><font color=red>返回上页</font></a><br><br>
 </td>
  </tr>
  </table>
  <%
  end if
Dvbbs.ActiveOnline	
Dvbbs.footer()
%>

