<?
require "include/bittorrent.php";

dbconn();

loggedinorreturn();

stdhead("Bookmarks");

//$id = (int)$_GET["id"];
$id = $CURUSER['id'];

$order = "bookmarks.id DESC";
$limit = "10";
$res = mysql_query("SELECT torrents.id, torrents.name, torrents.size, torrents.category, torrents.filename, torrents.added, torrents.seeders, torrents.leechers, torrents.owner, torrents.times_completed AS complete, bookmarks.id AS bid, bookmarks.torrentid, bookmarks.userid FROM bookmarks,torrents WHERE bookmarks.userid = '$id' AND torrents.id = bookmarks.torrentid ORDER BY $order") or sqlerr();
if (mysql_num_rows($res) > 0)
{
  $torrents = "<table class=main border=1 cellspacing=0 cellpadding=5>\n" .
    "<tr><td class=colhead></td><td class=colhead align=center>Type</td><td class=colhead>Name</td><td class=colhead align=center>Added</td><td class=colhead align=center>Size</td><td class=colhead>Snatched</td><td class=colhead>Sdrs</td><td class=colhead>Lchrs</td></tr>";
  while ($a = mysql_fetch_array($res))
  {
                //$r1 = mysql_query("SELECT id, username FROM users WHERE id=$a[owner]") or sqlerr(__FILE__, __LINE__);
				//$a1 = mysql_fetch_assoc($r1);
				//$owner = "<a href=userdetails.php?id=$a1[id]><b>$a1[username]</b></a>";
				$r2 = mysql_query("SELECT name, image FROM categories WHERE id=$a[category]") or sqlerr(__FILE__, __LINE__);
                $a2 = mysql_fetch_assoc($r2);
                $cat = "<img src=\"pic/$a2[image]\" alt=\"$a2[name]\">";

      if ($CURUSER["id"] == $row["owner"]) $CURUSER["downloadpos"] = "yes";
      if ($CURUSER["downloadpos"] != "no")
	
      if (($CURUSER[id] == $a[userid]) || (get_user_class() >= UC_MODERATOR) || ($CURUSER[id] == $a[bookmarks]))
	  $torrents .= "<tr class=tableb><td style='padding: 3px' align=center><a href=delmark.php?id=$a[bid]><img src=pic/minus.gif border=0 alt='Remove&nbsp;From&nbsp;Bookmarks'></a><br><br><a class=\"index\" href=\"download.php/$a[id]/" . rawurlencode($a["filename"]) . "\"><img src=pic/download.gif border=0 alt='Download&nbsp;$a[name]'></a></td><td style='padding: 0px'>$cat</td><td><a href=details.php?id=" . $a["id"] . "&hit=1><b>" . htmlspecialchars($a["name"]) . "</b></a></td>" .
        "<td align=center><nobr>" . str_replace(" ", "<br />", $a["added"]) . "</nobr></td><td align=center>" . str_replace(" ", "<br>", mksize($a["size"])) . "</td><td align=center>$a[complete]</td><td align=right>$a[seeders]</td><td align=right>$a[leechers]</td></tr>\n";
  }
  $torrents .= "</table>";
}

$ret1 = mysql_query("SELECT username FROM users WHERE id=$id") or sqlerr(__FILE__, __LINE__);
$arr1 = mysql_fetch_assoc($ret1);
$user = "<b>$arr1[username]</b>";
print("<table width=690 border=1><tr><td class=colhead align=center><b>Your Bookmarks</b></td></tr></table>\n");
print("<table width=690 class=main border=1 cellspacing=0 cellpadding=2>\n");
if (!$torrents)
  print("<tr valign=top><td align=left><center><b>No Bookmarks Here</b></center></td></tr>\n");
else {
  print("<tr valign=top><td align=center>$torrents</td></tr>\n");
}

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

?>
