<% @ Language=VBScript %>
<% Option Explicit %>
<!--#include file="common.asp" -->
<!--#include file="functions/functions_hash1way.asp" -->
<!--#include file="functions/functions_send_mail.asp" -->
<%
'****************************************************************************************
'**  Copyright Notice    
'**
'**  Web Wiz Guide - Web Wiz Mailing List
'**                                                              
'**  Copyright 2001-2005 Bruce Corkhill All Rights Reserved.                                
'**
'**  This program is free software; you can modify (at your own risk) any part of it 
'**  under the terms of the License that accompanies this software and use it both 
'**  privately and commercially.
'**
'**  All copyright notices must remain in tacked in the scripts and the 
'**  outputted HTML.
'**
'**  You may use parts of this program in your own private work, but you may NOT
'**  redistribute, repackage, or sell the whole or any part of this program even 
'**  if it is modified or reverse engineered in whole or in part without express 
'**  permission from the author.
'**
'**  You may not pass the whole or any part of this application off as your own work.
'**   
'**  All links to Web Wiz Guide and powered by logo's must remain unchanged and in place
'**  and must remain visible when the pages are viewed unless permission is first granted
'**  by the copyright holder.
'**
'**  This program is distributed in the hope that it will be useful,
'**  but WITHOUT ANY WARRANTY; without even the implied warranty of
'**  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR ANY OTHER 
'**  WARRANTIES WHETHER EXPRESSED OR IMPLIED.
'**
'**  You should have received a copy of the License along with this program; 
'**  if not, write to:- Web Wiz Guide, PO Box 4982, Bournemouth, BH8 8XP, United Kingdom.
'**    
'**
'**  No official support is available for this program but you may post support questions at: -
'**  http://www.webwizguide.info/forum
'**
'**  Support questions are NOT answered by e-mail ever!
'**
'**  For correspondence or non support questions contact: -
'**  info@webwizguide.info
'**
'**  or at: -
'**
'**  Web Wiz Guide, PO Box 4982, Bournemouth, BH8 8XP, United Kingdom
'**
'****************************************************************************************


'Set the response buffer to true as we maybe redirecting
Response.Buffer = True 

'Declare variables
Dim strEmail		'Holds the users e-mail address
Dim strUserName		'Holds the members name
Dim strPassword		'Holds the user password
Dim blnHTMLformat	'Set to true if email is to be in HTML format
Dim strMessage		'Holds the error message if the user is not entered into the database
Dim strUserCode		'Holds a unique code for the new list member
Dim blnEmailOK		'Set to true if the email address is valid
Dim lngMemberID		'Holds the members ID number
Dim laryCatID		'Holds the cat ID
Dim blnChecked		'Set to true if the category checkbox is to be checked
Dim blnEmailExists	'Set to true if the email address is already in the database
Dim strSubject		'Holds the subject of te email
Dim strEmailBody	'Holds the email body
Dim strSaltValue	'Holds the salt value for ecrypted passwords
Dim blnEmailBanned	'Holds if the email address or domain are banned
Dim strCheckEmailAddress'Holds the banned email address list to check
Dim strBlockedEmailAddress	'Hoilds the blocked email address


'Initialise variables
blnEmailOK = True
blnEmailExists = false
blnEmailBanned = false
lngMemberID = 0

'Read in the email address
strEmail = Trim(Mid(LCase(Request("email")), 1, 50))

'Clean up the email address address getting rid of unwanted characters
strEmail = characterStrip(strEmail)



