Location: PHPKode > projects > ADbNewsSender > ADbNewsSender_2.0.4/protected/admin/global/NLmanagement.php.inc
<?php
//Copyright (c) Florian Grannemann
//Last change in version: 2.0 Beta 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/
    ******************************************************************************
*/

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

if(isset($_REQUEST["Suboption"]))
{
    $Suboption=$_REQUEST["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']."?Suboption=NL_mtgm_list_nl\">$txt_nlMGT_index_shownls</a><br>";
    print "<a href=\"".$_SERVER['PHP_SELF']."?Suboption=NL_mgtm_create_NL\">$txt_nlMGT_index_createnew</a><br>";
}
if($Suboption=="NL_mtgm_list_nl")
{
    //list newsletters
  

    if($_REQUEST["deleteNL"]=="yes")
    {
	$deletelist=$_REQUEST["deletelist"];
	$numberofnls=$_REQUEST["numberofnls"];
	$i=0;

	
	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]);
		print $printMSG."<br>";
	    }
	    $i++;
	}
    print "<br><br>";
    }
    $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=\"Suboption\" value=\"$Suboption\">";
	print "<input type=\"hidden\" name=\"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>";

	$timezone=$MyCFG->get_timezone();
	$i=0;
	while($i<count($newsletters))
	{
	    $tmpNL= new priv_Newsletter($newsletters[$i],$MyDB);
	    print "<tr><td>";
	    print  "<input type=\"checkbox\" name=\"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><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></td></tr>";
	    $i++;
	}
	
	
	print "</table>";
	print "<input type=\"hidden\" name=\"numberofnls\" value=\"$i\">";
	print "<input type=\"submit\" value=\"$msg_nlMGT_showNLs_delete\"></form>";
	
    }

    print "<br><a href=\"".$_SERVER['PHP_SELF']."?Suboption=NL_mgtm_create_NL\">$txt_nlMGT_index_createnew</a>";
    print "<br>";
    print "<a href=\"".$_SERVER['PHP_SELF']."?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";
    $nl_language=$MyCFG->get_config_value("Language");
    if($_REQUEST["create_NL"]=="yes")
    {
	$error="";
	// print "h:$txt_nlMGT_create_Nl_name :".$_REQUEST["nl_name"];
	//is the newsletter name specified?
	if(!$_REQUEST["nl_name"])
	{
	   
	    $error=$txt_nlMGT_create_Nl_name;
	}
	
	//is the e-mail adress specified?
	if(!$_REQUEST["nl_email"])
	{
	   
	    $error=$error."<br>".$txt_nlMGT_create_Nl_email;
	}
	if(!$_REQUEST["nl_language"])
	{
	   
	    $error=$error."<br>".$txt_nlMGT_create_language;
	}
	
	
	if(!$error)
	{    //if all fields are specified:	
	    //creating newsletter:
	    $ID=$MyCFG->create_Newsletter(htmlentities($_REQUEST["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",$_REQUEST["nl_email"]);
		
		 $tmpNL->replace_setting("Limit_Confirmation_Attempts",$_REQUEST["nl_max_confirmation_attempts"]);
		if($_REQUEST["nl_max_confirmation_attempts"] <0)
		{   //setting to unlimited:	
		    $tmpNL->replace_setting("Limit_Confirmation_Attempts","0");
		}
		if($_REQUEST["nl_max_confirmation_attempts"] >30)
		{
		    $tmpNL->replace_setting("Limit_Confirmation_Attempts","30");
		}
		$tmpNL->replace_setting("Time_on_ML",$_REQUEST["nl_time_on_ML"]);
		if($_REQUEST["nl_time_on_ML"] <2)
		{
		    $tmpNL->replace_setting("Time_on_ML","2");
		}
		if($_REQUEST["nl_time_on_ML"] >60)
		{
		    $tmpNL->replace_setting("Time_on_ML","60");
		}

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

		$tmpNL->replace_setting("Language",$_REQUEST["nl_language"]);
		$tmpNL->replace_setting("Max_no_of_eq_IP_Addr_on_PL","0");
		print "<b>$msg_nlMGT_create_success</b><br><br>";
		print "<a href=\"".$_SERVER['PHP_SELF']."?SelectNL=$ID&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=$_REQUEST["nl_name"];
	    $nl_email=$_REQUEST["nl_email"];
	    $nl_time_on_ML=$_REQUEST["nl_time_on_ML"];
	    $nl_time_on_PL=$_REQUEST["nl_time_on_PL"];
	    $nl_language=$_REQUEST["nl_language"];
	    $nl_max_confirmation_attempts=$_REQUEST["nl_max_confirmation_attempts"];
	    $Archive_enabled=$_REQUEST["Archive_enabled"];
	    $Archive_storetime=$_REQUEST["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=\"nl_name\" value=\"$nl_name\" size=\"20\"></td></tr>";
    print "<tr><td>$txt_nlMGT_create_Nl_email</td><td><input type=\"text\" name=\"nl_email\" size=\"20\" value=\"$nl_email\"></td></tr>";
    print "<tr><td>$txt_nlMGT_create_time_on_ML</td><td><select name=\"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=\"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=\"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=\"Archive_enabled\" value=\"yes\"";
    
    if($Archive_enabled =="yes")
    {
	print " checked ";
    }
    print "> | $txt_nlMGT_create_no <input type=\"radio\" name=\"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=\"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=\"nl_language\"><option value=\"0\">$txt_nlMGT_create_select</option";
    include "$path_to_protected/localisation/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 "</table><input type=\"hidden\" name=\"Suboption\" value=\"$Suboption\"><input type=\"hidden\" name=\"create_NL\" value=\"yes\"><input type=\"submit\" value=\"$txt_nlMGT_create_submit\"></form>";
    print "<br><br><br>";
    print "<a href=\"".$_SERVER['PHP_SELF']."?Suboption=NL_mgtm_index\">$txt_nlMGT_back_to_index</a><br>";
}

?> 
Return current item: ADbNewsSender