<!--#include file="user_top.asp"-->
<%
Dim DivId,rs,sql,sDisable
Dim teamId,teamname,managerid
DivId=Request("div")
If DivId="" Then DivId=11
DivId=Cint(DivId)
'没有出现编辑器的情况下进行脚本保护
If DivId=13 Or DivId=14 Then
	Call oblog.makeEditorJs
End If
'如果有TeamId,则取得该群组的基本信息
teamId=Request("teamid")
If teamId<>"" Then 
	teamId=Int(teamId)
	Set rs=oblog.Execute("Select * From oblog_team Where istate>0 and teamid=" & teamId)
	teamname=rs("t_name")
	managerid=rs("managerid")
	Set rs=Nothing
	sDisable=""
Else
	sDisable=" disabled"
End If
	
%>
<script language="javascript">
function getImg(){
	if (document.oblogform.ico.value!=""){
		document.all.imgIcon.src=document.oblogform.ico.value;
	}
}
function doMenu1(URL){
	document.getElementById("teamFrame").src=URL;
	document.getElementById("swin2").style.display = "block";
	}

//window.onload=function(){
//	var trs=user_team_left.getElementsByTagName("ol")
//	for(var i=0;i<trs.length;i++){
//		trs[i].style.backgroundColor=((i%2==0)?"#fff":"#F5FBFF");
//	}
//}
</script>
</head>
<body style="overflow:auto!important;overflow-x:hidden;background:#FFf;">
	<ul id="user_team_top">
		<li id="p13"><a href="user_team.asp"><%=P_QQ_NAME%>首页</a></li>
		<li id="p14"><a href="user_team.asp?action=creatteam">创建<%=P_QQ_NAME%></a></li>
		<li id="p15"><a href="user_team.asp?action=listmanageteam">管理的<%=P_QQ_NAME%></a></li>
		<li id="p15"><a href="user_team.asp?action=listjoinedteam">加入的<%=P_QQ_NAME%></a></li>
		<li id="p16"><a href="user_team.asp?action=members&cmd=1">发出的邀请</a></li>
		<li id="p17"><a href="user_team.asp?action=members&cmd=3">发出的申请</a></li>
	</ul>
<div id="user_team">
<%
'teamusers: state 1有效;2申请加入3被邀请4 副管理员 5 管理员
dim action,id
action=request("action")
id=trim(request("id"))
select case action
	case "listjoinedteam"
		call listjoinedteam
	case "creatteam"
		call creatteam
	case "maketeam"
		call maketeam
	case "listuser"
		call listuser
	case "invite"
		call invite
	case "exitteam"
		call exitteam
	case "teamadmin"
		call teamadmin
	case "modifystate"
		call modifystate
	case "del"
		call del
	case "modifyteaminfo"
		call modifyteaminfo
	Case "members"
		Call ListMembers("",Cint(Request("cmd")))
	Case "state"
		Call MemberState
	case "links"
		call ShowAddon(1)
	case "announce"
		call ShowAddon(2)
	case "saveaddon"
		Call SaveAddon
	case "listmanageteam"
		call listmanageteam
	Case "teammanager"
		Call teammanager
	case else
		call main
		response.Write("<div style='display:none'>")'输出一个闭合标签
end select
%>
</div>
</body>
</html>
<%
sub listmanageteam()
%>
<table  class="win_user_team_table" align="center" border="0" cellpadding="0" cellspacing="1">
	<tr>
		<td class="win_user_team_table_top" colspan="5">我管理的<%=P_QQ_NAME%></td>
	  </tr>
	  <tr>
	  	<td>序号</td><td><%=P_QQ_NAME%>名称</td><td>创建时间</td><td>帖子/成员<td>操作</td>
	  </tr>
<%
dim rs,i
set rs=oblog.execute("select a.* From oblog_team a,oblog_teamusers b Where b.userid=" & oblog.l_uid&" and a.teamid=b.teamid and b.state=5 and a.istate>0")
while not rs.eof
	i=i+1
