<!--#include file=conn.asp-->
<!--#include file=config.asp-->
<!--#include file=const.asp-->
<!--#include file=char.asp-->
<!--#include file="Visual_const.asp"-->
<%
 '=========================================================
' File: visual_cartbag.asp
' Version:3.0
' Date: 2005-10-29
' Script Written by xmrxw
'=========================================================
' Copyright (C) 2004,2005 Xmrxw.Com All rights reserved.
' Web: http://www.xmrxw.com,http://www.xmzxw.com
' Email: info@mssky.com,super@mssky.com
' QQ：10689579　Msn：zdlmicr@hotmail.com
'=========================================================
dim CartBag,SendSplit,SumAmount,SendMsg,rs2,sendfee
dim itemsplit,itemcount,rsvisual,curtype,CurPrice,CurDate
response.buffer=true
if not Founduser then
		Errmsg=Errmsg+"<br>"+"<li>您还没有<a href=login.asp>登陆</a>，不能使用个人形象设计功能。如果您还没有<a href=reg.asp>注册</a>，请先<a href=reg.asp>注册</a>！"
	Founderr=true
end if
stats="我的购物袋"
call nav()
if founderr then
	call head_var("","")
	call Mslove_error()
else
	call head_var("购物袋","Visual_cartbag.asp")
	call Ctrl()
	call main()
if founderr then call Mslove_error()
end if
call activeonline()
call footer()

sub Ctrl()
CartBag=request.cookies("mybuy_"&userid)
if isnull(CartBag) then CartBag=""
if CartBag="" then
	itemcount=0
else
	itemsplit=split(CartBag,"|")
	itemcount=ubound(itemsplit)+1
end if

if request.form("cmdclear")="清空" then
	response.cookies("mybuy_"&userid)=""
	response.write "<script>"
	response.write "window.close();"
	response.write "</script>"
	response.end
end if
if request.form("cmddelete")="删除" then
	if itemcount>0 then
		if not isnull(request("seqno")) then
			if isnumeric(request("seqno")) then
				if cint(request("seqno"))<itemcount then
					CartBag=""
					for i=0 to itemcount-1
						if i<>cint(request("seqno")) then
							if CartBag<>"" then CartBag=CartBag&"|"
							CartBag=CartBag&itemsplit(i)
						end if
					next
					response.cookies("mybuy_"&userid)=CartBag
					response.redirect Request.ServerVariables("HTTP_REFERER")
				end if
			end if
		end if
	end if
