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
19// Forum index
20// shows the categories and the forums in each category
21
22require_once('../inc/forum.inc');
23require_once('../inc/pm.inc');
24require_once('../inc/time.inc');
25
26check_get_args(array("read", "return", "tnow", "ttok"));
27
28$user = get_logged_in_user(false);
29BoincForumPrefs::lookup($user);
30
31if (DISABLE_FORUMS && !is_admin($user)) {
32    error_page("Forums are disabled");
33}
34
35// Process request to mark all posts as read
36//
37if ((get_int("read", true) == 1)) {
38    if ($user) {
39        check_tokens($user->authenticator);
40        $now = time();
41        $user->prefs->update("mark_as_read_timestamp=$now");
42        Header("Location: ".get_str("return", true));
43    }
44}
45
46function show_forum_summary($forum) {
47    switch ($forum->parent_type) {
48    case 0:
49        $t = $forum->title;
50        $d = $forum->description;
51        break;
52    case 1:
53        $team = BoincTeam::lookup_id($forum->category);
54        $t = $forum->title;
55        if (!strlen($t)) $t = $team->name;
56        $d = $forum->description;
57        if (!strlen($d)) $d = tra("Discussion among members of %1", $team->name);
58        break;
59    }
60    echo "
61        <tr>
62        <td>
63            <a href=\"forum_forum.php?id=$forum->id\">$t</a>
64            <br><small>$d</small>
65        </td>
66        <td>$forum->threads</td>
67        <td>$forum->posts</td>
68        <td>".time_diff_str($forum->timestamp, time())."</td>
69    </tr>";
70}
71
72page_head(tra("Message boards"));
73
74show_forum_header($user);
75
76if (defined('FORUM_QA_MERGED_MODE') && FORUM_QA_MERGED_MODE){
77    $categories = BoincCategory::enum("true order by orderID");
78} else {
79    echo "<p>"
80        .tra("If you have a question or problem, please use the %1Questions & Answers%2 section of the message boards.", "<a href=\"forum_help_desk.php\">", "</a>")
81        ."</p>"
82    ;
83    $categories = BoincCategory::enum("is_helpdesk=0 order by orderID");
84}
85$first = true;
86foreach ($categories as $category) {
87    if ($first) {
88        $first = false;
89        echo "<p>";
90        show_forum_title($category, NULL, NULL);
91        echo "<p>";
92        show_mark_as_read_button($user);
93        start_table('table-striped');
94        row_heading_array(array(
95            tra("Topic"),
96            tra("Threads"),
97            tra("Posts"),
98            tra("Last post")
99        ));
100    }
101    if (strlen($category->name)) {
102        echo '
103            <tr>
104            <th class="info" colspan="4">'.$category->name.'</th>
105            </tr>
106        ';
107    }
108    $forums = BoincForum::enum("parent_type=0 and category=$category->id order by orderID");
109    foreach ($forums as $forum) {
110        show_forum_summary($forum);
111    }
112}
113
114if ($user && $user->teamid) {
115    $forum = BoincForum::lookup("parent_type=1 and category=$user->teamid");
116    if ($forum) {
117        show_forum_summary($forum);
118    }
119}
120end_table();
121
122if ($user) {
123    $subs = BoincSubscription::enum("userid=$user->id");
124    if (count($subs)) {
125        echo "<p><h3>".tra("Subscribed threads")."</h3><p>";
126        show_thread_and_context_header();
127        foreach ($subs as $sub) {
128            $thread = BoincThread::lookup_id($sub->threadid);
129            if (!$thread) {
130                BoincSubscription::delete($user->id, $sub->threadid);
131                continue;
132            }
133            if ($thread->hidden) continue;
134            show_thread_and_context($thread, $user);
135        }
136        end_table();
137    }
138}
139
140page_tail();
141BoincForumLogging::cleanup();
142
143$cvs_version_tracker[]="\$Id$";  //Generated automatically - do not edit
144?>
145