<?php

define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);

$userdata = session_pagestart($user_ip, PAGE_PRAVILA);
init_userprefs($userdata);

if ( !$userdata['session_logged_in'] )
{
	redirect(append_sid("login.$phpEx?redirect=lenta.$phpEx", true));
	exit;
}

if ( isset($HTTP_POST_VARS['start1']) )
{
	$start1 = abs(intval($HTTP_POST_VARS['start1']));
	$start = (($start1 - 1) * $board_config['topics_per_page']);
} else {
	$start = ( isset($HTTP_GET_VARS['start']) ) ? intval($HTTP_GET_VARS['start']) : 0;
	$start = ($start < 0) ? 0 : $start;
}

$page_title = $lang['todo'];
$on_page = 15; // на страницу
include($phpbb_root_path . 'includes/page_header.'.$phpEx);

$template->set_filenames(array(
	'body' => 'lenta.tpl')
	);
	
	$sql = "SELECT * FROM ".TODO_TABLE." ORDER BY time desc";
			if ( !($result = $db->sql_query($sql)) )
			{
				message_die(GENERAL_ERROR , "Could not get");
			}
			$info = $db->sql_fetchrowset($result);
			for($i = $start; $i < count($info) & $i < $on_page + $start; $i++)
		{
			$mode[$i] = $info[$i]['mode'];
			$user_id[$i] = $info[$i]['user_id'];
			$to_id[$i] = $info[$i]['to_id'];
			$username[$i] = $info[$i]['username'];
			$to_name[$i] = $info[$i]['to_name'];
			$date = create_date($board_config['default_dateformat'], $info[$i]['time'], $board_config['board_timezone']);
	
			if($mode[$i] == $lang['todo_album_inc'] || $mode[$i] == $lang['todo_album_add'])
			{
				$to_name[$i] = '<a href="' . append_sid("album.$phpEx?action=pic&amp;pic_id=" .$to_id[$i]) . '">' .$to_name[$i]. '</a>';
			}
			elseif($mode[$i] == $lang['todo_album_comm'])
			{
				$to_name[$i] = '<a href="' . append_sid("album.$phpEx?action=comment&amp;comment_id=" .$to_id[$i]) . '">' .$to_name[$i]. '</a>';
			}
			elseif($mode[$i] == $lang['todo_group_add'] || $mode[$i] == $lang['todo_group_out'])
			{
				$to_name[$i] = '<a href="' . append_sid("groupcp.$phpEx?g=" .$to_id[$i]) . '">' .$to_name[$i]. '</a>';
			}
			else
			{
				$to_name[$i] = '<a href="' . append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . '='  . $to_id[$i]). '">' .$to_name[$i]. '</a>';
			}
			
			$template->assign_block_vars('info', array(
			'WHO' => '<a href="' . append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . '='  . $user_id[$i]) . '">' . $username[$i] . '</a>',
			'WHAT' => $mode[$i],
			'DATE' => $date,
			'WHOM' => $to_name[$i]
			));		
	}
	
		$pagination = ( count($info) > $on_page) ? generate_pagination("lenta.$phpEx?", count($info), $on_page, $start). '&nbsp;' : '&nbsp;';
		$template->assign_vars(array(
			'PAGE' => $pagination,
			'TITLES' => $lang['todo'] 
		));
		
	$template->pparse('body');

?>