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

echo head . 'Микроблог' . div . katalog;
####################Запись онлайна##################
mysql_query("UPDATE `profile` SET `online` = 'microblog' WHERE `id` = '".$id_session."'");
####################################################
echo "<b>Сорт:</b> ";
if (!isset($_GET[time])) echo "<a href='?time'>Время</a>\n";
if (isset($_GET[time])) echo "<font color='red'>Время</font>\n";

echo "\n|\n";

if (!isset($_GET[rating])) echo "<a href='?rating'>Популярность</a>\n";
if (isset($_GET[rating])) echo "<font color='red'>Популярность</font>\n";

echo "\n|\n";

if (!isset($_GET[look])) echo "<a href='?look'>Просмотры</a>\n";
if (isset($_GET[look])) echo "<font color='red'>Просмотры</font>\n";

echo div . link1;


if (isset($user)) {

echo " <a href='add.php'>Новая запись</a></div>";
}

//echo '<hr>';

$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `microblog`"),0);


$order='`time` DESC';
if (isset($_GET[time])) $order='`time` DESC';
if (isset($_GET[rating])) $order='`rating` DESC';
if (isset($_GET[look])) $order='`view` DESC';

    $all = mysql_result(mysql_query("SELECT count(*) FROM `microblog`"), 0);
    
        
        $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;
        
$q=mysql_query("SELECT * FROM `microblog` ORDER BY $order  limit ".num($start).",".num($onpage)."");
if (mysql_num_rows($q)==0) {
    echo "Нет дневников<br />";
} else {
    
    //echo '<div class="link2"><b>Последние записи:</b></div>';
}


while ($dnev = mysql_fetch_assoc($q))
{



echo "<div class='link2'><b>Запись:</b> <a href='blog.php?id=$dnev[id]'>$dnev[name]</a><br/>\n";


if (mysql_result(mysql_query("SELECT COUNT(*) FROM `microblog_kom` WHERE `id_dnev` = '$dnev[id]'"),0)!=0) {
$post=mysql_fetch_assoc(mysql_query("SELECT * FROM `microblog_kom` WHERE `id_dnev` = '$dnev[id]' ORDER BY `time` DESC LIMIT 1"));


echo '['; echo mysql_result(mysql_query("SELECT COUNT(*) FROM `microblog_kom` WHERE `id_dnev` = '$dnev[id]'"),0)." комент.]<br />\n";
	}
echo user($dnev['id_user']) . " <font color='#afb0a3'>".date2($dnev[time])."</font></div>";
}
echo link1 . '<b>Страницы:</b> ';
navigation($allpage,"index.php?p={p}",1,1);
echo div;


$all_dnev=mysql_result(mysql_query("SELECT COUNT(*) FROM `microblog`"),0);
$new_d=mysql_result(mysql_query("SELECT COUNT(*) FROM `microblog` WHERE `time` > '".(time()-86400)."'"), 0);
$all_dnev_k=mysql_result(mysql_query("SELECT COUNT(*) FROM `microblog_kom`"),0);
$new_d_k=mysql_result(mysql_query("SELECT COUNT(*) FROM `microblog_kom` WHERE `time` > '".(time()-86400)."' "), 0);
echo "<div class='link2'>Всего дневников $all_dnev <font color='red'>+$new_d Сегодня</font><br/>Всего комментариев $all_dnev_k <font color='red'>+$new_d_k Сегодня</font></div>";

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

navig();
foot();
?>