view vote.inc.php @ 120:2c594958050e

Make test vote keys "testN" where N >= 1
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 22 Oct 2013 14:22:26 +0300
parents 9a52fa9d4ecc
children 71c35d5302c2
line wrap: on
line source

<?
$sessionType = "user";
$userKeyLen = stGetSetting("userKeyLength");


function stGetVoteButton()
{
  return
    "<div class=\"votectrl\">".
    stGetFormSubmitInput("vote", "Submit votes!", "return false").
    "</div>\n";
}

// Check if voting is enabled
if (!stChkSetting("allowVoting"))
{
  echo
  "<h1>Sorry, voting disabled!</h1>\n".
  "<p>Voting functionality not available at this time.</p>\n";
}
else
if (!stUserSessionAuth(FALSE))
{
  // Perform authentication if we are not in session already
  echo
    "<h1>Voting system</h1>\n".
    (stGetSessionItem("mode") == "error" ? "<p>ERROR occured, try again</p>." : "").
    stGetFormStart("vote", "usrlogin.php").
    " ".stGetFormHiddenInput("mode", "vote")."\n".
    " ".stGetFormHiddenInput("goto", "vote")."\n".
    " <div class=\"votectrl\">\n".
    "  Enter your vote key:\n".
    "  ".stGetFormTextInput($userKeyLen > 30 ? $userKeyLen : 30, $userKeyLen, "key", "", "", "", "autocomplete=\"off\"")."\n".
    "  ".stGetFormSubmitInput("login", "Login")."\n".
    " </div>\n".
    "</form>\n";
}
else
if (($mode = stGetSessionItem("mode")) == "vote")
{
?>
<script type="text/javascript">
// <? include "ajax.js"; ?>
</script>
<?
  stGetCompoList(TRUE, TRUE);

  // Try fetching previously stored votes
  $sql = stPrepareSQL(
    "SELECT * FROM votes WHERE voter_id=%d",
    stGetSessionItem("voter_id"));

  if (($res = stExecSQL($sql)) !== false)
  {
    foreach ($res as $vote)
    {
      stSetSessionItem("entry".$vote["entry_id"], $vote["value"]);
    }
  }

  // Output voting system HTML
  echo
  "<h1>Voting system</h1>\n".
  stGetFormStart("vote", "usrvote.php").
  " ".stGetFormHiddenInput("mode", "vote")."\n".
  " ".stGetFormHiddenInput("goto", "vote")."\n".
  " ".stGetFormHiddenInput("key", stGetSessionItem("key"))."\n".
  stGetVoteButton();

  foreach ($compos as $id => $compo)
  if (count($compo["entries"]) > 0)
  {
    echo
    " <table class=\"vote\">\n".
    "  <tr><th colspan=\"3\">".chentities($compo["name"])."</th></tr>\n".
    "  <tr>\n".
    "   <th class=\"vtitle\">Title</th>\n".
    ($compo["showAuthors"] ? "   <th class=\"vauthor\">Author</th>\n" : "").
    "   ";

    for ($i = stGetSetting("voteMin"); $i <= stGetSetting("voteMax"); $i++)
    {
      echo
      "<th class=\"vvalue\">".$i."</th>";
    }
    echo "\n".
    "  </tr>\n";

    $row = 0;
    foreach ($compo["entries"] as $eid => $entry)
    {
      echo
      "  <tr class=\"".($row % 2 == 1 ? "rodd" : "reven")."\">\n".
      "   <td class=\"show_id\">".($entry["show_id"] > 0 ? $entry["show_id"] : "-")."</td>\n".
      "   <td class=\"vtitle\">".$entry["name"]."</td>\n".
      ($compo["showAuthors"] ? "   <td class=\"vauthor\">".$entry["author"]."</td>\n" : "").
      "   ";

      for ($i = stGetSetting("voteMin"); $i <= stGetSetting("voteMax"); $i++)
      {
        $name = "entry".$eid;
        echo
          "<td class=\"vvalue\">".
          stGetFormRadioButtonInput($name, "", "", $i, ($i == stGetSessionItem($name, 0)), "").
          "</td>";
      }

      echo
      "\n".
      "  </tr>\n";

      $row++;
    }
    echo
    " </table>\n";
  }

  echo
  stGetVoteButton().
  "</form>\n";
}
else
if ($mode == "done")
{
  // Voting finished
  echo "<h1>Yay, you have voted!</h1>\n".
  "<p>Now go FAP some more! And make a demo about it.</p>";
  stSessionEnd(SESS_USER);
}
?>