'Read in the form details
If Request.Form("postBack") Then
	
	'Check to see if the user has entered an e-mail address and that it is a valid address
	If Len(strEmail) < 5 OR NOT Instr(1, strEmail, " ") = 0 OR InStr(1, strEmail, "@", 1) < 2 OR InStrRev(strEmail, ".") < InStr(1, strEmail, "@", 1) Then
		
		'Set an error message if the users has not enetered a valid e-mail address
		blnEmailOK = False 
		
	'Else the email address is OK
	Else
		blnEmailOK = True
	End If	
	
	'Read in the form details
	strUserName = removeAllTags(Trim(Mid(Request.Form("name"), 1, 25)))
	strPassword = removeAllTags(Trim(Mid(Request.Form("password"), 1, 25)))
	If blnPlainTextOption = true Then blnHTMLformat = CBool(Request.Form("HTMLformat")) Else blnHTMLformat = true





	'Check to see if the email address or email domain entered is banned
	
	'Initalise the strSQL variable with an SQL statement to query the database
	strSQL = "SELECT " & strDbTable & "EmailBanList.Email FROM " & strDbTable & "EmailBanList;"
	
	'Query the database
	rsCommon.Open strSQL, adoCon
	
	'If records are returned check-em out
	'Loop through the email address and check 'em out
        Do while NOT rsCommon.EOF

        	'Read in the email address to check
                strCheckEmailAddress = rsCommon("Email")

                'If a whildcard character is found then check that
                If Instr(1, strCheckEmailAddress, "*", 1) > 0 Then

	           	'Remove the wildcard charcter from the email address to check
	                strCheckEmailAddress = Replace(strCheckEmailAddress, "*", "", 1, -1, 1)

			'If the banned email and the email entered match up then don't let em sign up
	                If InStr(1, strEmail, strCheckEmailAddress, 1) Then 
	                	blnEmailBanned = True
	                	strBlockedEmailAddress = rsCommon("Email")
	                End If

	    	'Else check the actual name doesn't match
	   	Else
	        	'If the banned email and the email entered match up then don't let em sign up
	             	If strCheckEmailAddress = strEmail Then
	             		blnEmailBanned = True
	                	strBlockedEmailAddress = strCheckEmailAddress
	                End If
	        End If

                'Move to the next record
                rsCommon.MoveNext
     	Loop
     	
     	'Close recordset
     	rsCommon.Close

End If





