# HG changeset patch # User Matti Hamalainen # Date 1381472984 -10800 # Node ID 3ae137411706225cda195d86de808cc3c5020601 # Parent 23eba98e157501737ade8fc4c29ee54f460e5748 More work. diff -r 23eba98e1575 -r 3ae137411706 vote.inc.php --- 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 "

Sorry, voting disabled!

\n". "

Voting functionality not available at this time.

\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 + "

Voting system

\n". + stGetFormStart("vote", "usrlogin.php"). + " ".stGetFormHiddenInput("mode", "key")."\n". + " ".stGetFormHiddenInput("goto", "vote")."\n". + "
\n". + " Enter your vote key:\n". + " ".stGetFormTextInput(30, 30, "key", "", "", stGetSessionItem("key"), "autocomplete=\"off\"")."\n". + " ".stGetFormSubmitInput("login", "Login")."\n". + "
\n". + "\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 + "

Voting system

\n". + stGetFormStart("vote", "vsubmit.php"). + " ".stGetFormHiddenInput("mode", "vote")."\n". + " ".stGetFormHiddenInput("goto", "vote")."\n". + " ".stGetFormHiddenInput("key", stGetSessionItem("key"))."\n". + "
".stGetFormSubmitInput("vote", "Submit votes!")."
\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 - "

Voting system

\n". - stGetFormStart("vote", "vsubmit.php"). - " ".stGetFormHiddenInput("mode", "vote")."\n". - " ".stGetFormHiddenInput("goto", "vote")."\n". - " ".stGetFormHiddenInput("key", stGetSessionItem("key"))."\n". - "
".stGetFormSubmitInput("vote", "Submit votes!")."
\n"; + " \n". + " \n". + " \n". + " \n". + ($compo["showAuthors"] ? " \n" : ""). + " "; - foreach ($compos as $id => $compo) - if (count($compo["entries"]) > 0) + for ($i = stGetSetting("voteMin"); $i <= stGetSetting("voteMax"); $i++) { echo - "
".chentities($compo["name"])."
TitleAuthor
\n". - " \n". - " \n". - " \n". - ($compo["showAuthors"] ? " \n" : ""). + ""; + } + echo "\n". + " \n"; + + $row = 0; + foreach ($compo["entries"] as $eid => $entry) + { + echo + " \n". + " \n". + ($compo["showAuthors"] ? " \n" : ""). " "; for ($i = stGetSetting("voteMin"); $i <= stGetSetting("voteMax"); $i++) { + $name = "entry".$eid; echo - ""; + ""; } - echo "\n". + + echo + "\n". " \n"; - $row = 0; - foreach ($compo["entries"] as $eid => $entry) - { - echo - " \n". - " \n". - ($compo["showAuthors"] ? " \n" : ""). - " "; - - for ($i = stGetSetting("voteMin"); $i <= stGetSetting("voteMax"); $i++) - { - $name = "entry".$eid; - echo - ""; - } + $row++; + } + echo + "
".chentities($compo["name"])."
TitleAuthor".$i."
".$entry["name"]."".$entry["author"]."".$i."". + stGetFormRadioButtonInput($name, "", "", $i, ($i == stGetSessionItem($name, 0)), ""). + "
".$entry["name"]."".$entry["author"]."". - stGetFormRadioButtonInput($name, "", "", $i, ($i == stGetSessionItem($name, 0)), ""). - "
\n"; + } - echo - "\n". - " \n"; - - $row++; - } - echo - " \n"; - } - - echo - "
".stGetFormSubmitInput("vote", "Submit votes!")."
\n". - "\n"; - } - else - if ($status == 2) - { - echo "

Yay, you have voted!

\n". - "

Now go FAP some more! And make a demo about it.

"; - stSessionEnd(SESS_USER); - } + echo + "
".stGetFormSubmitInput("vote", "Submit votes!")."
\n". + "\n"; +} +else +if ($status == 2) +{ + // Voting finished + echo "

Yay, you have voted!

\n". + "

Now go FAP some more! And make a demo about it.

"; + stSessionEnd(SESS_USER); } ?> \ No newline at end of file