<!-- #include file="include/config.asp" -->
<!-- #include file="../include/jk_pagecute.asp" -->
<!-- #include file="../include/jk_page_cute.asp" -->
<%
dim nummer,nums,rssum,page,viewpage,thepages,pageurl,nsdim,nsnum
nsnum=-1
nummer=dim_num(0)
nums=nummer
page=1
dim str_prepay,now_otim
str_prepay=web_dim(50)
now_otim=joekoe_cms.now_time

select case action
case "note"
  tit="充值记录"
case else
  tit="充值服务"
end select

call web_head(2,0,0,0,0)
'----------------------------左边 开始----------------------------
call user_left(1)
'----------------------------左边 结束----------------------------
call web_center(0)
'----------------------------中间 开始----------------------------
call prepay_top()

select case action
case "note"
  call prepay_note()
case "order","order_to"
  call prepay_order()
case else
  call prepay_main()
end select

call prepay_end()
'----------------------------中间 结束----------------------------
call web_end(0,0)

sub prepay_top()
%>
  <table border=0>
  <tr height=50>
  <td><a href='?'><img src='<%response.write joekoe_cms.web_dir_skin%>main/emoney_prepay.gif' border=0></a></td>
  <td width=20></td>
  <td><a href='?action=note'><img src='<%response.write joekoe_cms.web_dir_skin%>main/emoney_prepay_note.gif' border=0></a></td>
  </tr>
  </tr>
  </table>
<%
  dim tmp1,str_estate,str_otim,str_sbate
  sql="select * from user_data where username='"&login_username&"'" 
  set rs=joekoe_cms.exec(sql,1)
  str_estate="<font class=red2>还不是</font>"
  if int(rs("estate"))=1 then
    now_otim=joekoe_cms.time_type(rs("otim"),4)
    str_estate="<font class=red>是</font>"
    str_otim="，过期时间为：<font class=blue>"&joekoe_cms.time_type(rs("otim"),4)&"</font>"
    str_sbate="，目前还未过期"
    if rs("abate")=true then str_sbate="，目前<font class=red2>已过期</font>"
  end if
  tmp1=vbcrlf&"<table border=0><tr><td align=center>" & _
       vbcrlf&"  <table border=0 class=tablew>" & _
       vbcrlf&"  <tr><td>您目前拥有的虚拟货币为：<font class=red>"&login_emoney&"</font>&nbsp;"&joekoe_cms.web_unit&"，您"&str_estate&"包月用户"&str_otim&str_sbate&"</td></tr>" & _
       vbcrlf&"  </table>" & _
       vbcrlf&"</td></tr></table>"
  response.write tmp1
end sub

sub prepay_end()
  dim tmp1
  tmp1=vbcrlf&"<table cellspacing=1 cellpadding=4 class=table><tr><td align=center>" & _
       vbcrlf&"  <table border=0 class=trb>" & _
       vbcrlf&"  <tr><td class=htd>充值服务即是计时用户包月形式的会员服务，充值后可<font class=red>免费</font>在本站内有<font class=red2>"&joekoe_cms.web_unit&"</font>扣取的文章浏览或下载资源。</td></tr>" & _
       vbcrlf&"  <tr><td class=htd>您在这里进行购买操作的 <font class=blue>充值服务</font> 为 <font class=red>不可逆操作</font> ！请在操作前注意一下。</td></tr>" & _
       vbcrlf&"  </table>" & _
       vbcrlf&"</td></tr></table>"
  response.write tmp1&ukong
end sub

