changeset 644:de35a9743557

Implement changing of compo type.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 03 Nov 2014 02:14:54 +0200
parents d32b5f601670
children cb06f048ec34
files admajax.php admin.js
diffstat 2 files changed, 31 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/admajax.php	Mon Nov 03 02:11:10 2014 +0200
+++ b/admajax.php	Mon Nov 03 02:14:54 2014 +0200
@@ -87,6 +87,9 @@
 
 function stGetCompoData($id, $item, $prefix)
 {
+  global $compoModeData;
+
+  // XXX TODO Dropdown menu or so for selecting compo type
   switch ($item["ctype"])
   {
     case COMPO_NORMAL:
@@ -101,6 +104,9 @@
 
   return
     "  <h2>#".$id." - ".chentities($item["name"])."</h2>\n".
+    "  Type: ".stGetOptionListFromArray("cotype".$id, "  ", FALSE, $compoModeData, $item["ctype"], 0)." ".
+    stGetFormButtonInput("change", $id, $prefix, "Change", "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".
     "  ".stGetFormTextArea(8, 60, "description", $id, $prefix, $item["description"])."<br />\n".
@@ -959,7 +965,9 @@
           "SELECT compos.*, ".
           "COUNT(DISTINCT entries.id) AS nentries ".
           "FROM compos LEFT JOIN entries ON compos.id=entries.compo_id ".
-          "GROUP BY compos.id HAVING COUNT(DISTINCT entries.id) > 0 ORDER BY compos.id DESC";
+          "GROUP BY compos.id ".
+          "HAVING COUNT(DISTINCT entries.id) > 0 AND compos.ctype=".COMPO_NORMAL." ".
+          "ORDER BY compos.id DESC";
 
         $currCompoID = stGetDisplayVar("compoID");
         if (($res = stExecSQL($sql)) !== false)
@@ -1511,6 +1519,17 @@
         stExecSQLCond($sql, "OK, news item updated.");
       }
       else
+      if ($type == "compotype")
+      {
+        $sql = stPrepareSQLUpdate("compos",
+          "WHERE id=".$id,
+          array(
+            "ctype" => "D",
+          ));
+
+        stExecSQLCond($sql, "OK, compo updated.");
+      }
+      else
       if ($type == "compo" && stValidateRequestCompoData(TRUE))
       {
         $sql = stPrepareSQLUpdate("compos",
--- a/admin.js	Mon Nov 03 02:11:10 2014 +0200
+++ b/admin.js	Mon Nov 03 02:14:54 2014 +0200
@@ -294,6 +294,17 @@
 }
 
 
+function updateCompoType(id)
+{
+  var msuccess = function(txt)
+  {
+    jsRefreshItems("compo"+id, "compo", "&id="+id);
+  }
+
+  jsSendPOSTRequest("action=update&type=compotype&id="+id+"&ctype="+jsGetValue("cotype"+id+"Sel", 4), msuccess);
+}
+
+
 function updateCompo(id)
 {
   var args = jsMakePostArgs({"name":1, "description":1, "visible":3, "voting":3, "show_authors":3, "cpath":1}, "co", id);