- 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)$/;
-
- 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;
-
- $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;