<?php
/* File: subscribe.php.inc
//Last change in version: 2.0.2
******************************************************************************
ADbNewsSender 2
Copyright (C) 2009 Florian Grannemann (hide@address.com)
Website: http://adbnewssender.sf.net
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/
******************************************************************************
*/
include "$path_to_protected_folder/skeleton/public_apis.class.php.inc";
$path_to_DB_defs="$path_to_protected_folder/skeleton/includes/db_defs/";
$path_to_DB_conf="$path_to_protected_folder/database/DBconf.php.inc";
$MyDB = new ADBNS_DB($path_to_DB_defs,$path_to_DB_conf);
$MyCFG=new global_config_ro($MyDB);
$option=$_REQUEST["subscroption"];
$NLID=$_REQUEST["NewsletterID"];
$email="";
$error="";
$message="";
//selecting language settings:
$lang="";
if(!$NLID||$NLID <1)
{
if($default_language=="global")
{
$langfile=$path_to_protected_folder."/localisation/lang/".$MyCFG->get_config_value("Language")."/lang_subscribe.php.inc";
}
else
{
if(!file_exists("$path_to_protected_folder/localisation/lang/$default_language/lang_subscribe.php.inc"))
{ //if the default language is invalid fall back to global settings:
$langfile=$path_to_protected_folder."/localisation/lang/".$MyCFG->get_config_value("Language")."/lang_subscribe.php.inc";
}
else
{
$langfile="$path_to_protected_folder/localisation/lang/$default_language/lang_subscribe.php.inc";
}
}
}
else
{
if(!$MyCFG->NL_exists($NLID))
{
die("Error: The selected Newsletter does not exist!");
}
$MyNL =new pub_Newsletter($NLID,$MyDB);
$langfile=$path_to_protected_folder."/localisation/lang/".$MyNL->get_NLconfig_setting("Language")."/lang_subscribe.php.inc";
}
//including the language file:
if(!@include_once($langfile))
{
die("Error: Could not include the language file!");
}
//does the layout template file exist?
if(!file_exists($LayoutFile))
{
//if not: die:
die($Error_Templatefile);
}
$templatefile=file("$LayoutFile");
//because this is an array, we need to implode it:
$templatefile=implode("\n",$templatefile);
if($option=="subscribe")
{
if(!isset($NLID) || $NLID <0)
{
$error=$error.$Text_OTHER[8]."<br>";
}
else
{
if($MyCFG->NL_exists($NLID))
{
//permission to receive the confirmation e-mail?
if($_POST["agreement"]=="yes")
{ //yes:
$email=$_POST["email"];
$email=preg_replace("/ /","",$email);
//trying to add to PL:
$result=$MyNL->add_to_PL($email,$_SERVER['REMOTE_ADDR'],$path_to_protected_folder."/localisation/lang/".$MyNL->get_NLconfig_setting("Language")."/confirmationmail.php.inc");
//was it successfully?
if($result <1)
{
//no, let's see what happened:
if($result <=-4)
{
//e-mail address is invalid or number of equal ip addresses has been reached:
$error=$error.$Text_OTHER[4]."<br>";
//if -4 the ip address is invalid
//for security reasons, to avoid cross site scripting:
$email=htmlentities($email);
}
if($result==-3)
{
//could not include the confirmation mail. (check if the path has been specified correctly!)
$error=$error.$Text_OTHER[10]."<br>";
}
if($result==-2)
{ //Already on ML(-2)
$error=$error.$Text_Email_Allready_ON_MaillingList."<br>";
}
if($result==-1)
{ //Already on PL
$error=$error.$Text_Email_Allready_ON_PendingList."<br>";
}
if($result==0)
{
//connection to database has failed :-(
$error=$error.$Text_OTHER[9]."<br>";
$email=htmlentities($email);
}
}
else
{
//yes, the confirmation e-mail has been sent, the e-mail address has been added to pendinglist.
//($result is the id number of the new pendinglist-entry)
$message=$message.$Text_OTHER[3]."<br>";
$email=htmlentities($email);
}
}
else
{ //no permission to receive the confirmation e-mail:
//to avoid cross site scripting:
$email=htmlentities($_POST["email"]);
$error=$error.$Text_OTHER[5]."<br>";
}
}
else
{
$error=$error.$Text_OTHER[8]."<br>";
}
}
}
if($option=="unsubscribe")
{
if(!isset($NLID) || $NLID <0)
{
$error=$error.$Text_OTHER[8]."<br>";
$email=htmlentities($email);
}
else
{
if($MyCFG->NL_exists($NLID))
{
$email=$_REQUEST["email"];
$email=preg_replace("/ /","",$email);
//try to get maillinglist entry id:
$result=$MyNL->get_ML_entry_id($email);
if($result <1)
{ //something has gone wrong....
if($result ==-2)
{
//empty or invalid e-mail address:
$email=htmlentities($email);
$error=$error.$Text_OTHER[4]."<br>";
}
if($result ==-1)
{
//The e-mail address is not on maillinglist:
$email=htmlentities($email);
$error=$error.$Text_OTHER[6]."<br>";
}
if($result==0)
{
//Connection to database has failed :-(
$error=$error.$Text_OTHER[9]."<br>";
$email=htmlentities($email);
}
}
else
{
//got the ID in $result.
//try to delete from ml:
if($MyNL->delete_from_ML($result))
{
//success:
$message=$message.$Text_OTHER[7]."<br>";
}
else
{
//failed:
$error=$error.$Text_OTHER[6]."<br>";
}
}
}
else
{
$email=htmlentities($_REQUEST["email"]);
$error=$error.$Text_OTHER[8]."<br>";
}
}
}
$message=$message."<br>".$error;
//printing subscription form:
//replacing placeholders:
$subscriptionform=preg_replace("/<-TextFieldEmail->/",$Text_OTHER[0],$templatefile);
$subscriptionform=preg_replace("/<-Email->/",$email,$subscriptionform);
$subscriptionform=preg_replace("/<-TxtSubscribe->/",$Text_Subscribe,$subscriptionform);
$subscriptionform=preg_replace("/<-TxtUnsubscribe->/",$Text_Unsubscribe,$subscriptionform);
$subscriptionform=preg_replace("/<-Agreement->/",$Text_OTHER[2]." ".$Text_OTHER[1],$subscriptionform);
$subscriptionform=preg_replace("/<-message->/",$message,$subscriptionform);
//preparing the <option> list of newsletters:
$Newsletters=array();
$Newsletter_options="<option value=\"0\">$Text_SelectNewsletter</option>";
$Newsletters=$MyCFG->get_all_newsletters();
$i=0;
if(count($Newsletters)==1)
{
$NLID=$Newsletters[0];
}
while($i <count($Newsletters))
{
$Newsletter_options=$Newsletter_options."<option value=\"".$Newsletters[$i]."\"";
if($NLID==$Newsletters[$i])
{
$Newsletter_options=$Newsletter_options." selected ";
}
$Newsletter_options=$Newsletter_options.">".$MyCFG->get_NL_name($Newsletters[$i])."</option>";
$i++;
}
$subscriptionform=preg_replace("/<-NewsletterOptionList->/",$Newsletter_options,$subscriptionform);
print $subscriptionform;
?>