<?
include '../config.php';
include '../func.php';
head();
aut();
ban();
////////////////////////
$id = num($_GET['id']);
$clan = mysql_fetch_assoc(mysql_query("SELECT * FROM `clans` WHERE `id` = '".$id."'"));

if ( empty( $clan['id'] ) ) {
    
    echo "<div class=\"head\"><b>Ошибка</b></div><div class=\"main\">";  
    echo 'Данной группы не существует.<br/>';
    pod_navig();
    foot();
    exit();
    
}

echo "<div class=\"head\"><b>Стена | ".$clan['name']."</b></div><div class=\"main\">";   

echo "<a href=\"view.php?id=".$clan['id']."\">Назад</a><br/><br/>";

if ( $_POST['submit'] ) {
    
    $msg = html($_POST['msg']);
    
    if ( empty($msg) )  $err = '<div class="input">Сообщение не введено.</div><br/>';
    
    $post = mysql_fetch_assoc(mysql_query("SELECT * FROM `clans_stena` WHERE `clan` = '".$id."' order by id desc limit 1"));
    
    if ( $msg == $post['text'] )  $err = '<div class="input">Повтор сообщения.</div><br/>';
    
    
    if ( $err ) {
        
        echo $err;
    
    } else {
        
    
        
        $a = mysql_query("INSERT INTO `clans_stena` SET `user` = '".$id_session."', `text` = '".nl2br($msg)."', `clan` = '".$id."', `date` = '".mktime()."'");
        
        if ( $a == 1 )
        echo '<div class="input">Сообщение успешно добавлено.</div><br/>';
        else
        echo '<div class="input">Возникла ошибка.</div><br/>';
    
    
}

}


echo '<form action="stena.php?id='.$clan['id'].'" 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><br/>';

$all = mysql_result(mysql_query("SELECT count(*) FROM clans_stena WHERE `clan` = '".$clan['id']."'"), 0);

if ( $all > 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;    
$result = mysql_query("SELECT * FROM clans_stena WHERE `clan` = '".$clan['id']."' order by id desc limit ".$start.",".$onpage."");
while($b = mysql_fetch_assoc($result)){
    
    echo '<b>'.user($b['user']).'';
    echo '</b> | '.$b['date'].'<br/>'.mat(smiles(parsebb(adminbb(nl2br($b['text']))))).'<br/><br/>';
}

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




} else {
    
    
    echo 'Здесь еще никто не писал.<br/>';
    
}


////////////////////////

pod_navig();
foot();
?>