cvs: pearweb /sql election.sql /templates election-confirm.tpl.php election-confirmed.tpl.php election-dovote.tpl.php election-register.tpl.php
election-vote.tpl.php

From: Date: Sun, 05 Nov 2006 22:38:20 +0000
Subject: cvs: pearweb /sql election.sql /templates election-confirm.tpl.php election-confirmed.tpl.php election-dovote.tpl.php election-register.tpl.php
election-vote.tpl.php
Groups: php.pear.cvs php.pear.core 
Request: Send a blank email to pear-core+get-5154@lists.php.net to get a copy of this message
cellog Sun Nov 5 22:38:20 2006 UTC Added files: /pearweb/sql election.sql /pearweb/templates election-confirm.tpl.php election-confirmed.tpl.php election-dovote.tpl.php election-register.tpl.php election-vote.tpl.php Log: initial secret ballot general election support. so far, only voting is supported. Votes can be retrieved with a special password that is not stored. Election results are not yet calculated or supported. Results will be calculated by a cron job to avoid server strain. This code is experimental, and will neither work on the live server or have any real effect on it. To use, run "source election.sql" from within the mysql command- line or load it in phpmyadmin and add some elections and choices both vote-for-1-thing-only and vote-for-multiple-things elections are supported, as well as the option to "abstain" which can be used to express disapproval of all choices.

