<!-- #include file="include/config.asp" -->
<!-- #include file="include/fir.asp" -->
<!-- #include file="include/main.asp" -->

<%
iframe=true
index_url="pay"
tit_fir="交流论坛"

select case action
case "special_guerdon"
  tits="奖赏用户"
case else
  tits="购买贴子"
end select
call web_head(h1,0,h_var3,0,0)
ftit=tit
call forum_first()
call forum_grade()
select case action

%>
<table border=0 cellspacing=0 cellpadding=0 class=bbs_tablew>
<tr align=center valign=top>
<td width=200>
<%call pay_left()%>
</td>
<td width=5></td>
<td width="*">
<%
select case action
case "special_buy"
  call pay_special_buy()
case "special_guerdon"
  call pay_special_guerdon()
case else
  call cms_chn_go(dirchn)
end select
%>
</td>
</tr>
</table>
<%
call web_end(0,0)

sub pay_left()
%>
<table cellspacing=1 cellpadding=4 class=bbs_tables>
<tr class=bbs_td><td colspan=2>个人信息</td></tr>
<tr class=bbs_th>
<td width="35%">用户名：</td>
<td width="75%"><a href="../user/view.asp?username=<%=loing_username%>" class=h_user target=_blank><%=loing_username%></a></td>
</tr>
<tr class=bbs_tr>
<td>货　币：</td>
<td><font class=emoney><%=loing_emoney%></font>&nbsp;<%=joekoe_cms.web_unit%></td>
</tr>
<tr class=bbs_tr>
<td>积　分：</td>
<td><font class=red><%=loing_integral%></font>&nbsp;积分/td>
</tr>
<!--
<tr class=bbs_tr>
<td>经　验：</td>
<td><font class=red><%'=cls.user(14)%></font>&nbsp;<%'=cls.web_unit("exp")%></td>
</tr>
<tr class=bbs_tr>
<td>体　力：</td>
<td><font class=red><%'=cls.user(15)%></font>&nbsp;<%'=cls.web_unit("strength")%></td>
</tr>
-->
</table>
<%
end sub

sub pay_special_buy()
  if int(t(26))<>2 then
    call cls.js_put("当前贴子不是购买贴！您无需进行购买。","view.asp?id="&id)
    exit sub
  end if
  dim tmpdim,tmpdim2,tmpnum,n,tmptrue,tmpdata
  tmpdim=split(t(27),",")
  if cls.chk then
    tmpdata=t(28)
    if tmpdata<>"" then
      if instr(1,","&tmpdata&",",","&cls.user(1)&",",1)>0 or instr(1,","&tmpdata&"|",","&cls.user(1)&"|",1)>0 then
        call cls.js_put("您好像已经购买过本贴内容！无需再次购买。",linkurl("view","id="&id))
        exit sub
      end if
    end if
    tmptrue=false
    if cdbl(cls.user(11))>=cdbl(tmpdim(1)) and int(cls.user(13))>=int(tmpdim(2)) and int(cls.user(14))>=int(tmpdim(3)) and int(cls.user(15))>=int(tmpdim(4)) then tmptrue=true
    if not tmptrue then
      erase tmpdim
      call cls.js_put("您当前的用户分值不足以购买本贴内容！",linkurl("view","id="&id))
      exit sub
    end if
    if tmpdata="" then
      tmpdata=cls.user(1)&"|"&cls.time_now
    else
      tmpdata=tmpdata&","&cls.user(1)&"|"&cls.time_now
    end if
    sql="update db_user set u_emoney=u_emoney-"&tmpdim(1)&",u_integral=u_integral-"&tmpdim(2)&",u_exp=u_exp-"&tmpdim(3)&",u_strength=u_strength-"&tmpdim(4)&" where userid="&cls.user(0)
    call cls.exec(sql,0)
    sql="update db_user set u_emoney=u_emoney+"&tmpdim(1)&",u_integral=u_integral+"&tmpdim(2)&",u_exp=u_exp+"&tmpdim(3)&",u_strength=u_strength+"&tmpdim(4)&" where userid="&t(9)
    call cls.exec(sql,0)
    sql="update db_bbs_topic set t_special_data='"&tmpdata&"' where t_id="&id
    call cls.exec(sql,0)
    erase tmpdim
    call cls.js_put("您已成功购买了本贴内容！",linkurl("view","id="&id))
    exit sub
  end if
