diff vote.inc.php @ 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 5bc8bd5c7ecc
children b27204653615
line wrap: on
line diff
--- 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