'If this is a post back run the add new or update code
If Request.Form("postBack") AND blnEmailOK AND strUserName <> "" AND strPassword <> "" AND blnEmailBanned = false Then
		
	
	'Initalise the strSQL variable with an SQL statement to query the database
	strSQL = "SELECT " & strDbTable & "Members.* FROM " & strDbTable & "Members;"
		
	With rsCommon
			
		'Set the cursor type property of the record set to Dynamic so we can navigate through the record set
		.CursorType = 2
				
		'Set the Lock Type for the records so that the record set is only locked when it is updated
		.LockType = 3
				
		'Query the database
		.Open strSQL, adoCon
		
				
		'Calculate a code for the user
		strUserCode = hexValue(20)
		
		'Loop through all the records in the recordset to check that the user id and the email address are not already in the database
		Do While NOT .EOF	
			
			'If there is no user code or it is already in the database make a new one and serch the recordset from the begining again
			If strUserCode = .fields("ID_Code") Then
				
				'Calculate a code for the user
				strUserCode = hexValue(20)
			
				'Move to the first record to make sure the new user code is not in the database
				.MoveFirst
			End If	
			
			'If the e-mail address is already in the database then this is an update so exit loop
			If strEmail = .fields("Email") Then
				
				'Set the blnEmailExists variable to true
				blnEmailExists = true
				
				'Exit the for loop
				Exit Do
			End If
			
			'Move to the next record in the recordset
			.MoveNext	
		Loop	
		
		
		'If the email doesn't already exsist then enter the email into the database
		If blnEmailExists = False Then
		
			'Encrypt password
			If blnEncryptPasswords Then
				
				'generate a salt value
				strSaltValue = hexValue(Len(strPassword))
				
				'Concatenate salt value to the password
		                strPassword = strPassword & strSaltValue
		
		                'Encrypt the password
		                strPassword = HashEncode(strPassword)
			End If
			
			
				
			'Add new record to a new recorset
			.AddNew
			
			'Set database fields	
			.Fields("Email") = strEmail
			.Fields("Name") = strUserName
			.Fields("Password") = strPassword
			If blnEncryptPasswords Then .Fields("Salt") = strSaltValue
			.Fields("ID_Code") = strUserCode
			.Fields("HTMLformat") = blnHTMLformat
			.Fields("Active") = False
				
			'Update the database
			.Update
			
			
			'Requery database to get the new id number
			.Requery
			
			'Move to the last record
			.MoveLast
			
			'Get the id number
			lngMemberID = CLng(.fields("Mail_ID"))
		End If
		
		'Reset recordset variable
		.Close
	End With
			
	
	
	'If the email doesn't already exsist then enter the categoriy details into the database
	If blnEmailExists = False Then
			
		'Add the category details to the database
		For each laryCatID in Request.Form("catID")
			
			'Add cat choices
			strSQL = "INSERT INTO " & strDbTable & "MemCat " & _
			"("  & _
			"[Mail_ID], " & _
			"[Cat_ID] " & _
			") " & _
			"VALUES " & _
			"('" & lngMemberID & "', " & _
			"'" & CLng(laryCatID) & "' " & _
			")" 
			
			'Write to database 
			adoCon.Execute(strSQL) 
		Next
	
		
		
		
		'If email activation of account is enabled then get send an activation email
		If blnActivate Then
			
			'Set the subject of the email
			strSubject = strWebsiteName & ": " & strTxtConformYourSubscriptionToMailingList
				
			'set the message body of the activation email
			strEmailBody = strTxtHi & " " & strUserName & "," & _
			vbCrLf & vbCrLf & strTxtGreetingsFrom & " " & strWebsiteName & "." & _
			vbCrLf & vbCrLf & strTxtWeReceivedYourRequestToSubscribe & " " & strWebsiteName & " " & strTxtMailingList & "." & _
			vbCrLf & vbCrLf & strTxtToActivateYourSubscriptionClickTheAddressBelow & ":-" & _
			vbCrLf & vbCrLf & strWebsiteAddress & "/activate.asp?ID=" & strUserCode & _
			vbCrLf & vbCrLf & strTxtIfYouDidNotSubscribe & "." & _
			vbCrLf & vbCrLf & strTxtThankYouForYourInterest & "." & _
			vbCrLf & vbCrLf & strSignature
				
			'Create email object
			Call createMailObject(strMailComponent)
			
			'***** START WARNING - REMOVAL OR MODIFICATION OF THIS CODE WILL VIOLATE THE LICENSE AGREEMENT ******	
			'Write a remove from mailing list message to add to the end of the e-mail in HTML Format
			strEmailBody = strEmailBody & mailBody("text", strEmail, blnLCode)
			'***** END WARNING - REMOVAL OR MODIFICATION OF THIS CODE WILL VIOLATE THE LICENSE AGREEMENT ******
					
			'Send the email
			Call SendMail(strUserName, strEmail, strMailComponent, "text")
			
			'Drop email component
			Call dropMailObject(strMailComponent)
			
			'Clean up
			Set rsCommon = Nothing
			adoCon.Close
			Set adoCon = Nothing    
			
			
			'Redirect to actiavtion page
			Response.Redirect("activate_confirm.asp?email=" & Server.URLEncode(strEmail))
						
		End If
		
		'Clean up
		Set rsCommon = Nothing
		adoCon.Close
		Set adoCon = Nothing    
			
			
		'Redirect to actiavtion page
		Response.Redirect("activate.asp?ID=" & strUserCode)
	End If	
	
End If

%>
<html>
<head>
<title>Mailing List: Maak een Account</title>
<!--#include file="includes/browser_page_encoding_inc.asp" -->
<!--//
/* *******************************************************
Application: Web Wiz Mailing List ver.<% = strVersion %>
Author: Bruce Corkhill
Info: http://www.webwizmailinglist.com
Available FREE: http://www.webwizmailinglist.com
Copyright: Bruce Corkhill ©2001-2005. All rights reserved
******************************************************* */
//-->
<script language="JavaScript">

