<?php
	/*
	*by Krite (http://upcoder.net)
	*/
	defined('_IN_JOHNCMS') or die('Error: restricted access');
	$textl = 'Новые статьи';
	require_once('../incfiles/head.php');
	echo '<div class="phdr">'.$textl.'</div>';
	$old = $realtime - (3 * 24 * 3600);
	$count = mysql_result(mysql_query("SELECT COUNT(*) FROM `" . $set['prefblog'] . "blogs` WHERE `time`>'" . $old . "'".($rights > 7?'':' AND `mod`=0').";"), 0);
	if($count>0)
	{
		$res = mysql_query("SELECT * FROM `" . $set['prefblog'] . "blogs` WHERE `time`>'" . $old . "'".($rights > 7?'':' AND `mod`=0')." 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>';
			}
			$golos = @ mysql_result(mysql_query('SELECT COUNT(*) FROM `' . $set['prefblog'] . 'blogs_rat` WHERE `ref`='.$row['id'].';'), 0);
			$count = @ mysql_result(mysql_query('SELECT SUM(`count`) FROM `' . $set['prefblog'] . 'blogs_rat` WHERE `ref`='.$row['id'].';'), 0);
			$rating = @ floor($count / $golos);
			echo '<div class="func">Автор: <b>' . $row['from'] . '</b><br />';
			echo ($golos!=0) ? 'Рейтинг: <img src="img/star'.$rating.'.png" alt="'.$rating.'" width="50" height="10" /> | Голосов: <a href="?act=golosa&amp;id='.$row['id'].'">'.$golos.'</a><br />':'';
			echo 'Статья написана: '.date_n($row['time']).'<br />';
			echo 'Прочтений: '.$row['count'].'</div>';
			echo '</div>';
			++$i;
		}
		if ($count > $kmess)
		{
			echo '<p class="menu">' . pagenav('?act=new&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>';
	}
	echo "<p class='menu'><a href='./'>К категориям</a></p>";
?>