<?php

/*
// +--------------------------------------------------------------------------+
// | Anzeige des gesamten Traffics eines Users auf dem Tracker                |
// | by truenoir                                                              |
// +--------------------------------------------------------------------------+
// | Obige Zeilen dürfen nicht entfernt werden!    Do not remove above lines! |
// +--------------------------------------------------------------------------+
*/

ob_start("ob_gzhandler");
require_once("include/bittorrent.php");
dbconn(false);
loggedinorreturn(false);

function bark($msg)
{
  stderr("Fehler",$msg);
}

function makeratio($down,$up)
{
  if ($down) {
      $ratio = floor(($up / $down) * 1000) / 1000;
      $ratio = "<font color=\"" . get_ratio_color($ratio) . "\">" . number_format($ratio, 3) . "</font>";
  } else {
      if ($up)
          $ratio = "Inf.";
      else
          $ratio = "---";
  }
  return($ratio);
}

function makerow($r,$full=1)
{
  if($full&&$r["free"]=="yes") $r["name"].=" ".$GLOBALS["UPON_TXT"];
  $ratio=makeratio($r["downloaded"],$r["uploaded"]);
  $s="<tr><td class=tableb".(!$full?" colspan=\"2\" align=\"center\" style=\"font-style: italic;\"":"").">".($full?"<a href=\"details.php?id=$r[torrentid]\">$r[name]</a>":"Gel&ouml;scht")."</td>";
  if($full)
    $s.="<td class=tablea>".mksize($r["size"])."</td>";
  $s.="<td class=tableb>".mksize($r["uploaded"])."</td>";
  $s.="<td class=tablea>".mksize($r["downloaded"])."</td>";
  $s.="<td class=tableb>$ratio</td>";
  $s.="</tr>\n";
  return($s);
}

if(get_user_class()<UC_MODERATOR)
  bark("Hast Du dich verlaufen?");

$id=$_GET["id"];
if(!$id||$id<1)
  bark("Ung&uuml;ltige ID");

$user=@mysql_fetch_assoc(mysql_query("SELECT * from users where id=$id"));
if(!$user)
  bark("Diese ID ist scheinbar ung&uuml;ltig");

$res1=mysql_query("select traffic.*, torrents.name, torrents.size, torrents.free from traffic,torrents where traffic.torrentid=torrents.id and traffic.userid=$id") or sqlerr(__FILE__,__LINE__);
$res2=mysql_query("select oldtraffic.* from oldtraffic where userid=$id") or sqlerr(__FILE__,__LINE__);

stdhead("Users Traffic");
begin_frame("Traffic von <a href=\"userdetails.php?id=$user[id]\">$user[username]</a>",true);
?>
<center>
<table cellpadding="4" cellspacing="1" border="0" class="tableinborder">
<tr>
<td class="tablecat"><b>Torrent</b></td>
<td class="tablecat"><b>Gr&ouml;&szlig;e</b></td>
<td class="tablecat"><b>Upload</b></td>
<td class="tablecat"><b>Download</b></td>
<td class="tablecat"><b>Fileratio</b></td>
</tr>
<?php
while($r=mysql_fetch_assoc($res1))
{
  $row=makerow($r);
  $dn+=$r["downloaded"];
  $up+=$r["uploaded"];
  echo $row;
}
while($r=mysql_fetch_assoc($res2))
{
  $row=makerow($r,0);
  $dn+=$r["downloaded"];
  $up+=$r["uploaded"];
  echo $row;
}
$ratio=makeratio($dn,$up);
$dn=mksize($dn);
$up=mksize($up);
?>
<tr><td class=tableb colspan="2"><b>Gesamt</b></td>
<td class=tableb><?=$up?></td>
<td class=tablea><?=$dn?></td>
<td class=tableb><?=$ratio?></td>
</tr>
</table>
</center>
<?php
end_frame();
stdfoot();
?>