changeset 371:1a7f97a36047

Modularize some more.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 03 Dec 2013 15:31:24 +0200
parents d65f28bf1080
children f09b4c08a920
files admajax.php
diffstat 1 files changed, 33 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- 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