<? 
if(isset($_GET['save']) && intval($_GET['write'])!=NULL && intval($_GET['write_time'])!=NULL && intval($_GET['level'])!=NULL){
////////

$write=intval($_GET['write']);
$write_time=intval($_GET['write_time']);
$levelu=intval($_GET['level']);
if ($_GET['write']==3)$timec=$time-intval($_GET['write_time'])*60*60*7;
if ($_GET['write']==2)$timec=$time-intval($_GET['write_time'])*60*60*24*30;
if ($_GET['write']==1)$timec=$time-intval($_GET['write_time'])*60*60*24*30*12;
$total = mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_user` WHERE `date_last` < '".$timec."' AND `level` = '".$levelu."' "), 0);


$q=mysql_query("SELECT * FROM `kolhoz_user` WHERE `date_last` < '".($timec)."' AND `level` = '".$levelu."'");
while($post=mysql_fetch_array($q)){

mysql_query("DELETE FROM `kolhoz_user` WHERE `id` = '$post[id]' LIMIT 1");
unlink("images/my_iconka/$post[id].jpg");
unlink("images/my_iconka/$post[id].gif");
unlink("images/my_iconka/$post[id].png");
unlink("images/avatars/$post[id].jpg");
unlink("images/avatars/$post[id].gif");
unlink("images/avatars/$post[id].png");
}
mysql_query("OPTIMIZE TABLE `kolhoz_user`");
$_SESSION['msg']="Успешно удалено ($total) шт.";
header("Location:/?admin=$admin");
}

if(isset($_GET['list'])){
echo "<div class='event'><h1><a href='/?admin=$admin'>Админка</a> / Просмотр на удаление</h1></div>";
echo '<div class="content"><div class="block">';
$write_time=intval($_GET['write_time']);
$write=intval($_GET['write']);
$levelu=intval($_GET['level']);
if ($_GET['write']==3)$timec=$time-intval($_GET['write_time'])*60*60*7;
if ($_GET['write']==2)$timec=$time-intval($_GET['write_time'])*60*60*24*30;
if ($_GET['write']==1)$timec=$time-intval($_GET['write_time'])*60*60*24*30*12;

$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_user` WHERE `date_last` < '".($timec)."' AND `level` = '".$levelu."'"),0);
if ($k_post==0)
{
echo "Список пуст...";
}
$k_page=k_page($k_post,15);
$page=page($k_page);
$start=15*$page-15;
$q=mysql_query("SELECT * FROM `kolhoz_user` WHERE `date_last` < '".($timec)."' AND `level` = '".$levelu."' ORDER BY `id` DESC LIMIT $start,15");

while ($post = mysql_fetch_assoc($q))
{
echo' '.on_k($post['id']).'';
echo"<a class='*' href='/user/$post[id]'>".($post['nick'])."</a></br>";
echo"".vremja($post['date_last'])."</br>";
}
if ($k_page>1)str("/?admin=$admin&list&write=$write&write_time=$write_time&",$k_page,$page); // Вывод страниц
echo"</div>";
include_once 'inc/foot.php';
}

if(isset($_POST['buy'])){
$write_time=intval($_POST['write_time']);
$write=intval($_POST['write']);
$levelu=intval($_POST['level']);
if ($_POST['write']==3)$timec=$time-intval($_POST['write_time'])*60*60*7;
if ($_POST['write']==2)$timec=$time-intval($_POST['write_time'])*60*60*24*30;
if ($_POST['write']==1)$timec=$time-intval($_POST['write_time'])*60*60*24*30*12;

if(isset($_POST['ok'])){
}else{

$total = mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_user` WHERE `date_last` < '".$timec."' AND `level` = '".$levelu."' "), 0);
echo "<div class='event'><h1><a href='/?admin=list'>Админка</a> / Подтверждение</h1></div>";
echo '<div class="content"><div class="block">';
echo"<li><span>Будет удалено </span>  <span>".($total)."</span> фермера</li></br>";


echo"<li><img alt='' width='16' height='16' src='/images/icons/action.png'> <a href='/?admin=$admin&list&write=$write&write_time=$write_time&level=$levelu'><span>Посмотреть ники</span></a></li></br>";
echo"<li><img alt='' width='16' height='16' src='/images/icons/tick.png'> <a href='/?admin=$admin&save&write=$write&write_time=$write_time&level=$levelu'><span>Да, подтверждаю</span></a></li>";
echo"<li><img alt='' width='16' height='16' src='/images/icons/cross.png'> <a href='/?admin=$admin'><span>Нет, отказываюсь</span></a></li></div>";
include_once 'inc/foot.php';exit;}}

echo "<div class='event'><h1><a href='?admin=list'>Админка</a> / $admin_name</h1></div>";
echo "<div class='content'><div class='block'>";

echo "<form method=\"post\" enctype='multipart/form-data'>\n";

echo"<li>Будут удалены пользователи, не посещавшие сайт:</li>";
echo "<li>Время</br><input name='write_time' type='text' maxlength='2' size='2' value=''></li>";
echo"<li><input type='radio' name='write' value='1' checked='checked'>Год. <input type='radio' name='write' value='2'>Мес. <input type='radio' name='write' value='3'>Сут.</br></br>";

echo "<li>Уровень</br><input name='level' type='text' maxlength='3' size='3' value=''></li>";
echo "<input value='Поехали' type='submit' name='buy' /></form></div>";

include_once 'inc/foot.php';
?>