<?

//ob_start("ob_gzhandler");

require_once("include/bittorrent.php");

hit_start();

// get agent
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]";
elseif (preg_match("/^ABC\/ABC-([0-9]+\.[0-9]+(\.[0-9]+)*)/", $httpagent, $matches))
return "ABC $matches[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]";
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, 4) == "FUTB")
   return "BitComet/0.57p";
  elseif(substr($peer_id, 0, 6) == "exbc\0:")
   return "BitComet/0.58";
  elseif(substr($peer_id, 0, 8) == "-BC0059-")
   return "BitComet/0.59";
  elseif(substr($peer_id, 0, 8) == "-BC0060-")
   return "BitComet/0.60";
  elseif(substr($peer_id, 0, 8) == "-BC0061-")
   return "BitComet/0.61";
  elseif(substr($peer_id, 0, 7) == "exbc.\0L")
   return "BitLord/1.0";
  elseif(substr($peer_id, 0, 7) == "exbc..L")
   return "BitLord/1.1";
  elseif ((strpos($httpagent, 'BitTorrent/4.1.2')!== false) && (substr($peer_id, 2, 2) == "BS"))
   return "BitSpirit/v3";


 else

   return "BitTorrent/$matches[1]";
}elseif (ereg("^uTorrent", $httpagent))
{
 if(substr($peer_id, 0, 8) == "-UT1130-")
   return "uTorrent 1.1.3";
 if(substr($peer_id, 0, 8) == "-UT1140-")
   return "uTorrent 1.1.4";
 if(substr($peer_id, 0, 8) == "-UT1150-")
   return "uTorrent 1.1.5";
 if(substr($peer_id, 0, 8) == "-UT1161-")
   return "uTorrent 1.1.6.1";
 if(substr($peer_id, 0, 8) == "-UT1171-")
   return "uTorrent 1.1.7.1";
 if(substr($peer_id, 0, 8) == "-UT1200-")
   return "uTorrent 1.2.0.0";
 if(substr($peer_id, 0, 8) == "-UT1220-")
   return "uTorrent 1.2.2.0";
 if(substr($peer_id, 0, 8) == "-UT123B-")
   return "uTorrent/1.2.3b";
 if(substr($peer_id, 0, 8) == "-UT1300-")
   return "uTorrent 1.3.0.0";
 if(substr($peer_id, 0, 8) == "-UT1400-")
   return "uTorrent/1.4.0";
 if(substr($peer_id, 0, 8) == "-UT1130-")
   return "uTorrent/1.1.3.0";
 if(substr($peer_id, 0, 8) == "-UT1140-")
   return "uTorrent/1.1.4.0";

 else

   return "uTorrent";

}

elseif (preg_match("/^Python-urllib\\/([0-9]+\\.[0-9]+(\\.[0-9]+)*)/", $httpagent, $matches))
return "G3 Torrent";
elseif (preg_match("/MLdonkey( |\/)([0-9]+\\.[0-9]+).*/", $httpagent, $matches))
return "MLdonkey$matches[1]";
elseif (preg_match("/ed2k_plugin v([0-9]+\\.[0-9]+).*/", $httpagent, $matches))
return "eDonkey/$matches[1]";
else
return ($httpagent != "" ? $httpagent : "---");
}

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=\"tablea\" border=\"0\" cellspacing=\"1\" cellpadding=\"4\">\n";
    $s .= "<tr><td class=\"colhead\">Benutzer/IP</td>" . "<td class=\"colhead\" style=\"text-align:center\">Erreichbar</td>" . "<td class=\"colhead\" style=\"text-align:center\">Hochgeladen</td>" . "<td class=\"colhead\" style=\"text-align:center\">Rate</td>" . "<td class=\"colhead\" style=\"text-align:center\">Runtergeladen</td>" . "<td class=\"colhead\" style=\"text-align:center\">Rate</td>" . "<td class=\"colhead\" style=\"text-align:center\">Ratio</td>" . "<td class=\"colhead\" style=\"text-align:center\">Fertig</td>" . "<td class=\"colhead\" style=\"text-align:center\">Verbunden</td>" . "<td class=\"colhead\" style=\"text-align:center\">Unt&auml;tig</td>" . "<td class=\"colhead\" style=\"text-align:center\">Client</td></tr>\n";

    $mod = get_user_class() >= UC_MODERATOR;
    $now = time();
    foreach ($arr as $e) {
        // user/ip/port
        // check if anyone has this ip
        ($unr = mysql_query("SELECT username, privacy, class, donor, enabled, warned, warncount, added FROM users WHERE id=$e[userid] ORDER BY last_access DESC LIMIT 1")) or die;
        $una = mysql_fetch_array($unr);
        $tdclass = $CURUSER && $e["userid"] == $CURUSER["id"] ? " class=\"inposttable\"": " class=\"tableb\"";
 //       if ($una["privacy"] == "strong") continue;
        $s .= "<tr>\n";
        if (($una["privacy"] == "strong") && (get_user_class() <= 5) && $e["userid"] != $CURUSER["id"])
	   $s .= "<td$tdclass nowrap=\"nowrap\"><b>Anonym</b><br>xx.xx.xx.xx</td>";
	else
        if ($una["username"])
            $s .= "<td$tdclass nowrap=\"nowrap\"><a href=\"userdetails.php?id=$e[userid]\"><font class=\"" . get_class_color($una["class"]) . "\"><b>$una[username]</b></font></a>&nbsp;" . get_user_icons($una) . "<br>" . ($mod || $CURUSER[id]==$e[userid] ? $e["ip"] : preg_replace('/\.\d+$/', ".xxx", $e["ip"])) . "</td>\n";
        else
            $s .= "<td$tdclass>" . ($mod ? $e["ip"] : preg_replace('/\.\d+$/', ".xxx", $e["ip"])) . "</td>\n";

        $revived = $e["revived"] == "yes";
        $s .= "<td$tdclass style=\"text-align:center\">" . ($e[connectable] == "yes" ? "Ja" : "<font color=\"red\">Nein</font>") . "</td>\n";
        $s .= "<td$tdclass style=\"text-align:right\">" . mksize($e["uploaded"]) . "</td>\n";
        $s .= "<td$tdclass style=\"text-align:right\" nowrap=\"nowrap\">" . mksize($e["uploaded"] / max(1, $e["uploadtime"])) . "/s</td>\n";
        $s .= "<td$tdclass style=\"text-align:right\">" . mksize($e["downloaded"]) . "</td>\n";
        $s .= "<td$tdclass style=\"text-align:right\" nowrap=\"nowrap\">" . mksize($e["downloaded"] / max(1, $e["downloadtime"])) . "/s</td>\n";

        if ($e["downloaded"]) {
            $ratio = floor(($e["uploaded"] / $e["downloaded"]) * 1000) / 1000;
            $s .= "<td$tdclass style=\"text-align:right\"><font color=\"" . get_ratio_color($ratio) . "\">" . number_format($ratio, 3) . "</font></td>\n";
        } else {
            if ($e["uploaded"])
                $s .= "<td$tdclass style=\"text-align:right\">Inf.</td>\n";
            else
                $s .= "<td$tdclass style=\"text-align:right\">---</td>\n";
        } 
$GLOBALS["PIC_BASE_URL"] = "pic/";
        $s .= "<td$tdclass style=\"text-align:right\"><div title=\"" . sprintf("%.2f%%", 100 * (1 - ($e["to_go"] / $torrent["size"]))) . "\"style=\"border:1px solid black;padding:0px;width:40px;height:10px;\"><div style=\"border:none;width:" . sprintf("%.2f", 40 * (1 - ($e["to_go"] / $torrent["size"]))) . "px;height:10px;background-image:url(" . $GLOBALS["PIC_BASE_URL"] . "ryg-verlauf-small.png);background-repeat:no-repeat;\"></div></div></td>\n";
        $s .= "<td$tdclass nowrap style=\"text-align:right\">" . mkprettytime($now - $e["st"]) . "</td>\n";
        $s .= "<td$tdclass style=\"text-align:right\">" . mkprettytime($now - $e["la"]) . "</td>\n";
        $s .= "<td$tdclass style=\"text-align:left\">" . htmlspecialchars(getagent($e["agent"], $e["peer_id"])) . "</td>\n";
        $s .= "</tr>\n";
    } 
    $s .= "</table>\n";
    return $s;
} 

