<?

ob_start("ob_gzhandler");

require_once("include/bittorrent.php");


function getagent($httpagent, $peer_id="")
{
if (preg_match("/^Azureus ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]\_B([0-9][0-9|*])(.+)$)/", $httpagent, $matches))
return "Azureus/$matches[1]";
elseif (preg_match("/^Azureus ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]\_CVS)/", $httpagent, $matches))
return "Azureus/$matches[1]";
elseif (preg_match("/^Java\/([0-9]+\.[0-9]+\.[0-9]+)/", $httpagent, $matches))
return "Azureus/<2.0.7.0";
elseif (preg_match("/^Azureus ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/", $httpagent, $matches))
return "Azureus/$matches[1]";
elseif (preg_match("/BitTorrent\/S-([0-9]+\.[0-9]+(\.[0-9]+)*)/", $httpagent, $matches))
return "Shadow's/$matches[1]";
elseif (preg_match("/BitTorrent\/U-([0-9]+\.[0-9]+\.[0-9]+)/", $httpagent, $matches))
return "UPnP/$matches[1]";
elseif (preg_match("/^BitTor(rent|nado)\\/T-(.+)$/", $httpagent, $matches))
return "BitTornado/$matches[2]";
elseif (preg_match("/^BitTornado\\/T-(.+)$/", $httpagent, $matches))
return "BitTornado/$matches[1]";
elseif (preg_match("/^BitTorrent\/ABC-([0-9]+\.[0-9]+(\.[0-9]+)*)/", $httpagent, $matches))
return "ABC/$matches[1]";
elseif (preg_match("/^ABC ([0-9]+\.[0-9]+(\.[0-9]+)*)\/ABC-([0-9]+\.[0-9]+(\.[0-9]+)*)/", $httpagent, $matches))
return "ABC/$matches[1]";
if(substr($peer_id, 0, 6) == "A310--")
return "ABC/3.1";
elseif (preg_match("/^Python-urllib\/.+?, BitTorrent\/([0-9]+\.[0-9]+(\.[0-9]+)*)/", $httpagent, $matches))
return "BitTorrent/$matches[1]";
elseif (ereg("^BitTorrent\/BitSpirit$", $httpagent))
return "BitSpirit";
elseif (ereg("^DansClient", $httpagent))
return "XanTorrent";
elseif (preg_match("/^BitTorrent\/brst(.+)/", $httpagent, $matches))
return "Burst/$matches[1]";
elseif (preg_match("/^RAZA (.+)$/", $httpagent, $matches))
return "Shareaza/$matches[1]";
if(substr($peer_id, 0, 8) == "-SZ2210-")
return "Shareaza/2.2.1.0";
elseif (preg_match("/Rufus\/([0-9]+\.[0-9]+\.[0-9]+)/", $httpagent, $matches))
return "Rufus/$matches[1]";
elseif (preg_match("/^BitTorrent\\/([0-9]+\\.[0-9]+(\\.[0-9]+)*)/", $httpagent, $matches))
{
if(substr($peer_id, 0, 6) == "exbc\08")
return "BitComet/0.56";
elseif(substr($peer_id, 0, 6) == "exbc\09")
return "BitComet/0.57";
elseif(substr($peer_id, 0, 6) == "exbc\0:")
return "BitComet/0.58";
if (substr($peer_id, 0,4) == "-BC0")
return "BitComet/0.".substr($peer_id,5,2);
elseif(substr($peer_id, 0, 7) == "exbc\0L")
return "BitLord/1.0";
elseif(substr($peer_id, 0, 7) == "exbcL")
return "BitLord/1.1";
else
return "Unknow";
}
elseif (preg_match("/^Python-urllib\\/([0-9]+\\.[0-9]+(\\.[0-9]+)*)/", $httpagent, $matches))
return "G3 Torrent";
elseif (preg_match("/MLDonkey\/([0-9]+).([0-9]+).([0-9]+)*/", $httpagent, $matches))
return "MLDonkey/$matches[1].$matches[2].$matches[3]";
elseif (preg_match("/ed2k_plugin v([0-9]+\\.[0-9]+).*/", $httpagent, $matches))
return "eDonkey/$matches[1]";
elseif (preg_match("/uTorrent\/([0-9]+)([0-9]+)([0-9]+)([0-9A-Z]+)/", $httpagent, $matches))
return "µTorrent/$matches[1].$matches[2].$matches[3].$matches[4]";
elseif (ereg("^0P3R4H", $httpagent))
return "Opera BT Client";
elseif (preg_match("/CT([0-9]+)([0-9]+)([0-9]+)([0-9]+)/", $peer_id, $matches))
return "cTorrent/$matches[1].$matches[2].$matches[3].$matches[4]";
elseif (preg_match("/Transmission\/([0-9]+).([0-9]+)/", $httpagent, $matches))
return "Transmission/$matches[1].$matches[2]";
elseif (preg_match("/KT([0-9]+)([0-9]+)([0-9]+)([0-9]+)/", $peer_id, $matches))
return "KTorrent/$matches[1].$matches[2].$matches[3].$matches[4]";
elseif (preg_match("/rtorrent\/([0-9]+\\.[0-9]+(\\.[0-9]+)*)/", $httpagent, $matches))
return "rTorrent/$matches[1]";
elseif(substr($peer_id, 0, 12) == "d0c")
return "Mainline";
elseif(substr($peer_id, 0, 1) == "M")
return "Mainline/Decoded";
elseif(substr($peer_id, 0, 3) == "-BB")
return "BitBuddy";


else
return "Unknow";
}

