<?
include 'config.php';
include 'func.php';
head();
aut();
ban();
####################Запись онлайна##################
mysql_query("UPDATE `profile` SET `online` = 'stena' WHERE `id` = '".$id_session."'");
####################################################

//////////////
$idu=(int)mysql_real_escape_string($_GET[id]);
$room=(int)mysql_real_escape_string($_GET[room]);

$user = mysql_fetch_assoc(mysql_query("SELECT * FROM `profile` WHERE `id` = '$idu'"));
$stena = mysql_fetch_assoc(mysql_query("SELECT * FROM `stena` WHERE `komu` = '$idu'"));
$kol_stena = mysql_result(mysql_query("SELECT count(*) FROM `stena` WHERE `komu` = '$idu'"), 0);


#if ( !empty($stena['id']) ) {
    
    
    
echo head . "Стена | <b>$user[login]</b>" . div;

if ( $kik_session > time()) {
    echo link1;
    echo 'Вы заблокированы. По причине: '.$whykik_session.', администратором/модератором: '.user($whokik_session).'. Осталось ждать: '.t($kik_session-time()).'<br/>';
    navig();
    foot();
    exit();
}



if ( isset($_POST['submit']) ) {

if ($user['private_stena'] == 1 AND $user['id'] != $id_session) $err = 'Вы не можете оставлять сообщения на стенк ' . $usinf['login'];
    
if ($user['private_stena'] == 2 OR $user['id'] != $id_session) {
$sql = mysql_query("SELECT * FROM `friends` WHERE `user_1` = $user[id] AND `user_2` = $id_session;");
if(mysql_num_rows($sql) ==0) $err = 'У пользователя '.$user['login'].' могут оставлять сообщения только его/ее друзья.';
}
    
if ($err) { 
    echo link1 . 'Ошибка, ' . $err . div;
}else {
////////////////////////////////
   
$msg = mysmile(html($_POST['msg']));
$result = mysql_query("INSERT INTO `stena` SET `date` = '".time()."', `msg` = '".$msg."', `ot_id` = '".$id_session."', `ot_login` = '".$login_session."', `komu` = '".$user['id']."'");
mysql_query("UPDATE `profile` SET `akt_rating` = '".($akt_session+0.1)."' WHERE `id` = '$user[id]' LIMIT 1");

if ($stena['komu']!=$id_session) {
$msg = "Вам написали на <a href=\"stena.php?id=".$id_session."\">стене</a>.";
mysql_query("INSERT INTO `mail` SET `msg` = '".$msg."', `to_user` = '".$user['id']."', `ot_user` = '".$id_session."',`status` = '0', `date` = '".time()."'");
}
if ( $result != NULL ) {
    
    header('Location: stena.php?id='.$user['id']);
    
}

}

}


if ($user['private_stena'] == 1 AND $user['id'] != $id_session) $err = 'Вы не можете оставлять сообщения на стенк ' . $usinf['login'];
    
if ($user['private_stena'] == 2 OR $user['id'] != $id_session) {
$sql = mysql_query("SELECT * FROM `friends` WHERE `user_1` = $user[id] AND `user_2` = $id_session;");
if(mysql_num_rows($sql) !=0) $err = 'У пользователя '.$user['login'].' могут оставлять сообщения только его/ее друзья.';
}
    
if (!$err) { 

    
//echo au;
if ( $_GET['act']=='addp' ) {
    $infuser = mysql_fetch_assoc(mysql_query("SELECT * FROM `profile` WHERE `id` = '".num($_GET['user'])."'"));
    echo link2 . '<form action="stena.php?act=add&id='.$user['id'].'" method="post" name="form">';
    echo '<textarea id="tarea" name="msg" cols="30" rows="5" style="width: 99%;">[b]'.$infuser['login'].'[/b], </textarea><br/>';
    echo '<input name="submit" type="submit" class="button" value="OK" /></form>' . div;

} else {

    echo link2 . '<form action="stena.php?act=add&id='.$user['id'].'" method="post" name="form">';
    echo '<textarea id="tarea" name="msg" cols="30" rows="5" style="width: 99%;"></textarea><br/>';
    echo '<input name="submit" type="submit" class="button" value="OK" /></form>' . div;    
    
}

}






echo div;

//echo kub . '<img src="style/img/kub.gif" alt="" />' . div . katalog;

if($kol_stena == 0){

echo link2 . "Пусто" . div;

} else {


if($kol_stena){
$onpage = 10;
$allpage = ceil($kol_stena/$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;


$result = mysql_query("SELECT * FROM stena  where `komu` = '".$idu."'order by id desc limit ".num($start).",".num($onpage)."");

while($stena = mysql_fetch_assoc($result)){

echo link1 . user($stena['ot_id']) . ' ' . date2($stena['date']) . div ; 

echo link2 . mat(smile(parsebb(adminbb(nl2br($stena['msg'])))));

echo '<br/ ><br/ >';

if ( $stena['user'] == $id_session OR $stena['ot_id'] == $id_session OR $level_session >=2 ) $del = "[<a href=\"stena.php?act=del&post=".$stena['id']."\">Del</a>]"; else $del;
echo "[<a href=\"stena.php?id=".$stena['ot_id']."&act=addp&user=".$stena['ot_id']."\">Отв</a>] [<a href=\"stena.php?id=".$stena['ot_id']."\">Его стена</a>] [<a href=\"stena.php?act=add&id=".$stena['ot_id']."\">Отв. на его стене</a>] ".$del." ";

echo div;
}


echo link1 . '<b>Страницы:</b> ';
navigation($allpage,"stena.php?id=$user[id]&p={p}",1,1);
echo div;
}

echo link2 . '<a href=\"stena.php?act=clean&id=".$id_session."\">Чистка стены</a> [моей]<br/ >';
}



if ( $_GET['act'] == 'del' ) {
    
    $post = num($_GET['post']);
    $infpost = mysql_fetch_assoc(mysql_query("SELECT * FROM `stena` WHERE `id` = '".$post."'"));
    
    if ( $infpost['komu'] == $id_session OR $infpost['ot_id'] == $id_session OR $level_session >=2) {
        
        $result = mysql_query("DELETE FROM stena  where `id` = '".$post."'");
        
        if ( $result != NULL ) {
            
            header('Location: stena.php?id='.$infpost['komu']);
            
        }
        
    }
    
}





if ( $_GET['act'] == 'clean' ) {
    
    $stena = $id_session;
    
    if ( $_GET['b'] != 'yes' ) {
        
        echo '<a href="stena.php?act=clean&b=yes&id='.$id_session.'">Подтвердить чистку</a><br/ >';
        
        } else {

        
        $result = mysql_query("DELETE FROM stena  where `komu` = '".$stena."'");
        
        if ( $result != NULL ) {
            
            header('Location: stena.php?id='.$stena);
            
        }
        
        }
        
    }
    

#} else {
    
    #echo head . 'Ошибка' . div . link1 . 'Стена не найдена' . div;
    
    
#}










navig();
foot();
?>