[foundation-web] Porting the maemo changes



commit 78387ca5e50f0be3b4ac095695a2b3f0edbbb1f7
Author: Tobias Mueller <tobiasmue gnome org>
Date:   Thu Jun 4 21:18:37 2009 +0200

    Porting the maemo changes
    
    I copied the maemo PHP files over the wml files and cherrypicked the
    necessary changes, i.e. I didn't update the Elections name and left the
    old elections gnome org address in place.
---
 foundation.gnome.org/vote/results.wml |   85 +++-------------
 foundation.gnome.org/vote/vote.wml    |  179 ++++++++++++++++++++++++++------
 foundation.gnome.org/vote/votes.wml   |   13 ++-
 3 files changed, 167 insertions(+), 110 deletions(-)

diff --git a/foundation.gnome.org/vote/results.wml b/foundation.gnome.org/vote/results.wml
index ac69bab..2c397de 100644
--- a/foundation.gnome.org/vote/results.wml
+++ b/foundation.gnome.org/vote/results.wml
@@ -38,85 +38,28 @@ if ($display && $election_id >= 0) {
     $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.<br />\n";
     $display = FALSE;
   }
-}
-
-if (isset ($election) && $election !== FALSE) {
-  echo "<h1>Results for the ".$election["name"]."</h1>\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;
+  else
+  {
+    $results = elec_get_results($handle, $election_id);
   }
 }
 
-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) {
-  $blank_results = elec_get_blank_votes_election ($handle, $election_id);
-  if ($results === FALSE) {
-    $error .= "Can not get the blank votes for this ".elec_election_get_type ($election).".\n";
-    $display = FALSE;
-  }
-}
-
-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";
+if (isset ($election) && $election !== FALSE) {
+  if ($results !== FALSE)
+  {
+    echo "<h1>Results for the ".$election["name"]."</h1>\n";
+  } else {
+    $error .= "The voting period for the specified ".elec_election_get_type ($election)." has closed, but the results of the election have not yet been calculated. It is not possible to see the results now.<br />\n";
+    echo "<p>In the meantime, you can look at the <a href=\"votes.php?election_id=".$election_id."\">list of all votes</a> and verify that your vote is correct.</p>\n";
     $display = FALSE;
   }
 }
 
 if ($display) {
-  $nb_voters = count ($anon_tokens);
-
-  $automatic_results = array ();
-
-  echo "<p>Please note that these results are automatically calculated and are thus not the official results.</p>\n";
-
-  echo "<p><strong>".$election["question"]."</strong></p>";
-  echo "<p>".$nb_voters." members voted for this ".elec_election_get_type ($election).". The repartition of the votes is:</p>\n";
-
-  echo "<div class=\"votedata\">\n";
-  foreach ($results as $result) {
-    $found = FALSE;
-    foreach ($choices as $choice) {
-      if ($choice["id"] == $result["choice_id"]) {
-        echo "<em>".$choice["choice"]."</em> (<strong>".$result["total_choice"]."</strong> votes)<br />\n";
-        $automatic_results[] = $choice["choice"];
-        $found = TRUE;
-        break;
-      }
-    }
-
-    if (!$found) {
-      echo "<em>Unknown value (".$result["choice_id"].")</em> (<strong>".$result["total_choice"]."</strong> votes)<br />\n";
-      $automatic_results[] = "Unknown value (".$result["choice_id"].")";
-      $error .= "There was an unkown vote: ".$result["choice_id"]."<br />\n";
-    }
-  }
-  if ($blank_results > 0) {
-    echo "<br />";
-    echo "blank votes: <strong>".$blank_results."</strong><br />\n";
-  }
-  echo "</div>\n";
-
-  echo "<p>The automatic result of this ".elec_election_get_type ($election)." is thus:</p>\n";
-  echo "<div class=\"votedata\">\n";
-  for ($i = 0; $i < $election["choices_nb"]; $i++) {
-    echo "<em>".$automatic_results[$i]."</em><br />\n";
-  }
-  echo "</div>\n";
-
+  echo "<hr/>";
+  echo $results["result"];
+  echo "<hr/>";
+   
   echo "<p>Please look at the <a href=\"votes.php?election_id=".$election_id."\">list of all votes</a> and verify that your vote is correct.</p>\n";
 }
 
diff --git a/foundation.gnome.org/vote/vote.wml b/foundation.gnome.org/vote/vote.wml
index 7c88357..62d37df 100644
--- a/foundation.gnome.org/vote/vote.wml
+++ b/foundation.gnome.org/vote/vote.wml
@@ -1,14 +1,6 @@
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
 <html>
 
