changeset 153:aecf145e7c70

Some work on the voting backend.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 25 Oct 2013 15:07:43 +0300
parents 6e6fba2da3d1
children 9055cfa14104
files usrajax.php
diffstat 1 files changed, 26 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/usrajax.php	Fri Oct 25 02:10:14 2013 +0300
+++ b/usrajax.php	Fri Oct 25 15:07:43 2013 +0300
@@ -92,14 +92,35 @@
 
   case "set":
     //
-    // Set vote
+    // Set vote, if voting is enabled
     //
-    if ($type == "votes" && stChkRequestItem("voter_id") &&
-      stChkRequestItem("entry_id") && stChkRequestItem("vote"))
+    if ($type == "votes" && stChkSetting("allowVoting") &&
+      stChkRequestItem("votekey") &&
+      stChkRequestItem("entry_id") &&
+      stChkRequestItem("vote"))
     {
-      stGetCompoList(FALSE);
+      // Check if voting is enabled on the compo and voter is valid
+      $entry_id = stGetRequestItem("entry_id");
+
+      $sql = stPrepareSQL("SELECT * FROM votekeys WHERE key=%s", stGetRequestItem("votekey"));
+      if (($votekey = stFetchSQLColumn($sql)) !== false)
+      {
+      }
       
-      stSubmitOneVote(stGetRequestItem("voter_id"), stGetRequestItem("entry_id"), stGetRequestItem("vote"));
+
+      $sql = stPrepareSQL("SELECT * FROM entries WHERE id=%d", $entry_id);
+      if (($entry = stFetchSQL($sql)) !== false)
+      {
+        if (($compo = stFetchSQL("SELECT * FROM compos WHERE id=".$entry["compo_id"])) !== false
+          && $compo["voting"] != 0)
+        {
+          stSubmitOneVote(stGetRequestItem("voter_id"), $entry_id, stGetRequestItem("vote"));
+        }
+        else
+          stSetStatus(902, "Voting not enabled on that compo.");
+      }
+      else
+        stSetStatus(902, "No such entry.");
     }
     else
       stSetStatus(902, "No data.");