diff --git a/ChangeLog b/ChangeLog index 8148b2a..2e485c0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2005-10-24 Vincent Untz + + * configure.in: + * foundation.gnome.org/Makefile.am: + * foundation.gnome.org/vote/*: add anonymous voting scripts + 2005-10-20 Vincent Untz * foundation.gnome.org/index.wml: diff --git a/configure.in b/configure.in index 441190e..a6b41b0 100644 --- a/configure.in +++ b/configure.in @@ -37,4 +37,6 @@ foundation.gnome.org/news/Makefile foundation.gnome.org/referenda/Makefile foundation.gnome.org/referenda/2004-10/Makefile foundation.gnome.org/referenda/2005-10/Makefile +foundation.gnome.org/vote/Makefile +foundation.gnome.org/vote/include/Makefile ]) diff --git a/foundation.gnome.org/Makefile.am b/foundation.gnome.org/Makefile.am index 5e30c0b..6af96bd 100644 --- a/foundation.gnome.org/Makefile.am +++ b/foundation.gnome.org/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = about contact elections img legal licensing membership news referenda finance +SUBDIRS = about contact elections img legal licensing membership news referenda finance vote urlpath = diff --git a/foundation.gnome.org/vote/.cvsignore b/foundation.gnome.org/vote/.cvsignore new file mode 100644 index 0000000..2d2f331 --- /dev/null +++ b/foundation.gnome.org/vote/.cvsignore @@ -0,0 +1,6 @@ +index.php +results.php +votes.php +vote.php +Makefile.in +Makefile diff --git a/foundation.gnome.org/vote/Makefile.am b/foundation.gnome.org/vote/Makefile.am new file mode 100644 index 0000000..428ed08 --- /dev/null +++ b/foundation.gnome.org/vote/Makefile.am @@ -0,0 +1,14 @@ +SUBDIRS = include + +urlpath = /vote + +page_SCRIPTS = \ + index.php \ + results.php \ + votes.php \ + vote.php + +page_DATA = \ + vote.css + +include $(top_srcdir)/rules.common diff --git a/foundation.gnome.org/vote/include/.cvsignore b/foundation.gnome.org/vote/include/.cvsignore new file mode 100644 index 0000000..3dda729 --- /dev/null +++ b/foundation.gnome.org/vote/include/.cvsignore @@ -0,0 +1,2 @@ +Makefile.in +Makefile diff --git a/foundation.gnome.org/vote/include/Makefile.am b/foundation.gnome.org/vote/include/Makefile.am new file mode 100644 index 0000000..e2a5bcd --- /dev/null +++ b/foundation.gnome.org/vote/include/Makefile.am @@ -0,0 +1,14 @@ +SUBDIRS = + +urlpath = /vote/include + +page_SCRIPTS = + +page_DATA = \ + election-sql.php \ + step1-login.php \ + step2-choose.php \ + step3-confirm.php \ + step4-commit.php + +include $(top_srcdir)/rules.common diff --git a/foundation.gnome.org/vote/include/election-sql.php b/foundation.gnome.org/vote/include/election-sql.php new file mode 100644 index 0000000..7eaaa53 --- /dev/null +++ b/foundation.gnome.org/vote/include/election-sql.php @@ -0,0 +1,385 @@ += voting_start AND '".$gmdate."' <= voting_end"; + return elec_get_by_date_desc_with_where ($handle, $where); +} + +function elec_get_previous_by_date_desc ($handle) { + $gmdate = gmdate ("Y-m-d H:i:s"); + $where = "WHERE '".$gmdate."' > voting_start AND '".$gmdate."' > voting_end"; + return elec_get_by_date_desc_with_where ($handle, $where); +} + +function elec_verify_email_token ($handle, $election_id, $email, $token) { + global $tokens_table; + global $members_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); + + $query = "SELECT COUNT(*) FROM " . $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.member_id = mt.id"; + $query .= " AND mt.email = '".$escaped_email."'"; + + $result = mysql_query ($query, $handle); + if (!$result) + return FALSE; + + return (mysql_result ($result, 0, 0) == 1); +} + +function elec_options_get ($handle, $election_id) { + global $options_table; + + if ($handle === FALSE) + return FALSE; + + $escaped_election_id = mysql_real_escape_string ($election_id, $handle); + + $query = "SELECT * FROM " . $options_table; + $query .= " WHERE election_id = '".$escaped_election_id."'"; + + $result = mysql_query ($query, $handle); + + if (!$result) { + $retval = FALSE; + } else { + $result_array = array (); + while ($buffer = mysql_fetch_assoc ($result)) { + $result_array[] = $buffer; + } + $retval = $result_array; + } + + return $retval; +} + +function elec_verify_elections ($options_nb, $options) { + if ($options_nb === FALSE || $options === FALSE) + return FALSE; + + if ($options_nb < 1) + return FALSE; + + if (count ($options) < $options_nb || count ($options) <= 1) + return FALSE; + + return TRUE; +} + +function elec_get_election ($handle, $election_id) { + global $elections_table; + + if ($handle === FALSE) + return FALSE; + + $escaped_election_id = mysql_real_escape_string ($election_id, $handle); + + $query = "SELECT * FROM " . $elections_table; + $query .= " WHERE id = '".$escaped_election_id."'"; + + $result = mysql_query ($query, $handle); + + if (!$result) + return FALSE; + + return mysql_fetch_assoc ($result); +} + +function elec_election_is_current ($election) { + $gmdate = gmdate ("Y-m-d H:i:s"); + return ($gmdate >= $election["voting_start"] && $gmdate <= $election["voting_end"]); +} + +function elec_election_has_ended ($election) { + $gmdate = gmdate ("Y-m-d H:i:s"); + return ($gmdate > $election["voting_start"] && $gmdate > $election["voting_end"]); +} + +function elec_election_get_type ($election) { + if ($election["type"] == "1") + return "referendum"; + else + return "election"; +} + +function elec_vote_get_votes_from_post ($options) { + $votes_array = array (); + + foreach ($options as $option) { + $name = "vote".$option["id"]; + if (isset ($_POST[$name]) && $_POST[$name] != "") { + array_push ($votes_array, $option["id"]); + } + } + + return $votes_array; +} + +function elec_verify_vote_is_valid ($options_nb, $options, $vote, $votes_array) { + if ($options_nb == 1) + return ""; + + if (count ($votes_array) > $options_nb) { + return "you chose ".count ($votes_array)." answers, while you can't choose more than ".$options_nb." answers."; + } + + return ""; +} + +function elec_insert_new_anon_token ($handle, $election_id, $anon_token) { + global $anon_tokens_table; + + if ($handle === FALSE) + return FALSE; + + $escaped_election_id = mysql_real_escape_string ($election_id, $handle); + $escaped_anon_token = mysql_real_escape_string ($anon_token, $handle); + + $query = "SELECT COUNT(*) FROM " . $anon_tokens_table; + $query .= " WHERE anon_token = '".$escaped_anon_token."'"; + + $result = mysql_query ($query, $handle); + if (!$result) + return FALSE; + + if (mysql_result ($result, 0, 0) != 0) + return FALSE; + + $query = "INSERT INTO " . $anon_tokens_table . " (anon_token, election_id)"; + $query .= " VALUES ('".$escaped_anon_token."', '".$escaped_election_id."')"; + + $result = mysql_query ($query, $handle); + if (!$result) + return FALSE; + + return mysql_insert_id ($handle); +} + +function elec_insert_new_vote ($handle, $anon_token_id, $vote) { + global $votes_table; + + if ($handle === FALSE) + return FALSE; + + $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 .= " VALUES ('".$escaped_vote."', '".$escaped_anon_token_id."')"; + + $result = mysql_query ($query, $handle); + if (!$result) + return FALSE; + + return TRUE; +} + +function elec_sql_remove_token ($handle, $election_id, $email, $token) { + global $members_table; + global $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); + + $query = "DELETE FROM " . $tokens_table; + $query .= " USING ". $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.member_id = mt.id"; + $query .= " AND mt.email = '".$escaped_email."'"; + + $result = mysql_query ($query, $handle); + if (!$result) + return FALSE; + + return TRUE; +} + +function elec_get_anon_tokens_for_election ($handle, $election_id) { + global $anon_tokens_table; + + if ($handle === FALSE) + return FALSE; + + $escaped_election_id = mysql_real_escape_string ($election_id, $handle); + + $query = "SELECT * FROM " . $anon_tokens_table; + $query .= " WHERE election_id = '".$escaped_election_id."'"; + $query .= " ORDER BY anon_token"; + + $result = mysql_query ($query, $handle); + + if (!$result) { + $retval = FALSE; + } else { + $result_array = array (); + while ($buffer = mysql_fetch_assoc ($result)) { + $result_array[] = $buffer; + } + $retval = $result_array; + } + + return $retval; +} + +function elec_get_results_election ($handle, $election_id) { + global $anon_tokens_table; + global $votes_table; + + if ($handle === FALSE) + return FALSE; + + $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 .= " 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"; + + $result = mysql_query ($query, $handle); + + if (!$result) { + $retval = FALSE; + } else { + $result_array = array (); + while ($buffer = mysql_fetch_assoc ($result)) { + $result_array[] = $buffer; + } + $retval = $result_array; + } + + return $retval; +} + +function elec_get_votes_for_anon_token ($handle, $anon_token_id) { + global $votes_table; + + if ($handle === FALSE) + return FALSE; + + $escaped_anon_token_id = mysql_real_escape_string ($anon_token_id, $handle); + + $query = "SELECT option_id FROM " . $votes_table; + $query .= " WHERE anon_id = '".$escaped_anon_token_id."'"; + $query .= " ORDER BY option_id"; + + $result = mysql_query ($query, $handle); + + if (!$result) { + $retval = FALSE; + } else { + $result_array = array (); + while ($buffer = mysql_fetch_assoc ($result)) { + $result_array[] = $buffer["option_id"]; + } + $retval = $result_array; + } + + return $retval; +} + +?> diff --git a/foundation.gnome.org/vote/include/step1-login.php b/foundation.gnome.org/vote/include/step1-login.php new file mode 100644 index 0000000..82c629f --- /dev/null +++ b/foundation.gnome.org/vote/include/step1-login.php @@ -0,0 +1,19 @@ +Step 1/4 - Login\n"; + + $result .= "

Please login using the informations that was sent to you in a ballot by e-mail.

\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 new file mode 100644 index 0000000..5603b27 --- /dev/null +++ b/foundation.gnome.org/vote/include/step2-choose.php @@ -0,0 +1,49 @@ +Step 2/4 - Choose your vote\n"; + + $result .= "

".$election["question"]."

\n"; + $result .= "

Possible answers:

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

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

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

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

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

You can choose up to ".$options_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 new file mode 100644 index 0000000..f8af55e --- /dev/null +++ b/foundation.gnome.org/vote/include/step3-confirm.php @@ -0,0 +1,68 @@ +Step 3/4 - Confirm your vote\n"; + + $result .= "

".$election["question"]."

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

You choose to vote for:

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

".$option["option"]."

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

Unknown vote: ".$vote."

\n"; + $error .= "There was an unkown vote: ".$vote."
\n"; + } + + } else { + + $result .= "
    \n"; + foreach ($votes_array as $vote) { + $found = FALSE; + foreach ($options as $option) { + if ($option["id"] == $vote) { + $result .= "
  • ".$option["option"]."
  • \n"; + $found = TRUE; + break; + } + } + + if (!$found) { + $result .= "
  • Unknown vote: ".$vote."
  • \n"; + $error .= "There was an unkown vote: ".$vote."
    \n"; + } + } + $result .= "
\n"; + + } + $result .= "
\n"; + + } else { + $result .= "
\n"; + $result .= "

You choose to vote for none of the possible answers.

\n"; + $result .= "
\n"; + } + + $result .= "

To confirm this vote, please continue to the next step.

\n"; + + return $result; +} + +?> diff --git a/foundation.gnome.org/vote/include/step4-commit.php b/foundation.gnome.org/vote/include/step4-commit.php new file mode 100644 index 0000000..51101ed --- /dev/null +++ b/foundation.gnome.org/vote/include/step4-commit.php @@ -0,0 +1,114 @@ +=10) && ($nextChar < 36)){ // uppercase letters + $nextChar -= 10; // bases the number at 0 instead of 10 + $nextChar = chr($nextChar + 65); // ord('A') == 65 + } else if($nextChar >= 36){ // lowercase letters + $nextChar -= 36; // bases the number at 0 instead of 36 + $nextChar = chr($nextChar + 97); // ord('a') == 97 + } else { // 0-9 + $nextChar = chr($nextChar + 48); // ord('0') == 48 + } + $retVal .= $nextChar; + } + return $retVal; +} + +function step4_do () { + global $error; + global $handle; + global $election_id; + global $options_nb; + global $vote; + global $votes_array; + global $email; + global $token; + + $result = ""; + + $res = elec_sql_start_transaction ($handle); + if (!$res) { + $error .= "Can not start a SQL transaction for the vote.
\n"; + return $result; + } + + $i = 0; + do { + $anon_token = randomCode (32); + $anon_token_id = elec_insert_new_anon_token ($handle, $election_id, $anon_token); + $i++; + } while ($anon_token_id === FALSE && $i < 10); + + if ($anon_token_id === FALSE) { + elec_sql_rollback ($handle); + $error .= "Can not create an anonymous token.
\n"; + return $result; + } + + if ($options_nb == 1) { + + $res = elec_insert_new_vote ($handle, $anon_token_id, $vote); + + if (!$res) { + elec_sql_rollback ($handle); + $error .= "Can not insert a vote.
\n"; + return $result; + } + + } else { + + foreach ($votes_array as $vote) { + $res = elec_insert_new_vote ($handle, $anon_token_id, $vote); + + if (!$res) { + elec_sql_rollback ($handle); + $error .= "Can not insert a vote.
\n"; + return $result; + } + } + + } + + $res = elec_sql_remove_token ($handle, $election_id, $email, $token); + + if (!$res) { + elec_sql_rollback ($handle); + $error .= "Can not remove temporary token.
\n"; + return $result; + } + + $res = elec_sql_commit ($handle); + if (!$res) { + $error .= "Can not commit the vote.
\n"; + return $result; + } + + $result .= "

Step 4/4 - Keep your anonymous token

\n"; + $result .= "

Your vote has been received.

\n"; + $result .= "

Please write this anonymous token somewhere:

\n"; + $result .= "

".$anon_token."

\n"; + $result .= "

This anonymous token will enable you to verify your vote when the preliminary results will be published. Nobody, even the Membership and Elections Committee, except you knows that this token is associated with you and only you will be able to verify your vote. It is not possible to request this anonymous token later.

\n"; + + return $result; +} + +?> diff --git a/foundation.gnome.org/vote/index.wml b/foundation.gnome.org/vote/index.wml new file mode 100644 index 0000000..128067e --- /dev/null +++ b/foundation.gnome.org/vote/index.wml @@ -0,0 +1,66 @@ + + + + + + + The GNOME Foundation - Votes + + + + + + +

GNOME Foundation Voting System

+ +

Welcome to the anonymous voting system of the GNOME Foundation. This system is maintained by the Membership and Elections Committee, which can be reached at elections@gnome.org.

+ + +Can not open the database.\n"; + $current_elections = array (); + $previous_elections = array (); +} else { + $current_elections = elec_get_current_by_date_desc ($handle); + $previous_elections = elec_get_previous_by_date_desc ($handle); + elec_sql_close ($handle); +} + +if (count ($current_elections) > 0) { +?> + +

Current elections & referenda

+ +

Please click on one of the following links in order to vote for the corresponding election or referendum.

+ + + 0) { +?> + +

Archives of previous elections & referenda

+ +

Please click on one of the following links in order to see the results for the corresponding election or referendum.

+ + + diff --git a/foundation.gnome.org/vote/results.wml b/foundation.gnome.org/vote/results.wml new file mode 100644 index 0000000..c341e4d --- /dev/null +++ b/foundation.gnome.org/vote/results.wml @@ -0,0 +1,119 @@ + + + + + + + The GNOME Foundation - Votes + + + + +\n"; + $display = FALSE; +} + +if ($display && isset ($_GET["election_id"]) && is_numeric ($_GET["election_id"])) + $election_id = $_GET["election_id"]; +else { + $election_id = -1; + $error .= "Please choose an election/referendum on this list.
\n"; + $display = FALSE; +} + +if ($display && $election_id >= 0) { + $election = elec_get_election ($handle, $election_id); + if ($election === FALSE) { + $error .= "The specified election/referendum does not exist.
\n"; + $display = FALSE; + } else if (!elec_election_has_ended ($election)) { + $error .= "The voting period for the specified ".elec_election_get_type ($election)." starts on ".$election["voting_start"]." (UTC) and ends on ".$election["voting_end"]." (UTC). It is not possible to see the results now.
\n"; + $display = FALSE; + } +} + +if (isset ($election) && $election !== FALSE) { + echo "

Results for the ".$election["name"]."

\n"; +} + +if ($display) { + $anon_tokens = elec_get_anon_tokens_for_election ($handle, $election_id); + if ($anon_tokens === FALSE) { + $error .= "Can not get the anonymous tokens for this ".elec_election_get_type ($election).".\n"; + $display = FALSE; + } +} + +if ($display) { + $results = elec_get_results_election ($handle, $election_id); + if ($results === FALSE) { + $error .= "Can not get the results for this ".elec_election_get_type ($election).".\n"; + $display = FALSE; + } +} + +if ($display) { + $options = elec_options_get ($handle, $election_id); + if ($options === FALSE) { + $error .= "The ".elec_election_get_type ($election)." is not properly set up.\n"; + $display = FALSE; + } +} + +if ($display) { + $nb_voters = count ($anon_tokens); + + $automatic_results = array (); + + echo "

Please note that these results are automatically calculated and are thus not the official results.

\n"; + + echo "

".$election["question"]."

"; + echo "

".$nb_voters." members voted for this ".elec_election_get_type ($election).". The repartition of the votes is:

\n"; + + 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"]; + $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 "
\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++) { + echo "".$automatic_results[$i]."
\n"; + } + echo "
\n"; + + echo "

Please look at the list of all votes and verify that your vote is correct.

\n"; +} + +if (isset ($error) && $error != "") { + echo "
".$error."
\n";; + echo "

If you don't understand the error, you should probably contact the Membership and Elections Committee, which can be reached at elections@gnome.org.

\n"; +} + +if (isset ($handle)) + elec_sql_close ($handle); + +?> diff --git a/foundation.gnome.org/vote/vote.css b/foundation.gnome.org/vote/vote.css new file mode 100644 index 0000000..96a053e --- /dev/null +++ b/foundation.gnome.org/vote/vote.css @@ -0,0 +1,54 @@ +div.error { + font-style: italic; + font-weight: bold; + color: red; +} + +div.votedata { + margin-left: 2em; +} + +label { + font-weight: bold; + font-size: 0.85em; +} + +input[type=text] { + border-color: #ccc; + border-style: solid; + border-width: 1px; + background-color: #eee; + margin: 0.1em 0 0.1em 0; + padding-left: 0.2em; + padding-right: 0.2em; + font-size : 1em; +} + +table.detailedvotes { + margin-left:auto; + margin-right:auto; + border-collapse: collapse; +} + +table.detailedvotes th, table.detailedvotes td { + border: 1px solid #333; + padding: 0.1em 0.5em 0.1em 0.5em; + vertical-align: top; +} + +table.detailedvotes th { + text-align: center; + background-color: #222; + color: #fff; + font-weight: bold; +} + +table.detailedvotes tr.colorA { + background-color: #eee; + color: #000; +} + +table.detailedvotes tr.colorB { + background-color: #888; + color: #fff; +} diff --git a/foundation.gnome.org/vote/vote.wml b/foundation.gnome.org/vote/vote.wml new file mode 100644 index 0000000..bb7085c --- /dev/null +++ b/foundation.gnome.org/vote/vote.wml @@ -0,0 +1,175 @@ + + + + + + + The GNOME Foundation - Votes + + + + + $max_step || $step < 1) { + $step = 1; +} + +$result = ""; +$error = ""; + +$handle = elec_sql_open (); +if ($handle === FALSE) { + $error .= "Can not open the database.
\n"; + $step = 0; +} + +$election_id = -1; +if ($step == 1) { + if (isset ($_GET["election_id"]) && is_numeric ($_GET["election_id"])) + $election_id = $_GET["election_id"]; +} else if ($step >= 1) { + if (isset ($_POST["election_id"]) && is_numeric ($_POST["election_id"])) + $election_id = $_POST["election_id"]; +} + +if ($election_id == -1) { + $error .= "Please choose an election/referendum on this list.
\n"; + $step = 0; +} else { + $election = elec_get_election ($handle, $election_id); + if ($election === FALSE) { + $error .= "The specified election/referendum does not exist.
\n"; + $step = 0; + } else if (!elec_election_is_current ($election)) { + $error .= "The voting period for the specified ".elec_election_get_type ($election)." starts on ".$election["voting_start"]." (UTC) and ends on ".$election["voting_end"]." (UTC). It is not possible to vote now.
\n"; + $step = 0; + } +} + + +if ($step > 1) { + $email = ""; + $token = ""; + if (isset ($_POST["email"]) && isset ($_POST["token"])) { + $email = $_POST["email"]; + $token = $_POST["token"]; + } + + if (!elec_verify_email_token ($handle, $election_id, $email, $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); + + if (!elec_verify_elections ($options_nb, $options)) { + $error .= "The ".elec_election_get_type ($election)." is not properly set up.\n"; + $step = 0; + } + + } +} + +if (isset ($election) && $election !== FALSE) { + echo "

".$election["name"]."

\n"; +} + +if ($step >= 2) { + if ($options_nb == 1) { + $votes_array = array (); + + if (isset ($_POST["vote"])) + $vote = $_POST["vote"]; + else + $vote = -1; + + } else { + + $votes_array = elec_vote_get_votes_from_post ($options); + $vote = -1; + } + + $res = elec_verify_vote_is_valid ($options_nb, $options, $vote, $votes_array); + + if ($res != "") { + $error .= "The vote you made is not valid: ".$res."
\n"; + $step = 2; + } +} + +if ($step == 4) { + /* vote has been confirmed */ + require ("include/step4-commit.php"); + + $result = step4_do (); +} else if ($step == 3) { + /* confirm vote */ + require ("include/step3-confirm.php"); + + $result = step3_do (); +} else if ($step == 2) { + /* choose vote */ + require ("include/step2-choose.php"); + + $result = step2_do (); +} else if ($step == 1) { + /* login */ + require ("include/step1-login.php"); + + $result = step1_do (); +} else { + if (!isset ($error) || $error == "") + $error = "Unknown error.
\n"; +} + +if (isset ($handle)) + elec_sql_close ($handle); + +if (isset ($error) && $error != "") { + echo "
".$error."
\n";; + echo "

If you don't understand the error, you should probably contact the Membership and Elections Committee, which can be reached at elections@gnome.org.

\n"; +} + +if ($step != $max_step && $step >= 1) { + echo "
\n"; +} + +echo $result; + +if ($step != $max_step && $step >= 1) { + if ($step > 1) { + echo " \n"; + echo " \n"; + } + if ($step > 2) { + if ($options_nb == 1) + echo " \n"; + else { + foreach ($options as $option) { + $name = "vote".$option["id"]; + if (in_array ($option["id"], $votes_array)) + $value = "on"; + else + $value = ""; + + echo " \n"; + } + } + } + echo " \n"; + echo " \n"; + echo " \n"; + echo "
\n"; +} +?> diff --git a/foundation.gnome.org/vote/votes.wml b/foundation.gnome.org/vote/votes.wml new file mode 100644 index 0000000..8e2a736 --- /dev/null +++ b/foundation.gnome.org/vote/votes.wml @@ -0,0 +1,121 @@ + + + + + + + The GNOME Foundation - Votes + + + + +\n"; + $display = FALSE; +} + +if ($display && isset ($_GET["election_id"]) && is_numeric ($_GET["election_id"])) + $election_id = $_GET["election_id"]; +else { + $election_id = -1; + $error .= "Please choose an election/referendum on this list.
\n"; + $display = FALSE; +} + +if ($display && $election_id >= 0) { + $election = elec_get_election ($handle, $election_id); + if ($election === FALSE) { + $error .= "The specified election/referendum does not exist.
\n"; + $display = FALSE; + } else if (!elec_election_has_ended ($election)) { + $error .= "The voting period for the specified ".elec_election_get_type ($election)." starts on ".$election["voting_start"]." (UTC) and ends on ".$election["voting_end"]." (UTC). It is not possible to see the results now.
\n"; + $display = FALSE; + } +} + +if (isset ($election) && $election !== FALSE) { + echo "

Detailed votes for the ".$election["name"]."

\n"; +} + +if ($display) { + $anon_tokens = elec_get_anon_tokens_for_election ($handle, $election_id); + if ($anon_tokens === FALSE) { + $error .= "Can not get the anonymous tokens for this ".elec_election_get_type ($election).".\n"; + $display = FALSE; + } +} + +if ($display) { + $options = elec_options_get ($handle, $election_id); + if ($options === 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"]; + } + + echo "

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

