function get_bt_userdata ($user_id, $update = true)
{
global $bb_cfg;
if($update)
{
$resoult = DB()->fetch_row("
SELECT bt.*, SUM(tr.speed_up) as speed_up, SUM(tr.speed_down) as speed_down
FROM ". BB_BT_USERS ." bt
LEFT JOIN ". BB_BT_TRACKER ." tr ON (bt.user_id = tr.user_id)
WHERE bt.user_id = ". (int) $user_id ."
GROUP BY bt.user_id
");
if($resoult)
{
$resoult['expire'] = TIMENOW + $bb_cfg['userstat']['cache']*60*60;
CACHE('bb_cache')->set('userstat['.$user_id.']', $resoult, $bb_cfg['userstat']['cache']*60*60);
}
}
else
{
if (!$resoult = CACHE('bb_cache')->get('userstat['.$user_id.']'))
{
$resoult = DB()->fetch_row("
SELECT bt.*, SUM(tr.speed_up) as speed_up, SUM(tr.speed_down) as speed_down
FROM ". BB_BT_USERS ." bt
LEFT JOIN ". BB_BT_TRACKER ." tr ON (bt.user_id = tr.user_id)
WHERE bt.user_id = ". (int) $user_id ."
GROUP BY bt.user_id
");
if($resoult)
{
$resoult['expire'] = TIMENOW + $bb_cfg['userstat']['cache']*60*60;
CACHE('bb_cache')->set('userstat['.$user_id.']', $resoult, $bb_cfg['userstat']['cache']*60*60);
}
}
else
{
$resoult = CACHE('bb_cache')->get('userstat['.$user_id.']');
}
}
return $resoult;
}
function show_bt_userdata_only ()
{
global $lang, $userdata;
$btu = get_bt_userdata($userdata['user_id'], false);
$GLOBALS['template']->assign_vars(array(
'SHOW_BT_RATE' => true,
));
$GLOBALS['template']->assign_block_vars('rate', array(
'UP_TOTAL' => humn_size($btu['u_up_total']),
'UP_BONUS' => humn_size($btu['u_up_bonus']),
'RELEASED' => humn_size($btu['u_up_release']),
'DOWN_TOTAL' => humn_size($btu['u_down_total']),
'DOWN_TOTAL_BYTES' => $btu['u_down_total'],
'USER_RATIO' => get_bt_ratio($btu),
'MIN_DL_FOR_RATIO' => humn_size(MIN_DL_FOR_RATIO),
'MIN_DL_BYTES' => MIN_DL_FOR_RATIO,
'AUTH_KEY' => ($btu['auth_key']) ? $btu['auth_key'] : $lang['NONE'],
'TD_DL' => humn_size($btu['down_today']),
'TD_UL' => humn_size($btu['up_today']),
'TD_REL' => humn_size($btu['up_release_today']),
'TD_BONUS' => humn_size($btu['up_bonus_today']),
'TD_POINTS' => ($btu['auth_key']) ? $btu['points_today'] : '0.00',
'YS_DL' => humn_size($btu['down_yesterday']),
'YS_UL' => humn_size($btu['up_yesterday']),
'YS_REL' => humn_size($btu['up_release_yesterday']),
'YS_BONUS' => humn_size($btu['up_bonus_yesterday']),
'YS_POINTS' => ($btu['auth_key']) ? $btu['points_yesterday'] : '0.00',
'SPEED_UP' => humn_size($btu['speed_up'], 0, 'KB') .'/s',
'SPEED_DOWN' => humn_size($btu['speed_down'], 0, 'KB') .'/s',
'TIME_UDATE_STATS' => bb_date($btu['expire']),
'POINTS' => $userdata['user_points'],
'USER_ID' => $userdata['user_id'],
'AVATAR' => get_avatar($userdata['user_id'], $userdata['avatar_ext_id'], !bf($userdata['user_opt'], 'user_opt', 'dis_avatar')),
));
}