%>
	<tr>
	<td><%=i%></td>
	<td><%="<a href=""group.asp?gid="&rs("teamid")&""" target=""_blank"">"&rs("t_name")&"</a>"%></td>
	<td><%=formatdatetime(rs("createtime"),2)%></td>
	<td><%=rs("icount2")%>/<%=rs("icount0")%></td>
	<td>
		<%
		Select Case Cint(OB_IIF(rs("istate"),2))
			Case 1			
				Response.write "待审"			
			Case 2
				Response.write "锁定"
			Case 3
			%>
			<a href="user_team.asp?action=teamadmin&teamid=<%=rs("teamid")%>">管理</a>
			<%
		End Select
	 %>
	</td>
	</td>

<%
	rs.movenext
wend
set rs=nothing
%>
</table>
<%
end sub

sub listjoinedteam()
dim rs,i
set rs=oblog.execute("Select a.teamid,a.t_name,b.addtime,b.post_all From oblog_team a,oblog_teamusers b Where a.teamid=b.teamid And b.userid=" & oblog.l_uid & " And b.state=3")
%>
<table  class="win_user_team_table" align="center" border="0" cellpadding="0" cellspacing="1">
	  <tr>
		<td class="win_user_team_table_top" colspan="5">我加入的他人创建的<%=P_QQ_NAME%></td>
	  </tr>
	  <tr>
	  	<td>序号</td><td><%=P_QQ_NAME%>名称</td><td>加入时间</td><td>帖数<td>操作</td>
	  </tr>
	  	<%
If rs.Eof Then
	Response.Write "<tr><td colspan=5>未加入他人创建的" &P_QQ_NAME & "</td></tr>"
Else
	Do while not rs.eof
		i=i+1
		
	%>
		<tr>
	  	<td><%=i%></td>
	  	<td><a href="group.asp?gid=<%=rs("teamid")%>" target=_blank><%=rs("t_name")%></a></td>
	  	<td><%=OB_IIF(rs("addtime"),"")%></td>
	  	<td><%=OB_IIF(rs("post_all"),0)%></td>
		<td><a href="user_team.asp?action=exitteam&teamid=<%=rs("teamid")%>" onclick="if (confirm('确认要退出该<%=P_QQ_NAME%>吗?')==false) return false;">退出</a></td>
	  </tr>
	<%
	rs.movenext
	Loop
End If
set rs=nothing
%>
</table>
<%
end sub

Sub creatteam()      '创建圈子页面部分
	Dim rs
	If oblog.l_Group(16,0)=0 Then
		oblog.AddErrStr ("您目前所属的等级目前不允许创建新的" &P_QQ_NAME)
	    oblog.showUserErr
	    Response.End
	End if
	'检查之前是够有待审核的申请
	Set rs=oblog.Execute("Select t_name From oblog_team Where istate=1 And managerid=" & oblog.l_uid)
	If Not rs.Eof Then
		oblog.adderrstr("您之前创建的 " & rs(0) & " 还没有被审核通过，不能再创建新的" &P_QQ_NAME)
		oblog.showusererr
		rs.Close
	End If
	'检查目前管理的总数
	Set rs=oblog.Execute("Select count(teamid) From oblog_team Where  managerid=" & oblog.l_uid)
	If rs(0)>=oblog.l_Group(16,0) Then
		oblog.adderrstr("您目前已管理 " & rs(0) & " 个" &P_QQ_NAME& "，达到系统的限额。" )
		oblog.showusererr
		rs.Close
	End If
	Set rs=Nothing
%>
<form name="oblogform" method="post" action="user_team.asp?action=maketeam" >
	<table  class="win_user_team_table" align="center" border="0" cellpadding="0" cellspacing="1" >
	  <tr>
		<td class="win_user_team_table_top" colspan="2">创建新<%=P_QQ_NAME%></td>
	  </tr>
	  <tr>
		<td class="win_user_team_table_td"><%=P_QQ_NAME%>名称：</td>
		<td><input type="text" name="name" size="30"></td>
	  </tr>
	  <tr>
		<td class="win_user_team_table_td">标记图片(120*90)</td>
		<td><div class="user_face"><img src="images/default_groupico.gif" id="imgIcon" width=120 height=90>
		<p><iframe id="d_file" frameborder="0" src="upload.asp?tMode=9&re=" width="300" height="80" scrolling="no"></iframe>
			<br/>图像地址，只支持jpg,gif,png,尺寸为120*90<br/>
			外部调用：<input name="ico" id="ico" type="text" value="images/default_groupico.gif" size="50" maxlength="200" onblur="getImg();">
			<br/>你可以直接输入一个有效的图片地址,也可以在这里直接选择一个系统可用的图片</p></div></td>
	  </tr>
	   <tr>
		<td class="win_user_team_table_td"><%=P_QQ_NAME%>类别：</td>
		<td>
		<select name="classid" id="classid" >
		<%=oblog.show_class("log",0,2)%>
		</select>		
		</td>
	  </tr>
	  <tr>
		<td class="win_user_team_table_td"><%=P_QQ_NAME%>标签：</td>
		<td><input type="text" name="tags" size="50">(最多支持5个，以逗号间隔)</td>
	  </tr>
	  <tr>
		<td class="win_user_team_table_td"><%=P_QQ_NAME%>加入条件：</td>
		<td><input type="radio" name="t1" value="-1">任意加入 <input type="radio" name="t1" value="0"checked>申请加入 <input type="radio" name="t1" value="1">仅可邀请<br/> <input type="radio" name="t1" value="2">积分限制，需大于<input type=text name="t2" size=5 maxlength=8>积分才能申请</td>
	  </tr>
	  <!--
	  <tr>
		<td class="win_user_team_table_td">是否允许非成员参与讨论：</td>
		<td><input type="radio" name="t3" value="1" checked>是 <input type="radio" name="t3" value="0">否</td>
	  </tr>
	  -->
	  <tr>
		<td class="win_user_team_table_td"><%=P_QQ_NAME%>申请说明<br/>管理员审核用：</td>
		<td><textarea rows="5" name="intro" cols="45"></textarea></td>
	  </tr>
	  <tr>
		<td colspan="2" align="center"><input type="submit" value=" 提交 " name="B1">　　　<input type="reset" value=" 重置 " name="B2"></td>
	  </tr>
	</table>
</form>
<%
End sub

Sub MakeTeam()
	Dim rs
	Set rs=Server.CreateObject("Adodb.Recordset")
    If oblog.l_Group(16,0)=0 Then
		oblog.AddErrStr ("您目前所属的等级目前不允许创建新的" &P_QQ_NAME)
	    oblog.showUserErr
	    Response.End
	End If
	If oblog.l_uScores<CLng(oblog.CacheScores(11)) Then
		oblog.AddErrStr ("您的积分不足，无法申请" &P_QQ_NAME)
	    oblog.showUserErr
	    Response.End
	End if
	'检查之前是够有待审核的申请
	Set rs=oblog.Execute("Select t_name From oblog_team Where istate=1 And managerid=" & oblog.l_uid)
	If Not rs.Eof Then
		oblog.adderrstr("您之前创建的 " & rs(0) & " 还没有被申请通过，不能再创建新的" &P_QQ_NAME)
		oblog.showusererr
		rs.Close
	End If
	'检查目前管理的总数
	Set rs=oblog.Execute("Select count(teamid) From oblog_team Where  managerid=" & oblog.l_uid)
	If rs(0)>=oblog.l_Group(16,0) Then
		oblog.adderrstr("您目前已管理 " & rs(0) & " 个" &P_QQ_NAME& "，达到系统的限额。" )
		rs.Close
		oblog.showusererr
	End If
	rs.Close
    Dim name, intro, sql, teamid, str,ico,tags,t1,t2,t3,tid,classid
    name = oblog.filt_badword(Trim(request.Form("name")))
    intro = Trim(request.Form("intro"))
	ico = Trim(request.Form("ico"))
    t1 = Trim(request.Form("t1"))
    t2 = Trim(request.Form("t2"))
    t3 = Trim(request.Form("t3"))
	classid = Trim(request.Form("classid"))
	if classid="" then
		oblog.showok "" &P_QQ_NAME& "分类不能为空！",""
	else
		classid=clng(classid)
	end if
    If name="" Then
    	oblog.showok "名称不能为空！",""
		exit sub
    Else
    	name=Left(name,50)
	End If
	If intro="" Then
    	oblog.showok "申请说明不能为空！",""
		exit sub
    Else
    	intro=Left(intro,240)
	End If
	If t1="2"  Then
		If  t2="" Or Not isNumeric(t2) Then
			oblog.showok "请输入加入时的积分限制",""
			exit sub
	     Eles
	     	t2=Int(t2)
	     End If
	Else
		t2=0
	End If
	
    rs.Open "select * from oblog_team where t_name='" & name & "'",conn,1,3
    If Not rs.EOF Then
        Set rs = Nothing
    	oblog.showok "此" & P_QQ_NAME & "名已经存在！",""
		exit sub
    Else
    	rs.AddNew
    	rs("t_name")=name
    	rs("t_ico")=ico
    	rs("joinlimit")=t1
    	rs("joinscores")=t2
    	rs("otherpost")=0
    	rs("createrid")=oblog.l_uid
    	rs("creatername")=oblog.l_uname
    	rs("managerid")=oblog.l_uid
    	rs("managername")=oblog.l_uname
    	rs("createtime")=ServerDate(Now)
    	If oblog.CacheConfig(49) = 1 Then 
			rs("istate")=1
		Else 
			rs("istate")=3
		End if
    	rs("icount0")=1
    	rs("intro")=intro
		rs("classid")=classid
    	rs.Update
    	rs.Close
    	rs.Open "Select Max(teamid) From oblog_team Where createrid=" & oblog.l_uid
    	tid=rs(0)
    	rs.Close
    	oblog.Execute "Insert into oblog_teamusers(teamid,userid,state) values (" & tid & "," & oblog.l_uid & ",5)"
		oblog.GiveScore "" ,-1*Abs(oblog.CacheScores(11)),""
    	str = "" & P_QQ_NAME & ":" & name &"提交完成"
		If oblog.CacheConfig(49) = 1 Then str=str & "正在等待管理员审核"
    	oblog.showok str, "user_team.asp"
    End If
End Sub


Sub listuser()
	teamadmin_top()
	Dim grade,i
	sql="select state from oblog_teamusers where userid="&oblog.l_uid&" and teamid="&teamid&" and state=5"
	set rs=oblog.execute(sql)
	if rs.eof or rs.bof then
		set rs=nothing
		oblog.adderrstr("您的权限不足,操作无法完成！")
		oblog.showusererr
	end if
%>
	<table  class="win_user_team_table" align="center" border="0" cellpadding="0" cellspacing="1">
		<tr>
			<td class="win_user_team_table_top" colspan="4" name="_teammember"><%=P_QQ_NAME%>用户管理</td>
 		</tr>
 		<form method="POST" action="user_team.asp?action=invite&teamid=<%=teamid%>">
		<tr>
		<td class="win_user_team_table_td">想邀请的用户：</td>
		<td colspan=3><input type="text" name="T1" size="20">
		　　<input type="submit" value=" 提交 " name="B3"></td>
		</tr>
	</form>
	<% If oblog.l_uid=managerid Then%>
 		<form method="POST" action="user_team.asp?action=teammanager&teamid=<%=teamid%>">
		<tr>
		<td class="win_user_team_table_td">转让<%=P_QQ_NAME%>：</td>
		<td colspan=3><input type="text" name="T1" size="20">
		　　<input type="submit" value=" 提交 " name="B3"></td>
		</tr>
	</form>
	<%End if%>
 			<tr><td>排序</td><td>用户名称</td><td>用户等级</td><td>管理操作</td></tr>
<%
	set rs=oblog.execute("select a.username,b.state,b.userid,b.id from oblog_teamusers b,oblog_user a where a.userid=b.userid and b.teamid="&teamid&" and b.state<>4")
	while not rs.eof
		select case cint(rs(1))
			case 3
				grade="普通用户"
			case 1
				grade="受邀但尚未回应"
			case 2
				grade="申请加入"
			case 5
				grade="管理员"
		end Select
		If rs(2)=managerid Then grade = grade & "<font color=red>（群主）</font>"
		i=i+1
%>
	<tr>
		<td><%=i%></td>
		<td><a href='blog.asp?name=<%=rs(0)%>' target="_blank"><%=rs(0)%></a></td>
		<td><%=grade%></td>
		<td><%select case cint(rs(1))
			case 3
		%> <a href="user_team.asp?action=del&state=1&userid=<%=rs(2)%>&teamid=<%=teamid%>">删除</a>&nbsp; <a href="user_team.asp?action=modifystate&g1=3&g2=5&userid=<%=rs(2)%>&teamid=<%=teamid%>">升为管理员</a> <%  case 1%>
		<a href="user_team.asp?action=del&state=1&userid=<%=rs(2)%>&teamid=<%=teamid%>">删除邀请</a>&nbsp; <%  case 2%>
		<a href="javascript:openScript('user_pm.asp?action=readteam&id=<%=rs(3)%>',450,380)"> 查看申请 </a>&nbsp;<a href="user_team.asp?action=modifystate&g1=2&g2=3&userid=<%=rs(2)%>&teamid=<%=teamid%>">同意申请</a>&nbsp;<a href="user_team.asp?action=del&state=2&userid=<%=rs(2)%>&teamid=<%=teamid%>"> 拒绝 </a><%  case 5%>
		<a href="user_team.asp?action=modifystate&g1=5&g2=3&userid=<%=rs(2)%>&teamid=<%=teamid%>">降为普通用户</a>&nbsp;
	<a href="user_team.asp?action=del&state=5&userid=<%=rs(2)%>&teamid=<%=teamid%>">删除</a><%end select%></td>
	</tr>

<%
	rs.movenext
wend
rs.close
%>
</table>

<%
end sub


Sub ExitTeam()

    Dim teamid, sql, rs, str, name
    teamid = request.QueryString("teamid")
    sql = "select t_name from oblog_team where teamid=" & teamid & ""
    Set rs = oblog.Execute(sql)
    name = rs(0)
    rs.Close
    sql = "select userid from oblog_teamusers where teamid=" & teamid & " and userid=" & oblog.l_uid & " and state=5"
    rs.open sql, conn, 1, 1
    If rs.recordcount = 1 Then
        str = "您是" & P_QQ_NAME & name & "的管理员,无法退出该" & P_QQ_NAME & ",若要退出请先转移管理员权限"
        oblog.adderrstr (str)
        oblog.showusererr
    End If
    sql = "delete from oblog_teamusers where (teamid=" & teamid & " and userid=" & oblog.l_uid & " and state=3) or (teamid=" & teamid & " and userid=" & oblog.l_uid & " and state=5)"
    oblog.Execute (sql)
    str = "成功退出了" & P_QQ_NAME & ":" & name & ",您已不再是" & name & "的正式成员"
    oblog.showok str, ""
End Sub

sub teamadmin()
%>
 	<!--群组信息-->
	<%
	dim i,grade
	set rs=oblog.execute("select state from oblog_teamusers where userid="&oblog.l_uid&" and teamid="&teamid)
	if not rs.eof then
		if rs(0)<>5 then oblog.adderrstr ("无权限")
	else
		oblog.adderrstr ("无权限")
	end if
	if oblog.errstr<>"" then
		set rs=nothing
		oblog.showusererr
		exit sub
	end if
	set rs=oblog.execute("select * from oblog_team where teamid="&teamid&"")
	ReCountTeamInfo(teamid)
	teamadmin_top()
%>

<form name="oblogform" method="post" action="user_team.asp?action=modifyteaminfo&teamid=<%=teamid%>">
<table  class="win_user_team_table" align="center" border="0" cellpadding="0" cellspacing="1">
	  <tr>
		<td class="win_user_team_table_top" colspan="2">修改<%=P_QQ_NAME%>信息</td>
	  </tr>
	  <tr>
		<td class="win_user_team_table_td"><%=P_QQ_NAME%>名称：</td>
		<td><input type="text" name="name" size="30" value="<%=rs("t_name")%>" disabled></td>
	  </tr>
	  <tr>
		<td class="win_user_team_table_td">标记图片(120*90)</td>
		<td><div class="user_face"><img id="imgIcon" width=120 height=90 src="<%=oblog.filt_html(OB_IIF(rs("t_ico"),""))%>">
		<p><iframe id="d_file" frameborder="0" src="upload.asp?tMode=9&re=" width="300" height="80" scrolling="no"></iframe>
			<br/>图像地址，只支持jpg,gif,png,尺寸为120*90<br/>
			外部调用：<input name="ico"  type="text" value="<%=oblog.filt_html(rs("t_ico"))%>" size="50" maxlength="200" / onblur="getImg();">
			<br/>你可以直接输入一个有效的图片地址,也可以在这里直接选择一个系统可用的图片</p></div></td>
	  </tr>
	  <tr>
		<td class="win_user_team_table_td"><%=P_QQ_NAME%>标签：</td>
		<td><input type="text" name="tags" size="50" value="<%=rs("t_tags")%>">(最多支持5个，以逗号间隔)</td>
	  </tr>
	  <tr>
		<td class="win_user_team_table_td"><%=P_QQ_NAME%>加入条件：</td>
		<td>
			<input type="radio" name="t1" value="-1" <%If rs("joinlimit")=-1 Then Response.Write " checked" End If%>>任意加入	
			<input type="radio" name="t1" value="0" <%If rs("joinlimit")=0 Then Response.Write " checked" End If%>>申请加入	
			<input type="radio" name="t1" value="1" <%If rs("joinlimit")=1 Then Response.Write " checked" End If%>>仅可邀请<br/> 
			<input type="radio" name="t1" value="2"  <%If rs("joinlimit")=2 Then Response.Write " checked" End If%>>积分限制，需大于<input type=text name="t2" size=5 maxlength=8 value="<%=rs("joinscores")%>">积分才能申请</td>
	  </tr>
	  <tr>
		<td class="win_user_team_table_td"><%=P_QQ_NAME%>申请说明<br/>不进行前台显示：</td>
		<td><textarea rows="5" name="intro" cols="45"><%=rs("intro")%></textarea></td>
	  </tr>
	  <tr>
		<td colspan="2" align="center"><input type="submit" value=" 提交 " name="B1">　　　<input type="reset" value=" 重置 " name="B2"></form></td>
	  </tr>
	</table>
</form>
<%
end sub


sub modifystate()
	
	dim g1,g2,sql,rs,userid,teamid,str
	g1=clng(request.QueryString("g1"))
	g2=clng(request.QueryString("g2"))  'g1是原始状态,G2是目标状态
	userid=clng(request.QueryString("userid"))
	teamid=clng(request.QueryString("teamid"))
	sql="select state from oblog_teamusers where userid="&oblog.l_uid&" and teamid="&teamid&""
	set rs=oblog.execute(sql)
	
	If userid=managerid Then
		oblog.adderrstr("您无权对群主进行操作！")
		oblog.showusererr
		Exit Sub
	end If
	
	if cint(rs(0))<>5 then
		oblog.adderrstr("您的权限不足,操作无法完成！")
		oblog.showusererr
	end if
	rs.close
	if g1=5 then
		sql="select state from oblog_teamusers where state=5 and teamid="&teamid&""
		rs.open sql,conn,1,1
		if rs.recordcount=1 then
			str="该管理员是"&P_QQ_NAME&"中唯一的管理员,无法降级"
			oblog.adderrstr(str)
			oblog.showusererr
		end if
	end if
	
	set rs=nothing
	
	sql="update oblog_teamusers set state="&g2&" where userid="&userid&" and state="&g1&" and teamid="&teamid&""
	oblog.execute(sql)
	oblog.showok "用户状态修改成功",""
end sub

Sub del()
	dim state,teamid,userid,sql,rs,str
	
	state=clng(request("state"))
	teamid=clng(request("teamid"))
	userid=clng(request("userid"))
	
	sql="select state from oblog_teamusers where userid="&oblog.l_uid&" and teamid="&teamid&""
	set rs=oblog.execute(sql)

	If userid=managerid Then
		oblog.adderrstr("您无权对群主进行操作！")
		oblog.showusererr
		Exit Sub
	end if	

	if cint(rs(0))<>5 then
		oblog.adderrstr("您的权限不足,操作无法完成！")
		set rs=nothing
		oblog.showusererr
		exit sub
	end if
	set rs=server.CreateObject("adodb.recordset")
	if state=5 then
		sql="select state from oblog_teamusers where state=5 and teamid="&teamid&""
		rs.open sql,conn,1,1
		if rs.recordcount=1 then
			str="该管理员是"&P_QQ_NAME&"中唯一的管理员,无法删除"
			oblog.adderrstr(str)
			oblog.showusererr
			exit sub
		end if
	end if	
	
	sql="delete from oblog_teamusers where teamid="&teamid&" and userid="&userid&""
	oblog.execute(sql)
	oblog.showok "成功删除相关信息",""
end sub

sub modifyteaminfo()
	Dim name, rs, intro, sql, str,ico,tags,t1,t2,t3
    intro = Trim(request.Form("intro"))
	ico = Trim(request.Form("ico"))
    t1 = Trim(request.Form("t1"))
    t2 = Trim(request.Form("t2"))
    t3 = Trim(request.Form("t3"))
	If intro="" Then
    	oblog.adderrstr ("介绍不能为空！")
        oblog.showusererr
    Else
    	intro=Left(intro,240)
	End If
	If t1="2"  Then
		If  t2="" Or Not isNumeric(t2) Then
			oblog.adderrstr ("请输入加入时的积分限制")
	        oblog.showusererr
	     Else
	     	t2=Int(t2)
	     End If
	Else
		t2=0
	End If
	Set rs=Server.CreateObject("Adodb.Recordset")
    rs.Open "select * from oblog_team where teamid=" & teamid & " And managerid=" & oblog.l_uid,conn,1,3
    If Not rs.EOF Then
    	rs("t_ico")=ico
    	rs("joinlimit")=t1
    	rs("joinscores")=t2
    	rs("intro")=intro
    	rs.Update
    	str = "" & P_QQ_NAME & "信息修改完成"
    Else
    	str = "" & P_QQ_NAME & "信息不存在"
    End If
    rs.Close
    Set rs=Nothing
    oblog.showok str, ""
End sub

sub invite()
	dim username,rs,id,teamid,sql,str
	username=oblog.filt_badstr(trim(request.Form("t1")))
	teamid=clng(request.QueryString("teamid"))
	sql="select userid from oblog_user where username='"&username&"'"	
	set rs=oblog.execute(sql)
	If rs.Eof Then
		str="用户名"&username&"不存在"
	Else
		id=clng(rs(0))
		set rs=oblog.execute("Select * From oblog_teamusers Where teamid=" & teamid & " And userid=" & id)
		
		if rs.eof then
			sql="insert into oblog_teamusers (teamid,userid,state) values("&teamid&","&id&",1)"
			oblog.execute(sql)
			str="成功向"&username&"发出邀请"
		else
			Select Case rs("state")
				Case 3
					str="此用户已经是" &P_QQ_NAME& "的成员"
				Case 1
					str="此用户已经被邀请了"
				Case 2
					str="此用户已经发出申请，请通过审核即可"
				Case 5
					str="此用户是" &P_QQ_NAME& "管理员,不需要进行申请"
			End Select
		End If
	end if
	Set rs=Nothing
	oblog.showok str,""
end sub

'teamusers: state 1被邀请2申请加入3成员4 副管理员 5 管理员
Sub ListMembers(teamid,cmd)
	Dim sTitle,i,SqlPart,grade
	i=0
	If teamid<>"" Then SqlPart="And b.teamid=" & Int(teamid) & " "
	Select Case cmd
		Case 1
			sTitle="我发出的邀请"
			Sql="Select a.userid,c.username,a.addtime,b.teamid,b.t_name,a.state From oblog_teamusers a,oblog_team b,oblog_user c  Where a.teamid=b.teamid And state=1 And a.userid=c.userid  And a.userid<>" & oblog.l_uid &" And b.managerid=" & oblog.l_uid & SqlPart
		Case 2
			sTitle="我接收到的邀请"
			Sql="Select a.userid,c.username,a.addtime,b.teamid,b.t_name,a.state From oblog_teamusers a,oblog_team b,oblog_user c  Where a.teamid=b.teamid And state=1 And a.userid=c.userid  And a.userid=" & oblog.l_uid &" And b.managerid<>" & oblog.l_uid & SqlPart
		Case 3
			sTitle="我发出的申请"
			Sql="Select a.userid,c.username,a.addtime,b.teamid,b.t_name,a.state From oblog_teamusers a,oblog_team b,oblog_user c  Where a.teamid=b.teamid And state=2 And a.userid=c.userid  And a.userid=" & oblog.l_uid &" And b.managerid<>" & oblog.l_uid & SqlPart
		Case 4			
			sTitle="我接收到的申请"
			Sql="Select a.userid,c.username,a.addtime,b.teamid,b.t_name,a.state,a.info From oblog_teamusers a,oblog_team b,oblog_user c  Where a.teamid=b.teamid And state=2 And a.userid=c.userid  And a.userid<>" & oblog.l_uid &" And b.managerid=" & oblog.l_uid & SqlPart
	End Select
	'Response.Write Sql
	Set rs=oblog.execute(Sql)

%>
	<table  class="win_user_team_table" align="center" border="0" cellpadding="0" cellspacing="1">
		<tr>
			<td class="win_user_team_table_top" colspan="6" name="_teammember"><%=sTitle%></td>
 		</tr>
 			<tr><td>序号</td><td><%=P_QQ_NAME%>名称</td><td>用户名称</td><td>时间</td><td>状态</td><td>管理操作</td></tr>
 		<%
 		If rs.Eof Then
 		%>
 		<tr><td colspan="6">没有相关数据</td></tr>
	<%		
		Else
			while not rs.eof
			select case cint(rs("state"))
				case 3
					grade="普通用户"
				case 2
					grade="申请待批准"
				case 1
					grade="受邀但尚未回应"
				case 5
					grade="管理员"
			end select
			i=i+1
	%>
		<tr>
			<td><%=i%></td>
			<td><a href="group.asp?gid=<%=rs("teamid")%>" target="_blank"><%=rs("t_name")%></a></td>
			<td><a href="go.asp?userid=<%=rs("userid")%>" target="_blank"><%=rs("username")%></a></td>
			<td><%=rs("addtime")%></td>
			<td><%=grade%></td>
			<td>
			<%
			Select Case cmd
				Case 1
					%>
					<a href="user_team.asp?action=state&cmd=1&state=0&userid=<%=rs("userid")%>&teamid=<%=rs("teamid")%>">取消邀请</a>
					<%
				Case 2
					%>					
					<a href="user_team.asp?action=state&cmd=2&state=3&userid=<%=rs("userid")%>&teamid=<%=rs("teamid")%>">接受</a>&nbsp;&nbsp;
					<a href="user_team.asp?action=state&cmd=2&state=0&userid=<%=rs("userid")%>&teamid=<%=rs("teamid")%>">拒绝</a>
					<%
				Case 3
					%>
					<a href="user_team.asp?action=state&cmd=3&state=0&userid=<%=rs("userid")%>&teamid=<%=rs("teamid")%>">取消申请</a>
					<%
				Case 4
					%>
					<a href="user_team.asp?action=state&cmd=4&state=3&userid=<%=rs("userid")%>&teamid=<%=rs("teamid")%>" title="<%=oblog.filt_html(rs("info"))%>">接受</a>&nbsp;&nbsp;
					<a href="user_team.asp?action=state&cmd=4&state=0&userid=<%=rs("userid")%>&teamid=<%=rs("teamid")%>" title="<%=oblog.filt_html(rs("info"))%>" >拒绝</a>
			<%
			End Select
			%>
			</td>
		</tr>					
	
	<%
			rs.movenext
		wend
	End If
	rs.close
%>
</table>
<%
End sub

Sub MemberState()
	Dim userId,sMsg,iState
	userid=Int(Request("userid"))
	iState=Cint(Request("state"))
	Select Case Int(Request("cmd"))
		Case 1
			'取消邀请(由管理员操作)
			Set rs=oblog.execute("Select teamid From oblog_team Where teamid=" & teamid & " And managerid=" & oblog.l_uid)
			If Not rs.Eof Then
				oblog.execute "Delete From oblog_teamusers Where userid=" & userid & " And teamid=" & teamId 
				sMsg="已取消对该用户的邀请"
			Else
				sMsg="您无权取消对该用户的邀请"
			End If
			Set rs=Nothing
		Case 2
			'接受邀请/拒绝邀请(由被邀请人操作)
			If iState=3 Then
				oblog.Execute "Update oblog_teamusers Set state=" & iState & " Where userid=" & oblog.l_uid & " And teamid=" & teamid
				sMsg="已接受该用户的邀请"
			Else
				oblog.execute "Delete From oblog_teamusers Where userid=" & oblog.l_uid & " And teamid=" & teamId 
				sMsg="已拒绝该用户的邀请"
			End If
		Case 3
			'取消申请(由申请人操作)
			oblog.execute "Delete From oblog_teamusers Where userid=" & oblog.l_uid & " And teamid=" & teamId 
			sMsg="您已取消对该" &P_QQ_NAME& "的加入申请"			
		Case 4
			'接受申请/拒绝申请(由管理员操作)
			Set rs=oblog.execute("Select teamid From oblog_team Where teamid=" & teamid & " And managerid=" & oblog.l_uid)
			If Not rs.Eof Then
				If iState=3 Then
					oblog.Execute "Update oblog_teamusers Set state=" & iState & " Where userid=" & userid & " And teamid=" & teamid
					sMsg="已接受该用户的申请"
				Else
					oblog.execute "Delete From oblog_teamusers Where userid=" & userid & " And teamid=" & teamId 
					sMsg="已拒绝该用户的申请"
				End If
			Else
				sMsg="您无权对该用户的申请进行操作"
			End If
			Set rs=Nothing
	End Select
	oblog.showok sMsg, "user_team.asp?action=memebers&cmd=" & Request("cmd")
End Sub

Sub SaveAddon()
    Dim rs,sType,sField,sTitle,sDesc,sContent
	sField=Request("itype")
	If  sField="1" Then
		sField="links"
		sTitle=P_QQ_NAME& "友情连接"
		sDesc="你可以在这里放置" &P_QQ_NAME& "的与其他站点、博客等的连接"
	Else
		sField="announce"
		sTitle=P_QQ_NAME& "公告"
		sDesc="你可以在这里放置" &P_QQ_NAME& "的介绍，或者你愿意放上去的任何信息"
	End If
    sContent = FilterJS(oblog.filt_astr(request.Form("edit"), 20000))
    Set rs = server.CreateObject("adodb.recordset")
    rs.open "select "& sField &" from oblog_team where teamid=" & teamid, conn, 1, 3
    rs(0) =  oblog.filtpath(sContent)
    rs.Update
    rs.Close
    Set rs = Nothing
    oblog.showok "修改" & sTitle & "成功", ""
End Sub

Sub ShowAddon(itype)
	Dim rs,sField,sTitle,sDesc
	If  itype="1" Then
		sField="links"
		sTItle=P_QQ_NAME& "友情连接"
		sDesc="你可以在这里放置" &P_QQ_NAME& "的与其他站点、博客等的连接"
	Else
		sField="announce"
		sTitle=P_QQ_NAME& "公告"
		sDesc="你可以在这里放置" &P_QQ_NAME& "的介绍，或者你愿意放上去的任何信息"
	End If
	
	Set rs = oblog.execute("select " & sField & " from oblog_team where teamid=" & teamid)
	teamadmin_top()
%>

	<table  class="dTab12_body" align="center" border="0" cellpadding="0" cellspacing="1">
	<tbody>
	  <form name="oblogform" method="post" action="user_team.asp?action=saveaddon&itype=<%=itype%>&teamid=<%=teamid%>" onSubmit="submits(); ">
	  <tr>
		<td colspan="2" class="dTab12_body_top"><%=sTitle%></td>
	  </tr>
	  <tr>
		<td class="dTab12_body_td"><%=sDesc%>
		</td>
	 </tr>
	 <tr>
		<td> 
		<span id="loadedit" style="font-size:12px"><img src='images/loading.gif' align='absbottom'> 正在载入编辑器...</span>
		 <textarea id="edit" name="edit" style="width:60%;height:220px; display:none"><%=Server.HtmlEncode(OB_IIF(rs(0),""))%></textarea >
  		</td>
  	</tr>
   <tr><td>
    &nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="Submit" value="提交修改" />
     </td>
	  </tr>
    </form>
	</tbody>
  </table>
 <%oblog.MakeEditorText "",1,"535","240"%>
<%
Set rs = Nothing
End Sub

sub teamadmin_top()
%>
	<ul class="user_setting_title" id="TabPage1">
	<li id="Tab00" <%If divId=00 Then%>class="Selected"<%End If%>><a href="group.asp?gid=<%=teamid%>" target="_blank" title="<%=teamname%>"><strong><%=teamname%></strong></a></li>
	<li id="Tab11"  <%If divId=11 Then%>class="Selected"<%End If%>><a href="user_team.asp?action=teamadmin&teamid=<%=teamid%>&div=11" ><%=P_QQ_NAME%>信息</a></li>
	<li id="Tab12"  <%If divId=12 Then%>class="Selected"<%End If%>><a href="user_team.asp?action=listuser&teamid=<%=teamid%>&div=12" >成员管理</a></li>
	<li id="Tab13"  <%If divId=13 Then%>class="Selected"<%End If%>><a href="user_team.asp?action=announce&teamid=<%=teamid%>&div=13"><%=P_QQ_NAME%>公告</a></li>
	<li id="Tab14"  <%If divId=14 Then%>class="Selected"<%End If%>><a href="user_team.asp?action=links&teamid=<%=teamid%>&div=14">友情链接</a></li>
</ul>
<%end sub

Sub ReCountTeamInfo(teamid)
	Dim rst,c1,c2,c3,c4
	Set rst=oblog.execute("Select Count(userid) From oblog_teamusers Where teamid=" & teamid)
	If not rs.Eof Then
		c1=OB_IIf(rst(0),0)
	Else
		c1=0
	End If	
	Set rst=oblog.execute("Select Count(postid) From oblog_teampost Where idepth=0 And teamid=" & teamid)
	If not rs.Eof Then
		c2=OB_IIf(rst(0),0)
	Else
		c2=0
	End If	
	Set rst=oblog.execute("Select Count(postid) From oblog_teampost Where idepth>0 And teamid=" & teamid)
	If not rs.Eof Then
		c3=OB_IIf(rst(0),0)
	Else
		c3=0
	End If	
	oblog.execute "Update oblog_team Set iCount0=" & c1 & ",iCount1=" & c2 & ",iCount2=" & c3 & " Where teamid=" & teamid
	Set rst=Nothing
End Sub

sub main()%>
	<div class="left" id="user_team_left">
		<div>最近话题</div>
	<%show_grouplist()%>
	</div>
	<div class="right">
		<div>我的<%=P_QQ_NAME%></div>
	<%show_mygroup()%>
	</div>
<%
end  sub

sub show_grouplist()
	dim rs,str,sql
	sql="select top 10 a.topic,a.postid,a.lastupdate,a.teamid,c.t_name,d.username,d.nickname from oblog_teampost a,oblog_teamusers b,oblog_team c,oblog_user d where a.iDepth=0 and b.userid="&oblog.l_uid&" and a.teamid=b.teamid and a.teamid=c.teamid and c.istate=3 and (b.state=3 or b.state=5) and a.userid=d.userid order by a.postid desc"
	set rs=oblog.execute(sql)
	while not rs.eof
		str=str&"<ol><li class=""l1""><a href=""group.asp?gid="&rs("teamid")&"&pid="&rs("postid")&""" title="""&rs("topic")&""" target=""_blank"">"&rs("topic")&"</a></li><li class=""l2""><a title="""&ob_iif(rs("username"),rs("nickname"))&" 发表于"&FmtMinutes(rs("lastupdate"))&"前"">"&ob_iif(rs("username"),rs("nickname"))&" 发表于"&FmtMinutes(rs("lastupdate"))&"前</a><span>来自：<a title=""来自："&rs("t_name")&""">"&rs("t_name")&"</a></span></li></ol>"
		rs.movenext
	wend
	response.Write(str)
	set rs=nothing
