view 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
line wrap: on
line source

<?
$sessionType = "vote";

// 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";

  $status = -1;
}
else
if (stUserSessionAuth())
{
  $status = stGetSessionItem("status");
  stStartSubmitStatus($status, "vote", "vsubmit.php", "Vote system");
} else
  $status = 0;

  
if ($status == 0)
{
  echo
  "<h1>Voting system</h1>\n".
  stGetFormStart("vote", "usrlogin.php").
  " ".stGetFormHiddenInput("mode", "key")."\n".
  " ".stGetFormHiddenInput("goto", "vote")."\n".
  " <div class=\"votectrl\">\n".
  "  Enter your vote key:\n".
  "  ".stGetFormTextInput(30, 30, "key", "", "", stGetSessionItem("key"), "autocomplete=\"off\"")."\n".
  "  ".stGetFormSubmitInput("login", "Login")."\n".
  " </div>\n".
  "</form>\n";
}
else
if ($status == 1)
{
  stGetCompoList(TRUE, TRUE);

  // Try fetching previously stored votes
  $sql = stPrepareSQL(
    "SELECT * FROM votes WHERE voter_id=%d",
    stGetSessionItem("user_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", "vsubmit.php").
  " ".stGetFormHiddenInput("mode", "vote")."\n".
  " ".stGetFormHiddenInput("goto", "vote")."\n".
  " ".stGetFormHiddenInput("key", stGetSessionItem("key"))."\n".
  " <div class=\"votectrl\">".stGetFormSubmitInput("vote", "Submit votes!")."</div>\n";

  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=\"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
  " <div class=\"votectrl\">".stGetFormSubmitInput("vote", "Submit votes!")."</div>\n".
  "</form>\n";
}
else
if ($status == 2)
{
  // 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);
}
?>