<?
$NETCAT_FOLDER = join(strstr(__FILE__, "/") ? "/" : "\\", array_slice(preg_split("/[\/\\\]+/", __FILE__), 0, -4)) . (strstr(__FILE__, "/") ? "/" : "\\");
include_once($NETCAT_FOLDER . "vars.inc.php");
require($INCLUDE_FOLDER . "index.php");

$nc_core = nc_core::get_object();


$dashamail = new DashaMail();
$connection_test = $dashamail->test_connection();

if (!$connection_test) {
  die();
}

$bases_list = $dashamail->get_bases_list();

$autoimport = $nc_core->get_settings('autoimport', 'notice');
$autoimport_base_id = $nc_core->get_settings('autoimport_base_id', 'notice');
if ($autoimport and $autoimport_base_id) {

  //
  //  Получаем список подписчиков
  //

  $subscribers_list = $db->get_results("SELECT base_id, email, merge_1, merge_2, merge_3, merge_4, merge_5 FROM Module_Dashamail_Subscribers");
  //
  //  Экспорт данных при отправки формы
  //
  var_dump($subscribers_list);

  $export_data = array();

  if (count($subscribers_list))
    foreach ($subscribers_list as $subscribers_list_row) {
      $export_data[] = array(
        "email" => $subscribers_list_row->email,
        "merge_1" => $subscribers_list_row->merge_1,
        "merge_2" => $subscribers_list_row->merge_2,
        "merge_3" => $subscribers_list_row->merge_3,
        "merge_4" => $subscribers_list_row->merge_4,
        "merge_5" => $subscribers_list_row->merge_5
      );
    }

  $result_text = array($dashamail->export_data($export_data, $autoimport_base_id));
}
