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

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