Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Help me please..


Alexandero

Recommended Posts

Hi,

 

Can anyone please modify this contibution so that it will be able to export all the emails in the database regardless of he is subscribed to newsletter or not.. I really appreciate your help.. any other suggestion will be welcome..

 
<?php 
########################INSTALL #################################################
# This little hack gives you the possibility to export your customers's email addresses  list in a SYLK format readable by Excel
# I use it to upload the file in  an other newsletter script than the admin one which is not powerfull enough for my needs
# This script only select email addresses from customers who subscribe to the newsletter

# 1 . fill with your database data the lines 23-24-25-26
# 2 . upload this file in the admin directory
# 3 . in admin/includes/boxes/tools.php add  '<a href="' . tep_href_link('mail_export.php', '', 'NONSSL') . '" class="menuBoxContentLink" target="_blank">Email Export</a><br>'.
# 4 . That's it !
################################################################################
###

define ( "FORMAT_REEL" ,	1 ); // #,##0.00 
define ( "FORMAT_ENTIER" , 2 ); // #,##0 
define ( "FORMAT_TEXTE" ,   3 ); // @ 

$cfg_formats [ FORMAT_ENTIER ] = "FF0"; 
$cfg_formats [ FORMAT_REEL ]   = "FF2"; 
$cfg_formats [ FORMAT_TEXTE ]  = "FG0"; 

// ---------------------------------------------------------------------------- 

$cfg_hote = 'localhost'; 
$cfg_user = 'username'; 
$cfg_pass = 'password'; 
$cfg_base = 'basename'; 

// ---------------------------------------------------------------------------- 

if ( mysql_connect ( $cfg_hote , $cfg_user , $cfg_pass )) 
{ 
 // ------------------------------------------------------------------------ 
$sql   = "SELECT  customers_email_address "; 
$sql .= "FROM customers where customers_newsletter = '1'  "; 
$sql .= "ORDER BY customers_email_address"; 

 // ------------------------------------------------------------------------ 
$champs = Array( 
Array( 'customers_email_address' ,	'Email' ,	FORMAT_TEXTE ,   'L' ,		 30 ) 

 ); 
// ------------------------------------------------------------------------ 


if ( $resultat = mysql_db_query ( $cfg_base , $sql )) 
 { 
//  HTTP HEADER
	 // -------------------------------------------------------------------- 
header ( 'Content-disposition: filename=file.slk' ); 
header ( 'Content-type: application/octetstream' ); 
header ( 'Pragma: no-cache' ); 
header ( 'Expires: 0' ); 

	 // -------------------------------------------------------------------- 
echo "ID;PASTUCES-phpInfo.net\n"; 
echo "\n"; 
echo "P;PGeneral\n";	   
	 echo "P;P#,##0.00\n";		
echo "P;P#,##0\n";		   
echo "P;P@\n";			 
echo "\n"; 
// polices 
echo "P;EArial;M200\n"; 
	 echo "P;EArial;M200\n"; 
	 echo "P;EArial;M200\n"; 
	 echo "P;FArial;M200;SB\n"; 
	 echo "\n"; 
//
echo "B;Y" .( mysql_num_rows ( $resultat )+ 1 ); 
	 echo ";X" .( $nbcol = mysql_num_fields ( $resultat )). "\n"; 
	 echo "\n"; 

	 // -------------------------------------------------------------------- 
for ( $cpt = 0; $cpt < $nbcol; $cpt ++) 
	 { 
$num_format [ $cpt ] = $champs [ $cpt ][ 2 ]; 
$format [ $cpt ] = $cfg_formats [ $num_format [ $cpt ]]. $champs [ $cpt ][ 3 ]; 
	 } 

	 // -------------------------------------------------------------------- 
for ( $cpt = 1; $cpt <= $nbcol; $cpt ++) 
	 { 
echo "F;W" . $cpt . " " . $cpt . " " . $champs [ $cpt - 1 ][ 4 ]. "\n"; 
	 } 
	 echo "F;W" . $cpt . " 256 8\n"; 
echo "\n"; 

	 // -------------------------------------------------------------------- 
for ( $cpt = 1; $cpt <= $nbcol; $cpt ++) 
	 { 
		 echo "F;SDM4;FG0C;" .( $cpt == 1 ? "Y1;" : "" ). "X" . $cpt . "\n"; 
		 echo "C;N;K\"" . $champs [ $cpt - 1 ][ 1 ]. "\"\n"; 
	 } 
	 echo "\n"; 

	 // -------------------------------------------------------------------- 
$ligne = 2; 
	 while ( $enr = mysql_fetch_array ( $resultat )) 
	 { 
for ( $cpt = 0; $cpt < $nbcol; $cpt ++) 
		 { 
// format 
echo "F;P" . $num_format [ $cpt ]. ";" . $format [ $cpt ]; 
			 echo ( $cpt == 0 ? ";Y" . $ligne : "" ). ";X" .( $cpt + 1 ). "\n"; 
// values 
if ( $num_format [ $cpt ] == FORMAT_TEXTE ) 
				 echo "C;N;K\"" . str_replace ( ';' , ';;' , $enr [ $cpt ]). "\"\n"; 
			 else 
				 echo "C;N;K" . $enr [ $cpt ]. "\n"; 
		 } 
		 echo "\n"; 
$ligne ++; 
	 } 

// EOF 
	 // -------------------------------------------------------------------- 
echo "E\n"; 
 } 

mysql_close (); 
} 

?>

Link to comment
Share on other sites

Hi again, I found this code right now, i think it is more easy to modify to do the job:

$filename="addresses.txt";  //.txt is good for import into excel workbook as tab delimited file