dbconn(false);

loggedinorreturn();

hit_count();

$id = $_GET["id"];
$id = 0 + $id;
if (!isset($id) || !$id)
	die();

$res = mysql_query("SELECT torrents.seeders, torrents.nfo, torrents.banned, torrents.screen1, torrents.screen2, torrents.werbeurl, torrents.werbeuser, torrents.staff, torrents.datestaff, torrents.donou, torrents.zonlyup, torrents.zonlydate, torrents.gu_agent, torrents.free, torrents.description, torrents.pu_ou,  torrents.class, torrents.zufall_ou, torrents.zou_time, torrents.activated, torrents.leechers, torrents.info_hash, torrents.filename, LENGTH(torrents.nfo) AS nfosz, UNIX_TIMESTAMP() - UNIX_TIMESTAMP(torrents.last_action) AS lastseed, torrents.numratings, torrents.numratings_video,torrents.numratings_audio, torrents.name, IF(torrents.numratings < $minvotes, NULL, ROUND(torrents.ratingsum / torrents.numratings, 1)) AS rating,IF(torrents.numratings_video < $minvotes, NULL, ROUND(torrents.ratingsum_video / torrents.numratings_video, 1)) AS rating_video,IF(torrents.numratings_audio < $minvotes, NULL, ROUND(torrents.ratingsum_audio / torrents.numratings_audio, 1)) AS rating_audio, 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, torrents.poster, 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);

//////////////////////////////////////////////
//////////CONFIG////////////////////////
$pngdir="/var/www/web3/html/nfo/";
$pngpath="http://www.trotz.mine.nu/nfo/";
///////////END CONFIG///////////////////
////////////////////////////////////////////////
$nfo = htmlspecialchars($row["nfo"]);
$nfo2 = format_urls($nfo);
$to_print .= "$nfo2";
$_FONT = 4;
$_MULT = 1;
$lines = explode( "\n" , $to_print );
$font = imageloadfont ("fonts/8x16.phpfont");
$height = count( $lines ) * imagefontheight( $font );
$longest = 0;

foreach( $lines as $line )
{
if( strlen( $line ) > $longest )
$longest = strlen( $line );
}
$width = $longest * imagefontwidth( $font );

$myimg = imagecreate( $width , $height );



$background = imagecolorallocate( $myimg , 169 , 185 , 196 );
#imagecolortransparent( $myimg , $background );
$textcolor = imagecolorallocate( $myimg , 0 , 0 , 0 );



for( $x = 0 , $y = count( $lines ); $x < $y; $x++ )
imagestring( $myimg , $font , 0 , $x * imagefontheight( $font ) , $lines[ $x ] , $textcolor );

$outimg = imagecreate( round( $width * $_MULT ) , round( $height * $_MULT ) );
$outbackground = imagecolorallocate( $outimg , 255 , 255 , 255 );
imagecolortransparent( $outimg , $outbackground );
imagecopyresized( $outimg , $myimg , 0 , 0 , 0 , 0 , round( $width * $_MULT ) , round( $height * $_MULT ) , $width , $height );
$image = ImageCreate ($width, $height);
ImageAlphaBlending($image, true);
ImagePNG($outimg, $pngdir . $row["id"] . ".png");


///////////////////////////////////////////////



$owned = $moderator = 0;
if ($CURUSER["id"] == $row["owner"])
    $owned = 1;
// We limit access for the GU team on torrents of users below UC_UPLOADER
elseif (get_user_class() >= UC_MODERATOR || ($row["activated"] == "no" && get_user_class() == UC_MODERATOR && $row["class"] < UC_UPLOADER))
    $owned = $moderator = 1;

if (!$row || ($row["banned"] == "yes" && !$moderator))
    stderr("Fehler", "Es existiert kein Torrent mit der ID $id.");

if (!$owned && $row["activated"] != "yes")
    stderr("Fehler", "Es existiert kein Torrent mit der ID $id.");
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");
		hit_end();
		exit();
	}
if ($_GET["activate"] && get_user_class() >= UC_MODERATOR && $row["activated"] != "yes") {
    mysql_query("UPDATE `torrents` SET `activated`='yes',`added`='".get_date_time(time())."' WHERE `id`=" . $row["id"]);

mysql_query("DELETE FROM `messages` WHERE `guid`=".$row["id"]) or sqlerr(__FILE__, __LINE__);


$dt = sqlesc(get_date_time());      
$mod_msg = sqlesc("Dein Torrent wurde von einem Moderator freigeschaltet! Dein Torrent [url=$BASEURL/details.php?id=" . $row["id"] . "]" . $row["name"] . "[/url] wurde von [url=$BASEURL/userdetails.php?id=" . $CURUSER["id"] . "]" . $CURUSER["username"] . "[/url] freigeschaltet. Du kannst jetzt mit dem Seeden beginnen.\n\nBei Fragen lies bitte zuerst das [url=$BASEURL/faq.php]FAQ[/url]!");	
mysql_query("INSERT INTO messages (sender, receiver, added, msg, poster, folder_in, subject) VALUES(0,$row[owner],$dt, $mod_msg, 0, -3, 'Gastupload')") or sqlerr(__FILE__, __LINE__);

write_log("Der Torrent <a href=\"details.php?id=" . $row["id"] . "\">" . htmlspecialchars($row["name"]) . "</a> wurde von <a href=\"userdetails.php?id=$CURUSER[id]\">$CURUSER[username]</a> freigeschaltet.");
    stderr("Torrent freigeschaltet", "Der Torrent wurde freigeschaltet, und ist nun über die Torrent-Suche auffindbar. Ebenso kann der Besitzer nun beginnen, den Torrent zu seeden. Eine Persönliche Nachricht wurde an den Uploader versendet, die ihn über die Freischaltung informiert.");

}
if ($_GET["agenttakeover"] == "acquire" && $row["gu_agent"] == 0 && $moderator && $row["activated"] != "yes") {
    $row["gu_agent"] = $CURUSER["id"];
    mysql_query("UPDATE `torrents` SET `gu_agent`=".$CURUSER["id"]." WHERE `id`=".$row["id"]);
} 
if ($_GET["agenttakeover"] == "release" && $row["gu_agent"] == $CURUSER["id"] && $moderator && $row["activated"] != "yes") {
    $row["gu_agent"] = 0;
    mysql_query("UPDATE `torrents` SET `gu_agent`=0 WHERE `id`=".$row["id"]);
} 
	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>Torrent erfolgreich Upgeloaded!</h2>\n");
			print("<p>Du kannst jetzt anfangen zu seeden. <b>Beachte</b>, das du das File erst erneut runterladen musst, bevor du seeden kannst!</p>\n");
		}
		elseif ($_GET["edited"]) {
			print("<h2>Erfolgreich bearbeitet!</h2>\n");
			if (isset($_GET["returnto"]))
				print("<p><b>Go back to <a href=\"" . htmlspecialchars($_GET["returnto"]) . "\">whence you came</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>Erfolgreich bewertet!</h2>\n");
}
elseif ($_GET["thanks"]){
  print("<h2>Danke hinzugefügt!</h2>\n");}
