<%
'##################################################################                                                                 
'★         web08.net - 威博购物系统                                              
'★  版权所有: web08.net                                                                                                       
'★  程序制作: 威博网络技术公司                                     
'★           email:web08net@hotmail.com                           
'★            Q Q :645095280,475980829
'★	       电话:021-55520018                                                                                                         
'★  相关网址: [产品介绍] http://www.021web.com.cn/gwxt.html
'★            [支持论坛] http://bbs.web08.net/                                                                                     
'★  主页地址: http://www.web08.net/  
'★		http://www.021web.com.cn/			                                                                 
'###################################################################
%>
<%
 function ischanagegift(vtype)
	select case  vtype
		case 0
			web_string=""
		case 1
			web_string="优惠券"
		case 2
			web_string="积分兑换"
		case 3
			web_string="优惠券/积分兑换"
	end select
	ischanagegift=web_string	
 end function
'###############################################
' 获取礼品名称
'###############################################
Function getgiftname(classid)
	if classid<>"" then
		classid=split(classid,",")
		for i=0 to ubound(classid)
			if (i+1) mod 6=0 then
				pnamestr="<br>"
			else
				pnamestr=""
			end if
			if IsSqlDataBase =1 then
        			p_namelist=p_namelist&"<font color='#ff0000'>&nbsp;&nbsp;"&getonevalue("Web_Gifts","G_name","id='"&classid(i)&"'")&"&nbsp;&nbsp;</font>,"&pnamestr
			else
				p_namelist=p_namelist&"<font color='#ff0000'>&nbsp;&nbsp;"&getonevalue("Web_Gifts","G_name","id="&classid(i)&"")&"&nbsp;&nbsp;</font>,"&pnamestr
			end if
			
		next
	End if
	getgiftname=p_namelist
end Function

Function web_getmultiname(tabname,fldname,classid)
 	p_namelist=""
	if classid<>"" then
		classid=split(classid,",")
		for i=0 to ubound(classid)
			if (i+1) mod 6=0 then
				pnamestr="<br>"
			else
				pnamestr=""
			end if
			p_namelist=p_namelist&"<font color='#ff0000'>&nbsp;&nbsp;"&getonevalue(tabname,fldname,"id="&trim(classid(i)))&"&nbsp;&nbsp;</font>,"&pnamestr
		next
	End if
	web_getmultiname=p_namelist
end Function
'###############################################
' 获取订单总信息
'###############################################
 function getorderycount(cartid)
	conndb
	totol_money=0
	sql="select * from web_cart where c_cartid='"&cartid&"' "
	
	set rs_cart=conn.execute(sql)

	if rs_cart.eof then	
		getorderycount=0
	else
		do while not rs_cart.eof
			totol_money=totol_money+rs_cart("C_preprice")*rs_cart("C_goodscount")
		rs_cart.movenext
	
		loop
		rs_cart.close
		getorderycount=totol_money
	end if
 end function 
'###############################################
' 获取订单商品总重量
'###############################################
 function getorderyweight(cartid)
	conndb
	totol_weight=0
	sql="select * from web_cart where c_cartid='"&cartid&"' "
	
	set rs_cart=conn.execute(sql)

	if rs_cart.eof then	
		getorderyweight=0
	else
		do while not rs_cart.eof
			totol_weight=totol_weight+rs_cart("C_weight")*rs_cart("C_goodscount")
		rs_cart.movenext
	
		loop
		rs_cart.close
		getorderyweight=totol_weight
	end if
 end function 
'###############################################
' 增加一条会员订阅信息
'###############################################
 function userOrderMail(web_user,web_mail)
  	IF web_mail<>"" then
 		conndb
		sql="insert into Web_UserMaillist(UML_Uid,UML_UMmail,UML_Time)values('"&web_user&"','"&web_mail&"','"&timeformat(now(),0)&"') "
		conn.execute(sql)
	end if 
 end function
