<?php
	/*
	*by Krite (http://upcoder.net)
	*/
	defined('_IN_JOHNCMS') or die('Error: restricted access');
	$textl = 'Непрочитанные статьи';
	require_once('../incfiles/head.php');
	switch ($do)
	{
		case 'all' :
			$vr = isset ($_REQUEST['vr']) ? abs(intval($_REQUEST['vr'])) : null;
			if (!$vr) 
			{
				echo '<div class="rmenu">Вы не ввели время!</div>
				<div class="menu"><a href="index.php?act=ns&amp;do=select">Повторить</a></div>';
				require_once '../incfiles/end.php';
				exit;
			}
			$vr1 = $realtime - $vr * 3600;
			$count = mysql_result(mysql_query("SELECT COUNT(*) FROM `" . $set['prefblog'] . "blogs` WHERE `time` > '" . $vr1 . "';"), 0);
				
			if ($count > 0)
			{
				echo '<div class="phdr"><a href="./">Блоги</a> | <strong>Все за период ' . $vr . ' часов</strong></div>';
				$res = mysql_query("SELECT * FROM `" . $set['prefblog'] . "blogs` WHERE `time` > '" . $vr1 . "' ORDER BY `time` DESC LIMIT " . $start . "," . $kmess);
				while ($row = mysql_fetch_assoc($res))
				{
					echo ($i % 2) ? '<div class="list2"><img src="img/b2.png" alt="&raquo;" width="14" height="14" /> ' : '<div class="list1"><img src="img/b1.png" alt="&raquo;" width="14" height="14" /> ';
					echo '<a href="?act=view&amp;id='.$row['id'].'">'.$row['name'].'</a>';
					if (mb_strlen($row['text']) > 150)
					{
						$text = mb_substr($row['text'], 0, 150);
						$text = checkout($text, 0, 2);
						echo '<div class="sub">'.$text.'...</div>';
					}
					else
					{
						echo '<div class="sub">'.checkout($row['text'], 0, 2).'</div>';
					}
					echo '<div class="func">';
					echo 'Автор: '.$row['from'].'<br />';
					echo '</div></div>';
					++$i;
				}
				if ($count > $kmess)
				{
					echo '<p class="menu">' . pagenav('index.php?act=ns&amp;do=all&amp;', $start, $count, $kmess) . '<br/>';
					echo '<form action="" method="POST">
					<input type="text" name="page" size="2"/> <input type="submit" value="Перейти"/></form></p>';
				}
			}
		break;
			
		case 'select' :
		echo '<div class="phdr"><b>Показать за период</b></div>';
		echo '<div class="list1"><form action="index.php?act=ns&amp;do=all" method="post">Период(в часах):<br/>';
		echo '<input type="text" maxlength="3" name="vr" value="24" size="3"/>';
		echo '<input type="hidden" name="act" value="ns"/><input type="hidden" name="do" value="all"/> <input type="submit" name="submit" value="Показать"/></form></div>';
		echo '<div class="phdr"><a href="index.php?act=ns">Назад</a></div>';
		break;
			
		default:
			$count = @ mysql_result(mysql_query('SELECT COUNT(*) FROM `' . $set['prefblog'] . 'blogs` LEFT JOIN `' . $set['prefblog'] . 'blogs_rdm` ON `' . $set['prefblog'] . 'blogs`.`id`=`' . $set['prefblog'] . 'blogs_rdm`.`topic_id` AND `' . $set['prefblog'] . 'blogs_rdm`.`user_id`=' . $user_id . ' WHERE `' . $set['prefblog'] . 'blogs_rdm`.`topic_id` Is Null OR `' . $set['prefblog'] . 'blogs`.`time`>`' . $set['prefblog'] . 'blogs_rdm`.`time`;'), 0);
			echo '<div class="phdr"><a href="./">Блоги</a> | Не прочитаные</div>';
			if($count>0)
			{
				$res = mysql_query("SELECT `" . $set['prefblog'] . "blogs`.* FROM `" . $set['prefblog'] . "blogs` LEFT JOIN `" . $set['prefblog'] . "blogs_rdm` ON `" . $set['prefblog'] . "blogs`.`id`=`" . $set['prefblog'] . "blogs_rdm`.`topic_id` AND `" . $set['prefblog'] . "blogs_rdm`.`user_id`='" . $user_id . "' WHERE `" . $set['prefblog'] . "blogs_rdm`.`topic_id` Is Null OR `" . $set['prefblog'] . "blogs`.`time`>`" . $set['prefblog'] . "blogs_rdm`.`time` ORDER BY `" . $set['prefblog'] . "blogs`.`time` DESC LIMIT " . $start . "," . $kmess);
				while ($row = mysql_fetch_assoc($res))
				{
					echo ($i % 2) ? '<div class="list2"><img src="img/b2.png" alt="&raquo;" width="14" height="14" /> ' : '<div class="list1"><img src="img/b1.png" alt="&raquo;" width="14" height="14" /> ';
					echo '<a href="?act=view&amp;id='.$row['id'].'">'.$row['name'].'</a>';
					if (mb_strlen($row['text']) > 150)
					{
						$text = mb_substr($row['text'], 0, 150);
						$text = checkout($text, 0, 2);
						echo '<div class="sub">'.$text.'...</div>';
					}
					else
					{
						echo '<div class="sub">'.checkout($row['text'], 0, 2).'</div>';
					}
					echo '<div class="func">';
					echo 'Автор: '.$row['from'].'<br />';
					echo '</div></div>';
					++$i;
				}
				if ($count > $kmess)
				{
					echo '<p class="menu">' . pagenav('index.php?act=ns&amp;id='.$id.'&amp;', $start, $count, $kmess) . '<br/>';
					echo '<form action="" method="POST">
					<input type="text" name="page" size="2"/><input type="submit" value="GO"/></form></p>';
				}
			}
			else
			{
				echo '<div class="menu">Не прочитаных статей нет</div>';
			}
			if($count>0)
			{
				echo '<div class="menu"><a href="?act=cleans">Сбросить</a></div>';
			}
			echo '<div class="menu"><a href="?act=ns&amp;do=select">Показать за период</a></div>';
		break;
	}
?>