# HG changeset patch # User Matti Hamalainen # Date 1386078607 -7200 # Node ID ff8462a80cf2700497144b2699ef4c87e5984912 # Parent f09b4c08a920e0cba51cb3e33103791db2773eb0 Moar work. diff -r f09b4c08a920 -r ff8462a80cf2 admajax.php --- a/admajax.php Tue Dec 03 15:36:53 2013 +0200 +++ b/admajax.php Tue Dec 03 15:50:07 2013 +0200 @@ -198,18 +198,37 @@ } -function stRandomizeCompoShowOrder($compo_id) { - $entries = stExecSQL("SELECT id FROM entries WHERE compo_id=".$compo_id); +function stRandomizeCompoShowOrder($compo_id, $patch) +{ + $entries = stExecSQL("SELECT id,show_id FROM entries WHERE compo_id=".$compo_id); if ($entries !== FALSE) { $final = array(); - foreach ($entries as $entry) - $final[] = $entry["id"]; + + if ($patch) + { + $iindex = -1; + foreach ($entries as $entry) + { + if ($entry["show_id"] == 0) + $final[] = $entry["id"]; - shuffle($final); + if ($entry["show_id"] > $index) + $index = $entry["show_id"]; + } + + $index++; + } + else + { + foreach ($entries as $entry) + $final[] = $entry["id"]; - $index = 1; + shuffle($final); + $index = 1; + } + foreach ($final as $entry) { $sql = stPrepareSQL("UPDATE entries SET show_id=%d WHERE id=%d", $index, $entry); @@ -258,20 +277,21 @@ // // Randomize entries display order // + $patch = intval(stGetRequestItem("patch", 1)); if ($type == "all") { if (($compos = stExecSQL("SELECT id FROM compos")) === FALSE) stError("Eh? SQL error occured."); else foreach ($compos as $compo) - stRandomizeCompoShowOrder($compo["id"]); + stRandomizeCompoShowOrder($compo["id"], $patch); } else if ($type == "compo") { if (stChkRequestItem("id", $compo_id, array(CHK_TYPE, VT_INT, "Invalid data."))) { - stRandomizeCompoShowOrder($compo_id); + stRandomizeCompoShowOrder($compo_id, $patch); } } else @@ -282,10 +302,10 @@ else foreach ($compos as $compo) { - $nentries = stFetchSQLColumn("SELECT COUNT(*) FROM entries WHERE show_id<>0 AND compo_id=".$compo["id"]); + $nentries = stFetchSQLColumn("SELECT COUNT(*) FROM entries WHERE show_id=0 AND compo_id=".$compo["id"]); if ($nentries > 0) { - stError("Compo #".$compo["id"]." - ".$compo["name"]." has show order set for at least some entries."); + stError("Compo #".$compo["id"]." - ".$compo["name"]." has NO show order set for some entries."); } } }