<!--#include file="conn.asp"-->
<!--#include file="inc/const.asp"-->
<!--#include file="inc/plus_check.asp"-->
<!--#include file="YD_pet_conn.asp"-->

<%
dim menu,savem,rsbank,rssql,chentitle,chenbackasp,stats,errmsg,founderr
chentitle="宠物事务所"
Dv_plus.name="petcenter"
'Dv_plus.checklogin()
Dvbbs.LoadTemplates("")
Dvbbs.Stats="宠物事务所"
Dvbbs.Nav()
Dvbbs.Head_var 0,"","宠物中心","YD_petcenter.asp"

if DvBBS.UserId = 0 then
	AlarmErrmsg
else
	'宠物插件状态
	if DEF_PET_close>1 then
		'暂时关掉开始
		if not dvbbs.master then
			call showmessage("调试中,请以后再来~","index.asp")
		end if
		'暂时关掉结束
	end if

	dim money,smoney,saveday,allmoney,time1,time2,daikuang,dkdu,daiday,sucmsg
	dim Form_userphoto,Form_FaceUrl,Form_FaceWidth,Form_FaceHeight,MemberName
	Dim Rs,SQL
	dim mypet,mypetsexmoney,pknow,relive
	set rs=Dvbbs.execute("select userWealth from [Dv_User] where UserID="&DvBBS.UserId)
	money=rs("userWealth")
	rs.close

	sql = "SELECT * FROM mypetdata WHERE username='"&DvBBS.MemberName&"' "
	rs.open sql,connpet,1,3
	if rs.eof then
		call showmessage("你还没有宠物啊，快攒钱去买吧~","YD_petshop.asp")
	else
		mypet = rs("mypet")
		mypetsexmoney = money
		pknow=rs("pktime")
		relive=rs("relive")
	end if

	select case lcase(request("action"))
		case "changename"
			dim petname
			petname = Checkstr(request("petsname"))
			if(len(request("petsname")) > DEF_PET_namelong) then
				SQL = "UPDATE mypetdata SET mypet='请重新填写' WHERE username='"&DvBBS.MemberName&"'"
				connpet.ExeCute(SQL)
				call showmessage("你的宝宝名字是不是太长了","YD_petother.asp")
			elseif(request("petsname")="") then
				call showmessage("你没有填写宝宝的名字","YD_petother.asp")
			else
				'宝宝名字过滤
				if len(DEF_PET_nameexpt) > 0 then
					if(instr(DEF_PET_nameexpt,"|")) > 0 then
						dim tarr,inum,errorflag
						tarr = split(DEF_PET_nameexpt,"|")
						for inum = 0 to ubound(tarr)
							if(instr(request("petsname"),tarr(inum))) > 0 then
								errorflag = 1
								Exit For
							end if
						next
						if(errorflag = 1) then
							call showmessage("你的宝宝名字含有系统规定不允许的字符，还是换一个吧~","YD_petother.asp")
						end if
					else
						if(instr(request("petsname"),DEF_PET_nameexpt)) > 0 then
							call showmessage("你的宝宝名字含有系统规定不允许的字符，还是换一个吧~","YD_petother.asp")
						end if
					end if
				end if
				
				if relive>0 then
				select case request("smart")
					case 1
						petname = "<font color=red>"& request("petsname") &"</font>"
					case 2
						petname = "<font color=blue>"& request("petsname") &"</font>"
					case 3
						petname = "<font color=green>"& request("petsname") &"</font>"
					case 4
						petname = "<font color=purple>"& request("petsname") &"</font>"
				end select
				end if
				SQL = "UPDATE mypetdata SET mypet='"& petname &"' WHERE username='"&DvBBS.MemberName&"'"
				connpet.ExeCute(SQL)
				call showmessage("改名成功，你的宝宝改名为 "& petname &" ！","YD_petmypet.asp")
			end if
		case "changesex"
			dim petsex
			petsex = cint(request("petsex")&"")
			if(mypetsexmoney<DEF_PET_changesexmoney) then
				call showmessage("对不起你没有那么多钱为宝宝做变性手术","YD_petmypet.asp")
			elseif(petsex<0 or petsex>2) then
				call showmessage("你还没有选定你宝宝的性别啊，难道要做人妖？","YD_petother.asp")
			elseif(petsex = 1) then
				Dvbbs.execute("UPDATE [DV_user] SET userWealth=userWealth-"&DEF_PET_changesexmoney&" WHERE username='"&DvBBS.MemberName&"'")
				connpet.ExeCute("UPDATE mypetdata SET mypetsex=1 WHERE username='"&DvBBS.MemberName&"'")
				call showmessage("改变性别成功，你的宝宝变为雄性 ！","YD_petmypet.asp")
			elseif(petsex = 2) then
				Dvbbs.execute("UPDATE [DV_user] SET userWealth=userWealth-"&DEF_PET_changesexmoney&" WHERE username='"&DvBBS.MemberName&"'")
				connpet.ExeCute("UPDATE mypetdata SET mypetsex=2 WHERE username='"&DvBBS.MemberName&"'")
				call showmessage("改变性别成功，你的宝宝变为雌性 ！","YD_petmypet.asp")
			end if
		case "openpk"
			if DateDiff("h", pknow, now())<12 then
				call showmessage("刚打完人就想溜？再等等吧！","YD_petmypet.asp")
			else
				if(request("openpetpk") = 1) then
					connpet.ExeCute("UPDATE mypetdata SET openpk=1 WHERE username='"&DvBBS.MemberName&"'")
					call showmessage("成功开启PK模式！","YD_petmypet.asp")
				elseif(request("openpetpk") = 2) then
					connpet.ExeCute("UPDATE mypetdata SET openpk=2 WHERE username='"&DvBBS.MemberName&"'")
					call showmessage("成功关闭PK模式！","YD_petmypet.asp")
				end if
			end if
		case "presentpet"
			dim newname
			newname = Checkstr(request("newname"))
			if(Dvbbs.MemberName = newname) then
				call showmessage("干吗啊，自己送宠物给自己！","YD_petother.asp")
			else
				SQL = "SELECT username FROM [Dv_user] WHERE username='"&newname&"'"
				set rs = Dvbbs.ExeCute(SQL)
				if rs.eof then
					call showmessage("社区里面没有这个人","YD_petother.asp")
				end if
				rs.close
				dim rs1
				SQL = "SELECT username FROM mypetdata WHERE username='"&newname&"'"
				set rs1 = connpet.ExeCute(SQL)
				if not rs1.eof then
					call showmessage("他已经有宠物了，你还是把宠物留给自己吧~","YD_petother.asp")
				else
					connpet.ExeCute("UPDATE mypetdata SET username='"&newname&"' WHERE username='"&Dvbbs.MemberName&"'")
					Dvbbs.ExeCute("INSERT INTO Dv_Message (Incept, Sender, Title, Content, SendTime,flag, isSend) values('"&newname&"','宠物管理员','"&Dvbbs.MemberName&" 送给你一个宠物，快来看看','你得到了一个宠物宝宝,快去宠物中心看看',"&SqlNowString&",'0','1')")
					UPDATE_User_Msg(newname)
				end if
				rs1.close
			end if
			call showmessage("赠送成功，你的宝宝已经送给了 "&newname&" ！","YD_petshop.asp")
		case "setimg"
			if rs("imgset")=-1 then
				if not isnumeric(request("imgset")) then
					call showmessage("等级必须是数字！","YD_petother.asp")
				elseif cint(request("imgset"))>cint(rs("mypetlevel")/10) then
					call showmessage("等级不得超过宠物现有等级！","YD_petother.asp")
				elseif mypetsexmoney < DEF_Pet_ImgMoney then
					call showmessage("你的钱不够啊！","YD_petother.asp")
				else
					Dvbbs.execute("UPDATE [DV_user] SET userWealth=userWealth-"& DEF_Pet_ImgMoney &" WHERE username='"&DvBBS.MemberName&"'")
					connpet.ExeCute("UPDATE mypetdata SET imgset="&cint(request("imgset"))&" WHERE username='"&DvBBS.MemberName&"'")
					response.redirect "YD_petother.asp"
				end if
			else
				connpet.ExeCute("UPDATE mypetdata SET imgset=-1 WHERE username='"&DvBBS.MemberName&"'")
				response.redirect "YD_petother.asp"
			end if
	end select
	call main()
