<?

include './system/common.php'; 
include './system/functions.php';
include './system/user.php';
    
if(!$user) { 
header('location: /'); 
exit;}

$act = isset($_GET['act']) ? $_GET['act'] : null;
switch($act)
{
default: //Главнвя
$id = abs(intval($_GET['id']));
$ban = mysql_fetch_assoc(mysql_query("SELECT * FROM `ban` WHERE `user` = '".$id."'"));
if(isset($ban['user']))
{
  if($user['access'] < '1'){
     header("Location: /");
     $_SESSION['mes'] = mes('Произошла ошибка!');
     exit;   
}

}

 if(isset($_REQUEST['submit'])) { //Если нажимаем Да
$text = _string($_POST['text']);
$time = _string($_POST['time']);
    $users = mysql_query('SELECT * FROM `users` WHERE `id` = "'.$id.'"');
    $users = mysql_fetch_array($users);
    
  $count = mysql_result(mysql_query('SELECT COUNT(*) FROM `ban` WHERE `user` = "'.$users['id'].'"'),0);
  if($count == 0) {
      if(mb_strlen($text) < 3){
      header('Location: /ban/'.$id.'');
     $_SESSION['mes'] = mes('Вы не ввели причину!');
     exit;  }
  if($users['access'] >= $user['access']){
      header('Location: /ban/'.$id.'');
     $_SESSION['mes'] = mes('У вас недостаточно прав!');
     exit;  }
        
    mysql_query('INSERT INTO `ban` (`user`,
                                    `time`,
                                    `text`,
									`who`,
                                      `ip`) VALUES ("'.$users['id'].'",
               "'.(time() + $time).'",
			                                               "'.$text.'",
											        "'.$user['id'].'",
                                                    "'.$users['ip'].'")');


   
$_SESSION['mes'] = mes('Персонаж заблокирован');	
header('location: /ban/'.$id.'');
exit;
}else{
$_SESSION['mes'] = mes('Персонаж уже заблокирован');	
header('location: /ban/'.$id.'');
exit;
}

}
$title='Забанить';
include './system/h.php';
echo '<div class="title">'.$title.'</div>';

     echo' '.$_SESSION['mes'].'  ';
    $_SESSION['mes']=NULL; //Удаляем сесию
echo '<div class="empty_block item_center">Вы действительно хотите забаннить '.nick($id).' ? </div>
<div class="line"></div>
<div class="empty_block item_center">
<form action="/ban/'.$id.'" method="post">
Причина:<br/>
<textarea name="text" style="width: 70%;"> '.($to ? $_to['login'].', ':'').' </textarea><br/>

Время:<br/>
<select name="time"/>
<option value="3600"> 1 час </option> 
<option value="43200"> 12 час </option> 
<option value="604800"> 7 деней </option> 
<option value="2592000"> 1 месяц </option> 
<option value="99999999999"> Навсегда </option> 
</select/> 

<center><input class="button" type="submit" name="submit" value="Сохранить"/></center>
</form></div>
<div class="line"></div>
<div class="block_link"><a href="/ban/list/"><img src="/images/ico/png/black.png" alt="*"/> Все забаненные ('.mysql_result(mysql_query('SELECT COUNT(*) FROM `ban` WHERE `time` > "'.time().'"'),0).') </a></div>
<div class="line"></div>';
break;


case 'ban_list':
$title='Все забаненные';
include './system/h.php';
echo '<div class="title">'.$title.'</div>';
    
echo' '.$_SESSION['mes'].'  ';
$_SESSION['mes']=NULL; //Удаляем сесию
    
$max = 10;
$count = mysql_result(mysql_query('SELECT COUNT(*) FROM `ban` WHERE `time` > "'.time().'"'),0);
$pages = ceil($count/$max);
$page = _string(_num($_GET['page']));

if($page > $pages) {$page = $pages;}
if($page < 1) {$page = 1;}
$start = $page * $max - $max;


if($count > 0) {
$id = _string(_num($_GET['id']));

  if($id) { 
  $ban = mysql_query('SELECT * FROM `ban` WHERE `id` = "'.$id.'"');
  $ban = mysql_fetch_array($ban);
  
  if(!$ban) {
$_SESSION['mes'] = mes('Игрок не заблокирован!');	
header('location: /ban/list/?page='.$page);
exit;}
  


  if($_GET['delete'] == true) {
$_SESSION['mes'] = mes('С игрока снята блокировка!');	
mysql_query('DELETE FROM `ban` WHERE `id` = "'.$id.'"');
header('location: /ban/list/?page='.$page);
} 
  }



$q = mysql_query('SELECT * FROM `ban` WHERE `time` > "'.time().'" ORDER BY `id` DESC LIMIT '.$start.', '.$max.'');
while($row = mysql_fetch_array($q)) {

  $u = mysql_query('SELECT * FROM `users` WHERE `id` = "'.$row['user'].'"');
  $u = mysql_fetch_array($u);


echo'<div class="empty_block">
<span style="float: right;"> <a href="/ban/list/?id='.$row['id'].'&delete=true&page='.$page.'"> снять</a></span>
<a href="/user/'.$u['id'].'/">'.nick($u['id']).'</a>
  <br/>
  Причина: '.$row['text'].' </br>
  Осталось: '._time($row['time'] - time()).'
  </div><div class="line"></div>';
}

echo pages('/ban/list/?');
echo'<div class="line"></div>';
 
}else{
echo'<div class="empty_block item_center">
Нет забаненных игроков </div>
<div class="line"></div>';
}

break;


}
include './system/f.php';
?>