<?php
include_once '../../sys/inc/start.php';
include_once '../../sys/inc/compress.php';
include_once '../../sys/inc/sess.php';
include_once '../../sys/inc/home.php';
include_once '../../sys/inc/settings.php';
include_once '../../sys/inc/db_connect.php';
include_once '../../sys/inc/ipua.php';
include_once '../../sys/inc/fnc.php';
include_once '../../sys/inc/user.php';


$set['title']='Заметки';
include_once '../../sys/inc/thead.php';
title();
aut();
err();



function vyvod_text( $text, $maxwords = 21, $maxchar = 210 )
{
$sep=' ';
$sep2='...';
$words = split($sep,$text);
$char = iconv_strlen($text,'utf-8');
if (count($words) > $maxwords)
{
$text = join($sep, array_slice($words, 0, $maxwords));
}
if ( $char > $maxchar )
{
$text = iconv_substr( $text, 0, $maxchar, 'utf-8' );
}
return $text.$sep2;
}


if (isset($_GET['sort']) && $_GET['sort'] =='t')$order='order by `time` desc';
elseif (isset($_GET['sort']) && $_GET['sort'] =='c') $order='order by `count` desc';
else $order='order by `time` desc';
if(isset($user))
{
echo'<div class="foot">';

echo "<a href=\"user.php\">Мои заметки</a> | ";
echo "<a href=\"add.php\">Создать заметку</a>";
echo '</div>';
}
echo'<div class="foot">';
echo"<a href='?sort=t'>Новые</a> | <a href='?sort=c'>Популярные</a>\n";
echo '</div>';


$num = 0;
$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `blog_list` WHERE `privat` = 0"),0);
$k_page=k_page($k_post,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$set['p_str'];
echo "<table class='post'>\n";


if($k_post==0)
{
echo "   <tr>\n";
echo "  <td class='p_t'>\n";
echo "Заметок пока нет<br />";
echo "  </td>\n";
echo "   </tr>\n";
}

$res = mysql_query("select * from `blog_list` WHERE `privat` = 0 $order LIMIT $start, $set[p_str];"); 
while ($notes = mysql_fetch_array($res)){

$ank=get_user($notes['id_user']);
echo "   <tr>\n";
echo "  <td class='p_t'>\n";
echo "- <a href='list.php?id=".$notes['id']."'>".htmlspecialchars($notes['name'])."</a> (".mysql_result(mysql_query("SELECT COUNT(*) FROM `blog_komm` WHERE `id_blog` = '$notes[id]'"),0).") ";
echo "  </td>\n";
echo "   </tr>\n";
echo "   <tr>\n";

if ($set['set_show_icon']==1)echo "  <td class='p_m' colspan='2'>\n"; else echo "  <td class='p_m'>\n";
echo "".group($ank['id'])." <a href='/info.php?id=".$ank['id']."'>".$ank['nick']."</a> ";

echo "".online($ank['id'])." (".vremja($notes['time']).")<br />\n";
echo "Просмотров: [".$notes['count']."]<br />\n";
echo "".vyvod_text(output_text($notes['msg'])).""; 
if (($user['level'] >= 2) || ($user['id'] ==$notes['id_user']))
{
echo " [<a href='edit.php?id=$notes[id]'><img src='/style/icons/edit.gif' alt='*' /> ред</a>] [<a href='edit.php?id=$notes[id]&amp;del'><img src='/style/icons/delete.gif' alt='*' /> удл</a>]<br />";
}

echo "  </td>\n";
echo "   </tr>\n";
}
echo "</table>\n";

if (isset($_GET['sort'])) $dop="sort=$_GET[sort]&amp;";
else $dop='';
if ($k_page>1)str('?'.$dop.'',$k_page,$page); // Вывод страниц






include_once '../../sys/inc/tfoot.php';

?>