<?
require_once ("include/bittorrent.php");
dbconn ();
validcan ( false, 'can_bookmarks' );

function bark($msg, $error = true) {
	global $tracker_lang;
	stdhead ( ($error ? $tracker_lang ['error'] : $tracker_lang ['torrent'] . " " . $tracker_lang ['bookmarked']) );
	stdmsg ( ($error ? $tracker_lang ['error'] : $tracker_lang ['success']), $msg, ($error ? 'error' : 'success') );
	stdfoot ();
	exit ();
}

$id = ( int ) $_GET ["torrent"];

if (! isset ( $id ))
	bark ( $tracker_lang ['torrent_not_selected'] );

$res = sql_query ( "SELECT name FROM torrents WHERE id = $id" ) or sqlerr ( __FILE__, __LINE__ );
$arr = mysql_fetch_array ( $res );

if ((get_row_count ( "bookmarks", "WHERE userid = $CURUSER[id] AND torrentid = $id" )) > 0)
	bark ( $tracker_lang ['torrent'] . " \"" . $arr ['name'] . "\"" . $tracker_lang ['already_bookmarked'] );

sql_query ( "INSERT INTO bookmarks (userid, torrentid) VALUES ($CURUSER[id], $id)" ) or sqlerr ( __FILE__, __LINE__ );
location ( "browse.php", 3 );
bark ( $tracker_lang ['torrent'] . " \"" . $arr ['name'] . "\"" . $tracker_lang ['bookmarked'], false );

?>