'###############################################
' 会员登录重新改变购物车中的商品价格
'###############################################
Function ChangMemberPrice(Cartid,Userid)
	conndb
	set rs_cart=conn.execute("select * from web_cart where C_cartid='"&Cartid&"'")
	 if not rs_cart.eof then
		do while not rs_cart.eof
			w_where=" and c_sxid='"&rs_cart("c_sxid")&"'"
			usersocre=getonevalue("web_user","u_score","u_username='"&Userid&"'")
	 		MemberPrice=trim(getonevalue("web_product","P_MemberPrice","id="&rs_cart("C_goodsid")))
			SetMyPrice=trim(getonevalue("web_product","P_SetMyPrice","id="&rs_cart("C_goodsid")))
			varprice=trim(getonevalue("web_product","P_varPrice","id="&rs_cart("C_goodsid")))
			if varPrice<>"" or isnull(varPrice)=true then
				price2=web_get_zhprice_mem(MemberPrice,SetMyPrice,trim(rs_cart("c_sxid")),varprice)
				w_zhprice=true
			else
				w_zhprice=false
			end if
			if w_zhprice=false then
				if SetMyPrice="" or isnull(SetMyPrice)=true then
					price2=MemberPrice*web_Getclassdiscount(Userid)/100
				else
					price2=GetUserClassprice(usersocre,SetMyPrice)
				end if
			end if
 			sql="update web_cart set C_preprice='"&price2&"' where C_cartid='"&Cartid&"' and C_goodsid="&rs_cart("C_goodsid")&" "&w_where
			conn.execute(sql)
		rs_cart.movenext
		loop
		rs_cart.close
	end if
End Function
'###############################################
' 检测优惠券函数是否可用函数
'###############################################
function  checkBenefittime(bfnum)
		conndb
		tflag=false
		sql="select * from Web_Benefit where BG_CodeID='"&bfnum&"'"
		set bff_rs=conn.execute(sql)
		if not bff_rs.eof then
			if   bff_rs("BG_State")=1 and   DateDiff("d",bff_rs("BG_Strattime"),timeformat(now(),0))>=0  and  DateDiff("d",timeformat(now(),0),bff_rs("BG_EndTime"))>=0   then
				tflag=true
			else
				tflag=false
			end if
		end if
	bff_rs.close
	checkBenefittime=tflag
  end function


'###############################################
' 购物车中使用兑换优惠券
'###############################################
 Function  checkBenefitflag(bfid,userid,Cartid) '判断优惠券是否可用
	conndb
	web_bene_flag=false
	if Web_C_Checkexist("id","Web_BenefitHistory","where userid='"&userid&"' and bh_type=0 and bh_codeid='"&bfid&"'")=1 then
		IF checkBenefittime(bfid)=false  then
			web_bene_flag=false	
		else
			web_bene_flag=true
		end if	
	end if
	checkBenefitflag=web_bene_flag
 end function

'######################################################################
'订单显示商品自定义属性
'######################################################################
Function showpother(web_other)
 	web_str=web_str&"<table width=100% border=0 cellpadding=3 cellspacing=1  bgcolor=#f1f1f1>"
	web_str=web_str&"<tr bgcolor=#ffffff>"
	web_str=web_str&"<td align=center colspan=2 height=25><font color=#ff0000>其他信息</font></td>"
 	web_str=web_str&"</tr>"
		if trim(web_other)="" or isnull(web_other) then
			web_str=web_str&"<tr><td clospan=2 heith=25 align=center>没有其他信息</td></tr>"
		else
			tmpnv=split(web_other,"@@")
			for ii=0 to ubound(tmpnv)
				tmpvalue=split(tmpnv(ii),"|")
	         		web_str=web_str&"<tr bgcolor=#ffffff height=20>"
				web_str=web_str&"<td align=right width=40% > "& tmpvalue(0)&" </td>"
				web_str=web_str&"<td align=left width=60% > "&tmpvalue(1)&" </td>"
	  			web_str=web_str&" </tr>"
			next
	 	end if 
		web_str=web_str&"</table>"
		showpother=web_str
end function

