<%
'乘风多用户计数器 Sql版
'作者QQ：178575
'作者EMail：yliangcf@163.com
'作者网站：http://www.qqcf.com
'详细简介：http://www.qqcf.com/cfcount.htm
'上面有程序在线演示，安装演示，使用疑难解答，最新版本下载等内容
'因为这些内容可能时常更新，就没有放在程序里，请自己上网站上查看
'有完整版本的演示
%>

<%If RsSet("LyTj")=0 Then Response.write "系统已经禁用此功能"%>
<%
Px=ChkStr(Request("Px"),1)
AddYear=ChkStr(Request("AddYear"),2)
AddMonth=ChkStr(Request("AddMonth"),2)

If Px="" Then  Px="IpCounter"
If AddYear="" Or AddMonth="" Then
 AddYear=Year(Now)
 AddMonth=Month(Now)
End If

Call PxFilter(Px,"id,ip,lyhead,addtime,MyCounter,IpCounter,lasttime")
%>
<table class="tb_1">
<form name="form2" method="post" action="?Action=<%=Action%>" onSubmit="return monthcheck2();">
<tr>
    <td colspan="9">选择查询月数
<Select  name="addyear" size="1">
<option>请选择年份</option>
<%Sql="Select AddYear From CFCount_Ly_Month Where UserName='"&UserName&"' Group By AddYear Order By AddYear Desc"
Set Rs = Server.CreateObject("ADODB.Recordset")
Rs.open Sql,Conn,1,1

While Not Rs.Eof 
 Response.Write "<option value='"&Rs("AddYear")&"'"
 If Cstr(AddYear)=Cstr(Rs("AddYear")) Then Response.Write " selected"
 Response.Write ">"&Rs("AddYear")&"年</option>"  
Rs.MoveNext
Wend  
%>
        </select>
<Select  name="addmonth" size="1">
<option>请选择月份</option>
<%Sql="Select AddMonth From CFCount_Ly_Month Where UserName='"&UserName&"' Group By AddMonth Order By AddMonth Desc"
Set Rs = Server.CreateObject("ADODB.Recordset")
Rs.open Sql,Conn,1,1

While Not Rs.Eof 
 Response.Write "<option value='"&Rs("AddMonth")&"'"
 If Cstr(AddMonth)=Cstr(Rs("AddMonth")) Then Response.Write " selected"
 Response.Write ">第"&Rs("AddMonth")&"月</option>"  
Rs.MoveNext
Wend  
%>
        </select>        <input type="submit" name="Submit3" value="查询">
      </td>
  </tr></form>
  
  <%
Sql="Select Sum(MyCounter),Sum(IpCounter) From CFCount_Ly_Month where UserName='"&UserName&"' And AddYear="&AddYear&" And AddMonth="&AddMonth
Set Rs=Conn.execute(Sql)
ShowTotal=Rs(0)
IpTotal=Rs(1)

Sql="Select * From CFCount_Ly_Month where UserName='"&UserName&"' And AddYear="&AddYear&" And AddMonth="&AddMonth
Sql=Sql&" Order By "&Px&" Desc"
Set Rs = Server.CreateObject("ADODB.Recordset")
Rs.open Sql,Conn,1,1
If Not rs.eof then
 If ChkStr(Request("Page"),2) = "" Then
  Page = 1
 Else 
  Page = CInt(ChkStr(Request("Page"),2))
 End If
 
 rs.pagesize=20
 totalrs=rs.RecordCount
 totalpage=rs.pageCount
 mypagesize=rs.pagesize
 rs.absolutepage=page
End If

%>
<tr class="tr_1">
    <td colspan="9"><%=AddYear%>年<%=AddMonth%>月 来源统计[可点击标题排序]</td>
  </tr>
  <tr class="tr_2"> 
    <td><a href="?Action=<%=Action%>&AddYear=<%=AddYear%>&AddMonth=<%=AddMonth%>&Px=ID">序号</a></td>
    <td><a href="?Action=<%=Action%>&AddYear=<%=AddYear%>&AddMonth=<%=AddMonth%>&Px=LyHead">来源网站</a></td>
    <td colspan="2"><a href="?Action=<%=Action%>&AddMonth=<%=AddMonth%>&AddWeek=<%=AddWeek%>&Px=MyCounter">PV数量</a></td>
    <td colspan="2"><a href="?Action=<%=Action%>&AddYear=<%=AddYear%>&AddMonth=<%=AddMonth%>&Px=IPCounter">IP数量</a></td>
    <td><a href="?Action=<%=Action%>&AddYear=<%=AddYear%>&AddMonth=<%=AddMonth%>&Px=AddTime">上站时间</a></td>
    <td><a href="?Action=<%=Action%>&AddYear=<%=AddYear%>&AddMonth=<%=AddMonth%>&Px=Ip">最后IP地址</a></td>
    <td><a href="?Action=<%=Action%>&AddYear=<%=AddYear%>&AddMonth=<%=AddMonth%>&Px=LastTime">最后访问时间</a></td>
  </tr>
  <%
