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

AddYear_1=ChkStr(Request("AddYear_1"),2)
AddWeek_1=ChkStr(Request("AddWeek_1"),2)

AddYear_2=ChkStr(Request("AddYear_2"),2)
AddWeek_2=ChkStr(Request("AddWeek_2"),2)


If AddYear_1="" Or AddWeek_1="" Or AddYear_2="" Or AddWeek_2="" Then
 AddYear_2=Year(Now)
 AddWeek_2=DatePart("ww",Now)
 
 MyDate=DateAdd("d",-(DatePart("w",Now)),Now) 

 AddYear_1=Year(MyDate)
 AddWeek_1=DatePart("ww",MyDate)
End If
%>

<form name="form2" method="post" action="?Action=<%=Action%>" onSubmit="return weekcheck();">
<table class="tb_1"><tr>
    <td>搜索引擎<Select  name="SiteFlag" size="1">
<%Sql="Select * From CFCount_Search_Set"
Set Rs = Server.CreateObject("ADODB.Recordset")
Rs.open Sql,Conn,1,1

While Not Rs.Eof 
 Response.Write "<option value='"&Rs("SiteFlag")&"'"
 If Cstr(SiteFlag)=Cstr(Rs("SiteFlag")) Then Response.Write " selected"
 Response.Write ">"&Rs("SiteDesc")&"</option>"  
 
 If SiteFlag="" Then
  If Instr(Rs("SiteFlag"),"baidu.com") Then
   SiteFlag = Rs("SiteFlag")
   SiteDesc = Rs("SiteDesc") 
  End If
 Else
  If Cstr(SiteFlag)=Cstr(Rs("SiteFlag")) Then
   SiteDesc = Rs("SiteDesc") 
  End if
 End If
Rs.MoveNext
Wend  
%>
        </select>周数
<Select  name="addyear_1" size="1">
<option>请选择年份</option>
<%Sql="Select AddYear From CFCount_SearchKeyword_Week 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_1)=Cstr(Rs("AddYear")) Then Response.Write " selected"
 Response.Write ">"&Rs("AddYear")&"年</option>"  
Rs.MoveNext
Wend  
%>
        </select>
<Select  name="addweek_1" size="1">
<option>请选择周数</option>
<%Sql="Select AddWeek From CFCount_SearchKeyword_Week Where UserName='"&UserName&"' Group By AddWeek Order By AddWeek Desc"
Set Rs = Server.CreateObject("ADODB.Recordset")
Rs.open Sql,Conn,1,1

While Not Rs.Eof 
 Response.Write "<option value='"&Rs("AddWeek")&"'"
 If Cstr(AddWeek_1)=Cstr(Rs("AddWeek")) Then Response.Write " selected"
 Response.Write ">第"&Rs("AddWeek")&"周</option>"  
Rs.MoveNext
Wend  
%>
        </select> -
<Select  name="addyear_2" size="1">
<option>请选择年份</option>
<%Sql="Select AddYear From CFCount_SearchKeyword_Week 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_2)=Cstr(Rs("AddYear")) Then Response.Write " selected"
 Response.Write ">"&Rs("AddYear")&"年</option>"  
Rs.MoveNext
Wend  
%>
        </select>
<Select  name="addweek_2" size="1">
<option>请选择周数</option>
<%Sql="Select AddWeek From CFCount_SearchKeyword_Week Where UserName='"&UserName&"' Group By AddWeek Order By AddWeek Desc"
Set Rs = Server.CreateObject("ADODB.Recordset")
Rs.open Sql,Conn,1,1

While Not Rs.Eof 
 Response.Write "<option value='"&Rs("AddWeek")&"'"
 If Cstr(AddWeek_2)=Cstr(Rs("AddWeek")) Then Response.Write " selected"
 Response.Write ">第"&Rs("AddWeek")&"周</option>"  
