<?
// phpbandwidth by Alexander Wigen
include("db_config.php");
include("db_$db[type].php");
include("user_functions.php");
include("header.php");
$conn = db_connect();
$users = db_get_users($conn);
echo "<h2>User stats for $users[$uid] in ".date("F", mktime(0,0,0,$current_month,$day,$current_year))."</h2>";
$day_today = date("d");
$days_in_month = date("t", mktime(0,0,0,$current_month,$day,$current_year));
$bw = array();
for ($day=1; $day < $days_in_month; $day++)
$bw[$day] = conv_mb(db_bandwidht_for_day($conn, $uid, $current_year, $current_month, $day));
rsort($bw, SORT_NUMERIC);
reset($bw);
$largest = current($bw);
unset($bw);
echo "<table border=0>";
if ($current_month == date('m') && $current_year == date('Y')){
for ($day=1; $day < $day_today; $day++)
{
$megabytes = conv_mb(db_bandwidht_for_day($conn, $uid, $current_year, $current_month, $day));
$bw[$day] = conv_mb(db_bandwidht_for_day($conn, $uid, $current_year, $current_month, $day));
if ($largest)
$prosent = $megabytes/$largest *100 ."%";
print_day($day, $prosent, $megabytes);
}
$bandwidth = fill_bandwidth_array($conn, $uid);
$megabytes = $bandwidth[today_total];
if ($largest < $bandwidth[today_total])
$largest = $bandwidth[today_total];
if ($largest)
$prosent = $megabytes/$largest *100 ."%";
print_day($day, $prosent, $bandwidth[today_total]);
}
else
for ($day=1; $day <= $days_in_month; $day++){
$megabytes = conv_mb(db_bandwidht_for_day($conn, $uid, $current_year, $current_month, $day));
$bw[$day] = conv_mb(db_bandwidht_for_day($conn, $uid, $current_year, $current_month, $day));
if ($largest)
$prosent = $megabytes/$largest *100 ."%";
print_day($day, $prosent, $megabytes);
}
echo "</table>";
function print_day($day, $prosent, $megabytes)
{
global $uid, $current_year, $current_month;
echo "<tr>";
echo "<td align=right><b>".date("l jS", mktime(0,0,0,$current_month,$day,$current_year))."</b></td>";
echo "<td><a href=\"bw_image_html.php?uid=$uid&year=$current_year&month=$current_month&day=$day&width=1000&heigth=250\"><img width=200 height=25 src=\"bw_image.php?uid=$uid&year=$current_year&month=$current_month&day=$day&width=200&heigth=25\"></a></td>";
echo "<td align=right><b>".number_format($megabytes,0,'','')."MB</b></td>";
echo "<td>".html_bar(200,$prosent)."</td>";
echo "</tr>";
}
?>