<%
'*******************************
'公用函数文件
'程序编写:chenht
'时间:2006-11-18
'*******************************
const fso="Scripting.FileSystemObject"
'文件夹生成函数
Public Function makefolder(Folder,fso)'Folder必须包含路径在内,fso是Scripting.FileSystemObject组件名称
  myFolder = Server.MapPath(Folder)
  Set fileStreamObj = CreateObject(fso)
  If fileStreamObj.FolderExists(myFolder) = False Then
     fileStreamObj.CreateFolder (myFolder)
  End If
End Function
'删除文件函数
Public Function DelFile(FileName,fso)'FileName必须包含路径在内
  mypicFile = Server.MapPath(FileName)
  Set fso = CreateObject(fso)
  If fso.FileExists(mypicFile) = True Then
     fso.DeleteFile(mypicFile)
  end if
  Set fso = nothing
End Function
'生成文件函数
Public Function makehtml(htmlurlname,fso,nl)'htmlurlname必须包含路径在内,nl为要写入的内容
  Const ForReading = 1
  Const Forwriting = 2
  Const ForAppending = 8
  myFile = Server.MapPath(htmlurlname)
  Set fileStreamObj = CreateObject(fso)
  fileStreamObj.CreateTextFile(myFile)
  set textStream = fileStreamObj.OpenTextFile(myFile,ForWriting,False)
  textStream.Write(nl)
  textStream.Close()
End Function
'功能：取目录大小 /形参：目录名 /返回值：成功为目录大小，失败为-1
Function GetFolderSize(FolderName,fso) 
  Dim f
  myFolder = Server.MapPath(FolderName)
  Set fso = CreateObject(fso)
  If fso.FolderExists(myFolder) = True Then 
     Set f = fso.GetFolder(myFolder) 
     GetFolderSize = f.Size 
  Else 
     GetFolderSize = -1 
  End if 
End Function
'清除字符串中的html代码,主要作用是截取字符串时不会出现html代码
Function ClearHTMLCode(StrCode) 
  dim str 
  set str = new RegExp 
  str.Pattern = "<[^>]*>" 
  str.Global = true 
  ClearHTMLCode = str.Replace(StrCode, "") 
