<!-- #include file="conn.asp" -->
<!-- #include file="cls_main.asp" -->
<!-- #include file="cls_Mesky_showPage.asp" -->
<% 
	dim Mesky,Keyword
	Dim FobWords,Fi
	IF Request("keyword") = "" then 
		Response.Write("搜索关键字不能为空！")
		Response.End()
	Else
		Set Mesky = New cls_main
		Keyword = Mesky.checkStr(Trim(Request("Keyword")))
		'搜索过滤字
		FobWords = Array(91,92,304,305,430,431,437,438,12460,12461,12462,12463,12464,12465,12466,12467,12468,12469,12470,12471,12472,12473,12474,12475,12476,12477,12478,12479,12480,12481,12482,12483,12485,12486,12487,12488,12489,12490,12496,12497,12498,12499,12500,12501,12502,12503,12504,12505,12506,12507,12508,12509,12510,12532,12533,65339,65340)
		For Fi = 1 to Ubound(FobWords,1)
			If InStr(keyword,ChrW(FobWords(Fi))) > 0 Then
				Response.Write("搜索关键字中包含非法字符！")
				Set Mesky = Nothing
				Response.End
				Exit For				
			End If
		Next
		FobWords = Array("~","!","@","#","$","%","^","&","*","(",")","_","+","=","`","[","]","{","}",";",":","""","'",",","<",">",".","/","\","|","?","_","about","1","2","3","4","5","6","7","8","9","0","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","after","all","also","an","and","another","any","are","as","at","be","because","been","before","being","between","both","but","by","came","can","come","could","did","do","each","for","from","get","got","had","has","have","he","her","here","him","himself","his","how","if","in","into","is","it","like","make","many","me","might","more","most","much","must","my","never","now","of","on","only","or","other","our","out","over","said","same","see","should","since","some","still","such","take","than","that","the","their","them","then","there","these","they","this","those","through","to","too","under","up","very","was","way","we","well","were","what","where","which","while","who","with","would","you","your","的","一","不","在","人","有","是","为","以","于","上","他","而","后","之","来","及","了","因","下","可","到","由","这","与","也","此","但","并","个","其","已","无","小","我","们","起","最","再","今","去","好","只","又","或","很","亦","某","把","那","你","乃","它")
		keyword = Left(keyword,100)
		keyword = Replace(keyword,"!"," ")
		keyword = Replace(keyword,"]"," ")
		keyword = Replace(keyword,"["," ")
		keyword = Replace(keyword,")"," ")
		keyword = Replace(keyword,"("," ")
		keyword = Replace(keyword,"　"," ")
		keyword = Replace(keyword,"-"," ")
		keyword = Replace(keyword,"/"," ")
		keyword = Replace(keyword,"+"," ")
		keyword = Replace(keyword,"="," ")
		keyword = Replace(keyword,","," ")
		keyword = Replace(keyword,"'"," ")
		For Fi = 0 To Ubound(FobWords,1)
			If keyword=FobWords(Fi) Then
				Response.Write("搜索关键字中包含非法字符！")
				Set Mesky = Nothing
				Response.End
				Exit For				
			End IF
		Next
		'If Not IsObject(Conn) Then ConnectionDatabase
		call Mesky.LoadSetting()
		dim arrPage,arrMainPage,sRs
		arrPage = Split(Mesky.ReadStylePage("Style_Cms_Search"),"<!--|||-->")
		arrMainPage = Split(Mesky.ReadStylePage("Style_Cms_Main"),"<!--|||-->")
		Call Main()
		Set Mesky = Nothing
	End IF


Sub Main()
	Response.Write(Replace(arrMainPage(0),"{$page_title}","下载搜索"))
	Response.Write(arrMainPage(1))
	Response.Write(arrMainPage(2))

		Call ViewSearchList()
	Response.Write(arrMainPage(4))
End Sub

Sub ViewSearchList()
    If Mesky.ChkPost = False Then
        Mesky.strMsg = "非法操作，不要从外部提交数据。"
        Call Mesky.SystemMsg
        Exit Sub
    End If
Dim Rs,showPageRs,sql,i,sColumn,sKeyword,q,sCatalog,iPage,currentPage
If Trim(Request.QueryString("Page")) = "" Then
    currentPage = 1
Else
    currentPage = Trim(Request.QueryString("Page"))
End If
sColumn = "ID,rootID,catalogID,catalogName,Title,DateAndTime,Hits,Excerpt,writer"

	Select Case Request("sType")
	Case "title"
		sKeyword = " (" & Mesky.translate(keyword,"title") & ")"		
		q="&action=s&sType=title&catalog="&Request("catalog")&"&keyword="&Server.URLEncode(keyword)
	Case "content"
		sKeyword = " (" & Mesky.translate(keyword,"Excerpt") & ")"
		q="&action=s&sType=content&catalog="&Request("catalog")&"&keyword="&Server.URLEncode(keyword)
	Case "UserName"
		sKeyword = " UserName = '"&Keyword&"'"
		q="&action=s&sType=UserName&catalog="&Request("catalog")&"&keyword="&Server.URLEncode(keyword)
	End Select
	
		If Request("catalog") <> "" Then
			if split(Request("catalog"),",")(2) = 0 Then
				sCatalog = sKeyword & " and RootID = " & split(Request("catalog"),",")(0)
			Else
				sCatalog = sKeyword & " and Depth>="&split(Request("catalog"),",")(2)&" and RootID = " & split(Request("catalog"),",")(0)
			End If
		Else
			sCatalog = sKeyword & ""
		End If
Set showPageRs= New cls_Mesky_showPage
	'.Conn=ConnStr		'得到数据库连接对象
	If IsSqlDataBase = 1 Then
		showPageRs.DbType = "MSSQL_SP"
	Else
		showPageRs.DbType = "AC"
	End If
	showPageRs.RecSql=0
	showPageRs.RecTerm=1
	showPageRs.CookieName="search"&keyword
	showPageRs.Order=1
	showPageRs.PageSize=30
	showPageRs.currentPage = currentPage
	showPageRs.Sql=sColumn&"$Mesky_Cms_Resource$"&sCatalog&"$Hits Desc$Hits"
	
	
dim iRecCount,sqlRs,no,result_info,s
iRecCount = showPageRs.RecCount
'Rs=showPageRs.ResultSet()
If Trim(Request.QueryString("Page"))="" or Trim(Request.QueryString("Page"))="1" then
	iPage = 1
Else
	iPage = clng(Trim(Request.QueryString("Page")))*Mesky.setting(83)+1-Mesky.setting(83)
End If
if iRecCount < 30 then
	no = iRecCount	
Elseif (iPage+29)>iRecCount then
	no = iRecCount
Else
	no = iPage+29
end if
result_info = "<font color=red>"&iRecCount&"</font> 个结果已找到，<font color=red>"&iPage&"-"&no&" 显示如下。排序依据受资源人气。" 
Response.Write(Replace(arrPage(0),"{$result_info}",result_info))
'Response.Write(arrPage(1))

If iRecCount < 1 then
	Response.Write(arrPage(1))
Else
	no = iPage
	Rs=showPageRs.ResultSet    '返回ResultSet
	'sColumn = "ID,rootID,catalogID,catalogName,Title,DateAndTime,Hits,Excerpt,writer"
	For i=0 To Ubound(Rs,2)			
	s = arrPage(2)
	s = Replace(s,"{$no}",no)
	s = Replace(s,"{$catalogurl}","../"&Replace(Replace(Mesky.setting(73),"{$id}",Rs(2,i)),"{$pages}","1"))
	s = Replace(s,"{$catalogname}",Rs(3,i))
	s = Replace(s,"{$articleurl}", Replace(Mesky.Setting(101), "{$id}", ID))
	s = Replace(s,"{$title}",Rs(4,i))
	s = Replace(s,"{$excerpt}",Rs(7,i))
	s = Replace(s,"{$dateandtime}",Mesky.FormatMyDate(Rs(5,i),"{Y}-{m}-{d}"))
	s = Replace(s,"{$hits}",Rs(6,i))
	s = Replace(s,"{$writer}",Rs(8,i))
	Response.Write(s)
	no = int(no) +1
	Next
End If
	'Set sqlRs = nothing

Response.Write(Replace(arrPage(3),"{$showpage}",showPageRs.ShowPage("?Page={$pages}"&q)))
Rs=NULL
showPageRs=NULL
Set showPageRs=NoThing
End Sub

'================================================================
' 上下页部分
'================================================================
Public Function ShowPage(FileName,totalRecord,Mesky_PageSize,Mesky_CurrentPage)
	Const Btn_First = "<font face=""webdings"" color=red Title=""First Page"">9</font>" '定义第一页按钮显示样式
	Const Btn_Prev = "<font face=""webdings"" color=red Title=""Prev Page"">3</font>"   '定义前一页按钮显示样式
	Const Btn_Next = "<font face=""webdings"" color=red Title=""Next Page"">4</font>"   '定义下一页按钮显示样式
	Const Btn_Last = "<font face=""webdings"" color=red Title=""Last Page"">:</font>"   '定义最后一页按钮显示样式
	Const BtnNum_Count = 6      '定义最多显示多少页分页
	Const Btn_more = ".."   '定义更多按钮
	Dim sPageInfo, totalPage
	Dim showNumBtn  '数字导航
	Dim showFirstPrev   '首页、前一页
	Dim showNextLast    '下一页、末页
	If (totalRecord Mod Mesky_PageSize) = 0 Then
		totalPage = totalRecord \ Mesky_PageSize
	Else
		totalPage = totalRecord \ Mesky_PageSize + 1
	End If
	sPageInfo = "页次:<b><font color=red>" & Mesky_CurrentPage & "</font></b>/" & totalPage & " 每页:<font color=red>" & Mesky_PageSize & "</font> 共计:<font color=red>" & totalRecord & "</font>"
	
	'数字导航
	Dim i, str_tmp
	Dim start_p, end_p
	Dim Str_start, str_end
	If totalPage < BtnNum_Count Then
		For i = 1 To totalPage
			If i = Mesky_CurrentPage Then
				str_tmp = str_tmp & "<b><font color=red>" & i & "</font></b> "
			Else
				str_tmp = str_tmp & "[<a href=" & Replace(FileName, "{$pages}", i) & ">" & i & "</a>] "
			End If
		Next
	Else
		If Mesky_CurrentPage <= BtnNum_Count Then
			start_p = 1
			end_p = BtnNum_Count
			Str_start = ""
			str_end = "<a href=" & Replace(FileName, "{$pages}", end_p + 1) & ">" & Btn_more & "</a> "
		ElseIf Mesky_CurrentPage > (totalPage \ BtnNum_Count) * BtnNum_Count Then
			start_p = (totalPage \ BtnNum_Count) * BtnNum_Count + 1
			end_p = totalPage
			Str_start = "<a href=" & Replace(FileName, "{$pages}", start_p - 1) & ">" & Btn_more & "</a> "
			str_end = ""
		Else
			If (Mesky_CurrentPage Mod BtnNum_Count) = 0 Then
				start_p = Mesky_CurrentPage - BtnNum_Count + 1
				end_p = Mesky_CurrentPage
			Else
				start_p = (Mesky_CurrentPage \ BtnNum_Count) * BtnNum_Count + 1
				end_p = (Mesky_CurrentPage \ BtnNum_Count) * BtnNum_Count + BtnNum_Count
			End If
			Str_start = "<a href=" & Replace(FileName, "{$pages}", start_p - 1) & " >" & Btn_more & "</a> "
			str_end = "<a href=" & Replace(FileName, "{$pages}", end_p + 1) & ">" & Btn_more & "</a> "
		End If
		For i = start_p To end_p
			If i = Mesky_CurrentPage Then
				str_tmp = str_tmp & "<b><font color=red>" & i & "</font></b> "
			Else
				str_tmp = str_tmp & "[<a href=" & Replace(FileName, "{$pages}", i) & ">" & i & "</a>] "
			End If
		Next
			str_tmp = Str_start & str_tmp & str_end
	End If
	showNumBtn = str_tmp
	i = Empty: str_tmp = Empty
	start_p = Empty: end_p = Empty
	Str_start = Empty: str_end = Empty
	'首页、前一页
	If Mesky_CurrentPage = 1 Then
		showFirstPrev = Btn_First & " " & Btn_Prev & " "
	Else
		showFirstPrev = "<a href=" & Replace(FileName, "{$pages}", "1") & ">" & Btn_First & "</a> <a href=" & Replace(FileName, "{$pages}", Mesky_CurrentPage - 1) & "> " & Btn_Prev & "</a> "
	End If
	'下一页、末页
	If Mesky_CurrentPage >= totalPage Then
		showNextLast = Btn_Next & " " & Btn_Last & " "
	Else
		showNextLast = "<a href=" & Replace(FileName, "{$pages}", Mesky_CurrentPage + 1) & ">" & Btn_Next & "</a> <a href=" & Replace(FileName, "{$pages}", totalPage) & ">" & Btn_Last & "</a> "
	End If

	ShowPage = ShowPage & "<table width=""100%"" border=""0"" style=""BORDER-COLLAPSE: collapse"" borderColor=""#111111"">" & vbCrLf
	ShowPage = ShowPage & "<form onsubmit=""window.location=this.goto.options[this.goto.selectedIndex].value; return false;"">" & vbCrLf
	ShowPage = ShowPage & "  <tr>" & vbCrLf
	ShowPage = ShowPage & "    <td style=""font-family: Verdana,宋体; font-size: 12px; line-height: 15px"">" & sPageInfo & "</td>" & vbCrLf
	ShowPage = ShowPage & "    <td align=""right"" style=""font-family: Verdana,宋体; font-size: 12px; line-height: 15px"">" & showFirstPrev & showNumBtn & showNextLast & "" & vbCrLf
	ShowPage = ShowPage & " <Script Language=""JavaScript"">" & vbCrLf
	ShowPage = ShowPage & " document.write (""Go:<select name=\""select\"" onchange=\""javascript:window.location.href=this.options[this.selectedIndex].value\"">"");" & vbCrLf
	ShowPage = ShowPage & " var url=""" & FileName & """;" & vbCrLf
	ShowPage = ShowPage & " for(var iPage = 1; iPage < " & totalPage & "+1; iPage++)  {" & vbCrLf
	ShowPage = ShowPage & " document.write (""<option value=\""""+url.replace(""{$pages}"",iPage)+""\"""");" & vbCrLf
	ShowPage = ShowPage & "     if (iPage == " & Mesky_CurrentPage & ")" & vbCrLf
	ShowPage = ShowPage & "     document.write ("" selected"");" & vbCrLf
	ShowPage = ShowPage & "     else" & vbCrLf
	ShowPage = ShowPage & "     document.write ("""");" & vbCrLf
	ShowPage = ShowPage & " document.write ("">第""+iPage+""页</option>"");" & vbCrLf
	ShowPage = ShowPage & " }" & vbCrLf
	ShowPage = ShowPage & " document.write (""</select>"")" & vbCrLf
	ShowPage = ShowPage & " </Script>" & vbCrLf
	ShowPage = ShowPage & " </td>" & vbCrLf
	ShowPage = ShowPage & "  </tr>" & vbCrLf
	ShowPage = ShowPage & "  </form>" & vbCrLf
	ShowPage = ShowPage & "</table> " & vbCrLf
End Function
%>
