1<?php
2// This file is part of BOINC.
3// http://boinc.berkeley.edu
4// Copyright (C) 2014 University of California
5//
6// BOINC is free software; you can redistribute it and/or modify it
7// under the terms of the GNU Lesser General Public License
8// as published by the Free Software Foundation,
9// either version 3 of the License, or (at your option) any later version.
10//
11// BOINC is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14// See the GNU Lesser General Public License for more details.
15//
16// You should have received a copy of the GNU Lesser General Public License
17// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
18
19require_once('../inc/util.inc');
20require_once('../inc/time.inc');
21require_once('../inc/forum.inc');
22require_once('../inc/user.inc');
23
24if (DISABLE_FORUMS) error_page("Forums are disabled");
25
26check_get_args(array("userid", "offset"));
27
28$userid = get_int("userid");
29$offset = get_int("offset", true);
30if (!$offset) $offset=0;
31$items_per_page = 20;
32
33$user = BoincUser::lookup_id($userid);
34$logged_in_user = get_logged_in_user(false);
35BoincForumPrefs::lookup($logged_in_user);
36
37// Policy for what to show:
38// Team message board posts:
39//    if requesting user is a member of team
40//        if post is hidden
41//           show only if requesting user is team admin
42//    else don't show
43// Other posts
44//    if post is hidden
45//       show only if requesting user is project admin
46//
47
48$show_all = false;
49$show_hidden = false;
50$teamid = 0;
51$show_team = false;
52$show_team_hidden = false;
53
54if ($logged_in_user) {
55    if ($user->id == $logged_in_user->id) {
56        $show_all = true;
57    } else {
58        if ($logged_in_user->prefs->privilege(0)) {
59            $show_hidden = true;
60        }
61        $teamid = $logged_in_user->teamid;
62        if ($teamid) {
63            $team = BoincTeam::lookup_id($teamid);
64            if ($team) {
65                $show_team = true;
66                if (is_team_admin($logged_in_user, $team)) {
67                    $show_team_hidden = true;
68                }
69            } else {
70                $teamid = 0;
71            }
72        }
73    }
74}
75page_head(tra("Posts by %1", $user->name));
76
77$posts = BoincPost::enum("user=$userid order by id desc limit 10000");
78$n = 0;
79start_table('table-striped');
80$options = get_output_options($logged_in_user);
81
82$show_next = false;
83foreach ($posts as $post) {
84    $thread = BoincThread::lookup_id($post->thread);
85    if (!$thread) continue;
86    $forum = BoincForum::lookup_id($thread->forum);
87    if (!$forum) continue;
88    if (!$show_all) {
89        if ($forum->parent_type == 1) {
90            // post to team msg board
91            if ($forum->category == $teamid) {
92				if ($thread->hidden && !$show_team_hidden) {
93					continue;
94				}
95                if ($post->hidden && !$show_team_hidden) {
96                    continue;
97                }
98            } else {
99                continue;
100            }
101        } else {
102			if ($thread->hidden && !$show_hidden) {
103				continue;
104			}
105            if ($post->hidden && !$show_hidden) {
106                continue;
107            }
108        }
109    }
110	if ($n == $offset + $items_per_page) {
111		$show_next = true;
112		break;
113	}
114    if ($n >= $offset) {
115        show_post_and_context($post, $thread, $forum, $options, $n+1);
116    }
117    $n++;
118}
119echo "</table><br><br>\n";
120
121if ($offset) {
122	$x = $offset - $items_per_page;
123    echo "<a href=forum_user_posts.php?userid=$userid&offset=$x>
124		<b>".tra("Previous %1", $items_per_page)."</b>
125		</a>
126    ";
127	if ($show_next) echo " &middot; ";
128}
129
130if ($show_next) {
131    $offset += $items_per_page;
132    echo "<a href=forum_user_posts.php?userid=$userid&offset=$offset>
133		<b>".tra("Next %1", $items_per_page)."</b>
134		</a>
135    ";
136}
137
138page_tail();
139?>
140