Array( 1 => "banana", 2 => "pineapple", 3 => "orange", 4 => "mango"), "Berries" => Array( 5 => "strawberry", 6 => "blueberry", 7 => "blackberry", 8 => "lingonberry"), "Classics" => Array( 9 => "vanilla", 10 => "chocolate chips", 11 => "toffe"), "Specials" => Array( 12 => "tofu based", 13 => "liqorice", 14 => "green tea", 15 => "garlic"), 16 => "Grandma's home made" ); $js_voter = new Js_Pref_Voter( $ice_creams ); // Parse votes if submitted $votelist = array(); if ( isset($_REQUEST["vote"])) $votelist = $js_voter->Parse_Vote_String($_REQUEST["vote"]); // Pre-fill the form with submitted votes, if given $pre_fill = array(); if ( count($votelist) > 0) foreach ( $votelist as $pos => $cands ) $pre_fill[$pos-1] = $cands; $js_voter->Print_Ballot_Filler_Head( $pre_fill ) ?>

js-pref-voter

A preferential ballot filling UI in Javascript and PHP.
Copyright (C) 2004, 2005 by Jarno Elonen <elonen@iki.fi>

Upd. 2005-03-30: cleaned up the code, made it a class and added a very useful function: Expand_Parties().

This is a preferential ballot filling user interface, mainly useful for Condorset methods, written in Javascript and server-side PHP. It was originally developed for the LFW project and is unfortunately not very well documented. The filler is designed for large elections -- for smaller ones, say, max. 5 candidates, it is definitely an overkill.

Warnings:

License:

'js-pref-voter' - Preferential ballot filler UI in Javascript and accompanying PHP functions

Copyright (c) 2004,2005 Jarno Elonen <elonen@iki.fi>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

0) { $expanded = $js_voter->Expand_Parties( $votelist ); $n_votes = count($expanded); $i = 0; print '

You voted thusly:

'; print ''; foreach( $expanded as $k => $v ) { print '' . ''; } print '
' . htmlentities($k) . '. '; $j=0; foreach( $v as $cand ) { if ( $j++ > 0 ) print "
"; print htmlentities( $js_voter->options[$cand] ); } print '

'; } ?>

Demonstration:

Print_Ballot_Filler_Table(); ?>

Want to restart? Clear the form.