<?php
if (!defined('ADMIN_FILE') || !is_admin_modul($aid, "Subscription")) die("Illegal File Access");
error_reporting(E_ALL);
function Subscription_Navi() {
	global $admin_file;
	GraphicAdmin();
	OpenTable();
    echo "<center><font class=\"title\"><b>Подписка и рассылка</b></font><br><br>"
	."[ <a href=".$admin_file.".php?op=Subscription_view>Формировать текст рассылки</a>"

	." ]</center>";
	CloseTable();
}

function Subscription_view() {
	global $prefix, $db, $multilingual, $admin_file;
    head();
    Subscription_Navi();

//	количество дат последних рассылок
	$kol_date = 5;
	$i = 0;
	$result = $db->sql_query("SELECT date FROM ".$prefix."_subscription_lastsend GROUP BY date ORDER BY date DESC LIMIT $kol_date");
	while ($row = $db->sql_fetchrow($result)) {
		$i++;
		$l_date_all[$i] = $row[date];
	}

// форматируем дату последней рассылки для отображения в календаре
	$l_date = explode("-", substr($l_date_all[1], 0, 10));
	$l_date[0] = intval($l_date[0]);
	$l_date[1] = intval($l_date[1]);
	$l_date[2] = intval($l_date[2]);
	
#	$result = $db->sql_query("SELECT p.pid, p.cid, p.title, p.active, c.cid, c.title FROM ".$prefix."_pages AS p LEFT JOIN ".$prefix."_pages_categories AS c ON (p.cid=c.cid) ORDER BY pid DESC LIMIT $offset, $storynum");
#    if ($db->sql_numrows($result) > 0) {
		OpenTable();

echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"0\" height=\"100%\" align=\"center\"><tr><td rowspan=\"4\">"; #общая структура

// массив месяцев
$month=array(1 => "января", "февраля", "марта", "апреля", "мая", "июня", "июля", "августа", "сентября", "октября", "ноября", "декабря");
// определение сегодняшнего числа
$e_date = getdate(time());

echo '
<form action="'.$admin_file.'.php?op=Subscription_StartSend" method="post" name="post" enctype="multipart/form-data" >
<table border="0" cellspacing="2" cellpadding="0" align="left">
	<tr>
		<td colspan="2"><font class="option">Включить в рассылку информацию:</font><br><i>при использовании bb-тегов сначала установи курсор в поле!</i><br><hr><br></td>
	</tr>

<tr><td><input type="checkbox" name="check_News" value="1" checked="checked"></td><td class="option">Новости</td></tr>
		<tr><td colspan="2">Информация администратора к разделу Новости<br><textarea id="area" name="desc_News" cols="65" rows="5" style="width:400px" OnKeyPress="TransliteFeld(this, event)" OnSelect="FieldName(this, this.name)" OnClick="FieldName(this, this.name)" OnKeyUp="FieldName(this, this.name)"></textarea>'.get_code("area").'<br>
			BB-код<input type="radio" name="radion" value="1" checked="checked">
			HTML-формат<input type="radio" name="radion" value="2"><br><br><hr><br></td></tr>

<tr><td><input type="checkbox" name="check_Files" value="1" checked="checked"></td><td class="option">Файлы</td></tr>
		<tr><td colspan="2">Информация администратора к разделу Файлы<br><textarea id="areaf" name="desc_Files" cols="65" rows="5" style="width:400px" OnKeyPress="TransliteFeld(this, event)" OnSelect="FieldName(this, this.name)" OnClick="FieldName(this, this.name)" OnKeyUp="FieldName(this, this.name)"></textarea>'.get_code("areaf").'<br>
			BB-код<input type="radio" name="radiof" value="1" checked="checked">
			HTML-формат<input type="radio" name="radiof" value="2"><br><br><hr><br></td></tr>

<tr><td><input type="checkbox" name="check_Pages" value="1" checked="checked"></td><td class="option">Публикации</td></tr>
		<tr><td colspan="2">Информация администратора к разделу Публикации<br><textarea id="areap" name="desc_Pages" cols="65" rows="5" style="width:400px" OnKeyPress="TransliteFeld(this, event)" OnSelect="FieldName(this, this.name)" OnClick="FieldName(this, this.name)" OnKeyUp="FieldName(this, this.name)"></textarea>'.get_code("areaf").'<br>
			BB-код<input type="radio" name="radiop" value="1" checked="checked">
			HTML-формат<input type="radio" name="radiop" value="2"><br><br></td></tr>

	</table>
</td><td rowspan="4"  bgcolor="#2666B9">&nbsp;</td><td  valign="top">"; 
<table border="0" cellspacing="2" cellpadding="0" align="left" >
	<tr>
		<td colspan="2"><font class="option" nowrap="nowrap">Выбрать интервал:</font><br><i>включительно</i></td>
	</tr>
		<tr>
		<td>от</td>
		<td valign="top" nowrap="nowrap"><select name="dd_1" size="1">';

for ($i=1; $i<=31; $i++) {
	if ($i==$l_date[2]) {
		$sel = " selected ";
	} else {
		$sel = "";
	}
	echo '<option value="'.$i.'"'.$sel.'>'.$i.'</option>';
}
										
 echo '</select><select name="mm_1" size="1">';

for ($i=1; $i<=12; $i++) {
	if ($i==$l_date[1]) {
		$sel = " selected ";
	} else {
		$sel = "";
	}
	echo '<option value="'.$i.'" '.$sel.'>'.$month[$i].'</option>';
}

	echo '</select><select name="yy_1" size="1">';

for ($i=2006; $i<=2012; $i++) {
	if ($i==$l_date[0]) {
		$sel = " selected ";
	} else {
		$sel = "";
	}
	echo '<option value="'.$i.'" '.$sel.'>'.$i.'</option>';
}

	echo '
			</select>
			</tr><tr><td>до</td><td nowrap="nowrap">
			<select name="dd_2" size="1">';

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

for ($i=1; $i<=31; $i++) {
	if ($i==$e_date[mday]) {
		$sel = " selected ";
	} else {
		$sel = "";
	}
		echo '<option value="'.$i.'" '.$sel.'>'.$i.'</option>';
}
									
 echo "
	</select><select name=\"mm_2\" size=\"1\">";

for ($i=1; $i<=12; $i++) {
	if ($i==$e_date[mon]) {
		$sel = " selected ";
	} else {
		$sel = "";
	}
	echo "<option value=\"$i\" $sel>".$month[$i]."</option>";
}

	echo "				
			</select><select name=\"yy_2\" size=\"1\">";
	
for ($i=2006; $i<=2012; $i++) {
	if ($i==$e_date[year]) {
		$sel = " selected ";
	} else {
		$sel = "";
	}
	echo "<option value=\"$i\" $sel>$i</option>";
}

	echo "
			</select></td>
	</tr>
</table>
";
			
echo "</td><td bgcolor=\"#2666B9\">&nbsp;</td><td  height=\"2px\" valign=\"top\">"; #общая структура

echo "<font class=\"option\">Даты последних<br>5-и рассылок:<br><hr></font>";

for ($i=1; $i<=$kol_date; $i++) {
echo "".formatTimestamp($l_date_all[$i])."<br>";
}

echo "</td></tr><tr>	<td colspan=\"3\">"; #общая структура

echo "<hr><br><font class=\"option\">HEADER письма:<br></font>
<textarea id=\"areahea\" name=\"desc_header\" cols=\"65\" rows=\"5\" style=\"width:400px\" OnKeyPress=\"TransliteFeld(this, event)\" OnSelect=\"FieldName(this, this.name)\" OnClick=\"FieldName(this, this.name)\" OnKeyUp=\"FieldName(this, this.name)\">"
."<i>Новостная рассылка сайта Понедельников НЕТ! (<a href=\"http://www.ponedelnikov.net\">http://www.ponedelnikov.net</a>) <br>от ".$e_date[mday].".".$e_date[mon].".".$e_date[year]."</i> <hr><br><b><font style=\"color: #FF5500;\">В этом выпуске...</font></b><br>"
		."</textarea>".get_code("areahea")."<br>
			BB-код<input type=\"radio\" name=\"radiohea\" value=\"1\">
			HTML-формат<input type=\"radio\" name=\"radionhea\" value=\"2\" checked=\"checked\"><br><br><hr><br>";

echo "</td></tr><tr>	<td colspan=\"3\">"; #общая структура

echo "<font class=\"option\">FOOTER письма:<br></font>
<textarea id=\"areafoo\" name=\"desc_footer\" cols=\"65\" rows=\"5\" style=\"width:400px\" OnKeyPress=\"TransliteFeld(this, event)\" OnSelect=\"FieldName(this, this.name)\" OnClick=\"FieldName(this, this.name)\" OnKeyUp=\"FieldName(this, this.name)\">"
."<i>С уважением,<br>администрация сайта «Понедельников НЕТ!»</i>"
		."</textarea>".get_code("areafoo")."<br>
			BB-код<input type=\"radio\" name=\"radiofoo\" value=\"1\">
			HTML-формат<input type=\"radio\" name=\"radionfoo\" value=\"2\" checked=\"checked\"><br><br><hr><br>";

echo "</td></tr><tr>	<td colspan=\"3\">"; #общая структура

echo "<font class=\"option\">Включить<br>";
echo "
	<input type=\"checkbox\" name=\"check_Sub\" value=\"1\" checked=\"checked\"> подписчиков<br>
	<input type=\"checkbox\" name=\"check_UserYes\" value=\"1\" checked=\"checked\"> пользователей, желающих получать рассылку<br>
	<input type=\"checkbox\" name=\"check_UserNo\" value=\"1\"> пользователей, не желающих получать рассылку<br>
	<input type=\"checkbox\" name=\"check_Admin\" value=\"1\"> администраторов<br>
";
echo "<br><input name=\"buttonName\" type=\"submit\" value=\"Начать рассылку\">";
echo "<br><br><br><br><br><br><br><br><br><br><br><br><br><br></font>";

echo "</td></tr></table>"; #общая структура
		CloseTable();
		echo "</form>";
#	}
	include("footer.php");
}