End Function
'数字导航分页显示rspagecount为记录页数userid为用户ID号
Function pagination(pagecount,userid)
       Dim wzpage,wzpagecount,pagenum
       If Len(Request.QueryString("page"))<>0 Then
          wzpage = clng(Request.QueryString("page"))
         Else 
          wzpage =1
       End If
       If wzpage <= 0 Then wzpage =1
       pagenum = (wzpage \ 10)*10+1
       If wzpage mod 10 = 0 Then pagenum = (wzpage \ 10)*10-9
       If wzpage > 10 Then
            Response.Write ("<font face=""webdings"">")
            Response.Write ("<a href=""?page=1&userid="&userid&""" title=""首页"">9</a> ")
            Response.Write ("<a href=""?page="& pagenum-1 &"&userid="&userid&""" title=""前十页"">7</a> ")
            Response.Write ("</font>")
       End If
       For pagenum = pagenum To pagenum + 9
           If pagenum = wzpage Then
                  Response.Write ("<font color=""#ff0000"">")
                  Response.Write (" ["& pagenum &"] ")
                  Response.Write ("</font>")
           Else
                  Response.Write (" <a href=""?page="& pagenum &"&userid="&userid&""">")
                  Response.Write ("["& pagenum &"]")
                  Response.Write ("</a> ")
           End If
           If pagenum >= pagecount Then Exit For
       Next

	 If wzpage <= (pagecount - (pagecount mod 10)) Then
            Response.Write ("<font face=""webdings"">")
            Response.Write ("<a href=""?page="& pagenum &"&userid="&userid&"""  title=""后十页"">8</a> ")
            Response.Write ("<a href=""?page="& pagecount &"&userid="&userid&"""  title=""末页"">:</a> ")
            Response.Write ("</font>")
     End If
End Function
'搜索分页函数
Function SearchPage(pagecount,tyname1,tyvalue1,tyname2,tyvalue2)
       Dim wzpage,wzpagecount,pagenum
       If Len(Request.QueryString("page"))<>0 Then
          wzpage = clng(Request.QueryString("page"))
         Else 
          wzpage =1
       End If
       If wzpage <= 0 Then wzpage =1
       pagenum = (wzpage \ 10)*10+1
       If wzpage mod 10 = 0 Then pagenum = (wzpage \ 10)*10-9
	        Response.Write ("<table border=""0"" cellspacing=""0"" cellpadding=""0""><tr>"& vbCrLf)
            Response.Write ("<td width=""2""></td><td class=""intd"" title=""主题数"">&nbsp;"& wzcount &"&nbsp;</td>"& vbCrLf)
	        Response.Write ("<td width=""2""></td><td class=""intd"" title=""当前页/总页数"">&nbsp;"&wzpage&"/"& pagecount &"&nbsp;</td>"& vbCrLf)
	        Response.Write ("<td width=""2""></td><td class=""intd"" title=""每页主题数"">&nbsp;"& wzrep &"&nbsp;></td>"& vbCrLf)
       If wzpage > 10 Then
            Response.Write ("<td class=""outtd""><a href=""?page=1&"&tyname1&"="&tyvalue1&"&"&tyname2&"="&tyvalue2&""" title=""首页""><img src=""images/first.gif"" border=""0""></a></td><td width=""2""></td>"& vbCrLf)
            Response.Write ("<td class=""outtd""><a href=""?page="& pagenum-1 &"&"&tyname1&"="&tyvalue1&"&"&tyname2&"="&tyvalue2&""" title=""前十页""><img src=""images/previous.gif"" border=""0""></a></td>"& vbCrLf)
       End If
       For pagenum = pagenum To pagenum + 9
           If pagenum = wzpage Then
		       Response.Write ("<td width=""2""></td><td class=""intd"" title=""当前页"">"& pagenum &"</td>"& vbCrLf)
           Else
		      Response.Write (" <td width=""2""></td><td class=""outtd"" onmouseover=""this.className='intd';"" onmouseout=""this.className='outtd';"">")
			  Response.Write (" <a href=""?page="& pagenum &"&"&tyname1&"="&tyvalue1&"&"&tyname2&"="&tyvalue2&"""><div style=""width:100%"">"& pagenum &"</div></a></td>"& vbCrLf)
           End If
           If pagenum >= pagecount Then Exit For
       Next

	 If wzpage <= (pagecount - (pagecount mod 10)) Then
            Response.Write ("<td width=""2""></td><td class=""outtd"" onmouseover=""this.className='outtd';"" onmouseout=""this.className='outtd';""><a href=""?page="& pagenum &"&"&tyname1&"="&tyvalue1&"&"&tyname2&"="&tyvalue2&"""  title=""后十页""><img src=""images/next.gif"" border=""0""></a></td> "& vbCrLf)
            Response.Write ("<td width=""2""></td><td class=""outtd"" onmouseover=""this.className='outtd';"" onmouseout=""this.className='outtd';""><a href=""?page="& pagecount &"&"&tyname1&"="&tyvalue1&"&"&tyname2&"="&tyvalue2&"""  title=""末页""><img src=""images/last.gif"" border=""0""></a></td>"& vbCrLf)
     End If
	 Response.Write (" <td width=""2""></td><td><input class=""inputpage"" name=""page"" type=""text"" size=""3"" onKeyDown=""if(event.keyCode==13) {window.location='?"&tyname1&"="&tyvalue1&"&"&tyname2&"="&tyvalue2&"&page='+this.value; return false;}""></td>"& vbCrLf)
	 Response.Write ("</tr></table>"& vbCrLf)
End Function
'多参数分页函数其中tyname是参数名tyvalue是参数值
Function pagenar(pagecount,userid,tyname,tyvalue)
       Dim wzpage,wzpagecount,pagenum
       If Len(Request.QueryString("page"))<>0 Then
          wzpage = clng(Request.QueryString("page"))
         Else 
          wzpage =1
       End If
       If wzpage <= 0 Then wzpage =1
       pagenum = (wzpage \ 10)*10+1
       If wzpage mod 10 = 0 Then pagenum = (wzpage \ 10)*10-9
       If wzpage > 10 Then
            Response.Write ("<font face=""webdings"">")
            Response.Write ("<a href=""?page=1&userid="&userid&"&"&tyname&"="&tyvalue&""" title=""首页"">9</a> ")
            Response.Write ("<a href=""?page="& pagenum-1 &"&userid="&userid&"&"&tyname&"="&tyvalue&""" title=""前十页"">7</a> ")
            Response.Write ("</font>")
       End If
       For pagenum = pagenum To pagenum + 9
           If pagenum = wzpage Then
                  Response.Write ("<font color=""#ff0000"">")
                  Response.Write (" ["& pagenum &"] ")
                  Response.Write ("</font>")
           Else
                  Response.Write (" <a href=""?page="& pagenum &"&userid="&userid&"&"&tyname&"="&tyvalue&""">")
                  Response.Write ("["& pagenum &"]")
                  Response.Write ("</a> ")
           End If
           If pagenum >= pagecount Then Exit For
       Next

	 If wzpage <= (pagecount - (pagecount mod 10)) Then
            Response.Write ("<font face=""webdings"">")
            Response.Write ("<a href=""?page="& pagenum &"&userid="&userid&"&"&tyname&"="&tyvalue&"""  title=""后十页"">8</a> ")
            Response.Write ("<a href=""?page="& pagecount &"&userid="&userid&"&"&tyname&"="&tyvalue&"""  title=""末页"">:</a> ")
            Response.Write ("</font>")
     End If
End Function
'三个参数分页函数其中tyname是参数名tyvalue是参数值
Function FtbbsPage(pagecount,tyname1,tyvalue1,tyname2,tyvalue2)
       Dim wzpage,wzpagecount,pagenum
       If Len(Request.QueryString("page"))<>0 Then
          wzpage = clng(Request.QueryString("page"))
         Else 
          wzpage =1
       End If
       If wzpage <= 0 Then wzpage =1
       pagenum = (wzpage \ 10)*10+1
       If wzpage mod 10 = 0 Then pagenum = (wzpage \ 10)*10-9
       If wzpage > 10 Then
            Response.Write ("<font face=""webdings"">")
            Response.Write ("<a href=""?page=1&"&tyname1&"="&tyvalue1&"&"&tyname2&"="&tyvalue2&""" title=""首页"">9</a> ")
            Response.Write ("<a href=""?page="& pagenum-1 &"&"&tyname1&"="&tyvalue1&"&"&tyname2&"="&tyvalue2&""" title=""前十页"">7</a> ")
            Response.Write ("</font>")
       End If
       For pagenum = pagenum To pagenum + 9
           If pagenum = wzpage Then
                  Response.Write ("<font color=""#ff0000"">")
                  Response.Write (" ["& pagenum &"] ")
                  Response.Write ("</font>")
           Else
                  Response.Write (" <a href=""?page="& pagenum &"&"&tyname1&"="&tyvalue1&"&"&tyname2&"="&tyvalue2&""">")
                  Response.Write ("["& pagenum &"]")
                  Response.Write ("</a> ")
           End If
           If pagenum >= pagecount Then Exit For
       Next

	 If wzpage <= (pagecount - (pagecount mod 10)) Then
            Response.Write ("<font face=""webdings"">")
            Response.Write ("<a href=""?page="& pagenum &"&"&tyname1&"="&tyvalue1&"&"&tyname2&"="&tyvalue2&"""  title=""后十页"">8</a> ")
            Response.Write ("<a href=""?page="& pagecount &"&"&tyname1&"="&tyvalue1&"&"&tyname2&"="&tyvalue2&"""  title=""末页"">:</a> ")
            Response.Write ("</font>")
     End If
End Function
'生成广告js文件
Function makeadjs(ft)
   dim adjsmb,adjsmb1,adjsmbx,sql
   sql="select * from "&ft&"ftbbs_ad where adflag=0 and adtype=0 order by id desc"
   set rs=server.createobject("adodb.recordset")
   rs.open sql,conn,3,1
   if not rs.eof then
   adjsmb1="adshu = "&rs.RecordCount& vbCrLf
   adjsmb1=adjsmb1+"FtbbsAds = new Array();" & vbCrLf
   adjsmbx=""
   for adnum=1 to rs.RecordCount
   adjsmbx=adjsmbx+"FtbbsAds["&adnum&"] = ""[广告]<font color="&rs("adcolor")&"><a href="&rs("adurl")&" target='_blank'>"&rs("adtitle")&"</a></font>"";" & vbCrLf
   adjsmb=adjsmbx
   rs.movenext
   next
   else
   adjsmb1="adshu = 3" & vbCrLf
   adjsmb1=adjsmb1+"FtbbsAds = new Array();" & vbCrLf
   adjsmb="FtbbsAds[1] = ""[广告]<font color=><a href=http://www.ftbbs.cn/20082/200825104432a355.htm target='_blank'>FTBBS商业版安装教程(ACCESS与SQL版图片教程)</a></font>"";" & vbCrLf
   adjsmb=adjsmb+"FtbbsAds[2] = ""[广告]<font color=#008000><a href=http://www.ftbbs.cn/2006430/13.htm target='_blank'>FTBBS免费版和商业版的区别是什么?</a></font>"";" & vbCrLf
   adjsmb=adjsmb+"FtbbsAds[3] = ""[广告]<font color=><a href=http://www.xmfangzi.com target='_blank'>找房买房厦门房子网帮你忙</a></font>"";" & vbCrLf
   end if
   adjsmb=adjsmb+"ad = parseInt(Math.random() * adshu + 1);" & vbCrLf
   adjsmb=adjsmb+"document.write(FtbbsAds[ad]);" & vbCrLf
   call makehtml("../ad.js",fso,adjsmb1&adjsmb)
   rs.close
   set rs=nothing
End Function
%>