comparison vote.inc.php @ 110:ff511f5351df

Work on voting.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 21 Oct 2013 22:48:55 +0300
parents 0f00192e64af
children 9a52fa9d4ecc
comparison
equal deleted inserted replaced
109:9a3f0ba4d72b 110:ff511f5351df
1 <? 1 <?
2 $sessionType = "user"; 2 $sessionType = "user";
3 $userKeyLen = stGetSetting("userKeyLength"); 3 $userKeyLen = stGetSetting("userKeyLength");
4
5
6 function stGetVoteButton()
7 {
8 return
9 "<div class=\"votectrl\">".
10 stGetFormSubmitInput("vote", "Submit votes!", "return false").
11 "</div>\n";
12 }
4 13
5 // Check if voting is enabled 14 // Check if voting is enabled
6 if (!stChkSetting("allowVoting")) 15 if (!stChkSetting("allowVoting"))
7 { 16 {
8 echo 17 echo
9 "<h1>Sorry, voting disabled!</h1>\n". 18 "<h1>Sorry, voting disabled!</h1>\n".
10 "<p>Voting functionality not available at this time.</p>\n"; 19 "<p>Voting functionality not available at this time.</p>\n";
11
12 $status = -1;
13 } 20 }
14 else 21 else
15 if (stUserSessionAuth()) 22 if (!stUserSessionAuth(FALSE))
16 { 23 {
17 $status = stGetSessionItem("status"); 24 // Perform authentication if we are not in session already
18 stStartSubmitStatus($status, "vote", "vsubmit.php", "Vote system");
19 } else
20 $status = 0;
21
22
23 if ($status == 0)
24 {
25 echo 25 echo
26 "<h1>Voting system</h1>\n". 26 "<h1>Voting system</h1>\n".
27 stGetFormStart("vote", "usrlogin.php"). 27 (stGetSessionItem("mode") == "error" ? "<p>ERROR occured, try again</p>." : "").
28 " ".stGetFormHiddenInput("mode", "key")."\n". 28 stGetFormStart("vote", "usrlogin.php").
29 " ".stGetFormHiddenInput("goto", "vote")."\n". 29 " ".stGetFormHiddenInput("mode", "vote")."\n".
30 " <div class=\"votectrl\">\n". 30 " ".stGetFormHiddenInput("goto", "vote")."\n".
31 " Enter your vote key:\n". 31 " <div class=\"votectrl\">\n".
32 " ".stGetFormTextInput($userKeyLen > 30 ? $userKeyLen : 30, $userKeyLen, 30, "key", "", "", stGetSessionItem("key"), "autocomplete=\"off\"")."\n". 32 " Enter your vote key:\n".
33 " ".stGetFormSubmitInput("login", "Login")."\n". 33 " ".stGetFormTextInput($userKeyLen > 30 ? $userKeyLen : 30, $userKeyLen, "key", "", "", "", "autocomplete=\"off\"")."\n".
34 " </div>\n". 34 " ".stGetFormSubmitInput("login", "Login")."\n".
35 "</form>\n"; 35 " </div>\n".
36 "</form>\n";
36 } 37 }
37 else 38 else
38 if ($status == 1) 39 if (($mode = stGetSessionItem("mode")) == "vote")
39 { 40 {
41 ?>
42 <script type="text/javascript">
43 // <? include "ajax.js"; ?>
44 </script>
45 <?
40 stGetCompoList(TRUE, TRUE); 46 stGetCompoList(TRUE, TRUE);
41 47
42 // Try fetching previously stored votes 48 // Try fetching previously stored votes
43 $sql = stPrepareSQL( 49 $sql = stPrepareSQL(
44 "SELECT * FROM votes WHERE voter_id=%d", 50 "SELECT * FROM votes WHERE voter_id=%d",
53 } 59 }
54 60
55 // Output voting system HTML 61 // Output voting system HTML
56 echo 62 echo
57 "<h1>Voting system</h1>\n". 63 "<h1>Voting system</h1>\n".
58 stGetFormStart("vote", "vsubmit.php"). 64 stGetFormStart("vote", "usrvote.php").
59 " ".stGetFormHiddenInput("mode", "vote")."\n". 65 " ".stGetFormHiddenInput("mode", "vote")."\n".
60 " ".stGetFormHiddenInput("goto", "vote")."\n". 66 " ".stGetFormHiddenInput("goto", "vote")."\n".
61 " ".stGetFormHiddenInput("key", stGetSessionItem("key"))."\n". 67 " ".stGetFormHiddenInput("key", stGetSessionItem("key"))."\n".
62 " <div class=\"votectrl\">".stGetFormSubmitInput("vote", "Submit votes!")."</div>\n"; 68 stGetVoteButton();
63 69
64 foreach ($compos as $id => $compo) 70 foreach ($compos as $id => $compo)
65 if (count($compo["entries"]) > 0) 71 if (count($compo["entries"]) > 0)
66 { 72 {
67 echo 73 echo
107 echo 113 echo
108 " </table>\n"; 114 " </table>\n";
109 } 115 }
110 116
111 echo 117 echo
112 " <div class=\"votectrl\">".stGetFormSubmitInput("vote", "Submit votes!")."</div>\n". 118 stGetVoteButton().
113 "</form>\n"; 119 "</form>\n";
114 } 120 }
115 else 121 else
116 if ($status == 2) 122 if ($mode == "done")
117 { 123 {
118 // Voting finished 124 // Voting finished
119 echo "<h1>Yay, you have voted!</h1>\n". 125 echo "<h1>Yay, you have voted!</h1>\n".
120 "<p>Now go FAP some more! And make a demo about it.</p>"; 126 "<p>Now go FAP some more! And make a demo about it.</p>";
121 stSessionEnd(SESS_USER); 127 stSessionEnd(SESS_USER);
122 } 128 }
123 ?> 129 ?>