<?
header('Cache-Control: no-store, no-cache, must-revalidate');	// HTTP/1.1


require( "inc/conf.inc.php" );
require( "inc/check.php" );
mysql_query( "update users set `ltime`='".time( )."', `lroom`='20' where id='{$id}' and ci='".$ci."';" );
echo "<title>-=Блоги=-</title>";
echo "<link rel=\"../shortcut icon\" href=\"favicon.ico\">";
echo "<meta http-equiv=\"refresh\" content=\"{$avr}\">";
echo "<style type=\"text/css\">";
echo "body { margin: auto; max-width: 500px; font: 12px Arial; color: #808080; background-color: #000000; }";
echo "a:link,a:visited { text-decoration: none; color: b0c4db; }";
echo "div { background-color: #202020; border-style:solid; border-width: 1px; }";
echo "img { vertical-align: middle; }";
echo "</style>";
echo "</head>";
echo "<body>\n";
$q_blog = @mysql_query( @"SELECT count(*) FROM users WHERE ltime>'".@intval( @time( ) - 300 )."' and `lroom`='20' " );

$mid = intval(check($mid));

if(empty($tyu))$tyu="left";
if(empty($title))$title="Дневники";

echo "<div align=\"center\">Дневники</div>";
$mod = check($mod);
switch($mod) {

case 'who':
echo $fsize1;
echo "<b>Кто отдал голос за этот дневник:</b><br/>";
echo $divide;
echo $fsize2;
if(empty($s)) $s=0;
$query = mysql_query("select * from bloggolos where blog='".$mid."';");
$num_of_rows=mysql_num_rows($query);
$total_mat_number=$num_of_rows;
$max = 10;
$total_ss=ceil($total_mat_number/$max);
$print = mysql_query("select * from bloggolos where blog='".$mid."' order by who desc limit ".$s.",".($max).";");
$i = 1+$s;
while($arr = @mysql_fetch_array($print)) {
$usid=$arr["who"];
$whogolos = @mysql_query("select * from users where id=".$usid.";");
$idatas = @mysql_fetch_array($whogolos);
$login=$idatas["login"];
echo $fsize1;
echo ($i++).") <a href=\"search.php?ci={$ci}&amp;id={$id}&amp;pass={$pass}&amp;url={$url}&amp;go=view$takep2&amp;nick=$usid\">".$login."</a><br/>";
echo $fsize2;
}
echo $fsize1;
echo $divide;
echo $fsize2;
echo "<dl><dt></dt></dl>\n";
for ($num=0; $num<$total_ss; $num++){
$s_number=$num*$max;
echo $fsize1;
if ($s_number!=$s) {
echo "<a href=\"blogs.php?mod=who&amp;ci={$ci}&amp;id={$id}&amp;pass={$pass}&amp;url={$url}&amp;s=$s_number&amp;mid=$mid\">".($num+1)."</a>|";
} else {
echo "".($num+1)."|";
}
}
echo "<dl><dt></dt></dl>\n";
echo $fsize2;
break;

case 'votes':
$q = @mysql_query("select * from `blogs` where id='".$mid."';");
$arr = @mysql_fetch_array($q);
$nk=$arr['avtor'];
if ($nk==$id){
echo $fsize1;
echo "Вы не можете голосовать за свой Дневник!<br/>";
print $fsize2;
}else{
$q0 = mysql_query("Select * from bloggolos where blog='".$mid."'");
$data0 = mysql_fetch_array($q0);
if ($data0['who']==$id){
echo $fsize1;
echo "Вы уже голосовали за этот Дневник. Голос не принят.<br/>";
echo $fsize2;
} else {
$q = mysql_query("select * from blogs where id='".$mid."';");
$data = mysql_fetch_array($q);
$counter = $data['golos'];
$login = $data['login'];
$counter2 = $counter+1;
mysql_query ("update blogs set golos='".$counter2."' where id='".$mid."';");
mysql_query ("INSERT INTO bloggolos SET blog = '".$mid."', who = '".$id."'");
echo $fsize1;
echo "Ваш голос принят!<br/>";
echo $fsize2;
}
}
break;

case 'users':
echo $fsize1;
echo "<b>Рейтинг Авторов:</b><br /><br />\n";
if(empty($s)) $s=0;
$query = mysql_query("select * from users where myblogs>'0';");
$num_of_rows=mysql_num_rows($query);
$total_mat_number=$num_of_rows;
$max = 20;
$total_ss=ceil($total_mat_number/$max);
$r = mysql_query ("select * from `users` where myblogs>'0' order by myblogs desc limit ".$s.",".$max.";");
$i = 1+$s;
while($arr = mysql_fetch_array($r)) {


echo ($i++).") <a href=\"blogs.php?ci={$ci}&amp;id={$id}&amp;pass={$pass}&amp;url={$url}&amp;mid=".$arr['id']."&amp;mod=user&amp;usid=".$arr['id']."\">".$arr['login']."</a> [".$arr['myblogs']." записей]<br/>";
}

echo "<dl><dt></dt></dl>\n";
for ($num=0; $num<$total_ss; $num++){
$s_number=$num*$max;

if ($s_number!=$s) {
echo "<a href=\"blogs.php?go=golos&amp;ci={$ci}&amp;id={$id}&amp;pass={$pass}&amp;url={$url}&amp;s=$s_number&amp;mod=user&amp;usid=$usid\">".($num+1)."</a>|";
} else {
echo "".($num+1)."|";
}}
echo "<dl><dt></dt></dl>\n";
echo $fsize2;
break;

case 'user':
echo $fsize1;
$av = mysql_query ("select * from `users` where id='".$usid."'");
$avt = mysql_fetch_array($av);
echo "Дневники <b>".$avt['login'].":</b><br /><br />\n";
if(empty($s)) $s=0;
$query = mysql_query("select * from blogs where avtor='$usid';");
$num_of_rows=mysql_num_rows($query);
$total_mat_number=$num_of_rows;
$max = 20;
$total_ss=ceil($total_mat_number/$max);
$r = mysql_query ("select * from `blogs` where avtor='$usid' order by golos desc limit ".$s.",".$max.";");
$i = 1+$s;
while($arr = mysql_fetch_array($r)) {


echo ($i++).") <a href=\"blogs.php?ci={$ci}&amp;id={$id}&amp;pass={$pass}&amp;url={$url}&amp;mid=".$arr['id']."&amp;mod=view\">".$arr['name']."</a> [".$arr['golos']."|".$arr['chit']."]<br/>";
}

echo "<dl><dt></dt></dl>\n";
for ($num=0; $num<$total_ss; $num++){
$s_number=$num*$max;

if ($s_number!=$s) {
echo "<a href=\"blogs.php?go=golos&amp;ci={$ci}&amp;id={$id}&amp;pass={$pass}&amp;url={$url}&amp;s=$s_number&amp;mod=user&amp;usid=$usid\">".($num+1)."</a>|";
} else {
echo "".($num+1)."|";
}}
echo "<dl><dt></dt></dl>\n";
echo $fsize2;
break;

case 'view':

$q = @mysql_query("select * from `blogs` where id='".$mid."';");
$arr = @mysql_fetch_array($q);

$av = mysql_query ("select * from `users` where id='".$arr['avtor']."'");
$avt = mysql_fetch_array($av);
echo $fsize1;

$mchit=$arr["chit"]+1;
mysql_query("update `blogs` set chit='$mchit'  WHERE `id`='".$mid."';");

echo "<b>".$arr['name']."</b>- ".$avt['login']."<br />\n";
echo "".$arr['blog']."<br />\n";
echo "Запись сделана: ".$arr['date']."<br />\n";
echo "Прочитанно: ".$arr['chit']."<br />\n";
echo "Голосов: <a href=\"blogs.php?ci={$ci}&amp;id={$id}&amp;pass={$pass}&amp;url={$url}&amp;mid=".$mid."&amp;mod=who\">".$arr['golos']."</a><br />\n";
echo "<a href=\"blogs.php?ci={$ci}&amp;id={$id}&amp;pass={$pass}&amp;url={$url}&amp;mid=".$mid."&amp;mod=votes\">Голосовать</a><br />\n";

if($row['moder']>=2) { echo "<br /><img src=\"icon/d.png\" alt=\"[DEL]\"/>  <a href=\"blogs.php?ci={$ci}&amp;id={$id}&amp;pass={$pass}&amp;url={$url}&amp;mid=".$mid."&amp;mod=delblogus&amp;usid=".$arr['avtor']."\">Удалить запись</a><br /><br />\n";}
echo $fsize2;
break;

case 'read':
echo $fsize1;
if(empty($s)) $s=0;
$query = mysql_query("select * from blogs;");
$num_of_rows=mysql_num_rows($query);
$total_mat_number=$num_of_rows;
$max = 20;
$total_ss=ceil($total_mat_number/$max);
$r = mysql_query ("select * from `blogs` order by golos desc limit ".$s.",".$max.";");
$i = 1+$s;
while($arr = mysql_fetch_array($r)) {

$av = mysql_query ("select * from `users` where id='".$arr['avtor']."'");
$avt = mysql_fetch_array($av);
echo ($i++).") <a href=\"blogs.php?ci={$ci}&amp;id={$id}&amp;pass={$pass}&amp;url={$url}&amp;mid=".$arr['id']."&amp;mod=view\">".$arr['name']."</a>, <a href=\"search.php?ci={$ci}&amp;id={$id}&amp;pass={$pass}&amp;url={$url}&amp;go=view$takep2&amp;nick=".$arr['avtor']."\">".$avt['login']."</a> [".$arr['golos']."|".$arr['chit']."]<br/>";
}
echo "<dl><dt></dt></dl>\n";
for ($num=0; $num<$total_ss; $num++){
$s_number=$num*$max;
if ($s_number!=$s) {
echo "<a href=\"blogs.php?go=golos&amp;ci={$ci}&amp;id={$id}&amp;pass={$pass}&amp;url={$url}&amp;s=$s_number&amp;mod=read\">".($num+1)."</a>|";
} else {
echo "".($num+1)."|";
}
}
echo "<dl><dt></dt></dl>\n";
echo $fsize2;
break;

default:
$q = mysql_query ("select count(id) as num from blogs;");
$bl = mysql_fetch_array($q);
$num = $bl["num"];
$q2 = mysql_query ("select count(id) as num from users where myblogs>'0';");
$bl2 = mysql_fetch_array($q2);
$num2 = $bl2["num"];
echo $fsize1;
echo "<b>Онлайн-дневники</b><br />
Онлайн-дневник (блог) - отличная способность выразить себя, поделиться своими мыслями, и ознакомиться с творчеством других чатлан!<br />\n";
echo "<a href=\"blogs.php?ci={$ci}&amp;id={$id}&amp;pass={$pass}&amp;url={$url}&amp;mod=read\">Читать дневники</a> ($num)<br />\n";
echo "<a href=\"blogs.php?ci={$ci}&amp;id={$id}&amp;pass={$pass}&amp;url={$url}&amp;mod=users\">Рейтинг авторов</a> ($num2)<br />\n";
echo "<a href=\"blogs.php?ci={$ci}&amp;id={$id}&amp;pass={$pass}&amp;url={$url}&amp;mod=add\">Добавить запись в дневник</a><br />\n";
echo "<a href=\"blogs.php?ci={$ci}&amp;id={$id}&amp;pass={$pass}&amp;url={$url}&amp;mod=delblog\">Удалить запись из дневника</a><br />\n";
echo $fsize2;
break;

case 'add':

$q = mysql_query("select * from `blogs`;");
$last_bl = @mysql_fetch_array($q);
if(empty($name)) {
echo $fsize1;
echo "<b>Добавить запись:</b><br />\n";
echo $fsize2;
echo $fsize1;
echo "<form action=\"blogs.php?ci={$ci}&amp;id={$id}&amp;pass={$pass}&amp;url={$url}&amp;mod=add\" method=\"post\"><br/>";
echo "Название:<br/><input name=\"name\" maxlength=\"50\"/><br/>\n";
echo "Текст:<br/><input type=\"text\" name=\"blog\" maxlength=\"1000\"/><br />\n";
echo "<input type=\"submit\" class=\"ibutton\" value=\"Добавить\"></form>";
echo $fsize2;

} else {

$datta= "".date("d-m-Y")." в ".date ("H:i")."";
$mmyblogs=$row["myblogs"]+1;
$name = trim(addslashes(htmlspecialchars($name)));
$blog = trim(addslashes(htmlspecialchars($blog)));
$name = check($name);
$blog = check($blog);
if ($row["translit"]==1) $name = trun_to_rus($name);
if ($row["translit"]==1) $blog = trun_to_rus($blog);
if(@mysql_query("insert into `blogs` values(0,'".$row['id']."','$name','$blog','0','0','".$datta."');") && @mysql_query("update `users` set `myblogs`='".$mmyblogs."' where `id`='".$id."';")) {

echo $fsize1;
print "Запись успешно добавлена<br />";echo $fsize2;
} else {echo $fsize1; print $lang['error'];echo $fsize2; }

}
break;

case 'delblog':
echo $fsize1;
$av = mysql_query ("select * from `users` where id='".$id."'");
$avt = mysql_fetch_array($av);
$bl = mysql_query ("select count(id) as num from blogs where avtor='$id';");
$bln = mysql_fetch_array($bl);
if ($bln["num"]==0){
echo "<b>У вас нет записей!<br /></b><br />\n";
}else{
echo "Чтобы удалить запись из дневника просто нажмите на нее.<br /><br />\n";
if(empty($s)) $s=0;
$query = mysql_query("select * from blogs where avtor='$id';");
$num_of_rows=mysql_num_rows($query);
$total_mat_number=$num_of_rows;
$max = 20;
$total_ss=ceil($total_mat_number/$max);
$r = mysql_query ("select * from `blogs` where avtor='$id' order by golos desc limit ".$s.",".$max.";");
$i = 1+$s;
while($arr = mysql_fetch_array($r)) {


echo ($i++).") <a href=\"blogs.php?ci={$ci}&amp;id={$id}&amp;pass={$pass}&amp;url={$url}&amp;mid=".$arr['id']."&amp;mod=delblogok\">".$arr['name']."</a> [".$arr['golos']."|".$arr['chit']."]<br/>";
}


for ($num=0; $num<$total_ss; $num++){
$s_number=$num*$max;

if ($s_number!=$s) {
echo "<a href=\"blogs.php?go=golos&amp;ci={$ci}&amp;id={$id}&amp;pass={$pass}&amp;url={$url}&amp;s=$s_number&amp;mod=delblog\">".($num+1)."</a>|";
} else {
echo "".($num+1)."|";
}

}
}
echo $fsize2;
break;

case 'delblogok':
echo $fsize1;
$bl = mysql_query ("select * from blogs where `id`='$mid';");
$bln = mysql_fetch_array($bl);
if ($id!=$bln['avtor']){
echo "Эта запись не ваша!<br />\n";
}else{
$mmyblogs=$row["myblogs"]-1;
if(@mysql_query("delete from `blogs` where `id`='$mid' limit 1;")&& @mysql_query("update `users` set `myblogs`='".$mmyblogs."' where `id`='".$id."';")&& mysql_query("delete from `bloggolos` where `blog`='".$mid."' limit 1;"))echo "Запись успешно удалена!<br />\n";
}
echo $fsize2;
break;

case 'delblogus':
echo $fsize1;
if($row['moder']>=2) {
$av = mysql_query ("select * from `users` where id='".$usid."'");
$avt = mysql_fetch_array($av);
$mmyblogs=$avt["myblogs"]-1;
if(@mysql_query("delete from `blogs` where `id`='$mid' limit 1;")&& @mysql_query("update `users` set `myblogs`='".$mmyblogs."' where `id`='".$usid."';")&& mysql_query("delete from `bloggolos` where `blog`='".$mid."' limit 1;"))echo "Запись успешно удалена!<br />\n";
}else{
echo "У вас нет права доступа!<br />\n";
}
echo $fsize2;
break;

}
echo $fsize1;
echo $divide;
if($mod) {
print "<br/>$div1<a href=\"?ci={$ci}&amp;id={$id}&amp;pass={$pass}&amp;url={$url}\">Дневники</a>$div9";
}


echo "<div align=\"center\"><a href=\"enter.php?ci={$ci}&amp;id={$id}&amp;pass={$pass}&amp;url={$url}&amp;ref=$rand\">Прихожая</a></div>";
echo $div2;

echo $div9;
echo $fsize2;
if ($wap=="1")echo "</p></card></wml>";
else echo "</div></body></html>";
mysql_close($link);
?>