<%option explicit%>
<!--#include file="shop$db.asp"-->
<!--#include file="shopcustomerform.asp"-->
<%
'*******************************************************
' Version 4.00 January 3, 2002
' If everyone must login then make them login
'*******************************************************
Dim strPassword1
Dim strPassword2
Dim msg, newcust
Dim i
Dim sAction
dim rs
' the database can be used. If you don't display form
Dim dbc
' **********************************************************************
' Set defaults here
'**********************************************************************
SetSess "CurrentURL","shoploginforce.asp"
SetSess "FollowonURL","shopdisplaycategories.asp"
'
sAction=Request.form("Action")   ' find out if we are being called via submit
If saction="" then
   sAction=Request.form("Action.x")   ' find out if we are being called via submit
end if   
Serror=GetSess("Loginerror")            ' possible mesage from login
SEtSess "Loginerror",""         ' error from shop login
If sAction = "" Then             ' no came from customer logic
     GetCustomerSessionData
     DisplayEverything
Else
     sError="" 
     ValidateData()             ' need to validate anything, nothing is required
     if sError = "" Then
        SEtSess "Login",strlastname
        UpdateOrderInformation  ' put in customer and order data
        SetSess "Login",strlastname
        Response.Redirect GetSess( "FollowonURL")
     else
        DisplayEverything 
      end if
end if
Sub DisplayEveryThing
     ShopPageHeader              ' Normal page header 
     Displayerrors               ' any input errors 
     DisplayLoginForm()          ' display customer 
     ShopPageTrailer             ' Normal page trailer
end Sub

' adds to customer table, order table, oitems table
Sub UpdateOrderInformation
UpdateContact             ' add customer to database
strCustomerid=GetSess("Customerid")
strDiscount=GetSess("CustDiscount")
UpdateCustomerSessionData
End Sub

Sub DisplayLoginForm()
        AddLogin           ' User login form
        If getconfig("xRestrictedtoExisting")= "Yes"  then exit sub
' Outside table
        Response.Write("<form name=Loginform method=Post action=shoploginforce.asp>")
	AddInformationTable
        ShopCustomerForm
        AddSubmitButton 
'       AddOptionalStuff
	Response.Write("</form>")

End Sub

Sub ValidateData()
	strFirstname = Request.Form("strFirstname")
	strLastname = Request.Form("strLastname")
	strAddress = Request.Form("strAddress")
	strCity = Request.Form("strCity")
	strState = Request.Form("strState")
	strPostCode = Request.Form("strPostCode")
	strCountry = Request.Form("strCountry")
	strCompany = Request.Form("strCompany")
	strWebsite = Request.Form("strWebsite")
	strPhone = Request.Form("strPhone")
	strWorkphone = Request.Form("strWorkphone")
	strMobilephone = Request.Form("strMobilephone")
	strFax = Request.Form("strFax")
	strEmail = Request.Form("strEmail")
	strPassword1 = Request.Form("strPassword1")
	strPassword2 = Request.Form("strPassword2")
	CustomerGetFields
	If strFirstname = "" Then
		sError = sError & LangCustFirstname  & LangCustRequired & "<br>"
	End If 

	If strLastname = "" Then
		sError = sError & LangCustLastname &  LangCustRequired & "<br>"
	End If 

	If strAddress = "" Then
		sError = sError & LangCustAddress & LangCustRequired & "<br>"
	End If 

	If strCity = "" Then
		sError = sError & LangCustCity & LangCustRequired & "<br>"
	End If 
If getconfig("xPromptForState")="Yes" then
	If strState = "" or strState="??"  Then
		sError = sError & LangCustState  & LangCustRequired & "<br>"
	End If 
end if
	If strPostCode = "" Then
		sError = sError & LangCustPostCode & LangCustRequired & "<br>"
	End If 

	If strPhone = "" Then
		sError = sError & LangCustPhone & LangCustRequired & "<br>"
	End If 

	If strEmail = "" Then
		sError = sError & LangCustEmail & LangCustRequired & "<br>"
	Else
	    CustomerValidateEmail stremail
	end if    
if getconfig("xCountryRequired")="Yes" then
       If strCountry=""  or strCountry="??" then 
		sError = sError & LangCustCountry & LangCustRequired & "<br>"
	End If 
end if

        ValidatePassword 
        
end sub

Sub AddLogin
If GetSess("Login")<>"" then
    exit sub
end if
If ucase(getconfig("Xpassword"))="YES" then
	Response.Write("<form name=form1 method=Post action=shoplogin.asp>")
        Response.write getconfig("xfont") & LangCust01 & "</font><br>"
	Response.Write TableDefLogin
        Response.Write (tablerow)
