<!-- #include file=../../inc/BBSsetup.asp -->
<!-- #include file=../../inc/Board_Popfun.asp -->

<!--#include file="ad_conn.asp"-->
<%
DEF_BBS_HomeUrl = "../../"
const npage = 2


GBL_CHK_TempStr=""
OpenDatabase
CheckUserOnline

dim headvar,stats
	headvar="&nbsp>>&nbsp<a href=ad.asp><font class=NavColor>广告公司</font></a>"
BBS_SiteHead DEF_SiteNameString&" "&DEF_BBS_Name,GBL_board_ID,headvar&" "&stats
         
dim sql,rs,msg
    msg=""

dim master
if CheckSupervisorUserName = 1  then
	master=true
  else
        master=false
end if

if GBL_CHK_User="" then
   msg="<li>你尚未登录，请<a href=" & DEF_BBS_HomeUrl & "User/Login.asp?u=" & urlencode(Request.Servervariables("SCRIPT_NAME") & "?" & Request.QueryString) & ">登录</a>！</li>"
   call Errormsg()
else
	dim action
	action=request("action")
	if action="save" then 
		call save()
	elseif action="update" then
		call update()
	else
		call main()
	end if
end if



sub main()

	set rs=server.createobject("adodb.recordset")
	sql="select * from [adv_config] where adv_type='默认'"
	rs.Open sql,conn_adv,1,1
	if rs.eof and rs.bof then
		msg="<li>广告公司尚未启用，请用管理员帐号登陆后进入<a href='ad_admin.asp'>管理</a>。</li>"
		call Errormsg()
                exit sub
	else
		dim adv_url
		dim adv_txt
		dim adv_img
		dim adv_cheat
		dim adv_wealth
		dim adv_cp
		dim adv_ep
		
		adv_url=rs("adv_url")
		adv_txt=rs("adv_txt")
		adv_img=rs("adv_img")
		adv_cheat=rs("adv_cheat")
		adv_wealth=rs("adv_wealth")
		adv_ep=rs("adv_ep")
		adv_cp=rs("adv_cp")
	end if
	rs.close
	set rs=nothing

	Response.Write "<table cellpadding=1 cellspacing=3 width="&DEF_BBS_ScreenWidth&" align=center class=tbone><tr class=tbhead2><td align=center colspan='3'><b><font class=HeadFont>广告公司</font></b></td></tr>"
	Response.Write "<tr class=tbbg1><td width='35%' valign='top'> <table style='width:100%' cellspacing=1 cellpadding=3 class=tbone>"
	Response.Write "<tr class=tbhead2><td align=center colspan='3'><b><font class=HeadFont>优秀广告人前10位排名</font></b></td></tr>"
	Response.Write "<tr class=tbbg1><td width='15%' align='center'>名次</td><td width='50%' align='center'>姓名</td><td width=* align='center'>反馈量</td></tr>"
	
	set rs=server.createobject("adodb.recordset")
	sql="select top 10 * from [adv_broker] order by count_Z desc"
	rs.Open sql,conn_adv,1,1
	dim i
	i=1
	do while not rs.eof
         	Response.Write "<tr height='23' class=tbbg1><td><img src='images/level-1-"&i&".gif' width='27' height='15'></td>"
		Response.Write "<td><a href='"&DEF_BBS_HomeUrl&"user/lookuserinfo.asp?id="&rs("userid")&"' target='_blank'>"&rs("username")&"</a></td><td align='right'><b>"&rs("count_z")&"</b></td></tr>"
		i=i+1
            	rs.movenext
           if i>12 then
              exit do
           end if
	loop
	rs.close
	Response.Write "</table>"
        
        if master then Response.Write "<table style='width:100%' cellspacing=1 cellpadding=3 class=tbone><tr class=tbhead2><td><b><font class=HeadFont><a href=ad_admin.asp>进入后台管理</a></font></b></td></tr></table><br>"
        
        Response.Write "</td><td width='65%' valign='top'> <table style='width:100%' cellspacing=1 cellpadding=3 class=tbone>"
	Response.Write "<tr class=tbhead2><td><b><font class=HeadFont>您的业务统计</font></b></td></tr><tr class=tbbg1><td>"
	sql="select * from [adv_broker] where userid="&GBL_UserID
	rs.Open sql,conn_adv,1,2
	if rs.eof and rs.bof then
		Response.Write "<a href='?action=save'><img src='images/adv_1.gif' border=0></a>"
		Response.Write "<br><br>通过做社区的广告经纪人赚钱可是一种很不错的方法，不过先要办一张证书。<br><b>办理费用：</b>免费<br><b>办理条件：</b>只要是会员均可办理" 
	else
		Response.Write "<table width='100%' border='0' cellpadding='1' cellspacing='3'><tr><td width=60% >"
		Response.Write "你总有效广告反馈量："&rs("count_z")
		Response.Write "次<br><br>您本次累积的反馈量："&rs("count_b")
		Response.Write "次<br><br>您本次累积业务佣金："&rs("count_b")*adv_wealth
		Response.Write "元<br>　　　　　　　魅力："&rs("count_b")*adv_cp
		Response.Write "点<br>　　　　　　　经验："&rs("count_b")*adv_ep
		Response.Write "点<br><br>您上次领取佣金时间："&rs("updatetime")
		Response.Write "</td><td>"
		Response.Write "<b>"&GBL_CHK_User&"</b>，欢迎你来到广告公司<br><br>"
		Response.Write "<a href='?action=update'><img src='images/adv_2.gif' border=0></a>"
		
		Response.Write "</td></tr></table>"
	end if
	rs.close	
	Response.Write "</td></tr></table>"
		
	Response.Write "<table style='width:100%' cellspacing=1 cellpadding=3 class=tbone><tr class=tbhead2><td><b><font class=HeadFont>宣传方式</font></b></td>"
	Response.Write "</tr><tr class=tbbg1><td >代码："
	Response.Write myurl&"/plug-ins/ad/get.asp?get="&GBL_UserID
	Response.Write "</td></tr><tr class=tbbg1><td align='left'><b>方法一：在其他论坛或聊天室发带有以下链接的帖子</b></td></tr><tr class=tbbg1><td >"
	%>
          进阶：<br> <table width="100%" border="0" cellspacing="0" cellpadding="3">
              <tr> 
                <td>在支持UBB的论坛上可以是这样</td>
              </tr>
              <tr> 
                <td><input name="textarea" type="text" style="width:420px" style="border: 1px  solid #000000; height: 18px;" value="[url=<%=myurl%>/plug-ins/ad/get.asp?get=<%=GBL_UserID%>]<%=adv_txt%>[/url]
		"></td>
              </tr>
              <tr> 
                <td><font color="#FF0000">效果：</font><a target=_blank href=<%=myurl%>/plug-ins/ad/get.asp?get=<%=GBL_UserID%>><%=adv_txt%></a></td>
              </tr>
              <tr> 
                <td>在论坛上，还可以把图片链接放到签名里（在帖子里好像不行）</td>
              </tr>
              <tr> 
                <td><input name="textfield" type="text" style="width:420px" style="border: 1px  solid #000000; height: 18px;"  value="[url=<%=myurl%>/plug-ins/ad/get.asp?get=<%=GBL_UserID%>][IMG]<%=adv_img%>[/IMG][/URL]
		"></td>
              </tr>
              <tr> 
                <td><font color="#FF0000">效果：</font><a href=<%=myurl%>/plug-ins/ad/get.asp?get=<%=GBL_UserID%>><img border=0 src="<%=adv_img%>"></a></td>
              </tr>
            </table>
	<%
	Response.Write "</td></tr><tr class=tbbg1><td align='left'><b>方法二：将此链接通过邮件或者QQ发给你的朋友</b></td></tr><tr class=tbbg1><td>"
	Response.Write "代码："
	Response.Write myurl&"/plug-ins/ad/get.asp?get="&GBL_UserID
	Response.Write "</td></tr><tr class=tbhead2><td align='left'><b><font class=HeadFont>广告公司说明</font></b></td></tr><tr class=tbbg1><td>"
	Response.Write "&nbsp&nbsp&nbsp&nbsp您可以将这些广告代码贴到其他论坛或个人主页等地方，别人通过这个链接进入本社区，您就能获得反馈。您可根据反馈量获得金币。<br>&nbsp&nbsp&nbsp&nbsp为防止作弊，同一IP地址在5分钟内重复点击，只算一次点击。 </td></tr>"
	Response.Write "</table></td></tr></table>"

