<?php
/**
*
* @package ppkBB3cker
* @version $Id: memberlist_add1_finished.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('topic_title', 'downloaded', 'uploaded', 'ratio', 'seeder', 'downtime');
					if(!in_array($opt_param, $sort_opt[$torrent_opt]))
					{
						$opt_param=$sort_opt[$torrent_opt][0];
					}
						foreach($sort_opt[$torrent_opt] as $v)
						{
							$template->assign_vars(array(
								'TORRENT_SORT_HEADER_'.strtoupper($v) => "{$memberlist_url}&amp;opt={$torrent_opt}&amp;opts=".($opt_sort=='DESC' ? 'ASC' : 'DESC')."&amp;optp={$v}#opt",
										)
									);
						}
						if($opt_param=='ratio')
						{
							$sql_addon="s.uploaded/s.downloaded $opt_sort";
						}
						else if($opt_param=='downtime')
						{
							$sql_addon="s.completedat-s.startdat $opt_sort";
						}
						else
						{
							$sql_addon="$opt_param $opt_sort";
						}

					$sql='SELECT s.*, t.topic_title, t.topic_first_post_id FROM '. TRACKER_SNATCHED_TABLE ." s LEFT JOIN ".ATTACHMENTS_TABLE." a ON s.torrent=a.attach_id LEFT JOIN ".TOPICS_TABLE." t ON a.post_msg_id=t.topic_first_post_id WHERE s.userid='$user_id' AND s.finished='yes' ORDER BY $sql_addon";
					$result=$db->sql_query($sql);
					while($userlist=$db->sql_fetchrow($result))
					{
						$i3+=1;
						$assign_vars[$i3]['TORRENT_NAME'] = $userlist['topic_title'] ? "<a href='".append_sid("{$phpbb_root_path}viewtopic.$phpEx", "p={$userlist['topic_first_post_id']}")."#p{$userlist['topic_first_post_id']}'>{$userlist['topic_title']}</a>" : '&nbsp;';
						$assign_vars[$i3]['TORRENT_UP'] = get_formatted_filesize($userlist['uploaded'], 0).' '.get_size_lang($userlist['uploaded']);
						$assign_vars[$i3]['TORRENT_DOWN'] = get_formatted_filesize($userlist['downloaded'], 0).' '.get_size_lang($userlist['downloaded']);
						$assign_vars[$i3]['TORRENT_RATIO'] = get_ratio($userlist['uploaded'], $userlist['downloaded']);
						$assign_vars[$i3]['TORRENT_NOWSEED'] = $userlist['seeder']=='yes' ? $user->lang['TORRENT_INFO_HEADER_NOWSEED_YES'] : $user->lang['TORRENT_INFO_HEADER_NOWSEED_NO'];
						$assign_vars[$i3]['TORRENT_DOWNTIME'] = get_time_diff($userlist['startdat'], $userlist['completedat']);
					}
					$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_WHOFINISHED'];
?>