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

<!--#include file="conn.asp"-->
<%
'---------------------
' write by 绿水青山 for 动网6.0
' 本插件经由 gafc 修改适应leadbbs3.14
'---------------------
DEF_BBS_HomeUrl = "../../"
opendatabase

dim stats
stats="<a href=write.asp>点歌控制面板</a>"
BBS_SiteHead DEF_SiteNameString & " " & DEF_BBS_Name,GBL_board_ID," >> "&stats

dim rs,sql
dim isfull,founderr,Errmsg
Errmsg=""
isfull=false
founderr=false		

'头部信息
If GBL_TableHeadString <> "" Then 
   response.write "<table width="&DEF_BBS_ScreenWidth&" border=0 cellspacing=0 cellpadding=0 align=center><tr><td>"& GBL_TableHeadString &"</td></tr></table>"
End If
		
if GBL_CHK_User="" then
   errmsg=errmsg&"<li>客人不可以查阅点歌列表。</li>"
   errmsg=errmsg&"<li>请先<a href="&DEF_BBS_HomeUrl&"user/userjoin.asp>注册</a>或<a href="&DEF_BBS_HomeUrl&"user/login.asp>登录</a>。</li>"
   call Errormsg()
   response.end
else
%>
<table width="<%=DEF_BBS_ScreenWidth%>" border=0 cellspacing=1 cellpadding=5 align=center bgcolor=<%=DEF_BBS_DarkColor%> class=TBone>
  <tr bgcolor=<%=DEF_BBS_LightDarkColor%> align=center class=tbhead2>
     <td><a href=listall.asp><font class=headfont><b>所有点歌列表</b></font></a></td>
     <td><a href=listme.asp><font class=headfont><b>我的点歌列表</b></font></a></td>
     <td><a href=write.asp><font class=headfont><b>我要点歌</b></font></a></td>
  </tr>
  <tr>
     <td class=tablebody2 align=center valign=middle colspan="3">点首歌曲祝福你的好友</td>
  </tr>
</table>

<% 
dim lincept,lcontent,lmedianame,lurl
dim successmsg

lincept=replace(trim(Request.Form("incept")),"'","")
lcontent=replace(Request.Form("content"),"'","")
lcontent=replace(server.htmlencode(lcontent),chr(13)," ")
lmedianame=replace(trim(server.htmlEncode(Request.Form("medianame"))),"'","")
lurl=trim(server.htmlEncode(Request.Form("url")))

  if lincept="" then 
	errmsg=errmsg&"<li>请输入接收用户名</li>"
	founderr=true
  else
	if instr(lincept,"全体会员")>0 then
		lincept="全体会员"
		isfull=true
	else 	
		lincept=split(lincept,"|")
		if ubound(lincept)>=5 then
			errmsg=errmsg&"<li>最多只能发送给5个用户</li>"
			founderr=true
		end if
	end if	
  end if
  if lmedianame="" then 
	errmsg=errmsg&"<li>请输入歌曲名</li>"
	founderr=true
  end if
  if lurl="" or lurl="http://" then 
	errmsg=errmsg&"<li>请正确输入音乐地址</li>"
	founderr=true
  end if
  if lcontent="" then 
	errmsg=errmsg&"<li>请输入祝福语</li>"	
	founderr=true
  end if
  if len(lmedianame)>50 then '--------------判断名字
	errmsg=errmsg&"<li>歌曲名不能多于50字</li>"
	founderr=true	
  end if
  if len(lcontent)>200 then '--------------判断名字
	errmsg=errmsg&"<li>祝福语不能多于200字</li>"
	founderr=true	
  end if
  if founderr=true then
     call Errormsg()
     response.end
  end if
	dim haverr      '是否有不存在的用户
	haverr=false
	call updata()
	call CloseDB()
	call success()
  '尾部信息
   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
end if
'===================================
sub updata()
	dim ii

	if isfull then
			set rs=server.createobject("adodb.recordset")
			sql="select * from media" 
			rs.open sql,connDG,3,2
			rs.addnew
			rs("sender")=GBL_CHK_User
			rs("incept")=lincept
			rs("sendtime")=now()
			rs("content")=lcontent
			rs("medianame")=lmedianame
			rs("url")=lurl
                        if lincept="全体会员" then
                        rs("acceptuser")="|"
                        end if
			rs.update
			rs.close
			set rs=nothing
			errmsg=""
			successmsg="<li>点歌祝福已成功发出!<br><li>你向论坛所有的会员发送了点歌祝福</li><br><br>"	
	else	
		for ii=0 to ubound(lincept)
			set rs=server.createobject("adodb.recordset")
			sql="select username from [leadbbs_user] where username='"&lincept(ii)&"'"
			rs.open sql,con,1,1
			if rs.eof and rs.bof then
				errmsg=errmsg&"<li>论坛没有<font color=red>["&lincept(ii)&"]</font>这个用户"
				haverr=true
			else
				rs.close
				set rs=server.createobject("adodb.recordset")
				sql="select * from [leadbbs_user] where username='"&GBL_CHK_User&"'"
				rs.open sql,con,1,3 
				if rs("points")-minpoints<0 then  
					errmsg=errmsg&"<li>您的积分已经低于<font color=#FF0000>"&minpoints&"</font>，不能再点歌了。每点一首歌将花费您<font color=#FF0000>"&points1&"</font>积分</li>"
					haverr=true
				else
				rs("points")=rs("points")-points1   
				rs.update
				rs.close
				
				sql="select * from media" 
				rs.open sql,connDG,3,2
				rs.addnew
				rs("sender")=GBL_CHK_User
				rs("incept")=lincept(ii)
				rs("sendtime")=now()
				rs("content")=lcontent
				rs("medianame")=lmedianame
				rs("url")=lurl
				rs.update
				rs.close
				set rs=nothing
				
				dim sender,title,body
				sender=GBL_CHK_User
				title="送给您的祝福"
				body=Sender&" 点了一首歌 "&lmedianame&" 给你！"&chr(10)&"祝福语："&lcontent&" "&chr(10)
				sql="insert into LeadBBS_InfoBox(ToUser,FromUser,title,Content,sendtime,ReadFlag,IP) values('"&lincept(ii)&"','"&sender&"','"&title&"','"&body&"',"&GetTimeValue(now)&",0,'"&GBL_IPAddress&"')"
				con.Execute(sql)
                                con.execute("update leadbbs_user set MessageFlag=1 where username='"&lincept(ii)&"'")
				successmsg=successmsg+"<br><li>点歌祝福已成功发出!系统已向<font color=red><b>["&lincept(ii)&"]</b></font>发出短消息通知，并自动扣除您<font color=#FF0000><b>"&points1&"</b></font>积分！</li>"
				end if
			end if	
		next
	end if		
end sub

sub success()
%>
<table width="<%=DEF_BBS_ScreenWidth%>" border=0 cellspacing=1 cellpadding=5 align=center bgcolor=<%=DEF_BBS_DarkColor%> class=TBone>
  <tr bgcolor=<%=DEF_BBS_LightDarkColor%> align=center class=tbhead2>
      <td colspan="2" width="100%"><b>点歌发送情况</b></td>
  </tr>
  <tr class=tbbg1> 
      <td width="100%"><%if haverr then%><b>操作结果:</b><br><br><%=errmsg%><br><%=successmsg%><%else%><b>操作成功:</b><br><br><%=successmsg%><%end if%></td>
  </tr>
  <tr align="center" class=tbbg1> 
      <td width="100%">
	<a href="javascript:history.go(-1)"> << 返回上一页</a>
      </td>
  </tr>  
</table>
<%
end sub
%>