elseif ($_GET["nothanks"]){
  print("<h2>Du hast dich schon bedankt !!!</h2>\n");}

if ($row[activated] == 'no')
print ("<h2><b><font color=#ff000>Dieser Gastupload muss noch freigeschaltet werden</font></b></h2>\n");

$res6 = mysql_query("SELECT class,id  from users WHERE users.id = $row[owner]") or sqlerr();
$row6 = mysql_fetch_array($res6); 

$res77 = mysql_query("SELECT id, privacy FROM users WHERE id = $row[owner]") or sqlerr();
$arr77 = mysql_fetch_assoc($res77);
$anonymous = $arr77["privacy"];
if ($anonymous =='strong' && get_user_class() < UC_MODERATOR && $CURUSER[id] != $row[owner])
{
$row[username] = "Anonym";
}
else
{
$row[username] = $row[username];
}


if ($row6["class"] <= '2')
$s= "<font color=#FF0000>[GU by $row[username]]</font> $row[name]";
else
{
$s=$row["name"];
}
if ($row["pu_ou"] == "yes"){
$class = $row["class"];
$class = get_user_class_name($class);
$extra = "<font color=blue>[$class Only UP]</font>";
print("<h1>$extra</h1><br>");
}
if ($row["free"] == "yes" && $row["zonlyup"] !="yes"){
$extra = "<font color=red>[Only UP]</font>";
print("<h1>$extra</h1><br>");
}
if ($row["free"] == "yes" && $row["zonlyup"] =="yes"){
$extra = "<font color=green>[Lucky UP]</font>";
print("<h1>$extra</h1><br>");
}
if ($row["donou"] == "yes"){
$extra = "<font color=yellow>[Spender Only UP]</font>";
print("<h1>$extra</h1><br>");
}

$descrs = $row["description"];
		print("<h1>$s</h1><a href=bookmark.php?torrent=$row[id]&site=details><img border=0 src=/pic/bookmark.gif alt=Bookmark title=Lesezeichen></a><br>");
if ($CURUSER["xxx"] != 'no'){               
$res12 = mysql_query("SELECT id,name FROM torrents WHERE id < $id ORDER BY id desc") or sqlerr();
$row12 = mysql_fetch_array($res12);
$idsz = $row12["id"]; 
if ($idsz >= 1)
print("Vorheriges File: <a class=\"index\" href=\"details.php?id=$idsz\">" . htmlspecialchars($row12["name"]) . "</a><br><br>");

$res13 = mysql_query("SELECT id,name FROM torrents WHERE id > $id ORDER BY id ") or sqlerr();
$row13 = mysql_fetch_array($res13);
$idsv = $row13["id"]; 
if ($idsv >= 1)
print("Nächstes File: <a class=\"index\" href=\"details.php?id=$idsv\">" . htmlspecialchars($row13["name"]) . "</a><br><br>");
}
else
{               
$res12 = mysql_query("SELECT id,name FROM torrents WHERE id < $id AND category != '40' ORDER BY id desc") or sqlerr();
$row12 = mysql_fetch_array($res12);
$idsz = $row12["id"]; 
if ($idsz >= 1)
print("Vorheriges File: <a class=\"index\" href=\"details.php?id=$idsz\">" . htmlspecialchars($row12["name"]) . "</a><br><br>");

$res13 = mysql_query("SELECT id,name FROM torrents WHERE id > $id AND category != '40' ORDER BY id ") or sqlerr();
$row13 = mysql_fetch_array($res13);
$idsv = $row13["id"]; 
if ($idsv >= 1)
print("Nächstes File: <a class=\"index\" href=\"details.php?id=$idsv\">" . htmlspecialchars($row13["name"]) . "</a><br><br>");
}

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("Name", $s, 1);

        if ($CURUSER["class"] < 2)
  {
 $gigs = $CURUSER["uploaded"] / (1024*1024*1024);
 $ratio = (($CURUSER["downloaded"] > 0) ? ($CURUSER["uploaded"] / $CURUSER["downloaded"]) : 0);
 if ($gigs < 1) $wait = 0;
 elseif ($ratio < 0.45 || $gigs < 2.5) $wait = 24;
 elseif ($ratio < 0.60 || $gigs < 3.0) $wait = 12;
 elseif ($ratio < 0.80 || $gigs < 3.5) $wait = 6;
 elseif ($ratio < 0.95 || $gigs < 4.0) $wait = 3;
 else $wait = 0;
$elapsed = floor((time() - strtotime($row["added"])) / 3600);
  }

