<!--#include file="inc_const.asp"-->
<%response.expires=0
Response.CacheControl = "Private"
application.lock

set cschat=server.createobject("ffcschat.cssbchat")
my_level=cschat.getLevel(Session,Application(ConstStr & "_user_list"),Application(ConstStr & "_room_list"))

if my_level=0 then
  response.redirect("showerr.asp")
  set cschat=nothing
  application.unlock
  response.end
end if

votes=application( ConstStr & "_votes")
if (votes(0)<>0 and votes(1)=myname) then my_level=1

room_array=split(Application( ConstStr & "_room_list"),"$><$")
room_num=(UBound(room_array)+1)\2

errText=""

if my_level-application( ConstStr & "_l_addroom")<0 then
  errText="你没有权力建立新的房间！"
elseif room_num-application( ConstStr & "_maxroomnum")>=0 then
  errText="房间数目已经达到最大允许建房数！"
else
  haveroom=false
  for i=0 to UBound(room_array) step 2
   room_array2=split(room_array(i),"$>")
   room_owner=room_array2(1)
   if lcase(room_owner)=lcase(myname) then
    haveroom=true
    exit for
   end if
  next
  if haveroom and my_level-application( ConstStr & "_l_delroom")<0 then
   errText="你已经有自己的房间了！"
  end if
end if

if errText<>"" then
  response.redirect("showerr.asp?errtext="&errText)
  set cschat=nothing
  application.unlock
  response.end
end if

myname=cschat.myname
room_id=cschat.room_id

Set Conn=Server.CreateObject("ADODB.Connection")
conn.open Application( ConstStr & "_connstr")
cschat.FilterStr=application(ConstStr & "_usernamefilter")

if request("cmdYes")="确认" then
  sRoom=left(request("sRoom"),10)
  if cschat.chuser(lcase(sRoom),Application(ConstStr & "_usernameenable")) then
    errText="房间名字里有非法字符。"
  elseif len(sRoom)-application( ConstStr & "_namelength")<0 then
    errText="房间名太短了！"
  else
    set rs1=conn.execute("select ID from room where room_name='"&sRoom&"'")
    if not (rs1.eof or rs1.bof) then
      errText="已经有了同名字的房间了！"
    else
      room_name=sRoom
      cschat.FilterStr = Application(ConstStr & "_saysfilterstr")
      room_des=left(cschat.trdb(trim(request("room_des"))),250)
      room_title=left(cschat.trdb(trim(request("sayabout"))),50)
      room_auto=left(cschat.trdb(trim(request("room_auto"))),10)
      if my_level-application( ConstStr & "_l_delroom")>=0 then
        room_owner=request("room_owner")
      else
        room_owner=myname
      end if
      room_keep=0
      if room_owner="" or room_name="" or room_auto="" or room_des="" or room_title="" then
        errText="聊天室名、机器人、标题和描述都不能为空！"
      else
        conn.execute("insert into room (room_top,room_name,room_owner,room_auto,room_des,room_title,room_keep,room_tt,room_time,room_exp,build_time) values ('"&room_title&"','"&room_name&"','"&room_owner&"','"&room_auto&"','"&room_des&"','你的传说，我的传说,在网路上隐隐约约地传说!<font style=color:990099>("&room_owner&","&cschat.gettimestr()&")</font>',"&room_keep&",1,'"&now()&"',0,'"&now()&"')")

        set rs=conn.execute("select * from room where room_name='"&room_name&"'")

        room_array=split(Application( ConstStr & "_room_list"),"<$"&room_id&"$>")
        room_array2=split(room_array(1),"$>")
        room_array2(12)=trim(replace(" "&room_array2(12)&" "," "&myname&" "," "))
        room_array(1)=join(room_array2,"$>")
        Application( ConstStr & "_room_list")=join(room_array,"<$"&room_id&"$>")&_
          "<$"&rs("ID")&"$>"&rs("room_name")&"$>"&rs("room_owner")&"$>"&_
          rs("room_auto")&"$>"&rs("room_des")&"$>"&rs("room_top")&"$>"&rs("room_title")&_
          "$>"&rs("room_keep")&"$>"&rs("room_time")&"$>"&rs("room_tt")&"$>"&rs("room_html")&_
          "$>"&rs("room_exp")&"$>"&rs("build_time")&"$>"&myname&"$>$>1$>1$><$"&rs("ID")&"$>"
          
        says = Application(ConstStr & "_says")
        current = Application(ConstStr & "_current")
        
        say_mess=split(application(ConstStr & "_newroomshow"),"::")
        cschat.newsay myname,sRoom,0,rs("ID"),say_mess(0),say_mess(1),say_mess(2),-3,says,current
        say_mess=split(application(ConstStr & "_tonewroomshow"),"::")
        cschat.newsay myname,sRoom,0,room_id,say_mess(0)&"<\script>parent.dell(\'" & myname & "\')</\script>",say_mess(1),say_mess(2),-3,says,current
        
        Application(ConstStr & "_says") = says
        Application(ConstStr & "_current") = current

        Application( ConstStr & "_user_list")=cschat.SetListValue(Application( ConstStr & "_user_list"),myname,10,now(),0,4,rs("ID"),0)
        conn.Execute("UPDATE user SET room_id=" & rs("ID") & " WHERE username = '"& myname &"'")%>
        <SCRIPT language=JavaScript>window.open("init.asp","refresh");window.close();</script>
        <%rs.close
        set rs=nothing
        rs1.close
        set rs1=nothing
        conn.close
        set conn=nothing
        set cschat=nothing
        application.unlock
        response.end
      end if
    end if
  end if
  response.redirect("showerr.asp?errtext="&errText)
