Das Output-Modul, das hier im rar-Archiv drinsteckt hat einige Bugs (s. Diskussion des Newsletter-Threads von HerrB).
Code: Alles auswählen
<?php
cInclude("classes", "class.newsletter.recipients.php");
cInclude("classes", "class.newsletter.php");
cInclude("classes", "class.frontend.users.php");
cInclude("classes", "class.phpmailer.php");
$objProperties = new PropertyCollection;
$objRecipients = new RecipientCollection;
$strMessage = " ";
$arrSettings = array();
$arrSettings["JoinSel"] = $objProperties->getValue("clientsetting", $client, "newsletter", "joinsel");
$arrSettings["JoinMultiple"] = $objProperties->getValue("clientsetting", $client, "newsletter", "joinmultiple");
$arrSettings["JoinGroups"] = $objProperties->getValue("clientsetting", $client, "newsletter", "joingroups");
$arrSettings["FrontendLink"] = $objProperties->getValue("clientsetting", $client, "newsletter", "frontendlink");
$arrSettings["FrontendConfirm"] = "CMS_VALUE[5]";
$arrSettings["FrontendDel"] = "CMS_VALUE[6]";
$arrSettings["SenderEMail"] = "CMS_VALUE[7]";
// Setting default values
if ($arrSettings["JoinSel"] == "" || $arrSettings["JoinGroups"] == "") {
$arrSettings["JoinSel"] = "Default";
}
if ($arrSettings["FrontendConfirm"] == "") {
$arrSettings["FrontendConfirm"] = "ActivateUser";
}
if ($arrSettings["FrontendDel"] == "") {
$arrSettings["FrontendDel"] = "DeleteUser";
}
if ($action == "subscribe") {
if (!isset($email) || !$email) {
$strMessage = mi18n("Please specify an e-mail address.");
} elseif (!isValidMail($email)) {
$strMessage = mi18n("Please specify a valid e-mail address.");
} elseif ($objRecipients->emailExists($email)) {
$strMessage = mi18n("This e-mail address has been already registered for the newsletter.");
} elseif (!isset($Nachname) || !$Nachname ) {
$strMessage = mi18n("Please specify a valid surname.");
} elseif (!isset($Vorname) || !$Vorname ) {
$strMessage = mi18n("Please specify a valid name.");
} else {
$email = ereg_replace("\n", "", $email);
$email = ereg_replace("\r", "", $email);
unset($recipient);
/* Analyze group specification */
switch ($arrSettings["JoinSel"]) {
case "Selected":
$recipient = $objRecipients->create($email, $emailname, 0, $arrSettings["JoinGroups"]);
break;
case "UserSelected":
$intSelCount = count($GroupSel);
if ($intSelCount == 0) {
$recipient = $objRecipients->create($email,$emailname); // No group selected
} else {
if ($intSelCount > 1 && $arrSettings["JoinMultiple"] != "enabled") {
$strMessage = mi18n("Please select one group, only.");
} else {
/* Recipient wants to join special groups */
$arrGroups = explode(",",$arrSettings["JoinGroups"]);
/* Check, if received data is valid and matches the group selection */
$blnError = false;
foreach ($GroupSel as $join) {
if (!is_numeric($join) || !in_array($join, $arrGroups)) {
$blnError = true;
break;
}
}
if ($blnError) {
$strMessage = mi18n("There was an error processing your request. Please ask the webmaster for help.");
} else {
$recipient = $objRecipients->create($email, $emailname, 0, implode(",",$GroupSel));
}
}
}
break;
default:
$recipient = $objRecipients->create($email,$emailname);
}
if ($recipient) {
$mail = new phpmailer();
$blackboxidcatart = $objProperties->getValue("clientsetting", $client, "Newsletter", "idcatart");
$body = mi18n("txtMailSubscribe")."\n".$cfgClient[$client]["path"]["htmlpath"]."front_content.php?changelang=".$lang."&idcatart=".$blackboxidcatart."&confirm=".$recipient->get("hash")."\n\n";
$mail->From = $arrSettings["SenderEMail"];
$mail->FromName = $arrSettings["SenderEMail"];
$mail->AddAddress($email);
$mail->Mailer = "mail";
$mail->Subject = mi18n("Newsletter: Confirmation");
$mail->Body = $body;
// $mail->AltBody = $body;
if($mail->Send()) {
// if (mail("$email", mi18n("Newsletter: Confirmation"), "$body", 'From: '.$arrSettings["SenderEMail"]."\n"."X-Mailer: Contenido [PHP/" . phpversion()."]")) {
$strMessage = mi18n("Dear subscriber,<br>your e-mail address is now subscribed for our newsletter. You will now receive an e-mail asking you to confirm your subscription.");
if ($arrSettings["FrontendLink"] == "enabled") {
$frontendusers = new FrontendUserCollection;
if (!$frontendusers->userExists($email)) {
if ($frontenduser = $frontendusers->create($email)) {
if ($arrSettings["FrontendConfirm"] == "ActivateUser") { // Inform about frontend user account creation
$strMessage .= mi18n("<br><br>After the confirmation you will also receive a password which you can use with your e-mail address to logon to special areas on this website.");
// Erweiterte FEUser Profil Daten speichern
$FEUserID = $frontenduser->get("idfrontenduser");
$oFEUser = new FrontendUser;
$oFEUser->loadByPrimaryKey($FEUserID);
$oFEUser->setProperty("address", "title", $Titel);
$oFEUser->setProperty("address", "surname", $Vorname);
$oFEUser->setProperty("address", "name", $Nachname);
$oFEUser->setProperty("address", "zip", $Postleitzahl);
$oFEUser->setProperty("adress", "city", $Ort);
$oFEUser->setProperty("address", "street", $Strasse);
$oFEUser->setProperty("address", "land", $Land);
$oFEUser->setProperty("address", "company", $Firma);
$oFEUser->setProperty("address", "telefone", $Telefon);
$oFEUser->setProperty("address", "fax", $Fax);
$oFEUser->setProperty("address", "mobile", $Mobil);
$oFEUser->setProperty("address", "homepage", $Homepage);
}
} else {
$strMessage .= mi18n("<br><br>Sorry, there was a problem creating your website account. Please ask the webmaster for help.");
}
}
}
} else {
$strMessage = mi18n("Sorry, there was a problem sending the confirmation mail to your e-mail address. Please ask the webmaster for help.");
}
} else {
$strMessage = mi18n("Sorry, there was a problem subscribing your e-mail address for the newsletter. Please ask the webmaster for help.");
}
}
} elseif ($action == "delete") {
if (!isset($email) || !$email) {
$strMessage = mi18n("Please specify an e-mail address.");
} elseif (!isValidMail($email)) {
$strMessage = mi18n("Please specify a valid e-mail address.");
} elseif ($recipient = $objRecipients->emailExists($email)) {
$mail = new phpmailer();
$blackboxidcatart = $objProperties->getValue("clientsetting", $client, "Newsletter", "idcatart");
$body = mi18n("txtMailDelete")."\n".$cfgClient[$client]["path"]["htmlpath"]."front_content.php?changelang=".$lang."&idcatart=".$blackboxidcatart."&unsubscribe=".$recipient->get("hash")."\n\n";
$mail->From = $arrSettings["SenderEMail"];
$mail->FromName = $arrSettings["SenderEMail"];
$mail->AddAddress($recipient->get("email"));
$mail->Mailer = "mail";
$mail->Subject = mi18n("Newsletter: Cancel subscription");
$mail->Body = $body;
// $mail->AltBody = $body;
if($mail->Send()) {
// if (mail($recipient->get("email"), mi18n("Newsletter: Cancel subscription"), $body, 'From: '.$arrSettings["SenderEMail"]."\n"."X-Mailer: Contenido [PHP/" . phpversion()."]")) {
$strMessage = mi18n("Dear subscriber,<br>a mail has been sent to your e-mail address. Please confirm the cancelation of the newsletter subscription.");
} else {
$strMessage = mi18n("Sorry, there was a problem sending you the cancelation confirmation e-mail. Please ask the webmaster for help.");
}
} else {
$strMessage = mi18n("Sorry, the e-mail address was not found.");
}
} elseif (strlen($confirm) == 30 && is_alphanumeric($confirm)) {
$objRecipients->select("idclient = '$client' AND idlang='$lang' AND hash = '$confirm'");
if ($recipient = $objRecipients->next()) {
// $idrecipient = $recipient->get("idnewsrcp");
$idrecipient = $recipient->get("idnewsrcp");
$email = $recipient->get("email");
$recipient->set("confirmed",1);
$recipient->set("confirmeddate", date("Y-m-d H:i:s"), false);
$recipient->set("deactivated",0);
$recipient->store();
$strMessage = mi18n("Thank you! You have confirmed your subscription to our newsletter!");
$newsletters = New NewsletterCollection;
$newsletters->select("idclient = '$client' AND idlang='$lang' AND welcome='1'");
if ($newsletter = $newsletters->next()) {
$result = $newsletter->send($objProperties->getValue("clientsetting", $client, "Newsletter", "idcatart"),"single",$idrecipient);
$strMessage .= mi18n(" The welcome newsletter is already on the way to you!");
}
if ($arrSettings["FrontendLink"] == "enabled" && $arrSettings["FrontendConfirm"] == "ActivateUser") {
$frontendusers = new FrontendUserCollection;
$frontendusers->select("idclient = '$client' AND username='".urlencode($email)."'");
if ($frontenduser = $frontendusers->next()) {
$frontenduser->set("active",1);
$pwd = substr(md5(rand()),0,8); // Generating password
$frontenduser->set("password", $pwd);
$frontenduser->store();
$strMessage .= mi18n("<br><br>Additionally, your website account has been activated. You can now use the following username and password to log in to access special areas on our website:<br>");
$strMessage .= mi18n("Username: ").$email.mi18n("<br>Password: ").$pwd;
$body = mi18n("txtMailPassword")."\n\n".mi18n("Username: ").$email."\n".mi18n("Password: ").$pwd."\n\n".mi18n("Click here to login: ").$cfgClient[$client]["path"]["htmlpath"]."front_content.php?changelang=".$lang;
$mail = new phpmailer();
$mail->From = $arrSettings["SenderEMail"];
$mail->FromName = $arrSettings["SenderEMail"];
$mail->AddAddress($email);
$mail->Mailer = "mail";
$mail->Subject = mi18n("Website account");
$mail->Body = $body;
// $mail->AltBody = $body;
if($mail->Send()) {
// if (mail($recipient->get("email"), mi18n("Website account"), $body, 'From: '.$arrSettings["SenderEMail"]."\n"."X-Mailer: Contenido [PHP/" . phpversion()."]")) {
$strMessage .= mi18n("<br><br>The account details and the password has also been sent to your mail account.");
} else {
$strMessage .= mi18n("<br><br><b>Sorry, there was a problem sending you the account details by mail. Please remember the given password.</b><b>");
}
} else {
$strMessage .= mi18n("<br><br>Sorry, there was a problem activating your website account, also. Please ask the webmaster for help.");
}
}
} else {
$strMessage = mi18n("Sorry, there was a problem confirming your subscription. Please ask the webmaster for help.");
}
} elseif (strlen($stop) == 30 && is_alphanumeric($stop)) {
$objRecipients->select("idclient = '$client' AND idlang='$lang' AND hash = '$stop'");
if ($recipient = $objRecipients->next()) {
$recipient->set("deactivated",1);
$recipient->store();
$strMessage = mi18n("Your newsletter subscription has been paused.");
} else {
$strMessage = mi18n("Sorry, there was a problem pausing your newsletter subscription. Please ask the webmaster for help.");
}
} elseif (strlen($goon) == 30 && is_alphanumeric($goon)) {
$objRecipients->select("idclient = '$client' AND idlang='$lang' AND hash = '$goon'");
if ($recipient = $objRecipients->next()) {
$recipient->set("deactivated",0);
$recipient->store();
$strMessage = mi18n("Newsletter subscription has been resumed.");
} else {
$strMessage = mi18n("Sorry, there was a problem resuming your newsletter subscription. Please ask the webmaster for help.");
}
} elseif (strlen($unsubscribe) == 30 && is_alphanumeric($unsubscribe)) {
$objRecipients->select("idclient = '$client' AND idlang='$lang' AND hash = '$unsubscribe'");
if ($recipient = $objRecipients->next()) {
$strEMail = $recipient->get("email"); // Saving recipient e-mail address
$objRecipients->delete($recipient->get("idnewsrcp"));
$strMessage = mi18n("Your e-mail address has been removed from our list of newsletter recipients.");
if ($arrSettings["FrontendLink"] == "enabled") {
$frontendusers = new FrontendUserCollection;
$frontendusers->select("idclient = '$client' AND username='".urlencode($strEMail)."'");
if ($frontenduser = $frontendusers->next()) {
switch ($arrSettings["FrontendDel"]) {
case "DeleteUser": // Deleting frontend account
$frontendusers->delete($frontenduser->get("idfrontenduser"));
$strMessage .= mi18n(" Your website account has been deleted.");
break;
case "DisableUser": // Disabling frontend account
$frontenduser->set("active",0);
$frontenduser->store();
$strMessage .= mi18n(" Your website account has been disabled.");
break;
default:
}
}
}
} else {
$strMessage = mi18n("Sorry, there was a problem removing your e-mail address. Please ask the webmaster for help.");
}
}
echo $strMessage;
?>