1 | package Vote::Controller::Admin; |
---|
2 | |
---|
3 | use strict; |
---|
4 | use warnings; |
---|
5 | use base 'Catalyst::Controller'; |
---|
6 | |
---|
7 | =head1 NAME |
---|
8 | |
---|
9 | Vote::Controller::Admin - Catalyst Controller |
---|
10 | |
---|
11 | =head1 DESCRIPTION |
---|
12 | |
---|
13 | Catalyst Controller. |
---|
14 | |
---|
15 | =head1 METHODS |
---|
16 | |
---|
17 | =cut |
---|
18 | |
---|
19 | |
---|
20 | =head2 index |
---|
21 | |
---|
22 | =cut |
---|
23 | |
---|
24 | sub index : Private { |
---|
25 | my ( $self, $c ) = @_; |
---|
26 | |
---|
27 | } |
---|
28 | |
---|
29 | sub default : Private { |
---|
30 | my ( $self, $c, undef, $id ) = @_; |
---|
31 | $c->stash->{voteid} = $id; |
---|
32 | |
---|
33 | # can't modify vote after date |
---|
34 | if ($c->model('Vote')->vote_status($id) ne 'BEFORE') { |
---|
35 | $c->stash->{template} = 'admin/denied.tt'; |
---|
36 | return; |
---|
37 | } |
---|
38 | |
---|
39 | my $vote = $c->model('Vote'); |
---|
40 | if (my ($upload) = $c->req->upload('votinglist')) { |
---|
41 | $vote->voting_from_file( |
---|
42 | $id, |
---|
43 | $upload->fh, |
---|
44 | $c->req->param('delete'), |
---|
45 | ) and $vote->db->commit; |
---|
46 | } elsif ($c->req->param('addch')) { |
---|
47 | $vote->vote_add_choice($id, $c->req->param('addch')) |
---|
48 | and $vote->db->commit; |
---|
49 | } elsif ($c->req->param('delch')) { |
---|
50 | $vote->delete_choice($c->req->param('delch')) |
---|
51 | and $vote->db->commit; |
---|
52 | } elsif ($c->req->param('label')) { |
---|
53 | $vote->vote_param( |
---|
54 | $id, |
---|
55 | map { $_ => ($c->req->param($_) || undef) } |
---|
56 | qw(label description start end choice_count free_choice) |
---|
57 | ) and $vote->db->commit; |
---|
58 | } elsif($c->req->param('delvoting')) { |
---|
59 | $vote->delete_voting($c->req->param('delvoting')) |
---|
60 | and $vote->db->commit; |
---|
61 | } elsif ($c->req->param('mail')) { |
---|
62 | $vote->addupd_voting($id, $c->req->param('id'), $c->req->param('mail')) |
---|
63 | and $vote->db->commit; |
---|
64 | } elsif($c->req->param('mailpasswd')) { |
---|
65 | $vote->mail_passwd_ifnul($id); |
---|
66 | } |
---|
67 | } |
---|
68 | |
---|
69 | =head1 AUTHOR |
---|
70 | |
---|
71 | Thauvin Olivier |
---|
72 | |
---|
73 | =head1 LICENSE |
---|
74 | |
---|
75 | This library is free software, you can redistribute it and/or modify |
---|
76 | it under the same terms as Perl itself. |
---|
77 | |
---|
78 | =cut |
---|
79 | |
---|
80 | 1; |
---|