changeset 748:e0431e12f3ea

Change compo editing.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 20 Nov 2014 07:59:20 +0200
parents 330e6d79c5dc
children 56dc64256d31
files admajax.php
diffstat 1 files changed, 45 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/admajax.php	Thu Nov 20 07:57:53 2014 +0200
+++ b/admajax.php	Thu Nov 20 07:59:20 2014 +0200
@@ -32,22 +32,22 @@
     case COMPO_NORMAL:
       stChkRequestItemFail("voting", $fake, $res,
         array(CHK_TYPE, VT_BOOL, "Invalid data."));
+
+      stChkRequestItemFail("show_authors", $fake, $res,
+        array(CHK_TYPE, VT_BOOL, "Invalid data."));
+
+      stChkRequestItemFail("preview_type", $fake, $res,
+        array(CHK_TYPE, VT_INT, "Invalid data."),
+        array(CHK_RANGE, VT_INT, array(EPREV_NONE, EPREV_AUDIO), "Invalid preview type value."));
+
+      stChkRequestItemFail("cpath", $fake, $res,
+        array(CHK_LTEQ, VT_STR, SET_LEN_COMPO_PATH, "Compo file path too long."));
       break;
   }
 
   stChkRequestItemFail("visible", $fake, $res,
     array(CHK_TYPE, VT_BOOL, "Invalid data."));
 
-  stChkRequestItemFail("show_authors", $fake, $res,
-    array(CHK_TYPE, VT_BOOL, "Invalid data."));
-
-  stChkRequestItemFail("preview_type", $fake, $res,
-    array(CHK_TYPE, VT_INT, "Invalid data."),
-    array(CHK_RANGE, VT_INT, array(EPREV_NONE, EPREV_AUDIO), "Invalid preview type value."));
-
-  stChkRequestItemFail("cpath", $fake, $res,
-    array(CHK_LTEQ, VT_STR, SET_LEN_COMPO_PATH, "Compo file path too long."));
-
   return $res;
 }
 
@@ -121,12 +121,18 @@
   switch ($item["ctype"])
   {
     case COMPO_NORMAL:
-      $str = "  ".stGetFormCheckBoxInput("voting", $id, $prefix, $item["voting"],
-        "Enable voting", "onChange=\"setCompoData(".$id.",'voting')\"");
+      $str1 = 
+        "  File path: ".stGetFormTextInput(40, SET_LEN_COMPO_PATH, "cpath", $id, $prefix, $item["cpath"])."<br />\n";
+
+      $str2 =
+        "  ".stGetFormCheckBoxInput("voting", $id, $prefix, $item["voting"],
+        "Enable voting", "onChange=\"setCompoData(".$id.",'voting')\"").
+        "  ".stGetFormCheckBoxInput("show_authors", $id, $prefix, $item["show_authors"], "Show authors")."\n".
+        "  ".stGetFormOptionListFromArray($prefix."preview_type".$id, "  ", FALSE, $previewTypeList, $item["preview_type"], 0)."\n";
       break;
 
     default:
-      $str = "  ".stGetFormHiddenInput("voting", $id, $prefix, $item["voting"]);
+      $str1 = $str2 = "";
       break;
   }
 
@@ -135,12 +141,10 @@
     "  Type: ".stGetFormOptionListFromArray($prefix."type".$id, "  ", FALSE, $compoModeData, $item["ctype"], 0, "updateCompoType(".$id.")").
     " - ".$compoModeData[$item["ctype"]][1]."<br />\n".
     "  Name: ".stGetFormTextInput(40, SET_LEN_COMPO_NAME, "name", $id, $prefix, $item["name"])."<br />\n".
-    "  File path: ".stGetFormTextInput(40, SET_LEN_COMPO_PATH, "cpath", $id, $prefix, $item["cpath"])."<br />\n".
+    $str1.
     "  ".stGetFormTextArea(8, 60, "description", $id, $prefix, $item["description"])."<br />\n".
     "  ".stGetFormCheckBoxInput("visible", $id, $prefix, $item["visible"], "Visible")."\n".
-    "  ".stGetFormCheckBoxInput("show_authors", $id, $prefix, $item["show_authors"], "Show authors")."\n".
-    "  ".stGetFormOptionListFromArray($prefix."preview_type".$id, "  ", FALSE, $previewTypeList, $item["preview_type"], 0)."\n".
-    $str."\n".
+    $str2."\n".
     "  ".stGetFormButtonInput("update", $id, $prefix, "Update", "updateCompo(".$id.")")."\n".
     "  ".stGetFormButtonInput("delete", $id, $prefix, "Delete", "deleteCompo(".$id.")")."\n";
 }
@@ -1506,7 +1510,7 @@
     if ($type == "compo" && stValidateRequestCompoData(FALSE))
     {
       $sql = stPrepareSQL(
-        "INSERT INTO compos (name,description,visible,voting,show_authors) VALUES (%S,%Q,0,0,0)",
+        "INSERT INTO compos (name,description,visible,voting,show_authors,preview_type) VALUES (%S,%Q,0,0,0,0)",
         "name", "description");
 
       stExecSQLCond($sql, "OK, compo added.");
@@ -1525,22 +1529,21 @@
       else
       if (stValidateRequestEntryData($cfake, TRUE, $compo["ctype"]))
       {
-        switch ($compo["type"])
+        switch ($compo["ctype"])
         {
           case COMPO_NORMAL:
             $sql = stPrepareSQL(
-            "INSERT INTO entries (name,author,compo_id,filename,info,notes) VALUES (%S,%S,%d,%S,%Q,%Q)",
-            "name", "author", $compo["id"], "filename", "info", "notes");
+            "INSERT INTO entries (name,author,compo_id,filename,info,notes,preview_type) VALUES (%S,%S,%d,%S,%Q,%Q,%D)",
+            "name", "author", $compo["id"], "filename", "info", "notes", "preview_type");
             break;
           
           case COMPO_POINTS:
           case COMPO_ASSIGN:
             $sql = stPrepareSQL(
-            "INSERT INTO entries (name,compo_id,notes) VALUES (%S,%d,%Q)",
-            "name", $compo["id"], "notes");
+            "INSERT INTO entries (name,compo_id,notes,evalue) VALUES (%S,%d,%Q,%D)",
+            "name", $compo["id"], "notes", "evalue");
             break;
         }
-
         stExecSQLCond($sql, "OK, entry added.");
       }
     }
@@ -1610,23 +1613,30 @@
         else
         if (stValidateRequestCompoData(TRUE, $compo["ctype"]))
         {
-          $skeys = array(
-            "name" => "S",
-            "description" => "Q",
-            "visible" => "B",
-            "show_authors" => "B",
-            "preview_type" => "D",
-            "cpath" => "S",
-          );
-
           switch ($compo["ctype"])
           {
             case COMPO_NORMAL:
-              $skeys["voting"] = "B";
+              $cdata = array(
+                "voting" => "B",
+                "show_authors" => "B",
+                "preview_type" => "D",
+                "cpath" => "S",
+              );
+              break;
+            
+            default:
+              $cdata = array();
               break;
           }
           
-          $sql = stPrepareSQLUpdate("compos", "WHERE id=".$id, $skeys);
+          $sql = stPrepareSQLUpdate("compos",
+            "WHERE id=".$id,
+            array_merge(array(
+              "name" => "S",
+              "description" => "Q",
+              "visible" => "B",
+            ), $cdata));
+
           stExecSQLCond($sql, "OK, compo updated.");
         }
       }