if ($CURUSER["id"] == $row["owner"]) $CURUSER["downloadpos"] = "yes";
if ($CURUSER["downloadpos"] != "no")
       {

$ratio = (($CURUSER["downloaded"] > 0) ? ($CURUSER["uploaded"] / $CURUSER["downloaded"]) : 0);
       $percentage = ($ratio * 100);
       print("<center><tr><td class=rowhead width=1% align=right>Download</td><br><td width=99% align=left>");
       if ((get_user_class() >= UC_VIP || $CURUSER["id"] == $row["owner"]) && $row["staff"] =='no') {
       
  //     print("<a class=\"index\" href=\"download.php?id=$id&name=" . rawurlencode($row["filename"]) . "\">" . htmlspecialchars($row["filename"]) . "</a>");



//print("<a class=index href=download.php?id=$id&name=" . rawurlencode($row["filename"]) . " ONMOUSEOVER="popup('java24.net * DIE Javascript-Resource','yellow')" ; ONMOUSEOUT="kill()">" . htmlspecialchars($row["filename"]) . "</a>");
 
print("<a class=\"index\" href=\"download.php?id=$id&name=" . rawurlencode($row["filename"]) . "\"onmouseover=\"writetxt('<center>Bitte das File nach dem Downloaden auch weiterseeden !!! Greetz // STAFF</center>')\" onmouseout=\"writetxt(0)\">" . htmlspecialchars($row["filename"]) . "</a>

");



  }
   else {
     $usid = $CURUSER["id"];
  $rs = mysql_query("SELECT * FROM users WHERE id='$usid'") or sqlerr();
  $ar = mysql_fetch_assoc($rs);
  $gigs = $ar["downloaded"] / (1024*1024*1024);
  if (($gigs > "10")&&($ratio < 0.7 and (!$owned|| 0) and ($CURUSER["downloaded"] <> 0)))
 
 {
       print("<p align=\"center\">");
       print("<font color=#ff0532><b><u>ACHTE AUF DEINE RATIO!!Bitte seede erst ein alten torrent weiter bist du wieder downloaden darfst!!!</font><border=\"1\" cellpadding=\"10\" cellspacing=\"10\"></u></b>");
       print("<p><font color=#ff0532><b>Deine ratio ist $ratio<b></font> - bedeutet das hast du ");
       print("$percentage % ");
       print("hochgeladen hast von dem was du runtergeladen hast!<p>
       Es ist wichtig sie oben zuhalten!!");
       print("Die Ratio soll helfen das alle Mitglieder schneller downloaden können!! </p>");
       print("<p><font color=#ff0532><b>Tip: <b></font>Du kannst deine Ratio verbessern, wenn ");
       print("du mindestens das gleiche wieder hochlädts bzw.seedest was Du runtergeladen hast!!<p>Du muss mindestens eine ");
       print("Ratio von 0.7  haben,dann darfst du wieder Downloaden!Schafft du dies nicht,wirst du gebannt!<p align=\"center\">");            
       print("</td></tr>");
}
else
if ($ratio <= 0.85 and (!$owned|| 0) and ($CURUSER["downloaded"] <> 0) && $elapsed >= $wait)
{
       print("<p align=\"center\">");
       print("<font color=#ff0532><b><u>Ratio Info!</font><border=\"1\" cellpadding=\"10\" cellspacing=\"10\"></u></b>");
       print("<p><font color=#ff0532><b>Deine ratio ist $ratio<b></font> - bedeutet das hast du ");
       print("$percentage % ");
       print("hochgeladen hast von dem was du runtergeladen hast!<p>
       Es ist wichtig sie oben zuhalten!!");
       print("Die Ratio soll helfen das alle Mitglieder schneller downloaden können!! </p>");
       print("<p><font color=#ff0532><b>Tip: <b></font>Du kannst deine Ratio verbessern, wenn ");
       print("du mindestens das gleiche wieder hochlädts bzw.seedest was Du runtergeladen hast!!<p>Du muss mindestens eine ");
       print("Ratio von 0.85 haben,schafft du dies nicht,werden deine downloadrechte entzogen!<p align=\"center\">");     
       print("<a class=\"index\" href=\"download.php?id=$id&name=" . rawurlencode($row["filename"]) . "\">");
       print("<font color=#ff0532>Klick hier weiter zum download!</a></font>");
       print("</td></tr>");
}
else
if ($CURUSER["warned"] == 'yes' && ($row["free"]=='yes' || $row["pu_ou"]=='yes'))
{
print("<a class=\"index\" href=\"download.php?id=$id&name=" . rawurlencode($row["filename"]) . "\"onmouseover=\"writetxt('<center>Bitte das File nach dem Downloaden auch weiterseeden !!! Greetz // STAFF</center>')\" onmouseout=\"writetxt(0)\">" . htmlspecialchars($row["filename"]) . "</a> <b><font color=red>Leider Wird bei dir auch der DL gezählt, weil du verwarnt bist!!!</font></b>");
}
elseif ($elapsed < $wait  && $row["owner"] != $CURUSER["id"])    {
print("<b><font color=red>Du hast Waittime, also warum solltest du hier klicken können ???</font></b>");
}
elseif ($row["staff"]=='yes' && get_user_class() <= UC_CO_ADMIN)    {
print("<b><font color=red>Dieses File Ist erst am $row[datestaff] zum Download bereit</font></b>");
}
else
{
print("<a class=\"index\" href=\"download.php?id=$id&name=" . rawurlencode($row["filename"]) . "\"onmouseover=\"writetxt('<center>Bitte das File nach dem Downloaden auch weiterseeden !!! Greetz // STAFF</center>')\" onmouseout=\"writetxt(0)\">" . htmlspecialchars($row["filename"]) . "</a>

");
}
      // print("<td></tr>");
}
if (get_user_class() >= UC_MODERATOR) {
if ($row["zonlyup"] =='yes' && $row["free"] =='no'){
$lup = ($row["zonlydate"]);
print("<tr><td class=rowhead width=1% align=right>Wird LuckyUP</td><td width=99% align=left>Am $lup</td></tr>");
}
if ($row["zonlyup"] =='yes' && $row["free"] =='yes'){
$lup = ($row["zonlydate"]);
print("<tr><td class=rowhead width=1% align=right>Ist LuckyUP</td><td width=99% align=left>Bis $lup</td></tr>");
}
}		
$res8 = mysql_query("SELECT users.webseed FROM users JOIN peers ON users.id = peers.userid WHERE peers.torrent=$id AND users.webseed ='yes' AND peers.seeder = 'yes'") or sqlerr();

if ($row["description"] !="" || (mysql_num_rows($res8) > 0)){

if (mysql_num_rows($res8) > 0)
{
$extra = "<font color=blue><b>[WEBSEED] </b></font>";
}
else
{
$extra ="";
}

print("<tr><td class=rowhead width=1% align=right>Mini Beschr.</td><td width=99% align=left>$extra$descrs</td></tr>");
}
$res77 = mysql_query("SELECT privacy FROM users WHERE id = $row[owner]") or sqlerr();
$arr77 = mysql_fetch_assoc($res77);
$anonymous = $arr77["privacy"];
$keepget = "";
if ($anonymous =='strong' && get_user_class() < UC_MODERATOR && $CURUSER[id] != $arr77[id])
{
$uprow ="<b>Anonym</b>";
}
else
{		

$uprow = (isset($row["username"]) ? ("<a href=userdetails.php?id=" . $row["owner"] . "><b>" . htmlspecialchars($row["username"]) .

"</b></a>") : "<i>Gelöscht</i>");
}
		if ($owned && $row["activated"] == "yes")
$uprow .= " $spacer<$editlink><b>[Bearbeiten]</b></a>";
		
elseif ($row["activated"] != "yes" && ($row["gu_agent"] == $CURUSER["id"] || $row["owner"] == $CURUSER["id"]))
$uprow .= " $spacer<$editlink><b>[Bearbeiten]</b></a>";
		
tr("Hochgeladen von", $uprow, 1);		

//		tr("Downloads&nbsp;as", $row["save_as"]);

		function hex_esc($matches) {
			return sprintf("%02x", ord($matches[0]));
		}
		//tr("Info hash", preg_replace_callback('/./s', "hex_esc", hash_pad($row["info_hash"])));
		 }
		else {
		tr("Download", "Dir ist es nicht erlaubt zu downloaden!");
		}
		  if ($row["poster"]=="")
$row["poster"] = "pic/default_avatar.gif";
if($row["screen1"]=="" && $row["screen2"]==""){
			tr("Beschreibung", "<center><img src='".$row["poster"]."' width=200px height=300px></center><br><center>".format_urls(format_comment(htmlspecialchars($row["descr"])))."<br><center><img src=pic/slunten.gif></center>", 1);
}
elseif($row["screen1"]!="" && $row["screen2"]==""){
tr("Beschreibung", "<center><img src='".$row["poster"]."' width=200px height=300px></center><br><center>".format_urls(format_comment(htmlspecialchars($row["descr"])))."<br><center><img src=pic/slunten.gif></center><center><br><u><b>Screenshots</b></u><br><br><img src='".$row[screen1]."' width=300px height=150px></center>", 1);
}
elseif($row["screen1"]=="" && $row["screen2"]!=""){
tr("Beschreibung", "<center><img src='".$row["poster"]."' width=200px height=300px></center><br><center>".format_urls(format_comment(htmlspecialchars($row["descr"])))."<br><center><img src=pic/slunten.gif></center><center><br><u><b>Screenshots</b></u><br><br><img src='".$row[screen2]."' width=300px height=150px></center>", 1);
}
elseif($row["screen1"]!="" && $row["screen2"]!=""){
tr("Beschreibung", "<center><img src='".$row["poster"]."' width=200px height=300px></center><br><center>".format_urls(format_comment(htmlspecialchars($row["descr"])))."<br><center><img src=pic/slunten.gif></center><center><br><u><b>Screenshots</b></u><br><br><img src='".$row[screen1]."' width=300px height=150px><img src='".$row[screen2]."' width=300px height=150px></center>", 1);
}
$res21 = mysql_query("SELECT crews.banner FROM crews INNER JOIN crew_members ON crews.id = crew_members.crew_id WHERE crew_members.user_id=$row[owner]") or sqlerr();
if (mysql_num_rows($res21) >= 1){
$row21 = mysql_fetch_array($res21);

print("<tr><td class=rowhead align=right>Crew</td><td colspan=2 align=left><img src=\"" . htmlspecialchars($row21["banner"]) . "\" width=400 height=60></td></tr>\n");
}
print("<tr><td class=heading valign=top align=right>NFO</td>");
print("<td align=left><a href=\"javascript: klappe_nfo('c".$array['id']."')\"><img border=\"0\" src=\"pic/zeig.gif\" id=\"picc".$array['id']."\" alt=\"Show/Hide\">" ."</a>&nbsp;&nbsp;<a href=viewnfo.php?id=$row[id]><b>Text Ansicht</b></a>");
print("<div id=\"kc".$array['id']."\" style=\"display: none;\"><img src=" . $pngpath . $row["id"] . ".png><br></div>");
print("</td></tr>\n");





//if ($row["nfosz"] > 0)
//print("<tr><td class=rowhead align=right>NFO</td><td align=left><a href=viewnfo.php?id=$row[id]><b>NFO Ansehen</b></a> (" .
//mksize($row["nfosz"]) . ")</td></tr>\n");
		if ($row["visible"] == "no")
			tr("Sichtbar", "<b>Nein</b> (Tod)", 1);
		if ($moderator)
			tr("Gebannt", $row["banned"]);

		if (isset($row["cat_name"]))
			tr("Typ", $row["cat_name"]);
		else
			tr("Typ", "(Nicht ausgewählt)");

		if ($row["type"] == "multi") {
			if (!$_GET["filelist"])
				tr("Dateien<br /><a href=\"details.php?id=$id&amp;filelist=1$keepget#filelist\" class=\"sublink\">[Liste anzeigen]</a>", $row["numfiles"] . " Dateien mit einer Gesamtgrösse<br>von " .mksize($row["size"]) . " (" . number_format($row["size"]) . " bytes)", 1);
			else {
				tr("Dateiliste", $row["numfiles"] . " Dateien", 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>Path</td><td class=colhead align=right>Size</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\">Dateiliste</a><br /><a href=\"details.php?id=$id$keepget\" class=\"sublink\">[Schliessen]</a>", $s, 1);
			}
		}
else
{
tr("Datei"," 1 mit einer Grösse von " .mksize($row["size"]) . " (" . number_format($row["size"]) . " bytes)");
}
		$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 .= "nur " . $row["numratings"];
				else
					$s .= "kein";
				$s .= ")";
			}
			else
				$s .= "Keiner hat das bis jetzt bewertet";
		}
		else {
			$rpic = ratingpic($row["rating"]);
			if (!isset($rpic))
				$s .= "invalid?";
			else
				$s .= "<b>" . $row["rating"] . " von 10 mit " . $row["numratings"] . " Bewertung(en) Total</b>";
		}
		$s .= "";
		$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(
					10 => "Spitze!",
					9 => "\/",
					8 => "\/",
					7 => "\/",
					6 => "\/",
					5 => "\/",
					4 => "\/",
					3 => "\/",
					2 => "\/",
					1 => "Shit!",
			);
			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 .= "(Du hast diesen Torrent mit " . $xrow["rating"] . " bewertet)";
				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\">(Auswahl)</option>\n";
					foreach ($ratings as $k => $v) {
						$s .= "<option value=\"$k\">$k - $v</option>\n";
					}
					$s .= "</select>\n";
					$s .= "<input type=\"submit\" value=\"Bewerten!\" />";
					$s .= "</form>\n";
				}
			}
		}
		$s .= "</td></tr></table>";

