<!-- #include file=../../inc/BBSsetup.asp -->
<!-- #include file=../../inc/Board_popfun.asp -->
<!-- #include file=pet_conn.asp -->
<!--#include file=pet_config.asp-->
<%
DEF_BBS_HomeUrl = "../../"
dim menu,savem,rsbank,rssql,chentitle,chenbackasp,stats,errmsg,founderr

chentitle= "宠物孤儿院"
chenbackasp="petcenter.asp"
stats="宠物孤儿院"
BBS_SiteHead DEF_SiteNameString&" "&DEF_BBS_Name,GBL_board_ID,">>&nbsp;<a href=petcenter.asp>宠物中心</a>&nbsp;>>&nbsp;" & chentitle

if GBL_CHK_User="" then
	AlarmErrmsg
else
    dim money,smoney,saveday,allmoney,time1,time2,daikuang,dkdu,daiday,sucmsg
    dim Form_userphoto,Form_FaceUrl,Form_FaceWidth,Form_FaceHeight
    
    Dim Rs,SQL

	OpenDatabase	
    set rs=con.execute("select * from [leadbbs_user] where username='"&GBL_CHK_User&"' ")
      	
    money=rs("points")

	Form_userphoto = Rs("Userphoto")
	If DEF_AllDefineFace = 1 Then
		Form_FaceUrl = Rs("FaceUrl")
		Form_FaceWidth = Rs("FaceWidth")
		Form_FaceHeight = Rs("FaceHeight")
	End If    

    rs.close
    


            
dim action,petsp,pettoday,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='"&GBL_CHK_User&"'"
    rs.open SQL,connpet,1,3
    if rs.eof then
            call showmessage("你还没有宠物啊，快攒钱去买吧~","petshop.asp")
        else
        
        if rs("mypetdead") <> 0 then 
                call showmessage("宠物收容所不接受死亡的宠物，先复活它吧~","mypet.asp")
            else

                petsp=DEF_PET_basicsp
                pettoday = now()
        
                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 ('"&GBL_CHK_User&"', '"& rs("mypet") &"', '"& rs("mypetname") &"', '"& rs("mypetlevel") &"', '"& newexp &"','"& rs("mypetmaxhp") &"', '"& rs("mypetatk") &"', '"& rs("mypetdef") &"', '"& rs("mypetsex") &"', '"& rs("mypetsx") &"', '"& pettoday &"')")
                connpet.ExeCute("DELETE FROM mypetdata WHERE username='"&GBL_CHK_User&"'")
                call showmessage("丢弃完了，宠物已经放在宠物收容所了","petorphanage.asp")
            
        end if

    end if
    rs.close

    case "alldelpet"

    SQL = "SELECT * FROM mypetdata WHERE username='"&GBL_CHK_User&"'"
    rs.open SQL,connpet,1,3
    if rs.eof then
            call showmessage("你还没有宠物啊，快攒钱去买吧~","petshop.asp")
        else

        connpet.ExeCute("DELETE FROM mypetdata WHERE username='"&GBL_CHK_User&"'")
        call showmessage("丢弃完了，宠物已经去天堂了，你好狠心啊","petorphanage.asp")

    end if
    rs.close

    case "adoptpet"
        
    SQL = "SELECT * FROM mypetdata WHERE username='"&GBL_CHK_User&"'"
    rs.open SQL,connpet,1,3
    if not rs.eof then
            call showmessage("你已经有一个宠物了，做人不要三心两意啊~","petorphanage.asp")
        else
        
        petsp=DEF_PET_basicsp
        pettoday = now()

        dim petid,mypet
        petid = request.querystring("petid")
        if petid = "" then petid = 0 end if

        SQL = "SELECT * FROM petdeldata WHERE id="&petid
        'response.write sql: response.end
        set rspet = connpet.ExeCute(SQL)
        if rspet.eof then
                call showmessage("你没有成功领养宠物，你要领养的宠物不存在~","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,hpitem,spitem,expitem)VALUES ('"&GBL_CHK_User&"', '"& rspet("mypet") &"', '"& rspet("mypetname") &"', '"& rspet("mypetlevel") &"', '"& rspet("mypetexp") &"', '"& rspet("mypetmaxhp") &"', '"& rspet("mypetmaxhp") &"', '"& petsp &"', '"& rspet("mypetatk") &"', '"& rspet("mypetdef") &"', '0', '"& rspet("mypetsex") &"', '"& rspet("mypetsx") &"', '"& pettoday &"', '0', '0', '0')")
                connpet.ExeCute("DELETE FROM petdeldata WHERE id="&petid)
                call showmessage("你领养了 "& mypet &" 好好照顾他啊","petorphanage.asp")
        end if
        rspet.close

    end if
    rs.close
    
end select


