<?php
require_once '../core/system.php';
require_once '../core/func_time.php';
echo Moder();
$header = 'Управление банами';
require_once H.'core/head.php';

switch($_GET['action']){
default:

$k_post = mysql_result(mysql_query("SELECT COUNT(*)  FROM `us_ban`"),0);
$k_page = k_page($k_post,$set['p_str']);
$page = page($k_page);
$start = $set['p_str']*$page-$set['p_str'];
$q = mysql_query("SELECT * FROM `us_ban` ORDER BY `id` DESC LIMIT $start, $set[p_str]");
if($k_post == 0)echo "<div class='player grey'>Пока нет банов!</div>";
while($post = mysql_fetch_assoc($q)) {

if($post['type']=='common'){
$type='забанен на общение';
}elseif($post['type']=='all')
{
$type='забанен на все';
}elseif($post['type']=='support'){
$type='забанен на службу поддержки';
}elseif($post['type'] == 'game'){
$type = 'заблокирован';
}
if($post['time'] > time()){
$sts='<font color="green">Активен</font> [<a href="?action=ban_deactive&id='.$post['id'].'">Разбанить</a>]';
}else{
$sts='<font color="red">Не активен</font>';
}

$ank= mysql_fetch_assoc(mysql_query("SELECT * FROM `user` WHERE `id` = $post[usban] LIMIT 1"));
$us= mysql_fetch_assoc(mysql_query("SELECT * FROM `user` WHERE `id` = $post[usid] LIMIT 1"));
echo ' <b>Игрок  <a href="/user/'.$us['id'].'/"> '.$us['nick'].'</a> <span class="red"> '.$type.' <br><div class="dot-line"></div>';
if($post['time'] > time()){
echo'До конца осталось:</span> '.sec2time($post['time'] - time()).'';
}else{echo'<span class="green">Бан закончился</span>';}
echo'<br/><div class="dot-line"></div><span class="blue">Заблокировал:<a href="/user/'.$ank['id'].'/"><img src="/images/icon/user.png"/>'.$ank['nick'].' </span></a><br/>
<div class="dot-line"></div><span class="blue">Причина: </span>'.htmlspecialchars($post['prich']).'</br><span class="blue">Бан:</span> '.$sts.' 
</b><div class="line"></div>';
}
if ($k_page>1)str('?',$k_page,$page); // Вывод страниц
break;

case 'ban':

if (isset($_GET['id']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `user` WHERE `id` = '$get_id'"),0) == true){
$ank = mysql_fetch_assoc(mysql_query("SELECT * FROM `user` WHERE `id`  = '$get_id'"));
}else{
$_SESSION['err'] = "Игрок не найден";
header('Location: /moder_tools/ban');
exit();
}
if(empty($_POST[text])){
$back_page = num($_GET['page']);
if (isset($_GET['msg_place']) == 'forum') {
$msg_id_back = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_comm` WHERE `id`  = '".intval($_GET['msg_id'])."'"));
$back_id = $msg_id_back[id_topic];
$back_un = '/topic?id='.$back_id.'&page='.$back_page.'';
$back = check($back_un);
$back_text = 'топик';
}Elseif (isset($_GET['msg_place']) == 'chat') {
$back_id = $msg_id_back[id_topic];
$back_un = '/chat?page='.$back_page.'';
$back = check($back_un);
$back_text = 'чат';
}
If (isset($_GET['msg_id']) && isset($_GET['msg_place'])) {
echo '
<div class="player menuList">
<li><a href="'.$back.'">Назад в '.$back_text.'</a></li>
</div>
<div class="mini-line"></div>';
}
echo '<form action="ban?action=do_ban&id='.$ank['id'].'" method="post">';
echo"ID игрока:<br/>
<input class='text large' type=\"text\" size=\"10\" value=\"$_GET[id]\" name=\"id\"/><br/>";
If (isset($_GET['msg_id']) && isset($_GET['msg_place'])) {
Echo"Местонахождение сообщения:
<input class='text large' type=\"text\" size=\"10\" value=\"$_GET[msg_place]\" name=\"msg_place\"/><br /><span>forum - Форум<br />chat - Чат</span><br/>
";

echo"ID сообщения:
<input class='text large' type=\"text\" size=\"10\" value=\"$_GET[msg_id]\" name=\"msg_id\"/><br/>
";
echo"<input type=\"hidden\" name=\"page\" value=\"$get_page\" />";
}

echo 'Время бана:<br/>
<input class="text large" type="text" size="10" name="time"/>';
Echo "<select name=\"time_type\">
<option value=\"minute\">Минуты</option>
<option value=\"hour\">Часы</option>
<option value=\"day\">Дни</option>
<option value=\"month\">Месяцы (30 дней)</option>
<option value=\"year\">Годы (365 дней)</option>
</select><br/>";

echo 'Причина бана:<br/>
<input class="text large" type="text" size="10" name="text"/>';

/*echo "Тип бана:<br/>
<select name=\"type\">
<option value=\"common\">На общение</option>
<option value=\"all\">На все</option>
<option value=\"support\">На Службу Поддержки</option>
</select><br/>";
*/
echo '<input class="button" style="width:30%;"  type="submit" value="Забанить" /></form>';
echo '<div class="mini-line"></div>';
If (isset($_GET['msg_id']) && isset($_GET['msg_place'])) {
echo '<div class="player menuList">
<li><a href="'.$back.'">Назад в '.$back_text.'</a></li>
</div>';
}
}
break;

case 'do_ban':
if (empty($_POST['text'])) {
$_SESSION['err'] = 'Вы не ввели причину';
header ("Location: ban");
exit();
}
$req = mysql_query("SELECT * FROM `user` where `id`='".mysql_real_escape_string($_POST[id])."'");
$avto=mysql_num_rows($req);
if($avto==0){echo"Нет такого игрока!";
require_once H.'core/foot.php';
exit;}
if (isset($_POST['msg_place']) == forum && isset($_POST['page'])) {
$topic_msg = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_comm` WHERE `id`  = '".intval($_POST['msg_id'])."'"));
}elseif (isset($_POST['msg_place']) == chat && isset($_POST['page'])) {
$chat_msg = mysql_fetch_assoc(mysql_query("SELECT * FROM `chat` WHERE `id`  = '".intval($_POST['msg_id'])."'"));
}
If (isset($_POST['msg_place'])) {
$msg_place = check($_POST['msg_place']);
}Else{
$msg_place = '0';
}
If (isset($_POST['msg_id'])) {
$msg_id = check($_POST['msg_id']);
}Else{
$msg_id = '0';
}
If (isset($_POST['msg_id']) && isset($_POST['msg_place'])) {
$ban_on_msg = '1';
$ban_msg_query = "UPDATE `forum_comm` SET `ban_msg` = '1' WHERE `id` = '".intval($_POST[msg_id])."'";
}Else{
$ban_on_msg = '0';
}
/*
if($_POST[type]==common){$_POST[type]=common;}
if($_POST[type]==support){$_POST[type]=support;}

$req1 = mysql_query("SELECT * FROM `us_ban` where `usid`='".mysql_real_escape_string($_POST[id])."' and `type`='$_POST[type]' and `time`>'".time()."'");
$avto=mysql_num_rows($req1);
if($avto==1){echo"Этот игрок уже забанен по этому типу бана";
require_once H.'core/foot.php';
exit;}
*/
$time_banned = time();
$time_ban = $time_banned;
if ($_POST['time_type'] == 'minute') {
$time_ban+=intval($_POST[time])*60;
}
if ($_POST['time_type'] == 'hour') {
$time_ban+=intval($_POST[time])*60*60;
}
if ($_POST['time_type'] == 'day') {
$time_ban+=$_POST[time]*60*60*24;
}
if ($_POST['time_type'] == 'month') {
$time_ban+=intval($_POST[time])*60*60*24*30;
}
if ($_POST['time_type'] == 'year') {
$time_ban+=intval($_POST[time])*60*60*24*30*365;
}
mysql_query("INSERT INTO
`us_ban` SET
`usid` = '".abs(intval($_POST[id]))."',
`usban` = '".$user['id']."',
`prich` = '".mysql_real_escape_string(htmlspecialchars($_POST[text]))."',
`time` = '$time_ban',
`time_banned` = '$time_banned',
`type` = 'common',
`ban_on_msg` = '$ban_on_msg',
`msg_id` = '$msg_id',
`msg_place` = '$msg_place'");
$now_ban = mysql_fetch_assoc(mysql_query("SELECT * FROM `us_ban` WHERE `time_banned`  = '$time_banned'"));
$banner_moder = mysql_fetch_assoc(mysql_query("SELECT * FROM `user` WHERE `id`  = '".intval($now_ban['usban'])."'"));
$now_ban_time = $now_ban['time']-time();
mysql_query("INSERT INTO
`mail` SET
`id_kont` = '".intval($now_ban['usid'])."',
`id_user` = '$system_profile_id',
`time` = '$time_banned',
`msg` = 'Вы были забанены модератором [url=user/".$banner_moder['id']."/]".$banner_moder['nick']."[/url] по причине \"".$now_ban[prich]."\".\n Осталось: ".sec2time($now_ban['time'] - time())."',
`read` = '1'");
// $system_profile_id находится в
// /core/function/control_variables.php
mysql_query("INSERT INTO
`users_konts` SET
`id_kont` = '$now_ban[usid]',
`id_user` = '$system_profile_id',
`time` = '$now_ban[time_banned]'");
mysql_query("INSERT INTO
`users_konts` SET
`id_kont` = '$system_profile_id',
`id_user` = '$now_ban[usid]',
`time` = '".intval($now_ban['time_banned'])."'");
mysql_query("UPDATE `users_konts` SET `new_msg` = '1' WHERE `id_kont` = '$system_profile_id' AND `id_user` = '".intval($now_ban['usid'])."'");
mysql_query($ban_msg_query);
if (!isset($_POST['page'])){
Header("Location: ban");
$_SESSION['message'] = 'Игрок '.$_POST[nick].' забанен!';
exit();
}If (isset($topic_msg)) {
$_SESSION['message'] = 'Игрок забанен!';
header("Location: /topic?id=$topic_msg[id_topic]&page=$_POST[page]");
exit();
}Elseif (isset($chat_msg)) {
$_SESSION['message'] = 'Игрок забанен!';
header("Location: /chat?page=$_POST[page]");
exit();
}
break;

case 'ban_deactive':
mysql_query("UPDATE`us_ban`SET`time`='0' WHERE`id`='".mysql_real_escape_string($_GET['id'])."'");
header('location: ban');
$_SESSION['message'] = 'Бан аннулирован';
exit();
break;
case 'block':

if (isset($_GET['id']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `user` WHERE `id` = '$get_id'"),0) == true){
$ank = mysql_fetch_assoc(mysql_query("SELECT * FROM `user` WHERE `id`  = '$get_id'"));
}else{
$_SESSION['err'] = "Игрок не найден";
header('Location: /moder_tools/ban');
exit();
}
if(empty($_POST[text])){
echo '<form action="ban?action=do_block&id='.$ank['id'].'" method="post">';
echo"ID игрока:<br/>
<input class='text large' type=\"text\" size=\"10\" value=\"$get_id\" name=\"id\"/><br/>";
echo 'Время блока:<br/>
<input class="text large" type="text" size="10" name="time"/>';
Echo "<select name=\"time_type\">
<option value=\"minute\">Минуты</option>
<option value=\"hour\">Часы</option>
<option value=\"day\">Дни</option>
<option value=\"month\">Месяцы (30 дней)</option>
<option value=\"year\">Годы (365 дней)</option>
</select><br/>";

echo 'Причина:<br/>
<input class="text large" type="text" size="10" name="text"/>';

/*echo "Тип бана:<br/>
<select name=\"type\">
<option value=\"common\">На общение</option>
<option value=\"all\">На все</option>
<option value=\"support\">На Службу Поддержки</option>
</select><br/>";
*/
echo '<input class="button" style="width:30%;"  type="submit" value="Забанить" /></form>';
echo '<div class="mini-line"></div>';
}
break;

case 'do_block':
if (empty($_POST['text'])) {
$_SESSION['err'] = 'Вы не ввели причину';
header ("Location: ban");
exit();
}
$req = mysql_query("SELECT * FROM `user` where `id`='".mysql_real_escape_string($_POST[id])."'");
$avto=mysql_num_rows($req);
if($avto==0){echo"Нет такого игрока!";
require_once H.'core/foot.php';
exit;}
$time_banned = time();
if ($_POST['time_type'] == minute) {
$time=intval($_POST[time])*60;
}
if ($_POST['time_type'] == hour) {
$time=intval($_POST[time])*60*60;
}
if ($_POST['time_type'] == day) {
$time=intval($_POST[time])*60*60*24;
}
if ($_POST['time_type'] == month) {
$time=intval($_POST[time])*60*60*24*30;
}
if ($_POST['time_type'] == year) {
$time=intval($_POST[time])*60*60*24*30*365;
}

$time_ban=time()+$time;
mysql_query("INSERT INTO
`us_ban` SET
`usid` = '".abs(intval($_POST[id]))."',
`usban` = '".$user['id']."',
`prich` = '".mysql_real_escape_string(htmlspecialchars($_POST[text]))."',
`time` = '".abs(intval($time_ban))."',
`time_banned` = '$time_banned',
`type` = 'game'");
$now_ban = mysql_fetch_assoc(mysql_query("SELECT * FROM `us_ban` WHERE `time_banned`  = '$time_banned'"));
$banner_moder = mysql_fetch_assoc(mysql_query("SELECT * FROM `user` WHERE `id`  = '".intval($now_ban['usban'])."'"));
$now_ban_time = $now_ban['time']-time();
mysql_query("INSERT INTO
`mail` SET
`id_kont` = '".intval($now_ban['usid'])."',
`id_user` = '$system_profile_id',
`time` = '$time_banned',
`msg` = 'Ваш аккаунт был заблокирован по причине \"".$now_ban[prich]."\".\n Заблокировал: [url=user/".$banner_moder['id']."/]".$banner_moder['nick']."[/url]\n Осталось: ".bansec2time($now_ban['time'] - time())."',
`read` = '1'");
// $system_profile_id находится в
// /core/function/control_variables.php
mysql_query("INSERT INTO
`users_konts` SET
`id_kont` = '".intval($now_ban['usid'])."',
`id_user` = '$system_profile_id',
`time` = '".intval($now_ban['time_banned'])."'");
mysql_query("INSERT INTO
`users_konts` SET
`id_kont` = '$system_profile_id',
`id_user` = '".intval($now_ban['usid'])."',
`time` = '".intval($now_ban['time_banned'])."'");
mysql_query("UPDATE `users_konts` SET `new_msg` = '1' WHERE `id_kont` = '$system_profile_id' AND `id_user` = '".intval($now_ban['usid'])."'");
break;

}
require_once H.'core/foot.php';
?>