tr("All. Bewertung", $s, 1);



                // :::: END of rating ::::
		
		   /* BEGIN
		  #################################################
		        Rate Audio / Video MOD by ShiZzl3
		   ################################################ 
		  */
		
		// ::: BEGIN OF AUDIO / VIDEO RATING ::: \\
		
		if (  // wenn torrent was mit video zu tun hat, dann.....
		       $row["cat_name"] == "Filme /DVD VOB"
		    || $row["cat_name"] == "Filme/ X-VCD"
		    || $row["cat_name"] == "Filme XVID/AVI"
		    || $row["cat_name"] == "Anime"
		    || $row["cat_name"] == "Doku"
		    || $row["cat_name"] == "TV-Rip"
		    || $row["cat_name"] == "Serien"
		    || $row["cat_name"] == "HDTV"
		    || $row["cat_name"] == "XXX"
		   ) 
		{
		 // :::: BEGIN of Video rating ::::
				
		$s = "";
		$s .= "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td valign=\"top\" class=embedded>";
		if (!isset($row["rating_video"])) {
			if ($minvotes > 1) {
				$s .= "none yet (needs at least $minvotes votes and has got ";
				if ($row["numratings_video"])
					$s .= "only " . $row["numratings_video"];
				else
					$s .= "none";
				$s .= ")";
			}
			else
				$s .= "Keiner hat das bis jetzt bewertet";
		}
		else {
			$rpic = ratingpic($row["rating_video"]);
			if (!isset($rpic))
				$s .= "invalid?";
			else
				$s .= "<b>" . $row["rating_video"] . " von 10 mit " . $row["numratings_video"] . " Bewertung(en) Total</b>";
		}
		$s .= "";
		$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(
					10 => "Spitze!",
					9 => "\/",
					8 => "\/",
					7 => "\/",
					6 => "\/",
					5 => "\/",
					4 => "\/",
					3 => "\/",
					2 => "\/",
					1 => "Shit!",
			);
			if (!$owned || $moderator) {
				$xres = mysql_query("SELECT rating_video, added_video FROM ratings_video WHERE torrent = $id AND user = " . $CURUSER["id"]);
				

$xrow = mysql_fetch_array($xres);
				if ($xrow["rating_video"] != 0)
					$s .= "(Du hast die Video Quali dieses Torrent mit " . $xrow["rating_video"] . " bewertet)";
				else {
					$s .= "<form method=\"post\" action=\"takerate.php\"><input type=\"hidden\" name=\"id\" value=\"$id\" />\n";
					$s .= "<select name=\"rating_video\">\n";
					$s .= "<option value=\"0\">(Auswahl)</option>\n";
					foreach ($ratings as $k => $v) {
						$s .= "<option value=\"$k\">$k - $v</option>\n";
					}
					$s .= "</select>\n";
					$s .= "<input type=\"submit\" value=\"Bewerten!\" />";
				$s .= "</form>\n";
			}
		}
	}
	$s .= "</td></tr></table>";
		
	tr(" Vid. Bewertung", $s, 1);
	             }

// :::: END of Video rating ::::

		if (  // wenn torrent was mit AUDIO zu tun hat, dann.....
		       $row["cat_name"] == "Filme /DVD VOB"
		    || $row["cat_name"] == "Filme/ X-VCD"
		    || $row["cat_name"] == "Filme XVID/AVI"
		    || $row["cat_name"] == "Anime"
		    || $row["cat_name"] == "Doku"
		    || $row["cat_name"] == "TV-Rip"
		    || $row["cat_name"] == "Serien"
		    || $row["cat_name"] == "HDTV"
		    || $row["cat_name"] == "XXX"
		    || $row["cat_name"] == "Musik"
		   ) 
		{
		 // :::: BEGIN of Audio rating ::::
				
		$s = "";
		$s .= "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td valign=\"top\" class=embedded>";
		if (!isset($row["rating_audio"])) {
			if ($minvotes > 1) {
				$s .= "none yet (needs at least $minvotes votes and has got ";
				if ($row["numratings_audio"])
					$s .= "only " . $row["numratings_audio"];
				else
					$s .= "none";
				$s .= ")";
			}
			else
				$s .= "Keiner hat das bis jetzt bewertet";
		}
		else {
			$rpic = ratingpic($row["rating_audio"]);
			if (!isset($rpic))
				$s .= "invalid?";
			else
				$s .= "<b>" . $row["rating_audio"] . " von 10 mit " . $row["numratings_audio"] . " Bewertung(en) Total</b>";
		}
		$s .= "";
		$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(
					10 => "Spitze!",
					9 => "\/",
					8 => "\/",
					7 => "\/",
					6 => "\/",
					5 => "\/",
					4 => "\/",
					3 => "\/",
					2 => "\/",
					1 => "Shit!",
			);
			if (!$owned || $moderator) {
				$xres = mysql_query("SELECT rating_audio, added_audio FROM ratings_audio WHERE torrent = $id AND user = " . $CURUSER["id"]);
				$xrow = mysql_fetch_array($xres);
				if ($xrow["rating_audio"] != 0)
					$s .= "(Du hast die Audio Quali dieses Torrent mit " . $xrow["rating_audio"] . " bewertet)";
				else {
					$s .= "<form method=\"post\" action=\"takerate.php\"><input type=\"hidden\" name=\"id\" value=\"$id\" />\n";
					$s .= "<select name=\"rating_audio\">\n";
					$s .= "<option value=\"0\">(Auswahl)</option>\n";
					foreach ($ratings as $k => $v) {
						$s .= "<option value=\"$k\">$k - $v</option>\n";
					}
					$s .= "</select>\n";
					$s .= "<input type=\"submit\" value=\"Bewerten!\" />";
				$s .= "</form>\n";
			}
		}
	}
	$s .= "</td></tr></table>";
		
	tr("Aud. Bewertung ", $s, 1);
	             }