%>
<% If GBL_TableHeadString <> "" Then %><table width=<%=DEF_BBS_ScreenWidth%> border=0 cellspacing=0 cellpadding=0 align=center><tr><td><%=GBL_TableHeadString%></td></tr></table><% End If %>
<table width="<%=DEF_BBS_ScreenWidth%>" border="0" cellspacing="1" cellpadding="5" align="center" class=TBone>
  <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="0" cellpadding="0">
              <tr> 
                <td width="28%"> <div align="right"> 
                    <table width="79%"  border="0" align="center" cellpadding="3" cellspacing="3">
                      <tr> 
                        <td width="100%"><div align="center">
					<%
					If isNull(Form_FaceUrl) Then Form_FaceUrl = ""
					If DEF_AllDefineFace = 0 or Trim(Form_FaceUrl) = "" Then%>
					<img src=<%=DEF_BBS_HomeUrl%>images/face/<%=string(4-len(cstr(Form_userphoto)),"0")&Form_userphoto%>.gif align=absmiddle width=62 height=62>
					<%Else%>
						<img src="<%=htmlencode(replace(Form_FaceUrl,"../","../../"))%>" align=absmiddle width=<%=Form_FaceWidth%> height=<%=Form_FaceHeight%>>
					<%End If%>
					<br><img src=../images/blank.gif width=2 height=5><br>
                        </div></td>
                      </tr>
                      <tr> 
                    <td> <div align="center">
                        <nobr>用户<%=DEF_PointsName%>: <%=money%></nobr>
                        </div></td>
                      </tr>
                    </table>
                  <table width="100%" border="0" cellspacing="4" cellpadding="4">
                      <tr> 
                        <td><div align="center"><a href="petorphanage.asp?action=adopt">领养宠物</a></div>
                          <div align="center"><a href="petorphanage.asp?action=del">丢弃宠物</a></div></td>
                      </tr>
                    </table>
                    <table width="90%"  border="0" align="center" cellpadding="3" cellspacing="3">
                      <tr> 
                        <td><div align="center"></div>
<!-- #include file=petnav.asp --></td>
                      </tr>
                    </table>
                  </div></td>
                <td> <div align="center"> </div>
                  <div align="center"></div>
                  <%if action = "adopt" then%>
                    <TABLE class=text1 cellSpacing=1 cellPadding=3 width=100% align=center border=0>
                      <TR> 
                        <TD colspan="5"> <DIV align=center> 
                            <table width="100%" border="0" align="center" cellpadding="3" cellspacing="3">
                              <tr> 
                                <td width="28%"><div align="center">宠物照片</div></td>
                                <td width="24%"><div align="center">宠物介绍</div></td>
                                <td width="33%"> 
                                  <div align="center">收养宠物</div>
                                  </td>
                              </tr>
<%
SQL = "SELECT top 10 * FROM petdeldata ORDER BY mypetlevel DESC"
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 width='28%'><div align='center'><IMG src='images/pet/<%=rspet("mypetname")%>/<%=rspet("mypetname")%><%=levelpic%>.gif'></div></td>
<td width='24%'>宠物名字：<%=rspet("mypet")%><br>宠物级别：<%=rspet("mypetlevel")%><br>宠物攻击力：<%=rspet("mypetatk")%><br>宠物防御力：<%=rspet("mypetdef")%><br>宠物性别：<%=thispetsex%><br>宠物前主人：<a href="../../User/LookUserinfo.asp?name=<%=rspet("username")%>"><%=rspet("username")%></a></div></td>
<td width='10%'><div align='center'>
<input name='Submit2' type='button' value='领养宠物' onclick="javascript:window.location='petorphanage.asp?action=adoptpet&petid=<%=rspet("id")%>';">
</div></td>
</tr>
<%
rspet.movenext
num = num + 1
wend
rspet.close
%>                               
                            </table>
                          </DIV></TD>
                      </TR>
                    </TABLE>
                  <%end if%>
                  <%if action = "del" then%>
                  <form action=petorphanage.asp name="name" mtehod=post>
                    <TABLE class=text1 cellSpacing=0 cellPadding=0 width=100% align=center border=0>
                      <TR> 
                        <TD width="57%"> <DIV align=center><img src="images/pet/30.gif"></DIV></TD>
                      </TR>
                      <TR> 
                        <TD><div align="center"><br>
                            <a href="petorphanage.asp?action=delpet">放进孤儿院</a> 
                            <a href="petorphanage.asp?action=alldelpet">彻底丢弃</a></div></TD>
                      </TR>
                    </TABLE>
                  </form>
                  <%end if%>
                </td>
              </tr>
            </table>


	</td></tr></table>
<% If GBL_TableBottomString <> "" Then %><table width=<%=DEF_BBS_ScreenWidth%> border=0 cellspacing=0 cellpadding=0 align=center><tr><td><%=GBL_TableBottomString%></td></tr></table><% End If %>
<%    
end if

SiteBottom 
If GBL_SiteBottomString <> "" Then Response.Write GBL_SiteBottomString
%>