<?php
//KasP DETECTED
define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
include($phpbb_root_path . 'includes/functions_news.'.$phpEx);
if (!empty($board_config['index_announcement']))
{
	include($phpbb_root_path . 'includes/bbcode.'.$phpEx);
}
if ( isset($HTTP_POST_VARS['start1']) )
{
$start1 = abs(intval($HTTP_POST_VARS['start1']));
$start = (($start1 - 1) * $board_config['posts_per_page']);
} else {
$start = ( isset($HTTP_GET_VARS['start']) ) ? intval($HTTP_GET_VARS['start']) : 0;
$start = ($start < 0) ? 0 : $start;
}
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);

$CFG['news_forum'] = '21'; //ID форума

define('SHOW_ONLINE', true);
$page_title = $lang['Index'];
include($phpbb_root_path . 'includes/page_header.'.$phpEx);

$template->set_filenames(array(
	'body' => 'news_body.tpl')
);

$time = time();
$lastnews = mysql_result(mysql_query( 'SELECT COUNT(topic_id) FROM phpbb_topics 
WHERE forum_id = '.$CFG['news_forum'].'
AND topic_time >= '.($time-( 86400 ))),0);
if ((int)$lastnews[0] == 0 )
{	
 $lastnews = '';
}else{	
 $lastnews = '/+'.(int)$lastnews[0];
};

$news = mysql_result(mysql_query( 'SELECT COUNT(topic_id) FROM phpbb_topics 
WHERE forum_id = '.$CFG['news_forum']),0);

if(!isset($HTTP_GET_VARS['news_id']))
{
	$template->assign_block_vars('welcome_text', array());

	$fetchposts = phpbb_fetch_posts($CFG['news_forum'], 0, $CFG['news_length']);
	$total = count($fetchposts);
	$pagination = ($news > 5) ? generate_pagination("news.$phpEx?", $total, 5, $start) : generate_pagination("news.$phpEx?", $total, 5, $start);
	$template->assign_vars(array(
			'PAGE' => $pagination)
		);
	for ($i = $start; $i < $total && $i < 5 + $start; $i++)
	{
		if( $fetchposts[$i]['striped'] == 1 )
		{
			$open_bracket = '';
			$close_bracket = '';
			$read_full = '&raquo;';
		}
		else
		{
			$open_bracket = '';
			$close_bracket = '';
			$read_full = '';
		}

		$template->assign_block_vars('fetchpost_row', array(
			'TITLE' => $fetchposts[$i]['topic_title'],
			'POSTER' => $fetchposts[$i]['username'],
			'TIME' => $fetchposts[$i]['topic_time'],
			'TEXT' => $fetchposts[$i]['post_text'],
			'REPLIES' => $fetchposts[$i]['topic_replies'],
			'U_VIEW_COMMENTS' => append_sid('viewtopic.' . $phpEx . '?t=' . $fetchposts[$i]['topic_id']),
			'U_POST_COMMENT' => append_sid('posting.' . $phpEx . '?mode=reply&amp;t=' . $fetchposts[$i]['topic_id']),
			'U_READ_FULL' => append_sid('index.' . $phpEx . '?news_id=' . $i),
			'L_READ_FULL' => $read_full,
			'OPEN' => $open_bracket,
			'CLOSE' => $close_bracket)
		);
	}
}
else
{
	$template->set_filenames(array(
	'body' => 'fullnews_body.tpl')
);
	$fetchposts = phpbb_fetch_posts($CFG['news_forum'], 0, 0);

	$i = intval($HTTP_GET_VARS['news_id']);

	$template->assign_block_vars('fetchpost_row', array(
		'TITLE' => $fetchposts[$i]['topic_title'],
		'VIEWS' => $fetchposts[$i]['topic_views'],
		'POSTER' => $fetchposts[$i]['username'],
		'TIME' => $fetchposts[$i]['topic_time'],
		'TEXT' => $fetchposts[$i]['post_text'],
		'REPLIES' => $fetchposts[$i]['topic_replies'],
		'U_VIEW_COMMENTS' => append_sid('viewtopic.' . $phpEx . '?t=' . $fetchposts[$i]['topic_id']),
		'U_POST_COMMENT' => append_sid('posting.' . $phpEx . '?mode=reply&amp;t=' . $fetchposts[$i]['topic_id'])
		)
	);
}

$template->pparse('body');

include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
//KasP DETECTED
?>