// :::: END of Audio rating ::::

// :::: END OF AUDIO / VIDEO RATING ::: \\

		   /* END 
		  #################################################
		        Rate Audio / Video MOD by ShiZzl3
		   ################################################ 
		  */


		tr("Geuppt", $row["added"]);
		tr("Ansicht/Downloads", $row["views"]." / ". $row["hits"]);
		

// 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("Traffic", $data);

  // Progressbar Mod
 $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("Verlauf", get_percent_completed_image(floor($progressTotal))." (".round($progressTotal)."%)", 1);

 // Totalspeed mod
 $resSpeed = mysql_query("SELECT seeders,leechers FROM torrents WHERE $where visible='yes' and id = $id ORDER BY added DESC LIMIT 15") or sqlerr(__FILE__, __LINE__);
 if ($rowTmp = mysql_fetch_row($resSpeed))
  list($seedersTmp,$leechersTmp) = $rowTmp;
 if ($seedersTmp >= 1 && $leechersTmp >= 1){
  $speedQ = mysql_query("SELECT (t.size * t.times_completed + SUM(p.downloaded)) / (UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(added)) AS totalspeed FROM torrents AS t LEFT JOIN peers AS p ON t.id = p.torrent WHERE p.seeder = 'no' AND p.torrent = '$id' GROUP BY t.id ORDER BY added ASC LIMIT 15") or sqlerr(__FILE__, __LINE__);
  $a = mysql_fetch_assoc($speedQ);
  $totalspeed = mksize($a["totalspeed"]) . "/s";
 }
 else
  $totalspeed = "Kein Traffic im Moment";
 tr("Geschwindigkeit", $totalspeed);


									 /////// completed_by hack /////////////
 if ($row["times_completed"] != 0)

 {

        echo("<tr colspan=1><td class=rowhead width=1%><img src=pic/help.png style=\"vertical-align:middle;\" title=\"Grün seedet noch\" alt=\"Grün seedet noch\">&nbsp;&nbsp;Alle Snatcher</td><td>");
        $IsNewLine = true;
        $snatched_res = mysql_query("SELECT users.username, users.warned, users.enabled, snatched.userid FROM snatched INNER JOIN users ON snatched.userid = users.id INNER JOIN torrents ON snatched.torrentid = torrents.id WHERE snatched.torrentid = $id ORDER BY snatched.id DESC");
        while ($snatched_row = mysql_fetch_array($snatched_res))
        {
                $torrent_ratio = "";
                $ratio = 1;
                $snatch_stats_res = mysql_query("SELECT uploaded, downloaded FROM snatcher_stats WHERE uid=$snatched_row[userid] AND torrent_id=" . $_GET["id"]);


                {

                        if ($snatch_stats_row["downloaded"] > 0)
                        {
                                $ratio = number_format($snatch_stats_row["uploaded"] / $snatch_stats_row["downloaded"], 2);
                                $torrent_ratio = number_format($snatch_stats_row["uploaded"] / $snatch_stats_row["downloaded"], 2);
                        }
                        else
                        {
                            if ($snatch_stats_row["uploaded"] > 0)
                                    $torrent_ratio = "Inf.";
                                else
                                         $torrent_ratio = "";
                        }
                }
                $lettercount += strlen($snatched_row["username"]) + 8 + (($snatched_row["warned"] == "yes") ? 2 : 0);
                if ($lettercount > 120)
                {
                        print "<br>";
                        $lettercount = strlen($snatched_row["username"]) + 8 + (($snatched_row["warned"] == "yes") ? 2 : 0);
                        $IsNewLine = true;
                }
                elseif (!$IsNewLine)
                        print("&nbsp;&nbsp;\n");

                $IsNewLine = false;
$res6 = mysql_query("SELECT seeder FROM peers WHERE userid = $snatched_row[userid] AND torrent = $id") or sqlerr();
$arr6 = mysql_fetch_assoc($res6);
$suser = ($snatched_row["username"]);
$res77 = mysql_query("SELECT id, privacy FROM users WHERE id = $snatched_row[userid]") or sqlerr();
$arr77 = mysql_fetch_assoc($res77);
$anonymous = $arr77["privacy"];
if ($anonymous =='strong' && get_user_class() < UC_MODERATOR && $CURUSER[id] != $arr77[id])
{
$suser = "Anonym";
}
else
{
$suser = ($snatched_row["username"]);
}
if ($arr6["seeder"] !='yes')
{$usercolor= "<font color=#FF0000>" .htmlspecialchars($suser). "</font>";}
else
{$usercolor= "<font color=#00BB00>" .htmlspecialchars($suser). "</font>";}
if ($anonymous =='strong' && get_user_class() < UC_MODERATOR && $CURUSER[id] != $arr77[id])
{
echo("<b>" . $usercolor . "</b>");
}
else
{
               // if ($snatch_stats_row["downloaded"] != 0)
                        echo("<b><a href=userdetails.php?id=" . $snatched_row["userid"] . ">" . $usercolor . "</font>" . (($snatched_row["warned"] == "yes" && $snatched_row["enabled"] == "yes") ? "<img src=\"pic/warned.gif\" border=\"0\">" : "")  . "" . (($snatched_row["enabled"] == "no") ? "<img src=\"pic/disabled.gif\" border=\"0\">" : "")  . "</a></b>");
}
             //   else
                //        echo("<b><a href=userdetails.php?id=$user_id>" . $snatched_row["username"] . (($torrent_ratio != "") ? "($torrent_ratio)" : "") . (($snatched_row["warned"] == "yes") ? "<img src=\"pic/warned.gif\" border=\"0\">" : "")  . "</a></b>");

                /*if ($i == 8)
                {
                         print "<br>";
                        $i = 1;
                }
                else
                {
                        print("&nbsp;&nbsp;");
                        $i++;
                }*/
        }
    echo ("</td></tr>");

 }

 ///// end /////


