<!-- #include file="setup.asp" -->
<%
if Request.Cookies("username")=empty then error("<li>您还未<a href=login.asp>登录</a>社区")

id=int(Request("id"))

sql="select * from [user] where username='"&Request.Cookies("username")&"'"
Set Rs=Conn.Execute(sql)
faction=rs("faction")
experience=rs("experience")
money=rs("money")
rs.close

top


if Request("menu")="factionadd" then
if faction<>"" then error("<li>您已经加入 "&faction&" 了！<li>请先退出 "&faction&" 才能加入新帮派！")

factionname=Conn.Execute("Select factionname From faction where id="&id&"")(0)
conn.execute("update [user] set faction='"&factionname&"' where username='"&Request.Cookies("username")&"'")

message=message&"<li>加入成功<li><a href=faction.asp>返回社区帮派</a><li><a href=Default.asp>返回论坛首页</a>"
succeed(""&message&"<meta http-equiv=refresh content=3;url=faction.asp>")
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
elseif Request("menu")="factionout" then
if faction=empty then error("<li>您目前没有加入任何帮派！")
if request.cookies("username")=conn.execute("select [buildman] from [faction] where factionname='"&faction&"'")(0) then error("<li>帮主不能退出自己创建的帮派！")
conn.execute("update [user] set faction='' where username='"&Request.Cookies("username")&"'")
message=message&"<li>退出帮派成功<li><a href=faction.asp>返回社区帮派</a><li><a href=Default.asp>返回论坛首页</a>"
succeed(""&message&"<meta http-equiv=refresh content=3;url=faction.asp>")
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
elseif Request("menu")="factiondel" then

sql="select * from faction where id="&id&""
Set Rs1=Conn.Execute(sql)
if rs1("buildman")<>""&Request.Cookies("username")&"" then error("<li>您不是该帮的帮主无法解散该帮")
conn.execute("update [user] set faction='' where faction='"&rs1("factionname")&"'")
conn.execute("delete from [faction] where id="&id&"")
message=message&"<li>解散帮派成功<li><a href=faction.asp>返回社区帮派</a><li><a href=Default.asp>返回论坛首页</a>"
succeed(""&message&"<meta http-equiv=refresh content=3;url=faction.asp>")
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
elseif Request("menu")="look" then
sql="select * from faction where id="&id&""
Set Rs=Conn.Execute(sql)
%>
<table border=0 width=97% align=center cellspacing=1 cellpadding=4 class=a2>
<tr class=a3>
<td height=25>&nbsp;<img src=images/Forum_nav.gif>&nbsp; <%ClubTree%> → 
<a href="faction.asp">社区帮派</a></td>
</tr>
</table><br>

<title><%=rs("factionname")%> - Powered By BBSxp</title>

<table width="82%" border="0" align="center" cellspacing="1" cellpadding="2"  class=a2 height="150">
<tr bgcolor="FFFFFF">
<td width="15%">
<div align="center"><font color="000066"><b>帮派简称:</b></font></div>
</td>
<td width="82%"><%=rs("factionname")%></td>
</tr>
<tr bgcolor="FFFFFF">
<td width="15%">
<div align="center"><font color="000066"><b>帮派名称:</b></font></div>
</td>
<td width="82%"><%=rs("allname")%></td>
</tr>
<tr bgcolor="FFFFFF">
<td width="15%">
<div align="center"><font color="000066"><b>帮派宗旨:</b></font></div>
</td>
<td width="82%"><%=rs("tenet")%></td>
</tr>
<tr bgcolor="FFFFFF">
<td width="15%">
<div align="center"><font color="000066"><b>创建时间:</b></font></div>
</td>
<td width="82%"><%=rs("addtime")%></td>
</tr>
<tr bgcolor="FFFFFF">
<td width="15%">
<div align="center"><font color="000066"><b>帮主名称:</b></font></div>
</td>
<td width="82%"><%=rs("buildman")%></td>
</tr>
<tr bgcolor="FFFFFF">
<td width="15%">
<div align="center"><font color="000066"><b>现有会员:</b></font></div>
</td>
<td width="82%">
<%
sql="select username from [user] where faction='"&rs("factionname")&"'"
Set Rs=Conn.Execute(sql)
Do While Not RS.EOF
i=i+1
list=list&""&rs("username")&" "
RS.MoveNext
loop
%><%=i%>人</td>
</tr>

