comparison 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
comparison
equal deleted inserted replaced
1086:4a95cd4fa341 1087:4c76b4994414
13 " <div class=\"voteControls\">\n". 13 " <div class=\"voteControls\">\n".
14 " ".stGetFormSubmitInput("vote", "Submit votes and log out", "")."\n". 14 " ".stGetFormSubmitInput("vote", "Submit votes and log out", "")."\n".
15 " </div>\n"; 15 " </div>\n";
16 } 16 }
17 17
18 18 function stVoteLoginForm()
19 // Check if voting is enabled 19 {
20 if (!stChkSetting("allowVoting")) 20 return
21 echo stGetSetting("votingDisabled");
22 else
23 if (!stUserSessionAuth(FALSE))
24 {
25 // Perform authentication if we are not in session already
26 $userKeyLen = stGetSetting("userKeyLength");
27
28 if (($error = stGetRequestItem("error", 0, TRUE)) != 0)
29 {
30 echo
31 "<h1>Voting system login failed</h1>\n".
32 "<p class=\"notice\">\n";
33
34 switch ($error)
35 {
36 case 1:
37 echo "The votekey does not exist. Please try again.";
38 break;
39
40 case 2:
41 echo "There was an error in the system. Contact an administrator.";
42 break;
43
44 case 3:
45 echo
46 "The votekey is not yet activated, try again later. If ".
47 "you are certain that it should be working now, go pester an organizer.";
48 break;
49
50 default:
51 echo
52 "Undefined error occured.";
53 break;
54 }
55
56 echo
57 "</p>\n";
58 }
59 else
60 {
61 echo
62 "<h1>Voting system</h1>\n";
63 }
64
65 echo
66 "<div class=\"voteLogin\">\n". 21 "<div class=\"voteLogin\">\n".
67 " ".stGetFormStart("vote", "usrlogin.php"). 22 " ".stGetFormStart("vote", "usrlogin.php").
68 " ".stGetFormHiddenInput("mode", "vote")."\n". 23 " ".stGetFormHiddenInput("mode", "vote")."\n".
69 " ".stGetFormHiddenInput("goto", "vote")."\n". 24 " ".stGetFormHiddenInput("goto", "vote")."\n".
70 " Enter your vote key:\n". 25 " Enter your vote key:\n".
71 " ".stGetFormTextInput($userKeyLen > 30 ? $userKeyLen : 30, $userKeyLen, "key", "", "", "", "autocomplete=\"off\" autofocus=\"autofocus\"")."\n". 26 " ".stGetFormTextInput($userKeyLen > 30 ? $userKeyLen : 30, $userKeyLen, "key", "", "", "", "autocomplete=\"off\" autofocus=\"autofocus\"")."\n".
72 " ".stGetFormSubmitInput("login", "Login")."\n". 27 " ".stGetFormSubmitInput("login", "Login")."\n".
73 " </form>\n". 28 " </form>\n".
74 "</div>\n"; 29 "</div>\n";
30 }
31
32 // Check if voting is enabled
33 if (!stChkSetting("allowVoting"))
34 echo stGetSetting("votingDisabled");
35 else
36 if (!stUserSessionAuth(FALSE))
37 {
38 // Perform authentication if we are not in session already
39 $userKeyLen = stGetSetting("userKeyLength");
40
41 if (($error = stGetRequestItem("error", 0, TRUE)) != 0)
42 {
43 echo
44 "<h1>Voting system login failed</h1>\n".
45 "<p class=\"notice\">\n";
46
47 switch ($error)
48 {
49 case 1:
50 echo "The votekey does not exist. Please try again.";
51 break;
52
53 case 2:
54 echo "There was an error in the system. Contact an administrator.";
55 break;
56
57 case 3:
58 echo
59 "The votekey is not yet activated, try again later. If ".
60 "you are certain that it should be working now, go pester an organizer.";
61 break;
62
63 default:
64 echo
65 "Undefined error occured.";
66 break;
67 }
68
69 echo
70 "</p>\n";
71 }
72 else
73 {
74 echo
75 "<h1>Voting system</h1>\n";
76 }
77
78 echo stVoteLoginForm();
75 } 79 }
76 else 80 else
77 if (($mode = stGetSessionItem("mode")) == "vote") 81 if (($mode = stGetSessionItem("mode")) == "vote")
78 { 82 {
79 ?> 83 ?>
171 "</form>\n"; 175 "</form>\n";
172 } 176 }
173 else 177 else
174 if ($mode == "done") 178 if ($mode == "done")
175 { 179 {
176 // Voting finished 180 // Voting finished successfully
177 echo stGetSetting("voteFinishedText"); 181 echo stGetSetting("voteFinishedText");
178 stSessionEnd(SESS_USER); 182 stSessionEnd(SESS_USER);
179 } 183 }
184 else
185 if ($mode == "error")
186 {
187 // Error cases in session, when using form submit
188 echo
189 "<h1>Voting system error</h1>\n".
190 "<ul class=\"notice\">\n";
191
192 foreach (stGetSessionItem("error") as $msg)
193 echo " <li>".chentities($msg)."</li>\n";
194
195 echo
196 "</ul>\n".
197 stVoteLoginForm();
198
199 stSessionEnd(SESS_USER);
200 }
180 ?> 201 ?>