comparison vote.inc.php @ 68:3ae137411706

More work.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 11 Oct 2013 09:29:44 +0300
parents 4fac95384753
children b75f99a8973c
comparison
equal deleted inserted replaced
67:23eba98e1575 68:3ae137411706
5 if (!stChkSetting("allowVoting")) 5 if (!stChkSetting("allowVoting"))
6 { 6 {
7 echo 7 echo
8 "<h1>Sorry, voting disabled!</h1>\n". 8 "<h1>Sorry, voting disabled!</h1>\n".
9 "<p>Voting functionality not available at this time.</p>\n"; 9 "<p>Voting functionality not available at this time.</p>\n";
10
11 $status = -1;
10 } 12 }
11 else 13 else
12 if (stUserSessionAuth()) 14 if (stUserSessionAuth())
13 { 15 {
14 $authState = "ok"; 16 $status = stGetSessionItem("status");
17 stStartSubmitStatus($status, "vote", "vsubmit.php", "Vote system");
18 } else
19 $status = 0;
20
21
22 if ($status == 0)
23 {
24 echo
25 "<h1>Voting system</h1>\n".
26 stGetFormStart("vote", "usrlogin.php").
27 " ".stGetFormHiddenInput("mode", "key")."\n".
28 " ".stGetFormHiddenInput("goto", "vote")."\n".
29 " <div class=\"votectrl\">\n".
30 " Enter your vote key:\n".
31 " ".stGetFormTextInput(30, 30, "key", "", "", stGetSessionItem("key"), "autocomplete=\"off\"")."\n".
32 " ".stGetFormSubmitInput("login", "Login")."\n".
33 " </div>\n".
34 "</form>\n";
15 } 35 }
16 else 36 else
37 if ($status == 1)
17 { 38 {
18 39 stGetCompoList(TRUE, TRUE);
19 $authState = "login";
20 }
21 40
41 // Try fetching previously stored votes
42 $sql = stPrepareSQL(
43 "SELECT * FROM votes WHERE voter_id=%d",
44 stGetSessionItem("user_id"));
22 45
23 { 46 if (($res = stExecSQL($sql)) !== false)
24 $status = stGetSubmitStatus(); 47 {
48 foreach ($res as $vote)
49 {
50 stSetSessionItem("entry".$vote["entry_id"], $vote["value"]);
51 }
52 }
25 53
26 stStartSubmitStatus($status, "vote", "vsubmit.php", "Vote system"); 54 // Output voting system HTML
27 55 echo
28 if ($status == 1) 56 "<h1>Voting system</h1>\n".
57 stGetFormStart("vote", "vsubmit.php").
58 " ".stGetFormHiddenInput("mode", "vote")."\n".
59 " ".stGetFormHiddenInput("goto", "vote")."\n".
60 " ".stGetFormHiddenInput("key", stGetSessionItem("key"))."\n".
61 " <div class=\"votectrl\">".stGetFormSubmitInput("vote", "Submit votes!")."</div>\n";
62
63 foreach ($compos as $id => $compo)
64 if (count($compo["entries"]) > 0)
29 { 65 {
30 stGetCompoList(TRUE, TRUE); 66 echo
67 " <table class=\"vote\">\n".
68 " <tr><th colspan=\"3\">".chentities($compo["name"])."</th></tr>\n".
69 " <tr>\n".
70 " <th class=\"vtitle\">Title</th>\n".
71 ($compo["showAuthors"] ? " <th class=\"vauthor\">Author</th>\n" : "").
72 " ";
31 73
32 // Try fetching previously stored votes 74 for ($i = stGetSetting("voteMin"); $i <= stGetSetting("voteMax"); $i++)
33 $sql = stPrepareSQL(
34 "SELECT * FROM votes WHERE voter_id=%d",
35 stGetSessionItem("user_id"));
36
37 if (($res = stExecSQL($sql)) !== false)
38 {
39 foreach ($res as $vote)
40 {
41 stSetSessionItem("entry".$vote["entry_id"], $vote["value"]);
42 }
43 }
44
45 echo
46 "<h1>Voting system</h1>\n".
47 stGetFormStart("vote", "vsubmit.php").
48 " ".stGetFormHiddenInput("mode", "vote")."\n".
49 " ".stGetFormHiddenInput("goto", "vote")."\n".
50 " ".stGetFormHiddenInput("key", stGetSessionItem("key"))."\n".
51 " <div class=\"votectrl\">".stGetFormSubmitInput("vote", "Submit votes!")."</div>\n";
52
53 foreach ($compos as $id => $compo)
54 if (count($compo["entries"]) > 0)
55 { 75 {
56 echo 76 echo
57 " <table class=\"vote\">\n". 77 "<th class=\"vvalue\">".$i."</th>";
58 " <tr><th colspan=\"3\">".chentities($compo["name"])."</th></tr>\n". 78 }
59 " <tr>\n". 79 echo "\n".
60 " <th class=\"vtitle\">Title</th>\n". 80 " </tr>\n";
61 ($compo["showAuthors"] ? " <th class=\"vauthor\">Author</th>\n" : ""). 81
82 $row = 0;
83 foreach ($compo["entries"] as $eid => $entry)
84 {
85 echo
86 " <tr class=\"".($row % 2 == 1 ? "rodd" : "reven")."\">\n".
87 " <td class=\"vtitle\">".$entry["name"]."</td>\n".
88 ($compo["showAuthors"] ? " <td class=\"vauthor\">".$entry["author"]."</td>\n" : "").
62 " "; 89 " ";
63 90
64 for ($i = stGetSetting("voteMin"); $i <= stGetSetting("voteMax"); $i++) 91 for ($i = stGetSetting("voteMin"); $i <= stGetSetting("voteMax"); $i++)
65 { 92 {
93 $name = "entry".$eid;
66 echo 94 echo
67 "<th class=\"vvalue\">".$i."</th>"; 95 "<td class=\"vvalue\">".
96 stGetFormRadioButtonInput($name, "", "", $i, ($i == stGetSessionItem($name, 0)), "").
97 "</td>";
68 } 98 }
69 echo "\n". 99
100 echo
101 "\n".
70 " </tr>\n"; 102 " </tr>\n";
71 103
72 $row = 0; 104 $row++;
73 foreach ($compo["entries"] as $eid => $entry) 105 }
74 { 106 echo
75 echo 107 " </table>\n";
76 " <tr class=\"".($row % 2 == 1 ? "rodd" : "reven")."\">\n". 108 }
77 " <td class=\"vtitle\">".$entry["name"]."</td>\n".
78 ($compo["showAuthors"] ? " <td class=\"vauthor\">".$entry["author"]."</td>\n" : "").
79 " ";
80 109
81 for ($i = stGetSetting("voteMin"); $i <= stGetSetting("voteMax"); $i++) 110 echo
82 { 111 " <div class=\"votectrl\">".stGetFormSubmitInput("vote", "Submit votes!")."</div>\n".
83 $name = "entry".$eid; 112 "</form>\n";
84 echo 113 }
85 "<td class=\"vvalue\">". 114 else
86 stGetFormRadioButtonInput($name, "", "", $i, ($i == stGetSessionItem($name, 0)), ""). 115 if ($status == 2)
87 "</td>"; 116 {
88 } 117 // Voting finished
89 118 echo "<h1>Yay, you have voted!</h1>\n".
90 echo 119 "<p>Now go FAP some more! And make a demo about it.</p>";
91 "\n". 120 stSessionEnd(SESS_USER);
92 " </tr>\n";
93
94 $row++;
95 }
96 echo
97 " </table>\n";
98 }
99
100 echo
101 " <div class=\"votectrl\">".stGetFormSubmitInput("vote", "Submit votes!")."</div>\n".
102 "</form>\n";
103 }
104 else
105 if ($status == 2)
106 {
107 echo "<h1>Yay, you have voted!</h1>\n".
108 "<p>Now go FAP some more! And make a demo about it.</p>";
109 stSessionEnd(SESS_USER);
110 }
111 } 121 }
112 ?> 122 ?>