else%>
    <script language=JavaScript>
      function CheckValid() {
        if (document.frmNewRoom.sRoom.value == "") {
          alert( "请输入房间名。");
          document.frmNewRoom.sRoom.focus();
          return false;
        }
        return true;
      }
    </script>
 <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
 <link rel="stylesheet" type="text/css" href="chat.css">
 <body  style="background-color:EAF2FF;color:112233;scrollbar-Base-Color: #b0d8ff;SCROLLBAR-DARKSHADOW-COLOR:#b0d8ff;SCROLLBAR-arrow-COLOR:#336699;SCROLLBAR-TRACK-COLOR: EAF2FF;SCROLLBAR-3DLIGHT-COLOR: #b0d8ff;SCROLLBAR-SHADOW-COLOR: #336699;SCROLLBAR-HIGHLIGHT-COLOR: #b0d8ff;" leftmargin=3 topmargin=20 >
  <table width=420 align=center cellspacing=0 cellpadding=0 border=1 BORDERCOLORLIGHT=#000000 BORDERCOLORDARK=#ffffff>
    <tr><td class=navy1 colspan=2>建新房间</td>
       <form name=frmNewRoom action=newroom.asp method=post>
            <tr><td height=60>房&nbsp;间&nbsp;名:<input name=sRoom maxlength=10 size=8><br>
            机&nbsp;器&nbsp;人:<input type=text name=room_auto maxlength=10 size=8 value="水吧女郎">　　　　　　
            <%if my_level-application( ConstStr & "_l_delroom")>=0 then%><br>房间主人:<input type=text name=room_owner maxlength=10 size=8><%else%><%end if%><br>房间类型:　<select name=list style="background-color:3399FF;color:FFFFFF"
               onchange="javascript:document.frmNewRoom.room_des.value=document.frmNewRoom.list.value;document.frmNewRoom.room_des.focus();">
               <option value="">选择</option>
              <%sql="SELECT alias,describ FROM room_des"
                Set Rs=conn.Execute(sql)
                set alias=Rs("alias")
                set describ=Rs("describ")
                do while not Rs.eof%>
                  <option value="<%=describ%>"><%=alias%></option>
                  <%Rs.MoveNext
                loop
              %>
            </select>
            <br><br>房间描述:<textarea rows="3" name="room_des" cols="40">屋顶铺着些茅草，门窗都是用乱木随意架起，屋子里十分整洁，摆着些年月久远的桌椅。</textarea>
            <br><br>管理标题:<textarea rows="3" name="sayabout" cols="40">我是网路上的一片云，偶然投影在你的波心！</textarea>
            <br><br><input class=navy1 type=submit name=cmdYes value=确认 onClick="return CheckValid();">
            <input class=navy1 type=reset name=cmdClear value=清除>
            <input class=navy1 type=button name=cmdCancel value=放弃 onClick="javascript:window.close()"><br>　</td>
           </tr>
         </table>
       </form>
     </body>
  </html>
<%end if
set cschat=nothing
application.unlock
rs.close
set rs=nothing
conn.close
set conn=nothing%>





















































































