<?

require_once("include/bittorrent.inc.php");

if (!mkglobal("id"))
	die();

$id = 0 + $id;
if (!$id)
	die();

dbconn();

loggedinorreturn();

$res = mysql_query("SELECT name FROM torrents WHERE id = $id");
$torrow = mysql_fetch_array($res);
if (!$torrow)
	die();

stdhead("Add a comment to \"" . $torrow["name"] . "\"");

?>
<SCRIPT LANGUAGE="JavaScript">

var max=750;  		// 750 caractères maximum

function compter(f) {
	var txt=f.main.value;
	var nb=txt.length;
	if (nb>max) { 
		alert("You are limited to "+max+" characters for comments !");
		f.zone.value=txt.substring(0,max);
		nb=max;
	}
	f.nbcar.value=nb;
}

function timer() {
	compter(document.forms["form1"]);
	setTimeout("timer()",100);
}

</SCRIPT>
<BODY onload="setTimeout('timer()',100)">
<h2>Add a comment to "<?= htmlspecialchars($torrow["name"]) ?>"</h2>
<p>
<form method="post" action="takecomment.php" name="form1">
<input type="hidden" name="id" value="<?= $id ?>" />
<textarea class="input" name="main" rows="20" cols="60" onkeypress="compter(this.form)"></textarea><br>
You are currently using : <INPUT type="text" name="nbcar" size=3> characters out of 750 authorized !
</p>
<p><input class="input" type="submit" value="Do it!" /></p>
</form>
<?

$res = mysql_query("SELECT comments.id, text, comments.added, username FROM comments LEFT JOIN users ON comments.user = users.id WHERE torrent = $id ORDER BY comments.id DESC LIMIT 5");

$allrows = array();
while ($row = mysql_fetch_array($res))
	$allrows[] = $row;

if (count($allrows)) {
	print("<hr />\n");
	print("<h2>Most recent comments, in reverse order</h2>\n");
	commenttable($allrows);
}

stdfoot();

?>
