<%@ LANGUAGE=VBScript codepage ="936" %>
<!--#include file="../../showchat.asp"-->
<!--#include file="../../const3.asp"-->
<%
Response.Expires=0
Response.ExpiresAbsolute = Now() - 1
Response.AddHeader "Pragma","No-Cache"
Response.AddHeader "Cache-Control","Private"
Response.CacheControl = "No-Cache"
cwjh_name=Session("cwjh_name")
cwjh_grade=Session("cwjh_grade")
cwjh_jhdj=Session("cwjh_jhdj")
nowinroom=session("nowinroom")
if cwjh_name="" then Response.Redirect "../../error.asp?id=440"
chatbgcolor=Application("cwjh_chatbgcolor")
chatimage=Application("cwjh_chatimage")
if chatbgcolor="" then chatbgcolor="008888"
cwjh_roominfo=split(Application("cwjh_room"),";")
chatinfo=split(cwjh_roominfo(session("nowinroom")),"|")
useronlinename=Application("cwjh_useronlinename"&session("nowinroom"))
id=trim(request("id"))
if InStr(id,"or")<>0 or InStr(id,"=")<>0 or InStr(id,"`")<>0 or InStr(id,"'")<>0 or InStr(id," ")<>0 or InStr(id,"　")<>0 or InStr(id,"'")<>0 or InStr(id,chr(34))<>0 or InStr(id,"\")<>0 or InStr(id,",")<>0 or InStr(id,"<")<>0 or InStr(id,">")<>0 then Response.Redirect "../../error.asp?id=54"
Set conn=Server.CreateObject("ADODB.CONNECTION")
Set rs=Server.CreateObject("ADODB.RecordSet")
conn.open Application("cwjh_usermdb")
rs.open "select * FROM 用户 WHERE 姓名='"&cwjh_name&"'",conn,1,3
if rs("转生")<2 then
	rs.close
	set rs=nothing	
	conn.close
	set conn=nothing
	Response.Write "<script language=JavaScript>{alert('提示：转生达到2次才能建立组队!');location.href = 'javascript:history.go(-1)';}</script>"
	Response.End
end if
if rs("组队")=false then
	rs.close
	set rs=nothing	
	conn.close
	set conn=nothing
	Response.Write "<script language=JavaScript>{alert('提示：请先打开组队状态!');location.href = 'javascript:history.go(-1)';}</script>"
	Response.End
end if
rs.close
select case id
case "建立组队"
zum=trim(request("zhm"))
zum=replace(zum,"'","''")
if zum="" or len(zum)<2 then
	Response.Write "<script language=JavaScript>{alert('提示：组名太短或不能为空!');location.href = 'javascript:history.go(-1)';}</script>"
	Response.End
end if
if len(zum)>6 then
	Response.Write "<script language=JavaScript>{alert('提示：组名太长!');location.href = 'javascript:history.go(-1)';}</script>"
	Response.End
end if
rs.open "select * from [组队] where 组长='"&cwjh_name&"'",conn,1,3
if not(rs.eof or rs.bof) then
	zm=rs("组名")
        rs.close
	set rs=nothing	
	conn.close
	set conn=nothing
	Response.Write "<script language=JavaScript>{alert('提示：你已经建立过一个组了，组名["&zm&"]！');location.href = 'javascript:history.go(-1)';}</script>"
	Response.End	
else
    conn.execute "insert into 组队 (组名,组长,时间,组员,组员数) values ('"&zum&"','"&cwjh_name&"','"&now()&"','"&cwjh_name&"',1)"
    conn.execute "update 用户 set 组名='"&zum&"' where 姓名='" & cwjh_name &"'"
	says="<font color=red>【组队消息】"&cwjh_name&"建立了组,组名["&zum&"]，赶快联系"&cwjh_name&"一起参加杀怪行动吧。</font>"
	Response.Write "<script language=JavaScript>{alert('提示：建立组队成功！如果组名含有不文明字符，你的账号将会被删除！');location.href = 'index.asp';}</script>"
   end if
 rs.close
case "删除组队"
rs.open "select * from [组队] where 组长='"&cwjh_name&"'",conn,1,1
if rs.eof or rs.bof then
        rs.close
	set rs=nothing	
	conn.close
	set conn=nothing
	Response.Write "<script language=JavaScript>{alert('提示：你没有建立组队，无此权限！');location.href = 'javascript:history.go(-1)';}</script>"
	Response.End	
else
   	conn.execute "update 用户 set 组名='无' where 组名='" &rs("组名")&"'"
   	sqlstr="delete * from 组队 where 组长='"&cwjh_name&"'"
	conn.Execute sqlstr
        says="<font color=red>【删除组队】"&cwjh_name&"删除了组队,（"&cwjh_name&"），所有组员解散。</font>"
	Response.Write "<script language=JavaScript>{alert('提示：删除组成功，所有组员解散！');location.href = 'javascript:history.go(-1)';}</script>"
end if
rs.close
case "添加组员"
to1=trim(request("to1"))
rs.open "select 组队,组名 FROM 用户 WHERE 姓名='"&to1&"'",conn
if rs.eof or rs.bof then
        rs.close
	set rs=nothing	
	conn.close
	set conn=nothing
	Response.Write "<script language=JavaScript>{alert('提示："&to1&"信息出错，请确认是否有此人');location.href = 'javascript:history.go(-1)';}</script>"
	Response.End	
end if
if rs("组队")=false  then
        rs.close
	set rs=nothing	
	conn.close
	set conn=nothing
	Response.Write "<script language=JavaScript>{alert('提示："&to1&"没有打开组队状态！禁止加组！');location.href = 'javascript:history.go(-1)';}</script>"
	Response.End	
end if
if rs("组名")<>"" and rs("组名")<>"无" then
        rs.close
	set rs=nothing	
	conn.close
	set conn=nothing
	Response.Write "<script language=JavaScript>{alert('提示："&to1&"已经有组了，不要重复加入，如果不是你的组，让他先退组！');location.href = 'javascript:history.go(-1)';}</script>"
	Response.End	
end if
rs.close
if Instr(useronlinename,""&to1&"")=0 then
Response.Write "<script Language=Javascript>alert('“" & to1 & "”不在聊天室中，不能加组。');location.href = 'javascript:history.go(-1)';</script>"
Response.end
end if
rs.open "select * from [组队] where 组长='"&cwjh_name&"'",conn,1,1
if rs.eof or rs.bof then
        rs.close
	set rs=nothing	
	conn.close
	set conn=nothing
	Response.Write "<script language=JavaScript>{alert('提示：你没有建立组，不要乱闯！');location.href = 'javascript:history.go(-1)';}</script>"
	Response.End	
else
	badword=rs("组员")
	if instr("," &badword&",",","&to1&",")<>0 then
        rs.close
	set rs=nothing	
	conn.close
	set conn=nothing
	Response.Write "<script language=JavaScript>{alert('提示："&to1&"已经在组里面了啊！');location.href = 'javascript:history.go(-1)';}</script>"
	Response.End	
end if
	if rs("组员数")>=cwjh_zudui then
        rs.close
	set rs=nothing	
	conn.close
	set conn=nothing
	Response.Write "<script language=JavaScript>{alert('提示："&to1&"不能加入,组内人数已经达到系统限制的"&cwjh_zudui&"人！');location.href = 'javascript:history.go(-1)';}</script>"
	Response.End	
end if
badword=badword&","&to1
conn.execute "update 用户 set 组名='"&rs("组名")&"' where 姓名='" & to1 &"'"
sqlstr="update 组队 set 组员='"&badword&"',组员数=组员数+1 where 组名='" &rs("组名")&"'"
conn.Execute sqlstr
says="<font color=#ff0000>【组队消息】</font><font color=blue>添加组员["&cwjh_name&"]把["&to1&"]加入了自己组，可以共同进步了</font>"
end if 
rs.close
Response.Write "<script language=JavaScript>{alert('提示："&to1&"添加成功！');location.href = 'javascript:history.go(-1)';}</script>"
case "删除组员"
to1=trim(request("to1"))
if to1=cwjh_name then
	Response.Write "<script language=JavaScript>{alert('提示：组长不可以删除自己，请删除组操作');location.href = 'javascript:history.go(-1)';}</script>"
	Response.End	
end if
rs.open "select 组队,组名 FROM 用户 WHERE 姓名='"&to1&"'",conn
if rs.eof or rs.bof then
        rs.close
	set rs=nothing	
	conn.close
	set conn=nothing
	Response.Write "<script language=JavaScript>{alert('提示："&to1&"信息出错，请确认是否有此人');location.href = 'javascript:history.go(-1)';}</script>"
	Response.End	
end if
tozm=rs("组名")
rs.close
rs.open "select * from [组队] where 组长='"&cwjh_name&"'",conn,1,1
if rs.eof or rs.bof then
        rs.close
	set rs=nothing	
	conn.close
	set conn=nothing
	Response.Write "<script language=JavaScript>{alert('提示：你没有建立组，不要乱闯！');location.href = 'javascript:history.go(-1)';}</script>"
	Response.End	
else
zuname=rs("组名")
if tozm<>zuname then
        rs.close
	set rs=nothing	
	conn.close
	set conn=nothing
	Response.Write "<script language=JavaScript>{alert('提示："&to1&"不是你的组员！');location.href = 'javascript:history.go(-1)';}</script>"
	Response.End	
end if
	badword=rs("组员")
	if instr("," &badword&",",","&to1&",")=0 then
        rs.close
	set rs=nothing	
	conn.close
	set conn=nothing
	Response.Write "<script language=JavaScript>{alert('提示："&to1&"不在组里面了啊！');location.href = 'javascript:history.go(-1)';}</script>"
	Response.End	
end if
badword=Replace(","&badword&",",","&to1&",",",")
badlan=cint(len(badword))
badword=right(badword,badlan-1)
badword=left(badword,badlan-2)
conn.Execute "update 用户 set 组名='无' where 姓名='"&to1&"'"
conn.Execute "update 组队 set 组员='"&badword&"',组员数=组员数-1 where 组名='"&zuname&"'"
conn.Execute "update 组队 set 组员数=1 where 组员数<=0"
conn.Execute "update 用户 set 魅力=魅力-100 where 姓名='"&to1&"'"
says="<font color=#ff0000>【组队消息】</font> <font color=blue>踢出组员"&cwjh_name&"把组员（"&to1&"）踢出了组，（"&to1&"）想到日后前途渺茫，感觉很没有面子，魅力丢失100。</font>"
end if
Response.Write "<script language=JavaScript>{alert('提示："&to1&"踢出成功！');location.href = 'javascript:history.go(-1)';}</script>"
rs.close
case else
 Response.Write "<script language=JavaScript>{alert('提示：命令有错！');location.href = 'javascript:history.go(-1)';}</script>"
 Response.End
end select
set rs=nothing
conn.close
set conn=nothing
call showchat(says)
%>
</body></html>