// end of configuration!
require('includes/application_top.php');  // gives us SOME security anyway
require_once('includes/configure.php');  // gives us osC database info

header('Content-Type: text/x-csv');
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');

if ( mysql_connect ( DB_SERVER , DB_SERVER_USERNAME , DB_SERVER_PASSWORD )) { 

$sql   = "SELECT  customers_firstname, customers_lastname, customers_email_address "; 

$sql .= "FROM customers WHERE customers_newsletter = '1'";

$result = mysql_db_query ( DB_DATABASE , $sql );

echo "email\tFirst Name\tLast Name\n";

while ( $row = mysql_fetch_array($result)) {

	if ($row[customers_email_address]) {

		echo "$row[customers_email_address]\t$row[customers_firstname]\t$row[customers_lastname]\n";
	}

} 
} 
mysql_close (); 
?>

Link to comment
Share on other sites

Here ya go...

 

<?php
########################INSTALL #################################################
# This little hack gives you the possibility to export your customers's email addresses  list in a SYLK format readable by Excel
# I use it to upload the file in  an other newsletter script than the admin one which is not powerfull enough for my needs

# 1 . fill with your database data the lines 23-24-25-26
# 2 . upload this file in the admin directory
# 3 . in admin/includes/boxes/tools.php add  '<a href="' . tep_href_link('mail_export.php', '', 'NONSSL') . '" class="menuBoxContentLink" target="_blank">Email Export</a><br>'.
# 4 . That's it !
################################################################################
###

define ( "FORMAT_REEL" ,    1 ); // #,##0.00
define ( "FORMAT_ENTIER" , 2 ); // #,##0
define ( "FORMAT_TEXTE" ,   3 ); // @

$cfg_formats [ FORMAT_ENTIER ] = "FF0";
$cfg_formats [ FORMAT_REEL ]   = "FF2";
$cfg_formats [ FORMAT_TEXTE ]  = "FG0";

// ----------------------------------------------------------------------------

$cfg_hote = 'localhost';
$cfg_user = 'username';
$cfg_pass = 'password';
$cfg_base = 'basename';

// ----------------------------------------------------------------------------

if ( mysql_connect ( $cfg_hote , $cfg_user , $cfg_pass ))
{
    // ------------------------------------------------------------------------
$sql   = "SELECT  customers_email_address ";
$sql .= "FROM ";
$sql .= "ORDER BY customers_email_address";

    // ------------------------------------------------------------------------
$champs = Array(
Array( 'customers_email_address' ,    'Email' ,    FORMAT_TEXTE ,   'L' ,         30 )

    );
// ------------------------------------------------------------------------


if ( $resultat = mysql_db_query ( $cfg_base , $sql ))
    {
//  HTTP HEADER
        // --------------------------------------------------------------------
header ( 'Content-disposition: filename=file.slk' );
header ( 'Content-type: application/octetstream' );
header ( 'Pragma: no-cache' );
header ( 'Expires: 0' );

        // --------------------------------------------------------------------
echo "ID;PASTUCES-phpInfo.net\n";
echo "\n";
echo "P;PGeneral\n";      
        echo "P;P#,##0.00\n";        
echo "P;P#,##0\n";          
echo "P;P@\n";            
echo "\n";
// polices
echo "P;EArial;M200\n";
        echo "P;EArial;M200\n";
        echo "P;EArial;M200\n";
        echo "P;FArial;M200;SB\n";
        echo "\n";
//
echo "B;Y" .( mysql_num_rows ( $resultat )+ 1 );
        echo ";X" .( $nbcol = mysql_num_fields ( $resultat )). "\n";
        echo "\n";

        // --------------------------------------------------------------------
for ( $cpt = 0; $cpt < $nbcol; $cpt ++)
        {
$num_format [ $cpt ] = $champs [ $cpt ][ 2 ];
$format [ $cpt ] = $cfg_formats [ $num_format [ $cpt ]]. $champs [ $cpt ][ 3 ];
        }

        // --------------------------------------------------------------------
for ( $cpt = 1; $cpt <= $nbcol; $cpt ++)
        {
echo "F;W" . $cpt . " " . $cpt . " " . $champs [ $cpt - 1 ][ 4 ]. "\n";
        }
        echo "F;W" . $cpt . " 256 8\n";
echo "\n";

        // --------------------------------------------------------------------
for ( $cpt = 1; $cpt <= $nbcol; $cpt ++)
        {
            echo "F;SDM4;FG0C;" .( $cpt == 1 ? "Y1;" : "" ). "X" . $cpt . "\n";
            echo "C;N;K\"" . $champs [ $cpt - 1 ][ 1 ]. "\"\n";
        }
        echo "\n";

        // --------------------------------------------------------------------
$ligne = 2;
        while ( $enr = mysql_fetch_array ( $resultat ))
        {
for ( $cpt = 0; $cpt < $nbcol; $cpt ++)
            {
// format
echo "F;P" . $num_format [ $cpt ]. ";" . $format [ $cpt ];
                echo ( $cpt == 0 ? ";Y" . $ligne : "" ). ";X" .( $cpt + 1 ). "\n";
// values
if ( $num_format [ $cpt ] == FORMAT_TEXTE )
                    echo "C;N;K\"" . str_replace ( ';' , ';;' , $enr [ $cpt ]). "\"\n";
                else
                    echo "C;N;K" . $enr [ $cpt ]. "\n";
            }
            echo "\n";
$ligne ++;
        }

// EOF
        // --------------------------------------------------------------------
echo "E\n";
    }

mysql_close ();
}

?>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...