changeset 257:ef9a007c0876

Modularize and add methods for getting single entry.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 24 Nov 2013 01:42:50 +0200
parents ed8d8d016420
children 08b292dd12ff
files admajax.php
diffstat 1 files changed, 25 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/admajax.php	Sun Nov 24 01:42:25 2013 +0200
+++ b/admajax.php	Sun Nov 24 01:42:50 2013 +0200
@@ -105,6 +105,23 @@
 }
 
 
+function stGetEntryItemData($eid, $item, $prefix)
+{
+  echo
+    "   <td>".$eid."</td>\n".
+    "   <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>".stGetFormTextInput(20, SET_LEN_ENTRY_INFO, "info", $eid, $prefix, $item["info"])."</td>\n".
+    "   <td>".
+    stGetFormButtonInput("delete", $eid, $prefix, "Del", "deleteEntry(".$eid.")").
+    stGetFormTextInput(3, 3, "compo_id", $eid, $prefix, $item["compo_id"]).
+    stGetFormButtonInput("update", $eid, $prefix, "Upd", "updateEntry(".$eid.")").
+    "</td>\n";
+}
+
+
 function stGetSaveButton()
 {
   return "<input type=\"submit\" value=\" Save \" />\n";
@@ -284,6 +301,12 @@
         }
         break;
 
+      case "entry":
+        $res = stFetchSQL(stPrepareSQL("SELECT * FROM entries WHERE id=%D", "id"));
+        if ($res !== FALSE)
+          echo stGetEntryItemData($res["id"], $res, "en");
+        break;
+
       case "entries":
         $id = intval(stGetRequestItem("id", 0));
         if (($compo = stFetchSQL("SELECT * FROM compos WHERE id=".$id)) !== false)
@@ -302,23 +325,11 @@
             "   <th>Actions</th>\n".
             "  </tr>\n";
 
-          $prefix = "en";
           foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$id) as $entry)
           {
-            $eid = $entry["id"];
             echo
-              "  <tr id=\"entry".$eid."\">\n".
-              "   <td>".$eid."</td>\n".
-              "   <td>".($entry["show_id"] > 0 ? $entry["show_id"] : "-")."</td>\n".
-              "   <td>".stGetFormTextInput(20, SET_LEN_ENTRY_NAME, "name", $eid, "en", $entry["name"])."</td>\n".
-              "   <td>".stGetFormTextInput(15, SET_LEN_ENTRY_AUTHOR, "author", $eid, "en", $entry["author"])."</td>\n".
-              "   <td>".stGetFormTextInput(20, SET_LEN_ENTRY_FILENAME, "filename", $eid, "en", $entry["filename"])."</td>\n".
-              "   <td>".stGetFormTextInput(20, SET_LEN_ENTRY_INFO, "info", $eid, "en", $entry["info"])."</td>\n".
-              "   <td>".
-              stGetFormButtonInput("delete", $eid, $prefix, "Del", "deleteEntry(".$eid.")").
-              stGetFormTextInput(3, 3, "compo_id", $eid, "en", $id).
-              stGetFormButtonInput("update", $eid, $prefix, "Upd", "updateEntry(".$eid.")").
-              "</td>\n".
+              "  <tr id=\"entry".$entry["id"]."\">\n".
+              stGetEntryItemData($entry["id"], $entry, "en").
               "  </tr>\n";
           }