setTitle("Mailing List - Edit"); $template->setKeywords("Tymax Systems, Mailing Lists, Products, Services"); $template->doHeader(); if(!isset($action)) { echo "

Mail List

"; echo "

Apply here to be notified of new products and services. We will never sell, rent,"; echo " trade or otherwise make available the e-mail addresses of anyone subscribed, "; echo "or previously subscribed.

\n"; echo "

\n"; echo "\n"; echo "\n"; echo "\t\n"; echo "\t\t\n"; echo "\t\t\n"; echo "\t\n"; echo "\t\t\n"; echo "\t\t\n"; echo "\t\n"; echo "\t\n"; echo "\t\t\n"; echo "\t\t\n"; echo "\t\n"; echo "
Name 
Email Address
 "; echo "

\n"; $template->doFooter(); exit; } if($action=="subscribe"){ $errorCount = 0; echo "

Submitting your details now.

\n"; $email = trim($email); $name = trim($name); if( $email=="") { $errorCount++; echo "

ERROR: Email address is required.

\n"; } else { if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){ $errorCount++; echo "

ERROR: ".htmlentities($email)." is not a valid email address.

"; } } if( $name=="") { $errorCount++; echo "

ERROR: Name is required.

\n"; } if($errorCount!=0){ echo "

There are $errorCount error(s) preventing a successful submission to our mailing list.

\n"; $template->doFooter(); exit; } // User aborts won't stop script execution // Essential since we're generating SQL ignore_user_abort(true); // Add the user ( if they don't already exist ) to our database. // Open up a SQL connection to the database global $REMOTE_ADDR; if($REMOTE_ADDR=="127.0.0.1") $sqlHandle = @mysql_connect("127.0.0.1","dbo36966841"); else $sqlHandle = @mysql_connect("db50.oneandone.co.uk","dbo36966841","fbcbcbn"); if($sqlHandle==false){ echo "

ERROR: Unable to connect with database.

\n"; echo "

Sorry there appears to have been a temporary fault. Your details were not added, please try again later.

\n"; $template->doFooter(); exit; } // Select the database. $result=@mysql_select_db("db36966841",$sqlHandle); if(!$result){ // Try one more time. $result=@mysql_select_db("db36966841",$sqlHandle); if(!$result){ echo "

ERROR: Unable to select database.

\n"; echo "

Sorry there appears to have been a temporary fault. Your details were not added, please try again later.

\n"; $template->doFooter(); exit; } // It connected second time. } // Initialise a table // If the subscriber table does not already // exist it will be created here. // The user table will be made here if it // does not already exist. $query = "CREATE TABLE IF NOT EXISTS `subscribers` ("; $query.= "`UserID` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, "; $query.= "`Email` CHAR(60) NOT NULL, "; $query.= "`Name` CHAR(45) NOT NULL, "; $query.= "`JDTimeStamp` INT UNSIGNED NOT NULL, "; $query.= "PRIMARY KEY (`UserID`), UNIQUE (`UserID`));"; $result = @mysql_query( $query ,$sqlHandle); if($result==false) { echo "

ERROR: Unable to initialise database table.

\n"; echo "

Sorry there appears to have been a temporary fault. Your details were not added, please try again later.

\n"; $template->doFooter(); exit; } // Ensure that replicate details don't already exist $query = "SELECT * FROM `subscribers` "; $query.= "WHERE email='$email' LIMIT 1;"; $result = @mysql_query( $query, $sqlHandle ); if($result == false ){ echo "

ERROR: General database error.

\n"; echo "

Sorry there appears to have been a temporary fault. Your details were not added, please try again later.

\n"; $template->doFooter(); exit; } if( @mysql_num_rows($result)!=0 ){ // This confirmation message should be the same as the one sent // if the users email address were NOT in the database. This // prevents hackers from determining which email address exist // in the database. echo "

Your details have been added to the subscriber list.\n"; echo "You'll be notified about new products and services from Tymax Systems.

\n"; $row = @mysql_fetch_array($result); $unsubscribeURL = buildUnsubscribeURL($row["UserID"],$row["Email"]); printf("

To unsubscribe click here.

",$unsubscribeURL); sendConfirmationEmail($email,$name,$unsubscribeURL); $template->doFooter(); exit; } // Generate a JD DateStamp $JDTimeStamp = unixtojd( time() ); // Now insert the user info into the database $query = "INSERT INTO `subscribers` "; $query.= "(`UserID`, `Name`, `Email`, `JDTimeStamp` ) "; $query.= "VALUES (0, '$name', '$email', $JDTimeStamp );"; $result= @mysql_query( $query ,$sqlHandle); if($result==false) { echo "

ERROR: Unable add your details to the database.

\n"; echo "

Sorry there appears to have been a temporary fault. Your details were not added, please try again later.

\n"; $template->doFooter(); exit; } // This confirmation message should be the same as the one sent // if the users email address was already in the database. This // prevents hackers from determining which email address exist // in the database. echo "

Your details have been added to the subscriber list.\n"; echo "You'll be notified about new products and services from Tymax Systems.

\n"; $unsubscribeURL = buildUnsubscribeURL( mysql_insert_id( $sqlHandle ),$email); printf("

To unsubscribe click here.

",$unsubscribeURL); sendConfirmationEmail($email,$name,$unsubscribeURL); sendSecurityEmail($name,$email,true); $template->doFooter(); exit; } if($action=="unsubscribe"){ $errorCount = 0; echo "

Removing your subscription details now.

\n"; $email = trim($email); $userid = trim($userid); if( $email=="") { $errorCount++; echo "

ERROR: Email address is required.

\n"; } else { if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){ $errorCount++; echo "

ERROR: ".htmlentities($email)." is not a valid email address.

"; } } if( $userid=="") { $errorCount++; echo "

ERROR: UserID is required.

\n"; } if($errorCount!=0){ echo "

There are $errorCount error(s) preventing your removal from our mailing list.

\n"; $template->doFooter(); exit; } // User aborts won't stop script execution // Essential since we're generating SQL ignore_user_abort(true); // Add the user ( if they don't already exist ) to our database. // Open up a SQL connection to the database global $REMOTE_ADDR; if($REMOTE_ADDR=="127.0.0.1") $sqlHandle = @mysql_connect("127.0.0.1","dbo36966841"); else $sqlHandle = @mysql_connect("db50.oneandone.co.uk","dbo36966841","fbcbcbn"); if($sqlHandle==false){ echo "

ERROR: Unable to connect with database.

\n"; echo "

Sorry there appears to have been a temporary fault. Your details were not removed, please try again later.

\n"; $template->doFooter(); exit; } // Select the database. $result=@mysql_select_db("db36966841",$sqlHandle); if(!$result){ // Try one more time. $result=@mysql_select_db("db36966841",$sqlHandle); if(!$result){ echo "

ERROR: Unable to select database.

\n"; echo "

Sorry there appears to have been a temporary fault. Your details were not removed, please try again later.

\n"; $template->doFooter(); exit; } // It connected second time. } // Initialise a table // If the subscriber table does not already // exist it will be created here. // The user table will be made here if it // does not already exist. $query = "CREATE TABLE IF NOT EXISTS `subscribers` ("; $query.= "`UserID` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, "; $query.= "`Email` CHAR(60) NOT NULL, "; $query.= "`Name` CHAR(45) NOT NULL, "; $query.= "`JDTimeStamp` INT UNSIGNED NOT NULL, "; $query.= "PRIMARY KEY (`UserID`), UNIQUE (`UserID`));"; $result = @mysql_query( $query ,$sqlHandle); if($result==false) { echo "

ERROR: Unable to initialise database table.

\n"; echo "

Sorry there appears to have been a temporary fault. Your details were not removed, please try again later.

\n"; $template->doFooter(); exit; } // Check that the user information actually exists $query = "SELECT * FROM `subscribers` "; $query.= "WHERE Email='$email' and UserID='$userid' LIMIT 1;"; $result = @mysql_query( $query, $sqlHandle ); if($result==false){ echo "

General DataBase error\nYour details were NOT removed from the subscriber list.

\n"; $template->doFooter(); exit; } else { if( @mysql_num_rows($result)==1 ) { echo "

Sorry to see you leave.

\n"; $row = @mysql_fetch_array($result); sendSecurityEmail($row["Name"],$row["Email"],false); } } // Delete the user record now $query = "DELETE FROM `subscribers` "; $query.= "WHERE Email='$email' and UserID='$userid' LIMIT 1;"; $result = @mysql_query( $query, $sqlHandle ); if($result==false){ echo "

General DataBase error\nYour details were NOT removed from the subscriber list.

\n"; $template->doFooter(); exit; } echo "

Your details were removed from the subscriber list.\n"; echo " You will not receive anymore emails about new products and services from Tymax Systems.

\n"; $template->doFooter(); exit; } echo "

ERROR: Undefined action.

\n"; $template->doFooter(); function buildUnsubscribeURL($UserID,$UserEmail) { global $REQUEST_URI; global $HTTP_HOST; $url_parts = parse_url( $REQUEST_URI ); $scheme = trim($url_parts["scheme"]); if( strlen($scheme)== 0 ) $scheme="http://"; $host = trim($url_parts["host"]); if( strlen($host)== 0 ) $host=$HTTP_HOST; $path = trim($url_parts["path"]); if( strlen($path)== 0 ) $path="/"; return $scheme.$host.$path."?action=unsubscribe&userid=$UserID&email=".rawurldecode($UserEmail); } function sendConfirmationEmail($email,$name,$unsubscribeURL) { global $REMOTE_ADDR; global $echoLocalEmailsFlag; $email = trim($email); $message = "Thank you $name.\n\n"; $message.= "Your email address $email has been entered into Tymax System's subscriber database.\n"; $message.= "You will be notified about new products and services from Tymax Systems.\n"; $message.= "You can remove this information whenever you like by following this link $unsubscribeURL.\n"; $message.= "\n\nYours sincerely\n"; $message.= "Tymax Systems.\n\n"; // Generate message headers $headers = "From: \n" ."Return-To: \n" ."Return-Path: \n"; // For errors $subject = "Tymax Systems Subscriber Confirmation"; if($REMOTE_ADDR!="127.0.0.1"){ return @mail($email,$subject,$message ,$headers); } if($echoLocalEmailsFlag==false) return true; echo "

You are working in test mode so the confirmation email was not sent

\n"; echo "

Subject

\n"; echo "

$subject

"; echo "

Message

\n"; echo "

$message

\n"; return true; } function sendSecurityEmail($name,$email,$addFlag) { global $REMOTE_ADDR; global $echoLocalEmailsFlag; $email = trim($email); $message.= "$name\n$email\n"; // Generate message headers $headers = "From: \n" ."Return-To: \n" ."Return-Path: \n"; // For errors if($addFlag==true) $subject = "ADDED $email to mailist."; else $subject = "REMOVED $email from maillist."; if($REMOTE_ADDR!="127.0.0.1"){ return @mail($email,$subject,$message ,$headers); } if($echoLocalEmailsFlag==false) return true; echo "

You are working in test mode so the confirmation email was not sent

\n"; echo "

Subject

\n"; echo "

$subject

"; echo "

Message

\n"; echo "

$message

\n"; return true; } ?>