-  <head>
-    <link rel="stylesheet" type="text/css" href="vote.css" />
-    <title>The GNOME Foundation - Votes</title>
-    <meta name="cvsdate" content="$Date$" />
-    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
-  </head>
-
-  <body>
 <?php
 require_once ("include/election-sql.php");
 
@@ -67,40 +59,156 @@ if ($step > 1) {
 
   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.<br />\n";
+    $error .= "The e-mail address and token you gave do not match an existing voter, or you have already voted.<br />\n";
   } else {
 
-    $choices_nb = $election["choices_nb"];
     $choices = elec_choices_get ($handle, $election_id);
 
-    if (!elec_verify_elections ($choices_nb, $choices)) {
+    if (!elec_verify_elections ($choices)) {
       $error .= "The ".elec_election_get_type ($election)." is not properly set up.\n";
       $step = 0;
     }
 
   }
 }
+?>
+  <head>
+    <link rel="stylesheet" type="text/css" href="vote.css" />
+<?php
+if ($step==2)
+{
+?>
+    <style>
+.canddata, .prefdata{
+width:30%;
+height: <?php echo 1.8*count($choices); ?>em;
+background: #E0FFD0;
+}
 
-if (isset ($election) && $election !== FALSE) {
-  echo "<h1>".$election["name"]."</h1>\n";
+
+.canddata ul{
+list-style-type: none;
+list-style-position: inside;
+}
+.prefdata ol{
+list-style-position: outside;
 }
 
-if ($step >= 2) {
-  if ($choices_nb == 1) {
-    $votes_array = array ();
+.canddata ul li:hover, .prefdata ol li:hover{
+background: #E0E0E0;
+cursor: pointer;
+}
+    </style>
+<?php
+}
+?>
+    <title>The GNOME Foundation - Votes</title>
+    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+
+<?php
+if ($step==2)
+{
+?>
+<script type="text/javascript">
+//<![CDATA[
+function addPreference(listItem)
+{
+var preferenceList = document.getElementById('preferences');
+listItem.parentNode.removeChild(listItem);
+preferenceList.appendChild(listItem);
+listItem.setAttribute('onclick', 'removePreference(this)');
+}
+function removePreference(listItem)
+{
+var candidateList = document.getElementById('candidates');
+listItem.parentNode.removeChild(listItem);
+candidateList.appendChild(listItem);
+listItem.setAttribute('onclick', 'addPreference(this)');
+}
 
-    if (isset ($_POST["vote"]))
-      $vote = $_POST["vote"];
-    else
-      $vote = -1;
+function populateList(){
+  var candidateList = document.getElementById('candidates');
+  var listItem;
+  var prefInput;
+  var listItemText;
 
-  } else {
+<?php
+  $index=0;
+  foreach ($choices as $choice) {
+    $index++;
+    echo "  listItem = document.createElement('li');\n";
+    echo "  listItem.setAttribute('name', 'vote" . $choice["id"] . "');\n";
+    echo "  listItem.setAttribute('onclick', 'addPreference(this)');\n";
+    echo "  listItemText = document.createTextNode('" . $choice["choice"] . "');\n";
+    echo "  listItem.appendChild(listItemText);\n";
+    echo "  candidateList.appendChild(listItem);\n\n";
+
+    echo "  prefInput = document.createElement('input');\n";
+    echo "  prefInput.value = '';\n";
+    echo "  prefInput.name = 'pref$index';\n";
+    echo "  prefInput.id = 'pref$index';\n";
+    echo "  prefInput.type = 'hidden';\n";
+    echo "  document.forms[0].appendChild(prefInput);\n";
+    echo "\n";
+  }
+?>
 
+}
+
+function submitPreferences() {
+  // Traverse OL, get name & position of preferences, and for each preference, 
+  // set value of hidden input with name prefN to value voteM before submitting
+  var preferenceList = document.getElementById('preferences');
+  var pref;
+  var i = 0;
+  var index = 0;
+
+  // Iterate through the list 
+  for( i = 0; i < preferenceList.childNodes.length; i++ ) 
+  {
+    node = preferenceList.childNodes[i];
+    // If we have a list item, get its name & set the appropriate hidden input
+    if (node.nodeName.toLowerCase() == 'li')
+    {
+       index++;
+       pref=document.getElementById('pref'+index)
+       pref.value = node.getAttribute('name');
+      // DEBUG: alert(pref.name + '=' + pref.value);
+    }
+  }
+}
+
+//]]>
+    </script>
+<?php
+ }
+?>
+  </head>
+
+<?php
+if ($step==2){
+?>
+  <body onLoad="populateList()">
+<?php
+} else {
+?>
+  <body>
+<?php
+}
+?>
+
+<?php
+
+
+if (isset ($election) && $election !== FALSE) {
+  echo "<h1>".$election["name"]."</h1>\n";
+}
+
+if ($step >= 2) {
     $votes_array = elec_vote_get_votes_from_post ($choices);
     $vote = -1;
-  }
 
-  $res = elec_verify_vote_is_valid ($choices_nb, $choices, $vote, $votes_array);
+  $res = elec_verify_vote_is_valid ($choices, $vote, $votes_array);
   
   if ($res != "") {
     $error .= "The vote you made is not valid: ".$res."<br />\n";
@@ -142,7 +250,11 @@ if (isset ($error) && $error != "") {
 }
 
 if ($step != $max_step && $step >= 1) {
-  echo "<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">\n";
+  echo "<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\"";
+  if ($step == 2) {
+    echo "onsubmit=\"submitPreferences()\"";
+  }
+  echo ">\n";
 }
 
 echo $result;
@@ -153,18 +265,14 @@ if ($step != $max_step && $step >= 1) {
     echo "  <input type=\"hidden\" name=\"tmp_token\" value=\"".$tmp_token."\" />\n";
   }
   if ($step > 2) {
-    if ($choices_nb == 1)
-      echo "  <input type=\"hidden\" name=\"vote\" value=\"".$vote."\" />\n";
-    else {
-      foreach ($choices as $choice) {
-        $name = "vote".$choice["id"];
-        if (in_array ($choice["id"], $votes_array))
-          $value = "on";
-        else
-          $value = "";
+      $index=0;
+
+      foreach ($votes_array as $vote) {
+  	$index++;
+        $name = "pref".$index;
+        $value = "vote".$vote;
 
         echo "  <input type=\"hidden\" name=\"".$name."\" value=\"".$value."\" />\n";
-      }
     }
   }
   echo "  <input type=\"hidden\" name=\"election_id\" value=\"".$election_id."\" />\n";
@@ -173,3 +281,6 @@ if ($step != $max_step && $step >= 1) {
   echo "</form>\n";
 }
 ?>
+</body>
+</html>
+
diff --git a/foundation.gnome.org/vote/votes.wml b/foundation.gnome.org/vote/votes.wml
index e54ad56..5e481f2 100644
--- a/foundation.gnome.org/vote/votes.wml
+++ b/foundation.gnome.org/vote/votes.wml
@@ -66,7 +66,8 @@ if ($display) {
     $choices_name[$choice["id"]] = $choice["choice"];
   }
 
-  echo "<p>Please look at the <a href=\"results.php?election_id=".$election_id."\">automatic results</a> to have a summary of the votes.</p>\n";
+  echo "<p>Please look at the <a href=\"results.php?election_id=".$election_id."\">automatic results</a> to have a summary of the votes. ";
+  echo "You can also <a href=\"blt.php?election_id=".$election_id."\">download the ballots</a> in the OpenSTV .blt file format and verify the results.</p>\n";
 
   echo "<p>Please note that these results are automatically calculated and are thus not the official results.</p>\n";
 
@@ -92,14 +93,16 @@ if ($display) {
     } else if (count ($votes) == 0) {
       echo "This member chose to vote for<br />none of the possible choices.";
     } else {
+      echo "<ol>";
       foreach ($votes as $vote) {
-        if (array_key_exists ($vote, $choices_name))
-          echo "<em>".$choices_name[$vote]."</em><br />\n";
+        if (array_key_exists ($vote["choice_id"], $choices_name))
+          echo "<li><em>".$votes["preference"]." ".$choices_name[$vote["choice_id"]]."</em></li>\n";
         else {
-          echo "<em>Unknown value (".$vote.")</em><br />\n";
-          $error .= "There was an unkown vote for anonymous token ".$anon_token["anon_token"].": ".$vote."<br />\n";
+          echo "<li><em>Unknown value (".$vote["choice_id"].")</em></li>\n";
+          $error .= "There was an unkown vote for anonymous token ".$anon_token["anon_token"].": ".$vote["choice_id"]."<br />\n";
         }
       }
+      echo "</ol>";
     }
 
     echo "</td>\n";



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]