<?

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

$all = mysql_result(mysql_query("SELECT count(*) FROM `profile` WHERE `vip` > '".time()."'"), 0);

echo link1 . 'VIP Пользователи / Всего: <b>'.$all.'</b> пользователей' . div;

switch ($_GET['act']) {
    default:
    if ($_GET['result'] == 'vip_off') $result = 'VIP режим успешно выключен';
    if ($_GET['result'] == 'vip_on') $result = 'VIP режим успешно активирован';
    if ($_GET['result'] == 'vip_error') $result = 'Возникла ошибка';
    
    if ($result) echo link1 . $result . div;
     
    $result = mysql_query("SELECT * FROM `profile` WHERE `vip` > '".time()."'");
    while($user = mysql_fetch_assoc($result)){
        echo link2 . "<a href=\"../../".$user['id']."\">".$user['login']."</a> [<a href=\"vip.php?act=off&id=".$user['id']."\">Выкл. режим</a>]" . div;
    }
    
    echo link1 . '<a href="vip.php?act=add">Вкл. VIP</a>' . div;
    break;
    
    case 'off':
    $id = num($_GET['id']);
    $user = mysql_fetch_assoc(mysql_query("SELECT * FROM `profile` WHERE `id` = '".$id."'"));
    if (empty($user)) $err = 'Пользователь не найден';
    if ($user['vip'] < time()) $err = 'У пользователя не активирован VIP режим';
    
    if (isset($err))
        echo link1 . 'Ошибка, ' .$err . div;
        
    else {
        if (mysql_query("UPDATE `profile` SET `vip` = '".time()."'WHERE `id` = '".$id."'"))
            header('Location: vip.php?result=vip_off');
        else
            header('Location: vip.php?result=vip_error');
     }  
    break;
    
    case 'add':
    if (empty($_POST['submit'])) {
        echo link2 . '<form action="vip.php?act=add" method="post" name="form">
        <b>ID юзера:</b><br/>
        <input name="id" type="text" maxlength="15"/><br/>';
        echo '<input name="submit" class="submit" type="submit" value="Далее" /></form>' . div;
    } else {
        $id = num($_POST['id']);
        $user = mysql_fetch_assoc(mysql_query("SELECT * FROM `profile` WHERE `id` = '".$id."'"));
        if ( isset($user['id']) ) {
            if (mysql_query("UPDATE `profile` SET `vip` = '".(time() + 604800)."'WHERE `id` = '".$id."'"))
                header('Location: vip.php?result=on');
            else
                header('Location: vip.php?result=error');
        }
    }
    break;
    
    
}
navig();
foot();
?>