//Function to check form is filled in correctly before submitting
function CheckForm () {

	var errorMsg = "";

	//Check for a name
        if (document.frmRegister.name.value.length == ''){
                errorMsg += "\n\t<% = strTxtNameEnterYourName %>";
        }
        
        //If an e-mail is entered check that the e-mail address is valid
        if (document.frmRegister.email.value == "" || (document.frmRegister.email.value.indexOf("@",0) == -1||document.frmRegister.email.value.indexOf(".",0) == -1)) {
                errorMsg +="\n\t<% = strTxtEmailAddressEnterYourValidEmailAddress %>";

        }

        //Check for a password
        if (document.frmRegister.password.value.length <= 3){
                errorMsg += "\n\t<% = strTxtPasswordYourPasswordMustB4Characters %>";
        }

        //Check both passwords are the same
        if ((document.frmRegister.password.value) != (document.frmRegister.password2.value)){
                errorMsg += "\n\t<% = strTxtPasswordErrorPasswordsDoNotMatch %>";
                document.frmRegister.password.value = ""
                document.frmRegister.password2.value = ""
        }

	//If there is aproblem with the form then display an error
	if (errorMsg != ""){
		msg = "<% = strTxtErrorDisplayLine %>\n\n";
		msg += "<% = strTxtErrorDisplayLine1 %>\n";
		msg += "<% = strTxtErrorDisplayLine2 %>\n";
		msg += "<% = strTxtErrorDisplayLine %>\n\n";
		msg += "<% = strTxtErrorDisplayLine3 %>\n";

		errorMsg += alert(msg + errorMsg + "\n\n");
		return false;
	}

	return true;
}

</script>

<!-- #include file="includes/header.asp" -->
<div align="center">
  <span class="heading"><% = strWebsiteName & "'s " & strTxtMailingList & " " & strTxtCreateAccount %></span><br />
  <div align="center">
   <%

'If there is a problem tell the user
If blnEmailOK = false OR blnEmailExists OR blnEmailBanned OR (Request.Form("postBack") AND (strUserName = "" OR strPassword = "")) Then

