<?
include_once '../sys/inc/start.php';

include_once '../sys/inc/compress.php';

include_once '../sys/inc/sess.php';

include_once '../sys/inc/home.php';

include_once '../sys/inc/settings.php';

include_once '../sys/inc/db_connect.php';

include_once '../sys/inc/ipua.php';

include_once '../sys/inc/fnc.php';

include_once '../sys/inc/user.php';

only_level(1);

if (isset($_GET['id']))$ank['id']=intval($_GET['id']);

else {header("Location: /index.php?".SID);exit;}

if (mysql_result(mysql_query("SELECT COUNT(*) FROM `user` WHERE `id` = '$ank[id]' LIMIT 1"),0)==0){header("Location: /index.php?".SID);exit;}

$ank=mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = $ank[id] LIMIT 1"));

if ($user['level']<=$ank['level'] || $user['id']==$ank['id']){header("Location: /index.php?".SID);exit;}

$set['title']='Бан пользователя '.$ank['nick'];

include_once '../sys/inc/thead.php';

title();

if (isset($_GET['unset']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `ban` WHERE `id_user` = '$ank[id]' AND `id` = '".intval($_GET['unset'])."'"),0) && isset($access['ban_unset']))

{

$ban_info=mysql_fetch_array(mysql_query("SELECT * FROM `ban` WHERE `id_user` = '$ank[id]' AND `id` = '".intval($_GET['unset'])."'"));

$ank2=mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = '$ban_info[id_ban]' LIMIT 1"));

if (($user['level']>$ank2['level'] || $user['id']==$ank2['id']) || $user['level']==4)

{

mysql_query("UPDATE `ban` SET `time` = '$time' WHERE `id` = '".intval($_GET['unset'])."' LIMIT 1");

msg('Время бана обнулено');

}

else

$err[]='Нет прав';

}

if (isset($_POST['ban_pr']) && isset($_POST['time']) && isset($_POST['vremja']) && isset($access['ban_set']))

{
$timeban=$time;

if ($_POST['vremja']=='min')$timeban+=intval($_POST['time'])*60;

if ($_POST['vremja']=='chas')$timeban+=intval($_POST['time'])*60*60;

if ($_POST['vremja']=='sut')$timeban+=intval($_POST['time'])*60*60*24;

if ($_POST['vremja']=='mes')$timeban+=intval($_POST['time'])*60*60*24*30;

if ($timeban<$time)$err[]='Ошибка времени бана';

$prich=$_POST['ban_pr'];

if (strlen2($prich)>1024){$err[]='Сообщение слишком длинное';}

if (strlen2($prich)<10){$err[]='Необходимо подробнее указать причину';}

$prich=mysql_real_escape_string($prich);

if (!isset($err)){

mysql_query("INSERT INTO `ban` (`id_user`, `id_ban`, `prich`, `time`) VALUES ('$ank[id]', '$user[id]', '$prich', '$timeban')");

msg('Пользователь успешно забанен');

}

}

err();

aut();

$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `ban` WHERE `id_user` = '$ank[id]'"),0);

$k_page=k_page($k_post,$set['p_str']);

$page=page($k_page);

$start=$set['p_str']*$page-$set['p_str'];

if ($k_post==0)

{

echo "Нет нарушений\n";

}

$q=mysql_query("SELECT * FROM `ban` WHERE `id_user` = '$ank[id]' ORDER BY `time` DESC LIMIT $start, $set[p_str]");

while ($post = mysql_fetch_array($q))

{

$ank2=mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = $post[id_ban] LIMIT 1"));

echo "<div class='news'>";

echo "".online($ank2['id'])." <a href='/info.php?id=$ank2[id]'>$ank2[nick]</a> до ".vremja($post['time'])."</div>";

echo"Причина: ";

echo esc(trim(br(bbcode(smiles(links(stripcslashes(htmlspecialchars($post['prich']))))))))."<br />\n";

if ($post['time']>$time && (isset($access['ban_unset']) && ($user['level']>$ank2['level'] || $user['id']==$ank2['id']) || $user['level']==4))

echo "<a href='?id=$ank[id]&amp;unset=$post[id]'>Снять бан</a><br />\n";

}

if ($k_page>1)str('?id='.$ank['id'].'&amp;',$k_page,$page); // Вывод страниц

if (isset($access['ban_set'])){

echo "<form action=\"ban.php?id=$ank[id]\" method=\"post\">\n";

echo "Причина:<br />\n";

echo "<textarea name=\"ban_pr\"></textarea><br />\n";

echo "Время бана:<br />\n<input type=\"text\" name=\"time\" title=\"Время бана\" value=\"10\" maxlength=\"11\" size='3' />\n";

echo "<select class=\"form\" name=\"vremja\">\n";

echo "<option value=\"min\">Минуты</option>\n";

echo "<option ".(($k_post>1)?'selected="selected" ':null)."value=\"chas\">Часы</option>\n";

echo "<option value=\"sut\">Сутки</option>\n";

echo "<option value=\"mes\">Месяцы</option>\n";

echo "</select><br />\n";

echo "<input type=\"submit\" value=\"Забанить\" />";

echo "</form>\n";

}

else

{

echo "<div class='err'>Нет прав для того, чтобы забанить пользователя</div>\n";

}

echo "<div class='news'>\n";

echo "&raquo; <a href=\"/mail.php?id=$ank[id]\">Написать сообщение</a><br />\n";

echo "&laquo; <a href=\"/info.php?id=$ank[id]\">В анкету</a><br />\n";

echo "</div>\n";

include_once '../sys/inc/tfoot.php';

?>