<?php
// mod_cheat for torrentbits based tracker
// Copy this file to the same dir as the rest of the tracker stuff...

$top = 100;  // Only look at the top xxx most likely...

require "include/bittorrent.php";

dbconn();

loggedinorreturn();

$search = trim($HTTP_GET_VARS['search']);
$class = $HTTP_GET_VARS['class'];
if ($class == '-' || !is_valid_id($class))
  $class = '';

if ($search != '' || $class)
{
  $query = "username LIKE " . sqlesc("%$search%") . " AND status='confirmed'";
	if ($search)
		  $q = "search=" . htmlspecialchars($search);
}
else
{
	$letter = trim($_GET["letter"]);
  if (strlen($letter) > 1)
    die;

  if ($letter == "" || strpos("0123456789abcdefghijklmnopqrstuvwxyz", $letter) === false)
    $letter = "";
$query = "username LIKE '$letter%' AND status='confirmed'";
$q = "letter=$letter";
if ($letter == "0"){
    //$letter = "";
$query = "status='confirmed'";
$q = "";
}





}

if ($class)
{
  $query .= " AND class=$class";
  $q .= ($q ? "&amp;" : "") . "class=$class";
}

stdhead("...Hit & Run... ::");

//begin_frame("<width=\"22\" height=\"22\" alt=\"\" style=\"vertical-align: middle;\"> Snatch & Leave", FALSE, "20px");


