<?php
/**
*
* @package ppkBB3cker
* @version $Id: viewtopic_add1_leech.php 1.000 2009-02-21 14:13:00 PPK $
* @copyright (c) 2008, 2009 PPK
* http://ppkbb3cker.rx22.ru, http://protoneutron.narod.ru
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
	exit;
}
					$sort_opt[$torrent_opt]=array('username', 'downloaded', 'uploaded', 'ratio', 'startdat', 'to_go', 'connectable', 'upspeed', 'downspeed');
					if(!in_array($opt_param, $sort_opt[$torrent_opt]))
					{
						$opt_param=$sort_opt[$torrent_opt][0];
					}
						foreach($sort_opt[$torrent_opt] as $v)
						{
							$postrow=array_merge($postrow, array(
								'TORRENT_SORT_HEADER_'.strtoupper($v) => "$viewtopic_url&amp;opt={$torrent_opt}&amp;opts=".($opt_sort=='DESC' ? 'ASC' : 'DESC')."&amp;optp={$v}#opt",
										)
									);
						}
						if($opt_param=='ratio')
						{
							$sql_addon="p.uploaded/p.downloaded $opt_sort";
						}
						else if($opt_param=='username')
						{
							$sql_addon="u.$opt_param $opt_sort";
						}
						else if($opt_param=='upspeed')
						{
							$sql_addon="p.uploadoffset/(p.last_action-p.prev_action) $opt_sort";
						}
						else if($opt_param=='downspeed')
						{
							$sql_addon="p.downloadoffset/(p.last_action-p.prev_action) $opt_sort";
						}
						else
						{
							$sql_addon="p.$opt_param $opt_sort";
						}

					$is_admod=$auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_') ? 1 : 0;
					$result=$db->sql_query('SELECT p.*, u.username, u.user_id, u.user_colour FROM '. TRACKER_PEERS_TABLE ." p LEFT JOIN ". USERS_TABLE ." u ON p.userid=u.user_id WHERE p.torrent='$torrent_id' AND seeder='no' ORDER BY p.seeder ASC, u.username");
					while($userlist=$db->sql_fetchrow($result))
					{
						if($userlist['userid']==$user->data['user_id'] || $is_admod)
						{

						}
						else
						{
							$userlist['ip']='';
							$userlist['port']='';
						}
						$i3+=1;
						$secs = max(10, ($userlist['last_action']) - $userlist['prev_action']);
						$assign_vars[$i3]['TORRENT_USER'] = !empty($userlist['username']) ? get_username_string('full', $userlist['user_id'], $userlist['username'], $userlist['user_colour'], $userlist['username']) : '&nbsp;';
						$assign_vars[$i3]['TORRENT_UP'] = get_formatted_filesize($userlist['uploaded'], 0).' '.get_size_lang($userlist['uploaded']);
						$assign_vars[$i3]['TORRENT_UPSP'] = get_formatted_filesize($userlist['uploadoffset'] / $secs, 0).' '.get_size_lang($userlist['uploadoffset'] / $secs, 1);
						$assign_vars[$i3]['TORRENT_DOWN'] = get_formatted_filesize($userlist['downloaded'], 0).' '.get_size_lang($userlist['downloaded']);
						$assign_vars[$i3]['TORRENT_DOWNSP'] = get_formatted_filesize($userlist['downloadoffset'] / $secs, 0).' '.get_size_lang($userlist['downloadoffset'] / $secs, 1);
						$assign_vars[$i3]['TORRENT_RATIO'] = get_ratio($userlist['uploaded'], $userlist['downloaded']);
						$assign_vars[$i3]['TORRENT_COMPLETED'] = sprintf("%.2f%%", 100 * (1 - ($userlist["to_go"] / $torrents[$userlist['torrent']]['size'])));
						$assign_vars[$i3]['TORRENT_A'] = get_time_diff($userlist['startdat'], time());
						//$assign_vars[$i3]['TORRENT_INA'] = get_time_diff($userlist['last_action'], time());
						$assign_vars[$i3]['TORRENT_UCONN'] = $userlist['connectable']=='yes' ? $user->lang['YES'] : $user->lang['NO'];
						$assign_vars[$i3]['TORRENT_AGENT'] = htmlspecialchars($userlist['agent']);
						$assign_vars[$i3]['TORRENT_IP'] = htmlspecialchars($userlist['ip']);
						$assign_vars[$i3]['TORRENT_PORT'] = htmlspecialchars($userlist['port']);
					}
					$torrent_info_curr=$torrent_opt;
					$torrent_info[$torrent_opt]='<b>'.$torrent_info[$torrent_opt].'</b> ('.$i3.')';
					$torrent_info_curr_explain[$torrent_opt]=$user->lang['TORRENT_LEECH'];
?>