Location: PHPKode > projects > ADbNewsSender > ADbNewsSender 2.1.0/protected/admin/nl/export.php.inc
<?php
//Copyright (c) Florian Grannemann
//Last change in version: 2.1 Alpha 4
/*
    ******************************************************************************
    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/
    ******************************************************************************
*/
//You can adapt the texts to your needs.
// But NEVER CHANGE variable-names, like <-Variable-> or $variable. 
// If you do that, it may interfear with the Script's functionality!
// If you want to set "-Characters please use \" (\"text\" instead of "text"). 


//loadling language file:
include "$path_to_languagefolder/lang_admin_export.php.inc";

if($MySessionHandler->getNLID()!=0 && $MyCFG->NL_exists($MySessionHandler->getNLID()))
{
    //mudule variables:
    $NLID=$MySessionHandler->getNLID();

    if(intval($MyRequestHandler->getNLModuleKeyValue("step")) ==0)
    {
	print "<h2>$MSG_export_options</h2>";
	print "<form action=\"".$_SERVER["PHP_SELF"]."\" method=\"post\" >";
	print "<input type=\"hidden\" name=\"".$MyRequestHandler->getNLModuleKeyName("step")."\" value=\"1\">";
	print "<table border=0>";
	print "<tr><td>$MSG_export_Seperator:</td><td><select name=\"".$MyRequestHandler->getNLModuleKeyName("seperator")."\"><option value=\"1\">$MSG_export_Sep_sem</option>";
	print "<option value=\"2\">$MSG_export_Sep_com</option>";
	print "<option value=\"3\">$MSG_export_Sep_newl</option>";

	print "</select></td></tr>";
	print "<tr><td>$MSG_entries_per_file:</td><td><input name=\"".$MyRequestHandler->getNLModuleKeyName("entries_per_file")."\" type=\"text\" value=\"1000\"></td></tr>";

	print " </table><br>";

    
	print "<br><input id=\"submit\" type=\"submit\" value=\"$MSG_submit\" >";
	print "</form>";
	    
    
    }
    else
    {
	//validate input
	$error="";
	
	$entries_per_file=intval($MyRequestHandler->getNLModuleKeyValue("entries_per_file"));

	//validating $entries_per_file:
	if($entries_per_file<1){
	    $entries_per_file=1;
	}
	//is the seperator valid?
	$seperator=intval($MyRequestHandler->getNLModuleKeyValue("seperator"));
	if($seperator <1 || $seperator >3 )
	{
	    $error=$error.$ERR_invalid_seperator;
	}
	if($seperator==1)
	{
	    $sep=";";
	}
	if($seperator==2)
	{
	    $sep=",";
	}
	if($seperator==3)
	{
	    $sep="\n";
	}    
    //has an error occured?
	if($error)
	{ //yes:
	    print "<b>".$MSG_Errors."</b><br>";
	    print $error."<br>";
	}
	else
	{    //if not:
	    //preparing to export:

	    if($seperator==1)
	    {
		$sep=";";
	    }
	    if($seperator==2)
	    {
		$sep=",";
	    }
	    if($seperator==3)
	    {
		$sep="\n";
	    }   
	    if($entries_per_file <1)
	    {
		$entries_per_file =1;
	    }
	    $NL_Name=$MyNL->get_NLconfig_setting("NL_name");
	
	    
	    $number_of_entries=$MyNL->number_of_ML_entries();
    
	    $number_of_files=intval($number_of_entries/$entries_per_file);
	    if($number_of_entries%$entries_per_file !=0)
	    {
		$number_of_files++;
	    }
	
	    $current_file_nr=1;
	    $current_date=date("y-m-d");
	    $startNr=0;
	    print "<h3>".$MSG_exporting_now."</h3>";
	    
	    while($startNr <$number_of_entries )
	    {
		$file=$path_to_protected."/export/".$NL_Name."_".$current_date."_".$current_file_nr."_".$number_of_files.".txt";
		
		//retreiving addresses
		   
		if($MyDB->connect())
		{
		    //fetching addresses:
		    $result=$MyDB->query("Select email from ADBNS2_Mailinglist_".$NLID." LIMIT $startNr, $entries_per_file ");
		
	    
		    $MyDB->disconnect();

	    
		
		    $addr=$MyDB->fetch_row($result);
		    $addresses=$addr[0];
		    while($addr=$MyDB->fetch_row($result))
		    {
			$addresses=$addresses.$sep.$addr[0];
		    
		    }
		    $handle = @fopen($file, "w");
		    $file=preg_replace("/admin\/\.\.\//","",$file);
		    //export addresses:
		    print preg_replace("/<-filename->/",$file,$MSG_exporting_file);
		    if (!@fwrite($handle, $addresses)) 
		    {
			// failed:
			print " ".$ERR_failed_to_write."<br>";
		    }
		    else
		    {
			//success:
		    print " ".$MSG_done."<br>";
			
		    }
		    @fclose($handle);
		    @chmod($file, 0666);
		}
		else
		{
		    print preg_replace("/<-filename->/",$file,$ERR_DB_connection_failed);
		}

		$startNr=$startNr+$entries_per_file;
		$current_file_nr++;
	    
	    
	    }   
	    print "<br>".$NOTE_Please_Delete."<br><br>";
	}
	print "<a href=\"".$_SERVER["PHP_SELF"]."\">".$MSG_back."</a>";
    }
}
else{
	print $ErrorNLdoesnotExist;

}
?>
Return current item: ADbNewsSender