<?

include '../../config.php';
include '../../func.php';
head();

    $id = $_SESSION['panel_user'];
    $user = mysql_fetch_assoc(mysql_query("SELECT * FROM `profile` WHERE `id` = '".$id."'"));
    
if ( isset( $_POST['submit'] ) ) {
    

    
    $ban_id = $user['id'];
    $ban_date = time();
    $ban_moder = $id_session;
    $ban_prich = html($_POST['prich']);

    
    ########
    $ban_a = num($_POST['a']);
    $ban_b = num($_POST['b']);
    if ( $ban_b == 1 ) $ban_time = ( time() + ($ban_a * 60) );
    if ( $ban_b == 2 ) $ban_time = ( time() + ($ban_a * 60 * 60) );
    if ( $ban_b == 3 ) $ban_time = ( time() + ($ban_a * 60 * 60 * 24) );
    if ( $ban_b == 4 ) $ban_time = ( time() + ($ban_a * 60 * 60 * 24 * 30) );
    ########
    
    if ( empty($ban_prich) ) {
        
        echo link1 . 'Вы не указали причину' . div;
        navig();
        foot();
        exit();
        
    }
    
    if ( empty($ban_a) ) {
        
        echo link1 . 'Вы не указали время' . div;
        navig();
        foot();
        exit();
        
    }
    
        if ( empty($user['id']) ) {
        
        echo link1 . 'Пользователь не найден' . div;
        navig();
        foot();
        exit();
        
    }
    
    $result = mysql_query("INSERT INTO `ban` SET `ban_id` = '".$ban_id."', `ban_mod` = '".$id_session."', `ban_date` = '".$ban_date."', `ban_time` = '".$ban_time."', `ban_prich` = '".$ban_prich."'");
    
    if ( $result != NULL ) {
        
        echo link1 . 'Пользователь <b>'.$user['login'].'<b> забанен' . div;
        
        mysql_query("UPDATE `profile` SET `narush` = '".( $user['narush']+1 )."'WHERE `id` = '".$id."'");
        
    } else {
        
        echo link1 . 'Возникла ошибка' . div;
        
    }
}

echo link1 . 'Баним пользователя <b>'.$user['login'].'</b>' . div;
echo link2 . '<form action="ban.php" method="post" name="form">';
echo '<b>Причина:</b><br/> <input name="prich" type="text" maxlength="500"/><br/>';
echo '<b>Время:</b><br/> <input name="a" type="text" maxlength="15"/><br/>';
echo '<select name="b">
<option value="1">Минуты</option>
<option value="2">Часы</option>
<option value="3">Сутки</option>
<option value="4">Месяцы</option>
</select>';
echo '<input name="submit" type="submit" class="button" value="Банить" /></form></div>';
echo div;