<!--#include file=conn.asp-->
<!--#include file="inc/const.asp" -->
<!--#include file="inc/plus_check.asp"-->
<!--#include file="Dv_Plus/Avatar/Plus_Avatar_Const.asp"-->
<%
Dim CurItem, ItemName
Dim FixType, FixDays, CurType, CurPrice, TempPeriod
Dim FixFee, TempStr, FixPeriod
Dim FixFee0, FixFee1, New0, New1
Dim RetFlag

Dv_Plus.Name = "Plus_Avatar"
Dv_Plus.CheckLogin
Dvbbs.LoadTemplates "Avatar"
Dvbbs.Stats = Template.Strings(9)
Dvbbs.ActiveOnline
v_FoundErr = False
If Request("action") = "fix" Then
	RetFlag = True
Else
	RetFlag = False
End If
If Dvbbs.Forum_Setting(82) <> "0" Then
	v_ErrCodes = "<li>该论坛尚未开启虚拟形象功能，不能翻新任何形象商品！"
	v_FoundErr = True
ElseIf Dvbbs.UserID = 0 Then
	v_ErrCodes = "<li>您不是会员，不能翻新任何形象商品！"
	v_FoundErr = True
Else
	If IsNull(Request("itemid")) Or Request("itemid") = "" Then
		If v_ErrCodes <> "" Then v_ErrCodes = v_ErrCodes & "<br>"
		v_ErrCodes = v_ErrCodes & "<li>没有指定商品编号！"
		v_FoundErr = True
	Else
		CurItem = CLng(Request("itemid"))
	End If
	If Request("action") = "fix" Then
		If IsNull(Request("fixtype")) Or Request("fixtype") = "" Then
			If v_ErrCodes <> "" Then v_ErrCodes = v_ErrCodes & "<br>"
			v_ErrCodes = v_ErrCodes & "<li>翻新方式不可为空！"
			v_FoundErr = True
		Else
			FixType = CLng(Request("fixtype"))
			If FixType <> 0 Then FixType = 1
		End If
		If FixType = 1 Then
			If IsNull(Request("fixdays")) Or Request("fixdays") = "" Then
				If v_ErrCodes <> "" Then v_ErrCodes = v_ErrCodes & "<br>"
				v_ErrCodes = v_ErrCodes & "<li>翻新天数不可为空！"
				v_FoundErr = True
			Else
				FixDays = Request("fixdays")
				If Not isInteger(FixDays) Then
					If v_ErrCodes <> "" Then v_ErrCodes = v_ErrCodes & "<br>"
					v_ErrCodes = v_ErrCodes & "<li>翻新天数必须是整数！"
					v_FoundErr = True
				Else
					FixDays = CLng(FixDays)
					If FixDays <= 0 Or FixDays > 100 Then
						If v_ErrCodes <> "" Then v_ErrCodes = v_ErrCodes & "<br>"
						v_ErrCodes = v_ErrCodes & "<li>翻新天数必须是介于0到100之间的整数！"
						v_FoundErr = True
					End If
				End If
			End If
		End If
	End If
End If
If v_FoundErr Then
	Call ShowErr(RetFlag)
