]> ruin.nu Git - ndwebbie.git/blob - NDWeb/Pages/Settings.pm
962035e6709360168f1a812e1c1d24d660a71246
[ndwebbie.git] / NDWeb / Pages / Settings.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 NDWeb::Pages::Settings;
21 use strict;
22 use warnings FATAL => 'all';
23 use ND::Include;
24 use CGI qw/:standard/;
25 use NDWeb::Include;
26
27 use base qw/NDWeb::XMLPage/;
28
29 $NDWeb::Page::PAGES{settings} = __PACKAGE__;
30
31 sub render_body {
32         my $self = shift;
33         my ($BODY) = @_;
34         $self->{TITLE} = 'Edit site preferences';
35         my $DBH = $self->{DBH};
36
37         if (defined param 'cmd'){
38                 if(param('cmd') eq 'stylesheet'){
39                         my $query = $DBH->prepare(q{UPDATE users SET css = NULLIF($2,'Default') WHERE uid = $1});
40                         $query->execute($ND::UID,escapeHTML(param 'stylesheet')) or $ND::ERROR .= p $DBH->errstr;
41                 }
42         }
43         if(param('oldpass') && param('pass')){
44                 my $query = $DBH->prepare('UPDATE users SET password = MD5(?) WHERE password = MD5(?) AND uid = ?');
45                 $query->execute(param('pass'),param('oldpass'),$ND::UID);
46         }
47         my ($css) = $DBH->selectrow_array(q{SELECT css FROM users WHERE uid = $1},undef,$ND::UID);
48         my @stylesheets = ({Style => 'Default'});
49         $css = '' unless defined $css;
50         while (<htdocs/stylesheets/*.css>){
51                 if(m{stylesheets/(\w+)\.css}){
52                         push @stylesheets,{Style => $1, Selected => $1 eq $css ? 1 : 0};
53                 }
54         }
55         $BODY->param(StyleSheets => \@stylesheets);
56         return $BODY;
57 }
58
59 1;