/*

		$keepget = "";
		  if($row["anonymous"] == "yes" AND get_user_class() < UC_MODERATOR AND $CURUSER["id"] != $row["owner"]){
  $row["owner"] = "<a href=#>";
  $row["username"] = "Anonymous";
 }
 else
  $row["owner"] = "<a href=userdetails.php?id=" . $row["owner"] . "";

$upnam = ($row["username"]);
$upclq = mysql_query("SELECT class, advertisename FROM users WHERE username = '$upnam'") or sqlerr();
$upclas = mysql_fetch_array($upclq);
$acclas = $upclas['class'];
$addnam = $upclas['advertisename'];

if ($acclas = 4) {
tr("Class", "Uploader",1); }
else {
tr("Class", "User",1); }


$keepget = "";
$uprow = ("<i>Anonymous</i>");

// Check if MODERATOR plus, OWNER or if uploader has Advertise Name set to Yes. If not Display Anonymous
if (get_user_class() >= UC_MODERATOR) {
$uprow = (isset($row["username"]) ? ("<a href=userdetails.php?id=" . $row["owner"] . "><b>" . htmlspecialchars($row["username"]) . "</b></a>") : "<i>unknown</i>"); }
if ($addnam == yes) {
$uprow = (isset($row["username"]) ? ("<a href=userdetails.php?id=" . $row["owner"] . "><b>" . htmlspecialchars($row["username"]) . "</b></a>") : "<i>unknown</i>"); }
if ($owned) {
$uprow .= " $spacer<$editlink><b>[Bearbeiten]</b></a>"; }
tr("Upped by", $uprow, 1);
*/
if ($row["activated"] != "yes") {
        if ($moderator) {
            echo "<tr><td class=\"tableb\" width=\"1%\"style=\"text-align:right\"><b>GU Upload</b></td><td class=\"tableb\" width=\"99%\" style=\"text-align:left\">";
            if ($row["gu_agent"] > 0) {
                $gu_agent = mysql_fetch_assoc(mysql_query("SELECT `username` FROM `users` WHERE `id`=".$row["gu_agent"]));
                echo "<font color=\"red\">Dieser Gast-Upload wird bereits von <b><a href=\"userdetails.php?id=".$row["gu_agent"]."\">".htmlspecialchars($gu_agent["username"])."</a></b> bearbeitet. ";
                if ($row["gu_agent"] == $CURUSER["id"]) {
                    echo "(<a class=\"index\" href=\"details.php?id=" . $row["id"] . "&amp;agenttakeover=release\">Bearbeitung abgeben</a>)";
                }
                echo "<br>";
            } else {
                echo "<a class=\"index\" href=\"details.php?id=" . $row["id"] . "&amp;agenttakeover=acquire\">Bearbeitung dieses Gastuploads übernehmen</a><br>";
            }
if ($row["gu_agent"] == $CURUSER[id])            
echo "<a class=\"index\" href=\"details.php?id=" . $row["id"] . "&amp;activate=1\">Torrent freischalten</a> oder <a class=\"index\" href=\"delete.php?id=" . $row["id"] . "&reasontype=5\">Torrent Löschen</a> oder <a class=\"index\" href=\"messages.php?action=send&amp;receiver=$row[owner]&amp;message=gu\">PN schicken</a></td></tr>";
        } else {
            echo "<tr><td class=\"tableb\" width=\"1%\"style=\"text-align:right\"><b>GU Upload</b></td><td class=\"tableb\" width=\"99%\" style=\"text-align:left\">Dieser Torrent muss erst von einem Moderator freigeschaltet werden, bevor er sichtbar wird.</td></tr>";
        } 

}
if ($row["activated"] == "yes" && $row["gu_agent"] > "0" && get_user_class() >= UC_MODERATOR) 
{
$gu_agent = mysql_fetch_assoc(mysql_query("SELECT `username` FROM `users` WHERE `id`=".$row["gu_agent"]));
echo "<tr><td class=\"tableb\" width=\"1%\"style=\"text-align:right\"><b>(GU)<br>Freigegeben</b></td><td class=\"tableb\" width=\"99%\" style=\"text-align:left\"><b><a href=\"userdetails.php?id=".$row["gu_agent"]."\">".htmlspecialchars($gu_agent["username"])."</a></b>";
}




    if (!$_GET["dllist"]) {
        tr("Peers<br /><a href=\"details.php?id=$id&amp;dllist=1$keepget#seeders\" class=\"sublink\">[Liste anzeigen]</a>", $row["seeders"] . " Seeder, " . $row["leechers"] . " Leecher = " . ($row["seeders"] + $row["leechers"]) . " Peer(s) gesamt  (Letzte Aktivität " . mkprettytime($row["lastseed"]) . " her).<br>Davon fertig: ".$row["times_completed"]."", 1);
    } else {
        $downloaders = array();
        $seeders = array();
        $subres = mysql_query("SELECT peer_id, seeder, ip, port, traffic.uploaded AS uploaded, traffic.downloaded AS downloaded, traffic.downloadtime AS downloadtime, traffic.uploadtime AS uploadtime, to_go, UNIX_TIMESTAMP(started) AS st, connectable, agent, UNIX_TIMESTAMP(last_action) AS la, peers.userid FROM peers LEFT JOIN traffic ON peers.userid=traffic.userid AND peers.torrent=traffic.torrentid 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\">Seeder</a><br /><a href=\"details.php?id=$id$keepget\" class=\"sublink\">[Liste verbergen]</a>", dltable("Seeder", $seeders, $row), 1);
        tr("<a name=\"leechers\">Leecher</a><br /><a href=\"details.php?id=$id$keepget\" class=\"sublink\">[Liste verbergen]</a>", dltable("Leecher", $downloaders, $row), 1);
	}
if ($CURUSER["werbung"] == "yes")
{
if ($row["werbeurl"] == "" || $row["werbeuser"] == $CURUSER["id"])
{
$uid = $CURUSER["id"]; 
print("<form method=post action=werbung.php>\n");
print("<input type=hidden name='torrentid' value='$id'>\n");
print("<input type=hidden name='werbeuser' value='$uid'>\n");
tr("Werbung", "Hier die Werbe-Url eintragen <input type=text size=60 name=werbung value=\"" . htmlspecialchars($row[werbeurl]) . "\"> <input type=submit class=btn value='Okay'></form>", 1);
tr("Werbetorrent", "<a href=downloaddump.php?id=$id&name=" . rawurlencode($row["filename"]) . ">" . htmlspecialchars($row["filename"]) . "</a> <b>Ohne den Passkey</b>", 1);
}
else
{
$werb = mysql_query("SELECT username FROM users where id=$row[werbeuser]");
    $werbu = mysql_fetch_array($werb);
tr("Werbung", "<b>Gemacht bei <a href=$row[werbeurl]>" . htmlspecialchars($row[werbeurl]) . "</a>  von " . htmlspecialchars($werbu[username]) . "", 1);
}
}

			tr("Torrent melden", "Klick <a href=report.php?torrent=$id><b>Hier</b></a> um den Torrent zu melden, weil er nicht den Regeln entspricht etc.", 1);
if ($row["times_completed"] >= 1 && $a["totalspeed"] <= 20000.0000 && $row["seeders"] <= 1 && $row["leechers"] !=0 )
{
 tr("Reseed <img src=\"pic/help.png\" style=\"vertical-align:middle;\" title=\"Schickt an alle Snatcher eine Anfrage zum Reseed\" alt=\"Schickt an alle Snatcher eine Anfrage zum Reseed\">", "Klick  <a href=takereseed.php?reseedid=$id><b>hier</b></a>", 1);
}

			$torrentid = $_GET["id"];
          $thanks_sql = mysql_query("SELECT * FROM thanks where torrentid=$torrentid");
    $thanks_all = mysql_numrows($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"];
    if ($username_t !=''){
if ($rows_a["privacy"] =='strong' && get_user_class() < UC_MODERATOR && $CURUSER[id] != $rows_a[id])   
{$thanksby =  $thanksby."Anonym,";}
else
{$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=\"Danke!\">
<input type=\"hidden\" name=\"torrentid\" value=\"$torrentid\">
</form>";
    }
    else {
    $thanksby = $thanksby." <form action=\"thanks.php\" method=\"post\">
<input type=\"submit\" name=\"submit\" value=\"Danke!\" disabled>
<input type=\"hidden\" name=\"torrentid\" value=\"$torrentid\">
</form>";
    }
    }
    else {
    $thanksby = "noch keiner
    <form action=\"thanks.php\" method=\"post\">
<input type=\"submit\" name=\"submit\" value=\"Danke!\">
<input type=\"hidden\" name=\"torrentid\" value=\"$torrentid\">
</form>
    ";
    }
        tr("Dankbar waren:",$thanksby,1);



		print("</table></p>\n");
	}
	else {
		stdhead("Comments for torrent \"" . $row["name"] . "\"");
		print("<h1>Comments for <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");
	}
	$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 = 10;
