Location: PHPKode > projects > ADbNewsSender > ADbNewsSender 2.1.0/protected/admin/global/NLmanagement.php.inc
<?php
//Copyright (c) Florian Grannemann
//Last change in version: 2.1 Alpha 3
/*
    ******************************************************************************
    ADbNewsSender 2

    Copyright (C) 2010 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/
    ******************************************************************************
*/

//Do not edit anything unless you realy REALY know what you are doing! 
include $path_to_languagefolder."lang_admin_nl_management.php.inc";

if($MyRequestHandler->getModuleKeyValue("Suboption"))
{
    $Suboption=$MyRequestHandler->getModuleKeyValue("Suboption");
}
if(!isset($Suboption))
{
    $Suboption="NL_mgtm_index";
}

if($Suboption!="NL_mgtm_index"&& $Suboption!="NL_mtgm_list_nl" && $Suboption!="NL_mgtm_create_NL")
{
    $Suboption="NL_mgtm_index";
}

if($Suboption=="NL_mgtm_index")
{
    
    print "<h2>$txt_nlMGT_index_title</h2>";
    print "<b>$txt_nlMGT_index_select:</b><br>";
    print "<a href=\"".$_SERVER['PHP_SELF']."?".$MyRequestHandler->getModuleKeyName("Suboption")."=NL_mtgm_list_nl\">$txt_nlMGT_index_shownls</a><br>";
    print "<a href=\"".$_SERVER['PHP_SELF']."?".$MyRequestHandler->getModuleKeyName("Suboption")."=NL_mgtm_create_NL\">$txt_nlMGT_index_createnew</a><br>";
}
if($Suboption=="NL_mtgm_list_nl")
{
    //list newsletters
  

    if($MyRequestHandler->getModuleKeyValue("deleteNL")=="yes")
    {
	$deletelist=$MyRequestHandler->getModuleKeyValue("deletelist");
	$numberofnls=$MyRequestHandler->getModuleKeyValue("numberofnls");
	$i=0;
	$defaultNL=intval($MyCFG->get_config_value("DefaultNL"));
	while($i < $numberofnls)
	{	
	    if(isset($deletelist[$i]))
	    {
	    
		$printMSG=preg_replace("/<-name->/",$MyCFG->get_NL_name($deletelist[$i]),$msg_nlMGT_showNLs_deleteNL);
		$printMSG=preg_replace("/<-ID->/",$deletelist[$i],$printMSG);
		$MyCFG->delete_Newsletter($deletelist[$i]);
		if($defaultNL==$deletelist[$i]){
		    //if the deleted nl is the default nl, unset default nl:
		    $MyCFG->replace_setting("DefaultNL","");
		}
		print $printMSG."<br>";
	    }
	    $i++;
	}
    print "<br><br>";
    }
    if($MyRequestHandler->issetModuleKey("setDefaultNL"))
    {
	if($MyCFG->NL_exists($MyRequestHandler->getModuleKeyValue("setDefaultNL"))){

	    $MyCFG->replace_setting("DefaultNL",$MyRequestHandler->getModuleKeyValue("setDefaultNL"));
	}
    }
    if($MyRequestHandler->getModuleKeyValue("unsetDefaultNL")=="yes")
    {
	$MyCFG->replace_setting("DefaultNL","");
    }
    $newsletters=array();
    $newsletters=$MyCFG->get_all_newsletters();
    if(count($newsletters) <1)
    {
	print "$msg_nlMGT_showNLs_no_nl";
    }
    else
    {
	print "<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">";
	print "<input type=\"hidden\" name=\"".$MyRequestHandler->getModuleKeyName("Suboption")."\" value=\"$Suboption\">";
	print "<input type=\"hidden\" name=\"".$MyRequestHandler->getModuleKeyName("deleteNL")."\" value=\"yes\">";
	print "<table border=1 class=\"shownewsletters\">";
	print "<tr><td>$msg_nlMGT_showNLs_table_delete</td><td>$msg_nlMGT_showNLs_table_id</td><td>$msg_nlMGT_showNLs_table_name</td>";
	print "<td>$msg_nlMGT_showNLs_table_created</td><td>$msg_nlMGT_showNLs_table_PLEntries</td><td>$msg_nlMGT_showNLs_table_MLEntries</td><td>$msg_nlMGT_showNLs_table_options</td></tr>";

	$defaultNL=intval($MyCFG->get_config_value("DefaultNL"));
	$timezone=$MyCFG->get_timezone();
	$i=0;
	while($i<count($newsletters))
	{
	    $tmpNL= new priv_Newsletter($newsletters[$i],$MyDB);
	    print "<tr";
	    $isdefaultNL=false;
	    if($defaultNL == $newsletters[$i]){
		$isdefaultNL=true;

		print " BGCOLOR=silver";
	    }
	    print "><td>";
	    print  "<input type=\"checkbox\" name=\"".$MyRequestHandler->getModuleKeyName("deletelist")."[$i]\" value=\"".$newsletters[$i]."\"></td>";
	    print  "<td>".$newsletters[$i]."</td><td>".$MyCFG->get_NL_name($newsletters[$i])."</td>";
	    print "<td>".date($msg_nlMGT_showNLs_dateformat,$MyCFG->get_NL_creation_time($newsletters[$i]))." ($timezone)</td>";
	    print "<td>".$tmpNL->number_of_PL_entries()."</td><td>".$tmpNL->number_of_ML_entries()."</td>";
	    print "<td><small>";
	    print "<a href=\"".$_SERVER['PHP_SELF']."?modul=".$MySessionHandler->getCurrentModule()."&".$MyRequestHandler->getModuleKeyName("Suboption")."=".$Suboption."&";
  
	    if($isdefaultNL){
		print $MyRequestHandler->getModuleKeyName("unsetDefaultNL")."=yes\">";
		print "<b>".$msg_nlMGT_showNLs_table_options_unsetAsDefaultNL."</b>";
	    }
	    else{
		print $MyRequestHandler->getModuleKeyName("setDefaultNL")."=".$newsletters[$i]."\">";
		print "<b>".$msg_nlMGT_showNLs_table_options_setAsDefaultNL."</b>";
	    }
	    print "</a><br>";
		    
	    print "<a href=\"".$_SERVER['PHP_SELF']."?modul=nl|3&SelectNL=".$newsletters[$i]."\">$msg_nlMGT_showNLs_table_options_changecfg</a><br>";
	    print "<a href=\"".$_SERVER['PHP_SELF']."?modul=nl|0&SelectNL=".$newsletters[$i]."\">$msg_nlMGT_showNLs_table_options_sendNL</a><br>";	  
	    print "</td></tr>";
	    $i++;
	}
	
	
	print "</table>";
	print "<input type=\"hidden\" name=\"".$MyRequestHandler->getModuleKeyName("numberofnls")."\" value=\"$i\">";
	print "<input type=\"submit\" value=\"$msg_nlMGT_showNLs_delete\"></form>";
	
    }

    print "<br><a href=\"".$_SERVER['PHP_SELF']."?".$MyRequestHandler->getModuleKeyName("Suboption")."=NL_mgtm_create_NL\">$txt_nlMGT_index_createnew</a>";
    print "<br>";
    print "<a href=\"".$_SERVER['PHP_SELF']."?".$MyRequestHandler->getModuleKeyName("Suboption")."=NL_mgtm_index\">$txt_nlMGT_back_to_index</a>";
}
if($Suboption=="NL_mgtm_create_NL")
{
   print "<h3>$txt_nlMGT_create_title</h3>";

    $nl_name="";
    $nl_email=$MyCFG->get_config_value("Email");
    $nl_time_on_ML=6;
    $nl_time_on_PL=2;
    $nl_max_confirmation_attempts=3;
    $Archive_storetime=6;
    $Archive_enabled="yes";
    $setAsDefaultNL="no";
    $nl_language=$MyCFG->get_config_value("Language");
    if($MyRequestHandler->getModuleKeyValue("create_NL")=="yes")
    {
	$error="";
	// print "h:$txt_nlMGT_create_Nl_name :".$_REQUEST["nl_name"];
	//is the newsletter name specified?
	if(!$MyRequestHandler->getModuleKeyValue("nl_name"))
	{
	   
	    $error=$txt_nlMGT_create_Nl_name;
	}
	
	//is the e-mail adress specified?
	if(!$MyRequestHandler->getModuleKeyValue("nl_email"))
	{
	   
	    $error=$error."<br>".$txt_nlMGT_create_Nl_email;
	}
	if(!$MyRequestHandler->getModuleKeyValue("nl_language"))
	{
	   
	    $error=$error."<br>".$txt_nlMGT_create_language;
	}
	
	if($MyRequestHandler->getModuleKeyValue("setAsDefaultNL")=="yes"){
	    $setAsDefaultNL="yes";
	 }
	if(!$error)
	{    //if all fields are specified:	
	    //creating newsletter:
	    $ID=$MyCFG->create_Newsletter(htmlentities($MyRequestHandler->getModuleKeyValue("nl_name")));
	    if($ID >0)
	    {
		//success, $ID contains the id number of the new newsletter
		//creating a temp newsletter object to write the nl configuration:
		$tmpNL= new priv_Newsletter($ID,$MyDB);
		
		//writing e-mail adress:
		$tmpNL->replace_setting("Email",$MyRequestHandler->getModuleKeyValue("nl_email"));
		
		 $tmpNL->replace_setting("Limit_Confirmation_Attempts",$MyRequestHandler->getModuleKeyValue("nl_max_confirmation_attempts"));
		if($MyRequestHandler->getModuleKeyValue("nl_max_confirmation_attempts") <0)
		{   //setting to unlimited:	
		    $tmpNL->replace_setting("Limit_Confirmation_Attempts","0");
		}
		if($MyRequestHandler->getModuleKeyValue("nl_max_confirmation_attempts") >30)
		{
		    $tmpNL->replace_setting("Limit_Confirmation_Attempts","30");
		}
		$tmpNL->replace_setting("Time_on_ML",$MyRequestHandler->getModuleKeyValue("nl_time_on_ML"));
		if($MyRequestHandler->getModuleKeyValue("nl_time_on_ML") <2)
		{
		    $tmpNL->replace_setting("Time_on_ML","2");
		}
		if($MyRequestHandler->getModuleKeyValue("nl_time_on_ML") >60)
		{
		    $tmpNL->replace_setting("Time_on_ML","60");
		}

		$tmpNL->replace_setting("Time_on_PL",$MyRequestHandler->getModuleKeyValue("nl_time_on_PL"));
		if($MyRequestHandler->getModuleKeyValue("nl_time_on_PL") <1)
		{
		    $tmpNL->replace_setting("Time_on_PL","1");
		}
		if($MyRequestHandler->getModuleKeyValue("nl_time_on_PL") >14)
		{
		    $tmpNL->replace_setting("Time_on_PL","14");
		}
		if($MyRequestHandler->getModuleKeyValue("Archive_enabled") !="yes")
		{
		    $tmpNL->replace_setting("Archive_enabled","no");
		}
		else
		{
		     $tmpNL->replace_setting("Archive_enabled","yes");
		}
		$tmpNL->replace_setting("Archive_storetime","".intval($MyRequestHandler->getModuleKeyValue("Archive_storetime"))."");
		if(intval($MyRequestHandler->getModuleKeyValue("Archive_storetime")) <1)
		{
		    $tmpNL->replace_setting("Archive_storetime","1");
		}
		if(intval($MyRequestHandler->getModuleKeyValue("Archive_storetime")) >120)
		{
		    $tmpNL->replace_setting("Archive_storetime","120");
		}

		$tmpNL->replace_setting("Language",$MyRequestHandler->getModuleKeyValue("nl_language"));
		$tmpNL->replace_setting("Max_no_of_eq_IP_Addr_on_PL","0");

		if($setAsDefaultNL=="yes"){
		    $MyCFG->replace_setting("DefaultNL",$ID);
		}
		print "<b>$msg_nlMGT_create_success</b><br><br>";
		print "<a href=\"".$_SERVER['PHP_SELF']."?SelectNL=$ID&".$MyRequestHandler->getModuleKeyName("Suboption")."=$Suboption\">$msg_nlMGT_create_success_select</a><br><br>";
	    }
	    else
	    {
		//something has gone wrong. Maybe the db connection has failed.
		
		print "<b>$msg_nlMGT_create_failed</b><br>";
	    }
	}
	else
	{   //if not: print error message:	
            print "<b>$error_nlMGT_create</b><br>$error<br><br><br>";
	    $nl_name=$MyRequestHandler->getModuleKeyValue("nl_name");
	    $nl_email=$MyRequestHandler->getModuleKeyValue("nl_email");
	    $nl_time_on_ML=$MyRequestHandler->getModuleKeyValue("nl_time_on_ML");
	    $nl_time_on_PL=$MyRequestHandler->getModuleKeyValue("nl_time_on_PL");
	    $nl_language=$MyRequestHandler->getModuleKeyValue("nl_language");
	    $nl_max_confirmation_attempts=$MyRequestHandler->getModuleKeyValue("nl_max_confirmation_attempts");
	    $Archive_enabled=$MyRequestHandler->getModuleKeyValue("Archive_enabled");
	    $Archive_storetime=$MyRequestHandler->getModuleKeyValue("Archive_storetime");
	}
   }
    
    print "<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">";
  
    print "<table border=0>";
	
    print "<tr><td>$txt_nlMGT_create_Nl_name</td><td><input type=\"text\" name=\"".$MyRequestHandler->getModuleKeyName("nl_name")."\" value=\"$nl_name\" size=\"20\"></td></tr>";
    print "<tr><td>$txt_nlMGT_create_Nl_email</td><td><input type=\"text\" name=\"".$MyRequestHandler->getModuleKeyName("nl_email")."\" size=\"20\" value=\"$nl_email\"></td></tr>";
    print "<tr><td>$txt_nlMGT_create_time_on_ML</td><td><select name=\"".$MyRequestHandler->getModuleKeyName("nl_time_on_ML")."\"><option value=\"0\">$txt_nlMGT_create_select</option";
    $i=2;
    while($i <=60)
    {
	print "<option value=\"$i\"";
	if($i==$nl_time_on_ML)
	{
	    print " selected ";
	}
	print ">$i</option>";
	$i++;

    }
    print "</select> $txt_nlMGT_create_months</td></tr>";
    
    print "<tr><td>$txt_nlMGT_create_time_on_PL</td><td><select name=\"".$MyRequestHandler->getModuleKeyName("nl_time_on_PL")."\"><option value=\"0\">$txt_nlMGT_create_select</option";
    $i=1;
    while($i <=14)
    {
	print "<option value=\"$i\"";
	if($i==$nl_time_on_PL)
	{
	    print " selected ";
	}
	print ">$i</option>";
	$i++;

    }
    print "</select> $txt_nlMGT_create_days</td></tr>";

    print "<tr><td>$txt_nlMGT_create_max_conf_attempts</td><td><select name=\"".$MyRequestHandler->getModuleKeyName("nl_max_confirmation_attempts")."\"><option value=\"0\"";
 
     
    if($nl_max_confirmation_attempts==0)
    {
	print " selected";
    }

    print ">$txt_nlMGT_create_unlimited</option>";
    $i=1;
    while($i <=30)
    {
	print "<option value=\"$i\"";
	if($i==$nl_max_confirmation_attempts)
	{
	    print " selected ";
	}
	print ">$i</option>";
	$i++;

    }
    print "</select></td></tr>";

    print "<tr><td>$txt_nlMGT_create_Archive_enabled</td><td> $txt_nlMGT_create_yes <input type=\"radio\" name=\"".$MyRequestHandler->getModuleKeyName("Archive_enabled")."\" value=\"yes\"";
    
    if($Archive_enabled =="yes")
    {
	print " checked ";
    }
    print "> | $txt_nlMGT_create_no <input type=\"radio\" name=\"".$MyRequestHandler->getModuleKeyName("Archive_enabled")."\" value=\"no\"";
    if($Archive_enabled !="yes")
    {
	print " checked ";
    }

    print "></td></tr>"; 

      print "<tr><td>$txt_nlMGT_create_Archive_storetime</td><td><select name=\"".$MyRequestHandler->getModuleKeyName("Archive_storetime")."\">";
 
     
    $i=1;
    while($i <=120)
    {
	print "<option value=\"$i\"";
	if($i==$Archive_storetime)
	{
	    print " selected ";
	}
	print ">$i</option>";
	$i++;

    }
    print "</select> $txt_nlMGT_create_months</td></tr>";

    print "<tr><td>$txt_nlMGT_create_language</td><td><select name=\"".$MyRequestHandler->getModuleKeyName("nl_language")."\"><option value=\"0\">$txt_nlMGT_create_select</option";
    include "$path_to_protected/localization/Language_Reg.php.inc";
    
    $i=0;
    while($i <count($Lang_pack_name))
    {
	print "<option value=\"".$Lang_pack_dir[$i]."\"";
	if($Lang_pack_dir[$i]==$nl_language)
	{
	    print " selected ";
	}
	print ">".$Lang_pack_name[$i]."</option>";
	$i++;

    }
    print "</select></td></tr>";

    print "<tr><td>$txt_nlMGT_create_set_as_default_nl</td><td> $txt_nlMGT_create_yes <input type=\"radio\" name=\"".$MyRequestHandler->getModuleKeyName("setAsDefaultNL")."\" value=\"yes\"";
    
    if($setAsDefaultNL =="yes")
    {
	print " checked ";
    }
    print "> | $txt_nlMGT_create_no <input type=\"radio\" name=\"".$MyRequestHandler->getModuleKeyName("setAsDefaultNL")."\" value=\"no\"";

    if($setAsDefaultNL !="yes")
    {
	print " checked ";
    }

    print "></td></tr>"; 


    print "</table><input type=\"hidden\" name=\"".$MyRequestHandler->getModuleKeyName("Suboption")."\" value=\"$Suboption\"><input type=\"hidden\" name=\"".$MyRequestHandler->getModuleKeyName("create_NL")."\" value=\"yes\"><input type=\"submit\" value=\"$txt_nlMGT_create_submit\"></form>";
    print "<br><br><br>";
    print "<a href=\"".$_SERVER['PHP_SELF']."?".$MyRequestHandler->getModuleKeyName("Suboption")."=NL_mgtm_index\">$txt_nlMGT_back_to_index</a><br>";
}

?> 
Return current item: ADbNewsSender