source: trunk/lib/Vote/Controller/Admin.pm @ 88

Last change on this file since 88 was 85, checked in by nanardon, 15 years ago
  • kill useless warnings
File size: 3.7 KB
Line 
1package Vote::Controller::Admin;
2
3use strict;
4use warnings;
5use base 'Catalyst::Controller';
6
7=head1 NAME
8
9Vote::Controller::Admin - Catalyst Controller
10
11=head1 DESCRIPTION
12
13Catalyst Controller.
14
15=head1 METHODS
16
17=cut
18
19
20=head2 index
21
22=cut
23
24sub begin : Private {
25    my ( $self, $c ) = @_;
26    $c->model('Vote')->db->rollback;
27}
28
29sub index : Private {
30    my ( $self, $c ) = @_;
31
32    $c->res->redirect($c->uri_for('/'));
33}
34
35sub default : Private {
36    my ( $self, $c, undef, $id ) = @_;
37    $c->stash->{voteid} = $id;
38    my $vote = $c->model('Vote');
39
40    $vote->vote_info($id) or do {
41        $c->res->redirect($c->uri_for('/'));
42        return;
43    };
44
45    my $password = $c->session->{vpassword} || $c->req->param('vpassword');
46
47    if (!$c->model('Vote')->auth_poll($id, $password)) {
48        $c->stash->{page}{title} = $vote->vote_info($id)->{label} . ': Login d\'administration';
49        $c->session->{vpassword} = undef;
50        $c->stash->{template} = 'admin/login.tt';
51        return;
52    }
53
54    $c->session->{vpassword} = $password;
55
56    $c->stash->{page}{title} = $c->model('Vote')->vote_info($id)->{label} . ': Administration';
57
58    for ($vote->vote_status($id) || '') {
59    /^BEFORE$/ and do {
60        if ($c->req->param('addch')) {
61            $vote->vote_add_choice($id, $c->req->param('addch'))
62                and $vote->db->commit;
63        } elsif ($c->req->param('delch')) {
64            $vote->delete_choice($c->req->param('delch'))
65                and $vote->db->commit;
66        } elsif ($c->req->param('label')) {
67            if ($c->req->param('dstart')) {
68                $c->req->param('start',
69                    $c->req->param('dstart') . ' ' . ($c->req->param('hstart') || '')
70                );
71            }
72            if ($c->req->param('dend')) {
73                $c->req->param('end',
74                    $c->req->param('dend') . ' ' . ($c->req->param('hend') || '')
75                );
76            }
77            $vote->vote_param(
78                $id,
79                map { $_ => ($c->req->param($_) || undef) }
80                qw(label description start end choice_count free_choice)
81            ) and $vote->db->commit;
82        }
83    };
84
85    /^(BEFORE|RUNNING)$/ and do {
86        if (my ($upload) = $c->req->upload('votinglist')) {
87            $vote->voting_from_file(
88                $id,
89                $upload->fh,
90                $c->req->param('delete'),
91            ) and $vote->db->commit;
92        } elsif($c->req->param('delvoting')) {
93            $vote->delete_voting($c->req->param('delvoting'))
94                and $vote->db->commit;
95        } elsif ($c->req->param('mail')) {
96            $vote->addupd_voting($id, $c->req->param('mail'), $c->req->param('id'))
97                and $vote->db->commit;
98        } elsif($c->req->param('mailpasswd')) {
99            $vote->mail_passwd_ifnul($id, {
100                voteurl => $c->uri_for('/ballot', $id),
101            });
102        }
103    };
104
105    /^AFTER$/ and do {
106        if ($c->req->param('mapfrom') && $c->req->param('mapto')) {
107            $vote->vote_map_value(
108                $id,
109                $c->req->param('mapfrom'),
110                $c->req->param('mapto'),
111            );
112        }
113        foreach my $bid ($vote->list_vote_ballot_needvalid($id)) {
114            if (!$c->req->param($bid)) {
115                next;
116            } elsif($c->req->param($bid) eq 'invalid') {
117                $vote->mark_ballot_invalid($bid, 1);
118                $vote->db->commit;
119            } elsif($c->req->param($bid) eq 'valid') {
120                $vote->mark_ballot_invalid($bid, 0);
121                $vote->db->commit;
122            }
123        }
124    };
125    }
126
127}
128
129=head1 AUTHOR
130
131Thauvin Olivier
132
133=head1 LICENSE
134
135This library is free software, you can redistribute it and/or modify
136it under the same terms as Perl itself.
137
138=cut
139
1401;
Note: See TracBrowser for help on using the repository browser.