changeset 373:ff8462a80cf2

Moar work.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 03 Dec 2013 15:50:07 +0200
parents f09b4c08a920
children 9c4accca7bf8
files admajax.php
diffstat 1 files changed, 30 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- 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.");
         }
       }
     }