%>
<table cellspacing=1 cellpadding=4 class=bbs_tables>
<tr class=bbs_td><td><%=tits%></td></tr>
<tr class=bbs_th><td>主题：<%=cls.code_html(t(3))%></td></tr>
<tr class=bbs_tr><td>
  <table border=0>
  <tr><td>购买本贴内容需：货币 <font class=red><%=tmpdim(1)%></font> <%=cls.web_unit%>、积分 <font class=red><%=tmpdim(2)%></font> <%=cls.web_unit("integral")%>、经验 <font class=red><%=tmpdim(3)%></font> <%=cls.web_unit("exp")%>、体力 <font class=red><%=tmpdim(4)%></font> <%=cls.web_unit("strength")%></td></tr>
  <form name=frm_pay action="<%=cls.web_browse_file%>" method=post>
  <input type=hidden name=_chk value="yes">
  <tr><td height=50><input type=submit name=_sbt class=btn value="我确定要购买此贴" onclick="javascirpt:return click_return('现在立即购买此贴',2);"></td></tr>
  </form>
  </table>
</td></tr>
</table>
<%=cls.ukong%>
<%
  tmpnum=0
  tmpdim=split(t(28),",")
  if t(28)<>"" then tmpnum=ubound(tmpdim)+1
%>
<table cellspacing=1 cellpadding=4 class=bbs_tables>
<tr class=bbs_td><td colspan=2>已购买用户信息(共<%=tmpnum%>人购买)</td></tr>
<tr class=bbs_th><td<%=cls.wid(1)%>>购买用户</td><td<%=cls.wid(2)%>>购买时间</td></tr>
<%
  for n=0 to ubound(tmpdim)
    if instr(tmpdim(n),"|")=0 then tmpdim(n)=tmpdim(n)&"|"
    tmpdim2=split(tmpdim(n),"|")
%>
<tr class=bbs_tr><td><%=cls.user_view(tmpdim2(0))%></td><td><%
    if tmpdim2(1)="" then
      response.write "<font class=gray>非限制用户</font>"
    else
      response.write tmpdim2(1)
    end if
%></td></tr>
<%
  next
%>
</table>
<%
  if isarray(tmpdim2) then erase tmpdim2
  erase tmpdim
end sub

sub pay_special_guerdon()
  if int(t(26))<>1 then
    call cls.js_put("当前贴子不是悬赏贴！您无法进行奖赏。","view.asp?id="&id)
    exit sub
  end if
  dim tmpdim,tmpdim2,tmpnum,n,tmptrue,tmpdata,tmpdimnew,tmpunum
  dim tmpusername,tmpemoney,tmpintegral,tmpexp,tmpstrength
  dim tmpemoneys,tmpintegrals,tmpexps,tmpstrengths
  tmpusername=cls.code_query("username")
  tmpemoney=cls.code_int("emoney",1)
  tmpintegral=cls.code_int("integral",1)
  tmpexp=cls.code_int("exp",1)
  tmpstrength=cls.code_int("strength",1)
  tmpdim=split(t(27),",")
  tmpemoneys=tmpdim(1)-tmpdim(5)
  tmpintegrals=tmpdim(2)-tmpdim(6)
  tmpexps=tmpdim(3)-tmpdim(7)
  tmpstrengths=tmpdim(4)-tmpdim(8)
  if cls.chk then
    if int(t(9))<>int(cls.user(0)) then
	    call cls.js_put("当前贴子悬赏人不是您！您无法进行奖赏。","view.asp?id="&id)
	    exit sub
  	end if
  	if tmpusername="" or lcase(tmpusername)=lcase(cls.user(1)) then
  		call cls.js_put("您要奖赏的用户不能为空或自己！","view.asp?id="&id)
	    exit sub
  	end if
  	tmpunum=cls.exec_num(now_bbs_data,"d_id","username='"&tmpusername&"' and t_id="&id)
  	if int(tmpunum)<1 then
  		call cls.js_put("回复人中没有该用户！","view.asp?id="&id)
	    exit sub
  	end if
    tmpdata=t(28)
    if tmpdata<>"" then
      if instr(1,","&tmpdata&",",","&tmpusername&",",1)>0 or instr(1,","&tmpdata&"|",","&tmpusername&"|",1)>0 then
        call cls.js_put("您好像已经奖赏过此用户！不允许重复奖赏。",linkurl("view","id="&id))
        exit sub
      end if
    end if
		if int(tmpemoney)<=0 and int(tmpintegral)<=0 and int(tmpexp)<=0 and int(tmpstrength)<=0 then
    	call cls.js_put("请输入要奖赏的分值！","pay.asp?action=special_guerdon&id="&id&"&username="&tmpusername)
    	exit sub
    end if
    tmptrue=false
    if int(tmpemoney)<=int(tmpemoneys) and int(tmpintegral)<=int(tmpintegrals) and int(tmpexp)<=int(tmpexps) and int(tmpstrength)<=int(tmpstrengths) then tmptrue=true
    if not tmptrue then
      erase tmpdim
      call cls.js_put("本贴当前剩余的悬赏分值不足以奖赏！","pay.asp?action=special_guerdon&id="&id&"&username="&tmpusername)
      exit sub
    end if
    if tmpdata="" then
      tmpdata=tmpusername&"|"&tmpemoney&"|"&tmpintegral&"|"&tmpexp&"|"&tmpstrength
    else
      tmpdata=tmpdata&","&tmpusername&"|"&tmpemoney&"|"&tmpintegral&"|"&tmpexp&"|"&tmpstrength
    end if
    tmpdimnew=tmpdim(0)&","&tmpdim(1)&","&tmpdim(2)&","&tmpdim(3)&","&tmpdim(4)&","&(tmpdim(5)+tmpemoney)&","&(tmpdim(6)+tmpintegral)&","&(tmpdim(7)+tmpexp)&","&(tmpdim(8)+tmpstrength)
    sql="update db_bbs_topic set t_special_num='"&tmpdimnew&"',t_special_data='"&tmpdata&"' where t_id="&id
    call cls.exec(sql,0)
    sql="update db_user set u_emoney=u_emoney+"&tmpemoney&",u_integral=u_integral+"&tmpintegral&",u_exp=u_exp+"&tmpexp&",u_strength=u_strength+"&tmpstrength&" where username='"&tmpusername&"'"
    call cls.exec(sql,0)
    erase tmpdim
    call cls.js_put("您已成功奖赏了该用户！",linkurl("view","id="&id))
    exit sub    
  end if