function dltable($name, $arr, $torrent)
{

        global $CURUSER;
        $s = "<b>" . count($arr) . " $name</b>\n";
        if (!count($arr))
                return $s;
        $s .= "\n";
        $s .= "<table width=100% class=main border=1 cellspacing=0 cellpadding=5>\n";
        $s .= "<tr><td class=colhead>Felhasználó</td>" .
          "<td class=colhead align=center>Kapcsolat</td>".
          "<td class=colhead align=right>Feltöltött</td>".
          "<td class=colhead align=right>Sebesség</td>".
          "<td class=colhead align=right>Letöltött</td>" .
          "<td class=colhead align=right>Sebesség</td>" .
          "<td class=colhead align=right>Arány</td>" .
          "<td class=colhead align=right>Kész</td>" .
          "<td class=colhead align=right>Kapcsolódva</td>" .
          "<td class=colhead align=right>Frissített</td>" .
          "<td class=colhead align=left>Kliens</td></tr>\n";
        $now = time();
        $moderator = (isset($CURUSER) && get_user_class() >= UC_MODERATOR);
$mod = get_user_class() >= UC_MODERATOR;
        foreach ($arr as $e) {


                // user/ip/port
                // check if anyone has this ip
                ($unr = mysql_query("SELECT username, privacy FROM users WHERE id=$e[userid] ORDER BY last_access DESC LIMIT 1")) or die;
                $una = mysql_fetch_array($unr);
                                if ($una["privacy"] == "strong") continue;
                $s .= "<tr>\n";
                if ($una["username"])
                  $s .= "<td><a href=userdetails.php?id=$e[userid]><b>$una[username]</b></a></td>\n";
                else
                  $s .= "<td>" . ($mod ? $e["ip"] : preg_replace('/\.\d+$/', ".xxx", $e["ip"])) . "</td>\n";
                $secs = max(1, ($now - $e["st"]) - ($now - $e["la"]));
                $revived = $e["revived"] == "yes";
        $s .= "<td align=center>" . ($e[connectable] == "yes" ? "Aktív" : "<font color=red>Passzív</font>") . "</td>\n";
                $s .= "<td align=right>" . mksize($e["uploaded"]) . "</td>\n";
                $s .= "<td align=right><nobr>" . mksize(($e["uploaded"] - $e["uploadoffset"]) / $secs) . "/s</nobr></td>\n";
                $s .= "<td align=right>" . mksize($e["downloaded"]) . "</td>\n";
                if ($e["seeder"] == "no")
                        $s .= "<td align=right><nobr>" . mksize(($e["downloaded"] - $e["downloadoffset"]) / $secs) . "/s</nobr></td>\n";
                else
                        $s .= "<td align=right><nobr>" . mksize(($e["downloaded"] - $e["downloadoffset"]) / max(1, $e["finishedat"] - $e[st])) .        "/s</nobr></td>\n";
                if ($e["downloaded"])
                                {
                  $ratio = floor(($e["uploaded"] / $e["downloaded"]) * 1000) / 1000;
                    $s .= "<td align=\"right\"><font color=" . get_ratio_color($ratio) . ">" . number_format($ratio, 3) . "</font></td>\n";
                                }
                       else
                  if ($e["uploaded"])
                    $s .= "<td align=right>Végtelen</td>\n";
                  else
                    $s .= "<td align=right>---</td>\n";
                $s .= "<td align=right>" . sprintf("%.2f%%", 100 * (1 - ($e["to_go"] / $torrent["size"]))) . "</td>\n";
                $s .= "<td align=right>" . mkprettytime($now - $e["st"]) . "</td>\n";
                $s .= "<td align=right>" . mkprettytime($now - $e["la"]) . "</td>\n";
                $s .= "<td align=left>" . htmlspecialchars(getagent($e["agent"], $e["peer_id"])) . "</td>\n";
                $s .= "</tr>\n";
        }
        $s .= "</table>\n";
        return $s;
}

dbconn(false);

loggedinorreturn();

$id = 0 + $_GET["id"];

if (!isset($id) || !$id)
        die();

if(($_POST['lefoglalas']=='lefoglalt') AND (get_user_class() >= UC_MODERATOR)){
mysql_query("UPDATE torrents SET ellenorizte = $CURUSER[id] WHERE id=$id") or sqlerr(__FILE__,__LINE__);
}