End If
Set Dv_plus=Nothing
Dvbbs.Footer

sub main()
%>
<table class=tableborder1 cellspacing=1 cellpadding=3 align=center>
  <tr>
    <th height=27 align=center><%=Dvbbs.stats%></th>
  </tr>
  <tr>
    <td class=TableBody1>
      <table width="100%" cellspacing="2" cellpadding="2">
	<tr>
	  <td>
	    <table width="79%" align="center" cellpadding="3" cellspacing="3">
	      <tr>
		<td width="100%" align="center">我的资料</td>
	      </tr>
	      <tr>
		<td align="center">
		<%
		'用户头像调用开始
		If IsNumeric(Dvbbs.UserSession.documentElement.selectSingleNode("userinfo/@userwidth").text) And IsNumeric(Dvbbs.UserSession.documentElement.selectSingleNode("userinfo/@userheight").text) And Dvbbs.UserSession.documentElement.selectSingleNode("userinfo/@userheight").text<>"" And Dvbbs.UserSession.documentElement.selectSingleNode("userinfo/@userwidth").text<>"" Then
			If Clng(Dvbbs.UserSession.documentElement.selectSingleNode("userinfo/@userheight").text)=Clng(Dvbbs.Forum_Setting(39)) And Clng(Dvbbs.UserSession.documentElement.selectSingleNode("userinfo/@userwidth").text)=Clng(Dvbbs.Forum_Setting(38)) Then
				response.write "<img src="&Dvbbs.UserSession.documentElement.selectSingleNode("userinfo/@userface").text&">"
			Else
				response.write "<img src="&Dvbbs.UserSession.documentElement.selectSingleNode("userinfo/@userface").text&" width=100 height=100>"
			End If
		Else
			response.write "<img src=images/logo_2.gif>"
		End If
		'用户头像调用结束
		%>
		</td>
	      </tr>
	      <tr>
		<td align="center"><nobr>现金货币: <%=money%></nobr></td>
	      </tr>
	    </table>
	    <br>
	    <table width="90%" align="center" cellpadding="3" cellspacing="3">
	      <tr>
		<td align="center"><!-- #include file=YD_petnav.asp --></td>
	      </tr>
	    </table>
	  </td>
	  <td>
	    <form action="YD_petother.asp" method=post>
	    <table width="100%" align="center" cellpadding="3" cellspacing="3">
	      <tr> 
		<td width="29%" align="center">为宝宝改名字：</td>
		<td width="71%"> <input name="petsname" type="text" value="<%=mypet%>" size="20" maxlength="16"> 
		<%if rs("relive")>0 then%>
			<select name="smart">
			<option value=0>名字醒目</option>
			<option value=1>红色醒目</option>
			<option value=2>蓝色醒目</option>
			<option value=3>绿色醒目</option>
			<option value=4>紫色醒目</option>
			</select>
		<%end if%>
		&nbsp;&nbsp;&nbsp; <input type="hidden" name="action" value="changename"> 
		<input type="submit" value="改名">
		&nbsp;&nbsp;<font color="#FF0000">注意：1转后可以修改名字颜色</font>
		</td>
	      </tr>
	    </table>
	    </form>
	    <form action="YD_petother.asp" method=post>
	    <table width="100%" align="center" cellpadding="3" cellspacing="3">
	      <tr>
		<td width="29%" align="right">为宝宝做变性手术：</td>
		<td width="71%">
		<input type="radio" name="petsex" value="1"> 雄&nbsp;&nbsp;&nbsp;
		<input type="radio" name="petsex" value="2"> 雌&nbsp;&nbsp;&nbsp;
		<input type="hidden" name="action" value="changesex">
		<input type="submit" name="Submit" value="改变性别">
		&nbsp;&nbsp;&nbsp; <font color="#FF0000">注意：需要花费<%=DEF_PET_changesexmoney%><%=DEF_PointsName%></font>
		</td>
	      </tr>
	    </table>
	    </form>
	    <form action="YD_petother.asp" method=post>
	    <table width="100%" align="center" cellpadding="3" cellspacing="3">
	      <tr>
		<td width="29%" align="right">把我的宝宝送给：</td>
		<td width="71%">
		<input name="newname" type="text" size="20" maxlength="16">&nbsp;&nbsp;&nbsp;
		<input type="hidden" name="action" value="presentpet">
		<input type="submit" name="Submit" value="赠送宠物">
		</td>
	      </tr>
	    </table>
	    </form>
	    <form action="YD_petother.asp" method=post>
	    <table width="100%" align="center" cellpadding="3" cellspacing="3">
	      <tr>
		<td width="29%" align="right">是否开启PK：</td>
		<td width="71%">
		<input type="radio" name="openpetpk" value="1">
		开启&nbsp;&nbsp;&nbsp;
		<input type="radio" name="openpetpk" value="2">
		关闭 &nbsp;&nbsp;
		<input type="hidden" name="action" value="openpk">
		<input type="submit" value="确定">
		&nbsp;&nbsp;&nbsp;
		</td>
	      </tr>
	    </table>
	    </form>
	    <form action="YD_petother.asp" method=post>
	    <table width="100%" align="center" cellpadding="3" cellspacing="3">
	      <tr>
	<%if rs("imgset")=-1 then%>
		<td width="29%" align="right">我决定把宝宝形象恒定在：</td>
		<td width="71%">
		<input name="imgset" type="text" size="20"> 级<font color=red>(0-11)</font>&nbsp;&nbsp;&nbsp;
		<input type="hidden" name="action" value="setimg">
		<input type="submit" name="Submit" value="恒定宠物形象">&nbsp;&nbsp;&nbsp; <font color="#FF0000">注意：需要花费<%=DEF_Pet_ImgMoney%><%=DEF_PointsName%></font>
		</td>
	<%else%>
		<td width="40%" align=right>您的宠物形象现在恒定在 <%=rs("imgset")%> 级</td>
		<td align=left><input type="hidden" name="action" value="setimg">
		<input type="submit" name="Submit" value="取消恒定形象">
		</td>
	<%end if%>
	      </tr>
	    </table>
	    </form>
	  </td>
	</tr>
      </table>
    </td>
  </tr>
