require_once("include/bittorrent.php"); $valid_actions = array('add', 'edit', 'delete', 'vieworiginal'); $action = in_array($_GET["action"], $valid_actions) ? $_GET['action'] : ''; dbconn(false); loggedinorreturn(); parked(); if ($action == "add") { if ($_SERVER["REQUEST_METHOD"] == "POST") { $torrentid = (int) $_POST["tid"]; if (!is_valid_id($torrentid)) stderr( _("Error"), _("Invalid ID")); $res = do_mysql_query("SELECT name FROM torrents WHERE id = $torrentid") or sqlerr(__FILE__,__LINE__); $arr = mysql_fetch_assoc($res); if (!$arr) stderr( _("Error"), _("No torrent with ID")); $text = trim($_POST["text"]); $text_parsed = format_comment($text); $text = mysql_escape_string($text); $text_parsed = mysql_escape_string($text_parsed); if (!$text) stderr( _("Error"), _("Comment body cannot be empty!") ); $add_comment_sql = sprintf("INSERT DELAYED INTO comments (user,torrent, added, text, text_parsed, ori_text) VALUES (%u,%u, NOW(), '%s', '%s', '%s')", $CURUSER['id'], $torrentid, $text, $text_parsed, $text); do_mysql_query($add_comment_sql); $newid = mysql_insert_id(); do_mysql_query("UPDATE LOW_PRIORITY torrents SET comments = comments + 1 WHERE id = ".$torrentid); do_mysql_query("UPDATE LOW_PRIORITY users SET comments = comments + 1 WHERE id = ".$CURUSER["id"]); header("Refresh: 0; url=details.php?id=$torrentid&viewcomm=$newid#comm$newid"); die; } $torrentid = (int) $_GET["tid"]; if (!is_valid_id($torrentid)) stderr( _("Error"), _("Invalid ID") ); $res = do_mysql_query("SELECT name FROM torrents WHERE id = $torrentid") or sqlerr(__FILE__,__LINE__); $arr = mysql_fetch_assoc($res); if (!$arr) stderr( _("Error"), _("No torrent with ID") ); stdhead( sprintf( _('Add a comment to "%s"'), htmlspecialchars($arr['name']) ) ); print("
"._('Tags')." | "._('Smilies')."
\n"); commenttable($allrows); } stdfoot(); die; } elseif ($action == "edit") { $commentid = (int) $_GET["cid"]; if (!is_valid_id($commentid)) stderr( _("Error"), _("Invalid ID")); $res = do_mysql_query("SELECT c.*, t.name FROM comments AS c LEFT JOIN torrents AS t ON c.torrent = t.id WHERE c.id=$commentid") or sqlerr(__FILE__,__LINE__); $arr = mysql_fetch_assoc($res); if (!$arr) stderr( _("Error"), _("Invalid ID")); if ($arr["user"] != $CURUSER["id"] && get_user_class() < UC_MODERATOR) stderr( _("Error"), _("Permission denied.")); if ($_SERVER["REQUEST_METHOD"] == "POST") { $text = $_POST["text"]; $returnto = htmlspecialchars($_POST["returnto"]); if ($text == "") stderr( _("Error"), "Comment body cannot be empty!"); $text_parsed = format_comment($text); $text = mysql_escape_string($text); $text_parsed = mysql_escape_string($text_parsed); $update_comment_sql = sprintf("UPDATE comments SET text='%s', text_parsed='%s', editedat=NOW(), editedby=%u WHERE id=%u", $text, $text_parsed, $CURUSER['id'],$commentid); do_mysql_query($update_comment_sql) or sqlerr(__FILE__, __LINE__); if ($returnto) header("Location: ".$returnto); else header("Location: ".$GLOBALS['DEFAULTBASEURL']); // change later ---------------------- die; } stdhead("Edit comment to \"" . $arr["name"] . "\""); print("\n"); print("
\n"); stdfoot(); die; } elseif ($action == "delete") { if( get_user_class() < UC_MODERATOR) stderr( _("Error"), _("Permission denied.")); $commentid = (int) $_GET["cid"]; if (!is_valid_id($commentid)) stderr( _("Error"), _("Invalid ID")); $sure = (int) $_GET["sure"]; if (!$sure) { $referer = htmlspecialchars($_SERVER["HTTP_REFERER"]); stderr( _("Delete comment"), sprintf( _("You are about to delete a comment. Click %s here %s if you are sure."), "", "") ); } $res = do_mysql_query("SELECT torrent FROM comments WHERE id=$commentid") or sqlerr(__FILE__,__LINE__); $arr = mysql_fetch_assoc($res); if ($arr) $torrentid = $arr["torrent"]; do_mysql_query("DELETE FROM comments WHERE id=$commentid") or sqlerr(__FILE__,__LINE__); if ($torrentid && mysql_affected_rows() > 0) do_mysql_query("UPDATE torrents SET comments = comments - 1 WHERE id = $torrentid"); $returnto = htmlspecialchars($_GET["returnto"]); if ($returnto) header("Location: $returnto"); else header("Location: ".$GLOBALS['DEFAULTBASEURL']); die; } elseif ($action == "vieworiginal") { if( get_user_class() < UC_MODERATOR) stderr( _("Error"), _("Permission denied.")); $commentid = (int) $_GET["cid"]; if (!is_valid_id($commentid)) stderr( _("Error"), _("Invalid ID") ); $res = do_mysql_query("SELECT c.*, t.name FROM comments AS c LEFT JOIN torrents AS t ON c.torrent = t.id WHERE c.id=$commentid") or sqlerr(__FILE__,__LINE__); $arr = mysql_fetch_assoc($res); if (!$arr) stderr( _("Error"), _("Invalid ID.")); stdhead( _("Original comment") ); print("\n"); print("
\n"); echo htmlspecialchars($arr["ori_text"]); print(" |