package Vote::Controller::Admin; use strict; use warnings; use base 'Catalyst::Controller'; =head1 NAME Vote::Controller::Admin - Catalyst Controller =head1 DESCRIPTION Catalyst Controller. =head1 METHODS =cut =head2 index =cut sub begin : Private { my ( $self, $c, @args ) = @_; $c->model('Vote')->db->rollback; warn join('-', @args); } sub index : Private { my ( $self, $c ) = @_; $c->res->redirect($c->uri_for('/')); } sub modify_poll : Private { my ( $self, $c) = @_; my $id = $c->stash->{voteid}; my $vote = $c->model('Vote'); for ($vote->vote_status($id) || '') { /^BEFORE$/ and do { if ($c->req->param('addch')) { $vote->vote_add_choice($id, $c->req->param('addch')) and $vote->db->commit; } elsif ($c->req->param('delch')) { $vote->delete_choice($c->req->param('delch')) and $vote->db->commit; } elsif ($c->req->param('pollparam')) { if ($c->req->param('dstart')) { $c->req->param('start', $c->req->param('dstart') . ' ' . ($c->req->param('hstart') || '') ); } if ($c->req->param('dend')) { $c->req->param('end', $c->req->param('dend') . ' ' . ($c->req->param('hend') || '') ); } $vote->vote_param( $id, map { $_ => ($c->req->param($_) || undef) } grep { exists($c->req->params->{$_}) } qw(label description start end choice_count free_choice) ) and $vote->db->commit; } }; /^(BEFORE|RUNNING)$/ and do { if (my ($upload) = $c->req->upload('votinglist')) { $vote->voting_from_file( $id, $upload->fh, $c->req->param('delete'), ) and $vote->db->commit; } elsif($c->req->param('delvoting')) { $vote->delete_voting($c->req->param('delvoting')) and $vote->db->commit; } elsif ($c->req->param('mail')) { $vote->addupd_voting($id, $c->req->param('mail'), $c->req->param('id')) and $vote->db->commit; } elsif($c->req->param('mailpasswd')) { $vote->mail_passwd_ifnul($id, { voteurl => $c->uri_for('/ballot', $id), }); } }; /^AFTER$/ and do { if ($c->req->param('mapfrom') && $c->req->param('mapto')) { $vote->vote_map_value( $id, $c->req->param('mapfrom'), $c->req->param('mapto'), ); } foreach my $bid ($vote->list_vote_ballot_needvalid($id)) { if (!$c->req->param($bid)) { next; } elsif($c->req->param($bid) eq 'invalid') { $vote->mark_ballot_invalid($bid, 1); $vote->db->commit; } elsif($c->req->param($bid) eq 'valid') { $vote->mark_ballot_invalid($bid, 0); $vote->db->commit; } } }; } } sub auth : Private { my ($self, $c) = @_; my $vote = $c->model('Vote'); my $password = $c->session->{vpassword} || $c->req->param('vpassword'); if (!$c->model('Vote')->auth_poll($c->stash->{voteid}, $password)) { $c->stash->{page}{title} = $vote->vote_info( $c->stash->{voteid} )->{label} . ': Login d\'administration'; $c->session->{vpassword} = undef; $c->stash->{template} = 'admin/login.tt'; return; } $c->session->{vpassword} = $password; return 1; } sub default : Private { my ( $self, $c, undef, $id ) = @_; $c->stash->{voteid} = $id; my $vote = $c->model('Vote'); $vote->vote_info($id) or do { $c->res->redirect($c->uri_for('/')); return; }; $c->forward('auth') or return; $c->forward('modify_poll'); $c->stash->{page}{title} = $c->model('Vote')->vote_info($id)->{label} . ': Administration'; } sub voting: LocalRegex('^(\d+)/voting$') { my ($self, $c, $id, @sub) = @_; ($c->stash->{voteid}) = @{ $c->req->snippets || [] }; my $vote = $c->model('Vote'); $vote->vote_info($id) or do { $c->res->redirect($c->uri_for('/')); return; }; $c->forward('auth') or return; $c->forward('modify_poll'); $c->stash->{page}{title} = $c->model('Vote')->vote_info( $c->stash->{voteid} )->{label} . ': Administration, liste des electeurs'; } sub ballot: LocalRegex('^(\d+)/ballot$') { my ($self, $c, $id, @sub) = @_; ($c->stash->{voteid}) = @{ $c->req->snippets || [] }; my $vote = $c->model('Vote'); $vote->vote_info($id) or do { $c->res->redirect($c->uri_for('/')); return; }; $c->forward('auth') or return; $c->forward('modify_poll'); $c->stash->{page}{title} = $c->model('Vote')->vote_info( $c->stash->{voteid} )->{label} . ': Administration, bulletin'; } =head1 AUTHOR Thauvin Olivier =head1 LICENSE This library is free software, you can redistribute it and/or modify it under the same terms as Perl itself or CeCILL. =cut 1;