-sub page {
- my ($PAGE) = @_;
- our $DBH = ND::DB::DB();
- $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,$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);
- $TICK = 0 unless defined $TICK;
-
-
- my $query = $DBH->prepare('SELECT groupname,attack,gid from groupmembers NATURAL JOIN groups WHERE uid = ?');
- $query->execute($UID);
-
- our $ATTACKER = 0;
- undef our %GROUPS;
- while (my ($name,$attack,$gid) = $query->fetchrow()){
- $GROUPS{$name} = $gid;
- $ATTACKER = 1 if $attack;
- }
-
- our $XML = 0;
- our $AJAX = 1;
-
- $PAGES{$PAGE}->{process}->();
-
- 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);
- }
-
- $ND::BODY = $PAGES{$PAGE}->{render}->($DBH,$ND::BODY);
-
- 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;
-}
-