diff --git a/foundation.gnome.org/vote/blt.wml b/foundation.gnome.org/vote/blt.wml new file mode 100644 index 0000000..a5108e6 --- /dev/null +++ b/foundation.gnome.org/vote/blt.wml @@ -0,0 +1,134 @@ += 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; + } +} + +/* Get election, choices, anon tokens & votes */ +if ($display) { + $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 (isset ($election) && $election !== FALSE) { + // Header: # candidates, # seats + echo count($choices)." ".$election["choices_nb"]."\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) { + $choices_name = array (); + $choices_pos = array (); + $index=1; + // Record names and positions of candidates + foreach ($choices as $choice) { + $choices_pos[$choice["id"]] = $index++; + } + + // One line per ballot: weight, preferences, 0 to end. + foreach ($anon_tokens as $anon_token) { + $votes = elec_get_votes_for_anon_token ($handle, $anon_token["id"]); + if ($votes === FALSE) { + echo "1 999 0\n"; + $error .= "Can not get votes for anonymous token ".$anon_token["anon_token"]."\n"; + } else if (count ($votes) == 0) { + echo "1 0\n"; + } else { + echo "1 "; + foreach ($votes as $vote) { + if (array_key_exists ($vote["choice_id"], $choices_pos)) + echo $choices_pos[$vote["choice_id"]]." "; + else { + echo "999 "; + $error .= "There was an unkown vote for anonymous token ".$anon_token["anon_token"].": ".$vote["choice_id"]."\n"; + } + } + echo "0\n"; + } + } + + // end of ballots marker + echo "0\n"; + + // Names of candidates + foreach ($choices as $choice) { + echo "\"".$choice["choice"]."\"\n"; + } + + // Title of election + echo "\"".$election["name"]."\"\n"; + +} + +if (isset ($error) && $error != "") { + echo "".$error."\n"; + echo "If you don't understand the error, you should probably contact the Maemo Community mailing list, which can be reached at maemo-community@maemo.org.\n"; +} + +if (isset ($handle)) + elec_sql_close ($handle); + +?>