changeset 68:3ae137411706

More work.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 11 Oct 2013 09:29:44 +0300
parents 23eba98e1575
children 30a4420e85ab
files vote.inc.php
diffstat 1 files changed, 87 insertions(+), 77 deletions(-) [+]
line wrap: on
line diff
--- a/vote.inc.php	Sat Oct 05 18:58:03 2013 +0300
+++ b/vote.inc.php	Fri Oct 11 09:29:44 2013 +0300
@@ -7,106 +7,116 @@
   echo
   "<h1>Sorry, voting disabled!</h1>\n".
   "<p>Voting functionality not available at this time.</p>\n";
+
+  $status = -1;
 }
 else
 if (stUserSessionAuth())
 {
-  $authState = "ok";
+  $status = stGetSessionItem("status");
+  stStartSubmitStatus($status, "vote", "vsubmit.php", "Vote system");
+} else
+  $status = 0;
+
+  
+if ($status == 0)
+{
+  echo
+  "<h1>Voting system</h1>\n".
+  stGetFormStart("vote", "usrlogin.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".
+  "  ".stGetFormSubmitInput("login", "Login")."\n".
+  " </div>\n".
+  "</form>\n";
 }
 else
-{
-  
-  $authState = "login";
-}
-
-
+if ($status == 1)
 {
-  $status = stGetSubmitStatus();
+  stGetCompoList(TRUE, TRUE);
+
+  // Try fetching previously stored votes
+  $sql = stPrepareSQL(
+    "SELECT * FROM votes WHERE voter_id=%d",
+    stGetSessionItem("user_id"));
 
-  stStartSubmitStatus($status, "vote", "vsubmit.php", "Vote system");
-  
-  if ($status == 1)
+  if (($res = stExecSQL($sql)) !== false)
   {
-    stGetCompoList(TRUE, TRUE);
+    foreach ($res as $vote)
+    {
+      stSetSessionItem("entry".$vote["entry_id"], $vote["value"]);
+    }
+  }
 
-    // Try fetching previously stored votes
-    $sql = stPrepareSQL(
-      "SELECT * FROM votes WHERE voter_id=%d",
-      stGetSessionItem("user_id"));
+  // Output voting system HTML
+  echo
+  "<h1>Voting system</h1>\n".
+  stGetFormStart("vote", "vsubmit.php").
+  " ".stGetFormHiddenInput("mode", "vote")."\n".
+  " ".stGetFormHiddenInput("goto", "vote")."\n".
+  " ".stGetFormHiddenInput("key", stGetSessionItem("key"))."\n".
+  " <div class=\"votectrl\">".stGetFormSubmitInput("vote", "Submit votes!")."</div>\n";
 
-    if (($res = stExecSQL($sql)) !== false)
-    {
-      foreach ($res as $vote)
-      {
-        stSetSessionItem("entry".$vote["entry_id"], $vote["value"]);
-      }
-    }
-
+  foreach ($compos as $id => $compo)
+  if (count($compo["entries"]) > 0)
+  {
     echo
-    "<h1>Voting system</h1>\n".
-    stGetFormStart("vote", "vsubmit.php").
-    " ".stGetFormHiddenInput("mode", "vote")."\n".
-    " ".stGetFormHiddenInput("goto", "vote")."\n".
-    " ".stGetFormHiddenInput("key", stGetSessionItem("key"))."\n".
-    " <div class=\"votectrl\">".stGetFormSubmitInput("vote", "Submit votes!")."</div>\n";
+    " <table class=\"vote\">\n".
+    "  <tr><th colspan=\"3\">".chentities($compo["name"])."</th></tr>\n".
+    "  <tr>\n".
+    "   <th class=\"vtitle\">Title</th>\n".
+    ($compo["showAuthors"] ? "   <th class=\"vauthor\">Author</th>\n" : "").
+    "   ";
 
-    foreach ($compos as $id => $compo)
-    if (count($compo["entries"]) > 0)
+    for ($i = stGetSetting("voteMin"); $i <= stGetSetting("voteMax"); $i++)
     {
       echo
-      " <table class=\"vote\">\n".
-      "  <tr><th colspan=\"3\">".chentities($compo["name"])."</th></tr>\n".
-      "  <tr>\n".
-      "   <th class=\"vtitle\">Title</th>\n".
-      ($compo["showAuthors"] ? "   <th class=\"vauthor\">Author</th>\n" : "").
+      "<th class=\"vvalue\">".$i."</th>";
+    }
+    echo "\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".
+      ($compo["showAuthors"] ? "   <td class=\"vauthor\">".$entry["author"]."</td>\n" : "").
       "   ";
 
       for ($i = stGetSetting("voteMin"); $i <= stGetSetting("voteMax"); $i++)
       {
+        $name = "entry".$eid;
         echo
-        "<th class=\"vvalue\">".$i."</th>";
+          "<td class=\"vvalue\">".
+          stGetFormRadioButtonInput($name, "", "", $i, ($i == stGetSessionItem($name, 0)), "").
+          "</td>";
       }
-      echo "\n".
+
+      echo
+      "\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".
-        ($compo["showAuthors"] ? "   <td class=\"vauthor\">".$entry["author"]."</td>\n" : "").
-        "   ";
-
-        for ($i = stGetSetting("voteMin"); $i <= stGetSetting("voteMax"); $i++)
-        {
-          $name = "entry".$eid;
-          echo
-            "<td class=\"vvalue\">".
-            stGetFormRadioButtonInput($name, "", "", $i, ($i == stGetSessionItem($name, 0)), "").
-            "</td>";
-        }
+      $row++;
+    }
+    echo
+    " </table>\n";
+  }
 
-        echo
-        "\n".
-        "  </tr>\n";
-
-        $row++;
-      }
-      echo
-      " </table>\n";
-    }
-
-    echo
-    " <div class=\"votectrl\">".stGetFormSubmitInput("vote", "Submit votes!")."</div>\n".
-    "</form>\n";
-  }
-  else
-  if ($status == 2)
-  {
-    echo "<h1>Yay, you have voted!</h1>\n".
-    "<p>Now go FAP some more! And make a demo about it.</p>";
-    stSessionEnd(SESS_USER);
-  }
+  echo
+  " <div class=\"votectrl\">".stGetFormSubmitInput("vote", "Submit votes!")."</div>\n".
+  "</form>\n";
+}
+else
+if ($status == 2)
+{
+  // Voting finished
+  echo "<h1>Yay, you have voted!</h1>\n".
+  "<p>Now go FAP some more! And make a demo about it.</p>";
+  stSessionEnd(SESS_USER);
 }
 ?>
\ No newline at end of file