<!-- #INCLUDE FILE="bkitadovbs.inc" -->
<!-- #INCLUDE FILE="bkitutillib.asp" -->

<!-- #include file="bkitonline.asp" -->

<%
' If user has requested to change login then clear any ref present
if trim(request("B1")) = "Change Login" then
	ref = ""
else
	' If member ref not already present then call login
	' page and stop rest of this page
	ref 		= trim(request("ref"))
	password 	= trim(request("password"))
end if 

'If not established who is or wish to change login then call login page
if ref = "" then
%>
	<!-- #include file="bkitlogin.asp" -->
<%
response.end
end if
%>


<%
eventno = TRIM( Request( "eventno" ) )

' Open Database Connection
Set Con = Server.CreateObject( "ADODB.Connection" )
%>

<!-- #INCLUDE FILE="connection.inc" -->

<%
Set memberrs = Server.CreateObject( "ADODB.Recordset" )
memberrs.ActiveConnection = Con

Set cartrs = Server.CreateObject( "ADODB.Recordset" )
cartrs.ActiveConnection = Con
sqlstring = _
"select 		count(*) as isame " &_
"from 			bkitcart "&_
"where			bkitcart.eventno = '" & eventno & "' and " &_
"				bkitcart.ref		= '" & ref & "'"
cartrs.open sqlstring
isame = clng(cartrs("isame"))
' need to close as gets opened again with new string in showcart
cartrs.close

Set defaultsrs = Server.CreateObject( "ADODB.Recordset" )
defaultsrs.ActiveConnection = Con
sqlstring = "select * from bkitdefaults"
defaultsrs.open sqlstring

' Only add if Add To Cart button pushed, otherwise just show cart
if trim(request("B1")) = "Add To Basket" then

	slots1 = TRIM( Request( "slots1" ) )
	slots2 = TRIM( Request( "slots2" ) )
	slots3 = TRIM( Request( "slots3" ) )
	slots4 = TRIM( Request( "slots4" ) )
	if slots1 = "" then slots1 = 0
	if slots2 = "" then slots2 = 0
	if slots3 = "" then slots3 = 0
	if slots4 = "" then slots4 = 0
	cpaytype = TRIM( Request( "cpaytype" ) )
	transport = TRIM( Request( "transport" ) )
	notes = trim(request( "notes" ) )

	feeamt1 = TRIM( Request( "feeamt1" ) )
	feeamt2 = TRIM( Request( "feeamt2" ) )
	feeamt3 = TRIM( Request( "feeamt3" ) )
	feeamt4 = TRIM( Request( "feeamt4" ) )
	depamt1 = TRIM( Request( "depamt1" ) )
	depamt2 = TRIM( Request( "depamt2" ) )
	depamt3 = TRIM( Request( "depamt3" ) )
	depamt4 = TRIM( Request( "depamt4" ) )
	
	'validation
	if isame > 0 then errorform "You already have this event in your shopping basket. Please delete it from your basket first if you wish to change the details", "bkitbookevent.asp?eventno=" & eventno
	if not isnumeric(slots1) or clng(slots1) < 0 then errorform "Invalid number of slots entered", "bkitbookevent.asp?eventno=" & eventno
	if not isnumeric(slots2) or clng(slots2) < 0 then errorform "Invalid number of slots entered", "bkitbookevent.asp?eventno=" & eventno
	if not isnumeric(slots3) or clng(slots3) < 0 then errorform "Invalid number of slots entered", "bkitbookevent.asp?eventno=" & eventno
	if not isnumeric(slots4) or clng(slots4) < 0 then errorform "Invalid number of slots entered", "bkitbookevent.asp?eventno=" & eventno
	totslots = clng(slots1)+clng(slots2)+clng(slots3)+clng(slots4)
	if totslots = 0 then errorform "You must book at least one slot", "bkitbookevent.asp?eventno=" & eventno
	if totslots > clng(defaultsrs("imaxwslots")) then errorform "You are not allowed to book this many slots on the web. Please call the office instead.", "bkitbookevent.asp?eventno=" & eventno

	sqlString = _
	"insert into bkitcart (" &_
		"ref, eventno, slots1, slots2, slots3, slots4, cpaytype, transport, " &_
		"amtdue1, amtdue2, amtdue3, amtdue4, depdue1, depdue2, " &_
		"depdue3, depdue4, notes ) " &_
	"values (" &_
		"'" & ref & "','" & eventno & "'," & slots1 & "," & slots2 & "," &_
		slots3 & "," & slots4 & ",'" & cpaytype & "','" & transport &_
		"', " & feeamt1 & "," & feeamt2 & "," & feeamt3 & "," &_
		feeamt4 & "," & depamt1 & "," & depamt2 & "," & depamt3 & "," &_
		depamt4 & ",'" & notes & "')"
	cartrs.Open sqlString
	
elseif trim(request("B1")) = "Delete" then

	sqlString = _
	"delete 	from bkitcart " &_
	"where 	ref = '" & ref & "' and eventno = '" & eventno & "'"
	cartrs.Open sqlString

end if
%>

<!-- #INCLUDE FILE="bkitshowcart.asp" -->

<% Con.Close %>