%>
   <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
    <tr>
     <td align="center" class="error"><br />
      <strong><% = strTxtYourSubscriptionRequestCouldNotBeProcessed %>.</strong><br /><%
      
	If blnEmailOK = false Then
		Response.Write(strTxtEmailAdressNotValid & ".")
	ElseIf blnEmailBanned Then
		Response.Write(strTxtTheEmailAddressOrDomainEntered & ", " & strBlockedEmailAddress & ", " & strTxtIsNotPermittedPleaseEnterNew & ".")
	ElseIf blnEmailExists Then
		Response.Write(strTxtTheEmailAddressYouEntered & ", " & strEmail & " " & strTxtIsAlreadySubscribedPlease & "  <a href=""default.asp?email=" & Server.URLEncode(strEmail) & """>" & strTxtClickhere & "</a> " & strTxtToLogInWithThisAddressToEditAccount & ".")
	ElseIf strUserName = "" Then
		Response.Write(strTxtPleaseEnterAValidName& ".")
	ElseIf strPassword = "" Then
		Response.Write(strTxtPleaseEnterAValidPassword& ".")
	End If
%>
    </tr>
   </table>
   <%

End If

%>
  <br />
  <form name="frmRegister" method="post" action="sign_up.asp" onSubmit="return CheckForm();">
   <table width="95%" border="0" cellspacing="0" cellpadding="1" bgcolor="<% = strTableBorderColour %>" align="center">
    <tr>
     <td>
      <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="<% = strTableBgColour %>">
       <tr>
        <td bgcolor="<% = strTableTitleColour %>">
         <table width="100%" border="0" cellspacing="1" cellpadding="3" bgcolor="<% = strTableBgColour %>">
          <tr bgcolor="<% = strTableTitleColour %>">
            <td colspan="2" background="<% = strTableTitleBgImage %>" class="tHeading"><% = strTxtNewAccountDetails %><span class="smText"> (<% = strTxtAllFieldsAreRequired %>) </span></td>
          </tr>
          <tr bgcolor="<% = strTableColour %>" background="<% = strTableBgImage %>">
           <td colspan="2" background="<% = strTableBgImage %>" bgcolor="<% = strTableColour %>" class="text"><% = strTxtPleaseRegisterToActivateYourMailingListSubscription & " " & strWebsiteName & " " & strTxtFeaturesAndNewsYouCanUnsubscribe %>. </td>
          </tr>
          <tr bgcolor="<% = strTableColour %>" background="<% = strTableBgImage %>">
           <td width="289" background="<% = strTableBgImage %>" bgcolor="<% = strTableColour %>" class="text"><% = strTxtName %>:</td>
           <td width="677" background="<% = strTableBgImage %>" bgcolor="<% = strTableColour %>" class="text"><input name="name" type="text" id="name" size="25" maxlength="25" value="<% = strUserName %>" /></td>
          </tr>
          <tr bgcolor="<% = strTableColour %>" background="<% = strTableBgImage %>">
           <td background="<% = strTableBgImage %>" bgcolor="<% = strTableColour %>" class="text"><% = strTxtEmailAddress %>:</td>
           <td bgcolor="<% = strTableColour %>" background="<% = strTableBgImage %>" class="text"><input name="email" type="text" id="email" size="25" maxlength="50" value="<% = strEmail %>" /></td>
          </tr>
          <tr bgcolor="<% = strTableColour %>" background="<% = strTableBgImage %>">
           <td background="<% = strTableBgImage %>" bgcolor="<% = strTableColour %>" class="text"><% = strTxtPassword %>: </td>
           <td bgcolor="<% = strTableColour %>" background="<% = strTableBgImage %>" class="text"><input name="password" type="password" id="password" size="25" maxlength="25" /></td>
          </tr>
          <tr bgcolor="<% = strTableColour %>" background="<% = strTableBgImage %>">
           <td background="<% = strTableBgImage %>" bgcolor="<% = strTableColour %>" class="text"><% = strTxtConfirmPassword %>: </td>
           <td bgcolor="<% = strTableColour %>" background="<% = strTableBgImage %>" class="text"><input name="password2" type="password" id="password2" size="25" maxlength="25" /><input type="hidden" name="postBack" value="true" /></td>
          </tr><%

'If the user can choose to have a plain text email sent give them the option
If blnPlainTextOption Then
	
%>
          <tr bgcolor="<% = strTableColour %>" background="<% = strTableBgImage %>">
           <td background="<% = strTableBgImage %>" bgcolor="<% = strTableColour %>" class="text"><% = strTxtEmailDeliveryFormat %>:</td>
           <td bgcolor="<% = strTableColour %>" background="<% = strTableBgImage %>" class="text"><input name="HTMLformat" type="radio" value="true" checked /><% = strTxtHTML %>&nbsp; <input name="HTMLformat" type="radio" value="false" /><% = strTxtPlainText %></td>
          </tr><%
End If

%>
          <tr align="center" bgcolor="<% = strTableColour %>" background="<% = strTableBgImage %>">
           <td colspan="2" background="<% = strTableBgImage %>" bgcolor="<% = strTableBottomRowColour %>" class="text">&nbsp;</td>
          </tr>
        </table></td>
       </tr>
     </table></td>
    </tr>
   </table>
   <br />
      <br />
   <span class="text">
   <input type="submit" name="Submit" value="<% = strTxtCreateMyAccount %>"></span>  
   <br /><br /><a href="privacy.asp" target="_blank" class="smLink"><% = strTxtPrivacyStatement %></a>
   </form>
   <%


Response.Write("<br />")


'***** START WARNING - REMOVAL OR MODIFICATION OF THIS CODE WILL VIOLATE THE LICENSE AGREEMENT ******
If blnLCode Then
	Response.Write("<span class=""smText"">Powered by <a href=""http://www.webwizmailinglist.com"" target=""_blank"" class=""smLink"">Web Wiz Mailing List</a> version " & strVersion & "</span>")
	Response.Write("<br /><span class=""smText"">Copyright &copy;2001-2005 <a href=""http://www.webwizguide.info"" target=""_blank"" class=""smLink"">Web Wiz Guide</a></span>")
End If 
'***** END WARNING - REMOVAL OR MODIFICATION OF THIS CODE WILL VIOLATE THE LICENSE AGREEMENT ******
 %>
 </div>
  </div>
<!--#include file="includes/footer.asp" -->
