<!-- #include file="../include/skin.asp" -->
<!-- #include file="../include/jk_ubb.asp" -->
<!-- #include file="include/common_plugin.asp" -->
<%

data_name="get_emoney"
index_url="user_main"
tit_fir="用户中心"
tit="领红包"
dim g_dim:g_dim=split(plugin_dim(0),"|")
dim emoney_type,emoney_name,emoney_num,get_num
emoney_type="emoney"
emoney_name=web_dim(9)
emoney_num=int(g_dim(2))

call web_head(1,0,2,0,0)


select case action
case "get"
  call get_emoney()
case else
  if g_dim(0)=1 then 
    call get_emoney_close()
  else
    call get_emoney_main()
  end if
end select


call web_end(0,0)

sub get_emoney_main()
 on error resume next
  sql="select count(id) from "&data_name&" where username='"&login_username&"'"
  set rs=joekoe_cms.exec(sql,1)
    if err then error.clear:response.write("<br><br><br>数据库执行失败，可能还没有建立红包数据库！<br><br><br>"):exit sub
  get_num=rs(0)
  rs.close
%>
<form action='?action=get' method=post>
<table height=250 cellspacing=0 cellpadding=0 class=table>
<tr class=bg_td><td align=center colspan=2><font class=red size=3><b><%response.write g_dim(1)%></b></font></td></tr>
<tr class=bg_td><td width='70%'>
  <table border=0 width='100%' align=center>
  <tr height=50><td>
    <table border=0 class=tf>
    <tr valign=top align=center><td>
    <%response.write code_jk(g_dim(4))%>
    </td></tr>
    </table>
  </td></tr>
  <tr><td height=50 align=center><input type=submit class=btn value='我要领取红包'> <%
  if login_mode<>"" then %>(每用户共可领<font class=red><%=g_dim(3)%></font>次红包,<%=login_username%>,你已经领了<font class=red><%=get_num%></font>次)<%
  else%>(您还没有登陆，请登陆后再领取红包)<%end if%></td></tr>
  </table>
<td width='30%' align=center><img src=images/plugin/get_emoney.gif></tr>
</table>
</form>
<%
end sub

sub get_emoney()
  if login_mode="" then  
  call get_emoney_error("login"):exit sub
  end if
  if joekoe_cms.post_chk=false then
    call get_emoney_error("post"):exit sub
  elseif chk_user=false then 
    call get_emoney_error("geted"):exit sub
  else
    sql="insert into "&data_name&" (username,emoney_num,emoney_type,tim) values ('"&login_username&"',"&emoney_num&",'"&emoney_name&"','"&joekoe_cms.now_time&"')"
    response.write joekoe_cms.exec(sql,0)  
    sql="update user_data set "&emoney_type&"="&emoney_type&"+"&emoney_num&" where username='"&login_username&"'"
    response.write joekoe_cms.exec(sql,0)  
    response.write "<script language=javascript>alert('恭喜，您已经成功的领取了红包！\n\n红包内容为： "&emoney_num&" "&emoney_name&"');location.href='?';</script>"
  end if
end sub

sub get_emoney_close()
%>
<table height=250 cellspacing=0 cellpadding=0 class=table>
<tr class=bg_td><td height=200 align=center><font class=red>对不起！本站暂时关闭 <font class=blue><% response.write tit %></font> 的功能。</font><br><br>如有需要，请与管理员联系。谢谢！</td></tr>
</table>
<%  
end sub

sub get_emoney_error(evar)
  select case evar
    case "post"
%>
<table height=250 cellspacing=0 cellpadding=0 class=table>
<tr class=bg_td><td height=200 align=center><font class=red>禁止外部提交！</font></td></tr>
</table>
<%  
    case "geted"
%>
<table height=250 cellspacing=0 cellpadding=0 class=table>
<tr class=bg_td><td height=200 align=center><font class=red>对不起！您已经领过红包了。</font><br><br>(每个用户总共可以领<font class=red><%=g_dim(3)%></font>次红包)<br><br>如有需要，请与管理员联系。谢谢！<br><br><%=go_back%></td></tr>
</table>
<%    
case "login"
%>
<table height=250 cellspacing=0 cellpadding=0 class=table>
<tr class=bg_td><td height=200 align=center><font class=red>对不起！您还没有登陆，我们没法把钱汇到您的帐号上。</font><br><br>请登陆后再来领取红包。谢谢！<br><br><%=go_back%></td></tr>
</table>
<%    
  end select
end sub

function chk_user()
  dim rs,sql
  chk_user=false
  sql="select count(id) from "&data_name&" where username='"&login_username&"'"
  set rs=joekoe_cms.exec(sql,1)
  if rs(0)>=int(g_dim(3)) then 
    chk_user=false
  else
    chk_user=true
  end if  
  rs.close
end function

%>
