]> ruin.nu Git - ndwebbie.git/blobdiff - ND.pm
restructure
[ndwebbie.git] / ND.pm
diff --git a/ND.pm b/ND.pm
index 404c8795648e042764cc2c28443b56a476e85981..7d9c8c08b2677cbc27e4ae5e64fe47e6cc3ab849 100755 (executable)
--- a/ND.pm
+++ b/ND.pm
@@ -24,7 +24,7 @@ use HTML::Template;
 use DBI;
 use DBD::Pg qw(:pg_types);
 use Apache2::Request;
-use ND::Include;
+use ND::Web::Include;
 use ND::DB;
 use Tie::File;
 use Fcntl 'O_RDONLY';
@@ -43,6 +43,7 @@ sub handler {
        local $ND::BODY;
        local $ND::TICK;
        local %ND::GROUPS;
+       local $ND::ERROR;
        local $ND::PAGE = $ND::req->param('page');
 
        if ($ENV{'SCRIPT_NAME'} =~ /(\w+)(\.(pl|php|pm))?$/){
@@ -55,7 +56,9 @@ sub handler {
 
 sub page {
        our $DBH = ND::DB::DB();
-       my $error = '';
+       $DBH->do(q{SET timezone = 'GMT'});
+
+       our $ERROR = '';
 
        chdir '/var/www/ndawn/code';
 
@@ -100,9 +103,9 @@ sub page {
        }
 
        unless (my $return = do "$ND::PAGE.pl"){
-               $error .= "<p><b>couldn't parse $ND::PAGE: $@</b></p>" if $@;
-               $error .= "<p><b>couldn't do $ND::PAGE: $!</b></p>"    unless defined $return && defined $!;
-               $error .= "<p><b>couldn't run $ND::PAGE</b></p>"       unless $return;
+               $ERROR .= "<p><b>couldn't parse $ND::PAGE: $@</b></p>" if $@;
+               $ERROR .= "<p><b>couldn't do $ND::PAGE: $!</b></p>"    unless defined $return && defined $!;
+               $ERROR .= "<p><b>couldn't run $ND::PAGE</b></p>"       unless $return;
        }
 
        unless ($XML){
@@ -110,6 +113,16 @@ 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 IN (SELECT fbid FROM forum_access WHERE gid IN (SELECT groups($1)))
+                       },undef,$UID) or $ERROR .= p($DBH->errstr);
+
+               $TEMPLATE->param(UnreadPosts => $unread);
                $TEMPLATE->param(Tick => $TICK);
                $TEMPLATE->param(isMember => (($TICK - $fleetupdate < 24) || isScanner()) && $PLANET && isMember());
                $TEMPLATE->param(isHC => isHC());
@@ -123,7 +136,7 @@ sub page {
                $TEMPLATE->param(Coords => param('coords') ? param('coords') : '1:1:1');
 
        }
-       $TEMPLATE->param(Error => $error);
+       $TEMPLATE->param(Error => $ERROR);
        $ND::TEMPLATE->param(BODY => $ND::BODY->output);
        my $output = $TEMPLATE->output;
        print header(-type=> $type, -charset => 'utf-8', -Content_Length => length $output);