<?

require_once("include/bittorrent.php");
dbconn(false);
loggedinorreturn();



$id = intval($_GET["id"]);

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

$res = sql_query("SELECT multitracker,multi_time,f_seeders,f_leechers, torrents.seeders, torrents.banned, torrents.leechers, torrents.info_hash, torrents.filename, 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, torrents.image1, torrents.image2, torrents.image3, torrents.image4, torrents.image5, 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(__FILE__, __LINE__);
$row = mysql_fetch_array($res);

sql_query("INSERT INTO readtorrents (userid, torrentid) VALUES (".sqlesc($CURUSER["id"]).", ".sqlesc($id).")")/* or sqlerr(__FILE__,__LINE__)*/;

$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($tracker_lang['error'], $tracker_lang['no_torrent_with_such_id']);
else {
        if (isset($_GET["hit"])) {
                sql_query("UPDATE torrents SET views = views + 1 WHERE id = $id");
                if (isset($_GET["tocomm"]))
                        header("Location: $DEFAULTBASEURL/details.php?id=$id&page=0#startcomments");
                elseif (isset($_GET["filelist"]))
                        header("Location: $DEFAULTBASEURL/details.php?id=$id&filelist=1#filelist");
                elseif (isset($_GET["toseeders"]))
                        header("Location: $DEFAULTBASEURL/details.php?id=$id&dllist=1#seeders");
                elseif (isset($_GET["todlers"]))
                        header("Location: $DEFAULTBASEURL/details.php?id=$id&dllist=1#leechers");
                else
                        header("Location: $DEFAULTBASEURL/details.php?id=$id");
                exit();
        }

        if (!isset($_GET["page"])) {
                stdhead($tracker_lang['torrent_details']." \"" . $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;";

                $prive = "";
                $s=$row["name"];

                ?>
				
		<!-- Детали торрента -->
		<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td class="block">
			<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr>
			<td class="block" width="10" align="left"><img src="themes/TBDev/images/news_cellpic_left.gif" width="10" height="22"></td>
			<td class="block" width="100%" align="center" valign="middle" background="themes/TBDev/images/news_cellpic.gif"><font class="block-title" valign="bottom"><strong><?=$row["cat_name"]?></strong></font></td>
			<td class="block" width="124" align="right"><img src="themes/TBDev/images/news_cellpic_right.gif" width="124" height="22"></td>
			</tr></table>
			<table width="100%" border="0" cellspacing="1" cellpadding="3"><tr><td>

		<div class="content gray"><div class="torrent-detail">
		<div class="torrent-detail-title font-bold"><?=$row["name"]?></div>
		<div class="float-right"><img alt="" class="torrent-detail-poster style-img" src="torrents/images/<?=$row["image1"]?>">
		<div align="center" id="divFaforits" class="torrent-detail-faforits"><img alt="" src="themes/TBDev/images/love16.png"><a href="javascript:favorites('insert',2,538588)">Добавить в избранное</a></div></div>
		<div class="font-bold2"><br><?print(format_comment($row["descr"]));?></div>
		<div align="left"><ul class="torrent-detail-screen">
		<?
		for ($i = 2; $i <= 5; $i++) {
					if ($row['image'.$i])
						$images[] = '<li><a href="torrents/images/' . $row['image'.$i] . '" rel="lightbox" title="Скриншот №'.($i - 1).'"><img class="style-img" title="Скриншот №'.($i - 1).'" border="0" src="screenshot.php?' . $row['image'.$i] . '" /></a></li>';
				}
				if (count($images))
					print(implode($images));
		?>
		</ul></div>
		
		<table class="torrent-info-table font-11-px border-top border-left">
		<tr><td colspan="3" align="center" class="torrent-info-table-tr1"><a href="download.php?id=<?=$id?>"><b><?=$row["name"]?></b></a></td></tr>
		<tr><td class="width-3 font-bold">Добавлен:</td><td class="font-bold2"><?=$row["added"]?></td>
		<td rowspan="7" align="center" class="width-4"><a href="download.php?id=<?=$id?>"><img alt="Скачать!" title="Скачать!" src="/themes/TBDev/images/1.png"></a><div class="blue-1"><b><?print(mksize($row["size"]));?></b></div></td></tr>
		<tr><td class="width-3 font-bold">Сид был:</td><td class="font-bold2"><?print(mkprettytime($row["lastseed"]) . " ".$tracker_lang["ago"]);?></td></tr>
		<tr><td class="width-3 font-bold">Статус:</td><td class="font-bold2"><span class="stat-green">&radic;</span> Оформлено</td></tr>
		<tr><td class="width-3 font-bold">Файл скачан:</td><td class="font-bold2"><?=$row["times_completed"]?> <?=$tracker_lang["times"]?></td></tr>
		<tr><td class="width-3 font-bold">Просмотров:</td><td class="font-bold2"><?=$row["views"]?> раз(а)</td></tr>
		<tr><td class="width-3 font-bold">Кол-во файлов:</td><td class="font-bold2"><?=$row["numfiles"]?> файл(ов)<div id="dialogFiles" title="Список файлов" style="display: none;"></div></td></tr>
		<tr><td class="width-3 font-bold">Загрузил:</td><td class="font-bold2"><a href="userdetails.php?id=<?=$row["owner"]?>"><b><?=$row["username"]?></b></a></td></tr><tr><td class="torrent-info-table-tr1 padding-all-0px"></td>
		<td class="torrent-info-table-tr1 font-bold2" align="center"><a href="/" target="_blank">Как качать?</a> &bull;
        <a href="/" target="_blank">Как раздавать?</a> &bull;
        <a href="/" target="_blank">FAQ по трекеру?</a></td><td class="torrent-info-table-tr1 padding-all-0px"></td></tr>
		</table>
		<br>
		<center class="font-bold2">Участники обмена: <?print($row["seeders"] + $row["f_seeders"]);?> сидов, <?print($row["leechers"] + $row["f_leechers"]);?> личеров = <?print($row["seeders"] + $row["f_seeders"] + $row["leechers"] + $row["f_leechers"]);?> всего</center>
		<!-- Детали торрента конец -->
				
				<?

        } else {
                stdhead($tracker_lang['comments_for']." \"" . $row["name"] . "\"");
                print("<h1>".$tracker_lang['comments_for']." <a href=details.php?id=$id>" . $row["name"] . "</a></h1>\n");
        }

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

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

        $limited = 10;

if (!$count) {

  print("<table style=\"margin-top: 2px;\" cellpadding=\"5\" width=\"100%\">");
  print("<tr><td class=colhead align=\"left\" colspan=\"2\">");
  print("<div style=\"float: left; width: auto;\" align=\"left\"> :: Список комментариев</div>");
  print("<div align=\"right\"><a href=#comments class=altlink_white>Добавить комментарий</a></div>");
  print("</td></tr><tr><td align=\"center\">");
  print("Комментариев нет. <a href=#comments>Желаете добавить?</a>");
  print("</td></tr></table><br>");

  print("<table style=\"margin-top: 2px;\" cellpadding=\"5\" width=\"100%\">");
  print("<tr><td class=colhead align=\"left\" colspan=\"2\"> <a name=comments>&nbsp;</a><b>:: Без комментариев</b></td></tr>");
  print("<tr><td align=\"center\" >");
  //print("<b>Ваше имя:</b> ");
  //print("".$CURUSER['username']."<p>");
  print("<form name=comment method=\"post\" action=\"comment.php?action=add\">");
  print("<div>");
  textbbcode("comment","text","");
  print("</div>");
  print("</td></tr><tr><td  align=\"center\" colspan=\"2\">");
  print("<input type=\"hidden\" name=\"tid\" value=\"$id\"/>");
  print("<input type=\"submit\" class=btn value=\"Разместить комментарий\" />");
  print("</td></tr></form></table>");

        }
        else {
                list($pagertop, $pagerbottom, $limit) = pager($limited, $count, "details.php?id=$id&", array(lastpagedefault => 1));

                $subres = sql_query("SELECT c.id, c.ip, c.text, c.user, c.added, c.editedby, c.editedat, u.avatar, u.warned, ".
                  "u.username, u.title, u.class, u.donor, u.downloaded, u.uploaded, u.gender, u.last_access, e.username AS editedbyname FROM comments AS c LEFT JOIN users AS u ON c.user = u.id LEFT JOIN users AS e ON c.editedby = e.id WHERE torrent = " .
                  "$id ORDER BY c.id $limit") or sqlerr(__FILE__, __LINE__);
                $allrows = array();
                while ($subrow = mysql_fetch_array($subres))
                        $allrows[] = $subrow;


         print("<table class=main cellspacing=\"0\" cellPadding=\"5\" width=\"100%\" >");
         print("<tr><td class=\"colhead\" align=\"center\" >");
         print("<div style=\"float: left; width: auto;\" align=\"left\"> :: Список комментариев</div>");
         print("<div align=\"right\"><a href=#comments class=altlink_white>Добавить комментарий</a></div>");
         print("</td></tr>");

         print("<tr><td>");
         print($pagertop);
         print("</td></tr>");
         print("<tr><td>");
                 commenttable($allrows);
         print("</td></tr>");
         print("<tr><td>");
         print($pagerbottom);
         print("</td></tr>");
         print("</table>");



  print("<table style=\"margin-top: 2px;\" cellpadding=\"5\" width=\"100%\">");
  print("<tr><td class=colhead align=\"left\" colspan=\"2\">  <a name=comments>&nbsp;</a><b>:: Добавить комментарий к торренту</b></td></tr>");
  print("<tr><td width=\"100%\" align=\"center\" >");
  //print("Ваше имя: ");
  //print("".$CURUSER['username']."<p>");
  print("<form name=comment method=\"post\" action=\"comment.php?action=add\">");
  print("<center><table border=\"0\"><tr><td class=\"clear\">");
  print("<div align=\"center\">". textbbcode("comment","text","", 1) ."</div>");
  print("</td></tr></table></center>");
  print("</td></tr><tr><td  align=\"center\" colspan=\"2\">");
  print("<input type=\"hidden\" name=\"tid\" value=\"$id\"/>");
  print("<input type=\"submit\" class=btn value=\"Разместить комментарий\" />");
  print("</td></tr></form></table>");

        }

}

stdfoot();

?>