Rs.MoveNext
Wend  
%>
        </select> <input type="submit" name="Submit3" value="查询">
        可同时选择两个周对比查询</td>
  </tr>

</table></form>
  
<table class="tb_4">
<tr>
    <td width="50%" valign="top">
	<table class="tb_3" width="98%">





        <%
ShowTotal=0
IpTotal=0
Session("CFCountTemp")=""

Sql="Select Sum(MyCounter),Sum(IpCounter) From CFCount_SearchKeyword_Week where UserName='"&UserName&"' And SiteFlag='"&SiteFlag&"' And AddYear="&AddYear_1&" And AddWeek="&AddWeek_1
Set Rs=Conn.Execute(Sql)
ShowTotal=Rs(0)
IpTotal=Rs(1)


Sql="Select Top 20 KeyWord,MyCounter,IpCounter,LastLy,LastTime From CFCount_SearchKeyword_Week where UserName='"&UserName&"' And SiteFlag='"&SiteFlag&"' And AddYear="&AddYear_1&" And AddWeek="&AddWeek_1&" Order By IpCounter Desc"
Set Rs=Conn.Execute(Sql)
If Not Rs.eof Then
  Session("CFCountTemp")=Rs.GetRows(-1)
End If


%>
	<tr class="tr_1">
          <td colspan="5"><%=AddYear_1%>年第<%=AddWeek_1%>周 <%=SiteDesc%>前20关键字报表</td>
        </tr>
        <tr class="tr_2"> 
          <td>&nbsp;</td>
          <td colspan="2">PV总量</td>
          <td colspan="2">唯一IP</td>
        </tr>
        <tr class="tr_2"> 
          <td><a href="?Action=keyworddaytj_2&SiteFlag=<%=SiteFlag%>&AddYear=<%=AddYear_1%>&AddWeek=<%=AddWeek_1%>">点击查看全部关键字</a></td>
          <td colspan="2">共&nbsp;<%=IpTotal%>&nbsp;PV</td>
          <td colspan="2">共&nbsp;<%=IpTotal%>&nbsp;IP</td>
        </tr>
        <tr class="tr_2"> 
          <td>关键字</td>
          <td colspan="2">PV数量</td>
          <td colspan="2">IP数量</td>
        </tr>
<%
MyI = 0

For MyI=0 To Ubound(Session("CFCountTemp"),2)
KeyWord=""
ShowNum=0
IpNum=0
LastLy=""
LastTime=""

KeyWord=Session("CFCountTemp")(0,MyI)
ShowNum=Session("CFCountTemp")(1,MyI)
IpNum=Session("CFCountTemp")(2,MyI)
LastLy=Session("CFCountTemp")(3,MyI)
LastTime=Session("CFCountTemp")(4,MyI)
%>
        <tr class="tr_2" title="最后更新<%=GetTurnTime(Hour(Cdate(LastTime)))&":"&GetTurnTime(Minute(Cdate(LastTime)))&":"&GetTurnTime(Second(Cdate(LastTime)))%>"> 
          <td>
<a href="<%=LastLy%>" target='_blank'> 
<%
 If Instr(LastLy,"google")>0 Or Instr(LastLy,"yahoo")>0 Then
  KeyWord_2=UTF2GB(KeyWord)  
 Else
  KeyWord_2=URLDecode(KeyWord)
 End If
 If Len(KeyWord_2)=0 Then KeyWord_2=KeyWord
 Response.write Server.HTMLEncode(KeyWord_2)
%>
</a>
</td>
          <td><%=ShowNum%></td>
          <td class="td_1"><img src=images/bar_blue.gif width=<%=CInt(ShowNum/ShowTotal*60)%> height=10><%=MyRate(ShowNum,ShowTotal)%>%</td>
          <td><%=IpNum%></td>
          <td class="td_1"><img src=images/bar_green.gif width=<%=CInt(IpNum/IpTotal*60)%> height=10><%=MyRate(IpNum,IpTotal)%>%</td>
        </tr>
        <%
