<SCRIPT LANGUAGE=VBScript RUNAT=Server>
Sub Application_OnStart
	'==FrontPage Generated - startspan==
	Dim FrontPage_UrlVars(1)
	'--Project Data Connection
		Application("estore101_ConnectionString") = "DSN=estore101;DRIVER={Microsoft Access Driver (*.mdb)}"
		Application("estore101_ConnectionTimeout") = 15
		Application("estore101_CommandTimeout") = 30
		Application("estore101_CursorLocation") = 3
		Application("estore101_RuntimeUserName") = ""
		Application("estore101_RuntimePassword") = ""
	'--
	Application("FrontPage_UrlVars") = FrontPage_UrlVars
	'==FrontPage Generated - endspan==
End Sub
Sub FrontPage_StartSession
	On Error Resume Next
	if Len(Application("FrontPage_VRoot")) > 0 then Exit Sub
	' discover the VRoot for the current page;
	' walk back up VPath until we find global.asa
	Vroot = Request.ServerVariables("PATH_INFO")
	strG1 = "global.asa"
	strG2 = "Global.asa"
	iCount = 0
	do while Len(Vroot) > 1
		idx = InStrRev(Vroot, "/")
		if idx > 0 then
			Vroot = Left(Vroot,idx)
		else
			' error; assume root web
			Vroot = "/"
		end if
		if FrontPage_FileExists(Server.MapPath(Vroot & strG1)) then exit do
		if FrontPage_FileExists(Server.MapPath(Vroot & strG2)) then exit do
		if Right(Vroot,1) = "/" then Vroot = Left(Vroot,Len(Vroot)-1)
		iCount = iCount + 1
		if iCount > 100 then
			' error; assume root web
			Vroot = "/"
			exit do
		end if
	loop
	' map all URL= attributes in _ConnectionString variables
	Application.Lock
	if Len(Application("FrontPage_VRoot")) = 0 then
		Application("FrontPage_VRoot") = Vroot
		UrlVarArray = Application("FrontPage_UrlVars")
		for i = 0 to UBound(UrlVarArray)
			if Len(UrlVarArray(i)) > 0 then FrontPage_MapUrl(UrlVarArray(i))
		next
	end if
	Application.Unlock
End Sub
Function FrontPage_FileExists(fspath)
	On Error Resume Next
	FrontPage_FileExists = False
	set fs = CreateObject("Scripting.FileSystemObject")
	Err.Clear
	set istream = fs.OpenTextFile(fspath)
	if Err.Number = 0 then
		FrontPage_FileExists = True
		istream.Close
	end if
	set istream = Nothing
	set fs = Nothing
End Function
Sub FrontPage_MapUrl(AppVarName)
	' convert URL attribute in conn string to absolute file location
	strVal = Application(AppVarName)
	strKey = "URL="
	idxStart = InStr(strVal, strKey)
	If idxStart = 0 Then Exit Sub
	strBefore = Left(strVal, idxStart - 1)
	idxStart = idxStart + Len(strKey)
	idxEnd = InStr(idxStart, strVal, ";")
	If idxEnd = 0 Then
		strAfter = ""
		strURL = Mid(strVal, idxStart)
	Else
		strAfter = ";" & Mid(strVal, idxEnd + 1)
		strURL = Mid(strVal, idxStart, idxEnd - idxStart)
	End If
	strOut = strBefore & Server.MapPath(Application("FrontPage_VRoot") & strURL) & strAfter
	Application(AppVarName) = strOut
End Sub


	TM = Time()
	HR = Hour(TM)
	MN = Minute(TM)
	SC = Second(TM)
	OrderTime = HR&":"&MN&":"&SC
	SpMarker = " "
	Function MakeUSDate(orderdate)
		If Not IsDate(orderdate) Then Exit Function
		MakeUSDate = Month(orderdate)&"/"&Day(orderdate)&"/"&Right(Year(orderdate),2)&SpMarker&OrderTime
	End Function

