<!--#include file="connection.asp"-->
<!--#include file="inc/const.asp"-->
<!--#include file="inc/plus_check.asp"-->
<!-- #include file=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,"","宠物中心","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
    
    Dim Rs,SQL

	set rs=Dvbbs.execute("select Jamonery from [Jauser] where Jauid="&DvBBS.UserId)
      	
    money=rs("Jamonery")

	    

    rs.close
    

    
    sql = "SELECT * FROM mypetdata WHERE username='"&Dvbbs.MemberName&"' "
    rs.open sql,conn,1,3
    if rs.eof then
        call showmessage("你还没有宠物啊，快攒钱去买吧~","petshop.asp")
        else
        dim mypet,mypetsexmoney
        
        mypet = rs("mypet")
        mypetsexmoney = money
            
    end if
    rs.close
    
    select case lcase(request("action"))
        case "changename"
            if(len(request("petsname")) > DEF_PET_namelong) then
                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
                
                SQL = "UPDATE mypetdata SET mypet='"& request("petsname") &"' WHERE username='"&Dvbbs.MemberName&"'"
                conn.ExeCute(SQL)
                call showmessage("改名成功，你的宝宝改名为 "& request("petsname") &" ！","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 [Jauser] SET Jamonery=Jamonery-"&DEF_PET_changesexmoney&" WHERE Jauname='"&Dvbbs.MemberName&"'")
                conn.ExeCute("UPDATE mypetdata SET mypetsex=1 WHERE username='"&Dvbbs.MemberName&"'")
                call showmessage("改变性别成功，你的宝宝变为雄性 ！","petmypet.asp")
            elseif(request("petsex") = 2) then
                Dvbbs.ExeCute("UPDATE [jauser] SET jamonery=jamonery-"&DEF_PET_changesexmoney&" WHERE Jauname='"&Dvbbs.MemberName&"'")
                conn.ExeCute("UPDATE mypetdata SET mypetsex=2 WHERE username='"&Dvbbs.MemberName&"'")
                call showmessage("改变性别成功，你的宝宝变为雌性 ！","petmypet.asp")
            end if
        case "openpk"
            if(request("openpetpk") = 1) then
                conn.ExeCute("UPDATE mypetdata SET openpk=1 WHERE username='"&Dvbbs.MemberName&"'")
                call showmessage("成功开启PK模式！","petmypet.asp")
            elseif(request("openpetpk") = 2) then
                conn.ExeCute("UPDATE mypetdata SET openpk=2 WHERE username='"&Dvbbs.MemberName&"'")
                call showmessage("成功关闭PK模式！","petmypet.asp")
            end if
        case "presentpet"
            if(Dvbbs.MemberName = request("newname")) then
              call showmessage("干吗啊，自己送宠物给自己！","petother.asp")
            else
                SQL = "SELECT Jauname FROM [Jauser] WHERE Jauname='"&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 = conn.ExeCute(SQL)
                if not rs1.eof then
                    call showmessage("他已经有宠物了，你还是把宠物留给自己吧~","petother.asp")
                    else
                    conn.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")
    end select
%>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<table border="0" align="center" cellpadding="3" cellspacing="1" class="TableBorder1">
  <tr> 
    <th height="25">&nbsp;</th>
  </tr>
  <tr> 
    <td height="200" valign="top" class=TableBody1> 
      <table width="100%" 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="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"> 
                          <script src=z_visual_const2.asp?n=1></script>
                          <br>
                          <img src=../images/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"></div>
                        <!-- #include file=petnav.asp -->
                      </td>
                    </tr>
                  </table>
                </td>
                <td>
                  <form action="petother.asp" mtehod=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">
                          &nbsp;&nbsp;&nbsp; 
                          <input type="hidden" name="action" value="changename">
                          <input type="submit" value="改名" name="submit">
                          &nbsp;&nbsp;</td>
                      </tr>
                    </table>
                  </form>
                  <form action="petother.asp" mtehod=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" mtehod=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" mtehod=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="确定" name="submit">
                          &nbsp;&nbsp;&nbsp;</td>
                      </tr>
                    </table>
                  </form>
                </td>
              </tr>
            </table>
          </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
	'sDvbbs.execute("UPDATE [Jauser] 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
%>