Changeset 206
- Timestamp:
- 04/16/09 00:16:56 (15 years ago)
- Location:
- trunk
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Vote/Controller/Admin.pm
r205 r206 37 37 my $id = $c->stash->{voteid}; 38 38 39 my $vote = $c->model('Vote');40 39 my $poll = $c->model('Vote')->poll($id); 41 40 for ($poll->status || '') { 42 41 /^BEFORE$/ and do { 43 42 if ($c->req->param('addch')) { 44 $ vote->vote_add_choice($id,$c->req->param('addch'))45 and $ vote->commit;43 $poll->add_choice($c->req->param('addch')) 44 and $poll->commit; 46 45 } elsif ($c->req->param('delch')) { 47 $ vote->delete_choice($c->req->param('delch'))48 and $ vote->commit;46 $poll->delete_choice($c->req->param('delch')) 47 and $poll->commit; 49 48 } elsif ($c->req->param('pollparam')) { 50 49 if ($c->req->param('dstart')) { … … 59 58 } 60 59 if ($c->req->param('end') && $c->req->param('start')) { 61 if ($ vote->check_date_max($c->req->param('start'))) {62 if (! $ vote->check_date_max($c->req->param('end'), $c->req->param('start'))) {60 if ($poll->check_date_max($c->req->param('start'))) { 61 if (! $poll->check_date_max($c->req->param('end'), $c->req->param('start'))) { 63 62 $c->stash->{dateerror} = "Le vote se termine avant de commencer"; 64 63 next; … … 76 75 grep { exists($c->req->params->{$_}) } 77 76 qw(label description start end choice_count free_choice) 78 ) and $ vote->commit;77 ) and $poll->commit; 79 78 } elsif ($c->req->param('encrypted')) { 80 79 my $passphrase = $c->req->param('passphrase') || 81 80 $c->session->{'vpass' . $c->stash->{voteid}}; 82 81 $poll->gen_poll_keys($passphrase) 83 and $ vote->commit;82 and $poll->commit; 84 83 } elsif ($c->req->param('notcrypted')) { 85 84 $poll->param(public_key => undef, private_key => undef) 86 and $ vote->commit;85 and $poll->commit; 87 86 } 88 87 }; … … 90 89 /^(BEFORE|RUNNING)$/ and do { 91 90 if (my ($upload) = $c->req->upload('votinglist')) { 92 $vote->voting_from_file( 93 $id, 91 $poll->voting_from_file( 94 92 $upload->fh, 95 93 $c->req->param('delete'), 96 ) and $ vote->commit;94 ) and $poll->commit; 97 95 } elsif($c->req->param('delvoting')) { 98 $ vote->delete_voting($c->req->param('delvoting'))99 and $ vote->commit;96 $poll->delete_voting($c->req->param('delvoting')) 97 and $poll->commit; 100 98 } elsif ($c->req->param('mail')) { 101 $ vote->addupd_voting($id,$c->req->param('mail'), $c->req->param('id'))102 and $ vote->commit;99 $poll->addupd_voting($c->req->param('mail'), $c->req->param('id')) 100 and $poll->commit; 103 101 } elsif($c->req->param('mailpasswd')) { 104 102 # TODO … … 125 123 /^AFTER$/ and do { 126 124 if ($c->req->param('mapfrom') && $c->req->param('mapto')) { 127 $ vote->vote_map_value(125 $poll->map_value( 128 126 $id, 129 127 $c->req->param('mapfrom'), … … 131 129 ); 132 130 } 133 foreach my $bid ($ vote->list_vote_ballot_needvalid($id)) {131 foreach my $bid ($poll->list_ballot_needvalid) { 134 132 if (!$c->req->param($bid)) { 135 133 next; 136 134 } elsif($c->req->param($bid) eq 'invalid') { 137 $ vote->mark_ballot_invalid($bid,1);138 $ vote->commit;135 $poll->ballot($bid)->mark_invalid(1); 136 $poll->commit; 139 137 } elsif($c->req->param($bid) eq 'valid') { 140 $ vote->mark_ballot_invalid($bid,0);141 $ vote->commit;138 $poll->ballot($bid)->mark_invalid(0); 139 $poll->commit; 142 140 } 143 141 } … … 160 158 sub auth : Private { 161 159 my ($self, $c) = @_; 162 my $ vote = $c->model('Vote');160 my $poll = $c->model('Vote')->poll($c->stash->{voteid}); 163 161 my $password = $c->session->{'vpass' . $c->stash->{voteid}} || 164 162 $c->req->param('vpass' . $c->stash->{voteid}); 165 163 166 if (!$c->model('Vote')->auth_poll($c->stash->{voteid}, $password)) { 167 $c->stash->{page}{title} = $vote->vote_info( 168 $c->stash->{voteid} 169 )->{label} . ': Login d\'administration'; 164 if (!$poll->auth_poll($password)) { 165 $c->stash->{page}{title} = $poll->info('label') . 166 ': Login d\'administration'; 170 167 $c->session->{'vpass' . $c->stash->{voteid}} = undef; 171 168 $c->stash->{template} = 'admin/login.tt'; … … 179 176 my ( $self, $c, undef, $id ) = @_; 180 177 $c->stash->{voteid} = $id; 181 my $ vote = $c->model('Vote');182 183 $ vote->vote_info($id)or do {178 my $poll = $c->model('Vote')->poll($id); 179 180 $poll->info or do { 184 181 $c->res->redirect($c->uri_for('/')); 185 182 return; … … 188 185 $c->forward('auth') or return; 189 186 $c->forward('modify_poll'); 190 $c->stash->{page}{title} = $ c->model('Vote')->vote_info($id)->{label}. ': Administration';187 $c->stash->{page}{title} = $poll->info('label') . ': Administration'; 191 188 } 192 189 … … 194 191 my ($self, $c) = @_; 195 192 ($c->stash->{voteid}) = @{ $c->req->snippets || [] }; 196 my $ vote = $c->model('Vote');197 198 $ vote->vote_info($c->stash->{voteid})or do {193 my $poll = $c->model('Vote')->poll($c->stash->{voteid}); 194 195 $poll->info or do { 199 196 $c->res->redirect($c->uri_for('/')); 200 197 return; … … 203 200 $c->forward('auth') or return; 204 201 $c->forward('modify_poll'); 205 $c->stash->{page}{title} = $c->model('Vote')->vote_info( 206 $c->stash->{voteid} 207 )->{label} . ': Administration, liste des electeurs'; 202 $c->stash->{page}{title} = $poll->info('label') . ': Administration, liste des electeurs'; 208 203 } 209 204 … … 211 206 my ($self, $c) = @_; 212 207 ($c->stash->{voteid}) = @{ $c->req->snippets || [] }; 213 my $ vote = $c->model('Vote');214 215 $ vote->vote_info($c->stash->{voteid})or do {208 my $poll = $c->model('Vote')->poll($c->stash->{voteid}); 209 210 $poll->info or do { 216 211 $c->res->redirect($c->uri_for('/')); 217 212 return; … … 220 215 $c->forward('auth') or return; 221 216 $c->forward('modify_poll'); 222 $c->stash->{page}{title} = $c->model('Vote')->vote_info( 223 $c->stash->{voteid} 224 )->{label} . ': Administration, bulletin'; 217 $c->stash->{page}{title} = $poll->info('label') . ': Administration, bulletin'; 225 218 } 226 219 227 220 sub privatekey : LocalRegex('^(\d+)/privatekey$') { 228 my ($self, $c , $id, @sub) = @_;221 my ($self, $c) = @_; 229 222 ($c->stash->{voteid}) = @{ $c->req->snippets || [] }; 230 my $ vote = $c->model('Vote');231 232 $ vote->vote_info($id)or do {233 $c->res->redirect($c->uri_for('/')); 234 return; 235 }; 236 $c->response->body($ vote->vote_info($c->stash->{voteid})->{private_key}|| '');223 my $poll = $c->model('Vote')->poll($c->stash->{voteid}); 224 225 $poll->info or do { 226 $c->res->redirect($c->uri_for('/')); 227 return; 228 }; 229 $c->response->body($poll->info('private_key') || ''); 237 230 } 238 231 -
trunk/lib/Vote/Controller/Ballot.pm
r205 r206 37 37 38 38 $c->stash->{voteid} = $id; 39 my $poll = $c->model('Vote')->poll($id); 39 40 40 if ($ c->model('Vote')->poll($id)->status ne 'RUNNING') {41 if ($poll->status ne 'RUNNING') { 41 42 $c->stash->{template} = 'ballot/closed.tt'; 42 43 return; … … 47 48 48 49 if (!$c->model('Vote')->auth_voting($id, $mail, $password)) { 49 $c->stash->{page}{title} = $ c->model('Vote')->vote_info($id)->{label}. ': Login';50 $c->stash->{page}{title} = $poll->info('label') . ': Login'; 50 51 $c->delete_session('invalid user/pass'); 51 52 $c->stash->{template} = 'ballot/login.tt'; … … 59 60 $c->session->{password} = $password; 60 61 61 $c->stash->{page}{title} = $ c->model('Vote')->vote_info($id)->{label}. ': Bulletin';62 $c->stash->{page}{title} = $poll->info('label') . ': Bulletin'; 62 63 63 64 # login succeed, but those this user has already voted 64 if (my $date = $ c->model('Vote')->voting_has_sign($id,$mail)) {65 if (my $date = $poll->voting_has_sign($mail)) { 65 66 $c->stash->{mail} = $c->session->{mail}; 66 67 $c->stash->{template} = 'ballot/signed.tt'; … … 88 89 89 90 if (scalar(@sbalval) + scalar(@{$c->stash->{fsbal} || []}) 90 > $ vote->vote_info($id)->{choice_count}) {91 > $poll->info('choice_count')) { 91 92 $c->req->parameters->{'ballot'} = ''; 92 93 $c->stash->{vote_error} = 'Seulement ' . 93 $ vote->vote_info($id)->{choice_count}. ' choix possible';94 $poll->info('choice_count') . ' choix possible'; 94 95 return; 95 96 } … … 122 123 From => $mail, 123 124 To => $mail, 124 Subject => 'Confirmation de vote: ' . $ vote->vote_info($id)->{label},125 Subject => 'Confirmation de vote: ' . $poll->info('label'), 125 126 mail => { 126 127 ballotid => $c->stash->{ballotid}, -
trunk/lib/Vote/Controller/Vote.pm
r198 r206 38 38 39 39 $c->stash->{voteid} = $id; 40 $c->stash->{page}{title} = 'Vote: ' . $c->model('Vote')-> vote_info($id)->{label};40 $c->stash->{page}{title} = 'Vote: ' . $c->model('Vote')->poll($id).info('label'); 41 41 } 42 42 … … 47 47 $c->stash->{template} = 'default.tt'; 48 48 49 $vote-> vote_info($c->stash->{voteid})or do {49 $vote->poll($c->stash->{voteid})->info or do { 50 50 $c->res->redirect($c->uri_for('/')); 51 51 return; -
trunk/lib/Vote/DB.pm
r205 r206 100 100 } 101 101 102 # TODO 102 103 sub ballot { 103 104 my ($self, $ballotid) = @_; 105 die "# ballot" . join(' ',caller()); 104 106 # TODO must die, ballot are attached to a poll 105 107 Vote::DB::Ballot->new($self->{dbstring}, $ballotid); … … 120 122 } 121 123 124 # TODO 122 125 sub vote_info { 123 126 my ($self, $id) = @_; 127 die "# vote_info" . join(' ',caller()); 124 128 $self->poll($id)->info; 125 129 } -
trunk/lib/Vote/DB/Poll.pm
r205 r206 143 143 my $res = $sth->fetchrow_hashref; 144 144 $sth->finish; 145 return defined($res->{ $var})146 ? $res->{ $var}145 return defined($res->{val}) 146 ? $res->{val} 147 147 : $default->{$var}; 148 148 } -
trunk/root/templates/admin/includes/poll_settings.tt
r205 r206 8 8 <form action="[% c.uri_for(voteid) %]" method="POST"> 9 9 10 [% thisvote = vote.vote_info(voteid) %] 11 12 Label: <input type="text" name="label" value="[% c.req.param('label') || thisvote.label | html %]"> 10 Label: <input type="text" name="label" value="[% c.req.param('label') || poll.info('label') | html %]"> 13 11 <br> 14 12 Description:<br> 15 <textarea name="description" cols="60" rows="4">[% c.req.param('description') || thisvote.description| html %]</textarea>13 <textarea name="description" cols="60" rows="4">[% c.req.param('description') || poll.info('description') | html %]</textarea> 16 14 <br> 17 15 <hr> … … 25 23 26 24 Debut du vote:<br> 27 Date: <input type="text" name="dstart" value="[% c.req.param('dstart') || thisvote.dstart| html %]">25 Date: <input type="text" name="dstart" value="[% c.req.param('dstart') || poll.info('dstart') | html %]"> 28 26 <A HREF="#" onClick="cal13.select(document.forms[0].dstart,'anchor13','dd/MM/yyyy'); return false;" TITLE="cal13.select(document.forms[0].dstart,'anchor13','dd/MM/yyyy'); return false;" NAME="anchor13" ID="anchor13">select</A> 29 Heure: <input type="text" size=9 name="hstart" value="[% c.req.param('hstart') || thisvote.hstart| html %]">27 Heure: <input type="text" size=9 name="hstart" value="[% c.req.param('hstart') || poll.info('hstart') | html %]"> 30 28 <br> 31 29 Fin du vote:<br> 32 Date: <input type="text" name="dend" value="[% c.req.param('dend') || thisvote.dend| html %]">30 Date: <input type="text" name="dend" value="[% c.req.param('dend') || poll.info('dend') | html %]"> 33 31 <A HREF="#" onClick="cal13.select(document.forms[0].dend,'anchor14','dd/MM/yyyy',(document.forms[0].dend.value=='')?document.forms[0].dstart.value:null); return false;" TITLE="cal13.select(document.forms[0].dend,'anchor14','dd/MM/yyyy',(document.forms[0].dend.value=='')?document.forms[0].dstart.value:null); return false;" NAME="anchor14" ID="anchor14">select</A> 34 Heure: <input type="text" size=9 name="hend" value="[% c.req.param('hend') || thisvote.hend| html %]">32 Heure: <input type="text" size=9 name="hend" value="[% c.req.param('hend') || poll.info('hend') | html %]"> 35 33 <br> 36 34 <hr> -
trunk/root/templates/admin/index.tt
r47 r206 1 1 [% vote = c.model('Vote') %] 2 [% poll = c.model('Vote').poll('voteid') %] 2 3 3 [% FOREACH voteid = vote.list_comming_vote %]4 <a href="[% c.uri_for('/admin', voteid) %]">[% vote.vote_info(voteid).label| html %]</a>4 [% FOREACH voteid = c.model('Vote').list_comming_vote %] 5 <a href="[% c.uri_for('/admin', voteid) %]">[% c.model('Vote').poll('voteid').info('label') | html %]</a> 5 6 <br> 6 7 [% END %] -
trunk/root/templates/admin/login.tt
r186 r206 1 1 <!-- $Id$ --> 2 2 [% vote = c.model('Vote') %] 3 [% poll = c.model('Vote').poll(voteid) %] 3 4 4 5 <div id="admin_login" class="login_box"> 5 6 <form action="[% c.uri_for('/admin', voteid) %]" method="POST"> 6 <p>Accès à l'interface d'administration du vote <b><i>[% vote.vote_info(voteid).label| html %]</i></b></p>7 <p>Accès à l'interface d'administration du vote <b><i>[% poll.info('label') | html %]</i></b></p> 7 8 <p>Veuillez saisir le mot de passe : <input type="password" name="[% 'vpass' _ voteid %]"> 8 9 <input type="submit"></p> -
trunk/root/templates/ballot/default.tt
r192 r206 1 1 [% vote = c.model('Vote') %] 2 3 [% thisvote = vote.vote_info(voteid) %] 2 [% poll = c.model('Vote').poll(voteid) %] 4 3 5 4 <div id="ballot" class="ballot"> 6 5 <form action="[% c.uri_for(voteid) %]" method="POST"> 7 <p><b>Vote: [% thisvote.label| html %]</b></p>6 <p><b>Vote: [% poll.info('label') | html %]</b></p> 8 7 [% IF c.req.param('ballot') %] 9 8 <p>Confirmez votre vote:</p> 10 9 [% ELSE %] 11 10 [% IF vote_error %]<p class="alert">Erreur: [% vote_error %]</p>[% END %] 12 <p>[% thisvote.description| html | html_line_break %]</p>13 <p>[% thisvote.choice_count%] choix possibles:</p>11 <p>[% poll.info('description') | html | html_line_break %]</p> 12 <p>[% poll.info('choice_count') %] choix possibles:</p> 14 13 [% END %] 15 14 <hr> -
trunk/root/templates/ballot/index.tt
r47 r206 1 1 [% vote = c.model('Vote') %] 2 [% poll = c.model('Vote').poll(voteid) %] 2 3 3 4 [% voteids = vote.list_running_vote %] … … 6 7 7 8 [% FOREACH voteid = voteids %] 8 <a href="[% c.uri_for('/ballot', voteid) %]">[% vote.vote_info(voteid).label| html %]</a>9 <a href="[% c.uri_for('/ballot', voteid) %]">[% poll.info('label') | html %]</a> 9 10 <br> 10 11 [% END %] -
trunk/root/templates/default.tt
r167 r206 10 10 [% END %] 11 11 <tr> 12 <td><lu><li><a href="[% c.uri_for( '/vote', id ) %]">[% vote.vote_info(id).label| html %]</a></lu></td></td>12 <td><lu><li><a href="[% c.uri_for( '/vote', id ) %]">[% c.model('Vote').poll(id).info('label') | html %]</a></lu></td></td> 13 13 <td>><a href="[% c.uri_for( '/ballot', id ) %]"> Voter</a></td> 14 14 </tr> … … 28 28 [% END %] 29 29 <tr> 30 <td><lu><li><a href="[% c.uri_for( 'vote', id ) %]">[% vote.vote_info(id).label| html %]</a></li></lu></td>30 <td><lu><li><a href="[% c.uri_for( 'vote', id ) %]">[% c.model('Vote').poll(id).info('label') | html %]</a></li></lu></td> 31 31 <td>><a href="[% c.uri_for( '/admin', id ) %]"> Administrer</a></td> 32 32 </tr> … … 47 47 [% END %] 48 48 <tr> 49 <td><lu><li><a href="[% c.uri_for( 'vote', id ) %]">[% vote.vote_info(id).label| html %]</a></lu></td></td>49 <td><lu><li><a href="[% c.uri_for( 'vote', id ) %]">[% c.model('Vote').poll(id).info('label') | html %]</a></lu></td></td> 50 50 </tr> 51 51 [% IF loop.last %] -
trunk/root/templates/includes/header.tt
r109 r206 19 19 [% IF voteid %] 20 20 :: <a href="[% c.uri_for('/vote', voteid) %]"> 21 Votre vote: [% c.model('Vote'). vote_info(voteid).label| truncate(40) | html %]21 Votre vote: [% c.model('Vote').poll(voteid).info('label') | truncate(40) | html %] 22 22 </a> 23 23 [% END %] -
trunk/root/templates/includes/poll.tt
r126 r206 1 1 [% vote = c.model('Vote') %] 2 [% thisvote = vote.vote_info(voteid) %]2 [% poll = c.model('Vote').poll(voteid) %] 3 3 4 4 <div id="poll_summary" class="box" style="clear: both;"> 5 5 <div style="float: left; width: 70%;"> 6 <p id="poll_label">[% thisvote.label| html %]</p>7 <p>[% thisvote.description| html | html_line_break %]</p>8 [% IF thisvote.dstart && thisvote.dend%]9 <p>Scrutin ouvert du <b>[% thisvote.dstart _ ' ' _ thisvote.hstart| html %]</b> au10 <b>[% thisvote.dend _ ' ' _ thisvote.hend| html %]</b></p>6 <p id="poll_label">[% poll.info('label') | html %]</p> 7 <p>[% poll.info('description') | html | html_line_break %]</p> 8 [% IF poll.info('dstart') && poll.info('dend') %] 9 <p>Scrutin ouvert du <b>[% poll.info('dstart') _ ' ' _ poll.info('hstart') | html %]</b> au 10 <b>[% poll.info('dend') _ ' ' _ poll.info('hend') | html %]</b></p> 11 11 [% END %] 12 Ont voté: [% vote.vote_signing_count(voteid) %] / [% vote.vote_voting_count(voteid)%]<br>13 Bulletins: [% vote.vote_ballot_count(voteid)%]14 [% IF vote.vote_signing_count(voteid) != vote.vote_ballot_count(voteid)%]12 Ont voté: [% poll.signing_count %] / [% poll.voting_count %]<br> 13 Bulletins: [% poll.ballot_count %] 14 [% IF poll.signing_count != poll.ballot_count %] 15 15 <p class="alert">Le nombre de bulletins et le nombre de personnes ayant voté divergent, 16 16 suspicion de tricherie</p> 17 17 [% END %] 18 18 </div> 19 [% FOREACH item = vote.vote_choices(voteid)%]19 [% FOREACH item = poll.choices %] 20 20 [% IF loop.first %] 21 21 <div style="float: right; width: 20%; top: 0px;" class="box"> … … 23 23 <ol style="padding-left:15px; margin:5px;"> 24 24 [% END %] 25 <li>[% vote.choice_info(item).label | html %]</li>25 <li>[% poll.choice(item).info.label | html %]</li> 26 26 [% IF loop.last %] 27 27 </ol> -
trunk/root/templates/includes/poll_results.tt
r193 r206 14 14 <p>Resultats:</p> 15 15 [% END %] 16 <p>Nombre de choix à retenir: [% vote.vote_info(voteid).choice_count%]</p>16 <p>Nombre de choix à retenir: [% poll.info('choice_count') %]</p> 17 17 <p>Participations: [% vote.vote_signing_count(voteid) %] / [% vote.vote_voting_count(voteid) %] 18 18 [% IF vote.vote_voting_count(voteid) %] … … 42 42 [% # If equality, we keep same color, even we are over resullts %] 43 43 [% mycount = loop.count %] 44 [% IF loop.count <= vote.vote_info(voteid).choice_count%]44 [% IF loop.count <= poll.info('choice_count') %] 45 45 [% IF res.count >= vote.absolute_majority %] 46 46 [% class = 'majabs' %] … … 78 78 <tr><th>numéro</th><th>Id</th> 79 79 <th>contenu (=> corrigé en) 80 [% IF vote.vote_info(voteid).free_choice%]80 [% IF poll.info('free_choice') %] 81 81 <br>(*: hors liste) 82 82 [% END %]
Note: See TracChangeset
for help on using the changeset viewer.