From 6810d2ffbdc54c7cdd59dc0add65ed25977489d6 Mon Sep 17 00:00:00 2001 From: Vincent Untz Date: Mon, 24 Oct 2005 18:25:43 +0000 Subject: [PATCH] s/option/choice/, also rename the variable for the temporary token to 2005-10-24 Vincent Untz * 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 --- ChangeLog | 7 ++ .../vote/include/election-sql.php | 114 ++++++++++-------- .../vote/include/step1-login.php | 4 +- .../vote/include/step2-choose.php | 22 ++-- .../vote/include/step3-confirm.php | 26 ++-- .../vote/include/step4-commit.php | 8 +- foundation.gnome.org/vote/results.wml | 20 +-- foundation.gnome.org/vote/vote.wml | 30 ++--- foundation.gnome.org/vote/votes.wml | 16 +-- 9 files changed, 137 insertions(+), 110 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2e485c0..a4edda9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2005-10-24 Vincent Untz + + * 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 * configure.in: diff --git a/foundation.gnome.org/vote/include/election-sql.php b/foundation.gnome.org/vote/include/election-sql.php index 7eaaa53..0f17210 100644 --- a/foundation.gnome.org/vote/include/election-sql.php +++ b/foundation.gnome.org/vote/include/election-sql.php @@ -1,13 +1,33 @@ $options_nb) { - return "you chose ".count ($votes_array)." answers, while you can't choose more than ".$options_nb." answers."; + if (count ($votes_array) > $choices_nb) { + return "you chose ".count ($votes_array)." answers, while you can't choose more than ".$choices_nb." answers."; } return ""; @@ -263,7 +283,7 @@ function elec_insert_new_vote ($handle, $anon_token_id, $vote) { $escaped_vote = mysql_real_escape_string ($vote, $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."')"; $result = mysql_query ($query, $handle); @@ -273,21 +293,21 @@ function elec_insert_new_vote ($handle, $anon_token_id, $vote) { 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 $tokens_table; + global $tmp_tokens_table; if ($handle === FALSE) return FALSE; $escaped_election_id = mysql_real_escape_string ($election_id, $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 .= " USING ". $tokens_table . " AS tt, " . $members_table . " AS mt"; + $query = "DELETE FROM " . $tmp_tokens_table; + $query .= " USING ". $tmp_tokens_table . " AS tt, " . $members_table . " AS mt"; $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 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); - $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 .= " AND att.id = vt.anon_id"; - $query .= " GROUP BY option_id"; - $query .= " ORDER BY total_option DESC"; + $query .= " GROUP BY choice_id"; + $query .= " ORDER BY total_choice DESC"; $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); - $query = "SELECT option_id FROM " . $votes_table; + $query = "SELECT choice_id FROM " . $votes_table; $query .= " WHERE anon_id = '".$escaped_anon_token_id."'"; - $query .= " ORDER BY option_id"; + $query .= " ORDER BY choice_id"; $result = mysql_query ($query, $handle); @@ -374,7 +394,7 @@ function elec_get_votes_for_anon_token ($handle, $anon_token_id) { } else { $result_array = array (); while ($buffer = mysql_fetch_assoc ($result)) { - $result_array[] = $buffer["option_id"]; + $result_array[] = $buffer["choice_id"]; } $retval = $result_array; } diff --git a/foundation.gnome.org/vote/include/step1-login.php b/foundation.gnome.org/vote/include/step1-login.php index 82c629f..fd5bc2b 100644 --- a/foundation.gnome.org/vote/include/step1-login.php +++ b/foundation.gnome.org/vote/include/step1-login.php @@ -2,7 +2,7 @@ function step1_do () { global $email; - global $token; + global $tmp_token; $result = "

Step 1/4 - Login

\n"; @@ -10,7 +10,7 @@ function step1_do () { $result .= "
\n"; $result .= "

\n"; - $result .= "

\n"; + $result .= "

\n"; $result .= "
\n"; return $result; diff --git a/foundation.gnome.org/vote/include/step2-choose.php b/foundation.gnome.org/vote/include/step2-choose.php index 5603b27..428317b 100644 --- a/foundation.gnome.org/vote/include/step2-choose.php +++ b/foundation.gnome.org/vote/include/step2-choose.php @@ -2,8 +2,8 @@ function step2_do () { global $election; - global $options_nb; - global $options; + global $choices_nb; + global $choices; global $vote; global $votes_array; @@ -13,35 +13,35 @@ function step2_do () { $result .= "

Possible answers:

\n"; $result .= "
\n"; - if ($options_nb == 1) { + if ($choices_nb == 1) { $result .= "

\n"; - foreach ($options as $option) { + foreach ($choices as $choice) { $checked = ""; - if ($option["id"] == $vote) { + if ($choice["id"] == $vote) { $checked = " checked=\"checked\""; } - $result .= " ".$option["option"]."
\n"; + $result .= " ".$choice["choice"]."
\n"; } $result .= "

\n"; } else { $result .= "

\n"; - foreach ($options as $option) { + foreach ($choices as $choice) { $checked = ""; - if (in_array ($option["id"], $votes_array)) { + if (in_array ($choice["id"], $votes_array)) { $checked = " checked=\"checked\""; } - $result .= " ".$option["option"]."
\n"; + $result .= " ".$choice["choice"]."
\n"; } $result .= "

\n"; } $result .= "
\n"; - if ($options_nb > 1) - $result .= "

You can choose up to ".$options_nb." answers.

\n"; + if ($choices_nb > 1) + $result .= "

You can choose up to ".$choices_nb." answers.

\n"; return $result; } diff --git a/foundation.gnome.org/vote/include/step3-confirm.php b/foundation.gnome.org/vote/include/step3-confirm.php index f8af55e..fa95206 100644 --- a/foundation.gnome.org/vote/include/step3-confirm.php +++ b/foundation.gnome.org/vote/include/step3-confirm.php @@ -2,30 +2,30 @@ function step3_do () { global $election; - global $options_nb; - global $options; + global $choices_nb; + global $choices; global $vote; global $votes_array; $result = "

Step 3/4 - Confirm your vote

\n"; $result .= "

".$election["question"]."

\n"; - if (($options_nb == 1 && $vote < 0) || - ($options_nb > 1 && count ($votes_array) >= 1)) { + if (($choices_nb == 1 && $vote < 0) || + ($choices_nb > 1 && count ($votes_array) >= 1)) { $result .= "

You choose to vote for:

\n"; $result .= "
\n"; - if ($options_nb == 1) { + if ($choices_nb == 1) { - $option = null; - foreach ($options as $opt) { + $choice = null; + foreach ($choices as $opt) { if ($opt["id"] == $vote) { - $option = $opt; + $choice = $opt; break; } } - if ($option != null) - $result .= "

".$option["option"]."

\n"; + if ($choice != null) + $result .= "

".$choice["choice"]."

\n"; else { $result .= "

Unknown vote: ".$vote."

\n"; $error .= "There was an unkown vote: ".$vote."
\n"; @@ -36,9 +36,9 @@ function step3_do () { $result .= "
    \n"; foreach ($votes_array as $vote) { $found = FALSE; - foreach ($options as $option) { - if ($option["id"] == $vote) { - $result .= "
  • ".$option["option"]."
  • \n"; + foreach ($choices as $choice) { + if ($choice["id"] == $vote) { + $result .= "
  • ".$choice["choice"]."
  • \n"; $found = TRUE; break; } diff --git a/foundation.gnome.org/vote/include/step4-commit.php b/foundation.gnome.org/vote/include/step4-commit.php index 51101ed..e7f12fa 100644 --- a/foundation.gnome.org/vote/include/step4-commit.php +++ b/foundation.gnome.org/vote/include/step4-commit.php @@ -37,11 +37,11 @@ function step4_do () { global $error; global $handle; global $election_id; - global $options_nb; + global $choices_nb; global $vote; global $votes_array; global $email; - global $token; + global $tmp_token; $result = ""; @@ -64,7 +64,7 @@ function step4_do () { return $result; } - if ($options_nb == 1) { + if ($choices_nb == 1) { $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) { elec_sql_rollback ($handle); diff --git a/foundation.gnome.org/vote/results.wml b/foundation.gnome.org/vote/results.wml index c341e4d..58ad80a 100644 --- a/foundation.gnome.org/vote/results.wml +++ b/foundation.gnome.org/vote/results.wml @@ -61,8 +61,8 @@ if ($display) { } if ($display) { - $options = elec_options_get ($handle, $election_id); - if ($options === FALSE) { + $choices = elec_choices_get ($handle, $election_id); + if ($choices === FALSE) { $error .= "The ".elec_election_get_type ($election)." is not properly set up.\n"; $display = FALSE; } @@ -81,26 +81,26 @@ if ($display) { echo "
    \n"; foreach ($results as $result) { $found = FALSE; - foreach ($options as $option) { - if ($option["id"] == $result["option_id"]) { - echo "".$option["option"]." (".$result["total_option"]." votes)
    \n"; - $automatic_results[] = $option["option"]; + foreach ($choices as $choice) { + if ($choice["id"] == $result["choice_id"]) { + echo "".$choice["choice"]." (".$result["total_choice"]." votes)
    \n"; + $automatic_results[] = $choice["choice"]; $found = TRUE; break; } } if (!$found) { - echo "Unknown value (".$result["option_id"].") (".$result["total_option"]." votes)
    \n"; - $automatic_results[] = "Unknown value (".$result["option_id"].")"; - $error .= "There was an unkown vote: ".$result["option_id"]."
    \n"; + echo "Unknown value (".$result["choice_id"].") (".$result["total_choice"]." votes)
    \n"; + $automatic_results[] = "Unknown value (".$result["choice_id"].")"; + $error .= "There was an unkown vote: ".$result["choice_id"]."
    \n"; } } echo "
    \n"; echo "

    The automatic result of this ".elec_election_get_type ($election)." is thus:

    \n"; echo "
    \n"; - for ($i = 0; $i < $election["options_nb"]; $i++) { + for ($i = 0; $i < $election["choices_nb"]; $i++) { echo "".$automatic_results[$i]."
    \n"; } echo "
    \n"; diff --git a/foundation.gnome.org/vote/vote.wml b/foundation.gnome.org/vote/vote.wml index bb7085c..53e8c6e 100644 --- a/foundation.gnome.org/vote/vote.wml +++ b/foundation.gnome.org/vote/vote.wml @@ -59,21 +59,21 @@ if ($election_id == -1) { if ($step > 1) { $email = ""; - $token = ""; - if (isset ($_POST["email"]) && isset ($_POST["token"])) { + $tmp_token = ""; + if (isset ($_POST["email"]) && isset ($_POST["tmp_token"])) { $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; $error .= "The e-mail address and token you gave do not match an existing voter.
    \n"; } else { - $options_nb = $election["options_nb"]; - $options = elec_options_get ($handle, $election_id); + $choices_nb = $election["choices_nb"]; + $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"; $step = 0; } @@ -86,7 +86,7 @@ if (isset ($election) && $election !== FALSE) { } if ($step >= 2) { - if ($options_nb == 1) { + if ($choices_nb == 1) { $votes_array = array (); if (isset ($_POST["vote"])) @@ -96,11 +96,11 @@ if ($step >= 2) { } else { - $votes_array = elec_vote_get_votes_from_post ($options); + $votes_array = elec_vote_get_votes_from_post ($choices); $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 != "") { $error .= "The vote you made is not valid: ".$res."
    \n"; @@ -150,15 +150,15 @@ echo $result; if ($step != $max_step && $step >= 1) { if ($step > 1) { echo " \n"; - echo " \n"; + echo " \n"; } if ($step > 2) { - if ($options_nb == 1) + if ($choices_nb == 1) echo " \n"; else { - foreach ($options as $option) { - $name = "vote".$option["id"]; - if (in_array ($option["id"], $votes_array)) + foreach ($choices as $choice) { + $name = "vote".$choice["id"]; + if (in_array ($choice["id"], $votes_array)) $value = "on"; else $value = ""; diff --git a/foundation.gnome.org/vote/votes.wml b/foundation.gnome.org/vote/votes.wml index 8e2a736..df18620 100644 --- a/foundation.gnome.org/vote/votes.wml +++ b/foundation.gnome.org/vote/votes.wml @@ -53,17 +53,17 @@ if ($display) { } if ($display) { - $options = elec_options_get ($handle, $election_id); - if ($options === FALSE) { + $choices = elec_choices_get ($handle, $election_id); + if ($choices === FALSE) { $error .= "The ".elec_election_get_type ($election)." is not properly set up.\n"; $display = FALSE; } } if ($display) { - $options_name = array (); - foreach ($options as $option) { - $options_name[$option["id"]] = $option["option"]; + $choices_name = array (); + foreach ($choices as $choice) { + $choices_name[$choice["id"]] = $choice["choice"]; } echo "

    Please look at the automatic results to have a summary of the votes.

    \n"; @@ -90,11 +90,11 @@ if ($display) { echo "Can not access votes
    for this anonymous token."; $error .= "Can not get votes for anonymous token ".$anon_token["anon_token"]."
    \n"; } else if (count ($votes) == 0) { - echo "This member chose to vote for
    none of the possible options."; + echo "This member chose to vote for
    none of the possible choices."; } else { foreach ($votes as $vote) { - if (array_key_exists ($vote, $options_name)) - echo "".$options_name[$vote]."
    \n"; + if (array_key_exists ($vote, $choices_name)) + echo "".$choices_name[$vote]."
    \n"; else { echo "Unknown value (".$vote.")
    \n"; $error .= "There was an unkown vote for anonymous token ".$anon_token["anon_token"].": ".$vote."
    \n";