<!--#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
	Dim Rs,SQL
	set rs=Dvbbs.execute("select userWealth from [Dv_User] where UserID="&DvBBS.UserId)
	money=rs("userWealth")
	rs.close

	dim action,petsp,newexp,levelpic,thispetsex
	if request("action") = "" then
		action = "adopt"
	else
		action = lcase(request("action"))
	end if

	select case action
		case "delpet"
			SQL = "SELECT * FROM mypetdata WHERE username='"& DvBBS.MemberName &"'"
			rs.open SQL,connpet,1,3
			if rs.eof then
				call showmessage("你还没有宠物啊，快攒钱去买吧~","YD_petshop.asp")
			else
				if rs("mypetdead") <> 0 then
					call showmessage("宠物收容所不接受死亡的宠物，先复活它吧~","YD_petmypet.asp")
				else
					petsp=DEF_PET_basicsp
					newexp=rs("mypetexp")-int(rs("mypetexp")*20/100)
					connpet.ExeCute("INSERT INTO petdeldata (username, mypet,mypetname,mypetlevel,mypetexp,mypetmaxhp,mypetatk,mypetdef,mypetsex,mypetsx,petdeldate)VALUES ('"& DvBBS.MemberName &"', '"& rs("mypet") &"', '"& rs("mypetname") &"', '"& rs("mypetlevel") &"', '"& newexp &"','"& rs("mypetmaxhp") &"', '"& rs("mypetatk") &"', '"& rs("mypetdef") &"', '"& rs("mypetsex") &"', '"& rs("mypetsx") &"', "& Pet_NowString &")")
					connpet.ExeCute("DELETE FROM mypetdata WHERE username='"& DvBBS.MemberName &"'")
					call showmessage("丢弃完了，宠物已经放在宠物收容所了","YD_petorphanage.asp")
				end if
			end if
			rs.close
		case "alldelpet"
			SQL = "SELECT * FROM mypetdata WHERE username='"& DvBBS.MemberName &"'"
			rs.open SQL,connpet,1,3
			if rs.eof then
				call showmessage("你还没有宠物啊，快攒钱去买吧~","YD_petshop.asp")
 			else
				connpet.ExeCute("DELETE FROM mypetdata WHERE username='"& DvBBS.MemberName &"'")
				call showmessage("丢弃完了，宠物已经去天堂了，你好狠心啊","YD_petorphanage.asp")
			end if
			rs.close
		case "adoptpet"
			SQL = "SELECT * FROM mypetdata WHERE username='"& DvBBS.MemberName &"'"
			rs.open SQL,connpet,1,3
			if not rs.eof then
				call showmessage("你已经有一个宠物了，做人不要三心两意啊~","YD_petorphanage.asp")
			else
				petsp=DEF_PET_basicsp
				dim petid,mypet
				petid = cint(request.querystring("petid"))
				if petid = "" then petid = 0
				SQL = "SELECT * FROM petdeldata WHERE id="&petid
				set rspet = connpet.ExeCute(SQL)
				if rspet.eof then
					call showmessage("你没有成功领养宠物，你要领养的宠物不存在~","YD_petorphanage.asp")
				else
					mypet = rspet("mypet")
					connpet.ExeCute("INSERT INTO mypetdata (username, mypet,mypetname,mypetlevel,mypetexp,mypethp,mypetmaxhp,mypetsp,mypetatk,mypetdef,mypetdead,mypetsex,mypetsx,petregdate,atkskill,defskill,luckskill,learnskill,lifeskill,hpmaxskill)VALUES ('"& DvBBS.MemberName &"', '"& rspet("mypet") &"', '"& rspet("mypetname") &"', '"& rspet("mypetlevel") &"', '"& rspet("mypetexp") &"', '"& rspet("mypetmaxhp") &"', '"& rspet("mypetmaxhp") &"', '"& petsp &"', '"& rspet("mypetatk") &"', '"& rspet("mypetdef") &"', '0', '"& rspet("mypetsex") &"', '"& rspet("mypetsx") &"', "&Pet_NowString&", '0', '0', '0', '0', '0', '0')")
					connpet.ExeCute("DELETE FROM petdeldata WHERE id="&petid)
					call showmessage("你领养了 "& mypet &" 好好照顾他啊","YD_petmypet.asp")
				end if
				rspet.close
			end if
			rs.close
	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 valign=top>
      <table width="100%" cellspacing="0" cellpadding="0">
	<tr>
	  <td width="28%" align="right">
	    <table width="79%" align="center" cellpadding="3" cellspacing="3">
	      <tr>
		<td width="100%" 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>
	    <table width="100%" cellspacing="4" cellpadding="4">
	      <tr>
		<td align="center"><a href="YD_petorphanage.asp?action=adopt">领养宠物</a><br>
		<a href="YD_petorphanage.asp?action=del">丢弃宠物</a>
		</td>
	      </tr>
	    </table>
	    <table width="90%" align="center" cellpadding="3" cellspacing="3">
	      <tr>
		<td align="center">
		<!-- #include file=YD_petnav.asp -->
		</td>
	      </tr>
	    </table>
	  </td>
	  <td align="center">
