<!--#include File="../../inc/conn.asp"-->
<%
If app_gbook = 0 Then writeE "评论关闭中"

dim action
action = be("get", "action")

Select Case action
	Case "save": save
	Case "glist" : glist
	Case "list" : list
	Case "tongji" : tongji
	Case Else: main
End Select
dispseObj()
    
Sub save()
	dim g_id,g_vid,g_audit,g_name,g_content,g_time,g_ip,verifycode,checkscode
	g_vid = be("all", "g_vid"): g_vid = chkSql(g_vid, True)
    g_name = be("all", "g_name") : g_content = be("all", "g_content")
    verifycode = be("all","verifycode")
    
    if not isN(g_vid) then
    	If Not isNum(g_vid) Then writeA "1": Exit Sub
    else
    	g_vid=0
    end if
    
    checkscode = Session("code_gbook")
    if checkscode = "" then checkscode = getCookie("code_gbook")
    
    if isN(g_name) or isN(g_content) then writeA "1": Exit Sub
    If app_gbookverify=1 And checkscode <> verifycode Then writeA "2": Exit Sub
    If getTimeSpan("lastgbookTime") < app_gbooktime Then writeA "3": Exit Sub
    
    g_name = badFilter(g_name) : g_name = chkSql(g_name, True)
    g_content = badFilter(g_content) : g_content = chkSql(g_content, True)
    g_ip = getIP()
    g_time = Now()
    if app_gbookaudit=1 then g_audit=0 else g_audit=1
	if len(g_name) >64 then g_name = left(g_name,64)
	if len(g_content) >255 then g_content = left(g_content,255)
	
	objdb.add "{pre}gbook", Array("g_vid","g_audit","g_name", "g_ip", "g_time", "g_content"), Array(g_vid, g_audit, g_name, g_ip, g_time, g_content)
	Session("lastgbookTime") = Now
    writeA "0"
End Sub

Sub tongji()
	dim count1,count2
	count1 = objdb.db("select count(*) from {pre}gbook","exe")(0)
	count2 = objdb.db("select count(*) from {pre}gbook where g_audit=1","exe")(0)
	writeA "["&count1&","&count2&"]"
End Sub

Sub main()
	dim g_vid,g_vname
	g_vid = be("get", "id") : g_vid = chkSql(g_vid, True)
	g_vname = be("get", "name") : g_vname = chkSql(g_vname, True)
	if not isN(g_vid) then
		if isN(g_vname) then writeA "err": Exit Sub
		If Not isNum(g_vid) Then writeA "err": Exit Sub
	end if
	
%>
<iframe width="100%" height="1" frameborder="0" marginheight="0" marginwidth="0" scrolling="yes" src="<%=app_installdir%>plus/gbook/?action=list&id=<%=g_vid%>&name=<%=g_vname%>" id="mac_gbook" name="mac_gbook"></iframe>
<%
End Sub

Sub list()
	dim g_vid,g_vname,g_name
	g_vid = be("get", "id") : g_vid = chkSql(g_vid, True)
	g_vname = be("get", "name") : g_vname = chkSql(g_vname, True)
	if not isN(g_vid) then
		if not isN(g_name) then writeA "err": Exit Sub
		If Not isNum(g_vid) Then writeA "err": Exit Sub
	end if
	If isN(session("username")) then g_name = "游客" else g_name = session("username")
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>留言本</title>
<link type="text/css" rel="stylesheet" href="images/style.css" />
<script type="text/javascript" src="../../js/jquery.js"></script>
</head>
<body>
<script>
var maccms_path = "<%=app_installdir%>";
var gbookverify = "<%=app_gbookverify%>";
var g_vid = "<%=g_vid%>";
var g_vname = "<%=g_vname%>";
var g_name = "<%=g_name%>";
function reinitIframe()
{
	try{
	var main = $(window.parent.document).find("#mac_gbook");
	var thisheight = $(document).height() ;
	main.height(thisheight);
	}catch (ex){}
}
$(document).ready(function(){
	window.setInterval("reinitIframe()", 200);
});
</script>
<script type="text/javascript" src="gbook.js"></script>
</body>
</html>
<%
End Sub

