diff vote.inc.php @ 32:36392d1d6b5f

Moar work.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 10 Dec 2012 11:14:05 +0200
parents b27204653615
children 7bdf89601ba0
line wrap: on
line diff
--- a/vote.inc.php	Sun Dec 09 06:21:19 2012 +0200
+++ b/vote.inc.php	Mon Dec 10 11:14:05 2012 +0200
@@ -1,4 +1,6 @@
 <?
+$sessionType = "vote";
+
 // Check if voting is enabled
 if (!stChkSetting("allowVoting"))
 {
@@ -7,44 +9,43 @@
   "<p>Voting functionality not available at this time.</p>\n";
 }
 else
+if (stUserSessionAuth())
 {
-  stUserSessionAuth();
-  $mode = stGetSessionItem("status", 0);
+  $authState = "ok";
+}
+else
+{
   
-  if ($mode < 0)
-  {
-    echo "<h1>Oh noes, an error!</h1>\n".
-    "<ul>\n".stGetSessionItem("message", "")."</ul>\n".
-    stGetFormStart("vote").
-    "  ".stGetFormHiddenInput("goto", "vote")."\n".
-    "  ".stGetFormSubmitInput("back", "Go back")."\n".
-    "</form>\n";
-    stSetSessionStatus(0);
-  }
-  else
-  if ($mode == 0)
-  {
-    echo
-    "<h1>Voting system</h1>\n".
-    stGetFormStart("vote", "submit.php").
-    " ".stGetFormHiddenInput("mode", "key")."\n".
-    " ".stGetFormHiddenInput("goto", "vote")."\n".
-    " <div class=\"votectrl\">\n".
-    "  Enter your user key:\n".
-    "  ".stGetFormTextInput(30, 30, "key", "", "", stGetSessionItem("key"), "autocomplete=\"off\"")."\n".
-    "  ".stGetFormSubmitInput("login", "Login")."\n".
-    " </div>\n".
-    "</form>\n";
-  }
-  else
-  if ($mode == 1)
+  $authState = "login";
+}
+
+
+{
+  $status = stGetSubmitStatus();
+
+  stStartSubmitStatus($status, "vote", "vsubmit.php", "Vote system");
+  
+  if ($status == 1)
   {
     $showAuthors = stGetSetting("showVoteAuthors");
     stGetCompoList(TRUE, TRUE);
 
+    // Try fetching previously stored votes
+    $sql = stPrepareSQL(
+      "SELECT * FROM votes WHERE voter_id=%d",
+      stGetSessionItem("user_id"));
+
+    if (($res = stExecSQL($sql)) !== false)
+    {
+      foreach ($res as $vote)
+      {
+        stSetSessionItem("entry".$vote["entry_id"], $vote["value"]);
+      }
+    }
+
     echo
     "<h1>Voting system</h1>\n".
-    stGetFormStart("vote", "submit.php").
+    stGetFormStart("vote", "vsubmit.php").
     " ".stGetFormHiddenInput("mode", "vote")."\n".
     " ".stGetFormHiddenInput("goto", "vote")."\n".
     " ".stGetFormHiddenInput("key", stGetSessionItem("key"))."\n".
@@ -102,7 +103,7 @@
     "</form>\n";
   }
   else
-  if ($mode == 2)
+  if ($status == 2)
   {
     echo "<h1>Yay, you have voted!</h1>\n".
     "<p>Now go FAP some more! And make a demo about it.</p>";