sub delALLfile(Filetype,onlyid)
	onlyid=trim(onlyid)
	select case filetype
		case "product"
			Filepath=Web_Get_RootDir(Web_C_setupfolder)&"html/product/"&onlyid&".html"
		case "file"
			Filepath=Web_Get_RootDir(Web_C_setupfolder)&"html/as/article/"&onlyid&".html"
		case "active"
			Filepath=Web_Get_RootDir(Web_C_setupfolder)&"html/Active/"&onlyid&".html"
		case "gift"
			Filepath=Web_Get_RootDir(Web_C_setupfolder)&"html/gift/"&onlyid&".html"
		case "guide"
			Filepath=Web_Get_RootDir(Web_C_setupfolder)&"html/guide/"&onlyid&".html"
		case "help"
			Filepath=Web_Get_RootDir(Web_C_setupfolder)&"html/help/"&onlyid&".html"
		case "helpclass"
			Filepath=Web_Get_RootDir(Web_C_setupfolder)&"html/help/class"&onlyid&".html"
		case "benefit"
			Filepath=Web_Get_RootDir(Web_C_setupfolder)&"html/Benefit/"&onlyid&".html"
		case "ns"
			Filepath=Web_Get_RootDir(Web_C_setupfolder)&"html/NS/"&onlyid&".html"
		case "feel"
			Filepath=Web_Get_RootDir(Web_C_setupfolder)&"html/feel/"&onlyid&".html"
		case "subject"
			Filepath=Web_Get_RootDir(Web_C_setupfolder)&"html/sys/"&onlyid&""
		case "buysell"
			Filepath=Web_Get_RootDir(Web_C_setupfolder)&"html/GS/info/"&onlyid&".html"
 	end select

	Set Fso = CreateObject(C_Web_FSO)
	if filetype="subject" then
		If Fso.folderexists(Filepath) then
			Set MyFile = Fso.GetFolder(Filepath)
			MyFile.Delete true
			set MyFile=nothing
			If Err Then
				err.Clear
				Response.Write "文件不能被删除,手动删除"
				Response.End
			End If
			Set MyFile=Nothing
		End If
	else
		AllFile=server.mappath(Filepath)
		If (Fso.FileExists(AllFile))=true Then
			fso.DeleteFile(AllFile)
	 	End If
		
	End if
end sub

''###############
'删除品牌、文章、商品分类HTML页面函数
'###############
sub web_deletehtml_class(byval Filetype,byval onlyid)
	onlyid1=split(onlyid,",")
	select case filetype
		case "category"
			for w_i_i=0 to ubound(onlyid1)
				call web_deletefile_class(server.mappath(""&Web_Get_RootDir(Web_C_setupfolder)&"html/category/class_"&trim(onlyid1(w_i_i))),0)
			next
		case "brand"
			for w_i_i=0 to ubound(onlyid1)
				call web_deletefile_class(server.mappath(""&Web_Get_RootDir(Web_C_setupfolder)&"html/brand/"&trim(onlyid1(w_i_i))),0)
			next
		case "as"
			for w_i_i=0 to ubound(onlyid1)
				call web_deletefile_class(server.mappath(""&Web_Get_RootDir(Web_C_setupfolder)&"html/as/class/class_"&trim(onlyid1(w_i_i))),0)
			next
 	end select
end sub
Function web_deletefile_class(byval w_file,w_i)
	w_j=w_i	
	if w_j=0 then
		w_filename=w_file&".html"
	else
		w_filename=w_file&"_"&w_i&".html"
	end if

	Dim fso, MyFile
	Set fso = CreateObject("Scripting.FileSystemObject")
  	If (fso.FileExists(w_filename)) Then
		Set MyFile = fso.GetFile(w_filename)
		response.write w_filename&"<br>"
		MyFile.Delete 
  	Else
		exit function
  	End If
	if w_j=0 then
		w_j=2
	else
		w_j=w_j+1
	end if
	call web_deletefile_class(w_file,w_j)
End Function

'##################################
'#获取自定义代理商价格函数
'#Levelid等级编号 MyPrice 价格	
'##################################
  Function  Web_agent_SetMyPrice(Levelid,MyPrice)
 	if MyPrice<>"" or isnull(myprice)=false then 
	  V_MyPrice=split(MyPrice,"$$")
	   For i=0 to ubound(V_MyPrice)
			T_MyPrice=split(V_MyPrice(i),"@@")
		if clng(trim(T_MyPrice(0)))=Int(Levelid) then
		  	strPrice=strPrice&T_MyPrice(1)
		end if
	    next
	 else
 	  strPrice=""
	end if
	Web_agent_SetMyPrice=strPrice
  end function  
'##################################
'#物流费用计算
'#Levelid等级编号 MyPrice 价格	
'##################################
function getweigthfee(sendid,areaid,feeweight)
	if sendid<>0 and areaid<>0 and feeweight<>0 then
		conndb
		sql="select * from Web_AreaPrice where sendid="&sendid&" and areaid="&areaid&""
		set rs_fee=conn.execute(sql)

		if rs_fee.eof then
			getweigthfee=""
		else
			if feeweight<rs_fee("BasicWeight") then
				getweigthfee=rs_fee("BasicPrice")
			else
				if rs_fee("BasicWeight")<>0 then
					getweigthfee=rs_fee("BasicPrice")+(myint(feeweight/rs_fee("BasicWeight"))-1)*rs_fee("BeyondPrice")
				else		
					getweigthfee=""			
				end if
			end if	
		end if
		rs_fee.close
	else
		getweigthfee=""	
	end if
	