if ($_POST["valtoz"]=="igen" AND get_user_class() >= UC_MODERATOR)
{
$tor=$id;
if ($_POST["ellenoriz"]=="yes") 
{
  mysql_query("UPDATE torrents SET ellenorizve = 'yes' WHERE id = $tor") or sqlerr(__FILE__,__LINE__);
  $hey= "Helyes! Megjegyzés: " . $_POST["ecomment"] . " Ellenőrizte: " . $CURUSER["username"];
   $ellenorizte=$CURUSER["id"];
 // $feltoltoidje = $row["owner"];
  //mysql_query("UPDATE users SET seedbonus = seedbonus + 5 WHERE id = $ellenorizte");
//mysql_query("UPDATE users SET seedbonus = seedbonus + 20 WHERE id = $feltoltoidje");
}
if ($_POST["ellenoriz"]=="no")
{
mysql_query("UPDATE torrents SET ellenorizve = 'no' WHERE id = $tor") or sqlerr(__FILE__,__LINE__);
$hey= "Hibás! Pótold: " . $_POST["ecomment"] . " Ellenőrizte: " . $CURUSER["username"];
$ellenorizte=$CURUSER["id"];
//$feltoltoidje = $row["owner"];
}

if ($_POST["ellenoriz"]=="yes") $hey="[color=green][b]".$hey."[/b][/color]";
if ($_POST["ellenoriz"]=="no") $hey="[color=red][b]".$hey."[/b][/color]";
mysql_query("UPDATE torrents SET elcomment = '$hey' WHERE id = $tor") or sqlerr(__FILE__,__LINE__);
//mysql_query("UPDATE torrents SET ellenorizte = '$ellenorizte' WHERE id = $tor");
}
$res = mysql_query("SELECT torrents.seeders, torrents.ellenorizve, torrents.elcomment, torrents.ellenorizte, torrents.banned, torrents.nuked, torrents.leechers, torrents.info_hash, torrents.filename, LENGTH(torrents.nfo) AS nfosz, UNIX_TIMESTAMP() - UNIX_TIMESTAMP(torrents.last_action) AS lastseed, torrents.numratings, torrents.name, IF(torrents.numratings < $minvotes, NULL, ROUND(torrents.ratingsum / torrents.numratings, 1)) AS rating, torrents.owner, torrents.save_as, torrents.descr, torrents.visible, torrents.size, torrents.added, torrents.views, torrents.hits, torrents.times_completed, torrents.id, torrents.type, torrents.numfiles, categories.name AS cat_name, users.username FROM torrents LEFT JOIN categories ON torrents.category = categories.id LEFT JOIN users ON torrents.owner = users.id WHERE torrents.id = $id")
        or sqlerr();
$row = mysql_fetch_array($res);

$owned = $moderator = 0;
        if (get_user_class() >= UC_MODERATOR)
                $owned = $moderator = 1;
        elseif ($CURUSER["id"] == $row["owner"])
                $owned = 1;
//}

if (!$row || ($row["banned"] == "yes" && !$moderator))
        stderr("Hiba", "Nincs ilyen ID-jű torrent.");