end if
if request.form("cmdclear")="结算" then
	set rsvisual=server.createobject("ADODB.Recordset")
	for i=0 to itemcount-1
		SendSplit=split(itemsplit(i),"$")
		sql="select top 1 * from visual_items where id="&SendSplit(0)
		rsvisual.open sql,conn,1,1
		sendfee=int(rsvisual("price1")*conn.execute("select top 1 send from visual_config")(0)/100+0.99)
		if v_myvip<=1 then
			SumAmount=SumAmount+rsvisual("price1")
		else
			SumAmount=SumAmount+rsvisual("price2")
		end if
		if ubound(SendSplit)=2 then
			SumAmount=SumAmount+SendFee
		end if
		rsvisual.close
	next
	if clng(mymoney)<cint(SumAmount) then
		Errmsg=Errmsg+"<br>"+"<li>购买的商品共计 "&SumAmount&" 元，您的现金 "&mymoney&" 元不够买这些商品。"
		Founderr=true
		exit sub
	else
		for i=0 to itemcount-1
			SendSplit=split(itemsplit(i),"$")
			sql="select top 1 * from visual_items where id="&SendSplit(0)
			rsvisual.open sql,conn,1,1
			sendfee=int(rsvisual("price1")*conn.execute("select top 1 send from visual_config")(0)/100+0.99)
			if v_myvip<=1 then
					CurPrice=rsvisual("price1")
			else
					CurPrice=rsvisual("price2")
			end if
			curtype=rsvisual("type") mod 100
			if curtype>=5 then
				curtype=4
			end if
			CurDate=year(now())&"-"&month(now())&"-"&day(now())
			conn.execute("update visual_items set quantity=quantity-1,totalsales=totalsales+1 where id="&SendSplit(0))
			if ubound(SendSplit)<2 then
				conn.execute("insert into visual_myitems (ItemID,UserName,FromUser,[Type],AddDate,FixDate,Period,Price) values ("&SendSplit(0)&",'"&MemberName&"','"&MemberName&"',"&curtype&",'"&curdate&"','"&curdate&"',"&rsvisual("period")&","&curprice&")")
				conn.execute("insert into visual_events (ItemID,UserName,FromUser,DateAndTime,Price,Type) values ("&sendsplit(0)&",'"&MemberName&"','#形象商店#','"&curdate&"',"&curprice&",0)")
			else
				conn.execute("insert into visual_myitems (ItemID,UserName,FromUser,[Type],AddDate,FixDate,Period,Price) values ("&SendSplit(0)&",'"&SendSplit(1)&"','"&MemberName&"',"&curtype&",'"&curdate&"','"&curdate&"',"&rsvisual("period")&","&curprice&")")
				conn.execute("insert into visual_events (ItemID,UserName,FromUser,DateAndTime,Price,Type) values ("&sendsplit(0)&",'"&SendSplit(1)&"','"&MemberName&"','"&curdate&"',"&curprice&",1)")
				conn.execute("insert into Ms_message (incept,sender,title,content,sendtime,flag,issend) values ('"&SendSplit(1)&"','"&trim(membername)&"','送您一件礼物，《"&rsvisual("name")&"》！','"&SendSplit(2)&chr(10)&chr(10)&"商品已经放到您的储物柜中，请笑纳！"&chr(10)&"请到以下地址查看储物柜。"&chr(10)&"[align=center][b][URL=Visual.asp?shopid=100]查看储物柜[/URL][/b][/align]',Now(),0,1)")
			end if
			if ubound(SendSplit)=2 then
				CurPrice=CurPrice+SendFee
			end if
			conn.execute("update [Ms_user] set userwealth=userwealth-"&CurPrice&" where username='"&MemberName&"'")
			rsvisual.close
		next
		response.cookies("mybuy_"&userid)=""
		sucmsg=sucmsg+"<br>"+"<li>您购买的商品已经放入您的储物柜中，赠送的商品已经发送到指定人员的储物柜。"
		call Mslove_suc()
		response.write "<script>"
		response.write "window.opener.document.URL='Visual_save.asp';"
		'response.write "window.opener.document.execCommand('Refresh');"
		response.write "</script>"
		response.end
	end if
	set rsvisual=nothing
end if
end sub

