<!--#include file="../inc/conn.asp"-->

<%
response.Charset="GBK"
Dim action,Gb_user,Gb_content,Gb_intro,Gb_id,Gb_code,Page,GbPage
Dim admin,pws,pageall

admin = app_gbuser
pws = app_gbpass

action = SafeData("R","action",0)
Gb_id = SafeData("R","gb_id",0)
if not isN(Gb_id) then Gb_id = clng(Gb_id)
Page = SafeData("R","page",0)
if isN(Page) then Page = 1 else Page = clng(Page)

select case action
case "addsave"
	call addsave
case "del"
	call del
case "login"
	call login
case "regb"
	call regb
case "delregb"
	call delregb
case "checklogin"
	call checklogin
case "loginout"
	call loginout
Case Else
	call main
end select

sub login
	dim admin2,pws2
	admin2 = SafeData("R","admin",0)
	pws2 = SafeData("R","pws",0)
	If admin="" Then
	   Response.Write "请填写管理员."
	   Exit sub
	End If
	If pws="" Then
	   Response.Write "请填写密码."
	   Exit sub
	End If
	if admin2=admin And pws2=pws then
		session("admin")="superman"&admin
		Response.Write "登陆成功."
	Else
		Response.Write "管理员或密码不正确."
	end if
end sub

sub checklogin
	if session("admin")<>"superman"&admin Then
		Response.Write "1"
	Else
		Response.Write "2"
	end if
end sub

sub loginout
	session("admin")=""
end sub

sub addsave
	Gb_user = SafeData("RF","gb_user",0)
	Gb_content = SafeData("RF","gb_content",0)
	Gb_code = SafeData("RF","gb_code",0)
	
	If Gb_code = "" Then
	    Response.Write "err1"
	ElseIf Gb_code <> Request.cookies("verifycode") Then
        Response.Write "err2"
	ElseIf GetTimeSpan("lasttime") < 30 Then 
        Response.Write "wait"
	Else
        'response.write Gb_user & "," & Gb_content & "," & Gb_code
		Dim result : result = DataBase.AddRecord("Tbl_Book",Array("B_Name:"&Gb_user, "B_LeaveWord:"&Gb_content,"B_LeaveWordTime:"&now(),"B_IP:"&getip()))
		Response.Write "ok"		
	    session("lasttime")=Now()
	End If
end sub

sub del
	If session("admin")="superman"&admin then
	 	Dim result : result = Database.DeleteRecord("Tbl_Book", "B_ID:" & Gb_id)   
	end if
	Response.Write"ok"
end sub	

sub regb
	dim Gb_intro
    Gb_intro=SafeData("R","gb_intro",0)
	If session("admin")="superman"&admin then
	 Dim result : result = DataBase.UpdateRecord("Tbl_Book","B_ID = "& Gb_id ,Array("B_Reply:"&Gb_intro))   
	end if
	Response.Write"ok"
end sub

sub delregb
	If session("admin")="superman"&admin then
	 Dim result : result = DataBase.UpdateRecord("Tbl_Book","B_ID = "& Gb_id ,Array("B_Reply:"))   
	end if
	Response.Write"ok"						
end sub

sub main
	dim rs,sql,rscount,i
	Set rs = Server.CreateObject("adodb.recordset")
	sql="select * from Tbl_Book order by b_id desc"
	rs.Open sql, Conn, 1, 1
	If Not(rs.bof And rs.eof) Then
	    rs.pagesize=10 '每页数量
		pageall=rs.pagecount   '总页数
		
	    rscount=rs.recordcount '总记录数
		If page>rs.PageCount Then page=rs.PageCount
		rs.absolutepage=page
		For i=1 to rs.pagesize
            Response.Write("<ul><li class='gb_user'>访客:"&rs("B_Name")&"</li>")
			Response.Write("<li class='gb_lastdate'>"&rs("B_LeaveWordTime")&"</li>")
			Response.Write("<li class='gb_content'>"&rs("B_LeaveWord")&"</li>")
			If rs("B_Reply")<>"" Then
				Response.Write("<li class='gb_intro'>"&rs("B_Reply")&"</li>")
			Else
				Response.Write("<li class='gb_intro' style='display:none' id='"&rs("B_ID")&"'></li>")
			End If
			
			If session("admin")="superman"&admin then 
			    Response.Write("<li class='gb_admin'>")

			    If rs("B_Reply")<>"" Then
				Response.Write("<a href=""javascript:"" class='delregb' onclick=""GbookList("&rs("B_ID")&","&page&",'delregb');"">删除回复</a> ")
				Else
				Response.Write("<a href=""javascript:"" class='regb' onclick=""ReGbook("&rs("B_ID")&","&page&");"">回复</a> ")
				End If				
				Response.Write("<a href=""javascript:"" class='del' onclick=""GbookList("&rs("B_ID")&","&page&",'del');"">删除</a> ")
				Response.Write("</li>")
			End If
			Response.Write("</ul>")	
		    rs.movenext
		    If rs.eof Then Exit For
		Next
		Call GbookPage
	Else
		Response.Write("暂时没有访客留言")
	End If
	rs.close
	Set rs=nothing
	
end sub


Sub GbookPage
    Dim m,x,y:x=page-5:y=page+5:if x<1 then x=1
	if y>pageall then y=pageall
	response.Write "<script language=""javascript"" src="""&app_installdir&"gbook/ajax.js""></script>"
	response.Write "<script language=""javascript"" src="""&app_installdir&"gbook/gbook.js""></script>"
    Response.Write "<div class=""gb_page"">"&chr(10)
	Response.Write "共"&pageall&"页 <a href=""javascript:void(0);"" onclick=""getGbook(1);return false;"" >首页</a> <a href=""javascript:void(0);"" onclick=""getGbook("&page-1&");return false;"">前一页</a>"
	For m=x to y
		If page=m Then Response.Write" <font color=""#FF0000"">"&m&"</font>" Else Response.Write " <a href=""javascript:void(0);"" onclick=""getGbook("&m&");return false;"">"&m&"</a>"
	Next
	Response.Write " <a onclick=""getGbook("&page+1&");"" href=""javascript:void(0);"">下一页</a> <a onclick=""getGbook("&pageall&")"" href=""javascript:void(0);"">尾页</a>"
	Response.Write "</div>"
End Sub

%>