<?php
/**
 * @package linea21.modules
 * @subpackage newsletter
 * @author linea21 <info@linea21.com>
 * @version $id SVN
 * @access public
 * @license http://opensource.org/licenses/gpl-3.0.html
 */

/**
* LogMailing()
* 
* @param string $string 
* @return void 
*/
function LogMailing($string)
{
    $fp = @fopen(LOG_MAILING, 'a');
    @fwrite($fp, $string);
    @fwrite($fp, END_LINE);
    @fclose($fp);
} 

include_once('../config/define.php');
include_once('../config/server.php');
include_once('../class/class.newsletter.php');
include_once('../class/system/class.'.SQL.'.php');
include_once("../lib/lib_common.php");
include_once("../lib/functions_auth.php");
include_once(SQL . '.inc.php');

set_time_limit(0); // suppression du timeout

$sql_entity = SQL;
$sql_object = new $sql_entity;
$sql_object->DBInitialise();
$sql_object->DBConnexion();
// sélection des newsletters à envoyer
$newsletters = $sql_object->DBSelect(SQL_GetNewsletter2Send());
if (count($newsletters) <= 1 && $newsletters[0] == false) exit;

// récupération des emails
$emails_batch = $sql_object->DBSelect(SQL_GetEmails4Sending());

if (count($emails_batch) == 1 && $emails_batch[0] == false) exit;

$newsletter_object = new newsletter;

$path = $newsletter_object->URI_TEMPLATE;

// html
$template_html = file_get_contents($path . '.html');
// text
$template_txt = file_get_contents($path . '.txt');


$log_sep='##';

require("../mail/template_newsletter.php");


?>