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

Last change on this file since 39 was 39, checked in by nanardon, 15 years ago
  • kill useless warn
File size: 2.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 index : Private {
25    my ( $self, $c ) = @_;
26
27}
28
29sub default : Private {
30    my ( $self, $c, undef, $id ) = @_;
31    $c->stash->{voteid} = $id;
32    my $vote = $c->model('Vote');
33
34    my $password = $c->session->{vpassword} || $c->req->param('vpassword');
35
36    if (!$c->model('Vote')->auth_poll($id, $password)) {
37        $c->session->{vpassword} = undef;
38        $c->stash->{template} = 'admin/login.tt';
39        return;
40    }
41
42    $c->session->{vpassword} = $password;
43
44    if ($vote->vote_status($id) eq 'BEFORE') {
45        if (my ($upload) = $c->req->upload('votinglist')) {
46            $vote->voting_from_file(
47                $id,
48                $upload->fh,
49                $c->req->param('delete'),
50            ) and $vote->db->commit;
51        } elsif ($c->req->param('addch')) {
52            $vote->vote_add_choice($id, $c->req->param('addch'))
53                and $vote->db->commit;
54        } elsif ($c->req->param('delch')) {
55            $vote->delete_choice($c->req->param('delch'))
56                and $vote->db->commit;
57        } elsif ($c->req->param('label')) {
58            $vote->vote_param(
59                $id,
60                map { $_ => ($c->req->param($_) || undef) }
61                qw(label description start end choice_count free_choice)
62            ) and $vote->db->commit;
63        } elsif($c->req->param('delvoting')) {
64            $vote->delete_voting($c->req->param('delvoting'))
65                and $vote->db->commit;
66        } elsif ($c->req->param('mail')) {
67            $vote->addupd_voting($id, $c->req->param('id'), $c->req->param('mail'))
68                and $vote->db->commit;
69        } elsif($c->req->param('mailpasswd')) {
70            $vote->mail_passwd_ifnul($id);
71        }
72    } elsif ($vote->vote_status($id) eq 'AFTER') {
73        foreach my $bid ($vote->list_vote_ballot_needvalid($id)) {
74            if (!$c->req->param($bid)) {
75                next;
76            } elsif($c->req->param($bid) eq 'invalid') {
77                $vote->mark_ballot_invalid($bid, 1);
78                $vote->db->commit;
79            } elsif($c->req->param($bid) eq 'valid') {
80                $vote->mark_ballot_invalid($bid, 0);
81                $vote->db->commit;
82            }
83        }
84    } else {
85        # can't modify vote after date
86        $c->stash->{template} = 'admin/denied.tt';
87        return;
88    }
89
90}
91
92=head1 AUTHOR
93
94Thauvin Olivier
95
96=head1 LICENSE
97
98This library is free software, you can redistribute it and/or modify
99it under the same terms as Perl itself.
100
101=cut
102
1031;
Note: See TracBrowser for help on using the repository browser.