function Subscription_StartSend() {

	global $prefix, $db, $multilingual, $admin_file, $homeurl;
    include("header.php");
    Subscription_Navi();

	$date_start = "".intval($_POST['yy_1']);
	if (intval($_POST['mm_1']) < 10) {$date_start .= "-0".intval($_POST['mm_1']);} else {$date_start .= "-".intval($_POST['mm_1']);}
	if (intval($_POST['dd_1']) < 10) {$date_start .= "-0".intval($_POST['dd_1']);} else {$date_start .= "-".intval($_POST['dd_1']);}
	$date_start .= " 00:00:00";

	$date_stop = "".intval($_POST['yy_2']);
	if (intval($_POST['mm_2']) < 10) {$date_stop .= "-0".intval($_POST['mm_2']);} else {$date_stop .= "-".intval($_POST['mm_2']);}
	if (intval($_POST['dd_2']) < 10) {$date_stop .= "-0".intval($_POST['dd_2']);} else {$date_stop .= "-".intval($_POST['dd_2']);}
	$date_stop .= " 23:59:59";
	
	$result = $db->sql_query("SELECT id FROM ".$prefix."_subscription_lastsend WHERE date ='$date_stop' ");
	if ($db->sql_numrows($result) < 1) {
		$db->sql_query("INSERT INTO ".$prefix."_subscription_lastsend  VALUES ('', '$date_stop')");
	}

	/* =========== НОВОСТИ =========== */
	$content_news = "";
	if ($_POST['check_News']==1) {
		$result = $db->sql_query("SELECT sid, title, hometext, time FROM ".$prefix."_stories  WHERE time < '$date_stop' AND time >= '$date_start' ORDER BY time DESC ");
	    while ($row = $db->sql_fetchrow($result)) {
			$sid = intval($row['sid']);
		    $title = stripslashes(check_html($row['title'], "nohtml"));
			$content_news .= "".formatTimestamp($row['time'])." ";
			$content_news .= "<b><a href=\"".$homeurl."/index.php?name=News&op=article&sid=".$sid."\">$title</a></b><br>";
		    $text_news = stripslashes(strip_tags(bb_decode($row['hometext']), "<b><i><a>"));
			$content_news .= cutstr( $text_news, 175 )."<br><br>";
	    }
	}
	if ($_POST['radion'] == 1) {$content_news .= bb_decode($_POST['desc_News']);} else {$content_news .= $_POST['desc_News'];}

	/* =========== ФАЙЛЫ =========== */
	$content_files = "";
	if ($_POST['check_Files']==1) {
		$result = $db->sql_query("SELECT lid, title, description, date FROM ".$prefix."_files  WHERE date < '$date_stop' AND date >= '$date_start' ORDER BY date DESC ");
		while ($row = $db->sql_fetchrow($result)) {
		    $lid = intval($row['lid']);
		    $title = stripslashes(check_html($row['title'], "nohtml"));
			$content_files .= "".formatTimestamp($row['date'])." ";
			$content_files .= "<b><a href=\"$homeurl/index.php?name=Files&op=view_file&lid=$lid\">$title</a></b><br>";
		    $text_files = stripslashes(strip_tags(bb_decode($row['description']), "<b><i><a>"));
			$content_files .= cutstr( $text_files, 175 )."<br><br>";
	    }
	}
	if ($_POST['radiof'] == 1) {$content_files .= bb_decode($_POST['desc_Files']);} else {$content_files .= $_POST['desc_Files'];}

	/* =========== ПУБЛИКАЦИИ =========== */
	$content_pages = "";
	if ($_POST['check_Pages']==1) {
		$result = $db->sql_query("SELECT pid, title, hometext , date FROM ".$prefix."_pages  WHERE date < '$date_stop' AND date >= '$date_start' ORDER BY date DESC ");
		while ($row = $db->sql_fetchrow($result)) {
		    $pid = intval($row['pid']);
		    $title = stripslashes(check_html($row['title'], "nohtml"));
			$content_pages .= "".formatTimestamp($row['date'])." ";
			$content_pages .= "<b><a href=\"$homeurl/index.php?name=Pages&op=page&pid=$pid\">$title</a></b><br>";
		    $text_pages = stripslashes(strip_tags(bb_decode($row['hometext']), "<b><i><a>"));
			$content_pages .= cutstr( $text_pages, 175 )."<br><br>";
		}
	}
	if ($_POST['radiop'] == 1) {$content_pages .= bb_decode($_POST['desc_Pages']);} else {$content_pages .= $_POST['desc_pages'];}

	/* =========== HEADER =========== */
	if ($_POST['radiohea'] == 1) {$content_header .= bb_decode($_POST['desc_header']);} else {$content_header .= $_POST['desc_header'];}
	/* =========== FOOTER =========== */
	if ($_POST['radiofoo'] == 1) {$content_footer .= bb_decode($_POST['desc_footer']);} else {$content_footer .= $_POST['desc_footer'];}

/*================= ВЫВОД ============*/
OpenTable();
$content_header .= "";
if ($_POST['desc_News']!="" OR $_POST['check_News']==1) {$content_header .= "<br>Новости";}
if ($_POST['desc_Files']!="" OR $_POST['check_Files']==1) {$content_header .= "<br>Файлы";}
if ($_POST['desc_Pages']!="" OR $_POST['check_Pages']==1) {$content_header .= "<br>Публикации";}
$content_header .= "<br><hr><br>";

$content_mail = $content_header;
if ($_POST['desc_News']!="" OR $_POST['check_News']==1) {$content_mail .= "<font style=\" font-weight: bold; color: #FF5500;\">Новости</font><br><br>$content_news<br><hr><br>";}
if ($_POST['desc_Files']!="" OR $_POST['check_Files']==1) {$content_mail .= "<font style=\" font-weight: bold; color: #FF5500;\">Файлы</font><br><br>$content_files<br><hr><br>";}
if ($_POST['desc_Pages']!="" OR $_POST['check_Pages']==1) {$content_mail .= "<font style=\" font-weight: bold; color: #FF5500;\">Публикации</font><br><br>$content_pages<br><hr><br>";}
$content_mail .= "<br>".$content_footer."<br><br><hr align=\"left\" width=\"50\">";
echo "$content_mail";
CloseTable();

OpenTable();
echo "
	<form action=\"$admin_file.php?op=Subscription_DownSend\" method=\"post\" name=\"post\" enctype=\"multipart/form-data\">
	<input type=\"hidden\" name=\"check_Sub\" value=\"".$_POST['check_Sub']."\"><br>
	<input type=\"hidden\" name=\"check_UserYes\" value=\"".$_POST['check_UserYes']."\">
	<input type=\"hidden\" name=\"check_UserNo\" value=\"".$_POST['check_UserNo']."\">
	<input type=\"hidden\" name=\"check_Admin\" value=\"".$_POST['check_Admin']."\">

	<input type=\"hidden\" name=\"stop1\" value=\"1\">
	<input type=\"hidden\" name=\"subid1\" value=\"0\">

	<input type=\"hidden\" name=\"stop2\" value=\"1\">
	<input type=\"hidden\" name=\"subid2\" value=\"0\">

	<input type=\"hidden\" name=\"stop3\" value=\"1\">
	<input type=\"hidden\" name=\"subid3\" value=\"0\">

	<input type=\"hidden\" name=\"stop4\" value=\"1\">
	<input type=\"hidden\" name=\"subid4\" value=\"0\">
	
	сервисная информация:<br>
	<textarea name=\"content_mail\" rows=\"5\" style=\"width:400px\">$content_mail</textarea><br><br><br>
	<input name=\"buttonName\" type=\"submit\" value=\"Продолжить рассылку\">
	</form>
";
CloseTable();
	include("footer.php");

}

