- our $XML = 0;
- $XML = 1 if param('xml') and $ND::PAGE =~ /^(raids)$/;
-
- our $AJAX = 1;
-
- my $type = 'text/html';
- if ($XML){
- $type = 'text/xml';
- $ND::TEMPLATE = HTML::Template->new(filename => "templates/xml.tmpl", cache => 1);
- $ND::BODY = HTML::Template->new(filename => "templates/$ND::PAGE.xml.tmpl", cache => 1);
- }else{
- $ND::BODY = HTML::Template->new(filename => "templates/$ND::PAGE.tmpl", global_vars => 1, cache => 1);
- $ND::BODY->param(PAGE => '/'.$ND::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;
- }
-
- unless ($XML){
- my $fleetupdate = $DBH->selectrow_array('SELECT landing_tick FROM fleets WHERE uid = ? AND fleet = 0',undef,$UID);
-
- $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);
-
- $TEMPLATE->param(UnreadPosts => $unread);
- $TEMPLATE->param(Tick => $TICK);
- $TEMPLATE->param(isMember => (($TICK - $fleetupdate < 24) || isScanner()) && $PLANET && isMember());
- $TEMPLATE->param(isHC => isHC());
- $TEMPLATE->param(isDC => isDC());
- $TEMPLATE->param(isBC => isBC());
- $TEMPLATE->param(isIntel => isBC());
- $TEMPLATE->param(isAttacker => $ATTACKER && (!isMember() || ((($TICK - $fleetupdate < 24) || isScanner()) && $PLANET)));
- if ($ATTACKER && (!isMember() || ((($TICK - $fleetupdate < 24) || isScanner()) && $PLANET))){
- $ND::TEMPLATE->param(Targets => listTargets());
- }
- $TEMPLATE->param(Coords => param('coords') ? param('coords') : '1:1:1');
-
- }
- $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);
- print $output;
-
-
- $DBH->rollback;
- $DBH->disconnect;
- $DBH = undef;
- $UID = undef;
- $USER = undef;
- $PLANET = undef;
- $TEMPLATE = undef;
- $TICK = undef;
- undef %GROUPS;
- $ND::BODY = undef;