<%
if action = "adopt" then
'凌峰,增加孤儿简单分页.2005-06-16
dim deldate, olddate, sqltmp
deldate = Checkstr(request("t"))
if deldate="" or not IsDate(deldate) then
	SQL = "SELECT top 10 * FROM petdeldata ORDER BY petdeldate DESC"
else
	SQL = "SELECT top 10 * FROM petdeldata where petdeldate<'"& deldate &"' ORDER BY petdeldate DESC"
end if
sqltmp = "select COUNT(id) from petdeldata"
%>
	    <TABLE cellSpacing=0 cellPadding=0 width=100% align=center>
	      <tr>
		<TD colspan="5" align=center>
		  	    <table class=tableborder1 style="width:100%" cellspacing=1 cellpadding=3 align=center>
		    <tr>
		      <th width="28%" align="center">宠物照片</th>
		      <th width="24%" align="center">宠物介绍</th>
		      <th width="33%" align="center">收养宠物</th>
		    </tr>
<%
	'取孤儿数
	set rspet = connpet.ExeCute(sqltmp)
	sqltmp=rspet(0)
	rspet.close
	set rspet =nothing

	set rspet = connpet.ExeCute(SQL)
	dim num
	num = 0
	while not rspet.eof and num < 10
		levelpic=int(rspet("mypetlevel")/10)
		if (levelpic>10) then levelpic=11 end if
		if (rspet("mypetsex")=1) then
			thispetsex="男生"
		else
			thispetsex="女生"
		end if
%>
		    <tr>
		      <td class=TableBody1 width="28%" align="center"><IMG src="YD_plus/YD_pet/PET/<%=rspet("mypetname")%>/<%=rspet("mypetname")%><%=levelpic%>.gif"></td>
		      <td class=TableBody1 width="24%">宠物名字：<%=rspet("mypet")%><br>宠物级别：<%=rspet("mypetlevel")%><br>宠物攻击力：<%=rspet("mypetatk")%><br>宠物防御力：<%=rspet("mypetdef")%><br>宠物性别：<%=thispetsex%><br>宠物前主人：<a href="dispuser.asp?name=<%=rspet("username")%>"><%=rspet("username")%></a></td>
		      <td class=TableBody1 width="10%" align="center">
			<input name='Submit2' type='button' value='领养宠物' onclick="javascript:window.location='YD_petorphanage.asp?action=adoptpet&petid=<%=rspet("id")%>';">
		      </td>
		    </tr>
<%
		olddate = rspet("petdeldate")
		rspet.movenext
		num = num + 1
	wend
%>
	<tr>
		<td class=TableBody1>
		共有 <%= sqltmp %> 只孤儿.
		</td>
		<td COLSPAN=2 ALIGN=right class=TableBody1>
			<a href="#" onclick="javascript:history.go(-1);">上一页</a>&nbsp;&nbsp;
			<% if num<10 then
				response.Write "下一页"
			else
			%>
			<a href="YD_petorphanage.asp?action=adopt&t=<%= olddate %>">下一页</a>
			<% end if %>
		</td>
	</tr>
<%
	rspet.close
%>                               
		  </table>
		</TD>
	      </TR>
	    </TABLE>
<%end if%>

<%if action = "del" then%>
	    <form action=YD_petorphanage.asp name="name" mtehod=post>
	    <TABLE cellSpacing=0 cellPadding=0 width=100% align=center>
	      <TR> 
		<TD width="57%" align=center><img src="YD_plus/YD_pet/PET/30.gif"></TD>
	      </TR>
	      <TR> 
		<TD align="center"><br>
		<a href="YD_petorphanage.asp?action=delpet">放进孤儿院</a> 
		<a href="YD_petorphanage.asp?action=alldelpet">彻底丢弃</a>
		</TD>
	      </TR>
	    </TABLE>
	    </form>
<%end if%>
	  </td>
	</tr>
      </table>
    </td>
  </tr>
</table>
<%
end sub
%>