else {
        if ($_GET["hit"]) {
                mysql_query("UPDATE torrents SET views = views + 1 WHERE id = $id");
                if ($_GET["tocomm"])
                        header("Location: $BASEURL/details.php?id=$id&page=0#startcomments");
                elseif ($_GET["filelist"])
                        header("Location: $BASEURL/details.php?id=$id&filelist=1#filelist");
                elseif ($_GET["toseeders"])
                        header("Location: $BASEURL/details.php?id=$id&dllist=1#seeders");
                elseif ($_GET["todlers"])
                        header("Location: $BASEURL/details.php?id=$id&dllist=1#leechers");
                else
                        header("Location: $BASEURL/details.php?id=$id");
                exit();
        }

        if (!isset($_GET["page"])) {
                stdhead("Details for torrent \"" . $row["name"] . "\"");

                if ($CURUSER["id"] == $row["owner"] || get_user_class() >= UC_MODERATOR)
                        $owned = 1;
                else
                        $owned = 0;

                $spacer = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";

                if ($_GET["uploaded"]) {
                        print("<h2>Sikeresen feltöltve!</h2>\n");
                        print("<p>Most már elkezdheted seedelni. <b>Megjegyzés:</b> a torrent addig nem fog látszódani amig nem kezded el seedelni!</p>\n");
                }
                elseif ($_GET["edited"]) {
                        print("<h2>Sikeresen szerkesztve!</h2>\n");
                        if (isset($_GET["returnto"]))
                                print("<p><b>Vissza ahonnan jöttél <a href=\"" . htmlspecialchars($_GET["returnto"]) . "\"></a>.</b></p>\n");
                }
                elseif (isset($_GET["searched"])) {
                        print("<h2>Your search for \"" . htmlspecialchars($_GET["searched"]) . "\" gave a single result:</h2>\n");
                }
                elseif ($_GET["rated"]) {
 print("<h2>Értékelés hozzáadva!</h2>\n");
}
elseif ($_GET["thanks"])
 print("<h2>Sikeresen megköszönted!</h2>\n");

$s=$row["name"];
                print("<h1>$s</h1>\n");
                print("<table width=750 border=\"1\" cellspacing=\"0\" cellpadding=\"5\">\n");

                $url = "edit.php?id=" . $row["id"];
                if (isset($_GET["returnto"])) {
                        $addthis = "&amp;returnto=" . urlencode($_GET["returnto"]);
                        $url .= $addthis;
                        $keepget .= $addthis;
                }
                $editlink = "a href=\"$url\" class=\"sublink\"";

//		$s = "<b>" . htmlspecialchars($row["name"]) . "</b>";
//		if ($owned)
//			$s .= " $spacer<$editlink>[Edit torrent]</a>";
		tr("Név", $s, 1);


print("<tr><td class=rowhead width=1%>Letöltés</td><td width=99% align=left>");
if ($row['ellenorizve']!='yes' AND $CURUSER['id']!=$row['owner'])
{
print("<FONT COLOR=RED><b>A torrent vezetői engedélyre vár!</b></FONT>");
}
else
{
print("<a class=\"index\" href=\"download.php/$id/" . rawurlencode($row["filename"]) . "\">" . htmlspecialchars($row["filename"]) . "</a>");
}
print("</td></tr>");


if ($row["ellenorizve"]=="nincs") $szoveg="[b][color=blue][u]Még nincs ellenőrizve![/color][/b][/u]";
else $szoveg=$row["elcomment"];


if($_POST['javit']=='javitottam')
{
$dt = sqlesc(get_date_time());
$msg = sqlesc("Üdv.\n Itt a rendszer!\n Csak üzent egy felhasználó, hogy már javította a torrentjét!\n
Menj és ellenőrizd! $BASEURL/details.php?id=$id\n Előre is köszönöm!\n Üdv. RENDSZER");
    
mysql_query("INSERT INTO messages (sender, receiver, added, msg, poster) VALUES(0, $row[owner], $dt, $msg, 0)") or sqlerr(__FILE__, __LINE__);
echo "<font color=red><blink><b>PM elküldve az ellenőrzőnek!</b></blink></font>";
}


$tor=$row["id"];
if ($row['owner']==$CURUSER['id'] AND $row['ellenorizve']=='no')
$vezetoi_szoveg = "<form method=post action=details.php?id=$id>" . format_comment($szoveg) . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type=hidden name=javit value=javitottam><input type=submit value='Javítottam (Csak 1x kattints! Az ellenőrzőt PM-ben értesítjük)'></form>";
else
$vezetoi_szoveg = format_comment($szoveg);

print("<tr><td class=\"row2\" align=\"right\"><b>Vezetői<br>Ellenőrzés </b></td><td class=\"row1\">$vezetoi_szoveg</td></tr>");
if (get_user_class() >= UC_MODERATOR){
$ell = mysql_query("SELECT `username` FROM `users` WHERE `id`=$row[ellenorizte]") or sqlerr(__FILE__,__LINE__);
$ell = mysql_fetch_assoc($ell);
$ellenorizte = $ell['username'];

if ($row['ellenorizte']>0 AND $CURUSER['id']==$row['ellenorizte'] AND $row['ellenorizve']!='yes'){
$staff = "<tr><td class=\"row2\" align=\"right\"><b>Staff</b></td><td class=\"row1\">
<form method=\"post\" action=\"details.php?id=".$row["id"]."\">
<input name=\"ellenoriz\" type=\"radio\" value=\"yes\">Jó feltöltés
<input name=\"ellenoriz\" type=\"radio\" value=\"no\">
    Rossz feltöltés 
	<input name=\"ecomment\" type=\"text\" width=\"10000\" size=\"50\">
	<input type=\"hidden\" name=\"valtoz\" value=\"igen\" width=\"10000\">
    <input type=\"submit\" name=\"Submit\" value=\"Ok\">
    </form></td></tr>
";}
elseif ($row['ellenorizte']>0 AND $CURUSER['id']==$row['ellenorizte'] AND $row['ellenorizve']=='yes'){
$staff = "<tr><td class=\"row2\" align=\"right\"><b>Staff</b></td><td class=\"row1\">
<font color=green><b>Elfogadtad a feltöltést helyesnek, már nem módosíthatsz rajta! <br>Ha mégis hiba van benne akkor köteles vagy te javítani a torrentet!</b></font>
</td></tr>";
}
elseif($row['ellenorizte']>0 AND $CURUSER['id']!=$row['ellenorizte']){
$staff = "<tr><td class=\"row2\" align=\"right\" ><b>Staff</b></td><td class=\"row1\">
<font color=orange><b>Lefoglalta: $ellenorizte</b></font>
</td></tr>";
}
elseif($row['ellenorizte']==0){
$staff = "<tr><td class=\"row2\" align=\"right\"<b>Staff</b></td><td class=\"row1\"><form method=\"post\" action=\"details.php?id=".$row["id"]."\">
 <input type=hidden name=lefoglalas value=lefoglalt>
    <input type = submit value=Leellenőrzöm>
    </form></td></tr>";
}


print("$staff");}
//tr("Letöltések máshonnan", $row["save_as"]);


		function hex_esc($matches) {
			return sprintf("%02x", ord($matches[0]));
		}
		tr("Hash infó", preg_replace_callback('/./s', "hex_esc", hash_pad($row["info_hash"])));

                if (!empty($row["descr"]))
                        tr("Leírás", str_replace(array("\n", "  "), array("<br>\n", "&nbsp; "), format_comment(htmlspecialchars($row["descr"]))), 1);
if (get_user_class() >= UC_POWER_USER && $row["nfosz"] > 0)
  print("<tr><td class=rowhead>NFO</td><td align=left><a href=viewnfo.php?id=$row[id]><b>View NFO</b></a> (" .
     mksize($row["nfosz"]) . ")</td></tr>\n");
                if ($row["visible"] == "no")
                        tr("Látható", "<b>NEM</b> (halott)", 1);
                if ($moderator){
                 if ($row["banned"]=='yes')
                 $bannolt = "Igen";
                 else
                 $bannolt ="Nem";
                tr("Tiltva", $bannolt);}
                
                if($row['nuked']=="yes")
                $kiemelt = "Igen";
                else $kiemelt= "Nem";
  print("<tr><td class=rowhead>Tiltott</td><td align=left>$kiemelt</td></tr>\n");

                if (isset($row["cat_name"]))
                        tr("Típus", $row["cat_name"]);
                else
                        tr("Típus", "(Nincs kiválasztva)");

                tr("Utolsó seeder", "Utolsó aktivitás " . mkprettytime($row["lastseed"]) . " ezelőtt");
                tr("Méret",mksize($row["size"]) . " (" . number_format($row["size"]) . " byte)");

                $s = "";
                $s .= "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td valign=\"top\" class=embedded>";
                if (!isset($row["rating"])) {
                        if ($minvotes > 1) {
                                $s .= "none yet (needs at least $minvotes votes and has got ";
                                if ($row["numratings"])
                                        $s .= "only " . $row["numratings"];
                                else
                                        $s .= "none";
                                $s .= ")";
                        }
                        else
                                $s .= "Nincs egy szavazat sem";
                }
                else {
                        $rpic = ratingpic($row["rating"]);
                        if (!isset($rpic))
                                $s .= "invalid?";
                        else
                                $s .= "$rpic (" . $row["rating"] . " az 5-ből " . $row["numratings"] . " szavazat összesen)";
                }
                $s .= "\n";
                $s .= "</td><td class=embedded>$spacer</td><td valign=\"top\" class=embedded>";
                if (!isset($CURUSER))
                        $s .= "(<a href=\"login.php?returnto=" . urlencode($_SERVER["REQUEST_URI"]) . "&amp;nowarn=1\">Log in</a> to rate it)";
                else {
                        $ratings = array(
                                        5 => "Király!",
                                        4 => "Jó",
                                        3 => "Elmegy",
                                        2 => "Gyenge",
                                        1 => "Törölni kellene!",
                        );
                        if (!$owned || $moderator) {
                                $xres = mysql_query("SELECT rating, added FROM ratings WHERE torrent = $id AND user = " . $CURUSER["id"]);
                                $xrow = mysql_fetch_array($xres);
                                if ($xrow)
                                        $s .= "(Szavaztál erre a torrentre \"" . $xrow["rating"] . " - " . $ratings[$xrow["rating"]] . "\")";
                                else {
                                        $s .= "<form method=\"post\" action=\"takerate.php\"><input type=\"hidden\" name=\"id\" value=\"$id\" />\n";
                                        $s .= "<select name=\"rating\">\n";
                                        $s .= "<option value=\"0\">(Szavazz!)</option>\n";
                                        foreach ($ratings as $k => $v) {
                                                $s .= "<option value=\"$k\">$k - $v</option>\n";
                                        }
                                        $s .= "</select>\n";
                                        $s .= "<input type=\"submit\" value=\"Szavazom!\" />";
                                        $s .= "</form>\n";
                                }
                        }
                }
                $s .= "</td></tr></table>";
                tr("Értékelés", $s, 1);
                tr("Hozzáadva", $row["added"]);
                tr("Megnézve", $row["views"]);
                tr("Elkezdve", $row["hits"]);
                print("<tr><td class=rowhead>Letöltve</td><td align=left><b><a href=viewsnatches.php?id=$id>".$row["times_completed"]." x</a></b></td></tr>\n");
                // Totaltraffic mod
$data = mysql_query("SELECT (t.size * t.times_completed + SUM(p.downloaded)) AS data FROM torrents AS t LEFT JOIN peers AS p ON t.id = p.torrent WHERE p.seeder = 'no' AND p.torrent = '$id' AND times_completed > 0 GROUP BY t.id ORDER BY added ASC LIMIT 15") or sqlerr(__FILE__, __LINE__);
 $a = mysql_fetch_assoc($data);
 $data = mksize($a["data"]) . "";  
tr("Teljese adatforgalom", $data);
if ($row[seeders] == 0) {
                tr("Seed kérése", "Seed kéréséhez kattints <a href=takereseed.php?reseedid=$id><b>IDE</b></a>.", 1);
}
if ($row["times_completed"] != 0)
{
echo("<tr><td class=rowhead width=1%>Utolsó 10 letöltő</td><td>");
$res3 = mysql_query("SELECT snatched.userid,users.username,users.uploaded,users.downloaded FROM snatched inner

join users on snatched.userid = users.id inner join torrents on snatched.torrentid = torrents.id WHERE torrentid

=$id order by snatched.id desc LIMIT 10") or sqlerr();
$num = mysql_num_rows($res3);

for ($i = 0; $i < $num; ++$i)
{
$arr3 = mysql_fetch_assoc($res3);
if ($arr3["downloaded"] > 0)
{
 $ratio = number_format($arr3["uploaded"] / $arr3["downloaded"], 2);
 $ratio = "<font color=" . get_ratio_color($ratio) . ">" . $arr3["username"] . " (" . $ratio . ")</font>";
}
echo("<b><a href=userdetails.php?id=" . $arr3["userid"] . ">" . $ratio . "</a></b>&nbsp;&nbsp;");
}
echo ("</td></tr>");
}

$seedersProgressbar = array();
$leechersProgressbar = array();
$resProgressbar = mysql_query("SELECT p.seeder, p.to_go, t.size FROM torrents AS t LEFT JOIN peers AS p ON t.id = p.torrent WHERE  p.torrent = '$id'") or sqlerr();
$progressPerTorrent = 0;
$iProgressbar = 0;
while ($rowProgressbar = mysql_fetch_array($resProgressbar)) {
 $progressPerTorrent += sprintf("%.2f", 100 * (1 - ($rowProgressbar["to_go"] / $rowProgressbar["size"])));    
 $iProgressbar++;
}
if ($iProgressbar == 0)
$iProgressbar = 1;
$progressTotal = sprintf("%.2f", $progressPerTorrent / $iProgressbar);
tr("Kész forrás", get_percent_completed_image(floor($progressTotal))." (".round($progressTotal)."%)", 1);

                $keepget = "";
                $uprow = (isset($row["username"]) ? ("<a href=userdetails.php?id=" . $row["owner"] . "><b>" . htmlspecialchars($row["username"]) . "</b></a>") : "<i>Ismeretlen</i>");
                if ($owned)
                        $uprow .= " $spacer<$editlink><b>[Torrent szerkeztése]</b></a>";
                tr("Feltöltötte", $uprow, 1);

                if ($row["type"] == "multi") {
                        if (!$_GET["filelist"])
                                tr("Fájlok<br /><a href=\"details.php?id=$id&amp;filelist=1$keepget#filelist\" class=\"sublink\">[Lista]</a>", $row["numfiles"] . " fájl", 1);
                        else {
                                tr("Fájlok", $row["numfiles"] . " files", 1);

                                $s = "<table class=main border=\"1\" cellspacing=0 cellpadding=\"5\">\n";

                                $subres = mysql_query("SELECT * FROM files WHERE torrent = $id ORDER BY id");
$s.="<tr><td class=colhead>Elérés</td><td class=colhead align=right>Méret</td></tr>\n";
                                while ($subrow = mysql_fetch_array($subres)) {
                                        $s .= "<tr><td>" . $subrow["filename"] .
                            "</td><td align=\"right\">" . mksize($subrow["size"]) . "</td></tr>\n";
                                }

                                $s .= "</table>\n";
                                tr("<a name=\"filelist\">Fájl lista</a><br /><a href=\"details.php?id=$id$keepget\" class=\"sublink\">[Lista elrejtése]</a>", $s, 1);
                        }
                }

                if (!$_GET["dllist"]) {
                        /*
                        $subres = mysql_query("SELECT seeder, COUNT(*) FROM peers WHERE torrent = $id GROUP BY seeder");
                        $resarr = array(yes => 0, no => 0);
                        $sum = 0;
                        while ($subrow = mysql_fetch_array($subres)) {
                                $resarr[$subrow[0]] = $subrow[1];
                                $sum += $subrow[1];
                        }
                        tr("Peers<br /><a href=\"details.php?id=$id&amp;dllist=1$keepget#seeders\" class=\"sublink\">[See full list]</a>", $resarr["yes"] . " seeder(s), " . $resarr["no"] . " leecher(s) = $sum peer(s) total", 1);
                        */
                        tr("Kapcsolatok<br /><a href=\"details.php?id=$id&amp;dllist=1$keepget#seeders\" class=\"sublink\">[Lista]</a>", $row["seeders"] . " feltöltő, " . $row["leechers"] . " letötlő = " . ($row["seeders"] + $row["leechers"]) . " kapcsolat összesen", 1);
                }
                else {
                        $downloaders = array();
                        $seeders = array();
                        $subres = mysql_query("SELECT seeder, finishedat, downloadoffset, uploadoffset, ip, port, uploaded, downloaded, to_go, UNIX_TIMESTAMP(started) AS st, connectable, agent, peer_id, UNIX_TIMESTAMP(last_action) AS la, userid FROM peers WHERE torrent = $id") or sqlerr();
                        while ($subrow = mysql_fetch_array($subres)) {
                                if ($subrow["seeder"] == "yes")
                                        $seeders[] = $subrow;
                                else
                                        $downloaders[] = $subrow;
                        }

                        function leech_sort($a,$b) {
                                if ( isset( $_GET["usort"] ) ) return seed_sort($a,$b);
                                $x = $a["to_go"];
                                $y = $b["to_go"];
                                if ($x == $y)
                                        return 0;
                                if ($x < $y)
                                        return -1;
                                return 1;
                        }
                        function seed_sort($a,$b) {
                                $x = $a["uploaded"];
                                $y = $b["uploaded"];
                                if ($x == $y)
                                        return 0;
                                if ($x < $y)
                                        return 1;
                                return -1;
                        }

                        usort($seeders, "seed_sort");
                        usort($downloaders, "leech_sort");

                        tr("<a name=\"seeders\">Feltöltők</a><br /><a href=\"details.php?id=$id$keepget\" class=\"sublink\">[Lista elrejtése]</a>", dltable("Seeder(s)", $seeders, $row), 1);
                        tr("<a name=\"leechers\">Letöltők</a><br /><a href=\"details.php?id=$id$keepget\" class=\"sublink\">[Lista elrejtése]</a>", dltable("Leecher(s)", $downloaders, $row), 1);
                
}
tr("Torrent bejelentése", "Kattints <a href=report.php?torrent=$id><b><font color=#ff0532>IDE</font></b></a> ha a ezzel a torrentel szabályt sértettek", 1);
                //.torrent file info link
                if (get_user_class() >= UC_MODERATOR)
                {
                tr("Torrent Infó", "<a href=\"torrent_info.php?id=$id\">Torrent Infó</a>", 1);
                }
$torrentid = $_GET["id"];
         $thanks_sql = mysql_query("SELECT * FROM thanks where torrentid=$torrentid");
   $thanks_all = mysql_num_rows($thanks_sql);
   if ($thanks_all) {
   while($rows_t = mysql_fetch_array($thanks_sql)) {
   $thanks_userid = $rows_t["userid"];
   $user_sql = mysql_query("SELECT * FROM users where id=$thanks_userid");
   $rows_a = mysql_fetch_array($user_sql);
   $username_t = $rows_a["username"];
   $thanksby =  $thanksby."<a href='userdetails.php?id=$thanks_userid'>$username_t</a>, ";
   }
   $t_userid = $CURUSER["id"];
   $tsql = mysql_query("SELECT COUNT(*) FROM thanks where torrentid=$torrentid and userid=$t_userid");
   $trows = mysql_fetch_array($tsql);
   $t_ab = $trows[0];
   if ($t_ab == "0") {
   $thanksby = $thanksby." <form action=\"thanks.php\" method=\"post\">
<input type=\"submit\" name=\"submit\" value=\"Köszi!\">
<input type=\"hidden\" name=\"torrentid\" value=\"$torrentid\">
</form>";
   }
   else {
   $thanksby = $thanksby." <form action=\"thanks.php\" method=\"post\">
<input type=\"submit\" name=\"submit\" value=\"Köszi!\" disabled>
<input type=\"hidden\" name=\"torrentid\" value=\"$torrentid\">
</form>";
   }
   }
   else {
   $thanksby = "Még senki nem köszönte meg! Légy te az első.  
   <form action=\"thanks.php\" method=\"post\">
<input type=\"submit\" name=\"submit\" value=\"Köszi!\">
<input type=\"hidden\" name=\"torrentid\" value=\"$torrentid\">
</form>
   ";
   }
       tr("Megköszönték",$thanksby,1);
                print("</table></p>\n");
        }
        else {

//// complex snatchlist mod by rightthere, oink and thebrass recreated by cue////

if (get_user_class() >= UC_USER) {

$res3 = mysql_query("select count(snatched.id) from snatched inner join users on snatched.userid = users.id inner join torrents on snatched.torrentid = torrents.id where snatched.torrentid =" . $_GET[id]) or die(mysql_error());

$row = mysql_fetch_array($res3);

$count = $row[0];

$perpage = 15;

list($pagertop, $pagerbottom, $limit) = pager($perpage, $count, $_SERVER["PHP_SELF"] . "?id=" . $_GET[id] . "&" );

$res6 = mysql_query("select name, category from torrents where id = $_GET[id]");

$arr6 = mysql_fetch_assoc($res6);

$dt = gmtime() - 180;

$dt = sqlesc(get_date_time($dt));

print("<table width=80% border=1 cellspacing=0 cellpadding=5 align=center>\n");

print("<tr><td class=colhead align=center colspan=11>Snatchdetails von: $s</td></tr>");

print("<tr>");

print("<td class=menuebutton align=center><b>Username</b></td>");

print("<td class=menuebutton align=center><b>Uploaded</b></td>");

print("<td class=menuebutton align=center><b>Downloaded</b></td>");

print("<td class=menuebutton align=center><b>Ratio</b></td>");

if (get_user_class() >= UC_MODERATOR) {

print("<td class=menuebutton align=center><b>Connected</b></td>");

print("<td class=menuebutton align=center><b>Stats</b></td>");

}

print("<td class=menuebutton align=center><b>Startdate</b></td>");

print("<td class=menuebutton align=center><b>Enddate</b></td>");

print("<td class=menuebutton align=center><b>Last action</b></td>");

print("<td class=menuebutton align=center><b>Finished</b></td>");

print("<td class=menuebutton align=center><b>Seeding</b></td>");

print("</tr>");

$res = mysql_query("select users.id, users.username, users.uploaded, users.downloaded, snatched.userid from snatched inner join users on snatched.userid = users.id inner join torrents on snatched.torrentid = torrents.id where snatched.torrentid =" . $_GET[id] . " ORDER BY snatched.id desc $limit");

while ($arr = mysql_fetch_assoc($res)) {

$res2 = mysql_query("SELECT id,donor,title,enabled,warned,last_access FROM users WHERE id=$arr[userid]") or sqlerr(__FILE__, __LINE__);

$arr2 = mysql_fetch_assoc($res2);

$res3 = mysql_query("SELECT * FROM peers WHERE torrent=$_GET[id] AND userid=$arr[userid]");

$arr3 = mysql_fetch_assoc($res3);

if ($arr["downloaded"] > 0) {

$ratio = number_format($arr["uploaded"] / $arr["downloaded"], 3);

$ratio = "<font color=" . get_ratio_color($ratio) . ">$ratio</font>";

}

else

if ($arr["uploaded"] > 0)

$ratio = "Inf.";

else

$ratio = "---";

$uploaded =mksize($arr["uploaded"]);

$downloaded = mksize($arr["downloaded"]);

$res5 = mysql_query("SELECT * FROM snatched WHERE torrentid = " . $_GET[id] . " AND userid = ". $arr[userid] ."");

while ($arr5 = mysql_fetch_assoc($res5)) {

if ($arr5["downloaded"] > 0) {

$ratio1 = number_format($arr5["uploaded"] / $arr5["downloaded"], 3);

$ratio1 = "<font color=" . get_ratio_color($ratio1) . ">$ratio1</font>";

}

else

if ($arr5["uploaded"] > 0)

$ratio1 = "Inf.";

else

$ratio1 = "---";

print("<tr>");

print("<td align=center><a href=userdetails.php?id=$arr[userid]><b>$arr[username]</b></a></td>");

print("<td align=center><font class=small><font color=green><u>Global:</u></font></font><br>$uploaded<br><font class=small><font color=green><u>Torrent:</u></font></font><br>". mksize($arr5[uploaded]) ."</td>");

print("<td align=center><font class=small><font color=green><u>Global:</u></font></font><br>$downloaded<br><font class=small><font color=green><u>Torrent:</u></font></font><br>". mksize($arr5[downloaded]) ."</td>");

print("<td align=center><font class=small><font color=green><u>Global:</u></font></font><br>$ratio<br><font class=small><font color=green><u>Torrent:</u></font></font><br>$ratio1</td>");

if (get_user_class() >= UC_MODERATOR) {

print("<td align=center><font class=small><font color=green><u>Client:</u></font></font><br>". $arr5[agent] ."<br><font class=small><font color=green><u>Peer-ID:</u></font></font><br>". $arr5[peer_id] ."</td>");

print("<td align=center><font class=small><font color=green><u>IP:</u></font></font><br>". $arr5[ip] ."<br><font class=small><font color=green><u>Port:</u></font></font><br>". $arr5[port] ."</td>");

}

print("<td align=center>". $arr5[start_date] ."</td>");

print("<td align=center>". $arr5[complete_date] ."</td>");

print("<td align=center>". $arr5[last_action] ."</td>");

print("<td align=center>" . ($arr5["finished"] == "yes" ? "<b><font color=green>Yes</font>" : "<font color=red>No</font></b>") . "</td>");

print("<td align=center>" . ($arr3["seeder"] == "yes" ? "<b><font color=green>Yes</font>" : "<font color=red>No</font></b>") . "</td>");

print("</tr>\n");

}

}

print("<tr><td align=center colspan=11 class=menuestats>$pagertop</td></tr>");

print("</table><br>\n");

}

//// end ////
                stdhead("Kommentek \"" . $row["name"] . "\"");
                print("<h1>Kommentek <a href=details.php?id=$id>" . $row["name"] . "</a></h1>\n");
//                print("<p><a href=\"details.php?id=$id\">Back to full details</a></p>\n");
        }

        print("<p><a name=\"startcomments\"></a></p>\n");

  $quickcomment = "<table style='border:1px solid #000000;'><tr>".
  "<td style='padding:10px;text-align:center;'><p><b>Gyors hozzászólás</b><br />".
  "<form name=comment method=\"post\" action=\"comment.php?action=add\">".
  "<textarea name=\"text\" rows=\"4\" cols=\"100\"></textarea>".
  "<input type=\"hidden\" name=\"tid\" value=\"$id\"/><br />".
  "<input type=\"submit\" class=btn value=\"Hozzászólok\" />".
  "</form></p></td></tr></table>";

        $subres = mysql_query("SELECT COUNT(*) FROM comments WHERE torrent = $id");
        $subrow = mysql_fetch_array($subres);
        $count = $subrow[0];

if (!$count) {
 print("<h3>Még senki sem szólt hozzá!</h3>\n");
 print($quickcomment);
        }
        else {
                list($pagertop, $pagerbottom, $limit) = pager(20, $count, "details.php?id=$id&", array(lastpagedefault => 1));

                $subres = mysql_query("SELECT comments.id, text, user, comments.added, editedby, editedat, avatar, warned, ".
                  "username, title, class, donor FROM comments LEFT JOIN users ON comments.user = users.id WHERE torrent = " .
                  "$id ORDER BY comments.id $limit") or sqlerr(__FILE__, __LINE__);
                $allrows = array();
                while ($subrow = mysql_fetch_array($subres))
                        $allrows[] = $subrow;

                print($commentbar);
                
                print($pagertop);

                commenttable($allrows);
$commentbar = "<p align=center><a class=index href=comment.php?action=add&amp;tid=$id>Teljes komment hozzáadása</a></p>\n";
                print("<br>\n");
                print($quickcomment);
                print($pagerbottom);
        }

        print($commentbar);
}

stdfoot();

?>