<!--#include file="Setup.asp"-->
<!--#include file="Pet/PetSetup.asp"-->

<%
top

if CookieUserName=empty then error("<li>您还未<a href=login.asp>登录</a>社区")
GoBack="<li><a href='PetAffairs.asp'>返回宠物事务所</a>" 

	Set RsPet=server.createobject("adodb.recordSet")
	sql_pet="Select * From [PetData] Where UserName='"&CookieUserName&"'"
	RsPet.Open sql_pet,ConnPet,1,1
	if RsPet.eof then
		error("你在论坛还没有宠物啊，<a href=PetShop.asp>抢先去买一个吧~</a>")
		else
        UserMoney=Conn.execute("Select UserMoney From [BBSXP_Users] Where UserName='"&CookieUserName&"'")(0)
        PetName = RsPet("MyPet")
		PetSex = RsPet("PetSex")
        PetOpenPk = RsPet("OpenPK")
            
    end if
    RsPet.close
    
Select case Request("Action")

'宠物改名
case "ChangeName"
    PetName=Request.Form("PetName")
    if(len(PetName) > DEF_PET_namelong) then
    message="<li>你的宝宝名字太长了,请控制在"&DEF_PET_namelong&"个字符以下."&GoBack
    elseif(PetName="") then
    message="<li>你没有填写宝宝的名字."&GoBack
    elseif instr("|"&DEF_PET_NameExpt&"|","|"&PetName&"|")>0 then
    error("你的宝宝名字含有系统规定不允许的字符，还是换个吧~")
    else
    sql_pet = "Update [PetData] Set MyPet='"&PetName&"' Where UserName='"&CookieUserName&"'"
    ConnPet.ExeCute(sql_pet)
    message="<li>改名成功，你的宝宝改名为 "&PetName&"!"&GoBack
    end if
    succeed(message&"<meta http-equiv=refresh content=3;url='PetAffairs.asp'")
'宠物更改性别
    case "ChangeSex"
    if(UserMoney<DEF_PET_ChangeSexMoney) then
    message="<li>对不起你没有那么多钱为宝宝做变性手术!"&GoBack&""
    else 
    Conn.Execute("Update [BBSXP_Users] Set UserMoney=UserMoney-"&DEF_PET_ChangeSexMoney&" Where UserName='"&CookieUserName&"'")
    ConnPet.ExeCute("Update PetData Set PetSex="&Request("PetSex")&" Where UserName='"&CookieUserName&"'")
    If Request("PetSex")=1 then message="<li>改变性别成功，你的宝宝变为雄性!"&GoBack end if
    if Request("PetSex")=2 then message="<li>改变性别成功，你的宝宝变为雌性!"&GoBack end if
    end if
    succeed(message&"<meta http-equiv=refresh content=3;url='PetAffairs.asp'")

'更改PK开关
    case "OpenPk"
	OpenPetPk=int(Request("OpenPetPk"))
    if OpenPetPk = 1 then message="<li>成功开启PK模式!"&GoBack end if
    if OpenPetPk = 0 then message="<li>成功关闭PK模式!"&GoBack end if
    ConnPet.ExeCute("Update [PetData] Set OpenPk="&OpenPetPk&" Where UserName='"&CookieUserName&"'")
    succeed(message&"<meta http-equiv=refresh content=3;url='PetAffairs.asp'")

'赠送宠物    
    case "PresentPet"
    NewName=HTMLEncode(Request("NewName"))
    if CookieUserName = NewName then
    message="<li>干吗啊，自己送宠物给自己!"
    elseif Conn.Execute("Select UserName From [BBSXP_Users] Where UserName='"&NewName&"'").eof then
    message="<li>论坛里面没有这个人"&GoBack
    elseif not ConnPet.Execute("Select UserName From [PetData] Where UserName='"&NewName&"'").eof then 
    message="<li>他已经有宠物了，你还是把宠物留给自己吧~"&GoBack
    else
    ConnPet.ExeCute("Update [PetData] Set UserName='"&NewName&"' Where UserName='"&CookieUserName&"'")
    Conn.Execute("insert into [BBSXP_Messages] (UserName,incept,content) values ('"&CookieUserName&"','"&Request("NewName")&"','【宠物消息】："&CookieUserName&"送给你一个宠物，并且留下赠言："&Request("message")&"，快去看看吧')")
    Conn.Execute "Update [BBSXP_Users] Set newmessage=newmessage+1 Where UserName='"&NewName&"'"
    message="<li>赠送成功，你的宝宝已经送给了 "&Request("NewName")&"!"&GoBack
    end if
    succeed(message&"<meta http-equiv=refresh content=3;url='PetAffairs.asp'")
