cvs: pearweb /include pear-election.php pear-voter.php /public_html election-info.php election-new.php /templates election-confirm.tpl.php
election-confirmed.tpl.php election-dovote.tpl.php election-new-step1.tpl.php election-new-step2.tpl.php election-new-step3.tpl.php
election-showresults.tpl.php
| From: | Greg Beaver | Date: | Tue, 07 Nov 2006 05:47:06 +0000 |
| Subject: | cvs: pearweb /include pear-election.php pear-voter.php /public_html election-info.php election-new.php /templates election-confirm.tpl.php election-confirmed.tpl.php election-dovote.tpl.php election-new-step1.tpl.php election-new-step2.tpl.php election-new-step3.tpl.php election-showresults.tpl.php |
||
| Groups: | php.pear.cvs php.pear.core | ||
| Request: | Send a blank email to pear-core+get-5158@lists.php.net to get a copy of this message | ||
cellog Tue Nov 7 05:47:06 2006 UTC
Added files:
/pearweb/include pear-election.php
/pearweb/public_html election-new.php
/pearweb/templates election-new-step1.tpl.php
election-new-step2.tpl.php
election-new-step3.tpl.php
Modified files:
/pearweb/include pear-voter.php
/pearweb/public_html election-info.php
/pearweb/templates election-confirm.tpl.php
election-confirmed.tpl.php
election-dovote.tpl.php
election-showresults.tpl.php
Log:
fix voting - in non-active election, it tried to vote
add facility to create new elections
http://cvs.php.net/viewvc.cgi/pearweb/include/pear-voter.php?r1=1.2&r2=1.3&diff_format=u Index: pearweb/include/pear-voter.php diff -u pearweb/include/pear-voter.php:1.2 pearweb/include/pear-voter.php:1.3 --- pearweb/include/pear-voter.php:1.2 Mon Nov 6 21:34:51 2006 +++ pearweb/include/pear-voter.php Tue Nov 7 05:47:05 2006 @@ -1,4 +1,5 @@ <?php +require 'Text/Wiki.php'; class PEAR_Voter { var $dbh; @@ -170,6 +171,9 @@ SELECT COUNT(*) FROM election_votes_abstain WHERE election_id=? ', array($id)); + $wiki =& new Text_Wiki(); + $wiki->disableRule('wikilink'); + $info['detail'] = $wiki->transform($info['detail']); if ($info['maximum_choices'] > 1) { $total = $this->dbh->getOne(' SELECT COUNT(*) FROM election_votes_multiple WHERE @@ -182,7 +186,11 @@ ', array($id)); } // percentage of abstaining voters - $info['abstain'] = $abstain / ($total + $abstain); + if ($total + $abstain > 0) { + $info['abstain'] = $abstain / ($total + $abstain); + } else { + $info['abstain'] = 0; + } return $info; } @@ -193,6 +201,22 @@ AND handle=?', array($id, $this->user)); } + function canVote($id) + { + if ($this->hasVoted($id)) { + return false; + } + $info = $this->electionInfo($id); + if (strtotime($info['votestart']) - time() > 0) { + // election is not active + return false; + } + if (strtotime($info['voteend']) - time() < 0) { + // election is finished + return false; + } + } + function getVoteSalt() { if (!isset($this->voteSalt)) { http://cvs.php.net/viewvc.cgi/pearweb/public_html/election-info.php?r1=1.2&r2=1.3&diff_format=u Index: pearweb/public_html/election-info.php diff -u pearweb/public_html/election-info.php:1.2 pearweb/public_html/election-info.php:1.3 --- pearweb/public_html/election-info.php:1.2 Mon Nov 6 05:54:53 2006 +++ pearweb/public_html/election-info.php Tue Nov 7 05:47:05 2006 @@ -109,8 +109,11 @@ $error = 'You cannot vote twice in the same election'; require dirname(dirname(__FILE__)) . '/templates/election-vote.tpl.php'; exit; - } else { + } elseif ($voter->canVote($_GET['election'])) { require dirname(dirname(__FILE__)) . '/templates/election-dovote.tpl.php'; + } else { + $info = $voter->electionInfo($_GET['election']); + require dirname(dirname(__FILE__)) . '/templates/election-showresults.tpl.php'; } } if (isset($_GET['results'])) { http://cvs.php.net/viewvc.cgi/pearweb/templates/election-confirm.tpl.php?r1=1.1&r2=1.2&diff_format=u Index: pearweb/templates/election-confirm.tpl.php diff -u pearweb/templates/election-confirm.tpl.php:1.1 pearweb/templates/election-confirm.tpl.php:1.2 --- pearweb/templates/election-confirm.tpl.php:1.1 Sun Nov 5 22:38:20 2006 +++ pearweb/templates/election-confirm.tpl.php Tue Nov 7 05:47:06 2006 @@ -5,7 +5,7 @@ <div class="errors"><?php echo $error; ?></div> <?php endif; // if (isset($error)): ?> <h2>Detail on the election</h2> -<?php echo nl2br(htmlspecialchars($info['detail'])); ?> +<?php echo $info['detail']; ?> <h2>Your Vote:</h2> <form action="/election-info.php" method="post"> <input type="hidden" name="election" value="<?php echo $info['id']; ?>" /> http://cvs.php.net/viewvc.cgi/pearweb/templates/election-confirmed.tpl.php?r1=1.1&r2=1.2&diff_format=u Index: pearweb/templates/election-confirmed.tpl.php diff -u pearweb/templates/election-confirmed.tpl.php:1.1 pearweb/templates/election-confirmed.tpl.php:1.2 --- pearweb/templates/election-confirmed.tpl.php:1.1 Sun Nov 5 22:38:20 2006 +++ pearweb/templates/election-confirmed.tpl.php Tue Nov 7 05:47:06 2006 @@ -5,7 +5,7 @@ <div class="errors"><?php echo $error; ?></div> <?php endif; // if (isset($error)): ?> <h2>Detail on the election</h2> -<?php echo nl2br(htmlspecialchars($info['detail'])); ?> +<?php echo $info['detail']; ?> <h2>Your Vote:</h2> <table> <tr> http://cvs.php.net/viewvc.cgi/pearweb/templates/election-dovote.tpl.php?r1=1.1&r2=1.2&diff_format=u Index: pearweb/templates/election-dovote.tpl.php diff -u pearweb/templates/election-dovote.tpl.php:1.1 pearweb/templates/election-dovote.tpl.php:1.2 --- pearweb/templates/election-dovote.tpl.php:1.1 Sun Nov 5 22:38:20 2006 +++ pearweb/templates/election-dovote.tpl.php Tue Nov 7 05:47:06 2006 @@ -29,7 +29,7 @@ <div class="errors"><?php echo $error; ?></div> <?php endif; // if (isset($error)): ?> <h2>Detail on the election</h2> -<?php echo nl2br(htmlspecialchars($info['detail'])); ?> +<?php echo $info['detail']; ?> <h2>Please choose <?php echo $pleasechoose; ?>:</h2> <form action="/election-info.php" method="post"> <input type="hidden" name="confirm" value="1" /> http://cvs.php.net/viewvc.cgi/pearweb/templates/election-showresults.tpl.php?r1=1.2&r2=1.3&diff_format=u Index: pearweb/templates/election-showresults.tpl.php diff -u pearweb/templates/election-showresults.tpl.php:1.2 pearweb/templates/election-showresults.tpl.php:1.3 --- pearweb/templates/election-showresults.tpl.php:1.2 Mon Nov 6 21:34:51 2006 +++ pearweb/templates/election-showresults.tpl.php Tue Nov 7 05:47:06 2006 @@ -3,7 +3,7 @@ <table> <tr> <th class="form-label_left">Election Issue</td> - <td class="form-input"><?php echo htmlspecialchars($info['detail']) ?></td> + <td class="form-input"><?php echo $info['detail'] ?></td> </tr> <tr> <th class="form-label_left">Election dates</th> http://cvs.php.net/viewvc.cgi/pearweb/include/pear-election.php?view=markup&rev=1.1 Index: pearweb/include/pear-election.php +++ pearweb/include/pear-election.php <?php class PEAR_Election { var $dbh; var $karma; var $user; function PEAR_Election() { $this->dbh = &$GLOBALS['dbh']; $this->user = isset($GLOBALS['auth_user']) ? $GLOBALS['auth_user']->handle : false; $this->karma =& new Damblan_Karma($this->dbh); } function validateStep1() { $error = array(); if (empty($_POST['purpose'])) { $error[] = 'Election Purpose (summary) is required'; } if (empty($_POST['choices'])) { $error[] = 'Number of Choices is required'; } else { if ((int) $_POST['choices'] != $_POST['choices']) { $error[] = 'Number of Choices must be an integer'; } if ($_POST['choices'] < 2 || $_POST['choices'] > 20) { $error[] = 'Number of Choices must be between 2 and 20'; } } if (empty($_POST['detail'])) { $error[] = 'Election detail is required'; } $nextyear = date('Y') + 1; $thisyear = $nextyear - 1; if (empty($_POST['year'])) { $error[] = 'Year is required'; } else { if (!is_numeric($_POST['year']) || $_POST['year'] != (int) $_POST['year']) { $error[] = 'Month is invalid'; } elseif ($_POST['year'] != $nextyear && $_POST['year'] != $thisyear) { $error[] = 'Year is invalid, must be next year or this year'; } } if (empty($_POST['month'])) { $error[] = 'Month is required'; } else { if (!is_numeric($_POST['month']) || $_POST['month'] != (int) $_POST['month']) { $error[] = 'Month is invalid'; } elseif ($_POST['month'] < 1 || $_POST['month'] > 12) { $error[] = 'Month is invalid, must be 1-12'; } } if (empty($_POST['day'])) { $error[] = 'Day is required'; } else { if (!is_numeric($_POST['day']) || $_POST['day'] != (int) $_POST['day']) { $error[] = 'Day is invalid'; } elseif ($_POST['day'] < 1 || $_POST['day'] > date('d', strtotime( $_POST['year'] . '-' . $_POST['month'] . '-01 +1 month -1 day'))) { $error[] = 'Day is invalid, must be 1-' . date('d', strtotime( $_POST['year'] . '-' . $_POST['month'] . '-01 +1 month -1 day')); } } $date = $_POST['year'] . '-' . $_POST['month'] . '-' . $_POST['day']; if (strtotime($date) != strtotime(date('Y-m-d', strtotime($date)))) { $error[] = 'Full date is invalid'; } if ((strtotime($date) - time()) / 86400 < 29.0) { $error[] = 'Voting must start at least 30 days from today'; } if (empty($_POST['length'])) { $error[] = 'Election length is required'; } else { if (!is_numeric($_POST['length']) || $_POST['length'] != (int) $_POST['length']) { $error[] = 'Voting length is invalid'; } elseif ($_POST['length'] < 1 || $_POST['length'] > 7) { $error[] = 'Voting length must be between 1 and 7 days'; } } if (empty($_POST['minimum'])) { $error[] = 'Election minimum votes needed is required'; } else { if (!is_numeric($_POST['minimum']) || $_POST['minimum'] != (int) $_POST['minimum']) { $error[] = 'Minimum votes needed is invalid'; } elseif ($_POST['minimum'] < 1 || $_POST['minimum'] > 19) { $error[] = 'Minimum votes needed must be between 1 and 19'; } } if (empty($_POST['maximum'])) { $error[] = 'Election maximum votes needed is required'; } else { if (!is_numeric($_POST['maximum']) || $_POST['maximum'] != (int) $_POST['maximum']) { $error[] = 'Maximum votes needed is invalid'; } elseif ($_POST['maximum'] < 1 || $_POST['maximum'] > 19) { $error[] = 'Maximum votes needed must be between 1 and 19'; } } if ($_POST['maximum'] < $_POST['minimum']) { $error[] = 'Maximum votes needed must be greater or the same as minimum votes needed'; } return $error; } function validateStep2() { $error = array(); for ($i = 1; $i <= $_POST['choices']; $i++) { if (empty($_POST['summary' . $i])) { $error[] = 'Summary for Choice #' . $i . ' must not be empty'; } if (empty($_POST['summary_link' . $i])) { $error[] = 'Link to more info for Choice #' . $i . ' must not be empty'; } } return $error; } function saveNewElection() { $startdate = date('Y-m-d', strtotime($_POST['year'] . '-' . $_POST['month'] . '-' . $_POST['day'])); $enddate = date('Y-m-d', strtotime($startdate . '. +' . $_POST['length'] . ' days')); $this->dbh->query(' INSERT INTO elections (purpose, detail, votestart, voteend, creator, createdate, minimum_choices, maximum_choices) VALUES(?,?,?,?,?,NOW(),?,?) ', array( $_POST['purpose'], $_POST['detail'], $startdate, $enddate, $this->user, $_POST['minimum'], $_POST['maximum'], )); $id = $this->dbh->phptype == 'mysql' ? mysql_insert_id() : mysqli_insert_id($this->dbh->connection); for ($i = 1; $i <= $_POST['choices']; $i++) { $this->dbh->query(' INSERT INTO election_choices (election_id, choice, summary, summary_link) VALUES(?,?,?,?) ', array($id, $i, $_POST['summary' . $i], $_POST['summary_link' . $i])); } } function canEdit($id) { } } http://cvs.php.net/viewvc.cgi/pearweb/public_html/election-new.php?view=markup&rev=1.1 Index: pearweb/public_html/election-new.php +++ pearweb/public_html/election-new.php <?php auth_require('pear.election'); $year = date('Y') + 1; $years = array($year--, $year); if (!isset($_POST['step'])) { $error = ''; $info = array( 'purpose' => '', 'detail' => '', 'choices' => 2, 'year' => date('Y', strtotime('+30 days')), 'month' => date('m', strtotime('+30 days')), 'day' => date('d', strtotime('+30 days')), 'length' => 7, 'minimum' => 1, 'maximum' => 1, ); require dirname(dirname(__FILE__)) . '/templates/election-new-step1.tpl.php'; } elseif ($_POST['step'] == 2) { require 'pear-election.php'; $election = new PEAR_Election; $error = $election->validateStep1(); $info['purpose'] = $_POST['purpose']; $info['detail'] = $_POST['detail']; $info['choices'] = (int) $_POST['choices']; $info['year'] = (int) $_POST['year']; $info['month'] = (int) $_POST['month']; $info['day'] = (int) $_POST['day']; $info['length'] = (int) $_POST['length']; $info['minimum'] = (int) $_POST['minimum']; $info['maximum'] = (int) $_POST['maximum']; if ($error) { require dirname(dirname(__FILE__)) . '/templates/election-new-step1.tpl.php'; exit; } for ($i = 1; $i <= $info['choices']; $i++) { $info['summary' . $i] = empty($_POST['summary' . $i]) ? '' : $_POST['summary' . $i]; $info['summary_link' . $i] = empty($_POST['summary_link' . $i]) ? '' : $_POST['summary_link' . $i]; } require dirname(dirname(__FILE__)) . '/templates/election-new-step2.tpl.php'; } elseif ($_POST['step'] == 3) { require 'pear-election.php'; $election = new PEAR_Election; $error = $election->validateStep1(); $info['purpose'] = $_POST['purpose']; $info['detail'] = $_POST['detail']; $info['choices'] = (int) $_POST['choices']; $info['year'] = (int) $_POST['year']; $info['month'] = (int) $_POST['month']; $info['day'] = (int) $_POST['day']; $info['length'] = (int) $_POST['length']; $info['minimum'] = (int) $_POST['minimum']; $info['maximum'] = (int) $_POST['maximum']; if ($error) { // this should never happen. It will only occur // if the user manually fills POST data without going // through the official form, and makes a mistake. require dirname(dirname(__FILE__)) . '/templates/election-new-step1.tpl.php'; exit; } if (isset($_POST['add1choice'])) { $info['choices']++; for ($i = 1; $i <= $info['choices']; $i++) { $info['summary' . $i] = empty($_POST['summary' . $i]) ? '' : $_POST['summary' . $i]; $info['summary_link' . $i] = empty($_POST['summary_link' . $i]) ? '' : $_POST['summary_link' . $i]; } require dirname(dirname(__FILE__)) . '/templates/election-new-step2.tpl.php'; exit; } if (isset($_POST['delete1choice']) && $info['choices'] > 2) { $info['choices']--; for ($i = 1; $i <= $info['choices']; $i++) { $info['summary' . $i] = empty($_POST['summary' . $i]) ? '' : $_POST['summary' . $i]; $info['summary_link' . $i] = empty($_POST['summary_link' . $i]) ? '' : $_POST['summary_link' . $i]; } require dirname(dirname(__FILE__)) . '/templates/election-new-step2.tpl.php'; exit; } $error = $election->validateStep2(); for ($i = 1; $i <= $info['choices']; $i++) { $info['summary' . $i] = empty($_POST['summary' . $i]) ? '' : $_POST['summary' . $i]; $info['summary_link' . $i] = empty($_POST['summary_link' . $i]) ? '' : $_POST['summary_link' . $i]; } if ($error) { require dirname(dirname(__FILE__)) . '/templates/election-new-step2.tpl.php'; exit; } require dirname(dirname(__FILE__)) . '/templates/election-new-step3.tpl.php'; } elseif ($_POST['step'] == 4) { require 'pear-election.php'; $election = new PEAR_Election; $error = $election->validateStep1(); $info['purpose'] = $_POST['purpose']; $info['detail'] = $_POST['detail']; $info['choices'] = (int) $_POST['choices']; $info['year'] = (int) $_POST['year']; $info['month'] = (int) $_POST['month']; $info['day'] = (int) $_POST['day']; $info['length'] = (int) $_POST['length']; $info['minimum'] = (int) $_POST['minimum']; $info['maximum'] = (int) $_POST['maximum']; if ($error) { // this should never happen. It will only occur // if the user manually fills POST data without going // through the official form, and makes a mistake. require dirname(dirname(__FILE__)) . '/templates/election-new-step1.tpl.php'; exit; } for ($i = 1; $i <= $info['choices']; $i++) { $info['summary' . $i] = empty($_POST['summary' . $i]) ? '' : $_POST['summary' . $i]; $info['summary_link' . $i] = empty($_POST['summary_link' . $i]) ? '' : $_POST['summary_link' . $i]; } $error = $election->validateStep2(); if ($error) { // this should never happen. It will only occur // if the user manually fills POST data without going // through the official form, and makes a mistake. require dirname(dirname(__FILE__)) . '/templates/election-new-step2.tpl.php'; exit; } $election->saveNewElection(); $error = ''; require dirname(dirname(__FILE__)) . '/templates/election-vote.tpl.php'; } http://cvs.php.net/viewvc.cgi/pearweb/templates/election-new-step1.tpl.php?view=markup&rev=1.1 Index: pearweb/templates/election-new-step1.tpl.php +++ pearweb/templates/election-new-step1.tpl.php <?php response_header('Election :: New'); ?> <h1>Create New Election [Step 1]</h1> <?php if ($error) { foreach ($error as $err) { echo '<div class="errors">' . htmlspecialchars($err) . '</div>'; } } ?> <form name="newelection" action="/election-new.php" method="post"> <input type="hidden" name="step" value="2" /> <table> <tr> <th class="form-label_left" colspan="2">(All entries are required)</th> </tr> <tr> <th class="form-label_left">Election Purpose (summary)</th> <td class="form-input"> <input type="text" name="purpose" size="100" maxlength="100" value="<?php echo htmlspecialchars($info['purpose']) ?>" /> </td> </tr> <tr> <th class="form-label_left">Number of items to choose from (items created in step 2)</th> <td class="form-input"> <select name="choices"> <?php for ($i = 2; $i <= 20; $i++) { if ($info['choices'] == $i) { $sel = ' selected="selected"'; } else { $sel = ''; } echo ' <option' . $sel . '>' . $i . '</option>' . "\n"; } ?> </select> </td> </tr> <tr> <th class="form-label_left">Election detail (wiki markup)</th> <td class="form-input"> <textarea name="detail" rows="20" cols="75"><?php echo $info['detail'] ?></textarea> </td> </tr> <tr> <th class="form-label_left">Election start date (must be at least 30 days from now)</th> <td class="form-input"> <select name="year"> <?php foreach ($years as $year) { if ($info['year'] == $year) { $sel = ' selected="selected"'; } else { $sel = ''; } echo ' <option' . $sel . '>' . $year . '</option>' . "\n"; } ?> </select>-<select name="month"> <?php for ($i = 1; $i <= 12; $i++) { if ($info['month'] == $i) { $sel = ' selected="selected"'; } else { $sel = ''; } echo ' <option' . $sel . '>' . $i . '</option>' . "\n"; } ?> </select>-<select name="day"> <?php for ($i = 1; $i <= 31; $i++) { if ($info['day'] == $i) { $sel = ' selected="selected"'; } else { $sel = ''; } echo ' <option' . $sel . '>' . $i . '</option>' . "\n"; } ?> </select> </td> </tr> <tr> <th class="form-label_left">Length of election in days</th> <td class="form-input"> <select name="length"> <?php for ($i = 1; $i <= 7; $i++) { if ($info['length'] == $i) { $sel = ' selected="selected"'; } else { $sel = ''; } echo ' <option' . $sel . '>' . $i . '</option>' . "\n"; } ?> </select> </td> </tr> <tr> <th class="form-label_left" colspan="2"> The next two sections relate to the number of items that a single voter can choose. For most elections, voters should choose only one (minimum=maximum=1). For some elections, like QA group, the voter should choose up to 5 developers to populate the QA group (minimum=1,maximum=5), and so on. </th> </tr> <tr> <th class="form-label_left">Minimum votes needed</th> <td class="form-input"> <select name="minimum"> <?php for ($i = 1; $i <= 19; $i++) { if ($info['minimum'] == $i) { $sel = ' selected="selected"'; } else { $sel = ''; } echo ' <option' . $sel . '>' . $i . '</option>' . "\n"; } ?> </select> </td> </tr> <tr> <th class="form-label_left">Maximum votes allowed</th> <td class="form-input"> <select name="maximum"> <?php for ($i = 1; $i <= 19; $i++) { if ($info['maximum'] == $i) { $sel = ' selected="selected"'; } else { $sel = ''; } echo ' <option' . $sel . '>' . $i . '</option>' . "\n"; } ?> </select> </td> </tr> </table> <input type="submit" name="newelection" value="Create New Election" /> </form> <?php response_footer(); http://cvs.php.net/viewvc.cgi/pearweb/templates/election-new-step2.tpl.php?view=markup&rev=1.1 Index: pearweb/templates/election-new-step2.tpl.php +++ pearweb/templates/election-new-step2.tpl.php <?php response_header('Election :: New'); ?> <h1>Create New Election [Step 2]</h1> <?php if ($error) { foreach ($error as $err) { echo '<div class="errors">' . htmlspecialchars($err) . '</div>'; } } ?> <form name="newelection" action="/election-new.php" method="post"> <input type="hidden" name="step" value="3" /> <input type="hidden" name="choices" value="<?php echo $info['choices'] ?>" /> <table> <?php for ($i = 1; $i <= $info['choices']; $i++): ?> <tr> <th class="form-label_left">Choice #<?php echo $i ?></th> <td class="form-input"> Summary:<br /><input name="summary<?php echo $i ?>" value="<?php echo htmlspecialchars($info['summary' . $i]) ?>" size="100" maxlength="100" /><br /> Link to more info:<br /><input name="summary_link<?php echo $i ?>" value="<?php echo htmlspecialchars($info['summary_link' . $i]) ?>" size="100" maxlength="255" /> </td> </tr> <?php endfor; // for ($i = 1; $i < $info['choices']; $i++): ?> <tr> <td colspan="2"> <input type="submit" name="add1choice" value="Add another choice" /> <?php if ($info['choices'] > 2): ?> <input type="submit" name="delete1choice" value="Remove last choice" /> <?php endif; ?> </td> </tr> <tr> <th class="form-label_left" colspan="2">Entered data (can be edited later)</th> </tr> <tr> <th class="form-label_left">Election Purpose</th> <td class="form-input"> <input type="hidden" name="purpose" value="<?php echo htmlspecialchars($info['purpose']); ?>" /> <?php echo htmlspecialchars($info['purpose']) ?> </td> </tr> <tr> <th class="form-label_left">Election detail</th> <td class="form-input"> <input type="hidden" name="detail" value="<?php echo htmlspecialchars($info['detail']); ?>" /> <?php echo htmlspecialchars($info['purpose']) ?> </td> </tr> <tr> <th class="form-label_left">Election start date</th> <td class="form-input"> <input type="hidden" name="year" value="<?php echo date('Y', strtotime($info['year'])) ?>" /> <input type="hidden" name="month" value="<?php echo date('m', strtotime($info['year'] . '-' . $info['month'] . '-' . $info['day'])) ?>" /> <input type="hidden" name="day" value="<?php echo date('d', strtotime($info['year'] . '-' . $info['month'] . '-' . $info['day'])); ?>" /> <?php echo $info['year'] . '-' . $info['month'] . '-' . $info['day'] ?> </td> </tr> <tr> <th class="form-label_left">Length of election in days</th> <td class="form-input"> <input type="hidden" name="length" value="<?php echo $info['length'] ?>" /> <?php echo $info['length']; ?> </td> </tr> <tr> <th class="form-label_left">Minimum votes needed</th> <td class="form-input"> <input type="hidden" name="minimum" value="<?php echo $info['minimum'] ?>" /> <?php echo $info['minimum'] ?> </td> </tr> <tr> <th class="form-label_left">Maximum votes allowed</th> <td class="form-input"> <input type="hidden" name="maximum" value="<?php echo $info['maximum'] ?>" /> <?php echo $info['maximum'] ?> </td> </tr> </table> <input type="submit" name="newelection" value="Create New Election" /> </form> <?php response_footer(); http://cvs.php.net/viewvc.cgi/pearweb/templates/election-new-step3.tpl.php?view=markup&rev=1.1 Index: pearweb/templates/election-new-step3.tpl.php +++ pearweb/templates/election-new-step3.tpl.php <?php response_header('Election :: New'); ?> <h1>Confirm Election Details [Step 3]</h1> <?php if ($error) { foreach ($error as $err) { echo '<div class="errors">' . htmlspecialchars($err) . '</div>'; } } ?> <form name="newelection" action="/election-new.php" method="post"> <input type="hidden" name="step" value="4" /> <input type="hidden" name="choices" value="<?php echo $info['choices'] ?>" /> <table> <?php for ($i = 1; $i <= $info['choices']; $i++): ?> <tr> <th class="form-label_left">Choice #<?php echo $i ?></th> <td class="form-input"> Summary:<br /> <input type="hidden" name="summary<?php echo $i ?>" value="<?php echo htmlspecialchars($info['summary' . $i]) ?>" /> <?php echo htmlspecialchars($info['summary' . $i]) ?><br /> Link to more info:<br /> <input type="hidden" name="summary_link<?php echo $i ?>" value="<?php echo htmlspecialchars($info['summary_link' . $i]) ?>" /> <a href="<?php echo htmlspecialchars($info['summary_link' . $i]) ?>"><?php echo htmlspecialchars($info['summary_link' . $i]) ?></a> </td> </tr> <?php endfor; // for ($i = 1; $i < $info['choices']; $i++): ?> <tr> <th class="form-label_left">Election Purpose</th> <td class="form-input"> <input type="hidden" name="purpose" value="<?php echo htmlspecialchars($info['purpose']); ?>" /> <?php echo htmlspecialchars($info['purpose']) ?> </td> </tr> <tr> <th class="form-label_left">Election detail</th> <td class="form-input"> <input type="hidden" name="detail" value="<?php echo htmlspecialchars($info['detail']); ?>" /> <?php echo htmlspecialchars($info['purpose']) ?> </td> </tr> <tr> <th class="form-label_left">Election start date</th> <td class="form-input"> <input type="hidden" name="year" value="<?php echo date('Y', strtotime($info['year'])) ?>" /> <input type="hidden" name="month" value="<?php echo date('m', strtotime($info['year'] . '-' . $info['month'] . '-' . $info['day'])) ?>" /> <input type="hidden" name="day" value="<?php echo date('d', strtotime($info['year'] . '-' . $info['month'] . '-' . $info['day'])); ?>" /> <?php echo $info['year'] . '-' . $info['month'] . '-' . $info['day'] ?> </td> </tr> <tr> <th class="form-label_left">Length of election in days</th> <td class="form-input"> <input type="hidden" name="length" value="<?php echo $info['length'] ?>" /> <?php echo $info['length']; ?> </td> </tr> <tr> <th class="form-label_left">Minimum votes needed</th> <td class="form-input"> <input type="hidden" name="minimum" value="<?php echo $info['minimum'] ?>" /> <?php echo $info['minimum'] ?> </td> </tr> <tr> <th class="form-label_left">Maximum votes allowed</th> <td class="form-input"> <input type="hidden" name="maximum" value="<?php echo $info['maximum'] ?>" /> <?php echo $info['maximum'] ?> </td> </tr> </table> <input type="submit" name="newelection" value="Create New Election" /><input type="submit" name="cancel" value="Cancel" /> </form> <?php response_footer();
http://cvs.php.net/viewvc.cgi/pearweb/include/pear-voter.php?r1=1.2&r2=1.3&diff_format=u Index: pearweb/include/pear-voter.php diff -u pearweb/include/pear-voter.php:1.2 pearweb/include/pear-voter.php:1.3 --- pearweb/include/pear-voter.php:1.2 Mon Nov 6 21:34:51 2006 +++ pearweb/include/pear-voter.php Tue Nov 7 05:47:05 2006 @@ -1,4 +1,5 @@ <?php +require 'Text/Wiki.php'; class PEAR_Voter { var $dbh; @@ -170,6 +171,9 @@ SELECT COUNT(*) FROM election_votes_abstain WHERE election_id=? ', array($id)); + $wiki =& new Text_Wiki(); + $wiki->disableRule('wikilink'); + $info['detail'] = $wiki->transform($info['detail']); if ($info['maximum_choices'] > 1) { $total = $this->dbh->getOne(' SELECT COUNT(*) FROM election_votes_multiple WHERE @@ -182,7 +186,11 @@ ', array($id)); } // percentage of abstaining voters - $info['abstain'] = $abstain / ($total + $abstain); + if ($total + $abstain > 0) { + $info['abstain'] = $abstain / ($total + $abstain); + } else { + $info['abstain'] = 0; + } return $info; } @@ -193,6 +201,22 @@ AND handle=?', array($id, $this->user)); } + function canVote($id) + { + if ($this->hasVoted($id)) { + return false; + } + $info = $this->electionInfo($id); + if (strtotime($info['votestart']) - time() > 0) { + // election is not active + return false; + } + if (strtotime($info['voteend']) - time() < 0) { + // election is finished + return false; + } + } + function getVoteSalt() { if (!isset($this->voteSalt)) { http://cvs.php.net/viewvc.cgi/pearweb/public_html/election-info.php?r1=1.2&r2=1.3&diff_format=u Index: pearweb/public_html/election-info.php diff -u pearweb/public_html/election-info.php:1.2 pearweb/public_html/election-info.php:1.3 --- pearweb/public_html/election-info.php:1.2 Mon Nov 6 05:54:53 2006 +++ pearweb/public_html/election-info.php Tue Nov 7 05:47:05 2006 @@ -109,8 +109,11 @@ $error = 'You cannot vote twice in the same election'; require dirname(dirname(__FILE__)) . '/templates/election-vote.tpl.php'; exit; - } else { + } elseif ($voter->canVote($_GET['election'])) { require dirname(dirname(__FILE__)) . '/templates/election-dovote.tpl.php'; + } else { + $info = $voter->electionInfo($_GET['election']); + require dirname(dirname(__FILE__)) . '/templates/election-showresults.tpl.php'; } } if (isset($_GET['results'])) { http://cvs.php.net/viewvc.cgi/pearweb/templates/election-confirm.tpl.php?r1=1.1&r2=1.2&diff_format=u Index: pearweb/templates/election-confirm.tpl.php diff -u pearweb/templates/election-confirm.tpl.php:1.1 pearweb/templates/election-confirm.tpl.php:1.2 --- pearweb/templates/election-confirm.tpl.php:1.1 Sun Nov 5 22:38:20 2006 +++ pearweb/templates/election-confirm.tpl.php Tue Nov 7 05:47:06 2006 @@ -5,7 +5,7 @@ <div class="errors"><?php echo $error; ?></div> <?php endif; // if (isset($error)): ?> <h2>Detail on the election</h2> -<?php echo nl2br(htmlspecialchars($info['detail'])); ?> +<?php echo $info['detail']; ?> <h2>Your Vote:</h2> <form action="/election-info.php" method="post"> <input type="hidden" name="election" value="<?php echo $info['id']; ?>" /> http://cvs.php.net/viewvc.cgi/pearweb/templates/election-confirmed.tpl.php?r1=1.1&r2=1.2&diff_format=u Index: pearweb/templates/election-confirmed.tpl.php diff -u pearweb/templates/election-confirmed.tpl.php:1.1 pearweb/templates/election-confirmed.tpl.php:1.2 --- pearweb/templates/election-confirmed.tpl.php:1.1 Sun Nov 5 22:38:20 2006 +++ pearweb/templates/election-confirmed.tpl.php Tue Nov 7 05:47:06 2006 @@ -5,7 +5,7 @@ <div class="errors"><?php echo $error; ?></div> <?php endif; // if (isset($error)): ?> <h2>Detail on the election</h2> -<?php echo nl2br(htmlspecialchars($info['detail'])); ?> +<?php echo $info['detail']; ?> <h2>Your Vote:</h2> <table> <tr> http://cvs.php.net/viewvc.cgi/pearweb/templates/election-dovote.tpl.php?r1=1.1&r2=1.2&diff_format=u Index: pearweb/templates/election-dovote.tpl.php diff -u pearweb/templates/election-dovote.tpl.php:1.1 pearweb/templates/election-dovote.tpl.php:1.2 --- pearweb/templates/election-dovote.tpl.php:1.1 Sun Nov 5 22:38:20 2006 +++ pearweb/templates/election-dovote.tpl.php Tue Nov 7 05:47:06 2006 @@ -29,7 +29,7 @@ <div class="errors"><?php echo $error; ?></div> <?php endif; // if (isset($error)): ?> <h2>Detail on the election</h2> -<?php echo nl2br(htmlspecialchars($info['detail'])); ?> +<?php echo $info['detail']; ?> <h2>Please choose <?php echo $pleasechoose; ?>:</h2> <form action="/election-info.php" method="post"> <input type="hidden" name="confirm" value="1" /> http://cvs.php.net/viewvc.cgi/pearweb/templates/election-showresults.tpl.php?r1=1.2&r2=1.3&diff_format=u Index: pearweb/templates/election-showresults.tpl.php diff -u pearweb/templates/election-showresults.tpl.php:1.2 pearweb/templates/election-showresults.tpl.php:1.3 --- pearweb/templates/election-showresults.tpl.php:1.2 Mon Nov 6 21:34:51 2006 +++ pearweb/templates/election-showresults.tpl.php Tue Nov 7 05:47:06 2006 @@ -3,7 +3,7 @@ <table> <tr> <th class="form-label_left">Election Issue</td> - <td class="form-input"><?php echo htmlspecialchars($info['detail']) ?></td> + <td class="form-input"><?php echo $info['detail'] ?></td> </tr> <tr> <th class="form-label_left">Election dates</th> http://cvs.php.net/viewvc.cgi/pearweb/include/pear-election.php?view=markup&rev=1.1 Index: pearweb/include/pear-election.php +++ pearweb/include/pear-election.php <?php class PEAR_Election { var $dbh; var $karma; var $user; function PEAR_Election() { $this->dbh = &$GLOBALS['dbh']; $this->user = isset($GLOBALS['auth_user']) ? $GLOBALS['auth_user']->handle : false; $this->karma =& new Damblan_Karma($this->dbh); } function validateStep1() { $error = array(); if (empty($_POST['purpose'])) { $error[] = 'Election Purpose (summary) is required'; } if (empty($_POST['choices'])) { $error[] = 'Number of Choices is required'; } else { if ((int) $_POST['choices'] != $_POST['choices']) { $error[] = 'Number of Choices must be an integer'; } if ($_POST['choices'] < 2 || $_POST['choices'] > 20) { $error[] = 'Number of Choices must be between 2 and 20'; } } if (empty($_POST['detail'])) { $error[] = 'Election detail is required'; } $nextyear = date('Y') + 1; $thisyear = $nextyear - 1; if (empty($_POST['year'])) { $error[] = 'Year is required'; } else { if (!is_numeric($_POST['year']) || $_POST['year'] != (int) $_POST['year']) { $error[] = 'Month is invalid'; } elseif ($_POST['year'] != $nextyear && $_POST['year'] != $thisyear) { $error[] = 'Year is invalid, must be next year or this year'; } } if (empty($_POST['month'])) { $error[] = 'Month is required'; } else { if (!is_numeric($_POST['month']) || $_POST['month'] != (int) $_POST['month']) { $error[] = 'Month is invalid'; } elseif ($_POST['month'] < 1 || $_POST['month'] > 12) { $error[] = 'Month is invalid, must be 1-12'; } } if (empty($_POST['day'])) { $error[] = 'Day is required'; } else { if (!is_numeric($_POST['day']) || $_POST['day'] != (int) $_POST['day']) { $error[] = 'Day is invalid'; } elseif ($_POST['day'] < 1 || $_POST['day'] > date('d', strtotime( $_POST['year'] . '-' . $_POST['month'] . '-01 +1 month -1 day'))) { $error[] = 'Day is invalid, must be 1-' . date('d', strtotime( $_POST['year'] . '-' . $_POST['month'] . '-01 +1 month -1 day')); } } $date = $_POST['year'] . '-' . $_POST['month'] . '-' . $_POST['day']; if (strtotime($date) != strtotime(date('Y-m-d', strtotime($date)))) { $error[] = 'Full date is invalid'; } if ((strtotime($date) - time()) / 86400 < 29.0) { $error[] = 'Voting must start at least 30 days from today'; } if (empty($_POST['length'])) { $error[] = 'Election length is required'; } else { if (!is_numeric($_POST['length']) || $_POST['length'] != (int) $_POST['length']) { $error[] = 'Voting length is invalid'; } elseif ($_POST['length'] < 1 || $_POST['length'] > 7) { $error[] = 'Voting length must be between 1 and 7 days'; } } if (empty($_POST['minimum'])) { $error[] = 'Election minimum votes needed is required'; } else { if (!is_numeric($_POST['minimum']) || $_POST['minimum'] != (int) $_POST['minimum']) { $error[] = 'Minimum votes needed is invalid'; } elseif ($_POST['minimum'] < 1 || $_POST['minimum'] > 19) { $error[] = 'Minimum votes needed must be between 1 and 19'; } } if (empty($_POST['maximum'])) { $error[] = 'Election maximum votes needed is required'; } else { if (!is_numeric($_POST['maximum']) || $_POST['maximum'] != (int) $_POST['maximum']) { $error[] = 'Maximum votes needed is invalid'; } elseif ($_POST['maximum'] < 1 || $_POST['maximum'] > 19) { $error[] = 'Maximum votes needed must be between 1 and 19'; } } if ($_POST['maximum'] < $_POST['minimum']) { $error[] = 'Maximum votes needed must be greater or the same as minimum votes needed'; } return $error; } function validateStep2() { $error = array(); for ($i = 1; $i <= $_POST['choices']; $i++) { if (empty($_POST['summary' . $i])) { $error[] = 'Summary for Choice #' . $i . ' must not be empty'; } if (empty($_POST['summary_link' . $i])) { $error[] = 'Link to more info for Choice #' . $i . ' must not be empty'; } } return $error; } function saveNewElection() { $startdate = date('Y-m-d', strtotime($_POST['year'] . '-' . $_POST['month'] . '-' . $_POST['day'])); $enddate = date('Y-m-d', strtotime($startdate . '. +' . $_POST['length'] . ' days')); $this->dbh->query(' INSERT INTO elections (purpose, detail, votestart, voteend, creator, createdate, minimum_choices, maximum_choices) VALUES(?,?,?,?,?,NOW(),?,?) ', array( $_POST['purpose'], $_POST['detail'], $startdate, $enddate, $this->user, $_POST['minimum'], $_POST['maximum'], )); $id = $this->dbh->phptype == 'mysql' ? mysql_insert_id() : mysqli_insert_id($this->dbh->connection); for ($i = 1; $i <= $_POST['choices']; $i++) { $this->dbh->query(' INSERT INTO election_choices (election_id, choice, summary, summary_link) VALUES(?,?,?,?) ', array($id, $i, $_POST['summary' . $i], $_POST['summary_link' . $i])); } } function canEdit($id) { } } http://cvs.php.net/viewvc.cgi/pearweb/public_html/election-new.php?view=markup&rev=1.1 Index: pearweb/public_html/election-new.php +++ pearweb/public_html/election-new.php <?php auth_require('pear.election'); $year = date('Y') + 1; $years = array($year--, $year); if (!isset($_POST['step'])) { $error = ''; $info = array( 'purpose' => '', 'detail' => '', 'choices' => 2, 'year' => date('Y', strtotime('+30 days')), 'month' => date('m', strtotime('+30 days')), 'day' => date('d', strtotime('+30 days')), 'length' => 7, 'minimum' => 1, 'maximum' => 1, ); require dirname(dirname(__FILE__)) . '/templates/election-new-step1.tpl.php'; } elseif ($_POST['step'] == 2) { require 'pear-election.php'; $election = new PEAR_Election; $error = $election->validateStep1(); $info['purpose'] = $_POST['purpose']; $info['detail'] = $_POST['detail']; $info['choices'] = (int) $_POST['choices']; $info['year'] = (int) $_POST['year']; $info['month'] = (int) $_POST['month']; $info['day'] = (int) $_POST['day']; $info['length'] = (int) $_POST['length']; $info['minimum'] = (int) $_POST['minimum']; $info['maximum'] = (int) $_POST['maximum']; if ($error) { require dirname(dirname(__FILE__)) . '/templates/election-new-step1.tpl.php'; exit; } for ($i = 1; $i <= $info['choices']; $i++) { $info['summary' . $i] = empty($_POST['summary' . $i]) ? '' : $_POST['summary' . $i]; $info['summary_link' . $i] = empty($_POST['summary_link' . $i]) ? '' : $_POST['summary_link' . $i]; } require dirname(dirname(__FILE__)) . '/templates/election-new-step2.tpl.php'; } elseif ($_POST['step'] == 3) { require 'pear-election.php'; $election = new PEAR_Election; $error = $election->validateStep1(); $info['purpose'] = $_POST['purpose']; $info['detail'] = $_POST['detail']; $info['choices'] = (int) $_POST['choices']; $info['year'] = (int) $_POST['year']; $info['month'] = (int) $_POST['month']; $info['day'] = (int) $_POST['day']; $info['length'] = (int) $_POST['length']; $info['minimum'] = (int) $_POST['minimum']; $info['maximum'] = (int) $_POST['maximum']; if ($error) { // this should never happen. It will only occur // if the user manually fills POST data without going // through the official form, and makes a mistake. require dirname(dirname(__FILE__)) . '/templates/election-new-step1.tpl.php'; exit; } if (isset($_POST['add1choice'])) { $info['choices']++; for ($i = 1; $i <= $info['choices']; $i++) { $info['summary' . $i] = empty($_POST['summary' . $i]) ? '' : $_POST['summary' . $i]; $info['summary_link' . $i] = empty($_POST['summary_link' . $i]) ? '' : $_POST['summary_link' . $i]; } require dirname(dirname(__FILE__)) . '/templates/election-new-step2.tpl.php'; exit; } if (isset($_POST['delete1choice']) && $info['choices'] > 2) { $info['choices']--; for ($i = 1; $i <= $info['choices']; $i++) { $info['summary' . $i] = empty($_POST['summary' . $i]) ? '' : $_POST['summary' . $i]; $info['summary_link' . $i] = empty($_POST['summary_link' . $i]) ? '' : $_POST['summary_link' . $i]; } require dirname(dirname(__FILE__)) . '/templates/election-new-step2.tpl.php'; exit; } $error = $election->validateStep2(); for ($i = 1; $i <= $info['choices']; $i++) { $info['summary' . $i] = empty($_POST['summary' . $i]) ? '' : $_POST['summary' . $i]; $info['summary_link' . $i] = empty($_POST['summary_link' . $i]) ? '' : $_POST['summary_link' . $i]; } if ($error) { require dirname(dirname(__FILE__)) . '/templates/election-new-step2.tpl.php'; exit; } require dirname(dirname(__FILE__)) . '/templates/election-new-step3.tpl.php'; } elseif ($_POST['step'] == 4) { require 'pear-election.php'; $election = new PEAR_Election; $error = $election->validateStep1(); $info['purpose'] = $_POST['purpose']; $info['detail'] = $_POST['detail']; $info['choices'] = (int) $_POST['choices']; $info['year'] = (int) $_POST['year']; $info['month'] = (int) $_POST['month']; $info['day'] = (int) $_POST['day']; $info['length'] = (int) $_POST['length']; $info['minimum'] = (int) $_POST['minimum']; $info['maximum'] = (int) $_POST['maximum']; if ($error) { // this should never happen. It will only occur // if the user manually fills POST data without going // through the official form, and makes a mistake. require dirname(dirname(__FILE__)) . '/templates/election-new-step1.tpl.php'; exit; } for ($i = 1; $i <= $info['choices']; $i++) { $info['summary' . $i] = empty($_POST['summary' . $i]) ? '' : $_POST['summary' . $i]; $info['summary_link' . $i] = empty($_POST['summary_link' . $i]) ? '' : $_POST['summary_link' . $i]; } $error = $election->validateStep2(); if ($error) { // this should never happen. It will only occur // if the user manually fills POST data without going // through the official form, and makes a mistake. require dirname(dirname(__FILE__)) . '/templates/election-new-step2.tpl.php'; exit; } $election->saveNewElection(); $error = ''; require dirname(dirname(__FILE__)) . '/templates/election-vote.tpl.php'; } http://cvs.php.net/viewvc.cgi/pearweb/templates/election-new-step1.tpl.php?view=markup&rev=1.1 Index: pearweb/templates/election-new-step1.tpl.php +++ pearweb/templates/election-new-step1.tpl.php <?php response_header('Election :: New'); ?> <h1>Create New Election [Step 1]</h1> <?php if ($error) { foreach ($error as $err) { echo '<div class="errors">' . htmlspecialchars($err) . '</div>'; } } ?> <form name="newelection" action="/election-new.php" method="post"> <input type="hidden" name="step" value="2" /> <table> <tr> <th class="form-label_left" colspan="2">(All entries are required)</th> </tr> <tr> <th class="form-label_left">Election Purpose (summary)</th> <td class="form-input"> <input type="text" name="purpose" size="100" maxlength="100" value="<?php echo htmlspecialchars($info['purpose']) ?>" /> </td> </tr> <tr> <th class="form-label_left">Number of items to choose from (items created in step 2)</th> <td class="form-input"> <select name="choices"> <?php for ($i = 2; $i <= 20; $i++) { if ($info['choices'] == $i) { $sel = ' selected="selected"'; } else { $sel = ''; } echo ' <option' . $sel . '>' . $i . '</option>' . "\n"; } ?> </select> </td> </tr> <tr> <th class="form-label_left">Election detail (wiki markup)</th> <td class="form-input"> <textarea name="detail" rows="20" cols="75"><?php echo $info['detail'] ?></textarea> </td> </tr> <tr> <th class="form-label_left">Election start date (must be at least 30 days from now)</th> <td class="form-input"> <select name="year"> <?php foreach ($years as $year) { if ($info['year'] == $year) { $sel = ' selected="selected"'; } else { $sel = ''; } echo ' <option' . $sel . '>' . $year . '</option>' . "\n"; } ?> </select>-<select name="month"> <?php for ($i = 1; $i <= 12; $i++) { if ($info['month'] == $i) { $sel = ' selected="selected"'; } else { $sel = ''; } echo ' <option' . $sel . '>' . $i . '</option>' . "\n"; } ?> </select>-<select name="day"> <?php for ($i = 1; $i <= 31; $i++) { if ($info['day'] == $i) { $sel = ' selected="selected"'; } else { $sel = ''; } echo ' <option' . $sel . '>' . $i . '</option>' . "\n"; } ?> </select> </td> </tr> <tr> <th class="form-label_left">Length of election in days</th> <td class="form-input"> <select name="length"> <?php for ($i = 1; $i <= 7; $i++) { if ($info['length'] == $i) { $sel = ' selected="selected"'; } else { $sel = ''; } echo ' <option' . $sel . '>' . $i . '</option>' . "\n"; } ?> </select> </td> </tr> <tr> <th class="form-label_left" colspan="2"> The next two sections relate to the number of items that a single voter can choose. For most elections, voters should choose only one (minimum=maximum=1). For some elections, like QA group, the voter should choose up to 5 developers to populate the QA group (minimum=1,maximum=5), and so on. </th> </tr> <tr> <th class="form-label_left">Minimum votes needed</th> <td class="form-input"> <select name="minimum"> <?php for ($i = 1; $i <= 19; $i++) { if ($info['minimum'] == $i) { $sel = ' selected="selected"'; } else { $sel = ''; } echo ' <option' . $sel . '>' . $i . '</option>' . "\n"; } ?> </select> </td> </tr> <tr> <th class="form-label_left">Maximum votes allowed</th> <td class="form-input"> <select name="maximum"> <?php for ($i = 1; $i <= 19; $i++) { if ($info['maximum'] == $i) { $sel = ' selected="selected"'; } else { $sel = ''; } echo ' <option' . $sel . '>' . $i . '</option>' . "\n"; } ?> </select> </td> </tr> </table> <input type="submit" name="newelection" value="Create New Election" /> </form> <?php response_footer(); http://cvs.php.net/viewvc.cgi/pearweb/templates/election-new-step2.tpl.php?view=markup&rev=1.1 Index: pearweb/templates/election-new-step2.tpl.php +++ pearweb/templates/election-new-step2.tpl.php <?php response_header('Election :: New'); ?> <h1>Create New Election [Step 2]</h1> <?php if ($error) { foreach ($error as $err) { echo '<div class="errors">' . htmlspecialchars($err) . '</div>'; } } ?> <form name="newelection" action="/election-new.php" method="post"> <input type="hidden" name="step" value="3" /> <input type="hidden" name="choices" value="<?php echo $info['choices'] ?>" /> <table> <?php for ($i = 1; $i <= $info['choices']; $i++): ?> <tr> <th class="form-label_left">Choice #<?php echo $i ?></th> <td class="form-input"> Summary:<br /><input name="summary<?php echo $i ?>" value="<?php echo htmlspecialchars($info['summary' . $i]) ?>" size="100" maxlength="100" /><br /> Link to more info:<br /><input name="summary_link<?php echo $i ?>" value="<?php echo htmlspecialchars($info['summary_link' . $i]) ?>" size="100" maxlength="255" /> </td> </tr> <?php endfor; // for ($i = 1; $i < $info['choices']; $i++): ?> <tr> <td colspan="2"> <input type="submit" name="add1choice" value="Add another choice" /> <?php if ($info['choices'] > 2): ?> <input type="submit" name="delete1choice" value="Remove last choice" /> <?php endif; ?> </td> </tr> <tr> <th class="form-label_left" colspan="2">Entered data (can be edited later)</th> </tr> <tr> <th class="form-label_left">Election Purpose</th> <td class="form-input"> <input type="hidden" name="purpose" value="<?php echo htmlspecialchars($info['purpose']); ?>" /> <?php echo htmlspecialchars($info['purpose']) ?> </td> </tr> <tr> <th class="form-label_left">Election detail</th> <td class="form-input"> <input type="hidden" name="detail" value="<?php echo htmlspecialchars($info['detail']); ?>" /> <?php echo htmlspecialchars($info['purpose']) ?> </td> </tr> <tr> <th class="form-label_left">Election start date</th> <td class="form-input"> <input type="hidden" name="year" value="<?php echo date('Y', strtotime($info['year'])) ?>" /> <input type="hidden" name="month" value="<?php echo date('m', strtotime($info['year'] . '-' . $info['month'] . '-' . $info['day'])) ?>" /> <input type="hidden" name="day" value="<?php echo date('d', strtotime($info['year'] . '-' . $info['month'] . '-' . $info['day'])); ?>" /> <?php echo $info['year'] . '-' . $info['month'] . '-' . $info['day'] ?> </td> </tr> <tr> <th class="form-label_left">Length of election in days</th> <td class="form-input"> <input type="hidden" name="length" value="<?php echo $info['length'] ?>" /> <?php echo $info['length']; ?> </td> </tr> <tr> <th class="form-label_left">Minimum votes needed</th> <td class="form-input"> <input type="hidden" name="minimum" value="<?php echo $info['minimum'] ?>" /> <?php echo $info['minimum'] ?> </td> </tr> <tr> <th class="form-label_left">Maximum votes allowed</th> <td class="form-input"> <input type="hidden" name="maximum" value="<?php echo $info['maximum'] ?>" /> <?php echo $info['maximum'] ?> </td> </tr> </table> <input type="submit" name="newelection" value="Create New Election" /> </form> <?php response_footer(); http://cvs.php.net/viewvc.cgi/pearweb/templates/election-new-step3.tpl.php?view=markup&rev=1.1 Index: pearweb/templates/election-new-step3.tpl.php +++ pearweb/templates/election-new-step3.tpl.php <?php response_header('Election :: New'); ?> <h1>Confirm Election Details [Step 3]</h1> <?php if ($error) { foreach ($error as $err) { echo '<div class="errors">' . htmlspecialchars($err) . '</div>'; } } ?> <form name="newelection" action="/election-new.php" method="post"> <input type="hidden" name="step" value="4" /> <input type="hidden" name="choices" value="<?php echo $info['choices'] ?>" /> <table> <?php for ($i = 1; $i <= $info['choices']; $i++): ?> <tr> <th class="form-label_left">Choice #<?php echo $i ?></th> <td class="form-input"> Summary:<br /> <input type="hidden" name="summary<?php echo $i ?>" value="<?php echo htmlspecialchars($info['summary' . $i]) ?>" /> <?php echo htmlspecialchars($info['summary' . $i]) ?><br /> Link to more info:<br /> <input type="hidden" name="summary_link<?php echo $i ?>" value="<?php echo htmlspecialchars($info['summary_link' . $i]) ?>" /> <a href="<?php echo htmlspecialchars($info['summary_link' . $i]) ?>"><?php echo htmlspecialchars($info['summary_link' . $i]) ?></a> </td> </tr> <?php endfor; // for ($i = 1; $i < $info['choices']; $i++): ?> <tr> <th class="form-label_left">Election Purpose</th> <td class="form-input"> <input type="hidden" name="purpose" value="<?php echo htmlspecialchars($info['purpose']); ?>" /> <?php echo htmlspecialchars($info['purpose']) ?> </td> </tr> <tr> <th class="form-label_left">Election detail</th> <td class="form-input"> <input type="hidden" name="detail" value="<?php echo htmlspecialchars($info['detail']); ?>" /> <?php echo htmlspecialchars($info['purpose']) ?> </td> </tr> <tr> <th class="form-label_left">Election start date</th> <td class="form-input"> <input type="hidden" name="year" value="<?php echo date('Y', strtotime($info['year'])) ?>" /> <input type="hidden" name="month" value="<?php echo date('m', strtotime($info['year'] . '-' . $info['month'] . '-' . $info['day'])) ?>" /> <input type="hidden" name="day" value="<?php echo date('d', strtotime($info['year'] . '-' . $info['month'] . '-' . $info['day'])); ?>" /> <?php echo $info['year'] . '-' . $info['month'] . '-' . $info['day'] ?> </td> </tr> <tr> <th class="form-label_left">Length of election in days</th> <td class="form-input"> <input type="hidden" name="length" value="<?php echo $info['length'] ?>" /> <?php echo $info['length']; ?> </td> </tr> <tr> <th class="form-label_left">Minimum votes needed</th> <td class="form-input"> <input type="hidden" name="minimum" value="<?php echo $info['minimum'] ?>" /> <?php echo $info['minimum'] ?> </td> </tr> <tr> <th class="form-label_left">Maximum votes allowed</th> <td class="form-input"> <input type="hidden" name="maximum" value="<?php echo $info['maximum'] ?>" /> <?php echo $info['maximum'] ?> </td> </tr> </table> <input type="submit" name="newelection" value="Create New Election" /><input type="submit" name="cancel" value="Cancel" /> </form> <?php response_footer();