</table>
<%
end sub

'更新用户短信通知信息（新短信条数||新短讯ID||发信人名）
Sub UPDATE_User_Msg(username)
Dim msginfo,i,UP_UserInfo,newmsg
newmsg=newincept(username)
If newmsg>0 Then
	msginfo=newincept(username) & "||" & inceptid(1,username) & "||" & inceptid(2,username)
Else
	msginfo="0||0||null"
End If
Dvbbs.execute("UPDATE [Dv_User] Set UserMsg='"&Dvbbs.CheckStr(msginfo)&"' WHERE username='"&Dvbbs.CheckStr(username)&"'")
If username=Dvbbs.MemberName Then
	UP_UserInfo=Session(Dvbbs.CacheName & "UserID")
	UP_UserInfo(30)=msginfo
	Session(Dvbbs.CacheName & "UserID")=UP_UserInfo
Else
	Call Dvbbs.NeedUpdateList(username,1)
End If
End Sub

'统计留言
Function newincept(iusername)
Dim Rs
Rs=Dvbbs.execute("SELECT Count(id) FROM Dv_Message WHERE flag=0 And issend=1 And DelR=0 And incept='"& iusername &"'")
newincept=Rs(0)
Set Rs=nothing
If isnull(newincept) Then newincept=0
End Function

Function inceptid(stype,iusername)
Set Rs=Dvbbs.execute("SELECT top 1 id,sender FROM Dv_Message WHERE flag=0 And issend=1 And DelR=0 And incept='"& iusername &"'")
If not rs.eof Then
	If stype=1 Then
		inceptid=Rs(0)
	Else
		inceptid=Rs(1)
	End If
Else
	If stype=1 Then
		inceptid=0
	Else
		inceptid="null"
	End If
End If
Set Rs=nothing
End Function
%>