http://cvs.php.net/viewvc.cgi/pearweb/sql/election.sql?view=markup&rev=1.1 Index: pearweb/sql/election.sql +++ pearweb/sql/election.sql -- election voting sql -- COLUMN REFERENCES -- -- election_id elections(id) -- vote election_choices(choice) CREATE TABLE election_votes_single ( election_id INT NOT NULL, vote TINYINT NOT NULL, vote_hash CHAR(32) NOT NULL, PRIMARY KEY (election_id, vote_hash) ); CREATE TABLE election_votes_multiple ( election_id INT NOT NULL, vote TINYINT NOT NULL, vote_hash CHAR(32) NOT NULL, PRIMARY KEY (election_id, vote, vote_hash) ); CREATE TABLE election_votes_abstain ( election_id INT NOT NULL , vote_hash CHAR(32) NOT NULL , PRIMARY KEY (election_id, vote_hash) ); CREATE TABLE elections ( id INT NOT NULL AUTO_INCREMENT, purpose VARCHAR(100) NOT NULL, detail TEXT NOT NULL, votestart DATE NOT NULL, voteend DATE NOT NULL, creator VARCHAR(20) NOT NULL, createdate DATETIME NOT NULL, winner TINYINT, minimum_choices TINYINT DEFAULT '1' NOT NULL, maximum_choicse TINYINT DEFAULT '1' NOT NULL, PRIMARY KEY (id) ); CREATE TABLE election_choices ( election_id INT NOT NULL, choice TINYINT NOT NULL, summary VARCHAR(100) NOT NULL, summary_link VARCHAR(255) NOT NULL, PRIMARY KEY (election_id, choice) ); CREATE TABLE election_handle_votes ( election_id INT NOT NULL, handle VARCHAR(20) NOT NULL, PRIMARY KEY (election_id, handle) ); http://cvs.php.net/viewvc.cgi/pearweb/templates/election-confirm.tpl.php?view=markup&rev=1.1 Index: pearweb/templates/election-confirm.tpl.php +++ pearweb/templates/election-confirm.tpl.php <?php response_header('Vote :: ' . htmlspecialchars($info['purpose'])); ?> <h1>Vote in PEAR Election :: <?php echo htmlspecialchars($info['purpose']); ?></h1> <?php if (isset($error)): ?> <div class="errors"><?php echo $error; ?></div> <?php endif; // if (isset($error)): ?> <h2>Detail on the election</h2> <?php echo nl2br(htmlspecialchars($info['detail'])); ?> <h2>Your Vote:</h2> <form action="/election-info.php" method="post"> <input type="hidden" name="election" value="<?php echo $info['id']; ?>" /> <table> <tr> <td class="form-input"> <table> <?php foreach ($info['choices'] as $choice): ?> <tr> <?php if (in_array($choice['choice'], $info['vote'], true)): ?> <input type="hidden" name="vote[]" value="<?php echo $choice['choice']; ?>" /> <td><strong>X</strong></td> <?php else: // if (in_array($choice['choice'], $info['vote'], true)): ?> <td>&nbsp;</td> <?php endif; // if (in_array($choice['choice'], $info['vote'], true)): ?> <td> <?php echo htmlspecialchars($choice['summary']); ?> </td> </tr> <?php endforeach; // foreach ($info['choices'] as $choice): ?> </table> </td> </tr> </table> <?php if ($info['abstain']): ?> <p><strong>(ABSTAIN)</strong></p> <input type="hidden" name="abstain" value="1" /> <h1>are you SURE you wish to abstain?</h1> <?php endif; ?> <input type="submit" name="finalvote" value="<?php echo $info['abstain'] ? 'Abstain' : 'Confirm Vote'; ?>" /><input type="submit" value="cancel" /> </form> http://cvs.php.net/viewvc.cgi/pearweb/templates/election-confirmed.tpl.php?view=markup&rev=1.1 Index: pearweb/templates/election-confirmed.tpl.php +++ pearweb/templates/election-confirmed.tpl.php <?php response_header('Vote :: ' . htmlspecialchars($info['purpose'])); ?> <h1>Vote in PEAR Election :: <?php echo htmlspecialchars($info['purpose']); ?></h1> <?php if (isset($error)): ?> <div class="errors"><?php echo $error; ?></div> <?php endif; // if (isset($error)): ?> <h2>Detail on the election</h2> <?php echo nl2br(htmlspecialchars($info['detail'])); ?> <h2>Your Vote:</h2> <table> <tr> <td class="form-input"> <table> <?php foreach ($info['choices'] as $choice): ?> <tr> <?php if (in_array($choice['choice'], $info['vote'], true)): ?> <td><strong>X</strong></td> <?php else: // if (in_array($choice['choice'], $info['vote'], true)): ?> <td>&nbsp;</td> <?php endif; // if (in_array($choice['choice'], $info['vote'], true)): ?> <td> <?php echo htmlspecialchars($choice['summary']); ?> </td> </tr> <?php endforeach; // foreach ($info['choices'] as $choice): ?> </table> </td> </tr> </table> <?php if ($info['abstain']): ?> <p><strong>(ABSTAIN)</strong></p> <?php endif; // if ($info['abstain']): ?> <h2>IMPORTANT:</h2> <p> Your vote serial number for this election is <strong><?php echo $salt; ?></strong>. Please write this number down, as it is the only way to retrieve your vote from the database and will not be stored to maintain the secret ballot. If you lose this number, there is no way to connect you to your actual vote. </p> <p> The database does store a record of whether you have voted however, so you will not be allowed to vote again in this election. Thank you for voting! </p> <p> <a href="/election.php">Return to Elections</a> </p> http://cvs.php.net/viewvc.cgi/pearweb/templates/election-dovote.tpl.php?view=markup&rev=1.1 Index: pearweb/templates/election-dovote.tpl.php +++ pearweb/templates/election-dovote.tpl.php <?php response_header('Vote :: ' . htmlspecialchars($info['purpose'])); ?> <?php if ($info['maximum_choices'] > 1) { $inputtype = 'checkbox'; $inputname = 'vote[]'; if ($info['minimum_choices'] > 1) { if ($info['minimum_choices'] != $info['maximum_choices']) { $pleasechoose = 'from ' . $info['minimum_choices'] . ' to ' . $info['maximum_choices'] . ' choices'; } else { $pleasechoose = 'exactly ' . $info['maximum_choices'] . ' choices'; } } else { if ($info['minimum_choices'] != $info['maximum_choices']) { $pleasechoose = 'up to ' . $info['maximum_choices']; } else { $pleasechoose = 'exactly ' . $info['maximum_choices'] . ' choices'; } } } else { $inputtype = 'radio'; $inputname = 'vote'; $pleasechoose = 'one'; } ?> <h1>Vote in PEAR Election :: <?php echo htmlspecialchars($info['purpose']); ?></h1> <?php if (isset($error)): ?> <div class="errors"><?php echo $error; ?></div> <?php endif; // if (isset($error)): ?> <h2>Detail on the election</h2> <?php echo nl2br(htmlspecialchars($info['detail'])); ?> <h2>Please choose <?php echo $pleasechoose; ?>:</h2> <form action="/election-info.php" method="post"> <input type="hidden" name="confirm" value="1" /> <input type="hidden" name="election" value="<?php echo $info['id']; ?>" /> <table> <tr> <td> <?php foreach ($info['choices'] as $choice): ?> <input type="<?php echo $inputtype; ?>" name="<?php echo $inputname; ?>" value="<?php echo $choice['choice']; ?>" /> <?php echo htmlspecialchars($choice['summary']); ?> <a href="<?php echo $choice['summary_link']; ?>">(more info)</a><br /> <?php endforeach; // foreach ($info['choices'] as $choice): ?> </td> </tr> </table> <input type="submit" name="abstain" value="Abstain (pass)" /><input type="submit" name="votesubmit" value="Vote" /><input type="submit" value="cancel" name="cancel" /> </form> http://cvs.php.net/viewvc.cgi/pearweb/templates/election-register.tpl.php?view=markup&rev=1.1 Index: pearweb/templates/election-register.tpl.php +++ pearweb/templates/election-register.tpl.php <?php response_header('PEAR :: Register to Vote'); ?> <h1>Register to Vote</h1> <h2> If you already have a PEAR developer account, Please <a href="login.php?redirect=/election.php<?php if ($query) { echo urlencode($query); } ?>">Log in</a>, you are already registered to vote. </h2> <p> If you would like to vote in a general PEAR election, you need a user account. Registration for an account is done at <a href="/account-request-vote.php">The Account Request Form.</a> </p> http://cvs.php.net/viewvc.cgi/pearweb/templates/election-vote.tpl.php?view=markup&rev=1.1 Index: pearweb/templates/election-vote.tpl.php +++ pearweb/templates/election-vote.tpl.php <?php response_header('Vote'); ?> <h1>Vote in a PEAR Election</h1> <?php if (isset($error)): ?> <div class="errors"><?php echo $error; ?></div> <?php endif; // if (isset($error)): ?> Current date is <strong><?php echo date('Y-m-d'); ?></strong> <?php if (count($currentelections)): ?> <h2>Current Elections:</h2> <table> <tr> <th class="form-label_top">Active</th> <th class="form-label_top">Election Issue</th> <th class="form-label_top">Election dates</th> <th class="form-label_top">Have you voted?</th> </tr> <?php foreach ($currentelections as $election): $class = $election['active'] == 'yes' ? 'vote-active' : 'vote-inactive'; if ($election['voted'] == 'yes') { $class = 'vote-complete'; } ?> <tr> <td class="<?php echo $class; ?>"><?php echo $election['active']; ?></td> <?php if ($election['voted'] == 'yes'): ?> <td class="<?php echo $class; ?>"><?php echo htmlspecialchars($election['purpose']); ?></td> <?php else: // if ($election['voted'] == 'yes'): ?> <td class="<?php echo $class; ?>"><a href="/election-info.php?election=<?php echo $election['id']; ?>&vote=1"><?php echo htmlspecialchars($election['purpose']); ?></a></td> <?php endif; // if ($election['voted'] == 'yes'): ?> <td class="<?php echo $class; ?>"><?php echo $election['votestart'] . ' until ' . $election['voteend']; ?></td> <td class="<?php echo $class; ?>"><?php echo $election['voted']; ?></td> </tr> <?php endforeach; // foreach ($currentelections as $election): ?> </table> <?php endif; // if (count($currentelections)) if (count($allelections)): if ($retrieval && isset($info)): ?> <h3>Your vote information:</h3> <table> <tr> <td class="form-input"> <table> <?php foreach ($info['choices'] as $choice): ?> <tr> <?php if (in_array($choice['choice'], $info['vote'], true)): ?> <input type="hidden" name="vote[]" value="<?php echo $choice['choice']; ?>" /> <td><strong>X</strong></td> <?php else: // if (in_array($choice['choice'], $info['vote'], true)): ?> <td>&nbsp;</td> <?php endif; // if (in_array($choice['choice'], $info['vote'], true)): ?> <td> <?php echo htmlspecialchars($choice['summary']); ?> </td> </tr> <?php endforeach; // foreach ($info['choices'] as $choice): ?> </table> </td> </tr> </table> <?php if ($info['vote'] == array('(abstain)')) { echo '<p><strong>(ABSTAIN)</strong></p>'; }; endif; // if ($retrieval && isset($info)) ?> <h3>Retrieve your vote in an election:</h3> <form name="checkvote" action="/election.php" method="post"> <select name="election"> <?php foreach ($allelections as $election): ?> <option value="<?php echo $election['id']; ?>"><?php echo htmlspecialchars($election['purpose']); ?></option> <?php endforeach; // foreach ($allelections as $elections): ?> </select> <input type="text" size="17" name="salt" /> <input type="submit" value="Retrieve Vote" /> </form> <?php endif; // if (count($allelections)) require dirname(__FILE__) . '/election-results.tpl.php';
« previous php.pear.core (#5154) next »