Else
	Set AvatarRs = Dvbbs.Plus_Execute("Select Top 1 Name,Class,Period,Price1,Price2 From Dv_Plus_Avatar_Items Where ID=" & CurItem)
	If Not AvatarRs.EOF Then
		ItemName = AvatarRs(0)
		CurType = AvatarRs(1)
		New0 = CLng(AvatarXMLDOM.documentElement.selectSingleNode("AvatarInfo").Attributes.getNamedItem("FixForeverFeeTimes").Text)
		New1 = CLng(AvatarXMLDOM.documentElement.selectSingleNode("AvatarInfo").Attributes.getNamedItem("FixOneDayFeeRate").Text)
		FixPeriod = 30
		If AvatarRs(2) > 0 Then FixPeriod = AvatarRs(2)
		If FixPeriod <= 0 Then FixPeriod = 30
		If v_MyVip <> 1 Then
			CurPrice = AvatarRs(3)
		Else
			CurPrice = AvatarRs(4)
		End If
		If CurType = 6 Then
			FixFee1 = Int(CurPrice / FixPeriod + 0.99)
		Else
			FixFee1 = Int(CurPrice * New1 / 100 / FixPeriod + 0.99)
		End If
		FixFee0 = CurPrice * New0
		If Request("action") = "fix" Then
			If FixType = 0 Then
				FixFee = FixFee0
			Else
				FixFee = FixFee1 * FixDays
			End If
		End If
		AvatarRs.Close
		AvatarSQL = "Select Top 1 Period,FixDate,Type From Dv_Plus_Avatar_MyItems Where ItemID=" & CurItem & " And UserName='" & Dvbbs.MemberName & "'"
		Set AvatarRs = Dvbbs.Plus_Execute(AvatarSQL)
		If AvatarRs.EOF Then
			If v_ErrCodes <> "" Then v_ErrCodes = v_ErrCodes & "<br>"
			v_ErrCodes = v_ErrCodes & "<li>您尚未拥有这个商品，不能翻新！"
			v_FoundErr = True
		ElseIf AvatarRs(0) = 0 Then
			If v_ErrCodes <> "" Then v_ErrCodes = v_ErrCodes & "<br>"
			v_ErrCodes = v_ErrCodes & "<li>您的这个商品已经是永远有效了，无须再次翻新！"
			v_FoundErr = True
		ElseIf CurType = 6 And FixType = 0 And Request("action") = "fix" Then
			If v_ErrCodes <> "" Then v_ErrCodes = v_ErrCodes & "<br>"
			v_ErrCodes = v_ErrCodes & "<li>整人道具不能翻新为永远有效！"
			v_FoundErr = True
		Else
			If AvatarRs(2) = 5 And Request("action") = "fix" Then CurType = 5
			If FixType = 0 Then
				TempPeriod = 0
			Else
				TempPeriod = AvatarRs(0) - DateDiff("d", AvatarRs(1), Now())
				If TempPeriod > 0 Then
					TempPeriod = TempPeriod + FixDays
				Else
					TempPeriod = FixDays
				End If
			End If
		End If
		AvatarRs.Close
	Else
		v_ErrCodes = v_ErrCodes & "<li>该商品不存在，不能翻新！"
		v_FoundErr = True
	End If
	If v_FoundErr Then
		Call ShowErr(RetFlag)
	Else
		If Request("action") = "fix" Then
			If v_MyMoney < FixFee Then
				If v_ErrCodes <> "" Then v_ErrCodes = v_ErrCodes & "<br>"
				v_ErrCodes = v_ErrCodes & "<li>翻新此商品需要现金 " & FixFee & " 元，您的现金(" & v_MyMoney & " 元)不足，无法翻新！"
				v_FoundErr = True
				Call ShowErr(RetFlag)
			Else
				Dvbbs.Plus_Execute ("Update Dv_Plus_Avatar_MyItems Set Period=" & TempPeriod & ",FixDate=" & SqlNowString & ",Type=" & CurType & " Where UserName='" & Dvbbs.MemberName & "' And ItemID=" & CurItem)
				Call UpdateUserWealth(Dvbbs.MemberName, -FixFee)
				SucMsg = "<li>已经成功地翻新了《" & ItemName & "》，花费了 <font color=" & Dvbbs.MainSetting(1) & ">" & FixFee & "</font> 元！"
				Call ShowSuc(SucMsg, False)
				Response.Write "<script>if(window.opener) window.opener.document.execCommand('Refresh');</script>"
			End If
		Else
			Dvbbs.Head
			TempStr = Template.HTML(10)
			TempStr = Replace(TempStr, "{$ItemName}", ItemName)
			With AvatarXMLDOM.documentElement.selectSingleNode("AvatarInfo").Attributes
				TempStr = Replace(TempStr, "{$SampleWidth}", .getNamedItem("SampleWidth").Text)
				TempStr = Replace(TempStr, "{$SampleHeight}", .getNamedItem("SampleHeight").Text)
				TempStr = Replace(TempStr, "{$LocalPic}", .getNamedItem("LocalPic").Text)
				TempStr = Replace(TempStr, "{$PicPath}", .getNamedItem("PicPath").Text)
			End With
			TempStr = Replace(TempStr, "{$ItemNo}", CurItem)
			TempStr = Replace(TempStr, "{$FixFee1}", FixFee1)
			If CurType = 6 Then
				TempStr = Replace(TempStr, "{$SecondExplain}", Template.Strings(40))
			Else
				TempStr = Replace(TempStr, "{$SecondExplain}", Replace(Template.Strings(39), "{$FixFee0}", FixFee0))
			End If
			TempStr = Replace(TempStr, "{$MyMoney}", v_MyMoney)
			If CurType = 6 Then TempStr = Replace(TempStr, "{$disabled}", "disabled=true")
			Response.Write TempStr
		End If
	End If
End If
Dvbbs.Footer
Set Dv_Plus = Nothing
%>