﻿<!--#include file="../Inc.asp"-->
<!--#include file="../ydzq.asp"-->
<% 
dim nam,roomadmin,txt,TP,ID
nam=usb(request("nam"))
TP=usb(request("TP"))
ID=usb(request("id"))
roomadmin=request("roomadmin")

set rs=Server.CreateObject("ADODB.Recordset")
rs.open"select * from Chat Where roomadmin2<>0  order by id desc",conn,1,1
If Not rs.eof Then

if Instr(","&rs("roomadmin")&",",","&myid&",") > 0 then
  Call Error("<card id=""main"" title=""出错"" ><p>一个会员只可以建立一个聊天室！")
end if
end if
rs.close
set rs=nothing


if roomadmin="0" then
  Call Error("<card id=""main"" title=""出错"" ><p>密码不能为0！")
end if
txt=usb(request("txt"))

IF TP<>"" then

if ID="" or IsNumeric(ID) = False then
  Call Error("<card id=""main"" title=""出错"" ><p>ID无效！")
end if
response.write"<card id=""main"" title=""编辑聊天室"" ><p>"
else
response.write"<card id=""main"" title=""自建聊天室"" ><p>"
end if

if nam="" then
  Call Error("名称不能为空！")
end if

set rs=Server.CreateObject("ADODB.Recordset")
IF TP<>"" then
rs.open"select * from chat where ID="&ID,conn,1,2
else
rs.open"select * from chat",conn,1,2
rs.addnew
end if
rs("roomname")=nam
if roomadmin<>"" then 
rs("roomadmin2")=roomadmin
else
'rs("roomadmin2")=1
end if

rs("roomadmin")=myid
IF TP="" then
rs("mmtext")=myid
end if
if txt<>"" then rs("title")=txt

rs.update
rs.close
set rs=nothing

'取ID
dim chatids
set rs=Server.CreateObject("ADODB.Recordset")
rs.open"select top 1 ID from [chat] order by id desc",conn,1,1
chatids=rs("ID")
rs.close
set rs=nothing
 conn.execute("update Users Set ChatID = "&chatids&" where ID="&myid)
conn.execute("update Chat Set Chatnum = 1 where ID="&chatids)

conn.close
set conn=nothing
IF TP<>"" then
response.write"成功编辑自建聊天室!<br/>"
else
response.write"成功增加自建聊天室<br/>"
end if
response.write"----------<br/>"
response.write"<a href=""index.asp?sid="&sid&""">聊吧大厅</a>"
%><!--#include file="../fanhui.asp"-->
</p></card>
</wml>