end function
function   MyInt(a)   
  if   a>int(a)   then  
	 MyInt=int(a)+1 
   else
	MyInt=a
  end if  
 end   function

'********************************************
'函数名：IsValidEmail
'作  用：检查Email地址合法性
'参  数：email ----要检查的Email地址
'返回值：True  ----Email地址合法
'       False ----Email地址不合法
'********************************************
function IsValidEmail(email)
	dim names, name, i, c
	IsValidEmail = true
	names = Split(email, "@")
	if UBound(names) <> 1 then
		IsValidEmail = false
		exit function
	end if
	for each name in names
		if Len(name) <= 0 then
			IsValidEmail = false
    			exit function
		end if
		for i = 1 to Len(name)
		    	c = Lcase(Mid(name, i, 1))
			if InStr("abcdefghijklmnopqrstuvwxyz_-.", c) <= 0 and not IsNumeric(c) then
				IsValidEmail = false
		       		exit function
		     	end if
	   	next
	   	if Left(name, 1) = "." or Right(name, 1) = "." then
    	  		IsValidEmail = false
	      		exit function
	   	end if
	next
	if InStr(names(1), ".") <= 0 then
		IsValidEmail = false
	   	exit function
	end if
	i = Len(names(1)) - InStrRev(names(1), ".")
	if i <> 2 and i <> 3 then
	   	IsValidEmail = false
	   	exit function
	end if
	if InStr(email, "..") > 0 then
	   	IsValidEmail = false
	end if