function Subscription_DownSend() 
{
global $prefix, $db, $multilingual, $admin_file, $homeurl,  $start_time, $adminmail, $sitename;
include("header.php");
Subscription_Navi();

OpenTable();
echo "
	<form action=\"$admin_file.php?op=Subscription_DownSend\" method=\"post\" name=\"post\" enctype=\"multipart/form-data\">
	<input type=\"hidden\" name=\"check_Sub\" value=\"".$_POST['check_Sub']."\"><br>
	<input type=\"hidden\" name=\"check_UserYes\" value=\"".$_POST['check_UserYes']."\">
	<input type=\"hidden\" name=\"check_UserNo\" value=\"".$_POST['check_UserNo']."\">
	<input type=\"hidden\" name=\"check_Admin\" value=\"".$_POST['check_Admin']."\">
";

/*================ Подписчикам =====================*/
if ( $_POST['stop1'] !="0" AND $_POST['check_Sub']) {
	$_POST['subid1'] = intval ($_POST['subid1']);
	$result = $db->sql_query("SELECT subid, username, email, pass FROM ".$prefix."_subscription WHERE active='1' AND subid > '".$_POST['subid1']."' ORDER BY subid ASC ");
	while (list($subid, $username, $email, $pass) = $db->sql_fetchrow($result)) {

echo "шаг1: $subid, $username, $email, $pass, ".$_POST['subid1']." <br>";

/*$tt = time();$tt = $tt+1;$f = 0;
while ($f!=1) {$ttt = time(); if ($ttt > $tt) {$f = 1;}}*/

echo "
	<input type=\"hidden\" name=\"stop1\" value=\"1\">
	<input type=\"hidden\" name=\"subid1\" value=\"$subid\">
";
		$subject = "$sitename - Подписка на новости";
		$content = $_POST['content_mail']."<br>Отписаться от рассылки можно перейдя по ссылке<br><a href=\"$homeurl/index.php?name=Subscription&op=Subscription_Stop&email=$sender_email&pass=$tmp_pass\">$homeurl/index.php?name=Subscription&op=Subscription_Stop&email=$email&pass=$pass</a><br>";
		$mailheaders = "Content-Type: text/html; charset=windows-1251\n";
		$mailheaders .= "X-Sender: <$adminmail>\n";
		$mailheaders .= "X-Priority: 3\n";
		$mailheaders .= "From: $adminmail <$adminmail>\n";
		$mailheaders .= "Reply-To: $adminmail\n\n";
        mail($email, $subject, $content, $mailheaders);

$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$end_time = $mtime;
$total_time = ($end_time - $start_time);
$total_time_db = $db->total_time_db;
$total_time = $total_time + $total_time_db;
if ($total_time > 20) {echo "
	сервисная информация:<br>
	<textarea name=\"content_mail\" rows=\"5\" style=\"width:400px\">".$_POST['content_mail']."</textarea><br><br><br>
	<input name=\"buttonName\" type=\"submit\" value=\"Продолжить рассылку\">
	</form>
	"; 
	include("footer.php"); break;
	}

echo "
	<input type=\"hidden\" name=\"stop1\" value=\"0\">
";

	}
}
/*================ Конец Подписчикам =====================*/

echo "<br>";
echo "<pre>";
print_r($_POST);
echo "</pre>";

/*================ Пользователям желающим =====================*/
if ( $_POST['stop2'] !="0" AND $_POST['check_UserYes']) {
	$_POST['subid2'] = intval ($_POST['subid2']);
	$result = $db->sql_query("SELECT user_id, user_name, user_email FROM ".$prefix."_users WHERE user_newsletter = '1' AND user_id > '".$_POST['subid2']."' ORDER BY user_id ASC ");
	while (list($subid, $username, $email) = $db->sql_fetchrow($result)) {

echo "шаг2: $subid, $username, $email, ".$_POST['subid2']." <br>";

/*$tt = time();$tt = $tt+1;$f = 0;
while ($f!=1) {$ttt = time(); if ($ttt > $tt) {$f = 1;}}*/

echo "
	<input type=\"hidden\" name=\"stop2\" value=\"1\">
	<input type=\"hidden\" name=\"subid2\" value=\"$subid\">
";
		$subject = "$sitename - Подписка на новости";
		$content = $_POST['content_mail']."<br>Отписаться от рассылки можно в личных настройках, авторизовавшись пользователем <br><a href=\"$homeurl/index.php?name=Account\">$homeurl/index.php?name=Account</a><br>";
		$mailheaders = "Content-Type: text/html; charset=windows-1251\n";
		$mailheaders .= "X-Sender: <$adminmail>\n";
		$mailheaders .= "X-Priority: 3\n";
		$mailheaders .= "From: $adminmail <$adminmail>\n";
		$mailheaders .= "Reply-To: $adminmail\n\n";
        mail($email, $subject, $content, $mailheaders);

$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$end_time = $mtime;
$total_time = ($end_time - $start_time);
$total_time_db = $db->total_time_db;
$total_time = $total_time + $total_time_db;
if ($total_time > 20) {echo "
	сервисная информация:<br>
	<textarea name=\"content_mail\" rows=\"5\" style=\"width:400px\">".$_POST['content_mail']."</textarea><br><br><br>
	<input name=\"buttonName\" type=\"submit\" value=\"Продолжить рассылку\">
	</form>
	"; 
	include("footer.php"); break;
	}

echo "
	<input type=\"hidden\" name=\"stop2\" value=\"0\">
";

	}
}
/*================ Конец Пользователям желающим =====================*/
echo "<br>";
/*================  Пользователям НЕ желающим =====================*/
if ( $_POST['stop3'] !="0" AND $_POST['check_UserNo']) {
	$_POST['subid3'] = intval ($_POST['subid3']);
	$result = $db->sql_query("SELECT user_id, user_name, user_email FROM ".$prefix."_users WHERE user_newsletter = '0' AND user_id > '".$_POST['subid3']."' ORDER BY user_id ASC ");
	while (list($subid, $username, $email) = $db->sql_fetchrow($result)) {

echo "шаг3: $subid, $username, $email, ".$_POST['subid3']." <br>";

/*$tt = time();$tt = $tt+1;$f = 0;
while ($f!=1) {$ttt = time(); if ($ttt > $tt) {$f = 1;}}*/

echo "
	<input type=\"hidden\" name=\"stop3\" value=\"1\">
	<input type=\"hidden\" name=\"subid3\" value=\"$subid\">
";
		$subject = "$sitename - Сообщение сайта";
		$content = $_POST['content_mail']."<br>";
		$mailheaders = "Content-Type: text/html; charset=windows-1251\n";
		$mailheaders .= "X-Sender: <$adminmail>\n";
		$mailheaders .= "X-Priority: 3\n";
		$mailheaders .= "From: $adminmail <$adminmail>\n";
		$mailheaders .= "Reply-To: $adminmail\n\n";
        mail($email, $subject, $content, $mailheaders);

$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$end_time = $mtime;
$total_time = ($end_time - $start_time);
$total_time_db = $db->total_time_db;
$total_time = $total_time + $total_time_db;
if ($total_time > 20) {echo "
	сервисная информация:<br>
	<textarea name=\"content_mail\" rows=\"5\" style=\"width:400px\">".$_POST['content_mail']."</textarea><br><br><br>
	<input name=\"buttonName\" type=\"submit\" value=\"Продолжить рассылку\">
	</form>
	"; 
	include("footer.php"); break;
	}

echo "
	<input type=\"hidden\" name=\"stop3\" value=\"0\">
";

	}
}
/*================ Конец Пользователям НЕ желающим =====================*/
echo "<br>";

/*================  Администраторам =====================*/
if ( $_POST['stop4'] !="0" AND $_POST['check_Admin']) {
	$_POST['subid4'] = intval ($_POST['subid4']);
	$result = $db->sql_query("SELECT id, name, email FROM ".$prefix."_admins WHERE id > '".$_POST['subid4']."' ORDER BY id ASC ");
	while (list($subid, $username, $email) = $db->sql_fetchrow($result)) {

echo "шаг4: $subid, $username, $email, ".$_POST['subid4']." <br>";

/*$tt = time();$tt = $tt+1;$f = 0;
while ($f!=1) {$ttt = time(); if ($ttt > $tt) {$f = 1;}}*/

echo "
	<input type=\"hidden\" name=\"stop4\" value=\"1\">
	<input type=\"hidden\" name=\"subid4\" value=\"$subid\">
";
		$subject = "$sitename - Сообщение для администраторов";
		$content = $_POST['content_mail']."<br>";
		$mailheaders = "Content-Type: text/html; charset=windows-1251\n";
		$mailheaders .= "X-Sender: <$adminmail>\n";
		$mailheaders .= "X-Priority: 3\n";
		$mailheaders .= "From: $adminmail <$adminmail>\n";
		$mailheaders .= "Reply-To: $adminmail\n\n";
        mail($email, $subject, $content, $mailheaders);

$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$end_time = $mtime;
$total_time = ($end_time - $start_time);
$total_time_db = $db->total_time_db;
$total_time = $total_time + $total_time_db;
if ($total_time > 20) {echo "
	сервисная информация:<br>
	<textarea name=\"content_mail\" rows=\"5\" style=\"width:400px\">".$_POST['content_mail']."</textarea><br><br><br>
	<input name=\"buttonName\" type=\"submit\" value=\"Продолжить рассылку\">
	</form>
	"; 
	include("footer.php"); break;
	}

echo "
	<input type=\"hidden\" name=\"stop4\" value=\"0\">
";

	}
}
/*================ Администраторам =====================*/
echo "<br>";
echo "
	АЛЕС!
	<input type=\"hidden\" name=\"stop1\" value=\"0\">
	<input type=\"hidden\" name=\"stop2\" value=\"0\">
	<input type=\"hidden\" name=\"stop3\" value=\"0\">
	<input type=\"hidden\" name=\"stop4\" value=\"0\">
	сервисная информация:<br>
	<textarea name=\"content_mail\" rows=\"5\" style=\"width:400px\">".$_POST['content_mail']."</textarea><br><br><br>
	<input name=\"buttonName\" type=\"submit\" value=\"Продолжить рассылку\">
	</form>
";

CloseTable();

include("footer.php");
}

switch ($op) {

	case "Subscription_DownSend":
	Subscription_DownSend();
	break;

	case "Subscription_StartSend":
	Subscription_StartSend();
	break;

	case "Subscription_view":
    Subscription_view();
    break;

}
?>