%@Language="VBScript"%>
<%Option Explicit%>
<%
'****************** VERY IMPORTANT *******************
' DO NOT CHANGE FIELD NAMES ON THIS PAGE, AS THEY ARE
' RELATED TO THE DATABASE, AND MAY CAUSE ERRORS !!!!!
'****************** VERY IMPORTANT *******************
dim formvalue,sql,objRS,EnquiryId,inputnamesplit,EnquiryQuestionId,Encrypted, formvaluetext, displayorder, question, CategoryId, CategoryName, QuestionId
dim strerrors,counter, getArrayPos, arrayName, FirstEmailArrayNo, SecondEmailArrayNo
dim values(500)
dim mailer
dim custEmailAddr,CustEmailName,MDEmailAddr,MDEmailName,secondapprequire
dim EmailHTML
dim qsDisplay : qsDisplay = request.QueryString("display")
function getArrayNameValue(arrayName)
formvalue = ""
inputnamesplit = ""
getArrayPos = PositionInArray(values,arrayName & "::" & request.Form(arrayName),"")
'response.Write(getArrayPos & " - " & arrayName & " - " & request.Form(arrayName) & "
")
if getArrayPos <> -1 then
inputnamesplit = split(values(getArrayPos),"::")
if ubound(inputnamesplit) > 0 then
'Cleanstring
formvalue = cleanstring(inputnamesplit(1))
end if
end if
end function
strErrors = ""
counter = 0
'SUBMIT D8A TO THE D8ABASE
if request.Form("submit1") <> "" then
for each formvalue in request.form
inputnamesplit = split(formvalue,"-")
if ubound(inputnamesplit) > 0 then
'Put ALL FORM VALUES into an array called 'VALUES'
counter = counter + 1
values(counter) = formvalue & "::" & request.Form(formvalue)
'#1 VALIDATION
'Check that all fields have been field out in the first applicant
'**** CHECK THAT THERE IS A VALUE IN THE INPUT TEXT ****
' if inputnamesplit(0) = "1" and instr(strErrors,"firstapp,") = false then
'if request.Form(formvalue) = "" then
'strErrors = strErrors & "firstapp,"
'end if
'
'end if
'#2 VALIDATION
'If any of the second applicant fields are filled in, they all need to be filled in.
'if inputnamesplit(0) = "2" and instr(strErrors,"secondapp,") = false then
'if request.Form(formvalue) <> "" then
' secondapprequire = true
'end if
'if secondapprequire = true AND instr(strErrors,"secondapp,") = false AND request.Form(formvalue) = "" AND formvalue <> "2-PropertyAddr" AND formvalue <> "2-PriceProperty" AND formvalue <> "2-PurposeMort" AND formvalue<>"2-PurposeProp" AND formvalue<> "2-TypeProp" AND formvalue <> "2-TotalCash" AND formvalue <> "2-TotalAmount" AND formvalue <> "2-TypeMortgage" AND formvalue <> "2-LengthTerm" AND formvalue <> "2-LoanAmount" then
' strErrors = strErrors & "secondapp,"
'end if
'#3 VALIDATION
'Check that DOB for second applicant is valid.
'if secondapprequire = true AND not isdate(request.Form("2-DOB")) then
' strErrors = strErrors & "seconddob,"
'end if
'end if
end if
next
'#4 VALIDATION - CHECK E-MAIL ADDRESS
'FIND ARRAY NUMBER TO FIRST APPLICANT E-MAIL ADDRESS IN VALUES
if isEmail(request.Form("1-email")) = false then
strErrors = strErrors & "firstemail,"
end if
if request.Form("1-Fullname") = "" then strErrors = strErrors & "fullname,"
if request.Form("1-Telno") = "" then strErrors = strErrors & "telno,"
CustEmailName = cleanstring(request.form("1-Fullname"))
CustEmailAddr = request.Form("1-Email")
'#5 VALIDATION - VALIDATE DATE OF BIRTH SO THEY CANT INPUT AN INCORRECT ONE
'if inStr(strErrors,"firstapp,") = false AND not isDate(request.Form("1-DOB")) then
'strErrors = strErrors & "firstdob,"
'end if
if strErrors = "" then
'******* BUILD SQL TABLE ********
'******* ADD RECORD TO ENQUIRY TABLE *******
application.Lock()
EnquiryId = IDinsertRS("INSERT INTO enquiry (affiliate,SessionId,submitdate) VALUES ('" & session("affiliate") & "','" & session("session_id") & "',{fn NOW()})")
Session("Session_id") = ""
application.UnLock()
'Clear Affiliate Section from Session
session("affiliate") = ""
'******* ADD ALL THE ANSWERS TO THE ENQUIRY ANSWER TABLE *******
for each formvalue in request.Form
'Each has two numbers seperated by a '-'. The first number is application number & second is Question ID
'if request.Form(formvalue) <> "" then
inputnamesplit = split(formvalue,"-")
if ubound(inputnamesplit) > 0 then
call makeRS(objRS,"SELECT * FROM enquiryquestion WHERE RelatedFieldName='" & inputnamesplit(1) & "'")
'Grab data from Question Table to input into answer table
EnquiryQuestionId = objRS("ID")
Encrypted = objRS("encrypted")
displayorder = objRS("displayorder")
question = objRS("question")
CategoryId = objRS("EnquiryCategoryId")
call closeRS(objRS)
call makeRS(objRS,"SELECT * FROM enquirycategory WHERE ID=" & CategoryId)
CategoryName = objRS("CategoryName")
call closeRS(objRS)
'******* ENCRYPTION ********
if encrypted = 1 then
'Encrypted text if requested
formvaluetext = request.Form(formvalue)
Dim encCM : Set encCM = Server.CreateObject("Persits.CryptoManager")
Dim encConText : Set encConText = encCM.OpenContext("", True) ' we must use containerless mode
Dim encExp1Key : Set encExp1Key = encConText.CreateExponentOneKey
Dim encBlob : Set encBlob = encCM.CreateBlob
Dim encKey : Set encKey = encConText.GenerateKeyFromPassword(EncKeyCode, calgSHA, calg3DES)
Dim EncryptedBlob : Set EncryptedBlob = encKey.EncryptText(formvaluetext)
formvaluetext = EncryptedBlob.Base64
else
formvaluetext = cleanstring(request.Form(formvalue))
end if
'INPUT ANSWER INTO TABLE
sql = "INSERT INTO enquiryanswer (EnquiryId,EnquiryQuestionId,Question,Encrypted,DisplayOrder,CategoryName,ApplicantNo,Answer) "
sql = sql & " VALUES ("
sql = sql & EnquiryId & ","
sql = sql & EnquiryQuestionId & ","
sql = sql & "'" & replace(question,"'","''") & "',"
sql = sql & encrypted & ","
sql = sql & displayorder & ","
sql = sql & "'" & CategoryName & "',"
sql = sql & inputnamesplit(0) & ","
sql = sql & "'" & formvaluetext & "')"
call executeRS(sql)
end if
'end if
next
'******** SEND CONFIRMATION E-MAIL TO CUSTOMER **********
' --------
if isEmail(custEmailAddr) then
CustEmailName = request.Form("1-FullName")
custEmailAddr = request.Form("1-Email")
MDEmailName = "MortgageDirectSL"
MDEmailAddr = "info@mortgagedirectsl.com"
EmailHTML = EmailHTML & "Thank you for your enquiry.
"
EmailHTML = EmailHTML & "We have recieved your enquiry and and will get back to you by return.
"
EmailHTML = EmailHTML & "Regards,
MortgageDirectSL"
set Mailer = nothing
Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
Mailer.FromName = MDEmailName
Mailer.FromAddress = MDEmailAddr
Mailer.RemoteHost = "mail.freshegg.net"
Mailer.ContentType = "text/html"
Mailer.AddRecipient CustEmailName, CustEmailAddr
'Mailer.AddBCC "lee", "lee@freshegg.com"
Mailer.Subject = "New Enquiry"
'Mailer.Encoding = 1
mailer.bodyText = EmailHTML
if not Mailer.SendMail then response.write "An error occured sending your confirmation email."
set Mailer = nothing
end if
EmailHTML = ""
'******** SEND CONFIRMATION E-MAIL TO ADMINISTRATOR **********
' -------------
EmailHTML = EmailHTML & "You have recieved a new enquiry from a customer.
"
EmailHTML = EmailHTML & "To view it, please log in to the admin area."
set Mailer = nothing
Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
Mailer.FromName = CustEmailName
Mailer.FromAddress = CustEmailAddr
Mailer.RemoteHost = "mail.freshegg.net"
Mailer.ContentType = "text/html"
Mailer.AddRecipient "Mortgage Direct SL", "info@mortgagedirectsl.com"
'Mailer.AddRecipient "David Grace", "david.grace@freshegg.com"
'Mailer.AddBCC "lee", "lee@freshegg.com"
Mailer.Subject = "A NEW Enquiry"
'Mailer.Encoding = 1
mailer.bodyText = EmailHTML
if not Mailer.SendMail then
response.write "An error occured sending your confirmation email."
response.Write(Mailer.Response)
response.End()
end if
response.Redirect("enquiry.asp?display=thankyou")
end if
end if
%>