'丢弃宠物
    case "DelPet"
    ConnPet.ExeCute("delete From [PetData] Where UserName='"&CookieUserName&"'")
    message="<li>丢弃完了，宠物已经去天堂了，你好狠心啊"&GoBack
    

    end Select
ShowPetTop("宠物事务所")
%>
<br />
<div class="mainnav">    
 <table width=100% border="0" cellspacing="2" cellpadding="2" align="center"><tr>
 <td>
 
 <form action="?Action=ChangeName" method="post">
 <table width="100%"  border="0" cellpadding="3" cellspacing="1" class=a2>
 <tr class=a3> 
 <td width="20%"> 为宝宝改名字： </td>
 <td width="71%"> <input name="PetName" type="text" value="<%=PetName%>" size="20" maxlength="16"> 
 <input type="submit" value="改名"> &nbsp;&nbsp;</td>              
 </tr>
 </table>
 </form>
				  
 <form action="?Action=ChangeSex" method="post">
 <table width="100%"  border="0" cellpadding="3" cellspacing="1" class=a2>
 <tr class=a3>
 <td width="20%">为宝宝做变性手术：</td>
 <td width="71%"><input type="radio" name="PetSex" <%if PetSex=1 then response.write "checked"%> value="1"> 雄&nbsp;&nbsp;&nbsp;
 <input type="radio" name="PetSex" <%if PetSex=2 then response.write "checked"%> value="2"> 雌&nbsp;&nbsp;&nbsp; 
 <input type="submit" name="Submit" value="改变性别">              
 &nbsp;&nbsp;&nbsp; <font color="#FF0000">注意：需要花费<%=DEF_PET_ChangeSexMoney%><%=DEF_PointsName%></font> </td>             
 </tr>
 </table>
 </form>

 <form action="?Action=PresentPet" method="post">
 <table width="100%" border="0" cellpadding="3" cellspacing="1" class=a2>
 <tr class=a3>
 <td width="20%" valign="top">把我的宝宝送给：</td>
 <td width="71%"><input name="NewName" type="text" size="20" maxlength="16">&nbsp;&nbsp;&nbsp;               
 <br /><br />
 <textarea name="message" cols="30" rows="4">赠送复言</textarea>
 <input type="submit" name="Submit" value="赠送宠物">              
 </td>
 </tr>
 </table>
 </form>
 
 <form action="?Action=OpenPk" method="post">
 <table width="100%" border="0" cellpadding="3" cellspacing="1" class=a2>
 <tr class=a3>
 <td width="20%"> 是否开启PK： </td>
 <td width="71%"> 
 <input type="radio" name="OpenPetPk" <%if PetOpenPk=1 then response.write "checked"%> value="1">开启&nbsp;&nbsp;&nbsp; 
 <input type="radio" name="OpenPetPk" <%if PetOpenPk=0 then response.write "checked"%> value="0">关闭 &nbsp;&nbsp;
 <input type="submit" value="确定"></td>
 </tr>
 </table></form>

 <table width="100%"  border="0" cellpadding="3" cellspacing="1" class=a2><tr class=a3>
 <td width="20%">宠物操作：</td>
 <td width="71%">&nbsp;&nbsp;<a href="#" title="未开放">宠物转生</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="?Action=DelPet" onClick="javascript:{if(confirm('您确定要永远丢弃你的宝宝么?')){return true;}return false;}">丢弃宠物</a></td>
 </tr></table>
          
 </td>
 </tr>
 </table>
</div>
	

<%
ShowPetBottom
htmlend
%>