<tr bgcolor="FFFFFF">
<td width="15%">
<div align="center"><font color="000066"><b>会员名单:</b></font></div>
</td>
<td width="82%">
<%=list%>
</td>
</tr>

</table>
<br><center><INPUT onclick=history.back(-1) type=button value=" << 返 回 ">
<%

htmlend

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
elseif Request("menu")="addok" then

factionname=HTMLEncode(Request("factionname"))
allname=HTMLEncode(Request("allname"))
tenet=HTMLEncode(Request("tenet"))


if faction<>empty then message=message&"<li>您已经加入了帮派！"

if experience< 5000 then message=message&"<li>您的经验值小于 5000 ！"

if money< 5000 then message=message&"<li>您的金币少于 5000 ！"

if factionname="" then message=message&"<li>帮派简称没有填写"

if Len(factionname)>7 then message=message&"<li>帮派简称最多7个字符"

if allname="" then message=message&"<li>帮派名称没有填写"

if tenet="" then message=message&"<li>帮派宗旨没有填写"

if message<>"" then error(""&message&"")




sql="insert into faction (factionname,allname,tenet,buildman) values ('"&factionname&"','"&allname&"','"&tenet&"','"&Request.Cookies("username")&"')"
conn.Execute(SQL)

conn.execute("update [user] set faction='"&factionname&"',[money]=[money]-5000 where username='"&Request.Cookies("username")&"'")


message=message&"<li>创建帮派成功<li><a href=faction.asp>返回社区帮派</a><li><a href=Default.asp>返回论坛首页</a>"
succeed(""&message&"<meta http-equiv=refresh content=3;url=faction.asp>")
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
elseif Request("menu")="xiuok" then

factionname=HTMLEncode(Request("factionname"))
allname=HTMLEncode(Request("allname"))
tenet=HTMLEncode(Request("tenet"))
mess=HTMLEncode(Request("mess"))
wages=HTMLencode(request("money"))
num=conn.execute("select count(id) from [user] where faction='"&factionname&"'")(0)

for j=1 to num
   if request.Form("check"&j)<>empty then
      if request.form("check"&j)=conn.execute("select [buildman] from [faction] where factionname='"&faction&"'")(0) then error("<li>不能踢出帮主！！")
      conn.execute("update user set [faction]='',[newmessage]=[newmessage]+1 where username='"&request.Form("check"&j)&"'")
	  conn.execute("insert into message(author,incept,content) values('"&request.Cookies("username")&"','"&request.Form("check"&j)&"','【帮派信息】由于种种原因，帮主决定将你逐出帮外。')")
      end if
next
if factionname="" then message=message&"<li>帮派简称没有填写"
if Len(factionname)>7 then message=message&"<li>帮派简称最多7个字符"
if allname="" then message=message&"<li>帮派名称没有填写"
if tenet="" then message=message&"<li>帮派宗旨没有填写"
if wages<0 then message=message&"<li>工资负数！你想剥削你的成员？"
if money<num*wages then message=messages&"<li>你没那么多现金啦。"
if message<>"" then error(""&message&"")

if wages<>0 then
sql="select * from [user] where faction='"&factionname&"'"
  rs.Open sql,Conn,1,3
  do while not rs.eof
     rs("money")=rs("money")+wages
	 rs.update
	 conn.execute("update [user] set [money]=[money]-"&wages&" where username='"&request.Cookies("username")&"'")
     rs.movenext
  loop 
  rs.close
end if
   
if mess<>"" then
  sql="select * from [user] where faction='"&factionname&"'"
  rs.Open sql,Conn,1,3
  do while not rs.eof
     rs("newmessage")=rs("newmessage")+1
     rs.update
     conn.execute "insert into message(author,incept,content)values('"&request.cookies("username")&"','"&rs("username")&"','"&mess&"')"
     rs.movenext
  loop 
  rs.close
end if

sql="select * from faction where id="&id&""
rs.Open sql,Conn,1,3
oldfactionname=rs("factionname")
rs("factionname")=factionname
rs("allname")=allname
rs("tenet")=tenet
rs.update
rs.close

conn.execute("update [user] set faction='"&factionname&"' where faction='"&oldfactionname&"'")
message=message&"<li>修改帮派成功<li><a href=faction.asp>返回社区帮派</a><li><a href=Default.asp>返回论坛首页</a>"
succeed(""&message&"<meta http-equiv=refresh content=3;url=faction.asp>")
end if



%>
<center>

