diff ajax.php @ 14:e36c4d2b09c4

Fix settings to work, clean up the code, etc.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 06 Dec 2012 16:13:08 +0200
parents 4c5f651aa107
children 6da681d1f62a
line wrap: on
line diff
--- a/ajax.php	Thu Dec 06 14:49:10 2012 +0200
+++ b/ajax.php	Thu Dec 06 16:13:08 2012 +0200
@@ -96,7 +96,40 @@
         break;
 
       case "settings":
-        $sql = "SELECT * FROM settings";
+        $prefix = "st";
+
+        echo
+        "<table>\n";
+        foreach (stExecSQL("SELECT * FROM settings WHERE vtype<>".VT_TEXT) as $item)
+        {
+          echo
+          " <tr>\n".
+          "  <td>";
+          $id = $item["key"];
+          switch ($item["vtype"])
+          {
+            case VT_INT:
+              echo stGetFormTextInput(10, 10, "", $id, $prefix, $item["vint"]);
+              break;
+            case VT_STR:
+              echo stGetFormTextInput(40, 128, "", $id, $prefix, $item["vstr"]);
+              break;
+            case VT_BOOL:
+              echo stGetFormCheckBoxInput("", $id, $prefix, $item["vint"], "");
+              break;
+          }
+          echo "</td>\n".
+          "  <td>".$item["desc"]."</td>\n".
+          " </tr>\n";
+        }
+        echo "</table>\n";
+
+        foreach (stExecSQL("SELECT * FROM settings WHERE vtype=".VT_TEXT) as $item)
+        {
+          echo "<h2>".chentities($item["desc"])."</h2>\n".
+          stGetFormTextArea(10, 60, "", $item["key"], $prefix, $item["vtext"]).
+          "\n<br />\n";
+        }
         break;
       
       case "entries":
@@ -205,7 +238,7 @@
         "  <th class=\"vid\">#</th>\n".
         "  <th class=\"vkey\">Vote key</th>\n".
         "  <th class=\"vname\">Name</th>\n".
-        "  <th style=\"vactive\">Active</th>\n".
+        "  <th class=\"vactive\">Active</th>\n".
         " </tr>\n";
         $row = 0;
         foreach ($res as $item)
@@ -227,10 +260,6 @@
         }
         echo "</table>\n";
       }
-      else
-      if ($type == "settings")
-      {
-      }
     }
     break;
 
@@ -356,6 +385,25 @@
       execSQLCond($sql, "OK, voter updated.");
     }
     else
+    if ($type == "settings")
+    {
+      foreach (stExecSQL("SELECT * FROM settings") as $item)
+      if (stChkRequestItem($item["key"]))
+      {
+        $val = stGetRequestItem($item["key"]);
+        switch ($item["vtype"])
+        {
+          case VT_INT:  $vsql = stPrepareSQL("vint=%d", $val); break;
+          case VT_BOOL: $vsql = stPrepareSQL("vint=%d", $val ? 1 : 0); break;
+          case VT_STR:  $vsql = stPrepareSQL("vstr=%s", $val); break;
+          case VT_TEXT: $vsql = stPrepareSQL("vtext=%s", $val); break;
+        }
+        
+        $sql = "UPDATE settings SET ".$vsql." WHERE key=".$db->quote($item["key"]);
+        execSQLCond($sql, "OK, setting updated.");
+      }
+    }
+    else
       setStatus(902, "No data.");
     break;