]> ruin.nu Git - ndwebbie.git/commitdiff
show all unread threads
authorMichael Andreen <harv@ruin.nu>
Tue, 2 Jan 2007 13:42:54 +0000 (13:42 +0000)
committerMichael Andreen <harv@ruin.nu>
Tue, 2 Jan 2007 13:42:54 +0000 (13:42 +0000)
forum.pl
nd.css
templates/forum.tmpl
templates/skel.tmpl

index 5d6dfba81c44c31985941b7b8a2b4f68e8611992..caf81d1680eec9389895d54b0b03c03a7c77a2d6 100644 (file)
--- a/forum.pl
+++ b/forum.pl
@@ -26,14 +26,15 @@ our $BODY;
 our $DBH;
 our $ERROR;
 
+
 my $board;
 if(param('b')){
-       my $query = $DBH->prepare(q{SELECT fb.fbid AS id,fb.board, bool_or(fa.post) AS post
+my $boards = $DBH->prepare(q{SELECT fb.fbid AS id,fb.board, bool_or(fa.post) AS post
 FROM forum_boards fb NATURAL JOIN forum_access fa
 WHERE fb.fbid = $1 AND (gid = -1 OR gid IN (SELECT gid FROM groupmembers
        WHERE uid = $2))
 GROUP BY fb.fbid,fb.board});
-       $board = $DBH->selectrow_hashref($query,undef,param('b'),$ND::UID) or $ERROR .= p($DBH->errstr);
+       $board = $DBH->selectrow_hashref($boards,undef,param('b'),$ND::UID) or $ERROR .= p($DBH->errstr);
 }
 
 my $thread;
@@ -65,6 +66,12 @@ if (defined param('cmd') && param('cmd') eq 'submit'){
        $DBH->commit or $ERROR .= p($DBH->errstr);
 }
 
+my $categories = $DBH->prepare(q{SELECT fcid AS id,category FROM forum_categories});
+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
+FROM forum_threads ft JOIN forum_posts fp USING (ftid) LEFT OUTER JOIN (SELECT * FROM forum_thread_visits WHERE uid = $2) ftv ON ftv.ftid = ft.ftid
+WHERE ft.fbid = $1
+GROUP BY ft.ftid, ft.subject
+HAVING count(NULLIF(COALESCE(fp.time > ftv.time,TRUE),FALSE)) >= $3});
 
 if ($thread){ #Display the thread
        $BODY->param(Thread => 1);
@@ -95,11 +102,7 @@ ORDER BY fp.time ASC});
        $BODY->param(Board => $board->{board});
        $BODY->param(Post => $board->{post});
        $BODY->param(Id => $board->{id});
-       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
-FROM forum_threads ft JOIN forum_posts fp USING (ftid) LEFT OUTER JOIN (SELECT * FROM forum_thread_visits WHERE uid = $2) ftv ON ftv.ftid = ft.ftid
-WHERE ft.fbid = $1
-GROUP BY ft.ftid, ft.subject});
-       $threads->execute($board->{id},$ND::UID) or $ERROR .= p($DBH->errstr);
+       $threads->execute($board->{id},$ND::UID,0) or $ERROR .= p($DBH->errstr);
        my $i = 0;
        my @threads;
        while (my $thread = $threads->fetchrow_hashref){
@@ -109,17 +112,47 @@ GROUP BY ft.ftid, ft.subject});
        }
        $BODY->param(Threads => \@threads);
 
+}elsif(defined param('allUnread')){ #List threads in this board
+       $BODY->param(AllUnread => 1);
+       $BODY->param(Id => $board->{id});
+       $categories->execute or $ERROR .= p($DBH->errstr);
+       my @categories;
+       my $boards = $DBH->prepare(q{SELECT fb.fbid AS id,fb.board, bool_or(fa.post) AS post
+FROM forum_boards fb NATURAL JOIN forum_access fa
+WHERE fb.fcid = $1 AND (gid = -1 OR gid IN (SELECT gid FROM groupmembers
+       WHERE uid = $2))
+GROUP BY fb.fbid,fb.board});
+       while (my $category = $categories->fetchrow_hashref){
+               $boards->execute($category->{id},$ND::UID) or $ERROR .= p($DBH->errstr);
+               my @boards;
+               while (my $board = $boards->fetchrow_hashref){
+                       $threads->execute($board->{id},$ND::UID,1) or $ERROR .= p($DBH->errstr);
+                       my $i = 0;
+                       my @threads;
+                       while (my $thread = $threads->fetchrow_hashref){
+                               $i++;
+                               $thread->{Odd} = $i % 2;
+                               push @threads,$thread;
+                       }
+                       $board->{Threads} = \@threads;
+                       delete $board->{post};
+                       push @boards,$board if $i > 0;
+               }
+               $category->{Boards} = \@boards;
+               delete $category->{id};
+               push @categories,$category if @boards;
+       }
+       $BODY->param(Categories => \@categories);
+
 }else{ #List boards
        $BODY->param(Overview => 1);
-       my $categories = $DBH->prepare(q{SELECT fcid AS id,category FROM
-               forum_categories});
-       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
+       $categories->execute or $ERROR .= p($DBH->errstr);
+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
 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 (SELECT * FROM forum_thread_visits WHERE uid = $2) ftv ON ftv.ftid = ft.ftid
 WHERE fb.fcid = $1 AND (gid = -1 OR gid IN (SELECT gid FROM groupmembers
                WHERE uid = $2))
 GROUP BY fb.fbid, fb.board
                });
