<!--#include file="conn.asp"-->
<!--#include file="inc/const.asp"-->
<!--#include file="inc/dv_clsother.asp"-->
<%
Dim TemplateStr,dhy_rs,dhy_sql,dhy_1,dhy_2,dhy_3,dhy_4,dhy_5,dhy_6,rs,sql,reg_yn
Dvbbs.LoadTemplates("")
TemplateStr="<tr><td class={$BgColor}><li>{$VarName}&nbsp;{$VarDesc}</td><td class={$BgColor}>&nbsp;当前值：<font color="&Dvbbs.MainSetting(1)&"><b>{$VarValue}</b></font></td></tr>"
Dvbbs.Stats="申请个人主页"
Dvbbs.Nav()
If Dvbbs.BoardID=0 Then
	Dvbbs.Head_var 2,0,"",""
Else
	Dvbbs.Head_var 1,Dvbbs.Board_Data(4,0),"",""
End If
Set dhy_rs =Dvbbs.Execute("select * from dhy_setup")
dhy_1=dhy_rs("index_reg_yn")
dhy_2=dhy_rs("bbs_title")
dhy_3=dhy_rs("bbs_money")
dhy_4=dhy_rs("bbs_jingyan")
dhy_5=dhy_rs("bbs_meilei")
dhy_6=dhy_rs("bbs_weiwang")
dhy_rs.close:set dhy_rs=nothing
if not Dvbbs.Founduser then
   errs("您还没有<a href=login.asp>登录论坛</a>，不能申请个人主页。如果您还没有<a href=reg.asp>注册</a>，请先<a href=reg.asp>注册</a>！")
end if
set rs=Dvbbs.Execute("select id,yn from [dhy_index] where user='"&Dvbbs.UserSession.documentElement.selectSingleNode("userinfo/@username").text&"' or userid="&Dvbbs.UserSession.documentElement.selectSingleNode("userinfo/@userid").text)
if rs.eof then
   reg_yn=3
elseif rs("yn")=0 then
   reg_yn=0
elseif rs("yn")=1 then
   reg_yn=1
elseif rs("yn")=2 then
   reg_yn=2
else
   reg_yn=0
end if
rs.close:set rs=nothing
if dhy_1=0 then
   errs("个人主页申请暂停开放，请稍后重试或<a href=mailto:"&Dvbbs.Forum_Info(5)&">联系管理员</a>.")
elseif reg_yn=0 and Request.ServerVariables("Query_String")<>"action=ok" then
   errs("您的个人主页正在审核中，请不要重复申请.")
elseif reg_yn=1 and Request.ServerVariables("Query_String")<>"action=ok" then
   errs("您已经拥自己的个人主页，请不要重复申请.")
elseif reg_yn=2 and Request.ServerVariables("Query_String")<>"action=ok" then
   errs("你的个人主页管理员还未处理，请不要重复申请.")
elseif dhy_2-Dvbbs.UserSession.documentElement.selectSingleNode("userinfo/@usertopic").text>0 then
   errs("您不能申请个人主页，您在 "&Dvbbs.Forum_Info(0)&" 的主题贴数少于 "&dhy_2&" 篇。")
elseif dhy_3-Dvbbs.UserSession.documentElement.selectSingleNode("userinfo/@userwealth").text>0 then
   errs("您不能申请个人主页，您在 "&Dvbbs.Forum_Info(0)&" 的金钱少于 "&dhy_3)
elseif dhy_4-Dvbbs.UserSession.documentElement.selectSingleNode("userinfo/@userep").text>0 then
   errs("您不能申请个人主页，您在 "&Dvbbs.Forum_Info(0)&" 的经验少于 "&dhy_4)
elseif dhy_5-Dvbbs.UserSession.documentElement.selectSingleNode("userinfo/@usercp").text>0 then
   errs("您不能申请个人主页，您在 "&Dvbbs.Forum_Info(0)&" 的魅力少于 "&dhy_5)