$page = $_GET['page'];
$perpage = 100;
$resm=mysql_query("SELECT COUNT(*) FROM snatched INNER JOIN torrents INNER JOIN traffic INNER JOIN users WHERE users.id=snatched.userid AND traffic.userid=snatched.userid AND torrents.id=snatched.torrentid
 AND traffic.torrentid=snatched.torrentid AND snatched.finished='yes' AND traffic.uploaded/traffic.downloaded < 0.7 AND ((snatched.last_action)-172800) <= snatched.completedat AND users.username !='' AND torrents.name !='' AND users.class <='4' AND snatched.last_action != '0000-00-00 00:00:00' AND snatched.takeuser <= '0' AND users.enabled !='no' ORDER BY users.username,
snatched.id ASC");
  $arrm = mysql_fetch_row($resm);
  $slcount = $arrm[0];
$res = mysql_query("SELECT COUNT(*) FROM snatched INNER JOIN torrents INNER JOIN traffic INNER JOIN users WHERE  users.id=snatched.userid AND traffic.userid=snatched.userid AND torrents.id=snatched.torrentid
 AND traffic.torrentid=snatched.torrentid AND snatched.finished='yes' AND traffic.uploaded/traffic.downloaded < 0.7 AND ((snatched.last_action)-172800) <= snatched.completedat AND users.username !='' AND torrents.name !='' AND users.class <='4' AND snatched.last_action != '0000-00-00 00:00:00' AND snatched.takeuser <= '0' AND users.enabled !='no' AND $query") or sqlerr();
$arr = mysql_fetch_row($res);

$pages = floor($arr[0] / $perpage);
if ($pages * $perpage < $arr[0])
  ++$pages;

if ($page < 1)
  $page = 1;
else
  if ($page > $pages)
    $page = $pages;

for ($i = 1; $i <= $pages; ++$i)
  if ($i == $page)
    $pagemenu .= "<b>$i</b>\n";
  else
    $pagemenu .= "<a href=?$q&page=$i><b>$i</b></a>\n";

if ($page == 1)
  $browsemenu .= "<b>&lt;&lt; Zurück</b>";
else
  $browsemenu .= "<a href=?$q&page=" . ($page - 1) . "><b>&lt;&lt; Zurück</b></a>";

$browsemenu .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";

if ($page == $pages)
  $browsemenu .= "<b>Weiter &gt;&gt;</b>";
else
  $browsemenu .= "<a href=?$q&page=" . ($page + 1) . "><b>Weiter &gt;&gt;</b></a>";



$offset = ($page * $perpage) - $perpage;
//print("</td></tr>\n");
if (get_user_class() < UC_MODERATOR) stderr("Sorry", "Wat willst du denn hier .");
mysql_query("UPDATE users SET modcount=modcount+1 WHERE id=".$CURUSER['id']);

mysql_query("UPDATE users SET url='hitrun.php', urldate=NOW(), modcount=modcount+1 WHERE id=".$CURUSER['id']);


print("<h2><b>Snatch & Leave</h2></b><br>");





//list($pagertop, $pagerbottom, $limit) = pager(20,$slcount,"hitrun.php?");
begin_frame();

print("<center><form method=get action=hitruned.php><input type=submit value=\"Bereits bearbeitet\" width=110px></form></center>");
print("<b><h1><center>Hier erscheinen alle die, die unter 72 STD nach fertigstellen des Torrents <br>aussteigen und eine File Ratio von unter 0.8 haben ! (bis inkl. Userklasse VIP)</b><br><br>");
//echo $pagertop;
begin_table(TRUE);
print("<tr><td class=tablea align=left><form method=get action=?>\n");
print("<input type=hidden value='Okay'></form></td></tr>\n");
print("<tr><td class=tablea align=center>\n");



for ($i = 97; $i < 123; ++$i)
{
	$l = chr($i);
	$L = chr($i - 32);
	if ($l == $letter)
    print("<b>$L</b>\n");
	else
    print("<a href=?letter=$l><b>$L</b></a>\n");

}
print("<br><br><a href=?letter=0><b>Alle anzeigen</b></a>\n");
print("</td></tr>\n");
print("<tr><td class=tablea align=center>$browsemenu<br>$pagemenu</td></tr>");
end_table();
print("<br><br>");
begin_table();
print("<form action=\"takehitrun.php\" method=post>\n");
print("<tr><td class=tablea colspan=10 align=right><input type=\"submit\" name=\"submit\" value=\"Bestätigen\"></td></tr>");
print("<input type=\"hidden\" name=\"page\" value=\"$page\">");
print("<input type=\"hidden\" name=\"letter\" value=\"$letter\">");
print("<tr><td class=tablea width=\"20%\"><b>User name</td><td class=tablea width=\"40%\"><b>Torrent</td><td class=tablea width=\"20%\"><b>Fertig</td><td class=tablea width=\"20%\"><b>Gestoppt</td><td class=tablea><b>Ratio</td><td class=tablea><center><b>PN</b></center></td><td class=tablea><b>Bearbeitet</b></td><td class=tablea><b>Erledigt</td></tr>\n");



$ressl1=mysql_query("SELECT snatched.id AS hid, snatched.takeuser AS stuid, snatched.userid AS suid , snatched.torrentid AS stid , traffic.uploaded AS tup, traffic.downloaded AS tdown, users.username AS unam , torrents.name AS tnam , users.downloaded as udown, users.uploaded AS uup, snatched.last_action AS last, snatched.completedat AS comp FROM snatched INNER JOIN torrents INNER JOIN traffic INNER JOIN users WHERE users.id=snatched.userid AND traffic.userid=snatched.userid AND torrents.id=snatched.torrentid
 AND traffic.torrentid=snatched.torrentid AND snatched.finished='yes' AND traffic.uploaded/traffic.downloaded < 0.7 AND ((snatched.last_action)-172800) <= snatched.completedat AND users.username !='' AND torrents.name !='' AND users.class <='4' AND snatched.last_action != '0000-00-00 00:00:00' AND snatched.takeuser <= '0' AND users.enabled !='no' AND $query ORDER BY users.username,
snatched.id ASC LIMIT $offset,$perpage");
while($rowsl1=mysql_fetch_array($ressl1))
{
$userid=$rowsl1["suid"];
$torrentid=$rowsl1["stid"];
$unam=$rowsl1["unam"];
$tnam=$rowsl1["tnam"];

$res = mysql_query("SELECT * FROM peers WHERE userid=$userid AND torrent=$torrentid AND seeder='yes'");
if (@mysql_num_rows($res) == 0)
{
if ($rowsl1[stuid] > 0)
{
 $res3 = mysql_query("SELECT username FROM users WHERE id=$rowsl1[stuid]");
 $arr3 = mysql_fetch_assoc($res3);
 $dealtwith = "<font color=green><b>Ja - <a href=userdetails.php?id=$rowsl1[stuid]><b>$arr3[username]</b></a></b></font>";
}
else
{
$dealtwith = "<font color=red><b>Nein</b></font>";
}
    if ($rowsl1["tdown"] > 0)
    {
      $ratio = number_format($rowsl1["tup"] / $rowsl1["tdown"], 2);
    }
    else
      if ($rowsl1["tup"] > 0)

        $ratio = "Inf.";
      else
        $ratio = "---";
if ($rowsl1["udown"] > 0)
    {
      $ratio1 = number_format($rowsl1["uup"] / $rowsl1["udown"], 2);
    }
    else
       if ($rowsl1["uup"] > 0)
        $ratio1 = "Inf.";
      else
        $ratio1 = "---";
//$rowsl1['tnam'] = CutName($rowsl1['tnam'], 30);
echo '<tr><td class=tablea><a href="userdetails.php?id='.$rowsl1['suid'].'">'.$rowsl1['unam'].'</a></td>';
echo '<td class=tablea><a href="details.php?id='.$rowsl1['stid'].'">'.$rowsl1['tnam'].'</a></td>';
echo '<td class=tablea>'.$rowsl1['comp'].'</a></td>';
echo '<td class=tablea>'.$rowsl1['last'].'</a></td>';
echo '<td class=tablea>Tor.<font color=' . get_ratio_color($ratio) . '>'.$ratio.'</font><br>Ges.<font color=' . get_ratio_color($ratio1) . '>'.$ratio1.'</font></td>';
print("<td class=tablea><a href=\"messages.php?action=send&receiver=$rowsl1[suid]&message=sl&torrent=$rowsl1[stid]&stop=$rowsl1[last]\">Klick</a></center></td>");
echo '<td class=tablea>'.$dealtwith.'</td>';
echo '<td class=tablea><input type=checkbox name=takeit[] value=' . $rowsl1['hid'] . '>Ja</td></tr>';

}

}
print("<tr><td class=tablea colspan=10 align=right><input type=\"submit\" name=\"submit\" value=\"Bestätigen\"></td>");
//print("<p align=right><input type=\"submit\" name=\"submit\" value=\"Bestätigen\"></p>");
end_table();


print("</form>");
//echo $pagerbottom;
end_frame();

stdfoot();
?>