s<?php
require "include/bittorrent.php";
dbconn(true);

stdhead("Uploader-Übersicht");

loggedinorreturn;

function table_kopf($s)
{
echo "<table class=\"tableinborder\" border=\"0\" cellpadding=\"4\" cellspacing=\"1\" width=\"900\">";
echo "<tr>";
echo "<td class=\"tabletitle\" colspan=\"8\">$s</td>";
echo "</tr>";
echo "<tr>";
echo "<td class=\"tabletitle\" width=\"20\">Pos.</td>";
echo "<td class=\"tabletitle\" width=\"130\">Username</td>";
echo "<td class=\"tabletitle\" width=\"150\">Upload / Dowload</td>";
echo "<td class=\"tabletitle\" width=\"70\">Ratio</td>";
echo "<td class=\"tabletitle\" width=\"80\">Anz. Torrents</td>";
echo "<td class=\"tabletitle\" width=\"220\">lezter Upload</td>";
echo "<td class=\"tabletitle\">akt. Monat</td>";
echo "<td class=\"tabletitle\">Sende PM</td>";
echo "</tr>";
}

function table_inhalt($user_klasse)
{
$query = "SELECT id, username, added, uploaded, downloaded, donor, warned FROM users WHERE class = $user_klasse";
$result = mysql_query($query);
$num = mysql_num_rows($result);
$zerofix = $num - 1; // remove one row because mysql starts at zero

for ($i = 0; $i <= $zerofix; $i++)
{
$id = mysql_result($result, $i, "id");
$username = mysql_result($result, $i, "username");
$added = mysql_result($result, $i, "added");
$uploaded = mksize(mysql_result($result, $i, "uploaded"));
$downloaded = mksize(mysql_result($result, $i, "downloaded"));
$uploadedratio = mysql_result($result, $i, "uploaded");
$downloadedratio = mysql_result($result, $i, "downloaded");
$donor = mysql_result($result, $i, "donor");
$warned = mysql_result($result, $i, "warned");

// Anzahl der im aktuellen Monat geuppten Files
$d = date("Y-m-01");
$datum = "\"" . $d . " 00:00:00\"";
$query = "SELECT * FROM torrents WHERE owner = $id AND added >= $datum ORDER BY owner" or sqlerr(__FILE__, __LINE__);
$count = mysql_query($query);
$anzahl = mysql_num_rows($count);

// get uploader torrents activity
$upperquery = "SELECT added FROM torrents WHERE owner = $id";
$upperresult = mysql_query($upperquery);

$torrentinfo = mysql_fetch_array($upperresult);

$numtorrents = mysql_num_rows($upperresult);


if ($downloaded > 0)
{
$ratio = $uploadedratio / $downloadedratio;
$ratio = number_format($ratio, 3);
$color = get_ratio_color($ratio);
if ($color)
$ratio = "<font color=$color>$ratio</font>";
}
else
if ($uploaded > 0)
$ratio = "Inf.";
else
$ratio = "---";

// get donor
if ($donor == "yes")
$star = "<img src=pic/star.gif>";
else
$star = "";

// get warned
if ($warned == "yes")
$klicaj = "<img src=pic/warned8.gif>";
else
$klicaj = "";

 $counter = $i + 1;

 echo "<tr>";
 echo "<td class=\"tablea\" align=\"center\">$counter.</td>";
 echo "<td class=\"tablea\"><a href=/userdetails.php?id=$id>$username</a> $star $klicaj</td>";
 echo "<td class=\"tablea\">$uploaded / $downloaded</td>";
 echo "<td class=\"tablea\">$ratio</td>";
 echo "<td class=\"tablea\">$numtorrents Torrents</td>";
 if ($numtorrents > 0)
 {
  $lastadded = mysql_result($upperresult, $numtorrents - 1, "added");
   echo "<td class=\"tablea\">vor " . get_elapsed_time(sql_timestamp_to_unix_timestamp($lastadded)) . " (" . gmdate("d. M Y",strtotime($lastadded)) . ")</td>";
  }
  else
  echo "<td class=\"tablea\">---</td>";
  echo "<td class=\"tablea\"><center>$anzahl</center></td>";
  echo "<td class=\"tablea\"><center><a href=\"messages.php?action=send&amp;receiver=$id\"><img src=\"pic/button_pm2.gif\" border=\"0\"></a></center></td>";

  echo "</tr>";
 }
 echo "</table><br>";
}






