%@ LANGUAGE="VBSCRIPT" %>
<% Option Explicit %>
<%
returnPage = "accountSignup.asp"
Dim firstName, surname, company, street, suburb, postCode, phone, fax, email, website, customerPassword, newsletter
Dim countriesExist, countryID, countryName
Dim statesExist, stateID, stateName, stateAutoLoad, other_state
Dim countryJsCode
Dim submitted
Dim errorMsg, errorFound
Dim enableNewsletter
Dim pageMode
pageMode = request("m")
errorMsg = ""
errorFound = False
submitted = request.form("submitted")
if submitted <> "" then
submitted = true
email = request.form("email")
customerPassword = request.form("customerPassword")
if Trim(email) = "" then
errorMsg = errorMsg & "
You must enter your email address "
errorFound = true
else
if checkEmailAddress(email) = false then
errorMsg = errorMsg & "
Your email address appears invalid, please check it and try again "
errorFound = true
end if
end if
if customerPassword <> "*!*^*$" AND Trim(customerPassword) = "" then
errorMsg = errorMsg & "
You must enter your password "
errorFound = true
end if
firstName = request.form("firstName")
surname = request.form("surname")
company = request.form("company")
street = request.form("street")
suburb = request.form("suburb")
countryID = request.form("countryID")
stateID = request.form("stateID")
other_state = request.form("other_state")
if isNumberValid(countryID) then
countryName = lookUpItem("tblCountries", "countryName", "countryID", countryID)
else
countryName = countryID
end if
if not isTextValid(other_state) then
stateID = request.form("stateID")
stateName = lookUpItem("tblCountry_States", "stateName", "stateID", stateID)
else
stateName = other_state
end if
postCode = request.form("postCode")
phone = request.form("phone")
fax = request.form("fax")
website = request.form("website")
if Trim(firstName) = "" then
errorMsg = errorMsg & "
Please enter your first name "
errorFound = true
end if
if Trim(surname) = "" then
errorMsg = errorMsg & "
Please enter your last name "
errorFound = true
end if
newsletter = cBoolean(Request.form("newsletter"))
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open dbConnectionStr
if errorFound = false then
if lcase(cstr(""&pageMode)) = "2" then
' Check if the customer already exists apart from current customerID
SQLQuery = "SELECT customerID FROM tblCustomers WHERE email = '" & prepString(email) & "' AND customerPassword = '" & prepString(customerPassword) & "' AND NOT customerID = " & session("eCart_customerID") & ";"
Set ds = objConn.Execute(SQLQuery)
if not ds.EOF and not ds.BOF then
errorMsg = errorMsg & "
Invalid password, please select another password."
errorFound = true
end if
ds.close
Set ds = Nothing
if errorFound = false then
updateAccount()
else
countriesInDB()
statesInDB()
countryJsCode = buildCountryJsCode()
end if
else
' Check if the customer already exists
SQLQuery = "SELECT customerID FROM tblCustomers WHERE email = '" & prepString(email) & "' AND customerPassword = '" & prepString(customerPassword) & "';"
Set ds = objConn.Execute(SQLQuery)
if not ds.EOF and not ds.BOF then
errorMsg = errorMsg & "
Invalid password, please select another password."
errorFound = true
end if
ds.close
Set ds = Nothing
if errorFound = false then
addAccount()
else
countriesInDB()
statesInDB()
countryJsCode = buildCountryJsCode()
end if
end if
else
countriesInDB()
statesInDB()
countryJsCode = buildCountryJsCode()
end if
objConn.close
set objConn = nothing
else
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open dbConnectionStr
countriesInDB()
statesInDB()
countryJsCode = buildCountryJsCode()
if lcase(cstr(""&pageMode)) = "2" then loadAccountdetails()
SQLQuery = "SELECT enableNewsletter FROM tblStore_Checkout;"
Set ds = objConn.Execute(SQLQuery)
If not ds.eof and not ds.bof then
enableNewsletter = ds("enableNewsletter")
end if
ds.close
set ds = nothing
objConn.close
set objConn = nothing
end if
Sub addAccount()
'if dMode <> true then on error resume next
countryName = lookUpItem("tblCountries", "countryName", "countryID", countryID)
if Trim(other_state) <> "" then
stateName = other_state
else
stateName = lookUpItem("tblCountry_States", "stateName", "stateID", stateID)
end if
if databaseType = 1 then
set ds = server.createObject("ADODB.recordSet")
ds.Open "tblCustomers", dbConnectionStr, 1, 2, &H0002
ds.AddNew
ds("firstName") = firstName
ds("surname") = surname
ds("company") = company
ds("street") = street
ds("suburb") = suburb
ds("postCode") = postCode
ds("state") = stateName
ds("country") = countryName
ds("phone") = phone
ds("fax") = fax
ds("email") = email
ds("website") = website
ds("customerPassword") = customerPassword
ds("newsletter") = newsletter
ds.update
i = ds("customerID")
ds.close
set ds = nothing
elseIf databaseType = 2 then
SQLQuery = "INSERT INTO tblCustomers (firstName,surname,company,street,suburb,postCode,state,country,phone,fax,email,website,customerPassword,newsletter) VALUES ('" & prepString(firstName) & "','" & prepString(surname) & "','" & prepString(company) & "','" & prepString(street) & "','" & prepString(suburb) & "','" & prepString(postCode) & "','" & prepString(stateName) & "','" & prepString(countryName) & "','" & prepString(phone) & "','" & prepString(fax) & "','" & prepString(email) & "','" & prepString(website) & "', '" & prepString(customerPassword) & "'," & prepBoolean(newsletter) & ");SELECT @@IDENTITY as newCustomerID;"
set ds = objConn.Execute(SQLQuery).NextRecordSet
i = ds("newCustomerID")
ds.Close
set ds = nothing
' insert customer details in the forum table (MC 17/01/05)
SQLQuery = "INSERT INTO FORUM_MEMBERS (MEMBER_ID, M_EMAIL, M_PASSWORD, M_FIRSTNAME, M_LASTNAME) VALUES (" & i & ",'" & prepString(email) & "', '" & prepString(customerPassword) & "', '" & prepString(firstName) & "', '" & prepString(surname) & "');"
objConn.Execute(SQLQuery)
end if
session("eCart_customerID") = i
end sub
Sub updateAccount()
if dMode <> true then on error resume next
if customerPassword = "*!*^*$" then
SQLQuery = "UPDATE tblCustomers SET email='" & prepString(email) & "', firstName='" & prepString(firstName) & "', surname='" & prepString(surname) & "', company='" & prepString(company) & "', street='" & prepString(street) & "', suburb='" & prepString(suburb) & "', country='" & prepString(countryName) & "', state='" & prepString(stateName) & "', postCode='" & prepString(postCode) & "', phone='" & prepString(phone) & "', fax='" & prepString(fax) & "', website='" & prepString(website) & "', newsletter=" & prepBoolean(cStr(newsletter)) & " WHERE customerID=" & session("eCart_customerID") & ";"
else
SQLQuery = "UPDATE tblCustomers SET email='" & prepString(email) & "', customerPassword='" & prepString(customerPassword) & "', firstName='" & prepString(firstName) & "', surname='" & prepString(surname) & "', company='" & prepString(company) & "', street='" & prepString(street) & "', suburb='" & prepString(suburb) & "', country='" & prepString(countryName) & "', state='" & prepString(stateName) & "', postCode='" & prepString(postCode) & "', phone='" & prepString(phone) & "', fax='" & prepString(fax) & "', website='" & prepString(website) & "', newsletter=" & prepBoolean(cStr(newsletter)) & " WHERE customerID=" & session("eCart_customerID") & ";"
end if
objConn.Execute(SQLQuery)
end sub
Sub countriesInDB()
if dMode <> true then on error resume next
SQLQuery = "SELECT TOP 1 countryID FROM tblCountries;"
Set ds = objConn.Execute(SQLQuery)
If not ds.eof and not ds.bof then
countriesExist = true
else
countriesExist = false
end if
ds.close
set ds = nothing
end sub
Sub statesInDB()
if dMode <> true then on error resume next
SQLQuery = "SELECT TOP 1 stateID FROM tblCountry_States;"
Set ds = objConn.Execute(SQLQuery)
If not ds.eof and not ds.bof then
statesExist = true
else
statesExist = false
end if
ds.close
set ds = nothing
end sub
Function buildCountryJsCode()
if dMode <> true then on error resume next
' build JavaScript code for country/state dropdown's
Dim f_jsCode
Dim f_currentCID
f_currentCID = 0
Set ds = Server.CreateObject("ADODB.Recordset")
SQLQuery = "SELECT countryID, stateName, stateID FROM tblCountry_States ORDER BY countryID, stateName;"
Set ds = objConn.Execute(SQLQuery)
if not ds.EOF and not ds.BOF then
i = 1
do until ds.EOF
if Not ds("countryID") = f_currentCID then
f_currentCID = ds("countryID")
if f_jsCode <> "" then
f_jsCode = f_jsCode & "} else if (countryID == " & f_currentCID & ") {" & vbCr
else
f_jsCode = f_jsCode & "if (countryID == " & f_currentCID & ") {" & vbCr
end if
f_jsCode = f_jsCode & " if (updateShipping==1) {fillShipping(" & f_currentCID & ", 0)};" & vbcr
i = 1
end if
f_jsCode = f_jsCode & " addOption(menuObject, '" & replace(ds("stateName"), "'", "\'") & "','" & ds("stateID") & "');" & vbCr
if stateID = ds("stateID") then
stateAutoLoad = i
end if
i = i + 1
ds.MoveNext
Loop
f_jsCode = f_jsCode & "} else {" & vbCr
f_jsCode = f_jsCode & " if (updateShipping==1) {fillShipping(countryID, 0)};" & vbcr
f_jsCode = f_jsCode & "}" & vbCr
end if
ds.close
Set ds = Nothing
buildCountryJsCode = f_jsCode
End Function
Sub loadAccountdetails()
if dMode <> true then on error resume next
SQLQuery = "SELECT firstName, surname, company, street, suburb, state, country, postCode, phone, fax, email, website, newsletter FROM tblCustomers WHERE customerID=" & session("eCart_customerID") & ";"
Set ds = objConn.Execute(SQLQuery)
If not ds.eof and not ds.bof then
firstName = ds("firstName")
surname = ds("surname")
customerPassword = "*!*^*$"
company = ds("company")
street = ds("street")
suburb = ds("suburb")
stateName = ds("state")
countryName = ds("country")
stateID = lookUpItem("tblCountry_States", "stateID", "stateName", stateName)
if not isNumberValid(stateID) then
stateID = 0
other_state = stateName
end if
if countriesExist then
countryID = lookUpItem("tblCountries", "countryID", "countryName", countryName)
else
countryID = countryName
end if
postCode = ds("postCode")
phone = ds("phone")
fax = ds("fax")
email = ds("email")
website = ds("website")
newsletter = ds("newsletter")
end if
ds.close
set ds = nothing
end sub
%>
<% =session("storePageTitle") %>
"") then %> onLoad="fillstates(document.myAccount.stateID,document.myAccount.countryID[document.myAccount.countryID.selectedIndex].value, 0); selectState();"<% end if %>>
<% if lcase(cstr(""&pageMode)) = "2" then %>Edit Account info<% else %>Sign Up<% end if %>
<% if submitted <> "" and errorFound = false then
if lcase(cstr(""&pageMode)) = "2" then %>
You have successfully updated your details.
Back to My Account
<% end if
else %>
<% if errorMsg <> "" then %>
Errors were found with your submission, the errors are as follows:
<% =errorMsg %>
<% else
if lcase(cstr(""&pageMode)) = "2" then %>
To update your details simply change your details before and click 'Update'.
<% else %>
<% if enableNewsletter = true then %>
To receive our newsletter, please enter your details and click the 'Sign up' button below. You can use your email address and the password specified during checkout when ordering to load your details automatically and to log into the 'My Account' section which allows you to unsubscribe from the newsletter, track your orders status, view your receipts etc.
<% else %>
To create your account please enter your details and click the 'Sign up' button below. You can use your email address and the password specified during checkout when ordering to load your details automatically and to log into the 'My Account' section which allows you to track you orders status, view your receipts etc.
<% end if %>
<% end if %>
Fields marked * are required.
<% end if %>
<% end if %>
<% ' ERROR REPORTING - DON'T REMOVE!
if dMode <> true AND err.number <> 0 then
reportError err.number, err.description, err.source, ""
end if %>