use strict;
use warnings FATAL => 'all';
-tie our @PAGES, 'Tie::File', "/var/www/ndawn/code/pages", mode => O_RDONLY or die $!;
sub handler {
local $ND::r = shift;
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))?$/){
$ND::PAGE = $1 unless $1 eq 'index' and $3 eq 'pl';
}
+ $ND::PAGE = '' unless defined $ND::PAGE;
page();
return Apache2::Const::OK;
}
sub page {
our $DBH = ND::DB::DB();
- our $USER = $ENV{'REMOTE_USER'};
- my $error = '';
+ $DBH->do(q{SET timezone = 'GMT'});
+
+ our $ERROR = '';
chdir '/var/www/ndawn/code';
our $TEMPLATE = HTML::Template->new(filename => 'templates/skel.tmpl', global_vars => 1, cache => 1);
- our ($UID,$PLANET) = $DBH->selectrow_array('SELECT uid,planet FROM users WHERE username = ?'
+ our ($UID,$PLANET,$USER) = $DBH->selectrow_array('SELECT uid,planet,username FROM users WHERE username ILIKE ?'
,undef,$ENV{'REMOTE_USER'});
our ($TICK) = $DBH->selectrow_array('SELECT tick()',undef);
our $LOG = $DBH->prepare('INSERT INTO log (uid,text) VALUES(?,?)');
- $ND::PAGE = 'main' unless grep { /^$ND::PAGE$/ } @PAGES;
+ tie my @pages, 'Tie::File', "/var/www/ndawn/code/pages", mode => O_RDONLY, memory => 0 or die $!;
+ $ND::PAGE = 'main' unless grep { /^$ND::PAGE$/ } @pages;
our $XML = 0;
$XML = 1 if param('xml') and $ND::PAGE =~ /^(raids)$/;
}
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){
$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());
$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);