1<?php
2// This file is part of BOINC.
3// http://boinc.berkeley.edu
4// Copyright (C) 2008 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
19// display the threads in a forum.
20
21require_once('../inc/util.inc');
22require_once('../inc/time.inc');
23require_once('../inc/forum.inc');
24require_once('../inc/pm.inc');
25
26check_get_args(array("id", "sort", "start"));
27
28$id = get_int("id");
29$sort_style = get_int("sort", true);
30$start = get_int("start", true);
31if (!$start) $start = 0;
32
33$forum = BoincForum::lookup_id($id);
34if (!$forum) error_page("forum ID not found");
35$user = get_logged_in_user(false);
36BoincForumPrefs::lookup($user);
37
38if (DISABLE_FORUMS && !is_admin($user)) {
39    error_page("Forums are disabled");
40}
41
42if (!is_forum_visible_to_user($forum, $user)) {
43    if ($user) {
44        remove_subscriptions_forum($user->id, $id);
45    }
46    error_page(tra("Not visible to you"));
47}
48
49if (!$sort_style) {
50    // get the sort style either from the logged in user or a cookie
51    if ($user){
52        $sort_style = $user->prefs->forum_sorting;
53    } else {
54        list($sort_style, $thread_style) = parse_forum_cookie();
55    }
56} else {
57    // set the sort style
58    if ($user){
59        $user->prefs->forum_sorting = $sort_style;
60        $user->prefs->update("forum_sorting=$sort_style");
61    } else {
62        list($old_style, $thread_style) = parse_forum_cookie();
63        send_cookie(
64            'sorting', implode("|", array($sort_style, $thread_style)), true
65        );
66    }
67}
68
69
70switch ($forum->parent_type) {
71case 0:
72    $category = BoincCategory::lookup_id($forum->category);
73    if ($category->is_helpdesk) {
74        page_head(tra("Questions and Answers").' : '.$forum->title);
75    } else {
76        page_head(tra("Message boards").' : '.$forum->title);
77    }
78    show_forum_header($user);
79    show_forum_title($category, $forum, NULL);
80    break;
81case 1:
82    $team = BoincTeam::lookup_id($forum->category);
83    page_head(tra("Team message board for %1", "<a href=team_display.php?teamid=$team->id>$team->name</a>"));
84    show_forum_header($user);
85    show_team_forum_title($forum);
86    break;
87}
88
89echo '
90    <p>
91    <form action="forum_forum.php" method="get" class="form-inline">
92    <input type="hidden" name="id" value="'.$forum->id.'">
93    <table width="100%" cellspacing="0" cellpadding="0">
94    <tr valign="top">
95    <td colspan=2>
96';
97
98if (user_can_create_thread($user, $forum)) {
99    show_button(
100        "forum_post.php?id=$id", tra("New thread"), tra("Add a new thread to this forum")
101    );
102}
103
104echo '</td>
105    <td valign=top align="right">
106    <div class="form-group">
107';
108echo select_from_array("sort", $forum_sort_styles, $sort_style);
109echo '
110    <input class="btn btn-default btn-sm" type="submit" value="Sort">
111    </div>
112    </td>
113    </tr>
114    </table>
115    </form>
116    <p></p>
117';
118
119show_forum($forum, $start, $sort_style, $user);
120
121echo "
122    <p>".
123    tra("This message board is available as an %1RSS feed%2", "<a href=forum_rss.php?forumid=$forum->id&setup=1>", " <img src=img/feed_logo.png></a>");
124
125page_tail();
126
127// This function shows the threads for the given forum
128// Starting from $start,
129// using the given $sort_style (as defined in forum.php)
130// and using the features for the logged in user in $user.
131//
132function show_forum($forum, $start, $sort_style, $user) {
133    $page_nav = page_links(
134        "forum_forum.php?id=$forum->id&amp;sort=$sort_style",
135        $forum->threads,
136        THREADS_PER_PAGE,
137        $start
138    );
139    echo $page_nav;
140    start_table('table-striped');
141    row_heading_array(array(
142        "",
143        tra("Threads"),
144        tra("Posts"),
145        tra("Author"),
146        tra("Views"),
147        "<nobr>".tra("Last post")."</nobr>"
148    ));
149
150    $sticky_first = !$user || !$user->prefs->ignore_sticky_posts;
151
152    // Show hidden threads if logged in user is a moderator
153    //
154    $show_hidden = is_moderator($user, $forum);
155    $threads = get_forum_threads(
156        $forum->id, $start, THREADS_PER_PAGE,
157        $sort_style, $show_hidden, $sticky_first
158    );
159
160    if ($user) {
161        $subs = BoincSubscription::enum("userid=$user->id");
162    }
163
164    // Run through the list of threads, displaying each of them
165    //
166    foreach ($threads as $thread) {
167        $owner = BoincUser::lookup_id($thread->owner);
168        if (!$owner) continue;
169        $unread = thread_is_unread($user, $thread);
170
171        //if ($thread->status==1){
172            // This is an answered helpdesk thread
173        if ($user && is_subscribed($thread, $subs)) {
174            echo '<tr class="bg-info">';
175        } else {
176            // Just a standard thread.
177            echo '<tr>';
178        }
179
180        echo "<td width=\"1%\"><nobr>";
181        if ($thread->hidden) {
182            show_image(IMAGE_HIDDEN, tra("This thread is hidden"), tra("hidden"));
183        } else if ($unread) {
184            if ($thread->sticky) {
185                if ($thread->locked) {
186                    show_image(NEW_IMAGE_STICKY_LOCKED, tra("This thread is sticky and locked, and you haven't read it yet"), tra("sticky/locked/unread"));
187                } else {
188                    show_image(NEW_IMAGE_STICKY, tra("This thread is sticky and you haven't read it yet"), tra("sticky/unread"));
189                }
190            } else {
191                if ($thread->locked) {
192                    show_image(NEW_IMAGE_LOCKED, tra("You haven't read this thread yet, and it's locked"), tra("unread/locked"));
193                } else {
194                    show_image(NEW_IMAGE, tra("You haven't read this thread yet"), tra("unread"));
195                }
196            }
197        } else {
198            if ($thread->sticky) {
199                if ($thread->locked) {
200                    show_image(IMAGE_STICKY_LOCKED, tra("This thread is sticky and locked"), tra("sticky/locked"));
201                } else {
202                    show_image(IMAGE_STICKY, tra("This thread is sticky"), tra("sticky"));
203                }
204            } else {
205                if ($thread->locked) {
206                    show_image(IMAGE_LOCKED, tra("This thread is locked"), tra("locked"));
207                } else {
208                    show_image(IMAGE_POST, tra("You read this thread"), tra("read"));
209                }
210            }
211        }
212        echo "</nobr></td>";
213
214        $title = cleanup_title($thread->title);
215        //$titlelength = 9999;
216        //if (strlen($title) > $titlelength) {
217        //    $title = substr($title, 0, $titlelength)."...";
218        //}
219        echo "<td><a href=\"forum_thread.php?id=$thread->id\">$title</a><br></td>";
220
221        echo '
222            <td>'.($thread->replies+1).'</td>
223            <td>'.user_links($owner, BADGE_HEIGHT_SMALL).'</td>
224            <td>'.$thread->views.'</td>
225            <td>'.time_diff_str($thread->timestamp, time()).'</td>
226            </tr>
227        ';
228        flush();
229    }
230    end_table();
231    echo "<br>$page_nav";    // show page links
232}
233
234?>
235