]> ruin.nu Git - ndwebbie.git/blobdiff - ND.pm
unread query outside include
[ndwebbie.git] / ND.pm
diff --git a/ND.pm b/ND.pm
index dd017f3a4201c73c8a579373ace4d9446e0d1eb1..c3391f2bcc2ddf74781cfd62e2de3a4ca49f488c 100755 (executable)
--- a/ND.pm
+++ b/ND.pm
@@ -26,6 +26,7 @@ use DBD::Pg qw(:pg_types);
 use Apache2::Request;
 use ND::Web::Include;
 use ND::DB;
+use ND::Include;
 use Tie::File;
 use Fcntl 'O_RDONLY';
 use strict;
@@ -52,7 +53,7 @@ sub handler {
        if ($ENV{'SCRIPT_NAME'} =~ /(\w+)(\.(pl|php|pm))?$/){
                $ND::PAGE = $1 unless $1 eq 'index' and $3 eq 'pl';
        }
-       $ND::PAGE = 'main' unless exists $PAGES{$ND::PAGE};
+       $ND::PAGE = 'main' unless (defined $ND::PAGE and exists $PAGES{$ND::PAGE});
 
        $PAGES{$ND::PAGE}->{parse}->($ENV{REQUEST_URI});
 
@@ -110,15 +111,8 @@ sub page {
 
                $fleetupdate = 0 unless defined $fleetupdate;
 
-               my ($unread) = $DBH->selectrow_array(q{
-                       SELECT count(*) AS unread
-FROM forum_boards fb NATURAL JOIN forum_threads ft 
-       JOIN forum_posts fp USING (ftid) LEFT OUTER JOIN 
-               (SELECT * FROM forum_thread_visits WHERE uid = $1) ftv ON ftv.ftid = ft.ftid
-WHERE (ftv.time IS NULL OR fp.time > ftv.time) AND fbid > 0 AND
-       fbid IN (SELECT fbid FROM forum_access WHERE gid IN (SELECT groups($1)))
-                       },undef,$UID) or $ERROR .= p($DBH->errstr);
-
+               my ($unread,$lastv) = $DBH->selectrow_array(unread_query,undef,$UID) or $ERROR .= p($DBH->errstr);
+               
                $TEMPLATE->param(UnreadPosts => $unread);
                $TEMPLATE->param(Tick => $TICK);
                $TEMPLATE->param(isMember => (($TICK - $fleetupdate < 24) || isScanner()) && $PLANET && isMember());