end sub

'领取证书
sub save()

	set rs=server.createobject("adodb.recordset")
	sql="select * from [adv_broker] where userid="&GBL_UserID
	rs.Open sql,conn_adv,1,2
	if rs.eof and rs.bof then
		rs.addnew
		rs("userid")=GBL_UserID
		rs("username")=GBL_CHK_User
		rs("addtime")=now()
		rs.update
		rs.close
		set rs=nothing
		conn_adv.close
%>
<script language="vbscript">
msgbox "广告经纪人证书领取成功！"
location.href = "ad.asp"
</script>		
		
		
<%	else
		rs.close
		set rs=nothing
		conn_adv.close
                
		msg= "<li>你已经领取证书了，请不要重复申领。</li>"
		call Errormsg()
	end if
end sub

'领取佣金
sub update()
	set rs=server.createobject("adodb.recordset")
	sql="select * from [adv_broker] where userid="&GBL_UserID
	rs.Open sql,conn_adv,1,2
	if rs.eof and rs.bof then
		rs.close
		set rs=nothing
		conn_adv.close
		
		Msg= "<li>你尚未办理广告经纪人证书，请到<a href=ad.asp>广告公司</a>去申请吧。</li>"
		call Errormsg()
	else
		if rs("updatetime")=date() then
			rs.close
			set rs=nothing
			conn_adv.close	
			Msg= "<li>你今天已经领取佣金了，明天再来吧。</li>"
			Errormsg
		else
			rs("updatetime")=date()
			dim dianshu
			dianshu=rs("count_b")
			rs("count_b")=0
			rs.update
			rs.close

			set rs=server.createobject("adodb.recordset")
			sql="select * from [adv_config] where adv_type='默认'"
			rs.Open sql,conn_adv,1,1
			if rs.eof and rs.bof then
			    Msg= "<li>出现故障了，数据找不到了，请联系管理员。</li>"
			    Errormsg
			else
				dim adv_wealth
				dim adv_cp
				dim adv_ep
				
				adv_wealth=rs("adv_wealth")
				adv_ep=rs("adv_ep")
				adv_cp=rs("adv_cp")
			end if
			rs.close
	
			sql = "select points,charmpoint,onlinetime from [leadbbs_user] where id="&GBL_UserID
			rs.open sql,con,1,3
			if not rs.eof then
				rs("points")=rs("points")+dianshu*adv_wealth
				rs("charmpoint")=rs("charmpoint")+dianshu*adv_cp
				rs("onlinetime")=clng(rs("onlinetime")/60+dianshu*adv_ep)*60
				rs.update
			end if
			rs.close
			set rs=nothing
%>
<script language="vbscript">
msgbox "你已成功领取佣金：金钱<%=dianshu*adv_wealth%>，魅力<%=dianshu*adv_CP%>，经验<%=dianshu*adv_EP%>！"
location.href = "ad.asp"
</script>							

<%			
		end if
	end if
end sub
'尾部信息
If GBL_TableBottomString <> "" Then %>
 <table width=<%=DEF_BBS_ScreenWidth%> border=0 cellspacing=0 cellpadding=0 align=center>
   <tr><td><%=GBL_TableBottomString%></td></tr>
 </table>
<% End If 
  SiteBottom 
   If GBL_SiteBottomString <> "" Then Response.Write GBL_SiteBottomString
%>