<!--#include file="conn.asp"-->
<!--#include file="inc/function.asp"-->
<%
dim id,rs,sql,title,sclass,Content,upfile,addurl,classLink,ansNum,viewNum,AskTime,AskUser,allansUser,askid,niming,nimings
dim comNum,i,addedcont,addedtime,bcnAns,qstate,tp,tpmax,sumtp,xShang
dim temp,ansStr,tpStr,tpcount
Dim tpansuser,zctp,fdtp
id=Trim(Request.QueryString("id"))
tp=Trim(Request.QueryString("tp"))
if Not IsNumeric(id) then Response.Redirect("/")
if clng(id)>0 then

Dim AskD,bodymenu, tpmeun, bestmenu, ansmenu
Set AskD = Server.CreateObject("KwAsk.FunAsk")
	opendb
	set AskD.myConn =conn
	AskD.myPredb =predb
	AskD.Getsetting()	
	siteinfo=AskD.siteinfo
	setting=AskD.setting

	AskD.GetTemplate("T-ask.html")
	bodymenu=AskD.bodymenu
	tpmeun=AskD.tpmeun
	bestmenu=AskD.bestmenu
	ansmenu=AskD.ansmenu
	
  '问题
  conn.execute("update "&predb&"ask set viewNum=viewNum+1 where askid="&Id)
  
  set rs = Server.CreateObject("adodb.recordset")
  sql="select * from "&predb&"ask where ispass=1 and askid="&Id
  rs.open sql,conn,1,3
  if rs.bof and rs.eof then
    Response.Redirect("/")
  else
  
    IF setting(27)*24-DateDiff("h",rs("AskTime"),now)<=0 and rs("state")=0 Then
	   rs("state")=2
	   rs.update
	   Call AskD.Score(rs("askuser"),-clng(setting(22)),"问题过期未处理")
	End IF
	
    askid=rs("askid")
    title=rs("title")
	Content=AskD.ReplaceKeyLink(rs("Content"))
	sclass=rs("sclass")
	upfile=rs("upfile")&""
	addurl=rs("addurl")&""
	xShang=rs("xShang")
	ansNum=rs("ansNum")
	AskTime=rs("AskTime")
	viewNum=rs("viewNum")
	AskUser=rs("AskUser")
	addedcont=rs("addedcont")
	addedtime=rs("addedtime")
	comNum=rs("comNum")
	allansUser=rs("AnsUser")&","
	tpmax=rs("tpmax")
	sumtp=rs("sumtp")
	qstate=rs("state")
	bcnAns=rs("bcnAns")
	nimings=rs("niming")
	
    If sumtp=0 Then sumtp=1 
  end if
  rs.close
  set rs=nothing

'导航
classLink=AskD.PostList(sclass)


'投票
IF qstate=4 then
	set rs = Server.CreateObject("adodb.recordset")
	sql="select ansuser,tpnum,zctp,fdtp,userid from "&predb&"ans a inner join "&predb&"user b on a.ansuser=b.id where a.istp=1 and a.askid="&askid
	rs.open sql,conn,1,1
	  tpcount=rs.recordcount
	if tpcount>1 then
	  do while not rs.eof
		  temp=RexHtml(tpmeun)
		  temp=RexHtml_IF(temp)
		  tpStr=tpStr&temp
	  rs.movenext
	  loop
	  tpmeun=tpStr
	else
	  tpmeun=""
	  tpansuser=rs("ansuser")
	  zctp=rs("zctp")
	  fdtp=rs("fdtp")
	end if
	rs.close
	set rs=nothing
Else
  tpmeun=""
End IF


