]> ruin.nu Git - ndwebbie.git/blob - NDWeb/Page.pm
Added model and renamed submodule
[ndwebbie.git] / NDWeb / Page.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 package NDWeb::Page;
20 use strict;
21 use warnings;
22 use CGI qw/:standard/;
23
24 our %PAGES;
25
26 sub new {
27         my $invocant = shift;
28         my $class = ref($invocant) || $invocant;
29         my $self = {@_};
30         $self->{PAGE} = 'main' unless (defined $self->{PAGE} and exists $PAGES{$self->{PAGE}});
31         $class = $PAGES{$self->{PAGE}};
32         bless $self, $class;
33         $self->parse;
34         $self->initiate;
35         return $self;
36 }
37
38 sub initiate : method {
39         my $self = shift;
40         my $DBH = $self->{DBH};
41
42         $DBH->do(q{SET timezone = 'GMT'});
43
44         ($self->{UID},$self->{PLANET},$self->{USER}) = $DBH->selectrow_array('SELECT uid,planet,username FROM users WHERE username ILIKE ?'
45                 ,undef,$ENV{'REMOTE_USER'});
46         $ND::UID = $self->{UID};
47
48         ($self->{TICK}) = $DBH->selectrow_array('SELECT tick()',undef);
49         $self->{TICK} = 0 unless defined $self->{TICK};
50
51
52         my $query = $DBH->prepare('SELECT groupname,attack,gid from groupmembers NATURAL JOIN groups WHERE uid = ?');
53         $query->execute($self->{UID});
54
55         while (my ($name,$attack,$gid) = $query->fetchrow()){
56                 $self->{GROUPS}{$name} = $gid;
57                 $self->{ATTACKER} = 1 if $attack;
58         }
59
60
61 }
62
63 sub parse : method {
64 }
65
66 sub render_body : method {
67         return "";
68 }
69
70 sub render : method {
71         my $self = shift;
72
73         print header;
74         print $self->render_body;
75 }
76
77 sub isInGroup ($) : method {
78         my $self = shift;
79         my $group = shift;
80         return exists $self->{GROUPS}{$group} || exists $self->{GROUPS}{Tech} || exists $self->{GROUPS}{HC};
81 }
82
83 sub isMember () : method {
84         my $self = shift;
85         $self->isInGroup('Members');
86 }
87
88 sub isHC () : method {
89         my $self = shift;
90         $self->isInGroup('HC');
91 }
92
93 sub isDC () : method {
94         $_[0]->isInGroup('DC');
95 }
96
97 sub isBC () : method {
98         $_[0]->isInGroup('BC');
99 }
100
101 sub isOfficer () : method {
102         $_[0]->isInGroup('Officers');
103 }
104
105 sub isScanner () : method {
106         $_[0]->isInGroup('Scanners');
107 }
108
109 sub isIntel () : method {
110         $_[0]->isInGroup('Intel');
111 }
112
113 sub isTech () : method {
114         $_[0]->isInGroup('Tech');
115 }
116
117
118
119 1;