diff admajax.php @ 682:2e54b6858ce9

A tiny bit more work on entry editing.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 09 Nov 2014 14:48:07 +0200
parents bf8a5009b3f2
children 8730bffcffd4
line wrap: on
line diff
--- a/admajax.php	Sun Nov 09 14:46:48 2014 +0200
+++ b/admajax.php	Sun Nov 09 14:48:07 2014 +0200
@@ -140,19 +140,42 @@
 }
 
 
-function stGetEntryItemData($eid, $item, $prefix)
+function stPrintEntryItemData($entry, $ctype, $prefix, $tr, $edit)
 {
-  return
-    "   <td>".($item["show_id"] > 0 ? $item["show_id"] : "-")."</td>\n".
-    "   <td>".stGetFormTextInput(20, SET_LEN_ENTRY_NAME, "name", $eid, $prefix, $item["name"])."</td>\n".
-    "   <td>".stGetFormTextInput(15, SET_LEN_ENTRY_AUTHOR, "author", $eid, $prefix, $item["author"])."</td>\n".
-    "   <td>".stGetFormTextInput(20, SET_LEN_ENTRY_FILENAME, "filename", $eid, $prefix, $item["filename"])."</td>\n".
-    "   <td>".stGetFormTextArea(2, 30, "info", $eid, $prefix, $item["info"])."</td>\n".
+  $eid = $entry["id"];
+  if ($ctype === FALSE)
+    $ctype = stFetchSQLColumn("SELECT ctype FROM compos WHERE id=".$entry["compo_id"]);
+
+  if ($tr)
+  {
+    echo
+      "  <tr id=\"entry".$eid."\" onClick=\"activateEntry(".$eid.")\">\n";
+  }
+
+  echo
+    "   <td>".($entry["show_id"] > 0 ? $entry["show_id"] : "-")."</td>\n".
+    "   ".stGetTDFormTextInput($edit, 20, SET_LEN_ENTRY_NAME, "name", $eid, $prefix, $entry["name"])."\n".
+    "   ".stGetTDFormTextInput($edit, 15, SET_LEN_ENTRY_AUTHOR, "author", $eid, $prefix, $entry["author"])."\n".
+    "   ".stGetTDFormTextInput($edit, 20, SET_LEN_ENTRY_FILENAME, "filename", $eid, $prefix, $entry["filename"])."\n".
     "   <td>".
-    stGetFormButtonInput("delete", $eid, $prefix, "Del", "deleteEntry(".$item["compo_id"].",".$eid.")").
-    stGetFormTextInput(3, 3, "compo_id", $eid, $prefix, $item["compo_id"]).
-    stGetFormButtonInput("update", $eid, $prefix, "Upd", "updateEntry(".$item["compo_id"].",".$eid.")").
+    stGetFormTextArea(2, 30, "info", $eid, $prefix, $entry["info"])."<br />".
+    stGetFormTextArea(2, 30, "notes", $eid, $prefix, $entry["notes"])."<br />".
+    // XXX TODO flags?
+    "</td>\n".
     "</td>\n";
+
+  if ($edit)
+  {
+    echo
+    "   <td>".
+    stGetFormButtonInput("delete", $eid, $prefix, "Del", "deleteEntry(".$entry["compo_id"].",".$eid.")").
+    stGetFormTextInput(3, 3, "compo_id", $eid, $prefix, $entry["compo_id"]).
+    stGetFormButtonInput("update", $eid, $prefix, "Upd", "updateEntry(".$entry["compo_id"].",".$eid.")").
+    "</td>\n";
+  }
+
+  if ($tr)
+    echo "  </tr>\n";
 }
 
 
@@ -1338,12 +1361,7 @@
             "  <tr><td colspan=\"6\"><hr /></td></tr>\n";
 
           foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$id." ORDER BY id ASC") as $entry)
-          {
-            echo
-              "  <tr id=\"entry".$entry["id"]."\">\n".
-              stGetEntryItemData($entry["id"], $entry, "en").
-              "  </tr>\n";
-          }
+            stPrintEntryItemData($entry, $compo["ctype"], "en", TRUE, FALSE);
 
           echo
             "</table>\n";
@@ -1353,7 +1371,7 @@
       case "entry":
         $res = stFetchSQL(stPrepareSQL("SELECT * FROM entries WHERE id=%D", "id"));
         if ($res !== FALSE)
-          echo stGetEntryItemData($res["id"], $res, "en");
+          stPrintEntryItemData($res, FALSE, "en", FALSE, stGetRequestItem("edit", FALSE));
         else
           stError("No such entry ID!");
         break;