-
Notifications
You must be signed in to change notification settings - Fork 6
/
userhistory.php
163 lines (155 loc) · 7.69 KB
/
userhistory.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
/*
// +--------------------------------------------------------------------------+
// | Project: NVTracker - NetVision BitTorrent Tracker |
// +--------------------------------------------------------------------------+
// | This file is part of NVTracker. NVTracker is based on BTSource, |
// | originally by RedBeard of TorrentBits, extensively modified by |
// | Gartenzwerg. |
// | |
// | NVTracker is free software; you can redistribute it and/or modify |
// | it under the terms of the GNU General Public License as published by |
// | the Free Software Foundation; either version 2 of the License, or |
// | (at your option) any later version. |
// | |
// | NVTracker is distributed in the hope that it will be useful, |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
// | GNU General Public License for more details. |
// | |
// | You should have received a copy of the GNU General Public License |
// | along with NVTracker; if not, write to the Free Software Foundation, |
// | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
// +--------------------------------------------------------------------------+
// | Obige Zeilen dürfen nicht entfernt werden! Do not remove above lines! |
// +--------------------------------------------------------------------------+
*/
ob_start("ob_gzhandler");
require "include/bittorrent.php";
dbconn(false);
loggedinorreturn();
$userid = $_GET["id"];
if(!is_valid_id($userid))
stderr("Error", "Invalid ID");
if(get_user_class() < UC_POWER_USER || ($CURUSER["id"] != $userid && get_user_class() < UC_MODERATOR))
stderr("Fehler", "Zugriff verweigert");
//$page = $_GET["page"];
$action = $_GET["action"];
// -------- Global variables
$perpage = 25;
// -------- Action: View posts
if($action == "viewposts"){
$select_is = "COUNT(DISTINCT p.id)";
$from_is = "posts AS p JOIN topics as t ON p.topicid = t.id JOIN forums AS f ON t.forumid = f.id";
$where_is = "p.userid = " . $userid . " AND f.minclassread <= " . $CURUSER['class'];
$order_is = "p.id DESC";
$query = "SELECT " . $select_is . " FROM " . $from_is . " WHERE " . $where_is;
$qry = $GLOBALS['DB']->prepare($query);
$qry->execute();
if($qry->rowCount())
$data = $qry->Fetch();
else
stderr("Error", "No posts found");
$postcount = $data[0];
// ------ Make page menu
list($pagertop, $pagerbottom, $limit) = pager($perpage, $postcount, $_SERVER["PHP_SELF"] . "?action=viewposts&id=" . $userid);
// ------ Get posts
$from_is = "posts AS p JOIN topics as t ON p.topicid = t.id JOIN forums AS f ON t.forumid = f.id LEFT JOIN readposts as r ON p.topicid = r.topicid AND p.userid = r.userid";
$select_is = "f.id AS f_id, f.name, t.id AS t_id, t.subject, t.lastpost, r.lastpostread, p.*";
$query = "SELECT $select_is FROM $from_is WHERE $where_is ORDER BY $order_is $limit";
$res = mysql_query($query) or sqlerr(__FILE__, __LINE__);
if(mysql_num_rows($res) == 0)
stderr("Error", "No posts found");
stdhead("Beitrags-History");
if($postcount > $perpage)
echo $pagertop;
// ------ Print table
begin_main_frame();
begin_frame("Beitrags-History", false, "650px");
while($arr = mysql_fetch_assoc($res)){
$postid = $arr["id"];
$posterid = $arr["userid"];
$topicid = $arr["t_id"];
$topicname = stripslashes($arr["subject"]);
$forumid = $arr["f_id"];
$forumname = stripslashes($arr["name"]);
$newposts = ($arr["lastpostread"] < $arr["lastpost"]) && $CURUSER["id"] == $userid;
$added = $arr["added"] . " (Vor " . (get_elapsed_time(sql_timestamp_to_unix_timestamp($arr["added"]))) . ")";
begin_table(TRUE);
print("<tr><td class=tableb>$added<br><b>Forum: </b><a href=/forums.php?action=viewforum&forumid=$forumid>$forumname</a> -- <b>Thema: </b><a href=/forums.php?action=viewtopic&topicid=$topicid>$topicname</a> -- <b>Beitrag: </b>#<a href=/forums.php?action=viewtopic&topicid=$topicid&page=p$postid#$postid>$postid</a>" . ($newposts ? " <b>(<font color=red>NEU!</font>)</b>" : "") . "</td></tr>\n");
$body = format_comment($arr["body"]);
if(is_valid_id($arr['editedby'])){
$subres = mysql_query("SELECT username FROM users WHERE id=$arr[editedby]");
if(mysql_num_rows($subres) == 1){
$subrow = mysql_fetch_assoc($subres);
$body .= "<p><font size=1 class=smallfont>Zuletzt bearbeitet von <a href=userdetails.php?id=$arr[editedby]><b>$subrow[username]</b></a> am $arr[editedat]</font></p>\n";
}
}
print("<tr valign=top><td class=tablea>$body</td></tr>\n");
end_table();
}
end_frame();
end_main_frame();
if($postcount > $perpage)
echo $pagerbottom;
stdfoot();
}
// -------- Action: View comments
if($action == "viewcomments"){
$select_is = "COUNT(*)";
// LEFT due to orphan comments
$from_is = "comments AS c LEFT JOIN torrents as t ON c.torrent = t.id";
$where_is = "c.user = $userid";
$order_is = "c.id DESC";
$query = "SELECT $select_is FROM $from_is WHERE $where_is ORDER BY $order_is";
$res = mysql_query($query) or sqlerr(__FILE__, __LINE__);
$arr = mysql_fetch_row($res) or stderr("Error", "No comments found");
$commentcount = $arr[0];
// ------ Make page menu
list($pagertop, $pagerbottom, $limit) = pager($perpage, $commentcount, $_SERVER["PHP_SELF"] . "?action=viewcomments&id=$userid&");
// ------ Get comments
$select_is = "t.name, c.torrent AS t_id, c.id, c.added, c.text";
$query = "SELECT $select_is FROM $from_is WHERE $where_is ORDER BY $order_is $limit";
$res = mysql_query($query) or sqlerr(__FILE__, __LINE__);
if(mysql_num_rows($res) == 0)
stderr("Error", "No comments found");
stdhead("Kommentar-History");
if($commentcount > $perpage)
echo $pagertop;
// ------ Print table
begin_main_frame();
begin_frame("Kommentar-History", FALSE, "650px");
while($arr = mysql_fetch_assoc($res)){
$commentid = $arr["id"];
$torrent = $arr["name"];
// make sure the line doesn't wrap
if(strlen($torrent) > 55)
$torrent = substr($torrent, 0, 52) . "...";
$torrentid = $arr["t_id"];
// find the page; this code should probably be in details.php instead
$subres = mysql_query("SELECT COUNT(*) FROM comments WHERE torrent = $torrentid AND id < $commentid") or sqlerr(__FILE__, __LINE__);
$subrow = mysql_fetch_row($subres);
$count = $subrow[0];
$comm_page = floor($count / 20);
$page_url = $comm_page?"&page=$comm_page":"";
$added = $arr["added"] . " (Vor " . (get_elapsed_time(sql_timestamp_to_unix_timestamp($arr["added"]))) . ")";
begin_table(TRUE);
print("<tr><td class=tableb>" . "$added<br><b>Torrent: </b>" .
(($torrent) ? ("<a href=/details.php?id=$torrentid&tocomm=1>$torrent</a>") : " [Deleted] ") . " -- <b>Kommentar: </b>#<a href=/details.php?id=$torrentid&tocomm=1$page_url>$commentid</a>
</td></tr>\n");
$body = format_comment($arr["text"]);
print("<tr valign=top><td class=tablea>$body</td></tr>\n");
end_table();
}
end_frame();
end_main_frame();
if($commentcount > $perpage)
echo $pagerbottom;
stdfoot();
}
// -------- Handle unknown action
if($action != "")
stderr("History Error", "Unknown action '$action'.");
// -------- Any other case
stderr("History Error", "Invalid or no query.");
?>