<!--#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 SumAmount, i, j, TempStr
Dim AvatarArray, ItemCount, AvatarStr, TempArray(), CartBagArray, TempCount

Dv_Plus.Name = "Plus_Avatar"
Dv_Plus.CheckLogin
Dvbbs.LoadTemplates "Avatar"
Dvbbs.Stats = Template.Strings(17)
Dvbbs.ActiveOnline
v_FoundErr = False
If Dvbbs.Forum_Setting(82) <> "0" Then
	v_ErrCodes = "<li>该论坛尚未开启虚拟形象功能，不能查看物品清单！"
	v_FoundErr = True
Else
	If Trim(Request("Avatar")) = "" Then
		AvatarStr = ""
	Else
		AvatarStr = Split(Trim(Request("Avatar")), ",")(0)
	End If
	ItemCount = Avatar_GetInfo(AvatarStr, AvatarArray)
	If ItemCount = 0 Then
		If v_ErrCodes <> "" Then v_ErrCodes = v_ErrCodes & "<br>"
		v_ErrCodes = v_ErrCodes & "<li>提交的数据有错误！"
		v_FoundErr = True
	Else
		ItemCount = 0
		For i = 0 To Ubound(AvatarArray)
			If AvatarArray(i) <> "" Then
				If Not IsEmotionItem(AvatarArray(i)) And Not IsDefaultItem(AvatarArray(i)) Then
					For j = 0 To i - 1
						If AvatarArray(j) = AvatarArray(i) Then Exit For
					Next
					If j > i - 1 Then
						ReDim Preserve TempArray(ItemCount)
						TempArray(ItemCount) = AvatarArray(i)
						ItemCount = ItemCount + 1
					End If
				End If
			End If
		Next
		If Request.Form("cmdclear") = "放入购物袋" Then
			If Dvbbs.UserID = 0 Then
				v_ErrCodes = v_ErrCodes & "<li>您不是会员，不能将商品放入购物袋！"
				v_FoundErr = True
			Else
				SucMsg = ""
				For i = 0 To ItemCount - 1
					TempCount = CartBag_GetInfo(CartBagArray, Dvbbs.UserID)
					If Not Dvbbs.Plus_Execute("Select Top 1 ID From Dv_Plus_Avatar_MyItems Where UserName='" & Dvbbs.MemberName & "' And ItemID=" & TempArray(i)).Eof Then
					ElseIf CartBag_FindItem(CartBagArray, CLng(TempArray(i)), "") Then
					ElseIf TempCount < CLng(AvatarXMLDOM.documentElement.selectSingleNode("AvatarInfo").Attributes.getNamedItem("CartLength").Text) Then
						Set AvatarRs = Dvbbs.Plus_Execute("Select Top 1 Name,VIP,Quantity,Flag From Dv_Plus_Avatar_Items Where ID=" & TempArray(i))
						If Not AvatarRs.Eof Then
							TempStr = CheckBuy(AvatarRs(0), AvatarRs(1), AvatarRs(2), AvatarRs(3))
							If TempStr <> "" Then
								If SucMsg <> "" Then SucMsg = SucMsg & "<br>"
								SucMsg = SucMsg & TempStr
							Else
								Call CartBag_AddItem(CartBagArray, CLng(TempArray(i)), "", "")
								Call CartBag_SetInfo(CartBagArray, Dvbbs.UserID)
								If SucMsg <> "" Then SucMsg = SucMsg & "<br>"
								SucMsg = SucMsg & "<li>已将商品《" & AvatarRs(0) & "》放到您的购物袋中！"
							End If
						End If
						AvatarRs.Close
					Else
						If SucMsg <> "" Then
							SucMsg = SucMsg & "<br><li>您的购物袋已满，只能放入部分商品！"
						Else
							SucMsg = "<li>您的购物袋已满，无法再放入任何商品！"
						End If
						Exit For
					End If
				Next
				If SucMsg = "" Then
					SucMsg = "<li>没有任何形象商品需要放入购物袋！"
				Else
					SucMsg = SucMsg & "<br><li>您选择的商品已经成功地放入购物袋中，请打开<a href=""Plus_Avatar_CartBag.asp"" target=""_blank""><font color=blue>购物袋</font></a>进行结算。"
				End If
				Call ShowSuc(SucMsg, False)
			End If
		Else
			Dvbbs.Head
			Call Main
		End If
	End If
End If
If v_FoundErr Then
	Call ShowErr(False)
End If
Dvbbs.Footer
Set Dv_Plus = Nothing

Sub Main()
	Dim i, TempStr, SendSplit, Rs, CurPrice, CurSex, SumAmount, ItemList, ListStr
	
	TempStr = Template.HTML(12)
	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
	TempStr = Replace(TempStr, "{$AvatarStr}", AvatarStr)
	SumAmount = 0
	If ItemCount = 0 Then
		TempStr = Replace(TempStr, "{$ItemList}", Template.HTML(14))
	Else
		ItemList = ""
		For i = 1 To ItemCount
			ListStr = Template.HTML(13)
			Set Rs = Dvbbs.Plus_Execute("Select Top 1 ID,Name,Sex,Price1,Price2 From Dv_Plus_Avatar_Items Where ID=" & TempArray(i - 1))
			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>"
				Else
					SumAmount = SumAmount + CurPrice
					CurPrice = CurPrice & " 元"
				End If
				If Not Dvbbs.Plus_Execute("Select Top 1 ID From Dv_Plus_Avatar_MyItems Where UserName='" & Dvbbs.MemberName & "' And ItemID=" & TempArray(i - 1)).Eof Then
					ListStr = Replace(ListStr, "{$HasOwned}", "是")
				Else
					ListStr = Replace(ListStr, "{$HasOwned}", "否")
				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, "{$Avatar}", Avatar_RemoveItem(AvatarArray, TempArray(i - 1)))
				ItemList = ItemList & ListStr
			End If
			Rs.Close
		Next
		TempStr = Replace(TempStr, "{$ItemList}", ItemList)
	End If
	TempStr = Replace(TempStr, "{$SumAmount}", SumAmount)
	If ItemCount = 0 Then
		TempStr = Replace(TempStr, "{$Disabled}", "disabled=""true""")
	Else
		TempStr = Replace(TempStr, "{$Disabled}", "")
	End If
	Response.Write TempStr
End Sub
%>