Sub Session_OnStart
	FrontPage_StartSession '==FrontPage Generated==
	
	Set Connection = Server.CreateObject("ADODB.Connection")
	dim appDict, i 						' Requires FP 2000 Extensions
	set appDict = Server.CreateObject("Scripting.Dictionary") ' Requires FP 2000 										'Extensions

	i = 0 							' Requires FP 2000 Extensions
	For each element in Application.Contents		' Requires FP 2000 Extensions
	appDict.Item(i) = element				' Requires FP 2000 Extensions
	i = i + 1						' Requires FP 2000 Extensions
	next							' Requires FP 2000 Extensions

	Session("DSN_Name") = Application(appDict.Item(0)) 	' Requires FP 2000 Extensions
	'Session("DSN_Name") = "Your DSN Name Here" 		' Use for FP 98 Extensions
	
	DSN_Name = Session("DSN_Name")
	
	Connection.Open DSN_Name
	
	KEY = Now()	
	OrderDate = MakeUSDate(KEY)
	RevDate = DateAdd("d", -1, Now())
	DelDate = MakeUSDate(RevDate)
	REMOTE_ADDRESS = Request.ServerVariables("REMOTE_ADDR")

	SQL = "INSERT INTO customer(ID, ORDER_DATE, REMOTE_ADDRESS) " _
		& " VALUES (" & Session.SessionID & ", #" & OrderDate & "#, '" & REMOTE_ADDRESS & "')"

	Set RSCustID = Connection.Execute(SQL)
	Set RSCustID =  nothing
	SQL = "SELECT CUSTOMER_ID AS ORDER_ID, ORDER_DATE " _
		& " FROM customer " _
		& " WHERE ((ID = " & Session.SessionID & ") " _
		& " AND (ORDER_DATE = #" & OrderDate & "#)) "
	Set RS = Connection.Execute(SQL)

	ORDER_ID = RS("ORDER_ID")
	Set RS = nothing

	Session("ORDER_ID") = ORDER_ID
	
	SQLStmt = "SELECT SF_PATH, DELETE_POLICY, DELETE_SCHEDULE, LCID FROM Admin"
	Set RSAdmin = Connection.Execute(SQLStmt)
	DeletePolicy = RSAdmin("DELETE_POLICY")
	DeleteSchedule = RSAdmin("DELETE_SCHEDULE")
	DeleteSchedule = MakeUSDate(Date()-DeleteSchedule)
	Session("sfPath") = RSAdmin("SF_PATH")
	Session("LCID") = Trim(RSAdmin("LCID"))
	Set RSAdmin = nothing
	session.LCID = Session("LCID")

		If DeletePolicy = "2" Then
		SQL = "UPDATE customer SET CARD_NO = '**** **** **** ****', CARD_EXP = '**/**' WHERE ORDER_DATE <= #" & DeleteSchedule &"#"
		Set RSCreditDelete = Connection.Execute(SQL)
		Set RSCreditDelete = nothing
		ElseIf DeletePolicy = "3" Then
		SQL = "DELETE * from Customer WHERE ORDER_DATE <= #" & DeleteSchedule &"#"
		Set RSCreditDelete = Connection.Execute(SQL)
		Set RSCreditDelete = nothing
		End If
	
	SQL = "DELETE * FROM customer WHERE " _
		& "((GRAND_TOTAL = '0') AND (ORDER_DATE < #"& DelDate &"#) AND MAIL_SUBSCRIBED <> '1') "
	Set RSCleanUp = Connection.Execute(SQL)
	Set RSCleanUp = nothing
	REFERER = Request("REFERER")
	HTTP_REFERER = Request.ServerVariables("HTTP_REFERER")
	
	SQL = "UPDATE customer SET REFERER = '" & REFERER & "', " _
		& "HTTP_REFERER = '" & HTTP_REFERER & "' " _
		& "WHERE ((CUSTOMER_ID = " & ORDER_ID & ") " _
		& "AND (ORDER_DATE = #" & OrderDate & "#)) "
	Set RSReferrer = Connection.Execute(SQL)
	Set RSReferrer = nothing
	Connection.Close

End Sub


</SCRIPT>
