<!--#include file="down_conn.asp" -->
<!--#include file="inc/const.asp" -->
<%
dim kind,path,classID,NclassID
const dateNum=10         		'列出多少天内的热门文章
const maxLen=10		'主题最多显示字数，字母算一个汉字算两个
const listNum=13			'显示多少个文章标题
const bullet="·"			'标题前的图片或符号
const hitColor="red"		'点击数的颜色
const new_color="red"		'新文章日期的颜色
const old_color="gray"		'旧文章日期的颜色

kind=request.querystring("kind")		'首页调用类型，1表示新文章，2表示热门文章
if kind<=0 or kind>2 then kind=1
ClassID=request.querystring("classid")               '指定首页调用文章分类ID，全部分类不填
if Not IsNumeric(ClassID) then ClassID=""
NclassID=request.querystring("nclassid")
if Not IsNumeric(NClassID) then NClassID=""
Path="http://"&request.servervariables("server_name")&replace(request.servervariables("script_name"),"js.asp","")
dim rs,sql,str,str1,topicLen,topic


function gotTopic(str,strlen)
	dim l,t,c, i
	l=len(str)
	t=0
	for i=1 to l
	c=Abs(Asc(Mid(str,i,1)))
	if c>255 then
	t=t+2
	else
	t=t+1
	end if
	if t>=strlen then
	gotTopic=left(str,i)&"..."
	exit for
	else
	gotTopic=str
	end if
	next
end function

set rs=server.createObject("Adodb.recordset")
sql="select top "&listNum&" download.*,Dnclass.nclass from Dnclass inner join download on Dnclass.nclassid=download.nclassid"

if NclassID<>"" then
	sql=sql&" where download.NclassID="&NclassID
elseif classID<>"" then
	sql=sql&" where download.classID="&classID
end if

if kind=2 then
	if nclassid="" and classID="" then
		sql=sql&" where"
	else
		sql=sql&" and"
	end if
end if

select case kind
	case "1" sql=sql&" order by download.dateandtime desc, download.id desc"
	case "2" sql=sql&" DATEDIFF('d',download.dateandtime,Now())<="&dateNum&" order by download.hits desc,download.showname"
end select

rs.open sql,conndown,1,1
if rs.bof and rs.eof then 
str=str+"没有符合条件的下载"
else

rs.movefirst
do while not rs.eof
	topic=gotTopic(rs("showname"),maxLen)
	topic=replace(server.HTMLencode(topic)," ","&nbsp;")
	topic=replace(topic,"'","&nbsp;")
	str=str+bullet &"<a href='"&Path&"list.asp?id="+Cstr(rs("id"))+"' target='_blank'  title='["& rs("nclass") &"]"& replace(replace(server.HTMLencode(rs("showname"))," ","&nbsp;"),"'","&nbsp;")&"&nbsp;&nbsp;共下载"& rs("hits") &"次') >"+Topic+"</a> ("
	
	str=str & "<font color="
	if rs("dateandtime")>=date then
		str=str & new_color
 	else
		str=str & old_color
	end if
	str=str &">" & Month(rs("DateAndTime"))&"月"&Day(rs("DateAndTime"))&"日</font></font>)<br>"

	rs.moveNext
loop
end if

response.write "document.write ('" & str & "');"
rs.close
conndown.close
%>