Changeset 22


Ignore:
Timestamp:
03/09/09 03:59:15 (15 years ago)
Author:
nanardon
Message:
  • admin page
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Vote/Controller/Admin.pm

    r16 r22  
    3636        return; 
    3737    } 
     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    } 
    3853} 
    3954 
  • trunk/lib/Vote/Controller/Ballot.pm

    r21 r22  
    6060    my %choices; 
    6161    foreach ($vote->vote_choices($id)) { 
    62         $choices{$_->{key}} = $_->{label}; 
     62        $choices{$vote->choice_info($_)->{key}} = $vote->choice_info($_)->{label}; 
    6363    } 
    6464    $c->stash->{choices} = { %choices }; 
  • trunk/lib/Vote/Model/Vote.pm

    r21 r22  
    172172    my $sth = $self->db->prepare_cached( 
    173173        q{ 
    174         select * from choice where poll = ? 
     174        select key from choice where poll = ? 
    175175        order by label 
    176176        } 
     
    179179    my @ch; 
    180180    while (my $res = $sth->fetchrow_hashref) { 
    181         push(@ch, $res); 
     181        push(@ch, $res->{key}); 
    182182    } 
    183183    @ch 
     184} 
     185 
     186sub 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 
     197sub 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 
     212sub 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 
     221sub 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); 
    184229} 
    185230 
     
    448493} 
    449494 
     495sub 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 
     513sub 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 
    450534 
    451535=head1 AUTHOR 
  • trunk/root/templates/admin/default.tt

    r16 r22  
    11[% vote = c.model('Vote') %] 
    22 
     3<table border="1"> 
     4<tr><th>Vote</th><th>Possibilité de vote</th></tr> 
     5<tr> 
     6<td valign="TOP"> 
    37<form action="[% c.uri_for(voteid) %]"> 
    48 
     
    1115Debut du vote: 
    1216<input type="text" name="start" value="[% c.req.param('start') || thisvote.start | html %]"> 
     17<br> 
    1318Fin du vote: 
    1419<input type="text" name="end" value="[% c.req.param('end') || thisvote.end | html %]"> 
     
    2025<input type="text" name="free_choice" value="[% c.req.param('free_choice') || thisvote.free_choice | html %]"> 
    2126<br> 
    22  
    23  
    2427<input type="submit"> 
    2528</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) %]"> 
     40Ajouter 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) %]"> 
     60Login: <input type="text" name="id"><br> 
     61Mail: <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  
    2727<form action="[% c.uri_for(voteid) %]"> 
    2828[% 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> 
    3232[% END %] 
    3333 
  • trunk/root/templates/ballot/done.tt

    r20 r22  
    11Vote réussi. 
     2 
     3Les 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.