end sub

sub show_mygroup()
	dim rs,str,sql
	set rs=oblog.execute("select a.teamid,a.t_name,a.createtime,a.istate,a.icount0,a.icount1,a.icount2,a.t_ico,b.state From oblog_team  a,oblog_teamusers b Where b.userid=" & oblog.l_uid&" and a.teamid=b.teamid and b.state>2 and a.istate>0 order by b.state desc ")
	while not rs.eof
		str=str&"<ul>"
		str=str&"<li class=""left""><a href=""group.asp?gid="&rs("teamid")&""" title=""点击查看" &P_QQ_NAME& "："&rs("t_name")&""" target=""_blank""><img src='"&rs("t_ico")&"' /></a></li>"
		str=str&"<li class=""right"">"
		str=str&"	<ol>"
		str=str&"		<li class=""o1""><a href=""group.asp?gid="&rs("teamid")&""" class=""left"" title=""点击查看" &P_QQ_NAME& "："&rs("t_name")&""" target=""_blank"">"&rs("t_name")&"</a>"
		Select Case Cint(OB_IIF(rs("istate"),2))
			Case 1			
			str=str&"<font color=""#0000FF"">待审</font>"			
			Case 2
			str=str&"<font color=""#ff0000"">锁定</font>"
			Case 3
				if rs("state")>3 then
					str=str&"<a href='user_team.asp?action=teamadmin&teamid="&rs("teamid")&"' class=""right"">管理</a>"
				end if
		end select
		str=str&"</li>"
		str=str&"		<li class=""o2"">创建时间："&rs("createtime")&"</li>"
		str=str&"		<li class=""o3""><span class=""left"">贴数："&rs("icount2")&"篇</span><span class=""right"">成员："&rs("icount0")&"人</span></li>"
		str=str&"	</ol>"
		str=str&"</li>"
		str=str&"</ul>"
		rs.movenext
	wend
	response.Write(str)
	set rs=nothing