<table border=0 width=97% align=center cellspacing=1 cellpadding=4 class=a2>
<tr class=a3>
<td height=25>&nbsp;<img src=images/Forum_nav.gif>&nbsp; <%ClubTree%> → 
<a href="faction.asp">社区帮派</a></td>
</tr>
</table><br>
<%
if Request("menu")="add" then

%>
<form method=post name=form action=faction.asp?menu=addok>

<table cellspacing=1 cellpadding=2 width=442 border=0 align="center" class=a2>
<tr class=a1>
<td width=526 colspan="2" align="center" height="25">
创建门派</td>
</tr>
<tr class=a3>
<td width=187 align="right">
<b><font color="0033CC">帮派简称：</font></b></td>
<td width=339>
<input maxlength=7 name=factionname size="10"> 最多7个字符</td>
</tr>
<tr class=a3>
<td width=187>
<div align="right"><b><font color="0033CC">帮派名称： </font></b></div>
</td>
<td width=339>
<input size=30 name=allname>
</td>
</tr>
<tr class=a3>
<td width=187 height=15>
<div align="right"><b><font color="0033CC">帮派宗旨： </font></b></div>
</td>
<td width=339 height=15>
<input size=40 name=tenet>
</td>
</tr>
<tr class=a3>
<td width=526 colspan=2 height=8>
<div align=center>
<input type=submit value=" 创 建 " name=Submit23>
<input type=reset value=" 重 填 " name=Submit24>
</div>
</td>
</tr>
<tr class=a3>
<td width=526 colspan=2 height=7>
<ol>
创建门派的必要条件：
<li>您的经验值必须 5000 以上
<li>需要扣除您身上 5000 金币作为门派基金 </li>
</td>
</tr>
</table>


</form>



<%
elseif Request("menu")="xiu" then
if Conn.Execute("Select buildman From [faction] where id="&id&"")(0)<>Request.Cookies("username")then error("<li>您不是该帮的帮主无法管理")
sql="select * from faction where id="&id&""
Set Rs=Conn.Execute(SQL)
%>


<form method=post action=faction.asp?menu=xiuok&id=<%=rs("id")%>>
<SCRIPT>valigntop()</SCRIPT>
<table cellpadding="2" cellspacing="1" width="97%" border="0" class=a2>

<tr>
<td colspan="2" height="25" align="center" class=a1>　　门派管理</td>
</tr>


<tr class=a3>
<td>　　帮派简称： </td>
<td>
<input size="20" maxlength=7 name="factionname" value="<%=rs("factionname")%>"> 
最多7个字符</td>
</tr>
<tr class=a3>
<td>　　帮派名称： </td>
<td><input size="30" name="allname" value="<%=rs("allname")%>"> </td>
</tr>
<tr class=a3>
<td>　　帮派宗旨： </td>
<td><input size="60" name="tenet" value="<%=rs("tenet")%>"> </td>
</tr>
<tr class=a3>
<td>　　帮内短信： </td>
<td><input size="60" name="mess" value=""><font color=red>不发送短信此处留空</font></td>
</tr>
<tr class=a3>
<td>　　成员工资： </td>
<td><input size="5" name="money" value="0"><font color=red>请勿用负数</font></td>
</tr>
<tr class=a3>
<td colSpan="2">
<table cellpadding="2" cellspacing="1" width="100%" border="0" class=a2>
<tr class=a1 align=center>
<td width=20% >用户名称</td>
<td width=15% >社区金币</td>
<td width=15% >用户经验</td>
<td width=12% >发表文章</td>
<td width=12% >回复文章</td>
<td width=10% >被删文章</td>
<td width=10% >精华文章</td>
<td width=5% >踢人</td>
</tr>
<%set rsf=conn.execute("select * from [user] where faction='"&rs("factionname")&"'")
allmoney=0
allexp=0
alltopic=0
allrevert=0
alldel=0
allgood=0
if rsf.eof then
response.write "<tr><td bgcolor=a3>无人加入此帮</td></tr>"
else
  i=1
  do while not rsf.eof
  response.write "<tr class=a3 align=center><td>"&rsf("username")&"</td><td>"&rsf("money")&"</td><td>"&rsf("experience")&"</td><td>"&rsf("posttopic")&"</td><td>"&rsf("postrevert")&"</td><td>"&rsf("deltopic")&"</td><td>"&rsf("goodtopic")&"</td><td><input type=checkbox name=check"&i&" value="&rsf("username")&"></td></tr>"
  allmoney=allmoney+rsf("money")
  allexp=allexp+rsf("experience")
  alltopic=alltopic+rsf("posttopic")
  allrevert=allevert+rsf("postrevert")
  allgood=allgood+rsf("goodtopic")
  alldel=alldel+rsf("deltopic")
  i=i+1 
  rsf.movenext
  loop
  response.write"<tr class=a1 align=center><td>本帮对社区的贡献</td><td>"&allmoney&"</td><td>"&allexp&"</td><td>"&alltopic&"</td><td>"&allrevert&"</td><td>"&alldel&"</td><td>"&allgood&"</td><td></td>"
