require "include/bittorrent.php";
dbconn(false);
loggedinorreturn();
if (get_user_class() < UC_MODERATOR)
stderr( _("Error"), _("Permission denied."));
stdhead("Stats");
?>
begin_main_frame();
$res = do_mysql_query("SELECT COUNT(*) FROM torrents") or sqlerr(__FILE__, __LINE__);
$n = mysql_fetch_row($res);
$n_tor = $n[0];
$res = do_mysql_query("SELECT COUNT(*) FROM peers") or sqlerr(__FILE__, __LINE__);
$n = mysql_fetch_row($res);
$n_peers = $n[0];
$uporder = $_GET['uporder'];
$catorder = $_GET["catorder"];
if ($uporder == "lastul")
$orderby = "last DESC, name";
elseif ($uporder == "torrents")
$orderby = "n_t DESC, name";
elseif ($uporder == "peers")
$orderby = "n_p DESC, name";
else
$orderby = "name";
$query = "SELECT u.id,
u.username AS name,
MAX(t.added) AS last,
COUNT(DISTINCT t.id) AS n_t,
COUNT(p.id) as n_p
FROM users as u
LEFT JOIN torrents as t ON u.id = t.owner
LEFT JOIN peers as p ON t.id = p.torrent
WHERE u.class = 3
GROUP BY u.id
UNION
SELECT u.id,
u.username AS name,
MAX(t.added) AS last,
COUNT(DISTINCT t.id) AS n_t,
COUNT(p.id) as n_p
FROM users as u
LEFT JOIN torrents as t ON u.id = t.owner
LEFT JOIN peers as p ON t.id = p.torrent
WHERE u.class > 3
GROUP BY u.id ORDER BY $orderby";
$res = do_mysql_query($query) or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($res) == 0)
stdmsg("Sorry...", "No uploaders.");
else
{
begin_frame("Uploader Activity", True);
begin_table();
print("
\n
Uploader | \n
Last Upload | \n
Torrents | \n
Perc. | \n
Peers | \n
Perc. | \n
\n");
while ($uper = mysql_fetch_array($res))
{
print("".$uper['name']." | \n");
print("".$uper['last']." (".get_elapsed_time(sql_timestamp_to_unix_timestamp($uper['last']))." ago)"):"align=center>---") . " | \n");
print("" . $uper['n_t'] . " | \n");
print("" . ($n_tor > 0?number_format(100 * $uper['n_t']/$n_tor,1)."%":"---") . " | \n");
print("" . $uper['n_p']." | \n");
print("" . ($n_peers > 0?number_format(100 * $uper['n_p']/$n_peers,1)."%":"---") . " |
\n");
}
end_table();
end_frame();
}
if ($n_tor == 0)
stdmsg("Sorry...", "No categories defined!");
else
{
if ($catorder == "lastul")
$orderby = "last DESC, c.name";
elseif ($catorder == "torrents")
$orderby = "n_t DESC, c.name";
elseif ($catorder == "peers")
$orderby = "n_p DESC, name";
else
$orderby = "c.name";
$res = do_mysql_query("SELECT c.name,
MAX(t.added) AS last,
COUNT(DISTINCT t.id) AS n_t,
COUNT(p.id) AS n_p
FROM categories as c
LEFT JOIN torrents as t ON t.category = c.id
LEFT JOIN peers as p ON t.id = p.torrent
GROUP BY c.id ORDER BY $orderby") or sqlerr(__FILE__, __LINE__);
begin_frame("Category Activity", True);
begin_table();
print("Category |
Last Upload |
Torrents |
Perc. |
Peers |
Perc. |
\n");
while ($cat = mysql_fetch_array($res))
{
print("" . $cat['name'] . " | ");
print("".$cat['last']." (".get_elapsed_time(sql_timestamp_to_unix_timestamp($cat['last']))." ago)"):"align = center>---") ." | ");
print("" . $cat['n_t'] . " | ");
print("" . number_format(100 * $cat['n_t']/$n_tor,1) . "% | ");
print("" . $cat['n_p'] . " | ");
print("" . ($n_peers > 0?number_format(100 * $cat['n_p']/$n_peers,1)."%":"---") . " | \n");
}
end_table();
end_frame();
}
end_main_frame();
stdfoot();
die;
?>