'最佳答案
dim anscontent,star,stars
if bcnAns>0 then
   set rs=conn.execute("select * from "&predb&"ans where ansid="&bcnAns)
    anscontent=AskD.ReplaceKeyLink(rs("anscontent"))
	star=rs("star")
	niming=rs("niming")
   select case star
   case 0
      stars=""
   case 1
      stars="☆"
   case 2
      stars="☆☆"
   case 3
      stars="☆☆☆"
   case 4
      stars="☆☆☆☆"
   case 5
      stars="☆☆☆☆☆"
   end select
   
	bestmenu=RexHtml(bestmenu)
	bestmenu=RexHtml_IF(bestmenu)
   set rs=nothing
else
   bestmenu=""
end if

'其他回答
set rs=conn.execute("select * from "&predb&"ans where iscn=0 and askid="&askid)
do while not rs.eof
i=i+1
     anscontent=AskD.ReplaceKeyLink(rs("anscontent"))
	 niming=rs("niming")
     temp=RexHtml(ansmenu)
	 temp=RexHtml_IF(temp)
	 ansStr=ansStr&temp
rs.movenext
loop
set rs=nothing
ansmenu=ansStr

'全部
    niming=nimings
	bodymenu=RexHtml(bodymenu)
	bodymenu=RexHtml_IF(bodymenu)
	Response.Write(bodymenu)
set AskD.myConn =Nothing
closedb
Set AskD = Nothing

End IF

Function UserInfo(uid)	
Dim str,rs,userid,face,score,gradename,GradeType
IF niMing=1 Then
		str=""
		str=str&"<div class=""asks-l"">"&vbcrlf
		str=str&"<ul>"&vbcrlf
		str=str&"<li><img width=""50"" height=""50"" src="""&siteInfo(1)&"UploadFile/Face/info.gif"" alt=""""/></li>"&vbcrlf
		str=str&"<li>匿名用户</li>"&vbcrlf
		str=str&"</ul>"&vbcrlf
		UserInfo=str&"</div>"&vbcrlf
Else
	set rs=conn.execute("select Userid,face,gradetype,score from "&predb&"user where id="&uid)
	if rs.bof and rs.eof then
	
		str=""
		str=str&"<div class=""asks-l"">"&vbcrlf
		str=str&"<ul>"&vbcrlf
		str=str&"<li><img width=""50"" height=""50"" src="""&siteInfo(1)&"UploadFile/Face/info.gif"" alt=""""/></li>"&vbcrlf
		str=str&"<li>用户已删除</li>"&vbcrlf
		str=str&"</ul>"&vbcrlf
		UserInfo=str&"</div>"&vbcrlf
	   set rs=nothing
	else
		userid=rs("Userid")
		face=rs("face")
		GradeType=rs("gradetype")
		score=rs("score")
		if isnull(face) or face="" then face="Face/info.gif"
		set rs=nothing
	
		if gradetype=0 then
		set rs=conn.execute("select gradename from ("&predb&"UserGrade a inner join "&predb&"UserGradeType b on b.id=a.GradeTypeId) inner join "&predb&"Score c on c.grade=a.grade where b.isDefault=1 and tscore>="&score&"")
		else
		set rs=conn.execute("select gradename from ("&predb&"UserGrade a inner join "&predb&"UserGradeType b on b.id=a.GradeTypeId) inner join "&predb&"Score c on c.grade=a.grade where b.id="&gradetype&" and tscore>="&score&"")
		end if
		if rs.bof and rs.eof then
		    gradename="超级"
		else
			gradename=rs(0)
		end if
		set rs=nothing
		
		str=""
		str=str&"<div class=""asks-l"">"&vbcrlf
		str=str&"<ul>"&vbcrlf
		str=str&"<li><img width=""50"" height=""50"" src="""&siteInfo(1)&"UploadFile/"&face&""" alt=""""/></li>"&vbcrlf
		str=str&"<li><a href=""user/userinfo.asp?id="&uid&""">"&Userid&"</a></li>"&vbcrlf
		str=str&"<li>["&gradename&"]</li>"&vbcrlf
		str=str&"</ul>"&vbcrlf
		UserInfo=str&"</div>"&vbcrlf
	end if
End IF
End Function
%>
