Changeset 22
- Timestamp:
- 03/09/09 03:59:15 (15 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Vote/Controller/Admin.pm
r16 r22 36 36 return; 37 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 } 38 53 } 39 54 -
trunk/lib/Vote/Controller/Ballot.pm
r21 r22 60 60 my %choices; 61 61 foreach ($vote->vote_choices($id)) { 62 $choices{$ _->{key}} = $_->{label};62 $choices{$vote->choice_info($_)->{key}} = $vote->choice_info($_)->{label}; 63 63 } 64 64 $c->stash->{choices} = { %choices }; -
trunk/lib/Vote/Model/Vote.pm
r21 r22 172 172 my $sth = $self->db->prepare_cached( 173 173 q{ 174 select *from choice where poll = ?174 select key from choice where poll = ? 175 175 order by label 176 176 } … … 179 179 my @ch; 180 180 while (my $res = $sth->fetchrow_hashref) { 181 push(@ch, $res );181 push(@ch, $res->{key}); 182 182 } 183 183 @ch 184 } 185 186 sub choice_info { 187 my ($self, $chid) = @_; 188 my $sth = $self->db->prepare_cached( 189 q{select * from choice where key = ?} 190 ); 191 $sth->execute($chid); 192 my $res = $sth->fetchrow_hashref; 193 $sth->finish; 194 $res 195 } 196 197 sub vote_add_choice { 198 my ($self, $voteid, $label) = @_; 199 200 my $sth = $self->db->prepare_cached( 201 q{insert into choice (poll, label) values (?,?)} 202 ); 203 204 $sth->execute($voteid, $label) or do { 205 $self->db->rollback; 206 return; 207 }; 208 209 1 210 } 211 212 sub modify_choice { 213 my ($self, $chid, $label) = @_; 214 215 my $sth = $self->db->prepare_cached( 216 q{update choice set label = ? where key = ?} 217 ); 218 $sth->execute($label, $chid); 219 } 220 221 sub delete_choice { 222 my ($self, $chid) = @_; 223 224 my $sth = $self->db->prepare_cached( 225 q{delete from choice where key = ?} 226 ); 227 228 $sth->execute($chid); 184 229 } 185 230 … … 448 493 } 449 494 495 sub addupd_voting { 496 my ($self, $voteid, $id, $mail) = @_; 497 498 my $upd = $self->db->prepare_cached( 499 q{ 500 update voting set mail = ? where poll = ? and id = ? 501 } 502 ); 503 504 if ($upd->execute($mail, $voteid, $id) == 0) { 505 my $add = $self->db->prepare_cached(q{ 506 insert into voting (poll, id, mail) values (?,?,?) 507 }); 508 509 $add->execute($voteid, $id, $mail); 510 } 511 } 512 513 sub voting_from_file { 514 my ($self, $voteid, $fh, $delete) = @_; 515 516 if ($delete) { 517 my $sth = $self->db->prepare(q{delete from voting where poll = ?}); 518 $sth->execute($voteid); 519 } 520 521 while (my $line = <$fh>) { 522 chomp($line); 523 warn $line; 524 my ($id, $mail) = split(';', $line); 525 $id && $mail or do { 526 $self->db->rollback; 527 return; 528 }; 529 $self->addupd_voting($voteid, $id, $mail); 530 } 531 1; 532 } 533 450 534 451 535 =head1 AUTHOR -
trunk/root/templates/admin/default.tt
r16 r22 1 1 [% vote = c.model('Vote') %] 2 2 3 <table border="1"> 4 <tr><th>Vote</th><th>Possibilité de vote</th></tr> 5 <tr> 6 <td valign="TOP"> 3 7 <form action="[% c.uri_for(voteid) %]"> 4 8 … … 11 15 Debut du vote: 12 16 <input type="text" name="start" value="[% c.req.param('start') || thisvote.start | html %]"> 17 <br> 13 18 Fin du vote: 14 19 <input type="text" name="end" value="[% c.req.param('end') || thisvote.end | html %]"> … … 20 25 <input type="text" name="free_choice" value="[% c.req.param('free_choice') || thisvote.free_choice | html %]"> 21 26 <br> 22 23 24 27 <input type="submit"> 25 28 </form> 29 </td> 30 <td valign="TOP"> 31 [% FOREACH choice = vote.vote_choices(voteid) %] 32 <form action="[% c.uri_for(voteid) %]"> 33 [% loop.count %] - [% vote.choice_info(choice).label | html %] 34 <input type="hidden" name="delch" value="[% vote.choice_info(choice).key %]"> 35 <input type="submit" name="del" value="Effacer"> 36 </form> 37 <br> 38 [% END %] 39 <form action="[% c.uri_for(voteid) %]"> 40 Ajouter un choix:<br> 41 <input type="text" name="addch"> 42 <input type="submit"> 43 </form> 44 </td> 45 </tr> 46 </table> 47 48 <hr> 49 50 <table border="1"> 51 <tr> 52 <td valign="TOP"> 53 [% signing = [ vote.vote_signing(voteid) ] %] 54 [% FOREACH voting = signing %] 55 [% voting.id | html %] [% voting.mail | html %]<br> 56 [% END %] 57 </td> 58 <td valign="TOP"> 59 <form action="[% c.uri_for(voteid) %]"> 60 Login: <input type="text" name="id"><br> 61 Mail: <input type="text" name="mail"><br> 62 <input type="submit"> 63 </form> 64 <hr> 65 <form method="POST" ENCTYPE="multipart/form-data" action="[% c.uri_for(voteid) %]"> 66 <input type="file" name="votinglist"><br> 67 <input type="checkbox" name="delete">Effacer la liste des votants<br> 68 <input type="submit"> 69 </form> 70 </td> 71 </tr> 72 </table> 73 </t -
trunk/root/templates/ballot/default.tt
r17 r22 27 27 <form action="[% c.uri_for(voteid) %]"> 28 28 [% FOREACH choice = vote.vote_choices(voteid) %] 29 [% key = choice.key %]30 <input type="checkbox" name="sbal" value="[% choice.key %]"[% " checked" IF sbal.$key %]>31 [% choice.label | html %]<br>29 [% key = vote.choice_info(choice).key %] 30 <input type="checkbox" name="sbal" value="[% key %]"[% " checked" IF sbal.$key %]> 31 [% vote.choice_info(choice).label | html %]<br> 32 32 [% END %] 33 33 -
trunk/root/templates/ballot/done.tt
r20 r22 1 1 Vote réussi. 2 3 Les résultats seront disponibles ici: 4 <a href="[% c.uri_for('/vote', voteid) %]">Ici</a>.
Note: See TracChangeset
for help on using the changeset viewer.