sub prepay_msg(pmtype,pmstr)
  dim tmp1,tmpstr
  select case pmtype
  case 1
    tmpstr="可能还没有您要购买的充值服务！"
  case 2
    tmpstr="您目前的"&joekoe_cms.web_unit&"不够购买本充值服务！"
  case 3
    if pmstr="" then
      tmpstr="请先输入您要赠送的用户名称或者您要赠送的用户不在线！"
    else
      tmpstr="您要赠送的用户（"&pmstr&"）不存在！"
    end if
  case 4
    tmpstr="可能没有您要购买的充值服务！"
  case else
    tmpstr="暂时没有可购买的充值服务！"
  end select
  tmp1=vbcrlf&"<table cellspacing=1 cellpadding=4 class=table><tr><td class=bg align=center height=200>" & _
       vbcrlf&"<table border=0>" & _
       vbcrlf&"<tr class=htd>" & _
       vbcrlf&"<td width=120><img src='images/load.gif' border=0></td>" & _
       vbcrlf&"<td align=center>"&tmpstr&"</td>" & _
       vbcrlf&"</tr>" & _
       vbcrlf&"</table>" & _
       vbcrlf&"</td></tr></table>"
  response.write tmp1&ukong
end sub

sub prepay_order()
  dim tmpstr,tmpdim,tmpnum,types,username,to_username,tmp_types,is_user,user_emoney,num_order,num_emoney
  username=login_username
  to_username=login_username
  tmp_types=0
  if action="order_to" then
    now_otim=joekoe_cms.now_time
    tmp_types=1
    is_user=false
    to_username=trim(request.form("to_username"))
    if symbol_name(to_username)=true then
      set rs=joekoe_cms.exec("select username,estate,otim from user_data where username='"&to_username&"'",1)
      if not rs.eof then
        to_username=rs("username")
        now_otim=rs("otim")
        if rs("estate")=1 then
          if datediff("d",joekoe_cms.now_time,now_otim)<1 then
            now_otim=joekoe_cms.now_time
          end if
        end if
        is_user=true
      end if
      rs.close
    end if
    if is_user=false then
      call prepay_msg(3,to_username)
      exit sub
    end if
  end if
  types=trim(request.querystring("types"))-1
  tmpdim=split(str_prepay,"|")
  tmpnum=ubound(tmpdim)
  if tmpnum<0 then
    erase tmpdim
    call prepay_msg(0,"")
    exit sub
  end if
  if types<0 or types>tmpnum then
    erase tmpdim
    call prepay_msg(1,"")
    exit sub
  end if
  tmpstr=tmpdim(types)
  erase tmpdim
  tmpdim=split(tmpstr,",")
  if tmpdim(0)<=0 or tmpdim(1)<=0 and tmpdim(2)="" then
    erase tmpdim
    call prepay_msg(1,"")
    exit sub
  end if
  user_emoney=login_emoney
  num_order=trim(request.querystring("num_order"))
  if num_order<1 then num_order=1
  num_emoney=num_order*tmpdim(1)
  if user_emoney<num_emoney then
    erase tmpdim
    call prepay_msg(2,"")
    exit sub
  end if
  'exit sub
  if lcase(username)=lcase(to_username) then
    now_otim=dateadd("m",num_order*tmpdim(0),now_otim)
    call joekoe_cms.exec("update user_data set estate=1,abate=0,otim='"&now_otim&"',emoney=emoney-"&num_emoney&" where username='"&username&"'",0)
    tmpstr="您已成功的为自己充值"&(num_order*tmpdim(0))&"个月，您的过期时间为："&now_otim&"。\n\n此次充值系统自动扣取您"&num_emoney&"个"&joekoe_cms.web_unit&"。"
  else
    now_otim=dateadd("m",num_order*tmpdim(0),now_otim)
    call joekoe_cms.exec("update user_data set estate=1,abate=0,otim='"&now_otim&"' where username='"&to_username&"'",0)
    call joekoe_cms.exec("update user_data set emoney=emoney-"&num_emoney&" where username='"&username&"'",0)
    sql="insert into user_mail(send_u,accept_u,topic,word,tim,types,isread) " & _
        "values('"&username&"','"&to_username&"','[系统]充值冲值信息提示','"&username&" 已成功的给您值了"&(num_order*tmpdim(0))&"个月！您的过期时间为："&now_otim&"。','"&joekoe_cms.now_time&"',1,0)"
    call joekoe_cms.exec(sql,0)
    tmpstr="您已成功的为 "&to_username&" 充值"&(num_order*tmpdim(0))&"个月。\n\n此次充值系统自动扣取您"&num_emoney&"个"&joekoe_cms.web_unit&"。"
  end if
  tmpdim(2)=replace(tmpdim(2),"'","")
  sql="insert into notes_prepay(username,username2,types,total,num_order,explain,num_month,price,tim) " & _
      "values('"&username&"','"&to_username&"',"&tmp_types&","&num_emoney&","&num_order&",'"&tmpdim(2)&"',"&tmpdim(0)&","&tmpdim(1)&",'"&joekoe_cms.now_time&"')"
  call joekoe_cms.exec(sql,0)  
  login_emoney=user_emoney-num_emoney
  response.write joekoe_cms.js_put("alert("""&tmpstr&""");",1)
  erase tmpdim
end sub

sub prepay_main()
  dim tmp1,tmpstr,tmpdim,tmpdim2,tmpnum
  tmpdim=split(str_prepay,"|")
  tmpnum=ubound(tmpdim)
  if tmpnum<0 then
    call prepay_msg(0,"")
    exit sub
  end if
  tmp1=vbcrlf&"<tr align=center>" & _
       vbcrlf&"<td class=td width='8%'>序号</td>" & _
       vbcrlf&"<td class=td width='18%'>充值名称</td>" & _
       vbcrlf&"<td class=td width='12%'>充值时间</td>" & _
       vbcrlf&"<td class=td width='13%'>购买价格</td>" & _
       vbcrlf&"<td class=td width='12%'>数量</td>" & _
       vbcrlf&"<td class=td width='27%'>赠送给其它人</td>" & _
       vbcrlf&"<td class=td width='10%'>购买</td>" & _
       vbcrlf&"</tr>"
  for i=0 to tmpnum
    tmpdim2=split(tmpdim(i),",")
    if tmpdim2(0)>0 and tmpdim2(1)>0 and tmpdim2(2)<>"" then
      tmp1=tmp1&vbcrlf&"<tr class=tr height=30>" & _
           vbcrlf&"<form name=prepay"&(i+1)&"_frm action='?' method=get>" & _
           vbcrlf&"<input type=hidden name=action value='order_to'>" & _
           vbcrlf&"<input type=hidden name=types value='"&(i+1)&"'>" & _
           vbcrlf&"<td align=center class=tims>NO."&(i+1)&"</td>" & _
           vbcrlf&"<td>"&tmpdim2(2)&"</td>" & _
           vbcrlf&"<td align=right><font class=blue><b>"&tmpdim2(0)&"</b></font> 个月</td>" & _
           vbcrlf&"<td align=right>"&tmpdim2(1)&" <font class=red2>"&joekoe_cms.web_unit&"</font></td>" & _
           vbcrlf&"<td align=right><input type=text name=num_order value='1' size=5 maxlength=5 onKeyUp=""javascript:prepay_checknum("&(i+1)&");"" style=""text-align: center;""></td>" & _
           vbcrlf&"<td align=center><input type=text name=to_username size=13 maxlength=20> <input type=submit class=btn value='赠送' onclick=""javascript:return click_return('进行此赠送操作',0);""></td>" & _
           vbcrlf&"<td align=center><input type=button class=btn value='购买' onclick=""javascript:prepay_order('"&tmpdim2(2)&"',"&(i+1)&");""></td>" & _
           vbcrlf&"</form>" & _
           vbcrlf&"</tr>"
    end if
  next
  if i=0 then
    tmp1=tmp1&vbcrlf&"<tr class=tr><td colspan=7 align=center height=50>暂时没有可以充值的服务！</td></tr>"
  end if
%>
<script language=javascript>
<!--
var strTemp="0123456789";
function prepay_checknum(strnum)
{
  var nnum=eval("document.prepay"+strnum+"_frm.num_order.value");
  var tnum=prepay_nums(nnum,1);
  eval("document.prepay"+strnum+"_frm.num_order.value="+tnum);
}

function prepay_nums(nums,bnum)
{
  var i,j;
  var tmpnum=nums;
  if (tmpnum=="" || tmpnum==null) { return bnum; }
  for (i=0;i<tmpnum.length;i++)
  {
    j=strTemp.indexOf(tmpnum.charAt(i));  
    if (j==-1) { return bnum; }
  }
  if (tmpnum<bnum) { tmpnum=bnum; }
  return tmpnum;
}

function prepay_order(str_name,str_types)
{
  if (click_return('购买“'+str_name+'”服务',0))
  {
    var nnum=eval("document.prepay"+str_types+"_frm.num_order.value");
    location.href='?action=order&types='+str_types+'&num_order='+nnum;
  }
}
-->
</script>
<%
  response.write vbcrlf&"<table cellspacing=1 cellpadding=4 class=table>"&tmp1&"</td></tr></table>"&ukong
end sub

sub prepay_note()
  dim tmp1,str_types,str_username,username2,num_order,str_tim
  tmp1=vbcrlf&"<tr align=center>" & _
       vbcrlf&"<td class=td width='8%'>序号</td>" & _
       vbcrlf&"<td class=td width='8%'>类型</td>" & _
       vbcrlf&"<td class=td width='13%'>购买总价</td>" & _
       vbcrlf&"<td class=td dd1>充值用户 </td>" & _
       vbcrlf&"<td class=td width='11%'>充值时间</td>" & _
       vbcrlf&"<td class=td width='18%'>充值名称</td>" & _
       vbcrlf&"<td class=td width='8%'>数量</td>" & _
       vbcrlf&"<td class=td width='14%'>购买时间</td>" & _
       vbcrlf&"</tr>"
    sql="select count(id) from notes_prepay"
    set rs=joekoe_cms.exec(sql,1)
    rssum=rs(0)
    rs.close
    call format_pagecute()
    sql="select top "&nummer*viewpage&" * from notes_prepay order by id desc"
    call joekoe_cms.exec(sql,-1)
    rs.open sql,conn,1,1
    if int(viewpage)>1 then  rs.move (viewpage-1)*nummer end if
    for i=1 to nummer
    if rs.eof then exit for
    str_types="购买"
    if rs("types")=1 then str_types="<font class=red>赠送</font>"
    str_username=rs("username")
    username2=rs("username2")
    if lcase(str_username)=lcase(username2) then
      str_username="<font class=gray>自己</font>"
    else
      str_username=format_user_view(username2,1,18)
    end if
    num_order=rs("num_order")
    str_tim=rs("tim")
    tmp1=tmp1&vbcrlf&"<tr class=tr height=30 align=center>" & _
         vbcrlf&"<td class=tims>"& (viewpage-1)*nummer+i &"</td>" & _
         vbcrlf&"<td>"&str_types&"</td>" & _
         vbcrlf&"<td align=right><font class=red2>"&rs("total")&"</font> "&img_emoney&"</td>" & _
         vbcrlf&"<td>"&str_username&"</td>" & _
         vbcrlf&"<td align=right><font class=blue><b>"&(num_order*rs("num_month"))&"</b></font> 个月</td>" & _
         vbcrlf&"<td><font alt='单价："&rs("price")&joekoe_cms.web_unit&"'>"&rs("explain")&"</font></td>" & _
         vbcrlf&"<td>"&num_order&"</td>" & _
         vbcrlf&"<td><font class=tims alt='"&str_tim&"'>"&joekoe_cms.time_type(str_tim,4)&"</font></td>" & _
         vbcrlf&"</tr>"
    rs.movenext
  next
  rs.close
    tmp1=tmp1&vbcrlf&"<tr class=trb height=30>" & _
          vbcrlf&"<td colspan=8>" & _
          vbcrlf&"共有 <font class=red>"& rssum &"</font> 个"& tit &"，每页 <font class=blue>"& nummer &"</font> 个，页次：<font class=red>"& viewpage&"</font>/<font class=red>"&thepages &"</font>&nbsp;&nbsp;分页："& jk_pagecute(nummer,thepages,viewpage,pageurl,5,"#ff0000")  &"" & _
          vbcrlf&"</td>" & _
          vbcrlf&"</tr>"
  response.write vbcrlf&"<table cellspacing=1 cellpadding=4 class=table>"&tmp1&"</table>"&ukong
end sub
%>