-       $categories->execute or $ERROR .= p($DBH->errstr);
        my @categories;
        while (my $category = $categories->fetchrow_hashref){
                $boards->execute($category->{id},$ND::UID) or $ERROR .= p($DBH->errstr);
diff --git a/nd.css b/nd.css
index d281c3197b8fdbc9bb430f39f2be0fb9dee74a66..26121cd646e4369bc3495c96ee435525c14e2e22 100644 (file)
--- a/nd.css
+++ b/nd.css
@@ -30,6 +30,13 @@ table.boards td {
        border-style: solid;
        border-width: 1px;
        padding: 1px;
+       font-size: larger;
+}
+table.boards th {
+       font-size: larger;
+}
+fieldset.forum-post legend b {
+       font-size: larger;
 }
 div.leftinfo{
        float: left;
index e4ad30588faeaa491392e5fa805fe9e8a7bf77a9..68b0ad5a1c773a5429c8b3d58088096ee348f5ea 100644 (file)
        </TMPL_LOOP>
 </TMPL_LOOP>
 </table>
+<TMPL_IF Post>
+<form action="<TMPL_VAR NAME=PAGE>#NewPosts" method="post"><fieldset> <legend>New Thread</legend>
+       <p>Subject: <input type="text" name="subject" value=""/></p>
+       <textarea rows="25" cols="80" name="message"></textarea>
+       <input type="hidden" name="cmd" value="submit"/>
+       <input type="hidden" name="b" value="<TMPL_VAR NAME=Id>"/>
+       <input type="hidden" name="page" value="<TMPL_VAR NAME=PAGE>"/>
+       <br/>
+       <input type="submit" value="Submit"/>
+</fieldset></form>
+</TMPL_IF>
+</TMPL_IF>
+<TMPL_IF AllUnread>
+<h2>All new posts</h2>
+<table class="boards">
+<tr>
+       <th>Unread</th>
+       <th>Total</th>
+       <th>Subject</th>
+</tr>
+<TMPL_LOOP Categories>
+       <tr><th colspan="2"><TMPL_VAR NAME=Category></th></tr>
+       <TMPL_LOOP Boards>
+       <tr>
+               <th></th>
+               <th colspan="2"><a href="<TMPL_VAR NAME=PAGE>?b=<TMPL_VAR NAME=Id>"><TMPL_VAR NAME=Board></a></th>
+       </tr>
+               <TMPL_LOOP Threads>
+       <tr class="<TMPL_IF ODD>odd<TMPL_ELSE>even</TMPL_IF>">
+               <td align="center"><TMPL_VAR NAME=Unread></td>
+               <td align="center"><TMPL_VAR NAME=Posts></td>
+               <td><a href="<TMPL_VAR NAME=PAGE>?t=<TMPL_VAR NAME=Id>#NewPosts"><TMPL_VAR NAME=Subject></a></td>
+       </tr>
+               </TMPL_LOOP>
+       </TMPL_LOOP>
+</TMPL_LOOP>
+</table>
 </TMPL_IF>
index b25989939c229e88a0260b5298e946fb6583eda1..b42a8603c7ba945806dc88f9beec4bdf26788b8e 100644 (file)
@@ -14,6 +14,7 @@
                <ul class="linkbar">
                        <li><a href="main">Main page</a></li>
                        <li><a href="forum">Forum</a></li>
+                       <li><a href="forum?allUnread=1">New posts</a></li>
                </ul>   <p>Tick: <TMPL_VAR NAME=TICK></p>
                <TMPL_IF isMEMBER>
                <p>Member menu</p>