<%
function getSourceOption(currentid,tablename)
dim ifselect,rs,sql
sql="select id,Title from "&tablename&" order by id asc"
Set rs = conn.Execute(sql)
if rs.eof or rs.bof then
	getSourceOption="<option value=""0"">暂时没有</option>"&Chr(13)
else
	getSourceOption="<option value=""0"">=请选择=</option>"&Chr(13)
end if
while not rs.eof
	if(Clng(rs(0))=Clng(currentid)) then
		ifselect=" selected"
	else
		ifselect=""
	end if
	getSourceOption=getSourceOption&"<option value="""&rs(0)&""" "&ifselect&">"&rs(1)&"</option>"&Chr(13)
	rs.movenext
wend
rs.close
set rs=nothing
end function

Sub	SaveTextFile(f_savepath,f_content)   
  Dim st   
  Set st=Server.CreateObject("ADODB.Stream")   
  st.Type=2   
  st.Mode=3   
  st.Charset="gb2312"   
  st.Open()   
  st.WriteText   f_content
  st.SaveToFile  f_savepath,2   
  st.Close()   
  Set   st=Nothing   
End   Sub
 
function ReadFromTextFile (f_savepath)
 dim str
 set stm=server.CreateObject("adodb.stream")
 stm.Type=2 '以本模式读取
 stm.mode=3 
 stm.charset="gb2312"
 stm.open
 stm.loadfromfile f_savepath
 str=stm.readtext
 stm.Close
 set stm=nothing
 ReadFromTextFile=str
end function

function GetWendaHot(n)
	dim str
	set rs=conn.execute("select top "&n&" id,UserId,Title,[Status],PubDate,Hits from t_wenda where IsCheck=1 order by Hits desc,id desc")
	while not rs.eof
		str=str&"<li><a href=""/wd/show/"&rs(0)&".html"">"&rs(2)&"</a></li>"
		rs.movenext
	wend
	rs.close
	set rs=nothing
	GetWendaHot=str
end function

function GetWendaCatalog
	dim str
	set rs=conn.execute("select id,title from t_wenda_catalog order by id asc")
	while not rs.eof
		str=str&"<li><a href=""/wd/list.asp?id="&rs(0)&""">"&rs(1)&"</a></li>"
		rs.movenext
	wend
	rs.close
	set rs=nothing
	GetWendaCatalog=str
end function

function GetBestAnswer(id)
	dim str
	set rs=conn.execute("select UserId,Content,PubIp,PubDate from t_reply where AskId="&id&" and IsAnswer=1")
	if not rs.eof then
		str=str&"<div class=""c"">"		
		str=str&rs(1)
		str=str&"</div>"
		str=str&"<div class=""user"">回答者："&rs(0)&"</div>"
	end if
	rs.close
	set rs=nothing
	GetBestAnswer=str
end function



function SetShowHtm(id)
	dim ask_template
	dim a_cid,a_title,a_content,a_userid,a_hits,a_pubdate,a_pubip,a_status,ctitle
	if id>0 then
		set rs=server.CreateObject("adodb.recordset")
		rs.open "select * from t_wenda where id="&id,conn,3,1
		if not rs.eof then
			a_cid=rs("CatalogId")
			a_userid=rs("UserId")
			a_title=rs("Title")
			a_content=rs("Content")
			a_status=rs("Status")
			a_pubip=rs("PubIp")
			a_pubdate=rs("PubDate")
			a_hits=rs("Hits")			
		end if
	end if
	rs.close
	set rs=nothing
	if(a_cid>0) then
		set rs=conn.execute("select Title from t_wenda_catalog where id="&a_cid)
		if not rs.eof then
			ctitle=rs(0)
		end if
		rs.close
		set rs=nothing
	end if
	ask_template=ReadFromTextFile(server.MapPath("/templet/wenda_show.htm"))
	ask_template=replace(ask_template,"$Head$",ReadFromTextFile(server.MapPath("/templet/head.htm")))
	ask_template=replace(ask_template,"$Nav$",ReadFromTextFile(server.MapPath("/wd/nav.asp")))
	ask_template=replace(ask_template,"$Root$",ReadFromTextFile(server.MapPath("/templet/root.htm")))
	ask_template=replace(ask_template,"$title$",a_title)
	ask_template=replace(ask_template,"$category_title$",ctitle)
	ask_template=replace(ask_template,"$category_id$",a_cid)
	ask_template=replace(ask_template,"$ask_catalogs$",GetWendaCatalog())
	ask_template=replace(ask_template,"$pubdate$",a_pubdate)
	ask_template=replace(ask_template,"$asker$",a_userid)
	ask_template=replace(ask_template,"$content$",a_content)
	ask_template=replace(ask_template,"$best_answer$",GetBestAnswer(id))
	ask_template=replace(ask_template,"$join_num$",conn.execute("select count(*) from t_reply where AskId="&id)(0))
	ask_template=replace(ask_template,"$answer_list$",GetAnswerList(id))
	ask_template=replace(ask_template,"$id$",id)
	ask_template=replace(ask_template,"$ask_options$",getSourceOption(0,"t_wenda_catalog"))
	ask_template=replace(ask_template,"$ask_hots$",GetWendaHot(10))
	if(a_status=1) then
		ask_template=replace(ask_template,"$ask_status$","<img src=""/wd/images/icon6.gif"" width=""18"" height=""18"" alt="" "" /> 解决")
	else
		ask_template=replace(ask_template,"$ask_status$","<img src=""/wd/images/icon1.gif"" width=""18"" height=""18"" alt="" "" /> 等待解决")
	end if
	call SaveTextFile(server.MapPath("/wd/show/"&id&".html"),ask_template)
end function
%>

