forked from Xkeeper0/jul
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrateuser.php
118 lines (107 loc) · 3.58 KB
/
rateuser.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
// WELCOME TO THE PORTING WORLD
// PORTING AND MORE PORTING AND MORE PORTING AND MORE PORTING
require "lib/common.php";
if (!$config['enable-ratings']) {
errorpage("User ratings are disabled.", 'index.php', 'the index page');
}
if (!$loguser['id']) {
errorpage("You need to be logged in to rate users.", 'login.php', 'log in');
}
$_GET['id'] = filter_int($_GET['id']);
$_GET['action'] = filter_string($_GET['action']);
$valid = $sql->resultq("SELECT 1 FROM users WHERE id = {$_GET['id']}");
if (!$valid) {
errorpage("This user doesn't exist.", 'index.php', 'the index page');
}
pageheader();
if (isset($_POST['submit'])) {
check_token($_POST['auth']);
$_POST['rating'] = numrange(filter_int($_POST['rating']), 0, 10);
if ($_GET['id'] == $loguser['id']) {
errorpage("Thank you, ".htmlspecialchars($loguser['name']).", for attempting to rate yourself.", 'index.php', 'return to the board');
}
$sql->query("
INSERT INTO userratings (userfrom, userrated, rating)
VALUES ({$loguser['id']}, {$_GET['id']}, {$_POST['rating']})
ON DUPLICATE KEY UPDATE rating = VALUES(rating)
");
errorpage("Thank you, ".htmlspecialchars($loguser['name']).", for rating this user.", "profile.php?id={$_GET['id']}", "the user's profile");
} else if ($_GET['action'] == 'viewvotes' && $isadmin) {
$userlink = getuserlink(NULL, $_GET['id']);
// Ratings to this user
$ratings = $sql->query("
SELECT r.userfrom, r.rating, {$userfields}
FROM userratings r
LEFT JOIN users u ON r.userfrom = u.id
WHERE r.userrated = {$_GET['id']}
");
if ($sql->num_rows($ratings)) {
$fromlist = "";
while ($x = $sql->fetch($ratings)) {
$fromlist .= "<b>{$x['rating']}</b> from ".getuserlink($x).'<br>';
}
} else {
$fromlist = "None.";
}
// Ratings by this user
$ratings = $sql->query("
SELECT r.userfrom, r.rating, {$userfields}
FROM userratings r
LEFT JOIN users u ON r.userrated = u.id
WHERE r.userfrom = {$_GET['id']}
");
if ($sql->num_rows($ratings)) {
$votelist = "";
while ($x = $sql->fetch($ratings)) {
$votelist .= "<b>{$x['rating']}</b> for ".getuserlink($x).'<br>';
}
} else {
$votelist = 'None.';
}
?>
<center>
<table class="table" style="max-width: 1000px">
<tr>
<td class="tdbgh center b" style="width: 50%">Votes for <?= $userlink ?>:</td>
<td class="tdbgh center b" style="width: 50%">Votes from <?= $userlink ?>:</td>
</tr>
<tr class="vatop">
<td class="tdbg1"><?= $fromlist ?></td>
<td class="tdbg1"><?= $votelist ?></td>
</tr>
</table>
</center>
<?php
} else {
$ratesel = $sql->fetchq("SELECT 1 rated, rating FROM userratings WHERE userfrom = {$loguser['id']} AND userrated = {$_GET['id']}");
if ($ratesel && $ratesel['rated']) {
$sel[$ratesel['rating']] = " checked";
}
$ratelist = "";
for ($i = 0; $i <= 10; $i++) {
$ratelist .= "<input type='radio' name='rating' ".filter_string($sel[$i])." value='{$i}'> {$i}  ";
}
?>
<form method="POST" action="?action=rateuser&id=<?=$_GET['id']?>">
<table class="table">
<tr>
<td class="tdbgh center" style="width: 150px"> </td>
<td class="tdbgh center"> </td>
</tr>
<tr>
<td class="tdbg1 center b">Rating:</td>
<td class="tdbg2"><?= $ratelist ?></td>
</tr>
<tr>
<td class="tdbg1"> </td>
<td class="tdbg2">
<input type="submit" name="submit" VALUE="Give rating!">
<?= auth_tag() ?>
</td>
</tr>
</table>
</form>
<?php
}
pagefooter();