end if
rsf.close
set rsf=nothing%>
</table>
</td>
</tr>
<tr class=a3>
<td colSpan="2">
<div align="center">
<input type="submit" value=" 执 行 " name="Submit">
<input type="reset" value=" 重 填 " name="Submit2">
</div>
</td>
</tr>
</table>
<SCRIPT>valignbottom()</SCRIPT>
</form>


<%
else
%>


<p>&nbsp;<a href="?menu=add"><img src="images/plus/niu05.gif" width="26" height="26" border="0"><img src="images/plus/cj.gif" width="95" height="26" border="0"></a>　　　　<a href="?menu=factionout"><img src="images/plus/niu05.gif" width="26" height="26" border="0"><img src="images/plus/tc.gif" width="95" height="26" border="0"></a><br>
</p>

<SCRIPT>valigntop()</SCRIPT>
<table border="0" cellpadding="5" cellspacing="1" class=a2 width=97%>
<tr>
<td width="15%" align="center" height="25" class=a1>派别</td>
<td width="40%" align="center" height="25" class=a1>宗旨</td>
<td width="15%" align="center" height="25" class=a1>创始人</td>
<td width="10%" align="center" height="25" class=a1>动作</td>
<td width="20%" align="center" height="25" class=a1>帮主管理</td>
</tr>


<%
faction=Conn.Execute("Select faction From [user] where username='"&Request.Cookies("username")&"'")(0)

 
sql="select * from faction order by addtime Desc"
rs.Open sql,Conn,1


pagesetup=20 '设定每页的显示数量
rs.pagesize=pagesetup
TotalPage=rs.pagecount  '总页数
PageCount = cint(Request.QueryString("ToPage"))
if PageCount <1 then PageCount = 1
if PageCount > TotalPage then PageCount = TotalPage
if TotalPage>0 then rs.absolutepage=PageCount '跳转到指定页数

i=0
Do While Not RS.EOF and i<pagesetup
i=i+1





%>

<tr>
<td width="10%" align="center" height="25" bgcolor="FFFFFF"> <a href=faction.asp?menu=look&id=<%=rs("id")%>><%=rs("factionname")%></a>
<td width="50%" align="center" height="25" bgcolor="FFFFFF"><%=rs("tenet")%>
<td width="10%" align="center" height="25" bgcolor="FFFFFF"><a href=Profile.asp?username=<%=rs("buildman")%>><%=rs("buildman")%></a>
<td width="10%" align="center" height="25" bgcolor="FFFFFF"><%
if faction=rs("factionname") then
response.write "<a onclick=checkclick('您确定要退出该帮派？') href=?menu=factionout>退出</a>"
else
response.write "<a onclick=checkclick('您确定要加入该帮派？') href=?menu=factionadd&id="&rs("id")&">加入</a>"
end if
%>
<td width="20%" align="center" height="25" bgcolor="FFFFFF"><a href="?menu=xiu&id=<%=rs("id")%>">管理</a>&nbsp;&nbsp;<a onclick=checkclick('您确定要解散该帮派？') href="?menu=factiondel&id=<%=rs("id")%>">解散</a></td>
</tr>

<%
RS.MoveNext
loop
RS.Close
%>

</table>
<SCRIPT>valignbottom()</SCRIPT>
Page：[
<script>
PageCount=<%=TotalPage%> //总页数
topage=<%=PageCount%>   //当前停留页

for (var i=1; i <= PageCount; i++) {
if (i <= topage+3 && i >= topage-3 || i==1 || i==PageCount){
if (i > topage+4 || i < topage-2 && i!=1 && i!=2 ){document.write(" ... ");}
if (topage==i){document.write(" "+ i +" ");}
else{
document.write("<a href=?topage="+i+">"+ i +"</a> ");
}
}
}
</script>
 ]<br>

<%
end if



%><%
htmlend
%>