<?php
/**
 * @package linea21.modules
 * @subpackage newsletter
 * @author Simon Georget <simon@linea21.com>
 * @version $id SVN
 * @access public
 * @license http://opensource.org/licenses/gpl-3.0.html
 */
session_start();

include_once('../config/define.php');

if (!$l21auth->isSuperAdmin()) ReloadIndex('admin');
////////////

include_once(override('../newsletter/'.SQL.'.inc.php'));
include_once('../class/class.newsletter.php');
include_once('../languages/' . U_L . '/lang_newsletter.' . CHARSET . '.php');


if(is_numeric($_REQUEST['id']) && is_string($_REQUEST['user_email'])) {

  // preparing data
  $emails_batch = array(0 => array('emailcol_id' => $user_id, 'emailcol_email' => $_REQUEST['user_email']));
  $doNotPublish = true; // needed to keep the newsletter with open status
  $newsletters = $sql_object->DBSelect(SQL_getoneCompleteNewsLetter($_REQUEST['id']));
  $newsletters[0]['newsletter_title'] .= ' (' .  _t('newsletter', 'test_add') . ')';
  
  if (count($newsletters) <= 1 && $newsletters[0] == false) {
    $status = 0;
    $o = _t('newsletter', 'sent_failed');
  }

  $newsletter_object = new newsletter;
  $path = $newsletter_object->URI_TEMPLATE;

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

  logfile(LOG_MAILING, array('[newsletter-start]', 'test mode', 'calling ' . __FILE__ ));
  require(override("../mail/template_newsletter.php"));
  logfile(LOG_MAILING, array('[newsletter-stop]'));
  $status = 1;
  $o = _t('newsletter', 'sent_successfully');
  
  /* Return json values */
  echo json_encode(array('status'=> $status,'msg'=> $o));
}
?>