if ($CURUSER['class'] >= UC_MODERATOR)

{
 echo "<h2>Uploader Info Panel</h2>";

 $t = UC_UPLOADER;
 $query = "SELECT id FROM users WHERE class = $t";
 $result = mysql_query($query);
 $num = mysql_num_rows($result); // how many uploaders
 $titel = "<center>Wir haben <font class=\"" . get_class_color($t) . "\">" . $num . " " . get_user_class_name($t) . "</font></center>";
 
 if ($num > 0)
 {
  table_kopf($titel);
  table_inhalt($t);
 }

 $t = UC_SUPERUPLOADER;
 $query = "SELECT id FROM users WHERE class = $t";
 $result = mysql_query($query);
 $num = mysql_num_rows($result); // how many uploaders
 $titel = "<center>Wir haben <font class=\"" . get_class_color($t) . "\">" . $num . " " . get_user_class_name($t) . "</font></center>";
 
 if ($num > 0)
 {
  table_kopf($titel);
  table_inhalt($t);
 }

 if (get_user_class() >= UC_ADMINISTRATOR)
 {
   print ("<br><center><font color=blue><b>Sichtbar ab Administrator</b></font></center><br>");

   $t = UC_MODERATOR;
   $query = "SELECT id FROM users WHERE class = $t";
   $result = mysql_query($query);
   $num = mysql_num_rows($result); // how many uploaders
   $titel = "<center>Wir haben <font class=\"" . get_class_color($t) . "\">" . $num . " " . get_user_class_name($t) . "(en)</font></center>";
 
   if ($num > 0)
   {
    table_kopf($titel);
    table_inhalt($t);
   }

   $t = UC_COADMIN;
   $query = "SELECT id FROM users WHERE class = $t";
   $result = mysql_query($query);
   $num = mysql_num_rows($result); // how many uploaders
   $titel = "<center>Wir haben <font class=\"" . get_class_color($t) . "\">" . $num . " " . get_user_class_name($t) . "(en)</font></center>";
 
   if ($num > 0)
   {
    table_kopf($titel);
    table_inhalt($t);
   }

   $t = UC_ADMINISTRATOR;
   $query = "SELECT id FROM users WHERE class = $t";
   $result = mysql_query($query);
   $num = mysql_num_rows($result); // how many uploaders
   $titel = "<center>Wir haben <font class=\"" . get_class_color($t) . "\">" . $num . " " . get_user_class_name($t) . "(en)</font></center>";
 
   if ($num > 0)
   {
    table_kopf($titel);
    table_inhalt($t);
   }

   $t = UC_TEAMLEITUNG;
   $query = "SELECT id FROM users WHERE class = $t";
   $result = mysql_query($query);
   $num = mysql_num_rows($result); // how many uploaders
   $titel = "<center>Wir haben <font class=\"" . get_class_color($t) . "\">" . $num . " " . get_user_class_name($t) . "(en)</font></center>";
 
   if ($num > 0)
   {
    table_kopf($titel);
    table_inhalt($t);
   }

   $t = UC_SYSOP;
   $query = "SELECT id FROM users WHERE class = $t";
   $result = mysql_query($query);
   $num = mysql_num_rows($result); // how many uploaders
   $titel = "<center>Wir haben <font class=\"" . get_class_color($t) . "\">" . $num . " " . get_user_class_name($t) . "(s)</font></center>";
 
   if ($num > 0)
   {
    table_kopf($titel);
    table_inhalt($t);
   }

   $t = UC_CODER;
   $query = "SELECT id FROM users WHERE class = $t";
   $result = mysql_query($query);
   $num = mysql_num_rows($result); // how many uploaders
   $titel = "<center>Wir haben <font class=\"" . get_class_color($t) . "\">" . $num . " " . get_user_class_name($t) . "</font></center>";
 
   if ($num > 0)
   {
    table_kopf($titel);
    table_inhalt($t);
   }

 }

}
 else
  echo "Zugriff verweigert";
stdfoot(true);
?> 