<!--#include file="conn.asp"-->
<!--#include file="inc/const.asp"-->
<!-- #include file=pet_conn.asp -->
<!--#include file="inc/plus_check.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,"","宠物中心","petcenter.asp"

if DvBBS.UserId = 0 then
	AlarmErrmsg
else
    dim money,smoney,saveday,allmoney,time1,time2,daikuang,dkdu,daiday,sucmsg
    dim Form_userphoto,Form_FaceUrl,Form_FaceWidth,Form_FaceHeight,MemberName
    
    Dim Rs,SQL

	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("你还没有宠物啊，快攒钱去买吧~","petshop.asp")
		else
		dim mypet,mypetsexmoney,pknow
		
		mypet = rs("mypet")
		mypetsexmoney = money
		pknow=rs("pktime")
			
	end if
	
	select case lcase(request("action"))
		case "changename"
			if(len(request("petsname")) > DEF_PET_namelong) then
				SQL = "UPDATE mypetdata SET mypet='请重新填写' WHERE username='"&DvBBS.MemberName&"'"
				connpet.ExeCute(SQL)
				call showmessage("你的宝宝名字是不是太长了","petother.asp")
			elseif(request("petsname")="") then
				call showmessage("你没有填写宝宝的名字","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("你的宝宝名字含有系统规定不允许的字符，还是换一个吧~","petother.asp")
							end if
						else
							if(instr(request("petsname"),DEF_PET_nameexpt)) > 0 then
								call showmessage("你的宝宝名字含有系统规定不允许的字符，还是换一个吧~","petother.asp")
							end if
					end if
				end if
				dim petname
				petname = request("petsname")
				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
				SQL = "UPDATE mypetdata SET mypet='"& petname &"' WHERE username='"&DvBBS.MemberName&"'"
				connpet.ExeCute(SQL)
				call showmessage("改名成功，你的宝宝改名为 "& petname &" ！","petmypet.asp")
			end if
		case "changesex"
			if(mypetsexmoney<DEF_PET_changesexmoney) then
				call showmessage("对不起你没有那么多钱为宝宝做变性手术","petmypet.asp")
			elseif(request("petsex") = "") then
				call showmessage("你还没有选定你宝宝的性别啊，难道要做人妖？","petother.asp")
			elseif(request("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("改变性别成功，你的宝宝变为雄性 ！","petmypet.asp")
			elseif(request("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("改变性别成功，你的宝宝变为雌性 ！","petmypet.asp")
			end if
		case "openpk"
			if DateDiff("h", pknow, now())<12 then
				call showmessage("刚打完人就想溜？再等等吧！","petmypet.asp")
			else
			if(request("openpetpk") = 1) then
				connpet.ExeCute("UPDATE mypetdata SET openpk=1 WHERE username='"&DvBBS.MemberName&"'")
				call showmessage("成功开启PK模式！","petmypet.asp")
			elseif(request("openpetpk") = 2) then
				connpet.ExeCute("UPDATE mypetdata SET openpk=2 WHERE username='"&DvBBS.MemberName&"'")
				call showmessage("成功关闭PK模式！","petmypet.asp")
			end if
			end if
        case "presentpet"
            if(Dvbbs.MemberName = request("newname")) then
              call showmessage("干吗啊，自己送宠物给自己！","petother.asp")
            else
                SQL = "SELECT username FROM [Dv_user] WHERE username='"&request("newname")&"'"
                set rs = Dvbbs.ExeCute(SQL)
                if rs.eof then
                    call showmessage("社区里面没有这个人","petother.asp")
                end if
                rs.close
                dim rs1
                SQL = "SELECT username FROM mypetdata WHERE username='"&request("newname")&"'"
                set rs1 = connpet.ExeCute(SQL)
                if not rs1.eof then
                    call showmessage("他已经有宠物了，你还是把宠物留给自己吧~","petother.asp")
                    else
                    connpet.ExeCute("UPDATE mypetdata SET username='"&request("newname")&"' WHERE username='"&Dvbbs.MemberName&"'")
                    Dvbbs.ExeCute("INSERT INTO Dv_Message (Incept, Sender, Title, Content, SendTime,flag, isSend) values('"&request("newname")&"','宠物管理员','"&Dvbbs.MemberName&" 送给你一个宠物，快来看看','你得到了一个宠物宝宝,快去宠物中心看看','"&now&"','0','1')")
                    UPDATE_User_Msg(request("newname"))
                end if
                rs1.close
            end if
            call showmessage("赠送成功，你的宝宝已经送给了 "&request("newname")&" ！","petshop.asp")
		case "setimg"
			if rs("imgset")=-1 then
				if not isnumeric(request("imgset")) then
					call showmessage("等级必须是数字！","petother.asp")
				elseif cint(request("imgset"))>cint(rs("mypetlevel")/10) then
					call showmessage("等级不得超过宠物现有等级！","petother.asp")
				elseif mypetsexmoney < DEF_Pet_ImgMoney then
					call showmessage("你的钱不够啊！","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 "petother.asp"
				end if
			else
				connpet.ExeCute("UPDATE mypetdata SET imgset=-1 WHERE username='"&DvBBS.MemberName&"'")
				response.redirect "petother.asp"
			end if
	end select
%>
<table  border="0" cellspacing="1" cellpadding="5" align="center" class=tableborder4>
  <tr>
	<td height=27 align="center" class=tbhead2><b><font class=HeadFont><%=stats%></font></b></td>
  </tr>
  <tr>
	<td class=tbbg1>
	
			<table width="100%" border="0" cellspacing="2" cellpadding="2">
			  <tr>
				<td><table width="79%"  border="0" align="center" cellpadding="3" cellspacing="3">
					<tr>
                      <td width="100%"><div align="center">我的资料</div></td>
                    </tr>
                    <tr>
                      <td><div align="center">
					<%
            		If IsNumeric(Dvbbs.MyUserInfo(12)) And IsNumeric(Dvbbs.MyUserInfo(13)) And Dvbbs.MyUserInfo(13)<>"" And Dvbbs.MyUserInfo(12)<>"" Then
            			If Clng(Dvbbs.MyUserInfo(13))=Clng(Dvbbs.Forum_Setting(39)) And Clng(Dvbbs.MyUserInfo(12))=Clng(Dvbbs.Forum_Setting(38)) Then
            			response.write "<img src="&Dvbbs.MyUserInfo(11)&">"
            			Else
            			response.write "<img src="&Dvbbs.MyUserInfo(11)&" width=60 height=60>"
            			End If
            		Else
            			response.write "<img src=dv_plus/pet/logo_2.gif>"
            		End If
					%>
					<br><img src=../dv_plus/pet/blank.gif width=2 height=5><br>                      
                      </div></td>
                    </tr>
                    <tr>
                    <td> <div align="center">
                        <nobr>现金货币: <%=money%></nobr>
                        </div></td>
                    </tr>
                  </table>
				  <br>
				  <table width="90%"  border="0" align="center" cellpadding="3" cellspacing="3">
					<tr>
					  <td><div align="center"><!-- #include file=petnav.asp --></div></td>
					</tr>
				  </table></td>
				<td><form action="petother.asp" method=post>
					<table width="100%"  border="0" align="center" cellpadding="3" cellspacing="3">
					  <tr> 
						<td width="29%"> <div align="right">为宝宝改名字： </div></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="petother.asp" method=post>
					<table width="100%"  border="0" align="center" cellpadding="3" cellspacing="3">
					  <tr>
	  <td width="29%"><div align="right">为宝宝做变性手术：</div></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="petother.asp" method=post>
					<table width="100%"  border="0" align="center" cellpadding="3" cellspacing="3">
					  <tr>
	  <td width="29%"><div align="right">把我的宝宝送给：</div></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="petother.asp" method=post>
					<table width="100%"  border="0" align="center" cellpadding="3" cellspacing="3">
					  <tr>
			  <td width="29%"> <div align="right">是否开启PK： </div></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="petother.asp" method=post>
					<table width="100%"  border="0" align="center" cellpadding="3" cellspacing="3">
					  <tr>
					  <%if rs("imgset")=-1 then%>
	  <td width="29%"><div align="right">我决定把宝宝形象恒定在：</div></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 If  :   Set Dv_plus=Nothing : Dvbbs.Footer %>
<%
'更新用户短信通知信息（新短信条数||新短讯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
%>