end Sub
'转让群主
sub teammanager()
	dim username,rs,id,teamid,sql,str
	username=oblog.filt_badstr(trim(request.Form("t1")))
	teamid=clng(request.QueryString("teamid"))
	sql="select userid from oblog_user where username='"&username&"'"	
	set rs=oblog.execute(sql)
	If rs.Eof Then
		str="用户名"&username&"不存在"
	Else
		id=clng(rs(0))

		Set rs = oblog.execute ("select * from oblog_teamusers where teamid= " & teamid & " And userid = " &id)

		If rs.eof Then 
			oblog.adderrstr ("此用户非本" &P_QQ_NAME& "成员！")
	        oblog.showusererr
			Exit Sub
		End if  
		Dim trs
		If Not IsObject(conn) Then link_database
		Set trs = server.CreateObject("adodb.recordset")
		trs.open "select * from oblog_team where teamid=" & teamid & " And managerid=" & oblog.l_uid ,conn,1,3

		If Not trs.eof Then
			trs("managerid")= id 
			trs("managername") = username
			trs.update
			oblog.execute ("update oblog_teamusers set state= 5 where teamid=" & teamid & " And userid=" & id)
			str="转让群主成功！"
		Else 
			trs.close
			oblog.adderrstr ("无权操作！")
	        oblog.showusererr
			Exit Sub
		End If
		Set trs=Nothing
	End If
	oblog.showok str,""
end sub
%>