list($pagertop, $pagerbottom, $limit) = pager($perpage, $count, $_SERVER["PHP_SELF"] . "?id=" . $_GET[id] . "&" );

$res2 = mysql_query("select name from torrents where id = $_GET[id]");
$arr2 = mysql_fetch_assoc($res2);
$dt = time() - 180;
$dt = sqlesc(get_date_time($dt));

if($count >= 1){
print("<h1 align=center>Komplette Snatch Details für <a href=viewsnatches.php?id=$_GET[id]><b>$arr2[name]</b></a></h1>\n");
print("<p align=center>Die letzten 10 User (oben steht der letzte,der fertig geworden ist)</p>");

//echo $pagertop;

print("<table border=1 cellspacing=0 cellpadding=5 align=center>\n");
print("<tr><td class=colhead align=left>Username</td><td class=colhead align=left>Upload</td><td class=colhead align=left>Download</td><td class=colhead align=left>Ratio</td><td class=colhead align=left>PM User</td><td class=colhead align=left><font color=red>Report User</font></td><td class=colhead align=left>On/Off</td><td class=colhead align=left>Seeding</td></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, warncount, heart, 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);

$res31 = mysql_query("SELECT * FROM peers WHERE userid=$arr[userid] AND seeder='no' AND torrent!=$_GET[id]");
$uleech = mysql_num_rows($res31);

$res32 = mysql_query("SELECT * FROM peers WHERE userid=$arr[userid] AND seeder='yes' AND torrent!=$_GET[id]");
$useed = mysql_num_rows($res32);

$res4 = mysql_query("SELECT userid,torrentid,downloaded,uploaded FROM traffic WHERE torrentid=$_GET[id] AND userid=$arr[userid]") or sqlerr(__FILE__, __LINE__);
$arr4 = mysql_fetch_assoc($res4);

if ($arr["downloaded"] > 0)
{
      $ratio = number_format($arr["uploaded"] / $arr["downloaded"], 2);
      $ratio = "<font color=" . get_ratio_color($ratio) . ">$ratio</font>";
   }
   else
      if ($arr["uploaded"] > 0)
        $ratio = "Inf.";
else
 $ratio = "---";
if ($arr4["downloaded"] > 0)
{
      $ratio4 = number_format($arr4["uploaded"] / $arr4["downloaded"], 2);
      $ratio4 = "<font color=" . get_ratio_color($ratio4) . ">$ratio4</font>";
   }
   else
      if ($arr4["uploaded"] > 0)
        $ratio4 = "Inf.";
else
 $ratio4 = "---";

$uploaded4 =mksize($arr4["uploaded"]);
$downloaded4 = mksize($arr4["downloaded"]);
$uploaded =mksize($arr["uploaded"]);
$downloaded = mksize($arr["downloaded"]);



$rt_uploaded = 0;
$rt_downloaded = 0;
$rt_uploaded += $ars["uploaded"];
$rt_downloaded += $ars["downloaded"];



$supload =mksize($ars["uploaded"]);
$sdownload = mksize($ars["downloaded"]);

$res77 = mysql_query("SELECT privacy FROM users WHERE id=".$arr['id']) or sqlerr();
$arr77 = mysql_fetch_assoc($res77);
$anonymous = $arr77["privacy"];
if ($anonymous =='strong' && get_user_class() < UC_MODERATOR && $CURUSER[id] != $arr[id]) 
{
$details ="<b>Anonym</b>";
$pms ="<input type=submit value=\"PM\" style='height: 22px'>";
}
else
{
if (get_user_class() >= UC_MODERATOR)
{
$details ="<a href=userdetails.php?id=".$arr['id']."><b>".$arr['username']. get_user_icons($arr2) ."</b></a><br> <b><font color=green>S:".$useed."</font>/<font color=red>L:".$uleech."</font></b>";
$pms ="<form method=post action=messages.php?action=send&amp;receiver=$arr[userid]><input type=submit value=\"PM\" style='height: 22px'></form>";
}
else
{
$details ="<a href=userdetails.php?id=".$arr['id']."><b>".$arr['username']. get_user_icons($arr2) ."</b></a>";
$pms ="<form method=post action=messages.php?action=send&amp;receiver=$arr[userid]><input type=submit value=\"PM\" style='height: 22px'></form>";
}
}
print("<tr><td>".$details."</td><td align=left><b>Torrent: ".$uploaded4."</b><br>Total: ".$uploaded."</td><td align=left><b>Torrent: ".$downloaded4."</b><br>Total: $downloaded</td><td align=left><b>Torrent: $ratio4</b><br>Total: $ratio</td><td>".$pms."<form method=post action=report.php?user=".$arr['userid']."></td><td align=left><input type=submit value=\"Report\" style='height: 23px'></form></td><td align=center>".("'".$arr2['last_access']."'">$dt?"<img src=".$pic_base_url."button_online.gif border=0 alt=\"Online\">":"<img src=".$pic_base_url."button_offline.gif border=0 alt=\"Offline\">" )."</td>"."
<td align=center>" . ($arr3["seeder"] == "yes" ? "<b><font color=green>Yes</font>" : "<font color=red>No</font></b>") . "</td></tr>\n");
}
print("</table>\n");
}
	print("<p><a name=\"startcomments\"></a></p>\n");

	$commentbar = "<p align=center><a class=index href=comment.php?action=add&amp;tid=$id>Add a comment</a></p>\n <a class=index</a></p>";

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



$tures = mysql_query("SELECT id,username FROM users,thanks WHERE users.id = thanks.uid AND thanks.torid = '$id' ");

/* $turow = mysql_fetch_array($tures);
$counttu = $turow[0];
if (!$counttu) {
print("<h2>No thanks yet</h2>n");
}
*/
begin_main_frame();
end_main_frame();

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

	$commentbar = "<p align=center><a class=index href=comment.php?action=add&amp;tid=$id>Vollen Kommentar abgeben</a></p>\n";


$quickcomment = "<table style='border:3px solid #000000;'><tr>".
  "<td style='padding:10px;text-align:center;'><p><b>Schnellen Kommentar abgeben</b><br />".
  "<form name=comment method=\"post\" action=\"comment.php?action=add\">".
  "<textarea name=\"text\" rows=\"4\" cols=\"50\"></textarea>".
  "<input type=\"hidden\" name=\"tid\" value=\"$id\"/><br />".
  "<input type=\"submit\" class=btn value=\"und weg\" />".
  "</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($quickcomment);
print($commentbar); 
print("<h3>Keine Kommentare vorhanden</h3>\n");
}
	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($quickcomment);
	print($commentbar); 	
		print($pagertop);

		commenttable($allrows);

		print($pagerbottom);
	}

	//print($commentbar);
}

stdfoot();

hit_end();

?>