elseif dhy_6-Dvbbs.UserSession.documentElement.selectSingleNode("userinfo/@userpower").text>0 then
   errs("您不能申请个人主页，您在 "&Dvbbs.Forum_Info(0)&" 的威望少于 "&dhy_6)
else
   if request("action")<>"" then
      call ok()
   else
      call dhy_reg_index()
   end if
end if
Dvbbs.ActiveOnline()
Dvbbs.Footer()

function errs(str)
Response.redirect "showerr.asp?ErrCodes=<li>"&str&"&action=OtherErr"
end function

function gl(str,str1)
If str="" or Len(str)<2 or Instr(str,"%")>0 or Instr(str,"?")>0 or Instr(str,"&")>0 or Instr(str,"'")>0 or Instr(str,"$")>0 Then
   errs(str1&" 含有非法字符或为空！")
end if
end function

public sub ok()
dim dqadd
dqadd=Request.ServerVariables("HTTP_REFERER")
Response.Write "<table cellpadding=4 cellspacing=1 align=center class=tableborder1 style=word-break:break-all><tr><th colspan=2>申请成功：欢迎你使用个人主页</th></tr>"
response.write "<tr>"
response.write "<td class=tablebody1>"
response.write "<li>你已成功申请个人主页！</li>"
response.write "<li>欢迎你使用由本社区提供的个人主页！</li>"
response.write "<li>请牢你的个人主页地址：<font color=red><b>"&left(dqadd,len(dqadd)-12)&"/dhy_index.asp?usID="&Dvbbs.UserSession.documentElement.selectSingleNode("userinfo/@userid").text&"</b></font></li>"
response.write "<br><li>你的网站目前处于审核状态。</li>"
response.write "<br><li>管理员会在1-2个工作日内对你所填写的资料进行审核！如核对无误即可开通你的个人主页！</li>"
response.write "</td>"
response.write "</tr>"
response.write "<tr>"
response.write "<td class=tablebody2><center>"
response.write "<input type=button value=返回首页 onclick=location.href('index.asp');>"
response.write "</td>"
response.write "</tr>"
response.write "</table>"
Dim sender,title,body,UserMsg,MsgID
sender=Dvbbs.UserSession.documentElement.selectSingleNode("userinfo/@username").text
title="申请开通个人主页"
body ="管理员，你好：<br>　　我已经在贵站审请了个人主页，请管理员尽快开通！<br>　　谢谢!<br>　　　　　　"&now()
set dhy_rs= Dvbbs.Execute("select UserName from [Dv_User] where UserGroupID=1")
do while not dhy_rs.eof
sql="insert into dv_message(incept,sender,title,content,sendtime,flag,issend) values('"&dhy_rs("UserName")&"','"&sender&"','"&title&"','"&body&"','"&now()&"',0,1)"
Dvbbs.Execute(sql)
Set rs=Dvbbs.execute("select top 1 ID from [Dv_message] order by ID desc")
MsgID=rs(0)
Rs.close:Set Rs=Nothing
UserMsg="1||"& MsgID &"||"& sender
Dvbbs.execute("UPDATE [Dv_User] Set UserMsg='"&Dvbbs.CheckStr(UserMsg)&"' WHERE UserName='"&dhy_rs("UserName")&"'")
dhy_rs.movenext()
loop
dhy_rs.close:set dhy_rs=nothing
end sub

