diff pages/vote.inc.php @ 1087:4c76b4994414

Somewhat refactor usrajax and voting.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 26 Jan 2017 00:38:06 +0200
parents 01783161eeb2
children 4f132374df75
line wrap: on
line diff
--- a/pages/vote.inc.php	Thu Jan 26 00:30:58 2017 +0200
+++ b/pages/vote.inc.php	Thu Jan 26 00:38:06 2017 +0200
@@ -15,6 +15,19 @@
     " </div>\n";
 }
 
+function stVoteLoginForm()
+{
+  return
+    "<div class=\"voteLogin\">\n".
+    " ".stGetFormStart("vote", "usrlogin.php").
+    " ".stGetFormHiddenInput("mode", "vote")."\n".
+    " ".stGetFormHiddenInput("goto", "vote")."\n".
+    "  Enter your vote key:\n".
+    "  ".stGetFormTextInput($userKeyLen > 30 ? $userKeyLen : 30, $userKeyLen, "key", "", "", "", "autocomplete=\"off\" autofocus=\"autofocus\"")."\n".
+    "  ".stGetFormSubmitInput("login", "Login")."\n".
+    " </form>\n".
+    "</div>\n";
+}
 
 // Check if voting is enabled
 if (!stChkSetting("allowVoting"))
@@ -62,16 +75,7 @@
       "<h1>Voting system</h1>\n";
   }
 
-  echo
-    "<div class=\"voteLogin\">\n".
-    " ".stGetFormStart("vote", "usrlogin.php").
-    " ".stGetFormHiddenInput("mode", "vote")."\n".
-    " ".stGetFormHiddenInput("goto", "vote")."\n".
-    "  Enter your vote key:\n".
-    "  ".stGetFormTextInput($userKeyLen > 30 ? $userKeyLen : 30, $userKeyLen, "key", "", "", "", "autocomplete=\"off\" autofocus=\"autofocus\"")."\n".
-    "  ".stGetFormSubmitInput("login", "Login")."\n".
-    " </form>\n".
-    "</div>\n";
+  echo stVoteLoginForm();
 }
 else
 if (($mode = stGetSessionItem("mode")) == "vote")
@@ -173,8 +177,25 @@
 else
 if ($mode == "done")
 {
-  // Voting finished
+  // Voting finished successfully
   echo stGetSetting("voteFinishedText");
   stSessionEnd(SESS_USER);
 }
+else
+if ($mode == "error")
+{
+  // Error cases in session, when using form submit
+  echo
+    "<h1>Voting system error</h1>\n".
+    "<ul class=\"notice\">\n";
+
+  foreach (stGetSessionItem("error") as $msg)
+    echo " <li>".chentities($msg)."</li>\n";
+
+  echo
+    "</ul>\n".
+    stVoteLoginForm();
+
+  stSessionEnd(SESS_USER);
+}
 ?> 
\ No newline at end of file