%>
<table cellspacing=1 cellpadding=4 class=bbs_tables>
<tr class=bbs_td><td><%=tits%></td></tr>
<tr class=bbs_th><td>主题：<%=cls.code_html(t(3))%></td></tr>
<tr class=bbs_tr><td>
  <table border=0 cellspacing=1 cellpadding=4>
  <tr><td>本贴剩余：货币 <font class=red><%=tmpemoneys%></font> <%=cls.web_unit%>、积分 <font class=red><%=tmpintegrals%></font> <%=cls.web_unit("integral")%>、经验 <font class=red><%=tmpexps%></font> <%=cls.web_unit("exp")%>、体力 <font class=red><%=tmpstrengths%></font> <%=cls.web_unit("strength")%></td></tr>
<%if int(t(9))=int(cls.user(0)) and lcase(tmpusername)<>"" then%>  
  <form name=frm_guerdon action="<%=cls.web_browse_file%>" method=post>
  <input type=hidden name=_chk value="yes">
  <tr><td>奖赏用户：<font class=blue><b><%=tmpusername%></b></font></td></tr>
  <tr><td>
  货币<input type=input class=txt_num name=emoney value="0" size=6 maxlength=10><%=cls.web_unit%>
  、积分<input type=input class=txt_num name=integral value="0" size=6 maxlength=10><%=cls.web_unit("integral")%>
  、经验<input type=input class=txt_num name=exp value="0" size=6 maxlength=10><%=cls.web_unit("exp")%>
  、体力<input type=input class=txt_num name=strength value="0" size=6 maxlength=10><%=cls.web_unit("strength")%>
  <input type=submit name=_sbt class=btn value="我确定要奖赏" onclick="javascirpt:return click_return('现在立即奖赏此用户',2);">
  </td></tr>
  </form>
<%end if%> 
  </table>
</td></tr>
</table>
<%=cls.ukong%>
<%
  tmpnum=0
  tmpdim=split(t(28),",")
  if t(28)<>"" then tmpnum=ubound(tmpdim)+1
%>
<table cellspacing=1 cellpadding=4 class=bbs_tables>
<tr class=bbs_td><td colspan=2>已奖赏用户信息(共奖赏了<%=tmpnum%>人)</td></tr>
<tr class=bbs_th><td<%=cls.wid(1)%>>奖赏用户</td><td<%=cls.wid(2)%>>奖赏分值</td></tr>
<%
  for n=0 to ubound(tmpdim)
    if instr(tmpdim(n),"|")=0 then tmpdim(n)=tmpdim(n)&"|"
    tmpdim2=split(tmpdim(n),"|")
%>
<tr class=bbs_tr>
<td><%=cls.user_view(tmpdim2(0))%></td>
<td>
货币 <font class=red><%=tmpdim2(1)%></font> <%=cls.web_unit%>
、积分 <font class=red><%=tmpdim2(2)%></font> <%=cls.web_unit("integral")%>
、经验 <font class=red><%=tmpdim2(3)%></font> <%=cls.web_unit("exp")%>
、体力 <font class=red><%=tmpdim2(4)%></font> <%=cls.web_unit("strength")%>
</td>
</tr>
<%
  next
%>
</table>
<%
  if isarray(tmpdim2) then erase tmpdim2
  erase tmpdim
end sub
%>