<?
include 'config.php';
include 'func.php';
head();
aut();
ban();
$id=(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` = '".$id."'"));

echo head . 'Ава | <b>'.$user['login'].'</b>' . div . katalog;

    switch ($_GET['mod']) {
        default:
        echo '<center>';
        if($user['upload_ava']){
        echo '<img src="resize.php?img=upload_ava/'.$user['upload_ava'].'&width=300&height" alt=""/></a><br/>';
            } else {
        rew($user['id']);
        }
        $all = mysql_result(mysql_query("SELECT count(*) FROM ava_coment  where `user_to` = '".$user['id']."'"), 0);
        $razr = getimagesize("upload_ava/".$user['upload_ava']);
        echo 'Скачать <a href="upload_ava/'.$user['upload_ava'].'"><b>Оригинал</b></a> '.$razr['0'].'x'.$razr['1'].'<br/>';
        echo '<a href="ava_view.php?mod=coment&id='.$user['id'].'">Коментировать</a> ['.$all.']<br/> <a href="'.$user['id'].'"><b>В анкету</b></a>';
        echo '</center>';
        break;
        
        case 'coment':
        if (isset($_POST['submit'])) {
            $msg = html($_POST['msg']);
            
            $msginf = mysql_fetch_assoc(mysql_query("SELECT * FROM `ava_coment` WHERE `msg` = '".$msg."' order by id desc limit 1"));
            if ($msg == $msginf['msg']) {
                echo link1 . 'Повтор коментария' . div; 
            } else {
            if (empty($msg)) {
                echo link1 . 'Вы не ввели коментарий' . div;
            } else {
                if (mysql_query("INSERT INTO `ava_coment` SET `msg` = '".$msg."', `user` = '".$id_session."', `user_to` = '".$user['id']."', `date` = '".time()."'"))
                echo link1 . 'Коментарий добавлен' . div;
                else
                echo link1 . 'Возникла ошибка' . div;
            }
            }
            
        }
        
        $all = mysql_result(mysql_query("SELECT count(*) FROM ava_coment  where `user_to` = '".$user['id']."'"), 0);
        
        if ($all == 0) echo 'Коментарий нет';
        if($all){
        $onpage = 5;
        $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 ava_coment  where `user_to` = '".$user['id']."' order by id desc limit ".num($start).",".num($onpage)."");
        
        while($msg = mysql_fetch_assoc($result)){
            echo user($msg['user']) . ' | ' . date2($msg['date']) . '<br/>' . smile($msg['msg']) . '<hr>';
        echo link1 . '<b>Страницы:</b> ';
       navigation($allpage,"stena.php?id=$user[id]&p={p}",1,1);
       echo div;
    }
    }
    
    
        echo '<center>';
        echo '<form action="ava_view.php?mod=coment&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>';  
        echo '</center>';  
        break;
}        
echo div;
navig();
foot();
?>