# HG changeset patch # User Matti Hamalainen # Date 1386077484 -7200 # Node ID 1a7f97a3604766d47096cca2e5bd59278192bd9b # Parent d65f28bf108091c3d809e8b5d84ca363852ab56e Modularize some more. diff -r d65f28bf1080 -r 1a7f97a36047 admajax.php --- a/admajax.php Tue Dec 03 15:22:57 2013 +0200 +++ b/admajax.php Tue Dec 03 15:31:24 2013 +0200 @@ -198,6 +198,30 @@ } +function stRandomizeCompoShowOrder($compo_id) +{ + $entries = stExecSQL("SELECT id FROM entries WHERE compo_id=".$compo_id); + if ($entries !== FALSE) + { + $final = array(); + foreach ($entries as $entry) + $final[] = $entry["id"]; + + $index = 1; + foreach ($final as $entry) + { + $sql = stPrepareSQL("UPDATE entries SET show_id=%d WHERE id=%d", $index, $entry); + if (stExecSQL($sql) === false) + { + stError("Error updating entry show positions."); + break; + } + $index++; + } + } +} + + // // Check if we are allowed to execute // @@ -232,32 +256,20 @@ // // Randomize entries display order // - if ($type == "set") + if ($type == "all") { - if (($compos = stExecSQL("SELECT * FROM compos")) === FALSE) + if (($compos = stExecSQL("SELECT id FROM compos")) === FALSE) stError("Eh? SQL error occured."); else foreach ($compos as $compo) + stRandomizeCompoShowOrder($compo["id"]); + } + else + if ($type == "compo") + { + if (stChkRequestItem("id", $compo_id, array(CHK_TYPE, VT_INT, "Invalid data."))) { - $entries = stExecSQL("SELECT id FROM entries WHERE compo_id=".$compo["id"]); - if ($entries !== FALSE) - { - $final = array(); - foreach ($entries as $entry) - $final[] = $entry["id"]; - - $index = 1; - foreach ($final as $entry) - { - $sql = stPrepareSQL("UPDATE entries SET show_id=%d WHERE id=%d", $index, $entry); - if (stExecSQL($sql) === false) - { - stError("Error updating entry show positions."); - break; - } - $index++; - } - } + stRandomizeCompoShowOrder($compo_id); } } else