<?
include '../config.php';
include '../func.php';
head();
aut();
ban();
////////////////////////////////////////
mysql_query("UPDATE `profile` SET `online` = 'blog' WHERE `id` = '".$id_session."'");

$id = num($_GET['blog']);
$blog = mysql_fetch_assoc(mysql_query("SELECT * FROM `blogs` WHERE `id` = '".$id."'"));
    
if ( empty($blog['id']) ) {
    
    echo katalog . 'Запись не найдена' . div;
    pod_navig();
    foot();
    exit();
    
}    

if ( $_GET['status'] == 'msg_empty' ) echo katalog . 'Не введен коментарий' . div;
if ( $_GET['status'] == 'msg_add' ) echo katalog . 'Коментарий добавлен' . div;
if ( $_GET['status'] == 'msg_error' ) echo katalog . 'Возникла ошибка' . div;

echo head . "Блоги / <b>".$blog['top']."</b>" . div;   
echo link1 . ''.user($blog['user']).' / ' . date2($blog['date']).div;
echo link2;
echo smile(parsebb(adminbb(nl2br($blog['msg']))));
//echo div;

//echo link1;
mysql_query("update blogs set view=view+'1' where id='".$id."'");
echo '<br/>Прочитано: '.$blog['view'].' раз<br/ >';

echo div;

echo link1 . '<b>Комментарии:</b></div>';
$all_coment = mysql_result(mysql_query("SELECT count(*) FROM blogs_coment WHERE `blog` = '".$id."'"), 0);

if ( $all_coment == 0 ) {
   
   echo '<div class="link2">Комментарий нет</div>'; 

} else {

if($all_coment){
$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 blogs_coment WHERE `blog` = ".$id." order by id desc limit ".$start.",".$onpage."");
while($coment = mysql_fetch_assoc($result)){

echo "
<b><div class='link2'>".user($coment['user_id'])."</b> | ".date2($coment['date'])."<br/ >
".mat(smile(adminbb(parsebb($coment[msg]))))."</div>";

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

}


msg( 'view.php?mod=add_coment&blog='.$id.'', 'msg' );
echo link2 . '<form action="view.php?mod=add_coment&blog='.$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="Написать" /></form></div>';
echo link2 . '<a href="index.php">Блоги</a> <a href="../smiles.php">Смайлы</a>' . div;


if ( $_GET['mod'] == 'add_coment' ) {
    
    if ( empty($blog['id']) ) {
    
    echo link2 . 'Запись не найдена' . div;
    pod_navig();
    foot();
    exit();
    
    }   
    
    $msg = html($_POST['msg']);
    
    
    if (empty($msg)) {
    
    header("Location: view.php?blog='".$id."'&status=msg_empty");
    
    } else {
    if ($id_session != $blog['user']) {
    $msg = 'Ваш блог откоментировали. Перейти к <b><a href="blog/view.php?blog='.$blog['id'].'">блогу</b></a>. Откоментировал(а): '.user($id_session).'. Дата: '.date2(time()).'';
    mysql_query("INSERT INTO `uvedom` SET  `msg` = '".$msg."', `md` = 'blog', `user_to` = '".$photo_info['user']."', `user_ot` = '".$id_session."', `date` = '".time()."', `status` = '1'");
    
    $msg1 = '<b>'.user($id_session).'</b> откоментировал <b><a href="blog/view.php?blog='.$blog['id'].'">блог</a></b>';
    mysql_query("INSERT INTO `jurnal` SET  `msg` = '".$msg1."', `user` = '".$id_session."', `date` = '".time()."'");
    }
    $result = mysql_query("INSERT INTO `blogs_coment` SET `user_id` = '".$id_session."', `msg` = '".$msg."', `date` = '".time()."', `blog` = '".$id."'");
    mysql_query("UPDATE `profile` SET `many` = '".($many_session+1)."' WHERE `id` = '".$id_session."'");
    if ( $result != NULL ) {
        
        header("Location: view.php?blog=".$id."&status=msg_add");
        
    } else {
        
        header("Location: view.php?blog=".$id."&status=msg_error");
        
    }
}

}

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

pod_navig();
foot();
?>