changeset 26:7be3f8cf1f7a

Lots of cleanups, preparing for adding entry submission support.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 08 Dec 2012 04:57:32 +0200
parents 8606c003ca48
children b27204653615
files admin.inc.php ajax.php createdb.php dovote.php fap.css keygen.php mconfig.inc.php.example msite.inc.php register.inc.php submit.php vote.inc.php
diffstat 11 files changed, 255 insertions(+), 235 deletions(-) [+]
line wrap: on
line diff
--- a/admin.inc.php	Fri Dec 07 23:31:23 2012 +0200
+++ b/admin.inc.php	Sat Dec 08 04:57:32 2012 +0200
@@ -257,9 +257,9 @@
 }
 
 
-function refreshVoters()
+function refreshUsers()
 {
-  refreshItems("nvoters", "voters", "Voters list");
+  refreshItems("nusers", "users", "Users list");
 }
 
 
@@ -352,26 +352,26 @@
 
 function updateVoter(id)
 {
-  var args = makePostArgs({"enabled":3, "name":0}, "vo", id);
+  var args = makePostArgs({"active":3, "name":0}, "vo", id);
 
   var msuccess = function(txt)
   {
-    setTimeout("refreshVoters();", 50);
+    setTimeout("refreshUsers();", 50);
   }
 
-  sendPOSTRequest("action=update&type=voter&id="+id+"&"+args, msuccess);
+  sendPOSTRequest("action=update&type=user&id="+id+"&"+args, msuccess);
 }
 
 
 function updateVoter2(id)
 {
-  var elem = document.getElementById("voenabled"+id);
+  var elem = document.getElementById("voactive"+id);
   if (elem && !elem.checked)
   {
     if (confirm("Are you sure you want deactivate vote ID #"+id+"?"))
       updateVoter(id);
     else
-      setTimeout("refreshVoters();", 50);
+      setTimeout("refreshUsers();", 50);
   }
   else
     updateVoter(id);
@@ -492,11 +492,11 @@
 
 <!-- ========================== -->
 
-<div id="tabVoters">
+<div id="tabUsers">
   <p>
     Key entries can only be generated via the shell-utility 'keygen'.
   </p>
-  <div id="nvoters"></div>
+  <div id="nusers"></div>
 </div>
 
 <!-- ========================== -->
@@ -508,7 +508,7 @@
   registerTab("tabDump", "Dump");
   registerTab("tabCompos", "Compos");
   registerTab("tabEntries", "Entries");
-  registerTab("tabVoters", "Voters");
+  registerTab("tabUsers", "Users");
   updateTabList();
   switchActiveTab("tabSettings");
 </script>
--- a/ajax.php	Fri Dec 07 23:31:23 2012 +0200
+++ b/ajax.php	Sat Dec 08 04:57:32 2012 +0200
@@ -181,8 +181,8 @@
         }
         break;
       
-      case "voters":
-        $sql = "SELECT * FROM voters ORDER BY id ASC";
+      case "users":
+        $sql = "SELECT * FROM users ORDER BY id ASC";
     }
     
     if (isset($sql) && ($res = execSQLCond($sql, "")) !== FALSE)
@@ -238,13 +238,13 @@
         }
       }
       else
