1 #**************************************************************************
2 # Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu> *
4 # This program is free software; you can redistribute it and/or modify *
5 # it under the terms of the GNU General Public License as published by *
6 # the Free Software Foundation; either version 2 of the License, or *
7 # (at your option) any later version. *
9 # This program is distributed in the hope that it will be useful, *
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 # GNU General Public License for more details. *
14 # You should have received a copy of the GNU General Public License *
15 # along with this program; if not, write to the *
16 # Free Software Foundation, Inc., *
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 #**************************************************************************/
21 use warnings FATAL => 'all';
23 $ND::TEMPLATE->param(TITLE => 'Forum');
30 #TODO: fetch thread info.
34 my $query = $DBH->prepare(q{SELECT fb.fbid AS id,fb.board, bool_or(fa.post) AS post
35 FROM forum_boards fb NATURAL JOIN forum_access fa
36 WHERE fb.fbid = $1 AND (gid = -1 OR gid IN (SELECT gid FROM groupmembers
38 GROUP BY fb.fbid,fb.board});
39 $board = $DBH->selectrow_hashref($query,undef,param('b'),$ND::UID) or $error .= p($DBH->errstr);
42 if ($thread){ #Display the thread
43 }elsif($board){ #List threads in this board
44 $BODY->param(Board => 1);
45 $BODY->param(Post => $board->{post});
46 $BODY->param(Id => $board->{id});
47 my $threads = $DBH->prepare(q{SELECT ft.ftid AS id,ft.subject,count(NULLIF(COALESCE(fp.time > ftv.time,TRUE),FALSE)) AS unread,count(fp.fpid) AS posts
48 FROM forum_threads ft JOIN forum_posts fp USING (ftid) LEFT OUTER JOIN forum_thread_visits ftv ON ftv.ftid = ft.ftid
50 GROUP BY ft.ftid, ft.subject});
51 $threads->execute($board->{id}) or $error .= p($DBH->errstr);
54 while (my $thread = $threads->fetchrow_hashref){
56 $thread->{Odd} = $i % 2;
57 push @threads,$thread;
59 $BODY->param(Threads => \@threads);
62 $BODY->param(Overview => 1);
63 my $categories = $DBH->prepare(q{SELECT fcid AS id,category FROM
65 my $boards = $DBH->prepare(q{SELECT fb.fbid AS id,fb.board,count(NULLIF(COALESCE(fp.fpid::boolean,FALSE) AND COALESCE(fp.time > ftv.time,TRUE),FALSE)) AS unread
66 FROM forum_boards fb NATURAL JOIN forum_access fa LEFT OUTER JOIN (forum_threads ft JOIN forum_posts fp USING (ftid)) ON fb.fbid = ft.fbid LEFT OUTER JOIN forum_thread_visits ftv ON ftv.ftid = ft.ftid
67 WHERE fb.fcid = $1 AND (gid = -1 OR gid IN (SELECT gid FROM groupmembers
69 AND (ftv.uid IS NULL OR ftv.uid = $2)
70 GROUP BY fb.fbid, fb.board
72 $categories->execute or $error .= p($DBH->errstr);
74 while (my $category = $categories->fetchrow_hashref){
75 $boards->execute($category->{id},$ND::UID) or $error .= p($DBH->errstr);
78 while (my $board = $boards->fetchrow_hashref){
80 $board->{Odd} = $i % 2;
83 $category->{Boards} = \@boards;
84 delete $category->{id};
85 push @categories,$category if $i > 0;
87 $BODY->param(Categories => \@categories);
90 $BODY->param(Error => $error);