While Not Rs.Eof And MyPageSize>0
%>
  <tr class="tr_2"> 
    <td><%=Rs.RecordCount-Rs.Pagesize*(page)+mypagesize%></td>
    <td > 
        <%If Rs("LyHead")="" Then
  Response.Write "直接从浏览器输入"
 Else
  Response.Write "<a href=?Action=urlgo&Url="&Server.URLEncode("http://"&Rs("LyHead"))&" target='_blank'>"&Rs("LyHead")&"</a>&nbsp;[<a href=?Action=urlgo&Url="&Server.URLEncode(Rs("Ly"))&" target='_blank'>详细</a>]"
 End If%>
      </td>
    <td><%=Rs("MyCounter")%></td>
    <td class="td_1"><img src=images/bar_blue.gif width=<%=CInt(Rs("MyCounter")/ShowTotal*80)%> height=10><%=MyRate(Rs("MyCounter"),ShowTotal)%>%</td>
    <td><%=Rs("IpCounter")%></td>
    <td class="td_1"><img src=images/bar_green.gif width=<%=CInt(Rs("IpCounter")/IpTotal*80)%> height=10><%=MyRate(Rs("IpCounter"),IpTotal)%>%</td>
    <td><%=GetTurnTime(Hour(Rs("AddTime")))&":"&GetTurnTime(Minute(Rs("AddTime")))&":"&GetTurnTime(Second(Rs("AddTime")))%></td>
    <td> 
        <%If Ip=Rs("Ip") Then Response.Write "<font color=ff0000>"%>
        <%=Rs("Ip")%> 
        <%If Ip=Rs("Ip") Then Response.Write "</font>"%>
      </td>
    <td ><%=GetTurnTime(Hour(Rs("LastTime")))&":"&GetTurnTime(Minute(Rs("LastTime")))&":"&GetTurnTime(Second(Rs("LastTime")))%></td>
  </tr>
  <%rs.movenext
mypagesize=mypagesize-1
wend%>
</table>
<table class="tb_3">
  <tr>
    <td><a href="?Action=<%=Action%>&AddYear=<%=AddYear%>&AddMonth=<%=AddMonth%>&Px=<%=Px%>&Page=1">第一页</a>
            <%
if page>1 then%>
            <a href='?Action=<%=Action%>&AddYear=<%=AddYear%>&AddMonth=<%=AddMonth%>&Px=<%=Px%>&Page=<%=Page-1%>'>上一页</a>
            <%
end if
%>
            <%
if page<rs.pagecount   then%>
            <a href='?Action=<%=Action%>&AddYear=<%=AddYear%>&AddMonth=<%=AddMonth%>&Px=<%=Px%>&Page=<%=Page+1%>'>下一页</a>
            <%

end if
%>
            <a href="?Action=<%=Action%>&AddYear=<%=AddYear%>&AddMonth=<%=AddMonth%>&Px=<%=Px%>&Page=<%=totalpage%>">最后一页</a> 页次：<font color="#ff0000"><%=page%></font>/<%=totalpage%>页&nbsp;&nbsp;共<%=totalrs%>条记录&nbsp;&nbsp;每页显示<%=rs.pagesize%>条

<%
Response.write "&nbsp;&nbsp;转到第<select id='page' onChange=""window.location=document.getElementById('page').options[document.getElementById('page').selectedIndex].value"">"
For I=1 To TotalPage
    Response.Write "<option value=?Action="&Action&"&AddYear="&AddYear&"&AddMonth="&AddMonth&"&Px="&Px&"&Page="&i
 If Page=I Then Response.Write " selected"
 Response.Write ">"& I &"</option>"
Next
Response.write "</select>页"
%>
</td>
  </tr>
</table>