-      if ($type == "voters")
+      if ($type == "users")
       {
         echo
-        "<table class=\"voters\">\n".
+        "<table class=\"users\">\n".
         " <tr>\n".
         "  <th class=\"vid\">#</th>\n".
-        "  <th class=\"vkey\">Vote key</th>\n".
+        "  <th class=\"vkey\">User key</th>\n".
         "  <th class=\"vname\">Name</th>\n".
         "  <th class=\"vactive\">Active</th>\n".
         " </tr>\n";
@@ -255,13 +255,13 @@
           $prefix = "vo";
           echo
           " <tr>\n".
-          " <tr class=\"".($item["enabled"] ? "vactive " : "").
-            ($row % 2 == 1 ? "rodd" : "reven")."\" id=\"voter".$id."\">\n".
+          " <tr class=\"".($item["active"] ? "vactive " : "").
+            ($row % 2 == 1 ? "rodd" : "reven")."\" id=\"user".$id."\">\n".
           "  <td class=\"vid\">".sprintf("%04d", $id)."</td>\n".
           "  <td class=\"vkey\">".chentities($item["key"])."</td>\n".
           "  <td class=\"vname\">".stGetFormTextInput(40, 64, "name", $id, $prefix, $item["name"],
           "onBlur=\"updateVoter(".$id.")\" autocomplete=\"off\"")."</td>\n".
-          "  <td class=\"vactive\">".stGetFormCheckBoxInput("enabled", $id, $prefix, $item["enabled"], "",
+          "  <td class=\"vactive\">".stGetFormCheckBoxInput("active", $id, $prefix, $item["active"], "",
           "onClick=\"updateVoter2(".$id.")\"")."</td>\n".
           " </tr>\n";
           $row++;
@@ -292,7 +292,8 @@
     break;
 
   case "add":
-    if ($type == "news" && stChkRequestItem("text") && stChkRequestItem("author") && stChkRequestItem("title"))
+    if ($type == "news" && stChkRequestItem("text") &&
+      stChkRequestItem("author") && stChkRequestItem("title"))
     {
       $sql = stPrepareSQL(
         "INSERT INTO news (utime,title,text,author) VALUES (%d,%S,%Q,%S)",
@@ -301,16 +302,18 @@
       execSQLCond($sql, "OK, news item added.");
     }
     else
-    if ($type == "compo" && stChkRequestItem("name") && stChkRequestItem("description"))
+    if ($type == "compo" && stChkRequestItem("name") &&
+      stChkRequestItem("description"))
     {
       $sql = stPrepareSQL(
-        "INSERT INTO compos (name,description,enabled) VALUES (%S,%Q,0)",
-        "name", "description", 0);
+        "INSERT INTO compos (name,description,visible,voting) VALUES (%S,%Q,0,0)",
+        "name", "description");
 
       execSQLCond($sql, "OK, compo added.");
     }
     else
-    if ($type == "entry" && stChkRequestItem("name") && stChkRequestItem("author") && stChkRequestItem("compo_id"))
+    if ($type == "entry" && stChkRequestItem("name") &&
+      stChkRequestItem("author") && stChkRequestItem("compo_id"))
     {
       $sql = stPrepareSQL(
         "INSERT INTO entries (name,author,compo_id) VALUES (%S,%Q,%D)",
@@ -367,17 +370,17 @@
       execSQLCond($sql, "OK, compo updated.");
     }
     else
-    if ($type == "voter" && stChkRequestItem("id") &&
-      stChkRequestItem("name") && stChkRequestItem("enabled"))
+    if ($type == "user" && stChkRequestItem("id") &&
+      stChkRequestItem("name") && stChkRequestItem("active"))
     {
-      $sql = stPrepareSQLUpdate("voters",
+      $sql = stPrepareSQLUpdate("users",
         "WHERE id=".intval(stGetRequestItem("id")),
         array(
           "name" => "S",
-          "enabled" => "B",
+          "active" => "B",
         ));
 
-      execSQLCond($sql, "OK, voter updated.");
+      execSQLCond($sql, "OK, user updated.");
     }
     else
     if ($type == "entry" && stChkRequestItem("id") &&
--- a/createdb.php	Fri Dec 07 23:31:23 2012 +0200
+++ b/createdb.php	Sat Dec 08 04:57:32 2012 +0200
@@ -121,7 +121,7 @@
   "attendees" => "id INTEGER PRIMARY KEY AUTOINCREMENT, regtime INT, name VARCHAR(64), groups VARCHAR(64), oneliner VARCHAR(64), email VARCHAR(80)",
   "compos" => "id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(128), description VARCHAR(4096), visible INT DEFAULT 0, voting INT DEFAULT 0",
   "entries" => "id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(64), author VARCHAR(64), compo_id INT DEFAULT NULL, filename VARCHAR(128) DEFAULT NULL, screenshot VARCHAR(128) DEFAULT NULL",
-  "voters" => "id INTEGER PRIMARY KEY AUTOINCREMENT, key VARCHAR(64), name VARCHAR(64), enabled INT DEFAULT 0",
+  "users" => "id INTEGER PRIMARY KEY AUTOINCREMENT, key VARCHAR(64), name VARCHAR(64), email VARCHAR(64), active INT DEFAULT 0",
   "votes" => "id INTEGER PRIMARY KEY AUTOINCREMENT, entry_id INT DEFAULT NULL, voter_id INT DEFAULT NULL, value INT DEFAULT 0",
   "settings" => "key VARCHAR(32) PRIMARY KEY, vtype INT, vstr VARCHAR(128), vtext TEXT, vint INT, desc VARCHAR(128)",
 );
--- a/dovote.php	Fri Dec 07 23:31:23 2012 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,136 +0,0 @@
-<?
-require "mconfig.inc.php";
-require "msite.inc.php";
-
-stSetupCacheControl();
-
-// Initiate SQL database connection
-if (!stConnectSQLDB())
-{
-  header("Location: vote");
-  exit;
-}
-
-// Get settings
-stReloadSettings();
-
-
-// Start vote session
-if (!stVoteSessionStart())
-{
-  header("Location: vote");
-  exit;
-}
-
-$_SESSION["message"] = "";
-stSetVoteStatus(0);
-
-
-if (stCheckHTTPS() && stChkSetting("allowVoting"))
-{
-  stGetCompoList(FALSE);
-  $mode = stGetRequestItem("mode");
-
-  // Check received data
-  if (stChkDataItem("key") ||
-    strlen(stGetRequestItem("key")) != stGetSetting("voteKeyLength"))
-  {
-    stError("Invalid or empty vote key, please check.");
-  }
-  else
-  {
-    // Check if the key exists and is active
-    $sql = stPrepareSQL(
-      "SELECT * FROM voters WHERE key=%S AND enabled<>0",
-      "key");
-
-    if (($voter = stFetchSQL($sql)) === FALSE)
-      stError("Vote key does not exist, perhaps you typed it incorrectly?");
-  }
-
-  if (!$errorSet && $mode == "key")
-  {
-    $_SESSION["key"] = stGetRequestItem("key");
-    stSetVoteStatus(1);
-
-    // Try fetching previously stored votes
-    $sql = stPrepareSQL(
-      "SELECT * FROM votes WHERE voter_id=%d",
-      $voter["id"]);
-
-    if (($res = stExecSQL($sql)) !== false)
-    {
-      foreach ($res as $vote)
-      {
-        $_SESSION["entry".$vote["entry_id"]] = $vote["value"];
-      }
-    }
-    
-//    print_r($_SESSION); exit;
-  }
-
-  if (!$errorSet && $mode == "check")
-  {
-    // Check the submitted vote values
-    foreach ($compos as $id => $compo)
-    if (count($compo["entries"]) > 0)
-    {
-      foreach ($compo["entries"] as $eid => $entry)
-      {
-        $name = "entry".$eid;
-        $vote = stGetRequestItem($name);
-        if (!$errorSet && ($vote < stGetSetting("voteMin") || $vote > stGetSetting("voteMax")))
-        {
-          stError("One or more vote value was out of bounds. Trying to cheat, eh?");
-          $vote = 0;
-        }
-        $_SESSION[$name] = $vote;
-      }
-    }
-  }
-
-  // Ookkay...
-  if (!$errorSet && $mode == "check")
-  {
-    foreach ($compos as $id => $compo)
-    if (count($compo["entries"]) > 0)
-    {
-      foreach ($compo["entries"] as $eid => $entry)
-      {
-        $vote = stGetRequestItem("entry".$eid);
-        $sql = stPrepareSQL("SELECT id FROM votes WHERE voter_id=%d AND entry_id=%d",
-          $voter["id"], $eid);
-
-        if (($res = stFetchSQLColumn($sql)) === false)
-        {
-          $sql = stPrepareSQL(
-            "INSERT INTO votes (voter_id,entry_id,value) VALUES (%d,%d,%d)",
-            $voter["id"], $eid, $vote);
-
-          if (stExecSQL($sql) === false)
-            break;
-        }
-        else
-        {
-          $sql = stPrepareSQL(
-            "UPDATE votes SET value=%d WHERE voter_id=%d AND entry_id=%d",
-            $vote, $voter["id"], $eid);
-
-          if (stExecSQL($sql) === false)
-            break;
-        }
-      }
-    }
-
-    stSetVoteStatus(2);
-  }
-}
-
-if ($errorSet)
-{
-  stSetVoteStatus(-1);
-  $_SESSION["message"] = $errorMsg;
-}
-
-header("Location: vote");
-?>
\ No newline at end of file
--- a/fap.css	Fri Dec 07 23:31:23 2012 +0200
+++ b/fap.css	Sat Dec 08 04:57:32 2012 +0200
@@ -260,7 +260,7 @@
 	width: 25%;
 }
 
-table.voters tr.vactive td {
+table.users tr.vactive td {
 	background: rgba(255,0,0,0.5);
 }
 
--- a/keygen.php	Fri Dec 07 23:31:23 2012 +0200
+++ b/keygen.php	Sat Dec 08 04:57:32 2012 +0200
@@ -56,18 +56,18 @@
       
       // Generate one keycode
       $key = "";
-      for ($n = 0; $n < stGetSetting("voteKeyLength"); $n++)
+      for ($n = 0; $n < stGetSetting("userKeyLength"); $n++)
         $key .= $keyChars[rand() % strlen($keyChars)];
 
       // Check if it already exists, to avoid duplicates
-      $sql = stPrepareSQL("SELECT * FROM voters WHERE key=%s", $key);
+      $sql = stPrepareSQL("SELECT * FROM users WHERE key=%s", $key);
       if (($res = @$db->query($sql)) !== FALSE)
       {
         if ($res->fetchColumn() === FALSE)
         {
           // Nope, add into database
           $sql = stPrepareSQL(
-            "INSERT INTO voters (key,name,enabled) VALUES (%s,'',0)",
+            "INSERT INTO users (key,active) VALUES (%s,0)",
             $key);
 
           if (($res = $db->query($sql)) === FALSE)
@@ -87,7 +87,7 @@
   case "pr":
     // Print keys
     $all = stCArgLC(2) == "all";
-    $sql = "SELECT * FROM voters ".($all ? "" : "WHERE enabled=0 ")."ORDER BY id ASC";
+    $sql = "SELECT * FROM users ".($all ? "" : "WHERE enabled=0 ")."ORDER BY id ASC";
     if (($res = @$db->query($sql)) !== FALSE)
     {
       $rows = 0;
--- a/mconfig.inc.php.example	Fri Dec 07 23:31:23 2012 +0200
+++ b/mconfig.inc.php.example	Sat Dec 08 04:57:32 2012 +0200
@@ -6,7 +6,7 @@
 
   "debug"           => false,
 
-  "voteKeyLength"   => 8,
+  "userKeyLength"   => 8,
   "voteMin"         => -1,
   "voteMax"         => 2,
 
--- a/msite.inc.php	Fri Dec 07 23:31:23 2012 +0200
+++ b/msite.inc.php	Sat Dec 08 04:57:32 2012 +0200
@@ -14,7 +14,6 @@
 define("VT_TEXT", 4);
 
 
-
 function stError($msg)
 {
   global $errorSet, $errorMsg;
@@ -106,7 +105,7 @@
 }
 
 
-function stVoteSessionAuth()
+function stUserSessionAuth()
 {
   if (@session_start() === TRUE && isset($_SESSION["key"]) && isset($_SESSION["votes"]))
     return stSessionExpire("voteTimeout");
@@ -115,7 +114,7 @@
 }
 
 
-function stVoteSessionStart()
+function stUserSessionStart()
 {
   if (@session_start() === TRUE)
   {
@@ -128,7 +127,7 @@
 }
 
 
-function stSetVoteStatus($st)
+function stSetSessionStatus($st)
 {
   $_SESSION["status"] = $st;
 }
@@ -219,11 +218,20 @@
 }
 
 
+function stGetFormRadioButtonInput($name, $id, $prefix, $value, $checked, $label, $extra = "")
+{
+  return
+    "<input ".$extra." type=\"radio\" ".stGetIDName($name, $id, $prefix).
+    ($checked ? "checked=\"checked\" " : "")." value=\"".$value."\" />".
+    ($label != "" ? "<label for=\"".$name."\">".$label."</label>" : "");
+}
+
+
 function stGetFormButtonInput($name, $id, $prefix, $label, $onclick = "")
 {
   return
     "<input type=\"button\" ".stGetIDName($name, $id, $prefix).
-    "value=\"".$label."\" ".
+    "value=\" ".chentities($label)." \" ".
     ($onclick != "" ? "onClick=\"".$onclick."\"" : "")." />";
 }
 
@@ -255,6 +263,15 @@
 }
 
 
+function stGetFormSubmitInput($name, $label, $onclick = "")
+{
+  return
+    "<input type=\"submit\" name=\"".$name.
+    "\" value=\" ".chentities($label)." \" ".
+    ($onclick != "" ? "onClick=\"".$onclick."\"" : "")." />";
+}
+
+
 function stGetFormHiddenInput($name, $value)
 {
   return
@@ -263,6 +280,15 @@
 }
 
 
+function stGetFormStart($name, $action = "", $method = "post")
+{
+  return
+    "<form name=\"".$name."\" action=\"".
+    ($action != "" ? $action : $name).
+    "\" method=\"".$method."\">\n";
+}
+
+
 function stGetTDEditTextItem($edit, $size, $len, $name, $id, $prefix, $value, $extra = "")
 {
   return
@@ -348,6 +374,12 @@
 }
 
 
+function stGetSessionItem($name, $default = "")
+{
+  return isset($_SESSION[$name]) ? trim($_SESSION[$name]) : $default;
+}
+
+
 function stLogSQLError($sql)
 {
   global $db;
--- a/register.inc.php	Fri Dec 07 23:31:23 2012 +0200
+++ b/register.inc.php	Sat Dec 08 04:57:32 2012 +0200
@@ -9,8 +9,8 @@
 function stPrintFormData($button, $mode = "start")
 {
   echo
-  "<form name=\"register\" action=\"register\" method=\"post\">\n".
-  " <input type=\"submit\" value=\"".chentities($button)."\" />\n";
+  stGetFormStart("register").
+  " ".stGetFormSubmitInput("continue", $button)."\n";
 
   stPrintFormHiddenInput("mode", $mode);
   
@@ -101,27 +101,25 @@
     $botCheckOPs[rand(0,2)].
     intValueToHash(5 * rand(1,5));
 
-?>
-<h1>Registration</h1>
+  echo
+  "<h1>Registration</h1>\n".
+  stGetFormStart("register").
+  " ".stGetFormHiddenInput("mode", "check")."\n".
+  " ".stGetFormHiddenInput("hash", $botCheckHash)."\n".
+  " <table>\n";
+  stPrintFormTextInput("Handle:", "(elite)", 30, 30, "name");
+  stPrintFormTextInput("Group(s):", "(elite crew^supahmen)", 40, 64, "groups");
+  stPrintFormTextInput("E-mail:", "(to be informed of location etc)", 40, 64, "email");
+  stPrintFormTextInput("Oneliner:", "(whatever)", 64, 64, "oneliner");
+  stPrintFormTextInput(hashToCheckStr($botCheckHash)." = ", "(I.Q. / robot check".
+  //" [".hashToAnswer($botCheckHash)."]".
+  ")", 20, 20, "botcheck", "autocomplete=\"off\"");
+  echo
+  "  <tr><td colspan=\"2\"></td><td>".stGetFormSubmitInput("register", "Register")."</td></tr>\n".
+  " </table>\n".
+  "</form>\n";
 
-<form name="register" action="register" method="post">
- <input type="hidden" name="mode" value="check">
- <input type="hidden" name="hash" value="<? echo $botCheckHash ?>">
- <table>
-<?
-stPrintFormTextInput("Handle:", "(elite)", 30, 30, "name");
-stPrintFormTextInput("Group(s):", "(elite crew^supahmen)", 40, 64, "groups");
-stPrintFormTextInput("E-mail:", "(to be informed of location etc)", 40, 64, "email");
-stPrintFormTextInput("Oneliner:", "(whatever)", 64, 64, "oneliner");
-stPrintFormTextInput(hashToCheckStr($botCheckHash)." = ", "(I.Q. / robot check".
-//" [".hashToAnswer($botCheckHash)."]".
-")", 20, 20, "botcheck", "autocomplete=\"off\"");
-?>
-  <tr><td colspan="2"></td><td><input type="submit" value="Register" /></td></tr>
- </table>
-</form>
-<?
-echo stGetSetting("registerInfoText");
+  echo stGetSetting("registerInfoText");
 }
 else
 if ($mode == "check")
@@ -139,7 +137,7 @@
       stError("E-mail address not given, or it is too short.");
   }
 
-  if (strlen($email >= 4) && (strpos($email, "@") === FALSE || strpos($email, ".") === FALSE))
+  if (strlen($email) >= 0 && (strpos($email, "@") === FALSE || strpos($email, ".") === FALSE))
     stError("E-mail address not in proper format.");
 
   $hash = stGetRequestItem("hash");
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/submit.php	Sat Dec 08 04:57:32 2012 +0200
@@ -0,0 +1,128 @@
+<?
+require "mconfig.inc.php";
+require "msite.inc.php";
+
+stSetupCacheControl();
+
+$sessionDestPage = stGetRequestItem("goto");
+
+// Initiate SQL database connection
+if (!stConnectSQLDB())
+{
+  header("Location: ".$sessionDestPage);
+  exit;
+}
+
+// Get settings
+stReloadSettings();
+
+
+// Start vote session
+if (!stUserSessionStart())
+{
+  header("Location: ".$sessionDestPage);
+  exit;
+}
+
+$_SESSION["message"] = "";
+stSetSessionStatus(0);
+
+
+if (stCheckHTTPS() && (stChkSetting("allowVoting") || stChkSetting("allowSubmit")))
+{
+  stGetCompoList(FALSE);
+  $mode = stGetRequestItem("mode");
+
+  // Check received data
+  if (stChkDataItem("key") ||
+    strlen(stGetRequestItem("key")) != stGetSetting("userKeyLength"))
+  {
+    stError("Invalid or empty vote key, please check.");
+  }
+  else
+  {
+    // Check if the key exists and is active
+    $sql = stPrepareSQL(
+      "SELECT * FROM users WHERE key=%S AND active<>0",
+      "key");
+
+    if (($voter = stFetchSQL($sql)) === FALSE)
+      stError("User key does not exist, perhaps you typed it incorrectly?");
+  }
+
+  if (!$errorSet && $mode == "key")
+  {
+    $_SESSION["key"] = stGetRequestItem("key");
+    stSetSessionStatus(1);
+
+    // Try fetching previously stored votes
+    $sql = stPrepareSQL(
+      "SELECT * FROM votes WHERE voter_id=%d",
+      $voter["id"]);
+
+    if (($res = stExecSQL($sql)) !== false)
+    {
+      foreach ($res as $vote)
+      {
+        $_SESSION["entry".$vote["entry_id"]] = $vote["value"];
+      }
+    }
+  }
+
+  if (!$errorSet && $mode == "vote")
+  {
+    // Check the submitted vote values
+    foreach ($compos as $id => $compo)
+    foreach ($compo["entries"] as $eid => $entry)
+    {
+      $name = "entry".$eid;
+      $vote = stGetRequestItem($name);
+      if (!$errorSet && ($vote < stGetSetting("voteMin") || $vote > stGetSetting("voteMax")))
+      {
+        stError("One or more vote value was out of bounds. Trying to cheat, eh?");
+        $vote = 0;
+      }
+      $_SESSION[$name] = $vote;
+    }
+    
+    if (!$errorSet)
+    {
+      foreach ($compos as $id => $compo)
+      foreach ($compo["entries"] as $eid => $entry)
+      {
+        $vote = stGetRequestItem("entry".$eid);
+        $sql = stPrepareSQL("SELECT id FROM votes WHERE voter_id=%d AND entry_id=%d",
+          $voter["id"], $eid);
+
+        if (($res = stFetchSQLColumn($sql)) === false)
+        {
+          $sql = stPrepareSQL(
+            "INSERT INTO votes (voter_id,entry_id,value) VALUES (%d,%d,%d)",
+            $voter["id"], $eid, $vote);
+
+          if (stExecSQL($sql) === false)
+            break;
+        }
+        else
+        {
+          $sql = stPrepareSQL(
+            "UPDATE votes SET value=%d WHERE voter_id=%d AND entry_id=%d",
+            $vote, $voter["id"], $eid);
+
+          if (stExecSQL($sql) === false)
+            break;
+        }
+      }
+      stSetSessionStatus(2);
+    }
+  }
+}
+
+if ($errorSet)
+{
+  stSetSessionStatus(-1);
+  $_SESSION["message"] = $errorMsg;
+}
+
+header("Location: ".$sessionDestPage);
+?>
\ No newline at end of file
--- a/vote.inc.php	Fri Dec 07 23:31:23 2012 +0200
+++ b/vote.inc.php	Sat Dec 08 04:57:32 2012 +0200
@@ -1,10 +1,4 @@
 <?
-function stGetSessionItem($name, $default = "")
-{
-  return isset($_SESSION[$name]) ? trim($_SESSION[$name]) : $default;
-}
-
-
 // Check if voting is enabled
 if (!stChkSetting("allowVoting"))
 {
@@ -14,29 +8,31 @@
 }
 else
 {
-  stVoteSessionAuth();
+  stUserSessionAuth();
   $mode = stGetSessionItem("status", 0);
   
   if ($mode < 0)
   {
     echo "<h1>Oh noes, an error!</h1>\n".
     "<ul>\n".stGetSessionItem("message", "")."</ul>\n".
-    "<form name=\"vote\" action=\"vote\" method=\"post\">\n".
-    " <input type=\"submit\" value=\" Go back \" />\n".
+    stGetFormStart("vote").
+    "  ".stGetFormHiddenInput("goto", "vote")."\n".
+    "  ".stGetFormSubmitInput("back", "Go back")."\n".
     "</form>\n";
-    stSetVoteStatus(0);
+    stSetSessionStatus(0);
   }
   else
   if ($mode == 0)
   {
     echo
     "<h1>Voting system</h1>\n".
-    "<form name=\"vote\" action=\"dovote.php\" method=\"post\">\n".
+    stGetFormStart("vote", "submit.php").
     " ".stGetFormHiddenInput("mode", "key")."\n".
+    " ".stGetFormHiddenInput("goto", "vote")."\n".
     " <div class=\"votectrl\">\n".
     "  Enter your vote key:\n".
     "  ".stGetFormTextInput(30, 30, "key", "", "", stGetSessionItem("key"), "autocomplete=\"off\"")."\n".
-    "  <input type=\"submit\" value=\" Login \" />\n".
+    "  ".stGetFormSubmitInput("login", "Login")."\n".
     " </div>\n".
     "</form>\n";
   }
@@ -48,23 +44,22 @@
 
     echo
     "<h1>Voting system</h1>\n".
-    "<form name=\"vote\" action=\"dovote.php\" method=\"post\">\n".
-    stGetFormHiddenInput("mode", "check")."\n".
-    stGetFormHiddenInput("key", stGetSessionItem("key"))."\n".
-    " <div class=\"votectrl\">\n".
-    "  <input type=\"submit\" value=\" Submit votes! \" />".
-    " </div>\n";
+    stGetFormStart("vote", "submit.php").
+    " ".stGetFormHiddenInput("mode", "vote")."\n".
+    " ".stGetFormHiddenInput("goto", "vote")."\n".
+    " ".stGetFormHiddenInput("key", stGetSessionItem("key"))."\n".
+    " <div class=\"votectrl\">".stGetFormSubmitInput("vote", "Submit votes!")."</div>\n";
 
     foreach ($compos as $id => $compo)
     if (count($compo["entries"]) > 0)
     {
       echo
-        " <table class=\"vote\">\n".
-        "  <tr><th colspan=\"3\">".chentities($compo["name"])."</th></tr>\n".
-        "  <tr>\n".
-        "   <th class=\"vtitle\">Title</th>\n".
-        ($showAuthors ? "   <th class=\"vauthor\">Author</th>\n" : "").
-        "   ";
+      " <table class=\"vote\">\n".
+      "  <tr><th colspan=\"3\">".chentities($compo["name"])."</th></tr>\n".
+      "  <tr>\n".
+      "   <th class=\"vtitle\">Title</th>\n".
+      ($showAuthors ? "   <th class=\"vauthor\">Author</th>\n" : "").
+      "   ";
 
       for ($i = stGetSetting("voteMin"); $i <= stGetSetting("voteMax"); $i++)
       {
@@ -72,38 +67,38 @@
         "<th class=\"vvalue\">".$i."</th>";
       }
       echo "\n".
-        "  </tr>\n";
+      "  </tr>\n";
 
       $row = 0;
       foreach ($compo["entries"] as $eid => $entry)
       {
         echo
-          "  <tr class=\"".($row % 2 == 1 ? "rodd" : "reven")."\">\n".
-          "   <td class=\"vtitle\">".$entry["name"]."</td>\n".
-          ($showAuthors ? "   <td class=\"vauthor\">".$entry["author"]."</td>\n" : "").
-          "   ";
+        "  <tr class=\"".($row % 2 == 1 ? "rodd" : "reven")."\">\n".
+        "   <td class=\"vtitle\">".$entry["name"]."</td>\n".
+        ($showAuthors ? "   <td class=\"vauthor\">".$entry["author"]."</td>\n" : "").
+        "   ";
 
         for ($i = stGetSetting("voteMin"); $i <= stGetSetting("voteMax"); $i++)
         {
           $name = "entry".$eid;
           echo
-            "<td class=\"vvalue\"><input type=\"radio\" name=\"".$name."\" ".
-            ($i == stGetSessionItem($name, 0) ? "checked=\"checked\" " : "")."value=\"".$i."\" /></td>";
+            "<td class=\"vvalue\">".
+            stGetFormRadioButtonInput($name, "", "", $i, ($i == stGetSessionItem($name, 0)), "").
+            "</td>";
         }
 
         echo
-          "\n".
-          "  </tr>\n";
+        "\n".
+        "  </tr>\n";
 
         $row++;
       }
       echo
-        " </table>\n";
+      " </table>\n";
     }
 
     echo
-    "<div class=\"votectrl\"><input type=\"submit\" value=\" Submit votes! \" /></div>\n";
-    echo
+    " <div class=\"votectrl\">".stGetFormSubmitInput("vote", "Submit votes!")."</div>\n".
     "</form>\n";
   }
   else