Function.asp
资源名称:1.rar [点击查看]
上传用户:yrf020
上传日期:2007-07-24
资源大小:1287k
文件大小:9k
源码类别:

WEB源码(ASP,PHP,...)

开发平台:

HTML/CSS

  1. <%
  2. function StrLen(Str)
  3.   if Str="" or isnull(Str) then 
  4.     StrLen=0
  5.     exit function 
  6.   else
  7.     dim regex
  8.     set regex=new regexp
  9.     regEx.Pattern ="[^x00-xff]"
  10.     regex.Global =true
  11.     Str=regEx.replace(Str,"^^")
  12.     set regex=nothing
  13.     StrLen=len(Str)
  14.   end if
  15. end function
  16. function StrLeft(Str,StrLen)
  17.   dim L,T,I,C
  18.   if Str="" then
  19.     StrLeft=""
  20.     exit function
  21.   end if
  22.   Str=Replace(Replace(Replace(Replace(Str,"&nbsp;"," "),"&quot;",Chr(34)),"&gt;",">"),"&lt;","<")
  23.   L=Len(Str)
  24.   T=0
  25.   for i=1 to L
  26.     C=Abs(AscW(Mid(Str,i,1)))
  27.     if C>255 then
  28.       T=T+2
  29.     else
  30.       T=T+1
  31.     end if
  32.     if T>=StrLen then
  33.       StrLeft=Left(Str,i) & "…"
  34.       exit for
  35.     else
  36.       StrLeft=Str
  37.     end if
  38.   next
  39.   StrLeft=Replace(Replace(Replace(replace(StrLeft," ","&nbsp;"),Chr(34),"&quot;"),">","&gt;"),"<","&lt;")
  40. end function
  41. function StrReplace(Str)'表单存入替换字符
  42.   if Str="" or isnull(Str) then 
  43.     StrReplace=""
  44.     exit function 
  45.   else
  46.     StrReplace=replace(str," ","&nbsp;") '"&nbsp;"
  47.     StrReplace=replace(StrReplace,chr(13),"&lt;br&gt;")'"<br>"
  48.     StrReplace=replace(StrReplace,"<","&lt;")' "&lt;"
  49.     StrReplace=replace(StrReplace,">","&gt;")' "&gt;"
  50.   end if
  51. end function
  52. function ReStrReplace(Str)'写入表单替换字符
  53.   if Str="" or isnull(Str) then 
  54.     ReStrReplace=""
  55.     exit function 
  56.   else
  57.     ReStrReplace=replace(Str,"&nbsp;"," ") '"&nbsp;"
  58.     ReStrReplace=replace(ReStrReplace,"<br>",chr(13))'"<br>"
  59.     ReStrReplace=replace(ReStrReplace,"&lt;br&gt;",chr(13))'"<br>"
  60.     ReStrReplace=replace(ReStrReplace,"&lt;","<")' "&lt;"
  61.     ReStrReplace=replace(ReStrReplace,"&gt;",">")' "&gt;"
  62.   end if
  63. end function
  64. function HtmlStrReplace(Str)'写入Html网页替换字符
  65.   if Str="" or isnull(Str) then 
  66.     HtmlStrReplace=""
  67.     exit function 
  68.   else
  69.     HtmlStrReplace=replace(Str,"&lt;br&gt;","<br>")'"<br>"
  70.   end if
  71. end function
  72. function ViewNoRight(GroupID,Exclusive)
  73.   dim rs,sql,GroupLevel
  74.   set rs = server.createobject("adodb.recordset")
  75.   sql="select GroupLevel from CompanyCMS_MemGroup where GroupID='"&GroupID&"'"
  76.   rs.open sql,conn,1,1
  77.   GroupLevel=rs("GroupLevel")
  78.   rs.close
  79.   set rs=nothing
  80.   ViewNoRight=true
  81.   if session("GroupLevel")="" then session("GroupLevel")=0
  82.   select case Exclusive
  83.     case ">="
  84.       if not session("GroupLevel") >= GroupLevel then
  85.     ViewNoRight=false
  86.   end if
  87.     case "="
  88.       if not session("GroupLevel") = GroupLevel then
  89.     ViewNoRight=false
  90.       end if
  91.   end select
  92. end function
  93. Function GetUrl()
  94.   GetUrl="http://"&Request.ServerVariables("SERVER_NAME")&Request.ServerVariables("URL")
  95.   If Request.ServerVariables("QUERY_STRING")<>"" Then GetURL=GetUrl&"?"& Request.ServerVariables("QUERY_STRING")
  96. End Function
  97. function HtmlSmallPic(GroupID,PicPath,Exclusive)
  98.   dim rs,sql,GroupLevel
  99.   set rs = server.createobject("adodb.recordset")
  100.   sql="select GroupLevel from CompanyCMS_MemGroup where GroupID='"&GroupID&"'"
  101.   rs.open sql,conn,1,1
  102.   GroupLevel=rs("GroupLevel")
  103.   rs.close
  104.   set rs=nothing
  105.   HtmlSmallPic=PicPath
  106.   if session("GroupLevel")="" then session("GroupLevel")=0
  107.   select case Exclusive
  108.     case ">="
  109.       if not session("GroupLevel") >= GroupLevel then HtmlSmallPic="Images/NoRight.jpg"
  110.     case "="
  111.       if not session("GroupLevel") = GroupLevel then HtmlSmallPic="Images/NoRight.jpg"
  112.   end select
  113.   if HtmlSmallPic="" or isnull(HtmlSmallPic) then HtmlSmallPic="Images/NoPicture.jpg"
  114. end function
  115. function IsValidMemName(memname)
  116.   dim i, c
  117.   IsValidMemName = true
  118.   if not (3<=len(memname) and len(memname)<=16) then
  119.     IsValidMemName = false
  120.     exit function
  121.   end if  
  122.   for i = 1 to Len(memname)
  123.     c = Mid(memname, i, 1)
  124.     if InStr("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-", c) <= 0 and not IsNumeric(c) then
  125.       IsValidMemName = false
  126.       exit function
  127.     end if
  128.   next
  129. end function
  130. function IsValidEmail(email)
  131.   dim names, name, i, c
  132.   IsValidEmail = true
  133.   names = Split(email, "@")
  134.   if UBound(names) <> 1 then
  135.     IsValidEmail = false
  136.     exit function
  137.   end if
  138.   for each name in names
  139. if Len(name) <= 0 then
  140.   IsValidEmail = false
  141.       exit function
  142.     end if
  143.     for i = 1 to Len(name)
  144.       c = Mid(name, i, 1)
  145.       if InStr("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-.", c) <= 0 and not IsNumeric(c) then
  146.         IsValidEmail = false
  147.         exit function
  148.       end if
  149. next
  150. if Left(name, 1) = "." or Right(name, 1) = "." then
  151.       IsValidEmail = false
  152.       exit function
  153.     end if
  154.   next
  155.   if InStr(names(1), ".") <= 0 then
  156.     IsValidEmail = false
  157.     exit function
  158.   end if
  159.   i = Len(names(1)) - InStrRev(names(1), ".")
  160.   if i <> 2 and i <> 3 then
  161.     IsValidEmail = false
  162.     exit function
  163.   end if
  164.   if InStr(email, "..") > 0 then
  165.     IsValidEmail = false
  166.   end if
  167. end function
  168. '================================================
  169. '函数名:FormatDate
  170. '作 用:格式化日期
  171. '参 数:DateAndTime            (原日期和时间)
  172. '       Format                 (新日期格式)
  173. '返回值:格式化后的日期
  174. '================================================
  175. Function FormatDate(DateAndTime, Format)
  176.   On Error Resume Next
  177.   Dim yy,y, m, d, h, mi, s, strDateTime
  178.   FormatDate = DateAndTime
  179.   If Not IsNumeric(Format) Then Exit Function
  180.   If Not IsDate(DateAndTime) Then Exit Function
  181.   yy = CStr(Year(DateAndTime))
  182.   y = Mid(CStr(Year(DateAndTime)),3)
  183.   m = CStr(Month(DateAndTime))
  184.   If Len(m) = 1 Then m = "0" & m
  185.   d = CStr(Day(DateAndTime))
  186.   If Len(d) = 1 Then d = "0" & d
  187.   h = CStr(Hour(DateAndTime))
  188.   If Len(h) = 1 Then h = "0" & h
  189.   mi = CStr(Minute(DateAndTime))
  190.   If Len(mi) = 1 Then mi = "0" & mi
  191.   s = CStr(Second(DateAndTime))
  192.   If Len(s) = 1 Then s = "0" & s
  193.    
  194.   Select Case Format
  195.   Case "1"
  196.     strDateTime = y & "-" & m & "-" & d & " " & h & ":" & mi & ":" & s
  197.   Case "2"
  198.     strDateTime = yy & m & d & h & mi & s
  199.     '返回12位 直到秒 的时间字符串
  200.   Case "3"
  201.     strDateTime = yy & m & d & h & mi    
  202.     '返回12位 直到分 的时间字符串
  203.   Case "4"
  204.     strDateTime = yy & "年" & m & "月" & d & "日"
  205.   Case "5"
  206.     strDateTime = m & "-" & d
  207.   Case "6"
  208.     strDateTime = m & "/" & d
  209.   Case "7"
  210.     strDateTime = m & "月" & d & "日"
  211.   Case "8"
  212.     strDateTime = y & "年" & m & "月"
  213.   Case "9"
  214.     strDateTime = y & "-" & m
  215.   Case "10"
  216.     strDateTime = y & "/" & m
  217.   Case "11"
  218.     strDateTime = y & "-" & m & "-" & d
  219.   Case "12"
  220.     strDateTime = y & "/" & m & "/" & d
  221.   Case "13"
  222.     strDateTime = yy & "." & m & "." & d
  223.   Case "14"
  224.     strDateTime = yy & "/" & m & "/" & d
  225.   Case "15"
  226.     strDateTime = yy & "-" & m & "-" & d
  227.   Case Else
  228.     strDateTime = DateAndTime
  229.   End Select
  230.   FormatDate = strDateTime
  231. End Function
  232. function WriteMsg(Message)
  233.   response.write "<div align=""center"">" &_
  234.                  "  <div style=""width:500px; padding:1px; border:1px solid #f00;"">" &_
  235.                  "    <div style=""background:#f00; line-height:24px; font-family:Arial; font-size:16px; color:#fff; font-weight:bold;"">" &_
  236.                  "      MESSAGE" &_
  237.                  "    </div>" &_
  238.                  "   <div style=""padding:4px 0; text-align:left; background:#fff; font-family:宋体; line-height:20px; font-size:13px;"">" &_
  239.                        Message &_
  240.                  "    </div>" &_
  241.                  "  </div>" &_
  242.                  "  <div style=""padding:8px;"">" &_
  243.                  "    <a href=""javascript:history.back(-1)""><img src=""Images/Arrow_05.gif"" border=""0"" /></a>" &_
  244.                  "  </div>" &_
  245.  "</div>"
  246. end function
  247. '================================================
  248. '函数名:SiteInfo
  249. '作 用:调用网站基本信息
  250. '参 数:
  251. '返回值:定义的所有变量
  252. '================================================
  253. public Language
  254. Language=split(request.servervariables("url"),"/")(UBound(split(request.servervariables("url"),"/"))-1)
  255. public SiteTitle,ComName,Address,SiteUrl,ZipCode,Telephone,Fax,Email,Keywords,Descriptions,IcpNumber,MesViewFlag
  256. public SiteTitleCh,SiteTitleEn,ComNameCh,ComNameEn,AddressCh,AddressEn
  257. sub SiteInfo()
  258.   dim rs,sql
  259.   set rs = server.createobject("adodb.recordset")
  260.   sql="select top 1 * from CompanyCMS_Site"
  261.   rs.open sql,conn,1,1
  262.   SiteTitle=rs("SiteTitle"&Language)
  263.   Keywords=rs("Keywords")
  264.   Descriptions=rs("Descriptions")
  265.   SiteUrl=rs("SiteUrl")
  266.   ComName=rs("ComName"&Language)
  267.   Address=rs("Address"&Language)
  268.   ZipCode=rs("ZipCode")
  269.   Telephone=rs("Telephone")
  270.   Fax=rs("Fax")
  271.   Email=rs("Email")
  272.   IcpNumber=rs("IcpNumber")
  273.   MesViewFlag=rs("MesViewFlag")
  274.   rs.close
  275.   set rs=nothing
  276. end sub
  277. %>