$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 = "";
$tmp_token = "";
if (isset ($_POST["email"]) && isset ($_POST["tmp_token"])) {
$email = $_POST["email"];
$tmp_token = $_POST["tmp_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 {
$choices_nb = $election["choices_nb"];
$choices = elec_choices_get ($handle, $election_id);
if (!elec_verify_elections ($choices_nb, $choices)) {
$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 ($choices_nb == 1) {
$votes_array = array ();
if (isset ($_POST["vote"]))
$vote = $_POST["vote"];
else
$vote = -1;
} else {
$votes_array = elec_vote_get_votes_from_post ($choices);
$vote = -1;
}
$res = elec_verify_vote_is_valid ($choices_nb, $choices, $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";
}
?>