<!--#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 CartBag, SendSplit, SumAmount, SendFee, TempStr
Dim CartBagArray, ItemCount, CurType, CurPrice, CurDate
Dim RetFlag

Dv_Plus.Name = "Plus_Avatar"
Dv_Plus.CheckLogin
Dvbbs.LoadTemplates "Avatar"
Dvbbs.Stats = Template.Strings(6)
Dvbbs.ActiveOnline
v_FoundErr = False
If Request.Form("cmdclear") = "结算" 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
	ItemCount = CartBag_GetInfo(CartBagArray, Dvbbs.UserId)
	If Request.Form("cmdclear") = "清空" Then
		ItemCount = 0
		ReDim CartBagArray(-1)
		Response.cookies("myAvatarBuy_" & Dvbbs.UserId) = ""
		Response.Write "<script>window.close();</script>"
	ElseIf Request.Form("cmddelete") = "删除" Then
		If ItemCount > 0 Then
			If Not IsNull(Request("seqno")) Then
				If isInteger(Request("seqno")) Then
					If CartBag_RemoveItem(CartBagArray, CLng(Request("seqno"))) Then
						ItemCount = ItemCount - 1
						Call CartBag_SetInfo(CartBagArray, Dvbbs.UserId)
					End If
					If Request("action") <> "" Then
						Response.redirect "Plus_Avatar_CartBag.asp"
					Else
						Response.redirect "Plus_Avatar_CartBag.asp?action=1"
					End If
				End If
			End If
		End If
		v_ErrCodes = "<li>提交的数据有错误！"
		v_FoundErr = True
	ElseIf Request.Form("cmdclear") = "结算" Then
		TempStr = CartBag_CheckBuy(CartBagArray)
		If TempStr <> "" Then
			v_ErrCodes = TempStr
			v_FoundErr = True
		Else
			SumAmount = CartBag_CalcAmount(CartBagArray, v_MyVip)
			If v_MyMoney < SumAmount Then
				v_ErrCodes = "<li>购买的商品共计 " & SumAmount & " 元，您的现金 " & v_MyMoney & " 元不够买这些商品。"
				v_FoundErr = True
			Else
				Call CartBag_Settlement(CartBagArray, Dvbbs.UserId, Dvbbs.MemberName)
				SucMsg = "<li>您购买的商品已经放入您的储物柜中，赠送的商品已经发送到指定人员的储物柜。"
				Call ShowSuc(SucMsg, False)
				If Request("action") <> "" Then
					Response.Write "<script>parent.location='Plus_Avatar_Save.asp?userisava=" & Request("UserIsAva") & "';</script>"
				Else
					Response.Write "<script>if(window.opener) window.opener.document.execCommand('Refresh');</script>"
				End If
			End If
		End If
	Else
		Dvbbs.Head
		Call Main
	End If
End If
If v_FoundErr Then Call ShowErr(RetFlag)
Dvbbs.Footer
Set Dv_Plus = Nothing

Sub Main()
	Dim i, TempStr, SendSplit, Rs, SendFee, CurPrice, CurSex, SumAmount, ItemList, ListStr
	
	TempStr = Template.HTML(7)
	TempStr = Replace(TempStr, "{$MyUserName}", Dvbbs.MemberName)
	TempStr = Replace(TempStr, "{$MyMoney}", v_MyMoney)
	If ItemCount = 0 Then
		TempStr = Replace(TempStr, "{$RowsCount}", 2)
	Else
		TempStr = Replace(TempStr, "{$RowsCount}", ItemCount + 1)
	End If
	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
	SumAmount = 0
	If ItemCount = 0 Then
		TempStr = Replace(TempStr, "{$ItemList}", Template.HTML(8))
	Else
		ItemList = ""
		For i = 1 To ItemCount
			ListStr = Template.HTML(9)
			SendSplit = Split(CartBagArray(i - 1), "$")
			Set Rs = Dvbbs.Plus_Execute("Select Top 1 ID,Name,Sex,Price1,Price2 From Dv_Plus_Avatar_Items Where ID=" & SendSplit(0))
			If Not Rs.EOF Then
				ListStr = Replace(ListStr, "{$ItemNo}", Rs(0))
				ListStr = Replace(ListStr, "{$ItemName}", Rs(1))
				If v_MyVip <> 1 Then
					CurPrice = Rs(3)
				Else
					CurPrice = Rs(4)
				End If
				If CurPrice <= 0 Then
					CurPrice = "<font color=" & Dvbbs.MainSetting(1) & ">免费</font>"
					If UBound(SendSplit) = 2 Then
						ListStr = Replace(ListStr, "{$SendUserName}", "<a href=Plus_Avatar_Send.asp?modify=1&itemid=" & SendSplit(0) & "&username=" & SendSplit(1) & "&myself=0><font color=blue>" & SendSplit(1) & "</font></a>")
					Else
						ListStr = Replace(ListStr, "{$SendUserName}", "自用")
					End If
				Else
					SumAmount = SumAmount + CurPrice
					If UBound(SendSplit) = 2 Then
						SendFee = Int(CurPrice * CDbl(AvatarXMLDOM.documentElement.selectSingleNode("AvatarInfo").Attributes.getNamedItem("SendFeeRate").Text) / 100 + 0.99)
						CurPrice = CurPrice & " <font color=" & Dvbbs.MainSetting(1) & "> + " & SendFee & " 元</font>"
						SumAmount = SumAmount + SendFee
						ListStr = Replace(ListStr, "{$SendUserName}", "<a href=Plus_Avatar_Send.asp?modify=1&itemid=" & SendSplit(0) & "&username=" & SendSplit(1) & "&myself=0><font color=blue>" & SendSplit(1) & "</font></a>")
					Else
						CurPrice = CurPrice & " 元"
						ListStr = Replace(ListStr, "{$SendUserName}", "自用")
					End If
				End If
				ListStr = Replace(ListStr, "{$ItemPrice}", CurPrice)
				If Rs(2) = 1 Then
					CurSex = "男"
				ElseIf Rs(2) = 0 Then
					CurSex = "女"
				Else
					CurSex = "不限"
				End If
				ListStr = Replace(ListStr, "{$ItemSex}", CurSex)
				ListStr = Replace(ListStr, "{$ItemSeqNo}", i)
				ItemList = ItemList & ListStr
			End If
		Next
		TempStr = Replace(TempStr, "{$ItemList}", ItemList)
	End If
	If ItemCount = 0 Then
		TempStr = Replace(TempStr, "{$Disabled}", "disabled=""true""")
	Else
		TempStr = Replace(TempStr, "{$Disabled}", "")
	End If
	TempStr = Replace(TempStr, "{$Action}", Request("action"))
	TempStr = Replace(TempStr, "{$UserIsAva}", Request("userisava"))
	TempStr = Replace(TempStr, "{$SumAmount}", SumAmount)
	Response.Write TempStr
End Sub
%>