<?
ob_start("ob_gzhandler");
require "include/bittorrent.php";
dbconn(false);
loggedinorreturn();

/* CONFIG */
$maxratio = 0.8; // Maximum ratio to list. Standard = 0.4.
$mindownload = 10737418240; // "Downloaded more than". Standard = 10 GB.
$deleteclass = UC_ADMINISTRATOR; // Minimum and equal class that can delete users.
$drsource = false; // Set to true if you use DR-source. False if you use Official source. Setting is for PM's.
$warnfor = 7; // Days warned * 2. 7 = 2 weeks.
$pmmsg = "Du bist hiermit verwarnt wegen schlechten Ratio. Du hast 2 Wochen zeit zu verbessern. Sollte das nicht passieren, wirst du gebannt. Achte in Zukunft immer auf deine Ratio! Account löschung wird durch System kontrolliert, so get to it! wink.gif";
/* END CONFIG */

if (get_user_class() < UC_MODERATOR)
stderr("Unauthorized", "Only staff can view the leechers list....");

if ($_GET['action'] == ""){

if ($_GET['godcomplex'] == "yes")
{
foreach ( $_POST as $key => $ertek )
{
if ( (strpos($key,'cb_') != 0) or ($ertek == -1) ) continue;
else
{
$username=substr($key,3);
}

if ($_POST['warn']){
$req="UPDATE users SET warned = 'yes', warneduntil = DATE_ADD(NOW(), INTERVAL ".(2 * $warnfor)." DAY) WHERE id = '$ertek'";
$res=mysql_query($req);
}

else if ($_POST['pm']){
$r = mysql_query("SELECT id AS userid FROM users WHERE id = '$ertek'") or sqlerr();
while($dat=mysql_fetch_assoc($r)){
if($drsource == "true"){
new_msg(0, $dat[userid], $pmmsg); /* DR Source */
}else{
mysql_query("INSERT INTO messages (sender, receiver, added, msg) VALUES (0,$dat[userid] , '" . get_date_time() . "', " . sqlesc($pmmsg) .")") or sqlerr(__FILE__,__LINE__); /* Official Source */
}
}
$res = "PM Sent!";
}

else if ($_POST['disable']){
$req="UPDATE users SET warned = 'yes', enabled = 'no' WHERE id = '$ertek'";
$res=mysql_query($req);
// write_log("User $username was diabled by $CURUSER[username]");
}

else if ($_POST['delete'] && get_user_class() > $deleteclass){
$req="DELETE FROM users WHERE id = '$ertek'";
$res=mysql_query($req);
// write_log("User $username was deleted by $CURUSER[username]");
}
if ($res == ''){print("<script language=\"javascript\">alert('Kein User verwarnt, deaktiviert oder gelöscht!');</script>");}
}
}


function usertable($res, $frame_caption)
{
global $CURUSER;
begin_frame($frame_caption, true);
begin_table();
?>
<tr>
<td class="tablea" align="left">User</td>
<td class="tablea">Upload</td>
<td class="tablea">Download</td>
<td class="tablea" align="right">Ratio</td>
<td class="tablea" align="left">Registriert</td>
<td class="tablea" align="center"></td>
</tr>
<?

$cba='';
if ( isset($_GET["select"]) )
{
$select=$_GET["select"];
if ( $select == 'all' ) $cba='checked';
elseif ( $select =='none' ) $cba='';
}

$num = 0;
print("<form method=\"post\" action=\"leechers.php?godcomplex=yes\">");
while ($a = mysql_fetch_assoc($res))
{
foreach ($a as $key => $ertek )

++$num;
$highlight = $CURUSER["id"] == $a["userid"] ? " bgcolor=#BBAF9B" : "";
if ($a["downloaded"])
{
$ratio = $a["uploaded"] / $a["downloaded"];
$color = get_ratio_color($ratio);
$ratio = number_format($ratio, 2);
if ($color)
$ratio = "<font color=$color>$ratio</font>";
}
else
$ratio = "Inf.";
print("<tr class=tableb $highlight><td align=left$highlight><a href=userdetails.php?id=" .
$a["userid"] . "><strong>" . $a["username"] . "</strong></a>");

if($a["warned"] == "yes"){print("<img src=\"" . $GLOBALS['pic_base_url'] . "/warnedbig.gif\" />");}

print("</td><td class=tableb align=right $highlight>" . mksize($a["uploaded"]) .
"</td><td class=tableb align=right $highlight>" . mksize($a["downloaded"]) .
"</td><td class=tableb align=right $highlight>" . $ratio .
"</td><td class=tableb align=left>" . gmdate("d-m-Y",strtotime($a["added"])) . " (" .
get_elapsed_time(sql_timestamp_to_unix_timestamp($a["added"])) . ")</td>
<td><input type=checkbox name=\"cb_" . $a["username"] . "\" value=\"" . $a["userid"] . "\""); if($_GET["select"] == "unwarned" && $a["warned"] == "no"){print("checked");} print(" " . $cba . " /></td>
</tr>");
}
end_table();
end_frame();
}

stdhead("Ratio unter $maxratio/$mindownload byte Download");
$mainquery = "SELECT id as userid, username, added, uploaded, downloaded, warned, uploaded / (UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(added)) AS upspeed, downloaded / (UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(added)) AS downspeed FROM users WHERE enabled = 'yes'";

$limit = 250;
$order = "added ASC";
$extrawhere = " AND uploaded / downloaded < $maxratio AND downloaded > $mindownload";
$r = mysql_query($mainquery . $extrawhere . " ORDER BY $order " . " LIMIT $limit") or sqlerr();
print("<a href=\"?select=unwarned\">Wähle unverwarnte</a> | <a href=\"?select=all\">Alle wählen</a> | <a href=\"?select=none\">Keine wählen</a><br>");
$mindownloadprint = mksize ($mindownload);
?><br>
<div style="width:480px;">
<?
usertable($r, "Ratio unter $maxratio / $mindownloadprint Download");
print("<a href=\"?action=sendpm\">Sende massen PM zu alle geringerte Ratio Users</a>");
print("<p><input type=\"submit\" name=\"pm\" value=\"PM wahl\" onclick=\"return confirm('PM alle gewählte users?');\" /></p>");
print("<input type=\"submit\" name=\"warn\" value=\"Verwarnte wahl\" onclick=\"return confirm('Warne alle gewählte users?');\" />");
print("<input type=\"submit\" name=\"disable\" value=\"Deaktivierte wahl\" onclick=\"return confirm('Deaktiviere alle gewählte users?');\" />");
if( get_user_class() > $deleteclass ){
print("<input type=\"submit\" name=\"delete\" value=\"Lösche wahl\" onclick=\"return confirm('Biste Wahnsinig? Wer immer du bist, biste dir sicher den zu löschen!?');\" />");
}
print("</form>");
?>
</div>
<?

$getlog = mysql_query("SELECT id, user, date, UNIX_TIMESTAMP(date) as utadded FROM leecherspmlog LIMIT 10");
print("<br /><p>Mass PM-Log.</p><p>");
print("<table border=1 cellspacing=0 cellpadding=5>\n");
print("<tr><td class=colhead>By User</td><td class=colhead>Datum</td><td class=colhead>Bestätigt</td></tr>");
while($arr2 = mysql_fetch_assoc($getlog)){
$r2 = mysql_query("SELECT username FROM users WHERE id=$arr2[user]") or sqlerr();
$a2 = mysql_fetch_assoc($r2);
$elapsed = get_elapsed_time($arr2["utadded"]);
print("<tr><td class=tablea><a href=userdetails.php?id=$arr2[user]>$a2[username]</a></td><td class=tablea>$arr2[date]</td><td>$elapsed ago</td></tr>");
}
print("</table>");

}

if ($_GET['taking'] == "takepm"){
if ($HTTP_SERVER_VARS["REQUEST_METHOD"] == "POST"){
$dt = sqlesc(get_date_time());
$msg = $_POST['msg'];
if (!$msg)
stderr("Error","Please Type In Some Text");

$query = "SELECT id as userid, username, added, uploaded, downloaded, warned, uploaded / (UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(added)) AS upspeed, downloaded / (UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(added)) AS downspeed FROM users WHERE enabled = 'yes'";
$limit = 250;
$order = "added ASC";
//$order = "uploaded / downloaded ASC, downloaded DESC";
$extrawhere = " AND uploaded / downloaded < $maxratio AND downloaded > $mindownload";
$r = mysql_query($mainquery . $extrawhere . " ORDER BY $order " . " LIMIT $limit") or sqlerr();

while($dat=mysql_fetch_assoc($r)){

if($drsource == "true"){
new_msg(0, $dat[userid], $msg); /* DR Source */
}else{
mysql_query("INSERT INTO messages (sender, receiver, added, msg) VALUES (0,$dat[userid] , '" . get_date_time() . "', " . sqlesc($msg) .")") or sqlerr(__FILE__,__LINE__); /* Official Source */
}
}
mysql_query("INSERT INTO leecherspmlog ( user , date ) VALUES ( $CURUSER[id], $dt)") or sqlerr(__FILE__,__LINE__);
header("Refresh: 0; url=leechers.php");


}
}

if ($_GET['action'] == "sendpm") {
stdhead("Users that are bad");
?>
<table class="main" width="750" border="0" cellspacing="0" cellpadding="0"><tr><td class="embedded">
<div align="center">
<h1>Massen Nachrichten zu alle schlechte User</a></h1>
<form method="post" action="leechers.php?taking=takepm">
<?

if ($_GET["returnto"] || $_SERVER["HTTP_REFERER"])
{
?>
<input type=hidden name=returnto value=<?=$_GET["returnto"] ? $_GET["returnto"] : $_SERVER["HTTP_REFERER"]?>>
<?
}
?>
<table cellspacing=0 cellpadding=5>
<tr>
<td>Sende massen Nachrichten zu alle schlechte User<br>
<table style="border: 0" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td style="border: 0">&nbsp;</td>
<td style="border: 0">&nbsp;</td>
</tr>
</table>
</td>
</tr>
<tr><td><textarea name=msg cols=120 rows=15><?=$pmmsg?></textarea></td></tr>
<tr>
<tr><td colspan=2 align=center><input type="submit" value="Send" class="btn"></td></tr>
</table>
<input type="hidden" name="receiver" value=<?=$receiver?>>
</form>

</div></td></tr></table>
<br>
NOTE: Keine HTML Code erlaubt. (NO HTML)
<?
}
stdfoot();
?>