<?
include 'config.php';
include 'func.php';
head();
aut();
ban();    

mysql_query("UPDATE `profile` SET `online` = 'besedka' WHERE `id` = '".$id_session."'");

echo head . '<b>Беседка:</b>' . div;
if ( $kik_session > time()) {
    echo link1;
    echo 'Вы заблокированы. По причине: '.$whykik_session.', администратором/модератором: '.user($whokik_session).'. Осталось ждать: '.t($kik_session-time()).'<br/>';
    navig();
    foot();
    exit();
}
switch ($_GET['act']) {
    default:
    $id = num($_GET['u']);
    $us = mysql_fetch_assoc(mysql_query("SELECT * FROM `profile` WHERE `id` = '".$id."'"));
    if ( isset($us['id']) )
    $msg = '[b]'.$us['login'].'[/b], ';
    else
    $msg;
    echo link1 . '<a href="besedka.php">Обновить</a> | <a href="../smiles.php">Смайлы</a> | <a href="../info.php?act=bb">BB коды</a> ';
    if ($level_session >= 3) echo ' |<b><a href="besedka.php?act=clean"> Очистить беседку</a></b>' . div; else echo div;
    
    echo link2 . '<form action="besedka.php?act=add" method="post" name="form">';
    echo '<textarea id="tarea" name="msg" cols="30" rows="5" style="width: 99%;">'.$msg.'</textarea><br/>';
    echo '<input class="button" name="submit" type="submit" class="button" value="Написать" /></form>' . div;

echo link2;    
$all = mysql_result(mysql_query("SELECT count(*) FROM `vip`"), 0);
if($all){
$onpage = 10;
$allpage = ceil($all/$onpage);
$this_page = (isset($_GET['p'])) ? intval($_GET['p']) : 1 ;
if($this_page < 1 || $this_page > $allpage)$this_page = 1;
$start = $this_page*$onpage - $onpage;
if($all>0)
{
$result = mysql_query("SELECT * FROM vip  order by id desc limit ".$start.",".$onpage."");
echo '<form action="besedka.php?act=del" method="post">';
while($msg = mysql_fetch_assoc($result)){
    if ($level_session >= 3) echo '<input type="checkbox"  name="check_del[]" value="'. $msg['id'] .'"> ';
    $user = mysql_fetch_assoc(mysql_query("SELECT * FROM `profile` WHERE `id` = '".$msg['user_1']."'"));
    echo xstatus($user['xstatus'], $msg['user_1']) . ' ' . colorl($msg['user_1']). " [<a href='besedka.php?u=".$msg['user_1']."'>отв</a>] [<a href='../profile.php?id=".$msg['user_1']."'>анк</a>] " .t2($msg['date']). ": " .smile(parsebb(adminbb(nl2br(mat($msg['msg']))))) . '<br/>';
//echo div;
}
if ($level_session >= 3) echo '<input type="submit" class="button" value="Удалить выделеное"/></form>';
echo div;
echo link1 . '<b>Страницы:</b> ';
navigation($allpage,"besedka.php?p={p}",1,1);
echo div;
}


} else { 
    
    echo link2 . 'Сообщений нет...' . div;
    
}



$online = mysql_result(mysql_query("SELECT count(*) FROM `profile` WHERE `time` > '".(time()-300)."' AND `online` = 'besedka' ORDER BY `time`"), 0);

if ( $online > 0 ) {
    echo link2 . '<b>В беседке: </b>';
    $result = mysql_query("SELECT * FROM `profile` WHERE `time` > '".(time()-300)."' AND `online` = 'besedka' ORDER BY `time`");
    while($users = mysql_fetch_assoc($result)){
    echo user($users['id']).' ';
    }
    echo div;
    
}    
break;


case 'add':
if(empty($_POST['submit'])){
echo '<div align="center"><form action="vip.php?act=add" method="post" name="form">';

if($vvod_session==0)
echo '<input name="msg" type="text" maxlength="1000" /><br/>';
else
echo '<textarea id="tarea" name="msg" cols="30" rows="5"></textarea><br/>';

echo '<input name="submit" type="submit" class="button" value="Написать" /></form></div>';
}else{
$msg = mysmile(html($_POST['msg']));

if(empty($msg)) {
    echo link1 . 'Не флуди' . div;
    exit();
}


mysql_query("INSERT INTO `vip` SET `msg` = '".$msg."', `user_1` = '".$id_session."', `date` = '".time()."'");
mysql_query("UPDATE `profile` SET `akt_rating` = '".($akt_session+0.1)."' WHERE `id` = '$user[id]' LIMIT 1");
$msg1 = '<b>'.user($id_session).'</b> оставил(а) сообщение в <b><a href="besedka.php">беседке</a></b>';
mysql_query("INSERT INTO `jurnal` SET  `msg` = '".$msg1."', `user` = '".$id_session."', `date` = '".time()."'");
header('Location: besedka.php');
}
break;

case 'clean':
if ($level_session >= 3) {
    
    if (empty($_GET['yes'])) {
        echo link1 . '<a href="besedka.php?act=clean&yes=clean">Подтвердить чистку</a><br/>' .div;
    } else {
        if (mysql_query("DELETE FROM `vip`")) {
            echo link1 .  'Беседка упешно очищена' .div;
        }
    }
    
}
break;
    

case del:
if  (!isset($_POST['check_del'])) {
header('Location: besedka.php?err=9');
}

$check_del = $_POST['check_del'];
$col = 0;
foreach  ($check_del as $check) {
$col  = $col + 1;

if(mysql_query("DELETE FROM `vip` WHERE `id` = '".(int)$check."'"))
{
header('Location: besedka.php?ok');
}
 else
{
header('Location: besedka.php?err=10');
}
}
break;

    
    
}



navig();
foot();
?>