diff admin.inc.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 11816aad6967
children ea0f98a0bed8
line wrap: on
line diff
--- a/admin.inc.php	Thu Dec 06 14:49:10 2012 +0200
+++ b/admin.inc.php	Thu Dec 06 16:13:08 2012 +0200
@@ -1,4 +1,33 @@
 <?
+function stCreateSettingsData()
+{
+  $args = array();
+
+  if (($res = stExecSQL("SELECT * FROM settings")) !== FALSE)
+  {
+    foreach ($res as $item)
+    {
+      switch ($item["vtype"])
+      {
+        case VT_STR:
+        case VT_TEXT: $type = 0; break;
+        case VT_INT: $type = 4; break;
+        case VT_BOOL: $type = 3; break;
+      }
+      $args[] = "\"".$item["key"]."\":".$type;
+    }
+  }
+
+  echo
+  "\n".
+  "function updateSettings()\n".
+  "{\n".
+  "  var args = makePostArgs({".implode(",", $args)."}, \"st\", \"\");\n".
+  "  sendPOSTRequest(\"action=update&type=settings&\"+args);\n".
+  "  return false;\n".
+  "}\n";
+}
+
 // Check if sessions are enabled
 if (!stChkSetting("admPassword"))
 {
@@ -31,6 +60,9 @@
 {
 ?>
 <script type="text/javascript">
+// <? stCreateSettingsData(); ?>
+
+
 function statusMsg(msg)
 {
   document.getElementById("nstatus").innerHTML = msg;
@@ -87,7 +119,10 @@
       else
       if (req.status == 200)
       {
-        success(req.responseText);
+        if (success)
+        {
+          success(req.responseText);
+        }
         statusMsg(req.statusText);
       }
       else
@@ -115,7 +150,7 @@
     var elem = document.getElementById(fprefix + id + fsuffix);
     if (!elem)
     {
-      alert("No such DOM element '"+ id +"'.");
+      alert("No such DOM element '"+ fprefix + id + fsuffix +"'.");
       return "";
     }
 
@@ -123,14 +158,18 @@
     {
       case 0:
       case 1:
+      case 4:
         {
           var str = strtrim(elem.value);
-          if (fields[id] == 1 && str == "")
+          if ((fields[id] == 1 || fields[id] == 4) && str == "")
           {
             alert("One or more of the fields are empty.");
             return "";
           }
-          res.push(id+"="+strencode(str));
+          if (fields[id] == 4)
+            res.push(id+"="+parseInt(elem.value));
+          else
+            res.push(id+"="+strencode(str));
         }
         break;
 
@@ -324,17 +363,6 @@
 }
 
 
-function updateSettings()
-{
-  var args = makePostArgs({
-    "oneliner":0,
-    "email":0
-    }, "st", "");
-
-  sendPOSTRequest("action=update&type=settings&"+args);
-}
-
-
 var registeredTabs = Object();