<?php
/**
*
* @package ppkBB3cker
* @version $Id: viewtopic_add1.php 1.000 2009-03-02 12:14: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;
}

		$is_canusefree = ($auth->acl_get('u_canusefree') && $auth->acl_get('f_canusefree', $forum_id)) ? 1 : 0;
		$is_canusebonus = ($auth->acl_get('u_canusebonus') && $auth->acl_get('f_canusebonus', $forum_id)) ? 1 : 0;

		$is_canskiprcheck = $user->data['user_id']!=$poster_id ? (($auth->acl_get('u_canskiprcheck') && $auth->acl_get('f_canskiprcheck', $forum_id)) ? 1 : 0) : 1;
		$is_canskiprequpload = $user->data['user_id']!=$poster_id ? (($auth->acl_get('u_canskiprequpload') && $auth->acl_get('f_canskiprequpload', $forum_id)) ? 1 : 0) : 1;
		$is_canskipreqratio = $user->data['user_id']!=$poster_id ? (($auth->acl_get('u_canskipreqratio') && $auth->acl_get('f_canskipreqratio', $forum_id)) ? 1 : 0) : 1;

		$user_ratio=get_ratio($user->data['user_uploaded'], $user->data['user_downloaded'], $config['ppkbb_tcratio_start'], $user->data['user_bonus']);

		$t_elapsed = intval((time() - @$torrents[$torrent_id]['added']) / 3600);
		$t_wait=-1;
		if(!$is_canskiprcheck && $config['ppkbb_tcwait_time'])
		{
			$t_wait=get_trestricts($user->data['user_uploaded'], $user->data['user_downloaded'], $user_ratio, $config['ppkbb_tcwait_time'], 'up');

			if ($t_wait > 0)
			{
				$t_elapsed < $t_wait ? $t_wait=$t_wait - $t_elapsed : $t_wait=-1;
			}
		}
		$t_wait2=-1;
		if(!$is_canskiprcheck && $config['ppkbb_tcwait_time2'])
		{
			$t_wait2=get_trestricts($user->data['user_uploaded'], $user->data['user_downloaded'], $user_ratio, $config['ppkbb_tcwait_time2']);
			if ($t_wait2 > 0)
			{
				$t_elapsed < $t_wait2 ? $t_wait2=$t_wait2 - $t_elapsed : $t_wait2=-1;
			}
		}

		$torrent_opt=request_var('opt', '');
		$torrent_info_curr='';

		$torrent_info_curr_explain=array();
		$assign_vars=array();
		$torrent_info=array();
		$torrent_stat=array();
		$torrent_action=array();
		$sort_opt=array();

		if($torrent_id)
		{
			isset($r_seeders[$torrent_id]) ? $torrents[$torrent_id]['seeders']=$r_seeders[$torrent_id] : '';
			isset($r_leechers[$torrent_id]) ? $torrents[$torrent_id]['leechers']=$r_leechers[$torrent_id] : '';

			$torrent_info['filelist']="<a href='$viewtopic_url&amp;opt=filelist&amp;optp=filename#opt'>{$user->lang['TORRENT_FILELIST']}</a>";
			$torrent_info['finished']="<a href='$viewtopic_url&amp;opt=finished&amp;optp=username#opt'>{$user->lang['TORRENT_WHOFINISHED']}</a>";
			$torrent_info['seed']="<a href='$viewtopic_url&amp;opt=seed&amp;optp=username#opt'>{$user->lang['TORRENT_SEED']}</a>";
			$torrent_info['leech']="<a href='$viewtopic_url&amp;opt=leech&amp;optp=username#opt'>{$user->lang['TORRENT_LEECH']}</a>";
			$torrent_info['thanks']="<a href='$viewtopic_url&amp;opt=thanks&amp;optp=username#opt'>{$user->lang['TORRENT_SAYTHANKS']}</a>";
			$torrent_info['history']="<a href='$viewtopic_url&amp;opt=history&amp;optp=username#opt'>{$user->lang['TORRENT_HISTORY']}</a>";
			$torrent_info['leave']="<a href='$viewtopic_url&amp;opt=leave&amp;optp=username#opt'>{$user->lang['TORRENT_LEAVE']}</a>";

			$opt_sort=request_var('opts', '');
			$opt_param=request_var('optp', '');
			$opt_sort=='ASC' ? '' : $opt_sort='DESC';

			$torrent_stat[]=$user->lang['TORRENT_ADDED'].': <b>'.$user->format_date($torrents[$torrent_id]['added']).'</b>';
			$torrent_stat[]=$user->lang['TORRENT_SEEDERS'].': <b>'.$torrents[$torrent_id]['seeders'].'</b>';
			$torrent_stat[]=$user->lang['TORRENT_LEECHERS'].': <b>'.$torrents[$torrent_id]['leechers'].'</b>';
			$torrent_stat[]=$user->lang['TORRENT_COMPLETED'].': <b>'.$torrents[$torrent_id]['times_completed'].'</b>';
			$torrent_stat[]=$user->lang['TORRENT_HEALTH'].': <b>'.get_torrent_health($torrents[$torrent_id]['seeders'], $torrents[$torrent_id]['leechers']).'%</b>';
			if($torrents[$torrent_id]['times_completed'])
			{
				$torrent_stat[]=$user->lang['TORRENT_PERCENT'].': <b>'.intval($torrents[$torrent_id]['seeders'] * 100 / $torrents[$torrent_id]['times_completed']).'%</b>';
			}
			$torrent_stat[]=$user->lang['TORRENT_SIZE'].': <b>'.get_formatted_filesize($torrents[$torrent_id]['size'], false).'</b> '.get_size_lang($torrents[$torrent_id]['size']);
			$torrent_stat[]=$user->lang['TORRENT_SIZE'].': <b>'.number_format($torrents[$torrent_id]['size'], 0, '.', ' ').'</b> '.$user->lang['BYTES'];
			$torrent_stat[]=$user->lang['TORRENT_HASH'].': <div style="overflow:auto;height:40px;width:'.intval($config['ppkbb_tmax_thumbwidth']+100/2).'px;"><b>'.$torrents[$torrent_id]['info_hash'].'</b><br /></div>';

			$dthanks=0;
			if(!$torrents[$torrent_id]['thanks'] && $torrents[$torrent_id]['poster_id']!=$user->data['user_id'] && $is_canusethanks)
			{
				$say_thanks=request_var('say_thanks', '');
				!$say_thanks ? $say_thanks=(request_var('say_thanks_x', '') || request_var('say_thanks_y', '')) : '';
				if(@$say_thanks)
				{
					$result=$db->sql_query('INSERT INTO '. TRACKER_THANKS_TABLE ." VALUES (0, '{$user->data['user_id']}', '$torrent_id', '{$torrents[$torrent_id]['poster_id']}')");
					$dthanks=1;
				}
				!$dthanks ? $torrent_action[]='<form action="'. $viewtopic_url .'&amp;opt=thanks#opt" method="post"><input type="submit" name="say_thanks" value="'.$user->lang['TORRENT_ACTION'].'" /> '.$user->lang['TORRENT_INFO_HEADER_SAYTHANKS'].'</form>' : '';
			}

			$i3=0;
			!$is_candowntorr ? $torrent_opt='' : '';
			$viewtopic_add1inc=$phpbb_root_path.'tracker/include/';
			switch($torrent_opt)
			{
				case 'leave':
					include($viewtopic_add1inc.'viewtopic_add1_leave.'.$phpEx);
					break;

				case 'history':
					include($viewtopic_add1inc.'viewtopic_add1_history.'.$phpEx);
					break;

				case 'filelist':
					include($viewtopic_add1inc.'viewtopic_add1_filelist.'.$phpEx);
					break;

				case 'finished':
					include($viewtopic_add1inc.'viewtopic_add1_finished.'.$phpEx);
					break;

				case 'seed':
					include($viewtopic_add1inc.'viewtopic_add1_seed.'.$phpEx);
					break;

				case 'leech':
					include($viewtopic_add1inc.'viewtopic_add1_leech.'.$phpEx);
					break;

				case 'thanks':
					include($viewtopic_add1inc.'viewtopic_add1_thanks.'.$phpEx);
					break;

				default:
					$torrent_opt=0;
					break;
			}
			$db->sql_freeresult($result);
		}

		$postrow=array_merge($postrow, array(
			'S_HAS_TRACKER_POSTER'	=> (@$torrents_attach['poster']) ? true : false,
			'S_HAS_TRACKER_TORRENT'	=> (@$torrents_attach['torrent']) ? true : false,
			'S_HAS_TRACKER_SCREENSHOT'	=> (@$torrents_attach['screenshot']) ? true : false,
			'S_HAS_TORRENT_EXPLAIN'	=> $torrent_info_curr ? true : false,
			'S_HAS_TORRENT_EXPLAIN_FILELIST'	=> @$torrent_info_curr_explain['filelist'] ? true : false,
			'S_HAS_TORRENT_EXPLAIN_FINISHED'	=> @$torrent_info_curr_explain['finished'] ? true : false,
			'S_HAS_TORRENT_EXPLAIN_THANKS'	=> @$torrent_info_curr_explain['thanks'] ? true : false,
			'S_HAS_TORRENT_EXPLAIN_HISTORY'	=> @$torrent_info_curr_explain['history'] ? true : false,
			'S_HAS_TORRENT_EXPLAIN_LEAVE'	=> @$torrent_info_curr_explain['leave'] ? true : false,
			'S_HAS_TORRENT_EXPLAIN_SEED'	=> @$torrent_info_curr_explain['seed'] ? true : false,
			'S_HAS_TORRENT_EXPLAIN_LEECH'	=> @$torrent_info_curr_explain['leech'] ? true : false,
			'MESS_FORUM_IMAGE'			=> $forum_image ? '<img src="' . $phpbb_root_path . $forum_image . '" alt="' . $topic_data['forum_name'] . '"  title="' . $topic_data['forum_name'] . '"/>' : '',
			'TORRENT_INFO_OPT2'=>implode('<br />', $torrent_stat),
			'TORRENT_INFO_OPT3'=>implode('<br />', $torrent_action),
			'TORRENT_INFO_OPT'=>$is_candowntorr ? implode(' : ', $torrent_info) : '',
		));
?>