]> ruin.nu Git - ndwebbie.git/blob - ND/Web/XMLPage.pm
Object Oriented Perl
[ndwebbie.git] / ND / Web / XMLPage.pm
1 #**************************************************************************
2 #   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
3 #                                                                         *
4 #   This program is free software; you can redistribute it and/or modify  *
5 #   it under the terms of the GNU General Public License as published by  *
6 #   the Free Software Foundation; either version 2 of the License, or     *
7 #   (at your option) any later version.                                   *
8 #                                                                         *
9 #   This program is distributed in the hope that it will be useful,       *
10 #   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12 #   GNU General Public License for more details.                          *
13 #                                                                         *
14 #   You should have received a copy of the GNU General Public License     *
15 #   along with this program; if not, write to the                         *
16 #   Free Software Foundation, Inc.,                                       *
17 #   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
18 #**************************************************************************/
19
20 package ND::Web::XMLPage;
21 use strict;
22 use warnings;
23 use CGI qw/:standard/;
24 use HTML::Template;
25
26 use ND::Include;
27 use ND::Web::Page;
28 use ND::Web::Include;
29
30 our @ISA = qw/ND::Web::Page/;
31
32 sub noAccess {
33         HTML::Template->new(filename => 'templates/NoAccess.tmpl', global_vars => 1, cache => 1);
34 };
35
36 sub process : method {
37 }
38
39 sub render : method {
40         my $self = shift;
41         my $DBH = $self->{DBH};
42
43
44         chdir '/var/www/ndawn/code';
45
46         my $template = HTML::Template->new(filename => 'templates/skel.tmpl', global_vars => 1, cache => 1);
47
48         my $TICK = $self->{TICK};
49         my $ATTACKER = $self->{ATTACKER};
50
51         $self->{XML} = 0;
52         $self->{AJAX} = 1;
53
54         $self->process;
55
56         my $type = 'text/html';
57         my $body;
58         if ($self->{XML}){
59                 $type = 'text/xml';
60                 $template = HTML::Template->new(filename => "templates/xml.tmpl", cache => 1);
61                 $body = HTML::Template->new(filename => "templates/$self->{PAGE}.xml.tmpl", cache => 1);
62         }else{
63                 $body = HTML::Template->new(filename => "templates/$self->{PAGE}.tmpl", global_vars => 1, cache => 1);
64                 $body->param(PAGE => $self->{PAGE});
65         }
66
67         $body = $self->render_body($body);
68
69         unless ($self->{XML}){
70                 my $fleetupdate = $DBH->selectrow_array('SELECT landing_tick FROM fleets WHERE uid = ? AND fleet = 0',undef,$self->{UID});
71
72                 $fleetupdate = 0 unless defined $fleetupdate;
73
74                 my ($last_forum_visit) = $DBH->selectrow_array(q{SELECT last_forum_visit FROM users WHERE uid = $1}
75                         ,undef,$self->{UID}) or $ND::ERROR .= p($DBH->errstr);
76                 my ($unread,$newposts) = $DBH->selectrow_array(unread_query(),undef,$self->{UID},$last_forum_visit)
77                         or $ND::ERROR .= p($DBH->errstr);
78                 
79                 $template->param(UnreadPosts => $unread);
80                 $template->param(NewPosts => $newposts);
81                 $template->param(Tick => $TICK);
82                 $template->param(isMember => (($TICK - $fleetupdate < 24) || $self->isScanner()) && $self->{PLANET} && $self->isMember);
83                 $template->param(isHC => $self->isHC);
84                 $template->param(isDC => $self->isDC());
85                 $template->param(isBC => $self->isBC());
86                 $template->param(isIntel => $self->isBC());
87                 $template->param(isAttacker => $ATTACKER && (!$self->isMember() || ((($TICK - $fleetupdate < 24) || $self->isScanner()) && $self->{PLANET})));
88                 if ($ATTACKER && (!$self->isMember() || ((($TICK - $fleetupdate < 24) || $self->isScanner()) && $self->{PLANET}))){
89                         $template->param(Targets => listTargets());
90                 }
91                 $template->param(Coords => param('coords') ? param('coords') : '1:1:1');
92                 my ($css) = $DBH->selectrow_array(q{SELECT css FROM users WHERE uid = $1},undef,$ND::UID);
93                 $template->param(CSS => $css);
94                 $template->param(TITLE => $self->{TITLE});
95
96         }
97         $template->param(Error => $ND::ERROR);
98         $template->param(BODY => $body->output);
99         my $output = $template->output;
100         print header(-type=> $type, -charset => 'utf-8', -Content_Length => length $output);
101         print $output;
102
103
104         $DBH->rollback unless $DBH->{AutoCommit};
105         $DBH->disconnect;
106
107 };
108
109 1;