end function
Function web_showmorepic(morepic)
 	if  morepic="-1NISNUL" then
		morepicture=""
	else
		morepicture=morepic
 	end if
	'response.write replace(morepicture,"uploadimage/",""&Web_Get_RootDir(Web_C_setupfolder)&"uploadimage/")
	'web_Pic_string=web_Pic_string&"<LINK href='"&Web_Get_RootDir(Web_C_setupfolder)&"images/morepic/b.css' type=text/css rel=stylesheet>"
	web_string=web_string&"<TABLE width='46%' border=0 align='center' cellPadding=0 cellSpacing=0>"&vbcrlf
	web_string=web_string&"<TBODY>"&vbcrlf
	web_string=web_string&"<TR>"&vbcrlf
	web_string=web_string&"<TD width='56%' height='60' align=middle vAlign=center>"&vbcrlf
	web_string=web_string&"<DIV style='OVERFLOW: auto; WIDTH: 650px; HEIGHT: 350px'>"&vbcrlf
	web_string=web_string&"<IMG id='Image1' class='zoomcss'></DIV></TD></TR>"&vbcrlf
	web_string=web_string&" <TR>"&vbcrlf
	web_string=web_string&"<TD align='center' style='HEIGHT: 28px'>"&vbcrlf
	web_string=web_string&"<DIV style='WIDTH: 191px; HEIGHT: 17px'>"&vbcrlf
	web_string=web_string&"<DIV style='FLOAT: left; WIDTH: 17px; HEIGHT: 17px'>"&vbcrlf
	web_string=web_string&"<IMG src='"&Web_Get_RootDir(Web_C_setupfolder)&"images/morepic/zoom_out.gif' border=0></DIV>"&vbcrlf
	web_string=web_string&"<DIV id=processbarDiv style='FONT-SIZE: 0px; FLOAT: left; BACKGROUND-IMAGE: url("&Web_Get_RootDir(Web_C_setupfolder)&"images/morepic/bg.gif); OVERFLOW: hidden; WIDTH: 157px; BACKGROUND-REPEAT: no-repeat; HEIGHT: 17px; TEXT-ALIGN: left'>"&vbcrlf
	web_string=web_string&"<IMG title=缩小|放大 style='LEFT: 70px; CURSOR: pointer; POSITION: relative; TOP: 0px' src='"&Web_Get_RootDir(Web_C_setupfolder)&"images/morepic/fetch.gif'></DIV>"&vbcrlf
	web_string=web_string&"<DIV style='FLOAT: left; WIDTH: 17px; HEIGHT: 17px'>"&vbcrlf
	web_string=web_string&"<IMG src='"&Web_Get_RootDir(Web_C_setupfolder)&"images/morepic/zoom_in.gif' border=0>"&vbcrlf
	web_string=web_string&"</DIV></DIV>"&vbcrlf
	web_string=web_string&"<script src='"&Web_Get_RootDir(Web_C_setupfolder)&"js/Web_MorePic.js' language='javascript'></script></TD>"&vbcrlf
	web_string=web_string&"</TR>"&vbcrlf
	web_string=web_string&"<TR>"&vbcrlf
	web_string=web_string&"<TD align='center' style='HEIGHT: 28px'><BR>"&vbcrlf
	web_string=web_string&"<TABLE id=DataList1 style='WIDTH: 100%; BORDER-COLLAPSE: collapse;display:none'  cellSpacing=0 border=0 >"&vbcrlf
	web_string=web_string&"<TBODY>"&vbcrlf
	web_string=web_string&"<TR>"&vbcrlf
	web_string=web_string&"<TD><IMG id=imgs style=""CURSOR: hand"" onclick=""colorchanged('"&replace(morepicture,"uploadimage/",""&Web_Get_RootDir(Web_C_setupfolder)&"uploadimage/")&"');"" height=20 src="""" width=""20"" border=""1""  bordercolor=""gray""> </TD>"&vbcrlf
	web_string=web_string&"</TR></TBODY></TABLE>"&vbcrlf
                    
        if morepicture<>""  then
		picaddr=split(morepicture,"|")
		piclen=ubound(picaddr)
		if piclen>=100 then
			piclen=100
		end if
		for ii=0 to piclen
                 	tmpstr1=tmpstr1&"<img  onmouseover=indexChanged("&ii&"); style=""cursor:hand"" src="&Web_Get_RootDir(Web_C_setupfolder)&picaddr(ii)&" width='50' height='50' border='0' alt='点击查看效果'>"&"&nbsp;&nbsp;"
			if (ii+1) mod 8=0 then
				tmpstr1=tmpstr1&"<br>"
			end if
		next
	end if
	web_string=web_string&tmpstr1&"</TD></TR>"&vbcrlf
	'web_string=web_string&"<TR><TD class=h vAlign=center align=center height=30>[<a onclick='window.close()' style='cursor:hand'>关闭窗口</a>]</TD></TR>"&vbcrlf
	web_string=web_string&"</TBODY></TABLE>"&vbcrlf
	web_showmorepic=web_string
End Function
'###########################
'+ 常用字符过滤
'#############################
 Function Nocommchar(web_inputStr)
	Str_InputStr=web_inputStr
	w_NoSqlHack_AllStr="*|' | |~| |(|)|!"
	w_NoSqlHack_Str = Split(w_NoSqlHack_AllStr,"|")

	For w_NoSqlHack_i=LBound(w_NoSqlHack_Str) To Ubound(w_NoSqlHack_Str)
		If Instr(LCase(Str_InputStr),f_NoSqlHack_Str(w_NoSqlHack_i))<>0 Then
			If w_NoSqlHack_Str(f_NoSqlHack_i)="'" Then w_NoSqlHack_Str(f_NoSqlHack_i)=" \' "
			Response.Write "<html><title>警告</title><body bgcolor=""EEEEEE"" leftmargin=""60"" topmargin=""30""><font style=""font-size:16px;font-weight:bolder;color:blue;""><li>您提交的数据有恶意字符</li></font><font style=""font-size:14px;font-weight:bolder;color:red;""><br><li>您的数据已经被记录!</li><br><li>您的IP："&Request.ServerVariables("Remote_Addr")&"</li><br><li>操作日期："&Now&"</li></font></body></html><!--Powered by Foosun Inc.,AddTime:"&now&"-->"
			Response.End
		End if
	Next
	Nocommchar = Replace(Str_InputStr,"'","''")
End Function

'############################
'获取无限级地区类别
'############################
Function Web_GetCityValue(w_city1,w_city2,w_require)
	S_Pro1=w_city1
	S_Pro2=w_city2
	'response.write s_pro1 & "  " & s_pro2
	'response.end
	if s_pro1=0 then
		if w_require=1 then
			call Web_C_ReMessage("请选择地区！",3,"")
		end if
	end if
	if s_pro1<>0 and cstr(s_pro2)="0" then
		if w_require=1 then
			call Web_C_ReMessage("请选择地区！",3,"")
		end if
	end if
	if s_pro2>0 then
		Web_GetCityValue=s_pro2
	else
		Web_GetCityValue=s_pro1
	end if

End Function 
%>