<!--#include file="conn.asp"-->
<!--#include file="inc/function.asp"-->
<%
response.addheader "Content-Encoding","GB2312"
Dim ID
ID=Trim(Request.QueryString("id"))
opendb
CALL GetOutCode(ID)
closedb

Sub GetOutCode(sID)
IF not isnumeric(sID) Then Exit Sub
Dim rs,Ftime,HttpRe,i,passUrl,isp
	Set rs=conn.execute("Select passUrl,Ftime from "&predb&"OutCode where id="&sid)
		IF not(rs.bof and rs.eof) Then
		    passUrl=rs("passUrl")
		    IF passUrl<>"" Then
			   HttpRe=Request.ServerVariables("SERVER_NAME")
			   IF instr(passUrl,vbcrlf)=0 Then
			      IF instr(HttpRe,passUrl)=0 Then Exit Sub
			   Else
			      passUrl=split(passUrl,vbcrlf)
				  Isp=False
				  For i=0 To uBound(passUrl)
				      IF instr(HttpRe,passUrl(i))>0 Then Isp=True:Exit For
				  Next
				  IF Isp=False Then Exit Sub
			   End IF
			End IF
		    IF not isnumeric(rs("Ftime")) or rs("Ftime")=0 Then Ftime=600 Else Ftime=rs("Ftime")
			IF isarray(application("OutCode"&sid))=false Then
			   Call ClsOutCode(sID)
			Else
			   IF DateDiff("s",application("OutCode"&sID)(0),now())>Ftime Then Call ClsOutCode(sID)
			End IF
			Response.Write("document.write('"&application("OutCode"&sID)(1)&"')")
		End IF
	Set rs=nothing
End Sub

Sub ClsOutCode(Cid)
Dim rs,rs1,ClassId,FormS,passUrl,Ftime,TopNum,ClassTitle,AskTitle,sqla,Targert,DateTime,xshang,str,Cachevalue(1),classn,classstr,p

Dim AskD
Set AskD = Server.CreateObject("KwAsk.FunAsk")
	set AskD.myConn =conn
	AskD.myPredb =predb
	AskD.Getsetting()
	siteinfo=AskD.siteinfo
	setting=AskD.setting
	set AskD.myConn =Nothing

   set rs=conn.execute("select * from "&predb&"outcode where id="&Cid)
   if rs.bof and rs.eof then
   Response.Write("暂无该调用")
   else
   ClassId=rs("ClassId")
   FormS=rs("FormS")
   passUrl=rs("passUrl")
   Ftime=rs("Ftime")
   end if
   set rs=nothing
   FormS=split(FormS,"|")
   
	select case FormS(1)
	  case "1"
		 sqla=" and state=0"
	  case "2"
		 sqla=" and xShang>=50"
	  case "3"
		 sqla=" and state=4"
	  case "4"
		 sqla=" and ansNum=0"
	  case "5"
		 sqla=" and(state=1 or state=5  or state=6  or state=7)"
	  case "6"
		 sqla=" and isStrong=1"
	end select
   
   IF FormS(5)>0 Then TopNum=" Top "&FormS(5)&" "
   
   IF ClassId="0" Then
      set rs=conn.execute("select "&TopNum&"* from "&predb&"ask a inner join "&predb&"class b on a.sclass=b.ClassId Where ispass=1"&sqla&" order by askid desc")
   Else 
      IF instr(ClassId,",")>0 Then
	     Classn=Split(ClassID,", ")
		 For p=0 To ubound(Classn)
		   ClassStr=ClassStr&" or ','+b.ParentStr+',' like '%,"&Classn(p)&",%' "
		 Next
	  Else
	       ClassStr=ClassStr&" or ','+b.ParentStr+',' like '%,"&ClassID&",%' "
	  End IF
      set rs=conn.execute("select "&TopNum&"* from "&predb&"ask a inner join "&predb&"class b on a.sclass=b.ClassId where ispass=1 and (b.classid in("&ClassId&")"&ClassStr&")"&sqla&" order by askid desc")
   End IF
   if rs.bof and rs.eof then
   str="分类下暂无问答"
   else
   do while not rs.eof
   IF FormS(3)>0 Then ClassTitle=AskD.LeftStr(rs("classname"),FormS(3))
   IF FormS(4)>0 Then AskTitle=AskD.LeftStr(rs("Title"),FormS(4)) 
   IF FormS(14)="1" Then Targert=" target=""_blank"" "
   
     str=str&"<div class=""OutCodeS"">"
   If FormS(6)="1" Then
      str=str&"<div class=""s6"">[<a href="""&siteInfo(0)&siteInfo(1)&""
    IF setting(34)=0 Then
	str=str&"List.asp?classid="&rs("CLassID")
	Else
	str=str&"List-"&rs("CLassID")&".html"
	End IF
	str=str&""""&Targert&">"&ClassTitle&"</a>]</div>"
   End IF
      str=str&"<div class=""st""><a href="""&siteInfo(0)&siteInfo(1)&""
  IF setting(34)=0 Then
  str=str&"ask.asp?id="&rs("askid")&""
  Else
  str=str&"ask-"&rs("askid")&".html"
  End IF
  str=str&""""&Targert&">"&AskTitle&"</a></div>"
   If FormS(7)="1" Then
      str=str&"<div class=""s7"">"
      set rs1=conn.execute("select userid from "&predb&"user where id="&rs("askuser"))
	  str=str&"<a href="""&siteInfo(0)&siteInfo(1)&"user/userinfo.asp?id="&rs("askuser")&""""&Targert&">"&rs1("userid")&"</a>"
	  set rs1=nothing
	  str=str&"</div>"
   End If
   If FormS(8)="1" Then
	   Select Case FormS(15)
		  Case "1"
			 DateTime=FormatDateTime(rs("asktime"),vbshortdate)
		  Case "2"
			 DateTime=Right("0"&month(rs("asktime")),2)&"/"&Right("0"&day(rs("asktime")),2)
		  Case "3"
			 DateTime=year(rs("asktime"))&"年"&month(rs("asktime"))&"月"&day(rs("asktime"))&"日"
		  Case "4"
			 DateTime=month(rs("asktime"))&"月"&day(rs("asktime"))&"日"
	   End Select
	   str=str&"<div class=""s8"">"&DateTime&"</div>"
    End If
	If FormS(9)="1" Then
	   str=str&"<div class=""s9"">"&rs("viewNum")&"</div>"
	End If
	If FormS(10)="1" Then
	   str=str&"<div class=""s10"">"&rs("state")&"</div>"
	End If
	If FormS(11)="1" Then
	   str=str&"<div class=""s11"">"&rs("comNum")&"</div>"
	End If
	If FormS(12)="1" Then
	   str=str&"<div class=""s12"">"&rs("ansNum")&"</div>"
	End If
	If FormS(13)="1" Then
	   IF FormS(16)="0" Then xshang=rs("xShang") Else xshang="<img src="""&siteInfo(0)&siteInfo(1)&"TempLate/"&siteInfo(11)&"/images/money.gif"" alt=""""> "&rs("xShang")
	   str=str&"<div class=""s13"">"&xshang&"</div>"
	End If
	str=str&"</div>"
   rs.movenext
   loop
   end if
   set rs=nothing 
   Cachevalue(0)=now()
   Cachevalue(1)=str
	application.Lock()
	application("OutCode"&Cid)=Cachevalue
	application.UnLock()
Set AskD = Nothing
End Sub
%>