% PageSecure = False %>
<%
iPID = GetVariable("ID1", -1, "int")
iQty = GetVariable("Qty", 1, "int")
sUser = GetVariable("Username", "", "string")
sPassword = GetVariable("Password", "", "string")
if Session("FinalPage") <> 1 then Session("FinalPage") = 0
dim arr(100,2)
if Action = "emptycart" then
session.abandon()
response.redirect("cart.asp")
elseif Action = "updatecart" then
'Remove any checked items
if len(request.form("Remove")) > 0 then
if instr(request.form("Remove"),", ") > 0 then
arrTmp = split(request.form("Remove"),", ")
for i=0 to ubound(arrTmp)
arrTmp1 = split(arrTmp(i),"*~*")
call deleteItem(arrTmp1(0),arrTmp1(1),arrTmp1(2))
next
elseif instr(request.form("Remove"),"*~*") then
arrTmp1 = split(request.form("Remove"),"*~*")
call deleteItem(arrTmp1(0),arrTmp1(1),arrTmp1(2))
end if
else
' Build array to display items in cart into a table
iWeight = 0
iPrice = 0
sItems = session("Items")
if len(sItems) > 0 then
if instr(sItems,"*|*") then
c = split(sItems,"*|*")
for i=0 to ubound(c)
tmpVal = 0
d = split(c(i),"*~*")
tmpVal2 = d(0) 'quantity
tmpVal1 = d(1) 'product id
tmpVal3 = d(2) 'item details
'Get new quantity
execute "tmpVal = request.form(""Qty_" & i & """)"
'Get item detail strings if avail
execute "sTmp1 = request.form(""ItemDetails1_" & i & """)"
execute "sTmp2 = request.form(""ItemDetails2_" & i & """)"
execute "sTmp3 = request.form(""ItemDetails3_" & i & """)"
execute "sTmp4 = request.form(""ItemDetails4_" & i & """)"
if len(tmpVal) > 0 then
arr(i,0) = tmpVal
else
arr(i,0) = tmpVal2
end if
sTmp = ""
if len(sTmp1) > 0 then
sTmp = "Item Detail 1: " & sTmp1 & ";"
end if
if len(sTmp2) > 0 then
sTmp = sTmp & " Item Detail 2: " & sTmp2 & ";"
end if
if len(sTmp3) > 0 then
sTmp = sTmp & " Item Detail 3: " & sTmp3 & ";"
end if
if len(sTmp4) > 0 then
sTmp = sTmp & " Item Detail 4: " & sTmp4 & ";"
end if
sItems = replace(sItems, tmpVal2 & "*~*" & tmpVal1 & "*~*" & tmpVal3, arr(i,0) & "*~*" & tmpVal1 & "*~*" & sTmp)
arr(i,1) = tmpVal1
session("Items") = replace(session("Items"), tmpVal2 & "*~*" & tmpVal1 & "*~*" & tmpVal3, arr(i,0) & "*~*" & tmpVal1 & "*~*" & sTmp)
next
elseif instr(sItems,"*~*") then
tmpVal = 0
d = split(sItems,"*~*")
tmpVal2 = d(0) 'quantity
tmpVal1 = d(1) 'product id
tmpVal3 = d(2) 'item details
'Get new quantity
execute "tmpVal = request.form(""Qty_0"")"
'Get item detail strings if avail
execute "sTmp1 = request.form(""ItemDetails1_0"")"
execute "sTmp2 = request.form(""ItemDetails2_0"")"
execute "sTmp3 = request.form(""ItemDetails3_0"")"
execute "sTmp4 = request.form(""ItemDetails4_0"")"
if len(tmpVal) > 0 then
arr(0,0) = tmpVal
else
arr(0,0) = tmpVal2
end if
sTmp = ""
if len(sTmp1) > 0 then
sTmp = "Item Detail 1: " & sTmp1 & ";"
end if
if len(sTmp2) > 0 then
sTmp = sTmp & " Item Detail 2: " & sTmp2 & ";"
end if
if len(sTmp3) > 0 then
sTmp = sTmp & " Item Detail 3: " & sTmp3 & ";"
end if
if len(sTmp4) > 0 then
sTmp = sTmp & " Item Detail 4: " & sTmp4 & ";"
end if
sItems = replace(sItems, tmpVal2 & "*~*" & tmpVal1 & "*~*" & tmpVal3, arr(0,0) & "*~*" & tmpVal1 & "*~*" & sTmp)
arr(0,1) = tmpVal1
session("Items") = replace(session("Items"), tmpVal2 & "*~*" & tmpVal1 & "*~*" & tmpVal3, arr(0,0) & "*~*" & tmpVal1 & "*~*" & sTmp)
end if
end if
end if
Action = ""
elseif Action = "login" then
s = "SELECT Email,UserID,Password,UID,UserType FROM Cart_Users WHERE UserID = '" & sUser & "';"
SET r = CreateRS(s)
if isnull(r) or r.eof then
sMessage = "Username not found."
else
if sPassword = decrypt(r("Password"),key) then
Session("LoggedIn") = 1
Session("UserLevel") = r("UserType")
Session("UID") = r("UID")
Response.Redirect("billing_shipping.asp")
else
sMessage = "Login failed, try again."
end if
end if
end if
if Action = "viewcart" or Action = "" then
Action = "viewcart"
end if
if len(Session("OID")) > 0 and Session("OID") <> -1 then
sNow = now()
iOID = Session("OID")
' Build item list
sItems = session("Items")
if len(sItems) > 0 then
if instr(sItems,"*|*") then
c = split(sItems,"*|*")
for i=0 to ubound(c)
d = split(c(i),"*~*")
arr(i,0) = d(0)
arr(i,1) = d(1)
arr(i,2) = d(2)
next
elseif instr(sItems,"*~*") then
d = split(sItems,"*~*")
arr(i,0) = d(0)
arr(i,1) = d(1)
arr(i,2) = d(2)
end if
end if
' Put item list into string
if iOID <> -1 then
s = "DELETE FROM Cart_Orders_Items WHERE OID = " & Session("OID")
ExecuteSQL(s)
end if
for i=0 to ubound(arr)
if len(arr(i,0)) > 0 then
iMultiType = getValue("MultiType","Cart_Products","PID",arr(i,1))
iCIDTmp = getValue("CID","Cart_Catagories_Index","PID",arr(i,1))
dBasePriceTmp = getValue("BasePrice","Cart_Products","PID",arr(i,1))
dBasePrice = dBasePriceTmp
dMultiPriceTmp = getValue("MultiPrice","Cart_Products","PID",arr(i,1))
dWeight = dWeight + (getValue("ProductWeight","Cart_Products","PID",arr(i,1)) * arr(i,0))
if cint(iMultiType) = 0 then 'multiple in catagory,limit 2
if dMultiPriceTmp > 0 and dMultiPriceTmp <> "" then
for z=0 to ubound(arr)
if len(arr(z,1)) > 0 then
iTmp = getValue("CID","Cart_Catagories_Index","PID",arr(z,1))
if ((arr(z,1) <> arr(i,1)) and (iTmp = iCIDTmp) and (instr(sDiscApplied,"|" & arr(z,1) & "|") = 0) and (iDiscApplied < 2)) then
sDiscApplied = sDiscApplied & "|" & trim(arr(z,1)) & "|"
iDiscApplied = iDiscApplied + 1
dBasePrice = dMultiPriceTmp
if iDiscApplied = 2 then iDiscApplied = 0
exit for
elseif (arr(z,1) = arr(i,1)) and (arr(z,0) > 1) then
sDiscApplied = sDiscApplied & "|" & trim(arr(z,1)) & "|"
iDiscApplied = iDiscApplied + 1
dBasePrice = dMultiPriceTmp
if iDiscApplied = 2 then iDiscApplied = 0
exit for
end if
end if
next
end if
elseif cint(iMultiType) = 1 then 'multiple of same product in cart
if dMultiPriceTmp > 0 and dMultiPriceTmp <> "" then
if arr(i,0) >= 2 then
dBasePriceTmp = dMultiPriceTmp
end if
end if
end if
dSubTotalTmp = 0
if arr(i,0) > 1 then
if cint(iMultiType) = 0 then
dSubTotalTmp = dSubTotalTmp + (dBasePrice * (arr(i,0)))
elseif cint(iMultiType) = 1 then
dSubTotalTmp = dSubTotalTmp + (dBasePrice)
dSubTotalTmp = dSubTotalTmp + (dBasePriceTmp * (arr(i,0)-1))
end if
else
dSubTotalTmp = dSubTotalTmp + (dBasePrice)
end if
if iOID <> -1 then
s = "INSERT INTO Cart_Orders_Items (OID,PID,Qty,Price,ItemDetail,Status,Created,Modified)" & _
" VALUES (" & iOID & "," & arr(i,1) & "," & arr(i,0) & "," & dSubTotalTmp & "," & _
"'" & arr(i,2) & "',2,#" & sNow & "#,#" & sNow & "#);"
ExecuteSQL(s)
end if
end if
next
end if
sub deleteItem(a,b,c)
if b <> -1 then
session("Items") = replace(session("Items"), a & "*~*" & b & "*~*" & c, "")
if len(session("Items")) > 0 and instr(session("Items"),"*|*") > 0 then
if left(Session("Items"),3) = "*|*" then Session("Items") = right(Session("Items"),len(Session("Items")) -3)
if right(Session("Items"),3) = "*|*" then Session("Items") = left(Session("Items"),len(Session("Items")) -3)
Session("Items") = replace(Session("Items"),"*|**|*","*|*")
end if
end if
end sub
Function checkItem(iTmp3)
iDetails1 = getValue("ItemDetails1","Cart_Products","PID",iTmp3)
iDetails2 = getValue("ItemDetails2","Cart_Products","PID",iTmp3)
iDetails3 = getValue("ItemDetails3","Cart_Products","PID",iTmp3)
iDetails4 = getValue("ItemDetails4","Cart_Products","PID",iTmp3)
if iDetails1 = "" or isnull(iDetails1) then iDetails1 = 0
if iDetails2 = "" or isnull(iDetails2) then iDetails2 = 0
if iDetails3 = "" or isnull(iDetails3) then iDetails3 = 0
if iDetails4 = "" or isnull(iDetails4) then iDetails4 = 0
checkItem = cint(iDetails1) + cint(iDetails2) + cint(iDetails3) + cint(iDetails4)
End Function
function getValue(f,t,q,id)
if len(id) > 0 and len(f) > 0 and len(t) > 0 and len(q) > 0 then
sSQL = "SELECT " & f & " FROM " & t & " WHERE " & q & " = " & id & ";"
set rs = CreateRS(sSQL)
if isnull(rs) or rs.eof then
getValue = ""
else
getValue = rs(0)
end if
rs.close
set rs = nothing
end if
end function
%>