<?php

require "include/bittorrent.php";
dbconn();
loggedinorreturn();

if (get_user_class() < UC_MODERATOR)
  stderr("Error", "Access denied.");

stdhead("Manuelle Slots");
begin_frame(".: User mit manueller Slotbegrenzung :.");

$mainsql="SELECT *, unix_timestamp(last_access) as udt FROM users WHERE tlimitall > 0 AND enabled = 'yes'";

$res2 = mysql_query($mainsql);
$count = mysql_num_rows($res2);
$perpage = 100;
list($pagertop, $pagerbottom, $limit) = pager($perpage, $count, $_SERVER["PHP_SELF"] ."?" );
echo $pagertop;

if($_GET["order"])
  switch($_GET["order"])
  {
    case "leeches":
      $order="tlimitleeches, tlimitseeds";
    break;
    case "seeds":
      $order="tlimitseeds, tlimitleeches";
    break;
    case "total":
      $order="tlimitall, tlimitleeches, tlimitseeds";
    break;
    case "name":
      $order="username, tlimitleeches, tlimitseeds";
    break;
    case "up":
      $order="uploaded, tlimitleeches, tlimitseeds";
    break;
    case "down":
      $order="downloaded, tlimitleeches, tlimitseeds";
    break;
    case "ratio":
      $order="uploaded/downloaded, tlimitleeches, tlimitseeds";
    break;
    case "activity":
      $order="udt, tlimitleeches, tlimitseeds";
    break;
  }
else
  $order="tlimitleeches, tlimitseeds";

$result = mysql_query ("$mainsql ORDER BY $order ASC $limit");

echo "<center>";
begin_table();
echo "<tr><td class=tablecat align=left><a href=\"$_SERVER[PHP_SELF]?order=leeches&page=".(0+$_GET["page"])."\"><b>Leechslots</b></a></td>";
echo "<td class=tablecat align=left><a href=\"$_SERVER[PHP_SELF]?order=seeds&page=".(0+$_GET["page"])."\"><b>Seedslots</b></a></td>";
echo "<td class=tablecat align=left><a href=\"$_SERVER[PHP_SELF]?order=total&page=".(0+$_GET["page"])."\"><b>Gesamtslots</b></a></td>";
echo "<td class=tablecat align=left><a href=\"$_SERVER[PHP_SELF]?order=name&page=".(0+$_GET["page"])."\"><b>Username</b></a></td>";
echo "<td class=tablecat align=left><a href=\"$_SERVER[PHP_SELF]?order=up&page=".(0+$_GET["page"])."\"><b>Upload</b></a></td>";
echo "<td class=tablecat align=left><a href=\"$_SERVER[PHP_SELF]?order=down&page=".(0+$_GET["page"])."\"><b>Download</b></a></td>";
echo "<td class=tablecat align=left><a href=\"$_SERVER[PHP_SELF]?order=ratio&page=".(0+$_GET["page"])."\"><b>Ratio</b></a></td>";
echo "<td class=tablecat align=left><a href=\"$_SERVER[PHP_SELF]?order=activity&page=".(0+$_GET["page"])."\"><b>Zuletzt aktiv</b></a></td>";
echo "</tr>";

if ($row = mysql_fetch_array($result))
{
  do
  {
  if ($row["uploaded"] == "0")
    $ratio = "inf";
  elseif ($row["downloaded"] == "0") 
    $ratio = "inf";
  else
  {
    $ratio = number_format($row["uploaded"] / $row["downloaded"], 3);
    $ratio = "<font color=" . get_ratio_color($ratio) . ">$ratio</font>";
  }
  $arr["username"] = "<font class=".get_class_color($row["class"]).">" . $row["username"] . "</font>";

  echo "<tr><td class=tableb>".$row["tlimitleeches"]."</td>";
  echo "<td class=tablea>".$row["tlimitseeds"]."</a></td>";
  echo "<td class=tableb>".$row["tlimitall"]."</td>";
  echo "<td class=tablea><a href=userdetails.php?id=".$row["id"]."><b>".$arr["username"]."</b>".get_user_icons($row)."</a></td>";
  echo "<td class=tableb>".mksize($row["uploaded"])."</td>";
  echo "<td class=tablea>".mksize($row["downloaded"])."</td>";
  echo "<td class=tableb><strong>".$ratio."</strong></td>";
  echo "<td class=tablea>".date("d.m.Y H:i:s",$row["udt"])."</td></tr>";


  } while($row = mysql_fetch_array($result));
}
else 
  print "<tr><td>Sorry, keine Einträge vorhanden!</td></tr>";
end_table();
echo "</center>";
print($pagerbottom);
end_frame();
stdfoot();
?>