public sub dhy_reg_index()
if request.form("submit")<>"" then
   response.write gl(request.form("site_name"),"<b>个人主页名称</b>")
   response.write gl(request.form("zs_name"),"<b>真实姓名</b>")
   response.write gl(request.form("E_mail"),"<b>真实姓名</b>")
   response.write gl(request.form("zs_add"),"<b>联系地址</b>")
   response.write gl(request.form("index_sm"),"<b>主页简介</b>")
   response.write gl(request.form("zs_tel"),"<b>电话</b>")
   if not IsNumeric(request.form("zs_code")) or len(request.form("zs_code"))<6 then errs("<b>邮政编码</b>含有非法字符或为空！")
   Set rs = Server.CreateObject("ADODB.Recordset")
   sql = "select * from dhy_index"
   rs.open sql,conn,1,3
   rs.addnew
   rs("site_name")=request.form("site_name")
   rs("zs_name")=request.form("zs_name")
   rs("E_mail")=request.form("E_mail")
   rs("zs_tel")=request.form("zs_tel")
   rs("zs_code")=request.form("zs_code")
   rs("zs_add")=request.form("zs_add")
   rs("user")=Dvbbs.UserSession.documentElement.selectSingleNode("userinfo/@username").text
   rs("userphoto")=Dvbbs.UserSession.documentElement.selectSingleNode("userinfo/@userface").text
   rs("userID")=Dvbbs.UserSession.documentElement.selectSingleNode("userinfo/@userid").text
   rs("index_sm")=request.form("index_sm")
   rs("add_time")=now()
   rs("start_time")=now()
   rs("end_time")=now()
   rs("yn")=0
   rs.update
   response.redirect "?action=ok"
end if
Response.Write "<table cellpadding=4 cellspacing=1 align=center class=tableborder1 style=word-break:break-all><tr><th colspan=2>申请个人主页</th></tr>"
response.write "<form method=POST name=form>"
   response.write "<tr>"
   response.write "<td class=tablebody1 width=40% ><b>个人主页名称</b><br>长度限制为2－15字节</td>"
   response.write "<td class=tablebody1><input type=text name=site_name maxlength=15 size=30></td>"
   response.write "</tr>"
   response.write "<tr>"
   response.write "<td class=tablebody1 width=40% ><b>真实姓名</b><br>长度限制为2－15字节(只有管理员可见)</td>"
   response.write "<td class=tablebody1><input type=text name=zs_name maxlength=15 size=30></td>"
   response.write "</tr>"
   response.write "<tr>"
   response.write "<td class=tablebody1 width=40% ><b>电子信箱</b></td>"
   response.write "<td class=tablebody1><input type=text name=E_mail value='"&Dvbbs.UserSession.documentElement.selectSingleNode("userinfo/@useremail").text&"' maxlength=100 size=30></td>"
   response.write "</tr>"
   response.write "<tr>"
   response.write "<td class=tablebody1 width=40% ><b>电　　话</b><br>你的真实电话号码，便于管理员工作。(只有管理员可见)</td>"
   response.write "<td class=tablebody1><input type=text name=zs_tel maxlength=30 size=30></td>"
   response.write "</tr>"
   response.write "<tr>"
   response.write "<td class=tablebody1 width=40% ><b>邮　　编</b><br>你的连接地址所在地的邮政编码。(只有管理员可见)</td>"
   response.write "<td class=tablebody1><input type=text name=zs_code maxlength=6 size=6></td>"
   response.write "</tr>"
   response.write "<tr>"
   response.write "<td class=tablebody1 width=40% ><b>联系地址</b><br>你的真实地址，便于管理员工作。(只有管理员可见)</td>"
   response.write "<td class=tablebody1><input type=text name=zs_add maxlength=200 size=50></td>"
   response.write "</tr>"
   response.write "<tr>"
   response.write "<td class=tablebody1 width=40% ><b>主页简介</b><br>个人主页简介，支持HTML，请注意不要有非法字符！</td>"
   response.write "<td class=tablebody1><textarea name=index_sm rows=5 cols=65></textarea>"
   response.write "<img src=images/manage/plus.gif onclick=document.form.index_sm.rows+=4 alt=放大>"
   response.write "<img src=images/manage/minus.gif onclick='if(document.form.index_sm.rows>=4)document.form.index_sm.rows-=4;else return false' alt=缩小>"
   response.write "</td>"
   response.write "</tr>"
   response.write "<tr>"
   response.write "<td class=tablebody2 colspan=2><center><input type=submit name=submit value=提交>　　<input type=button value=返回 onclick='javascript:history.go(-1);'></td>"
   response.write "</tr>"
   response.write "</form></table>"
end sub

%>