<?php
if (! defined ( 'BLOCK_FILE' )) {
	if (function_exists ( "location" ))
		location ( "../index.php" );
	else
		die ();
	exit ();
}
global $CURUSER, $CURGROUP, $tracker_lang, $minvotes, $img_on_server, $pic_base_url, $nowink_cache, $ALLGROUPS;
$blocktitle = "Новинки";
$page = ( int ) $_GET ["page"];
$content = ReadCache ( 'block-nowvink/nowvink-id' . $page, true, false, $nowink_cache );
if (! $content) {
	$content .= "<table cellspacing=\"0\" cellpadding=\"5\" width=\"100%\" border=0>";
	$perpage = 5;
	$withontop = 1; // 1 - ограничение на поле ontop, 0 - без ограничения
	$count = get_row_count ( "torrents", $withontop ? "WHERE ontop='yes'" : "" );
	list ( $pagertop, $pagerbottom, $limit ) = pager ( $perpage, $count, $_SERVER ["PHP_SELF"] . "?" );
	/// MOD INCAT ///
	$sql = "SELECT torrents.name, torrents.hide, torrents.poster AS poster, torrents.descr, torrents.id, torrents.comments, torrents.leechers, torrents.seeders, torrents.free AS free, torrents.numratings, torrents.ratingsum, categories.name AS cname, categories.image AS cimage, incat.name AS iname, incat.image AS iimage, IF(torrents.numratings < $minvotes, NULL, ROUND(torrents.ratingsum / torrents.numratings, 1)) AS rating, visible, category, incat, users.group FROM torrents LEFT JOIN categories ON torrents.category = categories.id LEFT JOIN incat ON torrents.incat = incat.id LEFT JOIN users ON users.id=torrents.owner " . ($withontop ? "WHERE ontop='yes'" : "") . " ORDER BY torrents.added DESC $limit";
	/// MOD INCAT ///
	$result = mysql_query ( $sql ) or die ( 'No torrents found' );
	if (! mysql_num_rows ( $result ))
		$content .= "<tr><td><div align=\"center\"><h3>Нет новинок</h3></div></td></tr></table>\n";
	else {
		include "include/codecs.php";
		$maxsymbols = 500; // Макс. кол-во символов в тексте, установите 0, для снятия ограничений.
		while ( $row = mysql_fetch_assoc ( $result ) ) {
			if (! $row ['poster'])
				$row ['poster'] = $pic_base_url . '/no_poster.png';
			$catid = $row ["category"];
			$incatid = $row ["incat"];
			$poster = "" . $row ["poster"] . "";
			$content .= "<tr><td style='border: none;'>";
			$content .= '<table class="main" border="0" cellpadding="5" cellspacing="0" width="100%"><tbody><tr>';
			$content .= '<td class="colhead"';
			$content .= ' colspan="2"';
			$content .= ' align="center">';
			$content .= '<b>' . htmlspecialchars_uni ( $row ['name'] ) . ' </b>';
			if ($row ['free'] == 'yes')
				$content .= ' <img src="' . $pic_base_url . 'freedownload.gif" border=0 title="Золотой торрент" alt="Золотой торрент">';
			$content .= '    </td>';
			$content .= '</tr><tr valign="top"><td align="center" width="160" style="\border: 0;\">';
			/// MOD INCAT ///
			$content .= '<img src="' . ($img_on_server ? 'torrents/images/' : '') . '' . $row ['poster'] . '" width="200"></td><td style="\border: none;\"><div align="left">' . WriteCurgroup ( '<a href="browse.php?cat=' . $row ['category'] . '">', '$CURGROUP ["can_browse"]' ) . '<img tooltip="' . htmlspecialchars_uni ( $row ['cname'] ) . '" src="' . $pic_base_url . 'cats/' . htmlspecialchars_uni ( $row ['cimage'] ) . '" align="right" border="0">' . WriteCurgroup ( '</a>', '$CURGROUP ["can_browse"]' );
			//$content .= '<img src="' . ($img_on_server ? 'torrents/images/' : '') . '' . $row ['poster'] . '" width="200"></td><td style="\border: none;\"><div align="left">' . WriteCurgroup ( '<a href="browse.php?cat=' . $row ['category'] . '">', '$CURGROUP ["can_browse"]' ) . '<img tooltip="' . htmlspecialchars_uni ( $row ['cname'] ) . '" src="image.php?image1=' . htmlspecialchars_uni ( $row ['cimage'] ) . '&image2=' . htmlspecialchars_uni ( $row ['iimage'] ) . '" align="right" border="0">' . WriteCurgroup ( '</a>', '$CURGROUP ["can_browse"]' );
			if ($incatid) {
				$content .= WriteCurgroup ( '<a href="browse.php?incat=' . $row ['incat'] . '">', '$CURGROUP ["can_browse"]' ) . '<img tooltip="' . $row ['iname'] . '"  src="' . $pic_base_url . 'cats/' . $row ['iimage'] . '" align="right" border="0" height="30" width="30">' . WriteCurgroup ( '</a>', '$CURGROUP ["can_browse"]' ) . '</div>';
			}
			/// MOD INCAT ///
			$descr = strlen ( $row ['descr'] ) > $maxsymbols && $maxsymbols ? substr ( format_comment ( $row ['descr'], true, $ALLGROUPS [$row ['group']] ['can_usepsmile'] ), 0, $maxsymbols ) . "..." : format_comment ( $row ['descr'], true, $ALLGROUPS [$row ['group']] ['can_usepsmile'] );
			$content .= '' . $descr . '';
			$content .= '</div><tr><td style="\border: none;\"><center>';
			
			if (! isset ( $row ["rating"] )) {
				if ($minvotes > 1) {
					$content .= sprintf ( $tracker_lang ['not_enough_votes'], $minvotes );
					if ($row ["numratings"])
						$content .= sprintf ( $tracker_lang ['only_votes'], $row ["numratings"] );
					else
						$content .= $tracker_lang ['none_voted'];
					$content .= ")";
				} else
					$content .= $tracker_lang ['no_votes'];
			} else {
				$rpic = ratingpic ( $row ["rating"] );
				if (! isset ( $rpic ))
					$content .= $tracker_lang ['none_voted'];
				else
					$content .= $rpic;
			
			}
			
			$content .= '</center></td><td style="\border: none;\"><div align="right">Раздают: <font color="red">' . $row ['seeders'] . '&nbsp;&nbsp;</font> Качают: <font color="green">' . $row ['leechers'] . '</font> &nbsp;&nbsp;Комментариев: ' . $row ['comments'] . ' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' . WriteCurgroup ( '[<a tooltip="' . $row ['name'] . '" href="details.php?id=' . $row ['id'] . '" alt="' . $row ['name'] . '"><b>Подробнее</b></a>]', '$CURGROUP ["can_details"]' ) . '</div></tr></td></tr></tbody>';
			$content .= '</tr></table>';
			$content = WriteCurgroup ( $content, '($CURGROUP ["can_viewhidden"] && ' . $row ["hide"] . ' == "yes") || ' . $row ["hide"] . ' == "no"' );
		}
		$content .= "<tr><td style='border: none'>";
		$content .= $pagerbottom;
		$content .= "</td></tr>";
		$content .= "</table>";
	}
	$content = WriteCurgroup ( $content, '$CURGROUP ["can_nowvink"]' );
	$content = WriteCache ( $content, "", $nowink_cache );
}
?>