# HG changeset patch # User Matti Hamalainen # Date 1386276203 -7200 # Node ID 7f950ab60be46a75e3e0b343d543e3114262c9c1 # Parent d948f1f12b23a871cc19437a815559ee1729ffbb Cleanups. diff -r d948f1f12b23 -r 7f950ab60be4 admajax.php --- a/admajax.php Thu Dec 05 22:31:23 2013 +0200 +++ b/admajax.php Thu Dec 05 22:43:23 2013 +0200 @@ -1278,7 +1278,7 @@ if ($type == "attendees" && stValidateRequestUserData(TRUE)) { $sql = stPrepareSQLUpdate("attendees", - "WHERE id=".intval(stGetRequestItem("id")), + "WHERE id=".$id, array( "name" => "S", "groups" => "S", @@ -1292,7 +1292,7 @@ if ($type == "news" && stValidateRequestNewsData()) { $sql = stPrepareSQLUpdate("news", - "WHERE id=".intval(stGetRequestItem("id")), + "WHERE id=".$id, array( "title" => "S", "text" => "Q", @@ -1305,7 +1305,7 @@ if ($type == "compo" && stValidateRequestCompoData(TRUE)) { $sql = stPrepareSQLUpdate("compos", - "WHERE id=".intval(stGetRequestItem("id")), + "WHERE id=".$id, array( "name" => "S", "description" => "Q", @@ -1326,7 +1326,7 @@ else { $sql = stPrepareSQLUpdate("entries", - "WHERE id=".intval(stGetRequestItem("id")), + "WHERE id=".$id, array( "name" => "S", "author" => "S", @@ -1338,42 +1338,44 @@ stExecSQLCond($sql, "OK, entry updated."); } } - else - if ($type == "votekey") + } + break; + + case "votekey": + if (stChkRequestItem("id", $id, array(CHK_TYPE, VT_INT, "Invalid data."))) + { + switch ($type) { - switch (stGetRequestItem("mode")) - { - case "assign": - // Check if already assigned to someone .. - $key_id = intval(stGetRequestItem("key_id", 0)); - $sql = stPrepareSQL("SELECT * FROM votekeys WHERE id=%d", $key_id); - if (stFetchSQL($sql) === false) - stError("Invalid key ID #."); + case "assign": + // Check if already assigned to someone .. + $key_id = intval(stGetRequestItem("key_id", 0)); + $sql = stPrepareSQL("SELECT * FROM votekeys WHERE id=%d", $key_id); + if (stFetchSQL($sql) === false) + stError("Invalid key ID #."); + else + { + $sql = stPrepareSQL("SELECT * FROM attendees WHERE key_id=%d", $key_id); + if (($attn = stFetchSQL($sql)) !== false && $attn["id"] != $id) + stError("That key has already been assigned to another attendee!"); else { - $sql = stPrepareSQL("SELECT * FROM attendees WHERE key_id=%d", $key_id); - if (($attn = stFetchSQL($sql)) !== false && $attn["id"] != $id) - stError("That key has already been assigned to another attendee!"); - else - { - // Assign .. - $sql = stPrepareSQL("UPDATE attendees SET key_id=%d WHERE id=%d", $key_id, $id); - stExecSQLCond($sql, "Assigned key updated."); - } + // Assign .. + $sql = stPrepareSQL("UPDATE attendees SET key_id=%d WHERE id=%d", $key_id, $id); + stExecSQLCond($sql, "Assigned key updated."); } - break; + } + break; - case "clear": - $sql = stPrepareSQL("UPDATE attendees SET key_id=NULL WHERE id=%D", "id"); - stExecSQLCond($sql, "Assigned key cleared."); - break; - - case "active": - // Autobots activate! - $sql = stPrepareSQL("UPDATE votekeys SET active=%B WHERE id=%D", "active", "id"); - stExecSQLCond($sql, "Votekey status changed."); - break; - } + case "clear": + $sql = stPrepareSQL("UPDATE attendees SET key_id=NULL WHERE id=%d", $id); + stExecSQLCond($sql, "Assigned key cleared."); + break; + + case "active": + // Autobots activate! + $sql = stPrepareSQL("UPDATE votekeys SET active=%B WHERE id=%d", "active", $id); + stExecSQLCond($sql, "Votekey status changed."); + break; } } break; diff -r d948f1f12b23 -r 7f950ab60be4 admin.php --- a/admin.php Thu Dec 05 22:31:23 2013 +0200 +++ b/admin.php Thu Dec 05 22:43:23 2013 +0200 @@ -441,14 +441,14 @@ } -function voteKeyUpdate(id, mode, args) +function voteKeyUpdate(id, type, args) { var msuccess = function(txt) { voteKeyRefresh(id); } - jsSendPOSTRequest("action=update&type=votekey&mode="+mode+"&id="+id+"&"+args, msuccess); + jsSendPOSTRequest("action=votekey&type="+type+"&id="+id+"&"+args, msuccess); }