If ucase(getconfig("xPasswordLastname"))="YES" then
        response.write (tablecolumn & LangCustLastname & tablecolumnend & "<td><input size=20 name=strLastname value=" & Chr(34) & strLastname & Chr(34) & "></td>")
end if
	Response.Write(tablecolumn & LangCustEmail & tablecolumnend & "<td><input size=20 name=strEmail" & "></font></td>")
        Response.Write(tablecolumn & LangLoginPassword & tablecolumnend & "<td><input size=10 type=password name=strPassword"  & "></font></td>")
	If getconfig("xbuttonlogin")="" then 
            Response.Write("<td><input type=submit name=action value='" & langcommonlogin & "'>")
        else
	    Response.Write("<td><input type=image name=action src='" & getconfig("xbuttonlogin") & "'>")   
	end if    
        Response.write "</td></tr></table></form>"
        response.write ("<font size=1><a href=shopmailpwd.asp>" & LangLoginForgot & "</a></font>")
else
	Response.Write("<form name=form1 method=Post action=shoplogin.asp>")
        Response.write getconfig("xfont") & LangCust01 & "</font><br>"
	Response.Write TableDefLogin
	Response.Write(tablerow & tablecolumn & LangCustLastname & tablecolumnend & "<td><input size=20 name=strLastname value=" & Chr(34) & strLastname & Chr(34) & "></font></td>")
	Response.Write(tablecolumn & LangCustEmail & tablecolumnend & "<td><input size=20 name=strEmail" & "></font></td>")
	If getconfig("xbuttonlogin")="" then 
            Response.Write("<td><input type=submit name=action value='" & langcommonlogin & "'>")
        else
	    Response.Write("<td><input type=image name=action src='" & getconfig("xbuttonlogin") & "'>")   
	end if    
        Response.write "</td></tr></table></form>"
end if
end sub

Sub AddOptionalStuff
If getcoinfig("xPromptForOptional")="Yes" then
       Response.Write("<br><b>" & LangCust02 & "</b>")
       Response.Write(TableDef)
       CreateCustRow LangCustWebsite, "strwebsite", strwebsite,"No"
       CreateCustRow LangCustWorkphone, "strWorkphone", strWorkPhone, "No"
       CreateCustRow LangCustMobilephone, "strMobilephone", strMobilePhone, "No"
       CreateCustRow LangCustFax, "strFax", strFax, "No"
       Response.Write("</table><p>")
end if
end sub
Sub ValidatePassword
Dim rc
if ucase(getconfig("xpassword"))="YES" then
    If strPassword1 = "" Then
	sError = sError & LangPassword & "1" & LangCustRequired & "<br>"
         exit sub
    End If 
    If strPassword2 = "" Then
	sError = sError & LangPassword & "2" & LangCustRequired & "<br>"
        exit sub
   End If 
   If StrPassword1<>strPassword2 then
           SError= SError & LangPasswordMismatch & "<br>"
           exit sub
   end if
   if len(strPassword1) >= 6 then 
          CheckForDuplicate  rc
          if rc > 0 then
                SError= SError & LangPasswordDuplicate & "<br>"
           end if
    else
           Serror=Serror & LangPasswordLength & "<br>"
    end if
end if 
End sub

Sub DisplayErrors
if sError<> "" then
       response.write "<b>" & getconfig("Xfont") & SError & "</b></font>"
       Serror=""
 end if

end Sub
Sub AddSubmitButton
If Getconfig("xbuttoncontinue")="" then
   Response.Write("<input type=submit name=action value=""" & trim(LangCommonContinue) & """>")
else
    Response.Write("<input type=image name=action src=""" & getconfig("xbuttoncontinue") & """>")
end if    
end sub
Sub CheckForDuplicate (rc)
Dim testsql
dim myconn
SetSess "Login","Force"
OpenCustomerDb myconn
sql = "select * from customers where lastname='" & strlastname & "' and  password ='" & strpassword1 & "'"
sql = sql & " and email='" & stremail & "'"
'debugwrite  sql
Set rs = myconn.Execute(SQL)
If Not rs.EOF Then
   rc=4
else
   rc=0
end if
rs.close
shopclosedatabase myconn
SetSess "Login",""
end sub
Sub addInformationTable
response.write "<p align=center>" & getconfig("xfont")
Response.Write LangCustomerPrompt & "<br>"
Response.write "</font></p>"     
end Sub

Sub ValidateEmail
If Not InStr(strEmail, "@") > 1 Then
     Serror=Serror & LangInvalidEmail & "<br>"
end if
End sub


%>