sub main()
SumAmount=0%>
<table cellpadding=3 cellspacing=1 border=0 align=center class=tableBorder1 width=97%>
  <tr height=25> 
    <th colspan=5><font style='font-size:12px'><%=MemberName%> ( <%=mymoney%> 元 )</font>：形象商品--购物袋</th>
  </tr>
  <tr height=20 valign=middle> 
    <td align=center class=tablebody2><b>商品名称</b></td>
    <td align=center class=tablebody2><b>享受单价</b></td>
    <td align=center class=tablebody2><b>受赠方</b></td>
    <td height="28" colspan="2" align=center class=tablebody2><b>操作</b></td>
  </tr>
  <form action=? method=post name=form1>
    <input type=hidden name=seqno value="">
    <%if itemcount=0 then%>
    <tr height=70 valign=middle> 
      <td colspan=5 align=center class=tablebody1>没有购买任何商品！</td>
    </tr>
    <%else
			set rsvisual=server.createobject("ADODB.Recordset")
			for i=0 to itemcount-1
				SendSplit=split(itemsplit(i),"$")
				sql="select top 1 * from visual_items where id="&SendSplit(0)
				rsvisual.open sql,conn,1,1
				sendfee=int(rsvisual("price1")*conn.execute("select top 1 send from visual_config")(0)/100+0.99)%>
    <tr height=20 valign=middle itemno="<%=SendSplit(0)%>"> 
      <td align=left class=tablebody1 onMouseOver=moveoverobject(this.parentElement,'TableBody2') onMouseOut=moveoutobject(this.parentElement,'TableBody1')>&nbsp; 
        <%
        		response.write rsvisual("name")
          	response.write "("
          	if rsvisual("sex")=1 then
          		response.write "男"
          	elseif rsvisual("sex")=0 then
          		response.write "女"
          	else
          		response.write "不限"
	          end if
	          response.write ")"
					%> </td>
      <td align=right class=tablebody1 onMouseOver=moveoverobject(this.parentElement,'TableBody2') onMouseOut=moveoutobject(this.parentElement,'TableBody1')> 
        <%
						if v_myvip<>1 then
          		if rsvisual("price1")<=0 then
          			response.write "<font style='font-size:12px'>免费</font>"
          		else
          			response.write rsvisual("price1")&" 元"
          		end if
          		SumAmount=SumAmount+rsvisual("price1")
          	else
          		if rsvisual("price2")<=0 then
          			response.write "<font style='font-size:12px'>免费</font>"
          		else
          			response.write rsvisual("price2")&" 元"
          		end if
          		SumAmount=SumAmount+rsvisual("price2")
          	end if
				  	if ubound(SendSplit)=2 then
				  		response.write " <font style='font-size:12px'> + "&SendFee&" 元</font>"
				  		SumAmount=SumAmount+SendFee
				  	end if
					%> &nbsp;</td>
      <td align=center class=tablebody1 onMouseOver=moveoverobject(this.parentElement,'TableBody2') onMouseOut=moveoutobject(this.parentElement,'TableBody1')> 
        <%
						if ubound(SendSplit)=2 then
							response.write "<a href=Visual_send.asp?itemid="&SendSplit(0)&"&username="&SendSplit(1)&"><font color=blue>"&SendSplit(1)&"</font></a>"
						else
							response.write "自用"
						end if
					%> </td>
      <td align=center class=tablebody1 onMouseOver=moveoverobject(this.parentElement,'TableBody2') onMouseOut=moveoutobject(this.parentElement,'TableBody1')><input type="submit" name="cmddelete" value="删除" onClick="if(confirm('您确定删除这个商品吗?')){this.document.form1.seqno.value='<%=i%>';this.document.form1.submit();return true;}return false;"></td>
    </tr>
    <%rsvisual.close
			next
			set rsvisual=nothing
		end if%>
    <tr height=20 valign=middle> 
      <td class=tablebody2 align=center><b>合计</b></td>
      <td class=tablebody2 align=right><b><%=SumAmount%> 元</b>&nbsp;</td>
      <td colspan="3" align=center class=tablebody2> 
        <%
				if itemcount=0 then
					%> &nbsp; <%
				else
					%> <input type="submit" name="cmdclear" value="清空" onClick="if(confirm('您确定清空购物袋吗?')){this.document.form1.submit();return true;}return false;"> 
        <%
				end if
			%> <%
				if itemcount=0 then
					%> &nbsp; <%
				else
					%> <input type="submit" name="cmdclear" value="结算" onClick="if(confirm('您确定结算这些商品吗?')){this.document.form1.submit();return true;}return false;"> 
        <%
				end if
			%> <input type="button" name="cmdclose" value="关闭" onClick="window.close();">
      </td>
    </tr>
  </form>
</table>
<script>
		function moveoverobject(object,classname) {
			for(var i=0;i<object.children.length;i++) 
				object.children[i].className=classname;
			if(itempic.readyState=="complete") itempic.ShowThisIMG(object.itemno);
		}
		function moveoutobject(object,classname) {
			for(var i=0;i<object.children.length;i++) 
				object.children[i].className=classname;
			if(itempic.readyState=="complete") itempic.ShowThisIMG('');
		}
	</script>
<%
end sub
%>   
</body>
</html> 