\n"; + + echo "

Please note that these results are automatically calculated and are thus not the official results.

\n"; + + echo "

".$election["question"]."

\n"; + + echo "\n\n"; + $color = TRUE; + foreach ($anon_tokens as $anon_token) { + $votes = elec_get_votes_for_anon_token ($handle, $anon_token["id"]); + if ($color) + $class = "colorA"; + else + $class = "colorB"; + + echo "\n"; + echo "\n"; + + echo "\n"; + + echo "\n"; + $color = !$color; + } + echo "
Anonymous tokenVote(s)
".$anon_token["anon_token"].""; + + if ($votes === FALSE) { + 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."; + } else { + foreach ($votes as $vote) { + if (array_key_exists ($vote, $options_name)) + echo "".$options_name[$vote]."
\n"; + else { + echo "Unknown value (".$vote.")
\n"; + $error .= "There was an unkown vote for anonymous token ".$anon_token["anon_token"].": ".$vote."
\n"; + } + } + } + + echo "
\n"; +} + +if (isset ($error) && $error != "") { + echo "
".$error."
\n";; + echo "

If you don't understand the error, you should probably contact the Membership and Elections Committee, which can be reached at elections@gnome.org.

\n"; +} + +if (isset ($handle)) + elec_sql_close ($handle); + +?>