changeset 223:532704115290

Make it possible to update news entries.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 18 Nov 2013 04:01:52 +0200
parents b236b4d8d7a9
children 0daedbef5678
files admajax.php admin.php
diffstat 2 files changed, 83 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/admajax.php	Mon Nov 18 02:43:05 2013 +0200
+++ b/admajax.php	Mon Nov 18 04:01:52 2013 +0200
@@ -79,6 +79,32 @@
 }
 
 
+function stGetCompoData($id, $item, $prefix)
+{
+  return
+    "  <h2>#".$id." - ".chentities($item["name"])."</h2>\n".
+    "  ".stGetFormTextInput(40, SET_LEN_COMPO_NAME, "name", $id, $prefix, $item["name"])."\n".
+    "  ".stGetFormCheckBoxInput("visible", $id, $prefix, $item["visible"], "Visible")."\n".
+    "  ".stGetFormCheckBoxInput("showAuthors", $id, $prefix, $item["showAuthors"], "Show authors")."\n".
+    "  ".stGetFormCheckBoxInput("voting", $id, $prefix, $item["voting"], "Enable voting")."<br />\n".
+    "  ".stGetFormTextArea(5, 60, "description", $id, $prefix, $item["description"])."\n<br />\n".
+    "  ".stGetFormButtonInput("update", $id, $prefix, "Update", "updateCompo(".$id.")")."\n";
+}
+
+
+function stGetNewsItemData($id, $item, $prefix)
+{
+  return
+    "  ".stGetFormTextInput(40, SET_LEN_NEWS_TITLE, "title", $id, $prefix, $item["title"]).
+    " - posted ".date("d M Y / H:i", $item["utime"])."<br />\n".
+    "  ".stGetFormTextArea(5, 60, "text", $id, $prefix, $item["text"])."<br />\n".
+    "  ".stGetFormTextInput(20, SET_LEN_NEWS_AUTHOR, "author",  $id, $prefix, $item["author"])."\n".
+    "  <br />\n".
+    "  ".stGetFormButtonInput("", "upd".$id, $prefix, "Update", "updateNews(".$id.")")."\n".
+    "  ".stGetFormButtonInput("", "del".$id, $prefix, "Delete", "deleteNews(".$id.")")."\n";
+}
+
+
 function stGetSaveButton()
 {
   return "<input type=\"submit\" value=\" Save \" />\n";
@@ -149,6 +175,12 @@
         $sql = "SELECT * FROM news ORDER BY utime DESC";
         break;
 
+      case "newsitem":
+        $res = stFetchSQL(stPrepareSQL("SELECT * FROM news WHERE id=%D", "id"));
+        if ($res !== FALSE)
+          echo stGetNewsItemData($res["id"], $res, "ne");
+        break;
+
       case "attendees":
         $sql = "SELECT * FROM attendees ORDER BY regtime DESC";
         break;
@@ -180,6 +212,12 @@
         $sql = "SELECT * FROM compos ORDER BY id DESC";
         break;
 
+      case "compo":
+        $res = stFetchSQL(stPrepareSQL("SELECT * FROM compos WHERE id=%D", "id"));
+        if ($res !== FALSE)
+          echo stGetCompoData($res["id"], $res, "co");
+        break;
+
       case "slides":
         $sql = "SELECT * FROM displaySlides SORT BY id ASC";
         $sql = "SELECT * FROM displayListData SORT BY id ASC";
@@ -238,17 +276,21 @@
         break;
       
       case "entries":
-        stGetCompoList(FALSE, FALSE);
-        
-        foreach ($compos as $id => $compo)
+        foreach (stExecSQL("SELECT * FROM compos") as $compo)
+        {
+          echo "registerTab(\"CM\",\"Compo".$compo["id"]."\",\"".chentities($compo["name"])."\");";
+        }
+        break;
+
+      case "entrylist":
+        $id = intval(stGetRequestItem("id", 0));
+        foreach (stExecSQL("SELECT * FROM compos WHERE id=".$id) as $compo)
         {
           echo
             "<form>\n".
+            " <h1>#".$id." - ".chentities($compo["name"])."</h1>\n".
             " <table class=\"misc\">\n".
             "  <tr>\n".
-            "   <th colspan=\"6\">#".$id." - ".chentities($compo["name"])."</th>\n".
-            "  </tr>\n".
-            "  <tr>\n".
             "   <th style=\"width:4%;\">ID#</th>\n".
             "   <th style=\"width:4%;\">S#</th>\n".
             "   <th>Title</th>\n".
@@ -259,8 +301,9 @@
             "  </tr>\n";
 
           $prefix = "en";
-          foreach ($compo["entries"] as $eid => $entry)
+          foreach (stExecSQL("SELECT * FROM entries WHERE compo_id=".$id) as $entry)
           {
+            $eid = $entry["id"];
             echo
               "  <tr id=\"entry".$eid."\">\n".
               "   <td>".$eid."</td>\n".
@@ -282,10 +325,10 @@
             "  <tr>\n".
             "   <td></td>\n".
             "   <td></td>\n".
-            "   <td>".stGetFormTextInput(20, SET_LEN_ENTRY_NAME, "name", $id, "ne", "")."</td>\n".
-            "   <td>".stGetFormTextInput(15, SET_LEN_ENTRY_AUTHOR, "author", $id, "ne", "")."</td>\n".
-            "   <td>".stGetFormTextInput(20, SET_LEN_ENTRY_FILENAME, "filename", $id, "ne", "")."</td>\n".
-            "   <td>".stGetFormTextInput(20, SET_LEN_ENTRY_INFO, "info", $id, "ne", "")."</td>\n".
+            "   <td>".stGetFormTextInput(20, SET_LEN_ENTRY_NAME, "name", $id, $prefix, "")."</td>\n".
+            "   <td>".stGetFormTextInput(15, SET_LEN_ENTRY_AUTHOR, "author", $id, $prefix, "")."</td>\n".
+            "   <td>".stGetFormTextInput(20, SET_LEN_ENTRY_FILENAME, "filename", $id, $prefix, "")."</td>\n".
+            "   <td>".stGetFormTextInput(20, SET_LEN_ENTRY_INFO, "info", $id, $prefix, "")."</td>\n".
             "   <td>".stGetFormButtonInput("add", $id, $prefix, "Add new", "addEntry(".$id.")")."</td>\n".
             "  </tr>\n".
             " </table>\n".
@@ -313,13 +356,11 @@
 
         foreach ($res as $item)
         {
-          $id = $item["id"];
-          stPrintNewsItem($item,
-            "<br />".
-            "  <button class=\"button\" id=\"ndel".$id.
-            "\" type=\"button\" onclick=\"deleteNews(".$id.
-            ")\">Delete</button>\n"
-            );
+          echo
+            "<div id=\"news".$item["id"]."\">\n".
+            stGetNewsItemData($item["id"], $item, "ne").
+            "</div>\n".
+            "<hr />\n";
         }
       }
       else
@@ -410,17 +451,9 @@
 
         foreach ($res as $item)
         {
-          $id = $item["id"];
-          $prefix = "co";
           echo
-            "<div id=\"compo".$id."\">\n".
-            "  <h2>#".$id." - ".chentities($item["name"])."</h2>\n".
-            "  ".stGetFormTextInput(40, SET_LEN_COMPO_NAME, "name", $id, $prefix, $item["name"])."\n".
-            "  ".stGetFormCheckBoxInput("visible", $id, $prefix, $item["visible"], "Visible")."\n".
-            "  ".stGetFormCheckBoxInput("showAuthors", $id, $prefix, $item["showAuthors"], "Show authors")."\n".
-            "  ".stGetFormCheckBoxInput("voting", $id, $prefix, $item["voting"], "Enable voting")."<br />\n".
-            "  ".stGetFormTextArea(5, 60, "description", $id, $prefix, $item["description"])."\n<br />\n".
-            "  ".stGetFormButtonInput("update", $id, $prefix, "Update", "updateCompo(".$id.")")."\n".
+            "<div id=\"compo".$item["id"]."\">\n".
+            stGetCompoData($item["id"], $item, "co").
             "</div>\n".
             "<hr />\n";
         }
--- a/admin.php	Mon Nov 18 02:43:05 2013 +0200
+++ b/admin.php	Mon Nov 18 04:01:52 2013 +0200
@@ -209,6 +209,21 @@
 }
 
 
+
+function updateNews(id)
+{
+  var args = makePostArgs({"title":1,"text":1,"author":1}, "ne", id);
+
+  var msuccess = function(txt)
+  {
+    refreshItems("news"+id, "newsitem", "News #"+id, "&id="+id);
+  }
+
+  if (args != "")
+    sendPOSTRequest("action=update&type=news&id="+id+"&"+args, msuccess);
+}
+
+
 function addAttendee()
 {
   var args = makePostArgs({"name":1,"groups":0,"oneliner":0,"email":0}, "ne", "x");
@@ -304,8 +319,13 @@
 {
   var args = makePostArgs({"name":1, "description":1, "visible":3, "voting":3, "showAuthors":3}, "co", id);
 
+  var msuccess = function(txt)
+  {
+    refreshItems("compo"+id, "compo", "Compo #"+id, "&id="+id);
+  }
+
   if (args != "")
-    sendPOSTRequest("action=update&type=compo&id="+id+"&"+args);
+    sendPOSTRequest("action=update&type=compo&id="+id+"&"+args, msuccess);
 }
 
 
@@ -330,6 +350,7 @@
 
   var msuccess = function(txt)
   {
+    // Full update needed, because of possibly changed compo_id
     setTimeout("refreshCCEntries();", 50);
   }