changeset 417:d2ece5d0aaa4

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 05 Dec 2013 18:48:43 +0200
parents 876846d8ed5b
children 0688a1d2122e
files admajax.php showajax.php
diffstat 2 files changed, 63 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/admajax.php	Thu Dec 05 17:55:07 2013 +0200
+++ b/admajax.php	Thu Dec 05 18:48:43 2013 +0200
@@ -206,7 +206,7 @@
 }
 
 
-function stGetInfoCurrEntryData()
+function stGetInfoCurrEntryData($indent)
 {
   $compoID = stGetDisplayVar("compoID");
   if ($compoID > 0)
@@ -222,13 +222,13 @@
     $strCompo = $strCurrEntry = $strPrevEntry = "-";
 
   return
-    "    <div>Current compo:<br /><b>".$strCompo."</b></div>\n".
-    "    <div>Current entry:<br /><b>".$strCurrEntry."</b></div>\n".
-    "    <div>Previous entry:<br /><b>".$strPrevEntry."</b></div>\n";
+    $indent."<div>Current compo:<br /><b>".$strCompo."</b></div>\n".
+    $indent."<div>Current entry:<br /><b>".$strCurrEntry."</b></div>\n".
+    $indent."<div>Previous entry:<br /><b>".$strPrevEntry."</b></div>\n";
 }
 
 
-function stGetInfoCurrEntryList()
+function stGetInfoCurrEntryList($indent, $outer)
 {
   $sql = stPrepareSQL(
     "SELECT * FROM entries WHERE compo_id=%d ORDER BY show_id ASC",
@@ -238,19 +238,48 @@
   if ($currShowID <= 0)
     $currShowID = -1;
 
-  $str = "    ".stGetOptionListStart("ctrlEntryList");
+  $str = stGetOptionListStart("ctrlEntryList", $indent, $outer);
 
   if (($res = stExecSQL($sql)) !== false)
   {
     foreach ($res as $item)
     {
-      $str .=
-        "    ".stGetOptionListItem($item["show_id"],
+      $str .= $indent."  ".
+        stGetOptionListItem($item["show_id"],
         ($item["show_id"] == $currShowID),
         sprintf("%3d. %s by %s", $item["show_id"], $item["name"], $item["author"]));
     }
   }
-  return $str."    ".stGetOptionListEnd();
+  
+  $str .= stGetOptionListEnd($indent, $outer);
+  return $str;
+}
+
+
+function stGetInfoRotationLists($indent, $outer)
+{
+  $sql =
+    "SELECT rotationListData.*, ".
+    "(SELECT COUNT(*) FROM rotationListSlides WHERE list_id=rotationListData.id) AS nslides ".
+    "FROM rotationListData ".
+    "LEFT JOIN rotationListSlides ON rotationListData.id=rotationListSlides.list_id ".
+    "ORDER BY id DESC";
+
+  $str = stGetOptionListStart("ctrlRotationLists", $indent, $outer);
+
+  if (($res = stExecSQL($sql)) !== false)
+  {
+    foreach ($res as $item)
+    {
+      $str .= $indent."  ".
+        stGetOptionListItem($item["id"],
+        ($currListID == $item["id"]),
+        $item["name"]." (".$item["nslides"]." slides)");
+    }
+  }
+
+  $str .= stGetOptionListEnd($indent, $outer);
+  return $str;
 }
 
 
@@ -260,11 +289,11 @@
 }
 
 
-function stGetOptionListStart($id, $size = 10, $onChange = "")
+function stGetOptionListStart($id, $indent, $outer, $size = 10, $onChange = "")
 {
   return
-    "<div id=\"".$id."\">\n".
-    "<select class=\"selectBox\" id=\"".$id."Sel\" size=\"".$size."\"".
+    ($outer ? $indent."<div id=\"".$id."\">\n" : "").
+    $indent."<select class=\"selectBox\" id=\"".$id."Sel\" size=\"".$size."\"".
     ($onChange != "" ? " onChange=\"".$onChange."\"" : "").">\n";
 }
 
@@ -278,9 +307,11 @@
 }
 
 
-function stGetOptionListEnd()
+function stGetOptionListEnd($indent, $outer)
 {
-  return "</select>\n"."</div>\n";
+  return
+    $indent."</select>\n".
+    ($outer ? $indent."</div>\n" : "");
 }
 
 
@@ -524,11 +555,15 @@
     switch ($type)
     {
       case "infoCurrEntryData":
-        echo stGetInfoCurrEntryData();
+        echo stGetInfoCurrEntryData("", FALSE);
         break;
 
       case "infoCurrEntryList":
-        echo stGetInfoCurrEntryList();
+        echo stGetInfoCurrEntryList("", FALSE);
+        break;
+      
+      case "infoRotationLists":
+        echo stGetInfoRotationLists("", FALSE);
         break;
     
       case "infoEditRotationList":
@@ -536,7 +571,7 @@
           "<div class=\"ctrlBox\" id=\"ctrlEditRotationList\">\n".
           "  <div class=\"ctrlTitle\">Edit rotation list</div>\n".
           "  ".stGetFormTextInput(30, 128, "ctrlEDRotationListName", "", "", "")."<br />\n".
-          "  ".stGetOptionListSTart("ctrlEDRotationList");
+          stGetOptionListStart("ctrlEDRotationList", "  ", TRUE);
 
         $sql = "SELECT * FROM displaySlides";
         if (($res = stExecSQL($sql)) !== false)
@@ -553,8 +588,8 @@
           $list_id);
 
         echo
