s/option/choice/, also rename the variable for the temporary token to
2005-10-24 Vincent Untz <vuntz@gnome.org> * foundation.gnome.org/vote/*: s/option/choice/, also rename the variable for the temporary token to tmp_token * foundation.gnome.org/vote/include/election-sql.php: make it possible to use a local configuration for testing
This commit is contained in:
parent
d49c1a02f2
commit
6810d2ffbd
9 changed files with 137 additions and 110 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
2005-10-24 Vincent Untz <vuntz@gnome.org>
|
||||||
|
|
||||||
|
* foundation.gnome.org/vote/*: s/option/choice/, also rename the
|
||||||
|
variable for the temporary token to tmp_token
|
||||||
|
* foundation.gnome.org/vote/include/election-sql.php: make it possible
|
||||||
|
to use a local configuration for testing
|
||||||
|
|
||||||
2005-10-24 Vincent Untz <vuntz@gnome.org>
|
2005-10-24 Vincent Untz <vuntz@gnome.org>
|
||||||
|
|
||||||
* configure.in:
|
* configure.in:
|
||||||
|
|
|
@ -1,13 +1,33 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once ("/home/admin/secret/anonvoting");
|
$has_config = FALSE;
|
||||||
|
|
||||||
|
$mysql_host = "";
|
||||||
|
$mysql_user = "";
|
||||||
|
$mysql_password = "";
|
||||||
|
$mysql_db = "";
|
||||||
|
|
||||||
$elections_table = "elections";
|
$elections_table = "elections";
|
||||||
$options_table = "election_options";
|
$choices_table = "election_choices";
|
||||||
$anon_tokens_table = "election_anon_tokens";
|
$anon_tokens_table = "election_anon_tokens";
|
||||||
$tokens_table = "election_tokens";
|
$tmp_tokens_table = "election_tmp_tokens";
|
||||||
$votes_table = "election_votes";
|
$votes_table = "election_votes";
|
||||||
$members_table = "foundation_members";
|
$members_table = "foundationmembers";
|
||||||
|
|
||||||
|
if (is_readable ("include/localconfig.php")) {
|
||||||
|
/* You can use such a file to have a local config for testing purpose. */
|
||||||
|
include ("include/localconfig.php");
|
||||||
|
$has_config = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_readable ("/home/admin/secret/anonvoting")) {
|
||||||
|
include ("/home/admin/secret/anonvoting");
|
||||||
|
$has_config = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$has_config) {
|
||||||
|
trigger_error ("No configuration found.");
|
||||||
|
}
|
||||||
|
|
||||||
function elec_sql_open () {
|
function elec_sql_open () {
|
||||||
global $mysql_host;
|
global $mysql_host;
|
||||||
|
@ -15,18 +35,18 @@ function elec_sql_open () {
|
||||||
global $mysql_password;
|
global $mysql_password;
|
||||||
global $mysql_db;
|
global $mysql_db;
|
||||||
|
|
||||||
$handle = mysql_connect ("$mysql_host", "$mysql_user", "$mysql_password");
|
$handle = mysql_connect ("$mysql_host", "$mysql_user", "$mysql_password");
|
||||||
if (!$handle) {
|
if (!$handle) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
$select_base = mysql_select_db ($mysql_database, $handle);
|
$select_base = mysql_select_db ($mysql_database, $handle);
|
||||||
if (!$select_base) {
|
if (!$select_base) {
|
||||||
elec_sql_close ($handle);
|
elec_sql_close ($handle);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $handle;
|
return $handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
function elec_sql_close ($handle) {
|
function elec_sql_close ($handle) {
|
||||||
|
@ -102,8 +122,8 @@ function elec_get_previous_by_date_desc ($handle) {
|
||||||
return elec_get_by_date_desc_with_where ($handle, $where);
|
return elec_get_by_date_desc_with_where ($handle, $where);
|
||||||
}
|
}
|
||||||
|
|
||||||
function elec_verify_email_token ($handle, $election_id, $email, $token) {
|
function elec_verify_email_tmp_token ($handle, $election_id, $email, $tmp_token) {
|
||||||
global $tokens_table;
|
global $tmp_tokens_table;
|
||||||
global $members_table;
|
global $members_table;
|
||||||
|
|
||||||
if ($handle === FALSE)
|
if ($handle === FALSE)
|
||||||
|
@ -111,11 +131,11 @@ function elec_verify_email_token ($handle, $election_id, $email, $token) {
|
||||||
|
|
||||||
$escaped_election_id = mysql_real_escape_string ($election_id, $handle);
|
$escaped_election_id = mysql_real_escape_string ($election_id, $handle);
|
||||||
$escaped_email = mysql_real_escape_string ($email, $handle);
|
$escaped_email = mysql_real_escape_string ($email, $handle);
|
||||||
$escaped_token = mysql_real_escape_string ($token, $handle);
|
$escaped_tmp_token = mysql_real_escape_string ($tmp_token, $handle);
|
||||||
|
|
||||||
$query = "SELECT COUNT(*) FROM " . $tokens_table . " AS tt, " . $members_table . " AS mt";
|
$query = "SELECT COUNT(*) FROM " . $tmp_tokens_table . " AS tt, " . $members_table . " AS mt";
|
||||||
$query .= " WHERE tt.election_id = '".$escaped_election_id."'";
|
$query .= " WHERE tt.election_id = '".$escaped_election_id."'";
|
||||||
$query .= " AND tt.token = '".$escaped_token."'";
|
$query .= " AND tt.tmp_token = '".$escaped_tmp_token."'";
|
||||||
$query .= " AND tt.member_id = mt.id";
|
$query .= " AND tt.member_id = mt.id";
|
||||||
$query .= " AND mt.email = '".$escaped_email."'";
|
$query .= " AND mt.email = '".$escaped_email."'";
|
||||||
|
|
||||||
|
@ -126,15 +146,15 @@ function elec_verify_email_token ($handle, $election_id, $email, $token) {
|
||||||
return (mysql_result ($result, 0, 0) == 1);
|
return (mysql_result ($result, 0, 0) == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
function elec_options_get ($handle, $election_id) {
|
function elec_choices_get ($handle, $election_id) {
|
||||||
global $options_table;
|
global $choices_table;
|
||||||
|
|
||||||
if ($handle === FALSE)
|
if ($handle === FALSE)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
$escaped_election_id = mysql_real_escape_string ($election_id, $handle);
|
$escaped_election_id = mysql_real_escape_string ($election_id, $handle);
|
||||||
|
|
||||||
$query = "SELECT * FROM " . $options_table;
|
$query = "SELECT * FROM " . $choices_table;
|
||||||
$query .= " WHERE election_id = '".$escaped_election_id."'";
|
$query .= " WHERE election_id = '".$escaped_election_id."'";
|
||||||
|
|
||||||
$result = mysql_query ($query, $handle);
|
$result = mysql_query ($query, $handle);
|
||||||
|
@ -152,14 +172,14 @@ function elec_options_get ($handle, $election_id) {
|
||||||
return $retval;
|
return $retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
function elec_verify_elections ($options_nb, $options) {
|
function elec_verify_elections ($choices_nb, $choices) {
|
||||||
if ($options_nb === FALSE || $options === FALSE)
|
if ($choices_nb === FALSE || $choices === FALSE)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if ($options_nb < 1)
|
if ($choices_nb < 1)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (count ($options) < $options_nb || count ($options) <= 1)
|
if (count ($choices) < $choices_nb || count ($choices) <= 1)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -201,25 +221,25 @@ function elec_election_get_type ($election) {
|
||||||
return "election";
|
return "election";
|
||||||
}
|
}
|
||||||
|
|
||||||
function elec_vote_get_votes_from_post ($options) {
|
function elec_vote_get_votes_from_post ($choices) {
|
||||||
$votes_array = array ();
|
$votes_array = array ();
|
||||||
|
|
||||||
foreach ($options as $option) {
|
foreach ($choices as $choice) {
|
||||||
$name = "vote".$option["id"];
|
$name = "vote".$choice["id"];
|
||||||
if (isset ($_POST[$name]) && $_POST[$name] != "") {
|
if (isset ($_POST[$name]) && $_POST[$name] != "") {
|
||||||
array_push ($votes_array, $option["id"]);
|
array_push ($votes_array, $choice["id"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $votes_array;
|
return $votes_array;
|
||||||
}
|
}
|
||||||
|
|
||||||
function elec_verify_vote_is_valid ($options_nb, $options, $vote, $votes_array) {
|
function elec_verify_vote_is_valid ($choices_nb, $choices, $vote, $votes_array) {
|
||||||
if ($options_nb == 1)
|
if ($choices_nb == 1)
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
if (count ($votes_array) > $options_nb) {
|
if (count ($votes_array) > $choices_nb) {
|
||||||
return "you chose ".count ($votes_array)." answers, while you can't choose more than ".$options_nb." answers.";
|
return "you chose ".count ($votes_array)." answers, while you can't choose more than ".$choices_nb." answers.";
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
|
@ -263,7 +283,7 @@ function elec_insert_new_vote ($handle, $anon_token_id, $vote) {
|
||||||
$escaped_vote = mysql_real_escape_string ($vote, $handle);
|
$escaped_vote = mysql_real_escape_string ($vote, $handle);
|
||||||
$escaped_anon_token_id = mysql_real_escape_string ($anon_token_id, $handle);
|
$escaped_anon_token_id = mysql_real_escape_string ($anon_token_id, $handle);
|
||||||
|
|
||||||
$query = "INSERT INTO " . $votes_table . " (option_id, anon_id)";
|
$query = "INSERT INTO " . $votes_table . " (choice_id, anon_id)";
|
||||||
$query .= " VALUES ('".$escaped_vote."', '".$escaped_anon_token_id."')";
|
$query .= " VALUES ('".$escaped_vote."', '".$escaped_anon_token_id."')";
|
||||||
|
|
||||||
$result = mysql_query ($query, $handle);
|
$result = mysql_query ($query, $handle);
|
||||||
|
@ -273,21 +293,21 @@ function elec_insert_new_vote ($handle, $anon_token_id, $vote) {
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
function elec_sql_remove_token ($handle, $election_id, $email, $token) {
|
function elec_sql_remove_tmp_token ($handle, $election_id, $email, $tmp_token) {
|
||||||
global $members_table;
|
global $members_table;
|
||||||
global $tokens_table;
|
global $tmp_tokens_table;
|
||||||
|
|
||||||
if ($handle === FALSE)
|
if ($handle === FALSE)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
$escaped_election_id = mysql_real_escape_string ($election_id, $handle);
|
$escaped_election_id = mysql_real_escape_string ($election_id, $handle);
|
||||||
$escaped_email = mysql_real_escape_string ($email, $handle);
|
$escaped_email = mysql_real_escape_string ($email, $handle);
|
||||||
$escaped_token = mysql_real_escape_string ($token, $handle);
|
$escaped_tmp_token = mysql_real_escape_string ($tmp_token, $handle);
|
||||||
|
|
||||||
$query = "DELETE FROM " . $tokens_table;
|
$query = "DELETE FROM " . $tmp_tokens_table;
|
||||||
$query .= " USING ". $tokens_table . " AS tt, " . $members_table . " AS mt";
|
$query .= " USING ". $tmp_tokens_table . " AS tt, " . $members_table . " AS mt";
|
||||||
$query .= " WHERE tt.election_id = '".$escaped_election_id."'";
|
$query .= " WHERE tt.election_id = '".$escaped_election_id."'";
|
||||||
$query .= " AND tt.token = '".$escaped_token."'";
|
$query .= " AND tt.tmp_token = '".$escaped_tmp_token."'";
|
||||||
$query .= " AND tt.member_id = mt.id";
|
$query .= " AND tt.member_id = mt.id";
|
||||||
$query .= " AND mt.email = '".$escaped_email."'";
|
$query .= " AND mt.email = '".$escaped_email."'";
|
||||||
|
|
||||||
|
@ -334,11 +354,11 @@ function elec_get_results_election ($handle, $election_id) {
|
||||||
|
|
||||||
$escaped_election_id = mysql_real_escape_string ($election_id, $handle);
|
$escaped_election_id = mysql_real_escape_string ($election_id, $handle);
|
||||||
|
|
||||||
$query = "SELECT option_id, COUNT(option_id) AS total_option FROM " . $anon_tokens_table . " AS att, " . $votes_table . " AS vt";
|
$query = "SELECT choice_id, COUNT(choice_id) AS total_choice FROM " . $anon_tokens_table . " AS att, " . $votes_table . " AS vt";
|
||||||
$query .= " WHERE att.election_id = '".$escaped_election_id."'";
|
$query .= " WHERE att.election_id = '".$escaped_election_id."'";
|
||||||
$query .= " AND att.id = vt.anon_id";
|
$query .= " AND att.id = vt.anon_id";
|
||||||
$query .= " GROUP BY option_id";
|
$query .= " GROUP BY choice_id";
|
||||||
$query .= " ORDER BY total_option DESC";
|
$query .= " ORDER BY total_choice DESC";
|
||||||
|
|
||||||
$result = mysql_query ($query, $handle);
|
$result = mysql_query ($query, $handle);
|
||||||
|
|
||||||
|
@ -363,9 +383,9 @@ function elec_get_votes_for_anon_token ($handle, $anon_token_id) {
|
||||||
|
|
||||||
$escaped_anon_token_id = mysql_real_escape_string ($anon_token_id, $handle);
|
$escaped_anon_token_id = mysql_real_escape_string ($anon_token_id, $handle);
|
||||||
|
|
||||||
$query = "SELECT option_id FROM " . $votes_table;
|
$query = "SELECT choice_id FROM " . $votes_table;
|
||||||
$query .= " WHERE anon_id = '".$escaped_anon_token_id."'";
|
$query .= " WHERE anon_id = '".$escaped_anon_token_id."'";
|
||||||
$query .= " ORDER BY option_id";
|
$query .= " ORDER BY choice_id";
|
||||||
|
|
||||||
$result = mysql_query ($query, $handle);
|
$result = mysql_query ($query, $handle);
|
||||||
|
|
||||||
|
@ -374,7 +394,7 @@ function elec_get_votes_for_anon_token ($handle, $anon_token_id) {
|
||||||
} else {
|
} else {
|
||||||
$result_array = array ();
|
$result_array = array ();
|
||||||
while ($buffer = mysql_fetch_assoc ($result)) {
|
while ($buffer = mysql_fetch_assoc ($result)) {
|
||||||
$result_array[] = $buffer["option_id"];
|
$result_array[] = $buffer["choice_id"];
|
||||||
}
|
}
|
||||||
$retval = $result_array;
|
$retval = $result_array;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
function step1_do () {
|
function step1_do () {
|
||||||
global $email;
|
global $email;
|
||||||
global $token;
|
global $tmp_token;
|
||||||
|
|
||||||
$result = "<h2>Step 1/4 - Login</h2>\n";
|
$result = "<h2>Step 1/4 - Login</h2>\n";
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ function step1_do () {
|
||||||
|
|
||||||
$result .= "<div class=\"votedata\">\n";
|
$result .= "<div class=\"votedata\">\n";
|
||||||
$result .= "<p><label for=\"email\">E-mail: </label><input type=\"text\" name=\"email\" value=\"".htmlspecialchars ($email)."\" /></p>\n";
|
$result .= "<p><label for=\"email\">E-mail: </label><input type=\"text\" name=\"email\" value=\"".htmlspecialchars ($email)."\" /></p>\n";
|
||||||
$result .= "<p><label for=\"token\">Vote token: </label><input type=\"text\" name=\"token\" value=\"".htmlspecialchars ($token)."\" /></p>\n";
|
$result .= "<p><label for=\"tmp_token\">Vote token: </label><input type=\"text\" name=\"tmp_token\" value=\"".htmlspecialchars ($tmp_token)."\" /></p>\n";
|
||||||
$result .= "</div>\n";
|
$result .= "</div>\n";
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
function step2_do () {
|
function step2_do () {
|
||||||
global $election;
|
global $election;
|
||||||
global $options_nb;
|
global $choices_nb;
|
||||||
global $options;
|
global $choices;
|
||||||
global $vote;
|
global $vote;
|
||||||
global $votes_array;
|
global $votes_array;
|
||||||
|
|
||||||
|
@ -13,35 +13,35 @@ function step2_do () {
|
||||||
$result .= "<p>Possible answers:</p>\n";
|
$result .= "<p>Possible answers:</p>\n";
|
||||||
|
|
||||||
$result .= "<div class=\"votedata\">\n";
|
$result .= "<div class=\"votedata\">\n";
|
||||||
if ($options_nb == 1) {
|
if ($choices_nb == 1) {
|
||||||
$result .= "<p>\n";
|
$result .= "<p>\n";
|
||||||
foreach ($options as $option) {
|
foreach ($choices as $choice) {
|
||||||
$checked = "";
|
$checked = "";
|
||||||
if ($option["id"] == $vote) {
|
if ($choice["id"] == $vote) {
|
||||||
$checked = " checked=\"checked\"";
|
$checked = " checked=\"checked\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
$result .= "<input type=\"radio\" name=\"vote\" value=\"".$option["id"]."\"".$checked."> ".$option["option"]."<br />\n";
|
$result .= "<input type=\"radio\" name=\"vote\" value=\"".$choice["id"]."\"".$checked."> ".$choice["choice"]."<br />\n";
|
||||||
}
|
}
|
||||||
$result .= "</p>\n";
|
$result .= "</p>\n";
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
$result .= "<p>\n";
|
$result .= "<p>\n";
|
||||||
foreach ($options as $option) {
|
foreach ($choices as $choice) {
|
||||||
$checked = "";
|
$checked = "";
|
||||||
if (in_array ($option["id"], $votes_array)) {
|
if (in_array ($choice["id"], $votes_array)) {
|
||||||
$checked = " checked=\"checked\"";
|
$checked = " checked=\"checked\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
$result .= "<input type=\"checkbox\" name=\"vote".$option["id"]."\"".$checked."> ".$option["option"]."<br />\n";
|
$result .= "<input type=\"checkbox\" name=\"vote".$choice["id"]."\"".$checked."> ".$choice["choice"]."<br />\n";
|
||||||
}
|
}
|
||||||
$result .= "</p>\n";
|
$result .= "</p>\n";
|
||||||
|
|
||||||
}
|
}
|
||||||
$result .= "</div>\n";
|
$result .= "</div>\n";
|
||||||
if ($options_nb > 1)
|
if ($choices_nb > 1)
|
||||||
$result .= "<p><em>You can choose up to ".$options_nb." answers.</em></p>\n";
|
$result .= "<p><em>You can choose up to ".$choices_nb." answers.</em></p>\n";
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,30 +2,30 @@
|
||||||
|
|
||||||
function step3_do () {
|
function step3_do () {
|
||||||
global $election;
|
global $election;
|
||||||
global $options_nb;
|
global $choices_nb;
|
||||||
global $options;
|
global $choices;
|
||||||
global $vote;
|
global $vote;
|
||||||
global $votes_array;
|
global $votes_array;
|
||||||
|
|
||||||
$result = "<h2>Step 3/4 - Confirm your vote</h2>\n";
|
$result = "<h2>Step 3/4 - Confirm your vote</h2>\n";
|
||||||
|
|
||||||
$result .= "<p><strong>".$election["question"]."</strong></p>\n";
|
$result .= "<p><strong>".$election["question"]."</strong></p>\n";
|
||||||
if (($options_nb == 1 && $vote < 0) ||
|
if (($choices_nb == 1 && $vote < 0) ||
|
||||||
($options_nb > 1 && count ($votes_array) >= 1)) {
|
($choices_nb > 1 && count ($votes_array) >= 1)) {
|
||||||
$result .= "<p>You choose to vote for:</p>\n";
|
$result .= "<p>You choose to vote for:</p>\n";
|
||||||
|
|
||||||
$result .= "<div class=\"votedata\">\n";
|
$result .= "<div class=\"votedata\">\n";
|
||||||
if ($options_nb == 1) {
|
if ($choices_nb == 1) {
|
||||||
|
|
||||||
$option = null;
|
$choice = null;
|
||||||
foreach ($options as $opt) {
|
foreach ($choices as $opt) {
|
||||||
if ($opt["id"] == $vote) {
|
if ($opt["id"] == $vote) {
|
||||||
$option = $opt;
|
$choice = $opt;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($option != null)
|
if ($choice != null)
|
||||||
$result .= "<p>".$option["option"]."</p>\n";
|
$result .= "<p>".$choice["choice"]."</p>\n";
|
||||||
else {
|
else {
|
||||||
$result .= "<p>Unknown vote: ".$vote."</p>\n";
|
$result .= "<p>Unknown vote: ".$vote."</p>\n";
|
||||||
$error .= "There was an unkown vote: ".$vote."<br />\n";
|
$error .= "There was an unkown vote: ".$vote."<br />\n";
|
||||||
|
@ -36,9 +36,9 @@ function step3_do () {
|
||||||
$result .= "<ul>\n";
|
$result .= "<ul>\n";
|
||||||
foreach ($votes_array as $vote) {
|
foreach ($votes_array as $vote) {
|
||||||
$found = FALSE;
|
$found = FALSE;
|
||||||
foreach ($options as $option) {
|
foreach ($choices as $choice) {
|
||||||
if ($option["id"] == $vote) {
|
if ($choice["id"] == $vote) {
|
||||||
$result .= "<li>".$option["option"]."</li>\n";
|
$result .= "<li>".$choice["choice"]."</li>\n";
|
||||||
$found = TRUE;
|
$found = TRUE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,11 +37,11 @@ function step4_do () {
|
||||||
global $error;
|
global $error;
|
||||||
global $handle;
|
global $handle;
|
||||||
global $election_id;
|
global $election_id;
|
||||||
global $options_nb;
|
global $choices_nb;
|
||||||
global $vote;
|
global $vote;
|
||||||
global $votes_array;
|
global $votes_array;
|
||||||
global $email;
|
global $email;
|
||||||
global $token;
|
global $tmp_token;
|
||||||
|
|
||||||
$result = "";
|
$result = "";
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ function step4_do () {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($options_nb == 1) {
|
if ($choices_nb == 1) {
|
||||||
|
|
||||||
$res = elec_insert_new_vote ($handle, $anon_token_id, $vote);
|
$res = elec_insert_new_vote ($handle, $anon_token_id, $vote);
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ function step4_do () {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$res = elec_sql_remove_token ($handle, $election_id, $email, $token);
|
$res = elec_sql_remove_tmp_token ($handle, $election_id, $email, $tmp_token);
|
||||||
|
|
||||||
if (!$res) {
|
if (!$res) {
|
||||||
elec_sql_rollback ($handle);
|
elec_sql_rollback ($handle);
|
||||||
|
|
|
@ -61,8 +61,8 @@ if ($display) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($display) {
|
if ($display) {
|
||||||
$options = elec_options_get ($handle, $election_id);
|
$choices = elec_choices_get ($handle, $election_id);
|
||||||
if ($options === FALSE) {
|
if ($choices === FALSE) {
|
||||||
$error .= "The ".elec_election_get_type ($election)." is not properly set up.\n";
|
$error .= "The ".elec_election_get_type ($election)." is not properly set up.\n";
|
||||||
$display = FALSE;
|
$display = FALSE;
|
||||||
}
|
}
|
||||||
|
@ -81,26 +81,26 @@ if ($display) {
|
||||||
echo "<div class=\"votedata\">\n";
|
echo "<div class=\"votedata\">\n";
|
||||||
foreach ($results as $result) {
|
foreach ($results as $result) {
|
||||||
$found = FALSE;
|
$found = FALSE;
|
||||||
foreach ($options as $option) {
|
foreach ($choices as $choice) {
|
||||||
if ($option["id"] == $result["option_id"]) {
|
if ($choice["id"] == $result["choice_id"]) {
|
||||||
echo "<em>".$option["option"]."</em> (<strong>".$result["total_option"]."</strong> votes)<br />\n";
|
echo "<em>".$choice["choice"]."</em> (<strong>".$result["total_choice"]."</strong> votes)<br />\n";
|
||||||
$automatic_results[] = $option["option"];
|
$automatic_results[] = $choice["choice"];
|
||||||
$found = TRUE;
|
$found = TRUE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$found) {
|
if (!$found) {
|
||||||
echo "<em>Unknown value (".$result["option_id"].")</em> (<strong>".$result["total_option"]."</strong> votes)<br />\n";
|
echo "<em>Unknown value (".$result["choice_id"].")</em> (<strong>".$result["total_choice"]."</strong> votes)<br />\n";
|
||||||
$automatic_results[] = "Unknown value (".$result["option_id"].")";
|
$automatic_results[] = "Unknown value (".$result["choice_id"].")";
|
||||||
$error .= "There was an unkown vote: ".$result["option_id"]."<br />\n";
|
$error .= "There was an unkown vote: ".$result["choice_id"]."<br />\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
echo "</div>\n";
|
echo "</div>\n";
|
||||||
|
|
||||||
echo "<p>The automatic result of this ".elec_election_get_type ($election)." is thus:</p>\n";
|
echo "<p>The automatic result of this ".elec_election_get_type ($election)." is thus:</p>\n";
|
||||||
echo "<div class=\"votedata\">\n";
|
echo "<div class=\"votedata\">\n";
|
||||||
for ($i = 0; $i < $election["options_nb"]; $i++) {
|
for ($i = 0; $i < $election["choices_nb"]; $i++) {
|
||||||
echo "<em>".$automatic_results[$i]."</em><br />\n";
|
echo "<em>".$automatic_results[$i]."</em><br />\n";
|
||||||
}
|
}
|
||||||
echo "</div>\n";
|
echo "</div>\n";
|
||||||
|
|
|
@ -59,21 +59,21 @@ if ($election_id == -1) {
|
||||||
|
|
||||||
if ($step > 1) {
|
if ($step > 1) {
|
||||||
$email = "";
|
$email = "";
|
||||||
$token = "";
|
$tmp_token = "";
|
||||||
if (isset ($_POST["email"]) && isset ($_POST["token"])) {
|
if (isset ($_POST["email"]) && isset ($_POST["tmp_token"])) {
|
||||||
$email = $_POST["email"];
|
$email = $_POST["email"];
|
||||||
$token = $_POST["token"];
|
$tmp_token = $_POST["tmp_token"];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!elec_verify_email_token ($handle, $election_id, $email, $token)) {
|
if (!elec_verify_email_tmp_token ($handle, $election_id, $email, $tmp_token)) {
|
||||||
$step = 1;
|
$step = 1;
|
||||||
$error .= "The e-mail address and token you gave do not match an existing voter.<br />\n";
|
$error .= "The e-mail address and token you gave do not match an existing voter.<br />\n";
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
$options_nb = $election["options_nb"];
|
$choices_nb = $election["choices_nb"];
|
||||||
$options = elec_options_get ($handle, $election_id);
|
$choices = elec_choices_get ($handle, $election_id);
|
||||||
|
|
||||||
if (!elec_verify_elections ($options_nb, $options)) {
|
if (!elec_verify_elections ($choices_nb, $choices)) {
|
||||||
$error .= "The ".elec_election_get_type ($election)." is not properly set up.\n";
|
$error .= "The ".elec_election_get_type ($election)." is not properly set up.\n";
|
||||||
$step = 0;
|
$step = 0;
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ if (isset ($election) && $election !== FALSE) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($step >= 2) {
|
if ($step >= 2) {
|
||||||
if ($options_nb == 1) {
|
if ($choices_nb == 1) {
|
||||||
$votes_array = array ();
|
$votes_array = array ();
|
||||||
|
|
||||||
if (isset ($_POST["vote"]))
|
if (isset ($_POST["vote"]))
|
||||||
|
@ -96,11 +96,11 @@ if ($step >= 2) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
$votes_array = elec_vote_get_votes_from_post ($options);
|
$votes_array = elec_vote_get_votes_from_post ($choices);
|
||||||
$vote = -1;
|
$vote = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$res = elec_verify_vote_is_valid ($options_nb, $options, $vote, $votes_array);
|
$res = elec_verify_vote_is_valid ($choices_nb, $choices, $vote, $votes_array);
|
||||||
|
|
||||||
if ($res != "") {
|
if ($res != "") {
|
||||||
$error .= "The vote you made is not valid: ".$res."<br />\n";
|
$error .= "The vote you made is not valid: ".$res."<br />\n";
|
||||||
|
@ -150,15 +150,15 @@ echo $result;
|
||||||
if ($step != $max_step && $step >= 1) {
|
if ($step != $max_step && $step >= 1) {
|
||||||
if ($step > 1) {
|
if ($step > 1) {
|
||||||
echo " <input type=\"hidden\" name=\"email\" value=\"".$email."\">\n";
|
echo " <input type=\"hidden\" name=\"email\" value=\"".$email."\">\n";
|
||||||
echo " <input type=\"hidden\" name=\"token\" value=\"".$token."\">\n";
|
echo " <input type=\"hidden\" name=\"tmp_token\" value=\"".$tmp_token."\">\n";
|
||||||
}
|
}
|
||||||
if ($step > 2) {
|
if ($step > 2) {
|
||||||
if ($options_nb == 1)
|
if ($choices_nb == 1)
|
||||||
echo " <input type=\"hidden\" name=\"vote\" value=\"".$vote."\">\n";
|
echo " <input type=\"hidden\" name=\"vote\" value=\"".$vote."\">\n";
|
||||||
else {
|
else {
|
||||||
foreach ($options as $option) {
|
foreach ($choices as $choice) {
|
||||||
$name = "vote".$option["id"];
|
$name = "vote".$choice["id"];
|
||||||
if (in_array ($option["id"], $votes_array))
|
if (in_array ($choice["id"], $votes_array))
|
||||||
$value = "on";
|
$value = "on";
|
||||||
else
|
else
|
||||||
$value = "";
|
$value = "";
|
||||||
|
|
|
@ -53,17 +53,17 @@ if ($display) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($display) {
|
if ($display) {
|
||||||
$options = elec_options_get ($handle, $election_id);
|
$choices = elec_choices_get ($handle, $election_id);
|
||||||
if ($options === FALSE) {
|
if ($choices === FALSE) {
|
||||||
$error .= "The ".elec_election_get_type ($election)." is not properly set up.\n";
|
$error .= "The ".elec_election_get_type ($election)." is not properly set up.\n";
|
||||||
$display = FALSE;
|
$display = FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($display) {
|
if ($display) {
|
||||||
$options_name = array ();
|
$choices_name = array ();
|
||||||
foreach ($options as $option) {
|
foreach ($choices as $choice) {
|
||||||
$options_name[$option["id"]] = $option["option"];
|
$choices_name[$choice["id"]] = $choice["choice"];
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "<p>Please look at the <a href=\"results.php?election_id=".$election_id."\">automatic results</a> to have a summary of the votes.</p>\n";
|
echo "<p>Please look at the <a href=\"results.php?election_id=".$election_id."\">automatic results</a> to have a summary of the votes.</p>\n";
|
||||||
|
@ -90,11 +90,11 @@ if ($display) {
|
||||||
echo "Can not access votes<br />for this anonymous token.";
|
echo "Can not access votes<br />for this anonymous token.";
|
||||||
$error .= "Can not get votes for anonymous token ".$anon_token["anon_token"]."<br />\n";
|
$error .= "Can not get votes for anonymous token ".$anon_token["anon_token"]."<br />\n";
|
||||||
} else if (count ($votes) == 0) {
|
} else if (count ($votes) == 0) {
|
||||||
echo "This member chose to vote for<br />none of the possible options.";
|
echo "This member chose to vote for<br />none of the possible choices.";
|
||||||
} else {
|
} else {
|
||||||
foreach ($votes as $vote) {
|
foreach ($votes as $vote) {
|
||||||
if (array_key_exists ($vote, $options_name))
|
if (array_key_exists ($vote, $choices_name))
|
||||||
echo "<em>".$options_name[$vote]."</em><br />\n";
|
echo "<em>".$choices_name[$vote]."</em><br />\n";
|
||||||
else {
|
else {
|
||||||
echo "<em>Unknown value (".$vote.")</em><br />\n";
|
echo "<em>Unknown value (".$vote.")</em><br />\n";
|
||||||
$error .= "There was an unkown vote for anonymous token ".$anon_token["anon_token"].": ".$vote."<br />\n";
|
$error .= "There was an unkown vote for anonymous token ".$anon_token["anon_token"].": ".$vote."<br />\n";
|
||||||
|
|
Loading…
Reference in a new issue