Next
%>
      </table></td>
    <td valign="top">
	<table class="tb_3" width="98%">



        <%
ShowTotal=0
IpTotal=0
Session("CFCountTemp")=""

Sql="Select Sum(MyCounter),Sum(IpCounter) From CFCount_SearchKeyword_Week where UserName='"&UserName&"' And SiteFlag='"&SiteFlag&"' And AddYear="&AddYear_1&" And AddWeek="&AddWeek_2
Set Rs=Conn.Execute(Sql)
ShowTotal=Rs(0)
IpTotal=Rs(1)


Sql="Select Top 20 KeyWord,MyCounter,IpCounter,LastLy,LastTime From CFCount_SearchKeyword_Week where UserName='"&UserName&"' And SiteFlag='"&SiteFlag&"' And AddYear="&AddYear_1&" And AddWeek="&AddWeek_2&" Order By IpCounter Desc"
Set Rs=Conn.Execute(Sql)
If Not Rs.eof Then
  Session("CFCountTemp")=Rs.GetRows(-1)
End If


%>
	<tr class="tr_1">
          <td colspan="5"><%=AddYear_2%>年第<%=AddWeek_2%>周 <%=SiteDesc%>前20关键字报表</td>
        </tr>
        <tr class="tr_2"> 
          <td>&nbsp;</td>
          <td colspan="2">PV总量</td>
          <td colspan="2">唯一IP</td>
        </tr>
        <tr class="tr_2"> 
          <td><a href="?Action=keyworddaytj_2&SiteFlag=<%=SiteFlag%>&AddYear=<%=AddYear_2%>&AddWeek=<%=AddWeek_2%>">点击查看全部关键字</a></td>
          <td colspan="2">共&nbsp;<%=IpTotal%>&nbsp;PV</td>
          <td colspan="2">共&nbsp;<%=IpTotal%>&nbsp;IP</td>
        </tr>
        <tr class="tr_2"> 
          <td>关键字</td>
          <td colspan="2">PV数量</td>
          <td colspan="2">IP数量</td>
        </tr>
<%
MyI = 0

For MyI=0 To Ubound(Session("CFCountTemp"),2)
KeyWord=""
ShowNum=0
IpNum=0
LastLy=""
LastTime=""

KeyWord=Session("CFCountTemp")(0,MyI)
ShowNum=Session("CFCountTemp")(1,MyI)
IpNum=Session("CFCountTemp")(2,MyI)
LastLy=Session("CFCountTemp")(3,MyI)
LastTime=Session("CFCountTemp")(4,MyI)
%>
        <tr class="tr_2" title="最后更新<%=GetTurnTime(Hour(Cdate(LastTime)))&":"&GetTurnTime(Minute(Cdate(LastTime)))&":"&GetTurnTime(Second(Cdate(LastTime)))%>"> 
          <td>
<a href="<%=LastLy%>" target='_blank'> 
<%
 If Instr(LastLy,"google")>0 Or Instr(LastLy,"yahoo")>0 Then
  KeyWord_2=UTF2GB(KeyWord)  
 Else
  KeyWord_2=URLDecode(KeyWord)
 End If
 If Len(KeyWord_2)=0 Then KeyWord_2=KeyWord
 Response.write Server.HTMLEncode(KeyWord_2)
%>
</a>
</td>
          <td><%=ShowNum%></td>
          <td class="td_1"><img src=images/bar_blue.gif width=<%=CInt(ShowNum/ShowTotal*60)%> height=10><%=MyRate(ShowNum,ShowTotal)%>%</td>
          <td><%=IpNum%></td>
          <td class="td_1"><img src=images/bar_green.gif width=<%=CInt(IpNum/IpTotal*60)%> height=10><%=MyRate(IpNum,IpTotal)%>%</td>
        </tr>
        <%
Next
%>
      </table></td>
  </tr>
</table>