Sub glist
	dim g_id,g_vid,g_audit,g_name,g_content,g_reply,g_time,g_replytime,g_ip,tmpIpArr
	dim page,sql,rs,rs1,replystr,i,total,p,bgcolorArr,bgstr,span,j
	page = be("all","page")
	if not isNum(page) then page=1 else page=cint(page)
	
	sql = "SELECT g_id,g_vid,g_audit,g_name,g_content,g_reply,g_time,g_replytime,g_ip from {pre}gbook WHERE g_audit=1 ORDER BY g_id DESC"
    bgcolorArr=Array("#D66203","#513DBD","#784E1A","#C55200","#DA6912","#537752","#C58200","#519DBD","#D60103","#531752")
	Set rs = objdb.DB(sql, "rs1")
	i = 0
	If rs.Bof And rs.EOF Then
		writeA "<center><h3> 暂无留言，快来抢沙发吧！</h3></center>"
	Else
		rs.pagesize = app_gbooknum
		total = rs.pagecount
		p = rs.recordcount
		
		If page > total Then
			page = total
		Else
			rs.absolutePage = page
		End If
		Do While Not rs.EOF
			i = i + 1
			
			if i > app_gbooknum then exit do
			
			g_id = rs("g_id")
			g_audit = rs("g_audit")
			g_name = rs("g_name")
			g_content = rs("g_content")
			g_content = regReplace(g_content, "\[em:(\d{1,})?\]", "<img src=""../../images/face/$1.gif"" border=0/>")
			g_reply = rs("g_reply")
			g_time = rs("g_time")
			g_replytime = rs("g_replytime")
			g_ip = rs("g_ip")
			If Not isN(g_ip) Then
				tmpIpArr = Split(g_ip, ".")
				g_ip = tmpIpArr(0) & "." & tmpIpArr(1) & "." & tmpIpArr(2) & ".*"
			End If
			
			replystr = ""
			bgstr = bgcolorArr(getRndNum(1))
			
			if not isN(g_reply) then
				replystr = "<div class=""citation""><p class=""content"">站长回复："&g_reply&"</p></div>"
			end if
			span=""
			if len(g_name) <4 then
				for j=len(g_name) to 4
					span = span&"&nbsp;&nbsp;"
				next
			end if
			
			writeA "<div class=""dt""><span class=""author""><span class=""name"" style=""background-color:"&bgstr&";"">"&g_name&span&"</span><span class=""address"">IP:["&g_ip&"]</span></span><span class=""post-time"">发表于:["&g_time&"]</span><div class=""clear""><br/></div></div><div class=""dd""><p class=""content"">"&g_content&"</p>"&replystr&"<div class=""toolbar"" id=""toolbar-"&g_id&"""></div></div>"
            rs.movenext
        Loop
        objdb.C (rs)
        
        writeA "<div class=""pages"">" & getPageInfo(total, page ) & "</div>"
	End If
End Sub
    
Function getPageInfo(totalPage, absolutePage)
        Dim pgStr, has1, has2, begin, endnum, i
        has1 = absolutePage - 5 >= 1
        has2 = absolutePage + 5 <= totalPage
        begin = 1: endnum = 1
        
        If has1 And has2 Then
          begin = absolutePage - 4
          endnum = absolutePage + 5
        ElseIf Not has1 And has2 Then
          begin = 1
          If totalPage >= 10 Then endnum = 10 Else endnum = totalPage
        ElseIf has1 And Not has2 Then
          begin = totalPage - 9
          If begin < 1 Then begin = 1
          endnum = totalPage
        Else
          begin = 1
          endnum = totalPage
        End If
        
        pgStr = "共" & totalPage & "页&nbsp;"
        If absolutePage > 1 Then
            pgStr = pgStr & "<a href='javascript:' p='1' title='首页'>首页</a>"
        End If
        
        If absolutePage > 1 Then
            pgStr = pgStr & " <a href='javascript:' p='" & (absolutePage - 1) & "' title='上一页'>上一页</a>"
        End If
        
        For i = begin To endnum
            If i <> absolutePage Then
                pgStr = pgStr & " <a href='javascript:' p='" & i & "'"  & ">" & i & "</a>"
            Else
                pgStr = pgStr & " <span class=""active""" & ">" & i & "</span>"
            End If
        Next
        
        If absolutePage < totalPage Then
            pgStr = pgStr & " <a href='javascript:' p='" & (absolutePage + 1) & "' title='下一页'>下一页</a>"
            pgStr = pgStr & " <a href='javascript:' p='" & (totalPage) & "' title='尾页'>尾页</a>"
        End If
        getPageInfo = pgStr
    End Function
%>