Location: PHPKode > projects > ADbNewsSender > ADbNewsSender 2.1.0/protected/admin/nl/import.php.inc
<?php
//Copyright (c) Florian Grannemann
//Last change in version: 2.1.0
/*******************************************************************************
    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/
    ******************************************************************************
*/

//loadling language file:
include "$path_to_languagefolder/lang_admin_import.php.inc";
if($MySessionHandler->getNLID()!=0 && $MyCFG->NL_exists($MySessionHandler->getNLID()))
{
    
    //mudule variables:
    $NLID=$MySessionHandler->getNLID();
    //maximum web upload size in byte:
    //default 2621440 (2.5 MB)
    $max_upload_size="2621440";

   
  
    if(intval($MyRequestHandler->getNLModuleKeyValue("step")) <1 || intval($MyRequestHandler->getNLModuleKeyValue("step")) >1)
    {
	$defaultstyleWebUpload="";
	$defaultStautusWebUpload="";
	$defaultStautusSelectedWebUpload="selected";
	$defaultstyleFTPUpload="style=\"visibility:hidden\"";
	$defaultStautusFTPUpload="disabled";
	$defaultStautusSelectedFTPUpload="";
		

	if($MyRequestHandler->getNLModuleKeyValue("refreshftpfiles") =="yes"){
	    $defaultstyleWebUpload="style=\"visibility:hidden\"";
	    $defaultStautusWebUpload="disabled";
	    $defaultStautusSelectedWebUpload="";
	    $defaultstyleFTPUpload="";
	    $defaultStautusFTPUpload="";
	    $defaultStautusSelectedFTPUpload="selected";
	}
	print "<h2>$MSG_import_options</h2>";
	print "<form onSubmit=\"UploadMSG('".$MSG_importing."','".$MSG_Uploading."')\" enctype=\"multipart/form-data\" name=\"importform\" action=\"".$_SERVER["PHP_SELF"]."\" method=\"post\" >";
	
	
	//Upload method
	print "$MSG_import_Method: <select name=\"".$MyRequestHandler->getNLModuleKeyName("upload_method")."\" onChange=\"switch_file_select()\">";
	print "<option id=\"web\" value=\"web\" $defaultStautusSelectedWebUpload>$MSG_import_Method_web</option>";
	print "<option id=\"ftp\" value=\"ftp\" $defaultStautusSelectedFTPUpload>$MSG_import_Method_ftp</option>";
	print "</select><br>";
  

	print $MSG_import_select_file;

	//ftp upload
	print " <select id=\"ftpuploadform\" name=\"".$MyRequestHandler->getNLModuleKeyName("selected_file_ftp")."\"  ".$defaultstyleFTPUpload." ".$defaultStautusFTPUpload.">";
	$dir=$path_to_protected."/import";
	$folder = opendir ( $dir );
	while ( $file = readdir ( $folder ) )
	{
	    if($file !=".." && $file !=".")
	    {
		print "<option value=\"$file\">$file</option>";
	    } 

	}
	print "</select>";
	print " <input type=button id=\"refreshftpfiles\" ".$defaultstyleFTPUpload." onClick=\"window.location.href='".$_SERVER["PHP_SELF"]."?".$MyRequestHandler->getNLModuleKeyName("refreshftpfiles")."=yes&".$MyRequestHandler->getNLModuleKeyName("step")."=0'\" value=\"$MSG_import_refreshFTPFiles\"><br>";
	
	//web upload

	print "<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"$max_upload_size\" $defaultStautusWebUpload >";

	print "<input type=\"file\" id=\"webuploadform\" name=\"".$MyRequestHandler->getNLModuleKeyName("selected_file_web")."\" ".$defaultstyleWebUpload." ".$defaultStautusWebUpload."><br>";
	

	print "<input type=\"hidden\" name=\"".$MyRequestHandler->getNLModuleKeyName("step")."\" value=\"1\">";


	print "<br>$MSG_import_Seperator: </td><td><select name=\"".$MyRequestHandler->getNLModuleKeyName("seperator")."\"><option value=\"1\">$MSG_import_Sep_sem</option>";
	print "<option value=\"2\">$MSG_import_Sep_com</option>";
	print "<option value=\"3\">$MSG_import_Sep_newl</option>";
	print "</select>";


	
	print " <input id=\"submit\" type=\"submit\" value=\"$MSG_submit\" >";
	print "</form>";

    
    }
    else
    {
	
	$error="";
	
	//overview
	if($MyRequestHandler->getNLModuleKeyValue("upload_method")=="web")
	{	//web upload
	    if($_FILES[$MyRequestHandler->getNLModuleKeyName("selected_file_web")]['error'])
	    {
		$error=$ERR_Upload_failed;
	    }
	    else
	    {
		$importfile=$_FILES[$MyRequestHandler->getNLModuleKeyName("selected_file_web")]["tmp_name"]; 
		$filesize=$_FILES[$MyRequestHandler->getNLModuleKeyName("selected_file_web")]["size"];    

	    }
	    
	}
	else
	{    //select file from ftp-directory
	    if(!file_exists($path_to_protected."/import/".$MyRequestHandler->getNLModuleKeyValue("selected_file_ftp")) || !$MyRequestHandler->getNLModuleKeyValue("selected_file_ftp"))
	    {
		    $error=$ERR_File_does_not_exist;
	    }
	    else
	    {
		$importfile=$path_to_protected."/import/".$MyRequestHandler->getNLModuleKeyValue("selected_file_ftp");
		$filesize=filesize($importfile);
	    }
	}
	
	if(!file_exists($path_to_protected."/localization/lang/".$MyNL->get_NLconfig_setting("Language")."/import_confirmationmail.php.inc"))
	{
	    
	    if(file_exists($path_to_languagefolder."/import_confirmationmail.php.inc"))
	    {
		$confirmationmail=$path_to_languagefolder."/import_confirmationmail.php.inc";
		    
	    }
	    else
	    {
		$error=$error."<br>".$ERR_confmail_does_not_exist;	    
	    }
	}
	else
	{
	    $confirmationmail=$path_to_protected."/localization/lang/".$MyNL->get_NLconfig_setting("Language")."/import_confirmationmail.php.inc";
	}

	if($error)
	{
	    print "<h2>$MSG_Errors</h2>";
	    print $error."<br><br>";
		

	}
	else
	{
	    print "<h2>$MSG_summary</h2>";
	    

	    if(intval($MyRequestHandler->getNLModuleKeyValue("seperator")) <2)
	    {
		$seperator=";";
	    }
	    if(intval($MyRequestHandler->getNLModuleKeyValue("seperator")) ==2)
	    {
		$seperator=",";
	    }
		
	    if(intval($MyRequestHandler->getNLModuleKeyValue("seperator")) >2)
	    {
		$seperator="\n";
	    }
	    print "<br>";

	    //starting the import
	    
	    $fp = fopen($importfile, 'rb');
	    $AddressList = fread($fp, $filesize);
	    fclose($fp); 
	    
	    $AddressList=preg_replace("/\r/","",$AddressList);
	    $AddressARR=explode($seperator,$AddressList);
		
	    //counter of successfull imports:
	    $count_success=0;
	    //counter of failed imports:
	    $count_failed=0;
	    
	    //array for invalid addresses:
	    $invalid_arr=array();
		
	    //array for existing addresses:
	    $exists_arr=array();
	    
	    //starting:
	    $i=0;
	    $addr_counter=0;
	    while($i <count($AddressARR))
	    {
		    
		$AddressARR[$i]=preg_replace("/\n/","",$AddressARR[$i]);
		$AddressARR[$i]=preg_replace("/ /","",$AddressARR[$i]);
		if(!$AddressARR[$i])
		{
		    $i++;
		    continue;
		}
		$result=$MyNL->add_to_PL($AddressARR[$i], $i, $confirmationmail);
		$addr_counter++;
		if($result >0)
		{
		    $count_success++;
		}
		else
		{
			    
		    $count_failed++;
		    if($result <(-2) || $result == 0)
		    {	//e-mail address is invalid
			$invalid_arr[count($invalid_arr)]=$AddressARR[$i];
		    }
		    else
		    { 	//e-mail address is already on ml or pl
			$exists_arr[count($exists_arr)]=$AddressARR[$i];
		    }
			
		}

		$i++;
	    }
	    
	    //printing results:
	    print "$MSG_Addresses_total ".$addr_counter."<br>";
	    print "$MSG_imported  $count_success<br><br>";
	    print "$MSG_not_imported $count_failed<br><br>";
		
	    print "$MSG_invalid<br>";

	    if(count($invalid_arr) >0)
	    {
		$i=0;
		//printing invalid addresses:
		while($i <count($invalid_arr))
		{
		    print $invalid_arr[$i];
		    if($i < (count($invalid_arr)-1))
		    {
			print ", ";
		    }
			
		    $i++;
		}
		print "<br><br>";
	    }
	    else
	    {
		print $MSG_none."<br><br>";
	    }

		
	    print "$MSG_existing <br>";

	    if(count($exists_arr) >0)
	    {
		$i=0;
		//printing invalid addresses:
		while($i <count($exists_arr))
		{
		    print $exists_arr[$i];
		    if($i < (count($exists_arr)-1))
		    {
			print ", ";
		    }
			
		    $i++;
		}
	    }
	    else
	    {
		print $MSG_none."<br>";
	    }
	    if($MySessionHandler->getNLModuleKeyValue("upload_method")=="web")
	    {
		if(file_exists($importfile))
		{
		    @unlink($importfile);
		}
	    }
	}
	print "<br><br><a href=\"".$_SERVER["PHP_SELF"]."\">$MSG_back</a>";
    }
}
else
{
    print $ErrorNLdoesnotExist;
}
?>
Return current item: ADbNewsSender