<?php
include_once "../../tools/inc.php";
$page = include("../common.php");
include("../tools/function.string.php");
include("../tools/function.sql.php");
include("../tools/class.send.php");
$status=0;
$max=100;
$n=$settings["rec_count"];
$table="newsletters".$config["table_prefix"];
$table_s="subscribers".$config["table_prefix"];
$table_sg="subscribers_group".$config["table_prefix"];
$table_g="mailing_groups".$config["table_prefix"];
$access=check_level("Newsletters");

if (isset($access["view"]) or isset($access["admin"])) {
	$sql="select * from $table where id='$id' and status='$status'";
	list($data)=$db->select($sql);
	if (isset($l) and isset($data['id'])) {
		$sql="select s.id from
			$table_s s,
			$table_sg sg,
			$table_g g
		where
			s.status='".$data["recipients"]."' and
			s.id=sg.subscribers_id and
			sg.group_id=g.id and
			g.enabled=1 and
			g.id in (".$data["groups"].")
		group by s.id
		limit ".($l*$max).", ".$max;
		$sth=$db->execute($sql);
		$e=new msg('msg_newsletters'.$config["table_prefix"]);
		while ($rs=$db->get_row($sth)) {
			$r=array(
				'subscriber_id'	=> $rs['id'],
				'newsletter_id'	=> $id,
			);
			$e->add($r);
		}
	}
}
print $PATH.'newsletters/?send_all='.$id.'&step=1';
$db->close();
exit;
?>