forked from mlangill/biotorrents
-
Notifications
You must be signed in to change notification settings - Fork 0
/
takerate.php
45 lines (32 loc) · 1.02 KB
/
takerate.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
require_once("include/bittorrent.php");
dbconn();
function bark($msg) {
genbark($msg, "Rating failed!");
}
if (!isset($CURUSER))
bark("Must be logged in to vote");
if (!mkglobal("rating:id"))
bark("missing form data");
$id = 0 + $id;
if (!$id)
bark("invalid id");
$rating = 0 + $rating;
if ($rating <= 0 || $rating > 5)
bark("invalid rating");
$res = mysql_query("SELECT owner FROM torrents WHERE id = $id");
$row = mysql_fetch_assoc($res);
if (!$row)
bark("no such torrent");
//if ($row["owner"] == $CURUSER["id"])
// bark("You can't vote on your own torrents.");
$res = mysql_query("INSERT INTO ratings (torrent, user, rating, added) VALUES ($id, " . $CURUSER["id"] . ", $rating, NOW())");
if (!$res) {
if (mysql_errno() == 1062)
bark("You have already rated this torrent.");
else
bark(mysql_error());
}
mysql_query("UPDATE torrents SET numratings = numratings + 1, ratingsum = ratingsum + $rating WHERE id = $id");
header("Refresh: 0; url=details.php?id=$id&rated=1");
?>