<?
if(!defined('DATALIFEENGINE')){die("Hacking attempt!");}

$limit = intval(  $config['torrent_number'] );
$count_all = $db->super_query("SELECT COUNT(*) as count FROM ".PREFIX."_torrents as torrents, ".PREFIX."_post as post WHERE torrents.news_id=post.id AND post.approve=1");
$posts = $count_all['count'];

if($posts){

    $page = intval( $_REQUEST['cstart'] );
    $total = intval( ( ( $posts - 1 ) / $limit ) + 1 );
	if( $page <= 0 ) $page = 1;
	if( $page > $total ) $page = $total;
    $start = $page * $limit - $limit;
	$i = $start;

			$result = $db->query("SELECT torrents.news_id, torrents.ctime, torrents.leechers, torrents.seeders, torrents.completed, torrents.size, post.category, post.alt_name, post.title FROM ".PREFIX."_torrents as torrents, ".PREFIX."_post as post WHERE torrents.news_id=post.id AND post.approve=1 ORDER BY post.date DESC LIMIT " . $start . "," . $limit);
			while($row = $db->get_row($result)){
                $i ++;
                $cat = "<a href=\"" . $config['http_home_url'] . get_url($row['category']) . "/\">".$cat_info[$row['category']]['name']."</a>";
				$news_link = "<a href='/".$row['news_id']."-".$row['alt_name'].".html'>".$row['title']."</a>";

                $top_table .= "<tr><td>$cat</td><td align=\"center\">$news_link</td><td style=\"color:#F55;\" align=\"center\">".$row['seeders']."</td><td style=\"color:#1FA800;\" align=\"center\">".$row['leechers']."</td><td style=\"color:#5579FF;\" align=\"center\">".$row['completed']."</td><td align=\"center\">".mksize($row['size'])."</td><td align=\"center\">".date("j.m.Y", $row['ctime'])."</td></tr>";
			}
        $tpl->load_template('tracker.tpl');
		$tpl->set('{list}', $top_table);
	    $tpl->compile( 'content' );
	    $tpl->clear();

        $nav = "/tracker/page/{page}";
        CreateNavigation( $nav, $page, $total );
        $db->free($result);
} else {
    msgbox("Ошибка", "Загруженные торренты отсутвуют");
}
?>