-          "  ".stGetOptionListEnd().
-          "  ".stGetOptionListStart("ctrlEDDisplaySlides");
+          stGetOptionListEnd("  ", TRUE).
+          stGetOptionListStart("ctrlEDDisplaySlides", "  ", TRUE);
 
         if (($res = stExecSQL($sql)) !== false)
         {
@@ -563,7 +598,7 @@
         }
 
         echo
-          "  ".stGetOptionListEnd().
+          stGetOptionListEnd("  ", TRUE).
           "  <div class=\"ctrlButtons\">\n".
           "    ".stGetFormButtonInput("moveslideup", "", "", "Move Up", "moveListSlide(-1)")."\n".
           "    ".stGetFormButtonInput("moveslidedn", "", "", "Move Down", "moveListSlide(1)")."\n".
@@ -607,21 +642,7 @@
         echo
           "<div class=\"ctrlBox\" id=\"ctrlListRotationLists\">\n".
           "  <div class=\"ctrlTitle\">Rotation lists:</div>\n".
-          "  ".stGetOptionListStart("ctrlRotationLists");
-
-        $sql =
-          "SELECT rotationListData.* FROM rotationListData ".
-          "LEFT JOIN rotationListSlides ON ".
-          "ORDER BY id DESC";
-
-        if (($res = stExecSQL($sql)) !== false)
-        {
-          foreach ($res as $item)
-            echo "    ".stGetOptionListItem($item["id"], FALSE, $item["name"]);
-        }
-
-        echo
-          "  ".stGetOptionListEnd().
+          stGetInfoRotationLists("    ", TRUE).
           "  <div class=\"ctrlButtons\">\n".
           "    ".stGetFormButtonInput("actlist", "", "", "Set Active", "activateRotationList()")."\n".
           "    ".stGetFormButtonInput("editlist", "", "", "Edit", "editRotationList()")."\n".
@@ -633,7 +654,7 @@
         echo
           "<div class=\"ctrlBox\" id=\"ctrlListDisplaySlides\">\n".
           "<div class=\"ctrlTitle\">Display slides:</div>\n".
-          "  ".stGetOptionListStart("ctrlDisplaySlides");
+          stGetOptionListStart("ctrlDisplaySlides", "  ", TRUE);
 
         $sql = "SELECT * FROM displaySlides ORDER BY id DESC";
         if (($res = stExecSQL($sql)) !== false)
@@ -643,7 +664,7 @@
         }
 
         echo
-          "  ".stGetOptionListEnd().
+          stGetOptionListEnd("  ", TRUE).
           "  <div class=\"ctrlButtons\">\n".
           "    ".stGetFormTextInput(3, 5, "tempDuration", "", "", stGetDisplayVar("tempDuration"))." min\n".
           "    ".stGetFormButtonInput("setslide", "", "", "Set Temp", "activateTempSlide()")."\n".
@@ -657,7 +678,7 @@
           "<div class=\"ctrlBox\" id=\"ctrlCompoControl\">\n".
           "  <div class=\"ctrlTitle\">Competition control:</div>\n".
           "  <div class=\"ctrlDBox1\">\n".
-          "    ".stGetOptionListStart("ctrlCompoList");
+          stGetOptionListStart("ctrlCompoList", "    ", TRUE);
 
         $sql =
           "SELECT compos.*, ".
@@ -677,7 +698,7 @@
         }
 
         echo
-          "    ".stGetOptionListEnd().
+          stGetOptionListEnd("    ", TRUE).
           "    <div class=\"ctrlButtons\">\n".
           "      ".stGetFormButtonInput("setcompo", "", "", "Change compo", "activateCompo()")."\n".
           "    </div>\n".
@@ -685,7 +706,7 @@
         
         echo
           "  <div class=\"ctrlDBox1\">\n".
-          stGetInfoCurrEntryList().
+          stGetInfoCurrEntryList("    ", TRUE).
           "    <div class=\"ctrlButtons\">\n".
           "      ".stGetFormButtonInput("setentry", "", "", "Set selected entry", "setSelectedEntry()")."\n".
           "      ".stGetFormButtonInput("preventry", "", "", "Prev entry", "switchEntry(-1)")."\n".
@@ -693,7 +714,7 @@
           "    </div>\n".
           "  </div>\n".
           "  <div class=\"ctrlDBox2\" id=\"ctrlCurrEntryData\">\n".
-          stGetInfoCurrEntryData().
+          stGetInfoCurrEntryData("    ").
           "  </div>\n".
           "</div>\n";
         break;
--- a/showajax.php	Thu Dec 05 17:55:07 2013 +0200
+++ b/showajax.php	Thu Dec 05 18:48:43 2013 +0200
@@ -250,5 +250,5 @@
 // Save changed variables
 stSaveDisplayVars();
 
-stDumpAJAXStatusErrors();
+//stDumpAJAXStatusErrors();
 ?>
\ No newline at end of file