started implementing the configuration dialog stuff
[gwvp.git] / gwvplib / gwvpconfig.php
index 74ee6ec..e63c99f 100644 (file)
@@ -10,13 +10,25 @@ $MENU_ITEMS["40config"]["link"] = "$BASE_URL/admin/config";
 $MENU_ITEMS["40config"]["userlevel"] = "admin";
 //}
 
-global $repo_base, $data_directory; 
+// config types are bool, int, or text
+$CONFIG_VARS["userreg"]["type"] = "bool";
+$CONFIG_VARS["userreg"]["text"] = "Allow User Registration"; 
+
+$CONFIG_VARS["usercreategroups"]["type"] = "bool";
+$CONFIG_VARS["usercreategroups"]["text"] = "Allow User Created Groups";
+
+$CONFIG_VARS["repodir"]["type"] = "text";
+$CONFIG_VARS["repodir"]["text"] = "Repository Storage Directory";
+
+
+global $data_directory, $CONFIG_VARS; 
 
 function gwvp_ConfigCallMe()
 {
        if(isset($_REQUEST["q"])) {
                $query = $_REQUEST["q"];
                if($query == "admin/config") return "gwvp_ConfigPage";
+               if($query == "admin/configupdate") return "gwvp_ConfigUpdatePage";
                else return false;
        }
        
@@ -28,19 +40,69 @@ function gwvp_ConfigPage()
        gwvp_goMainPage("gwvp_ConfigPageBody");
 }
 
+function gwvp_ConfigUpdatePage()
+{
+       global $CONFIG_VARS, $BASE_URL;
+       
+       foreach($CONFIG_VARS as $key => $val) {
+               switch($val["type"]) {
+                       case "bool":
+                               if(isset($_REQUEST["$key"])) {
+                                       $pushval = 1;
+                               } else {
+                                       $pushval = 0;
+                               }
+                               
+                               break;
+                       default:
+                               $pushval = $_REQUEST["$key"];
+               }
+               error_log("pushing value, $pushval for $key");
+               gwvp_setConfigVal($key, $pushval);
+       }
+       
+       gwvp_SendMessage("info", "Configuration Updated");
+       header("Location: $BASE_URL/admin/config");
+       
+}
 
 function gwvp_ConfigPageBody()
 {
-?>
-<h1>Global Configuration</h1>
-<form method="post">
-<table>
-<tr><td>Allow User Registration</td><td><input type="checkbox" name="allowreg"></td></tr>
-<tr><td>Allow User Created Groups</td><td><input type="checkbox" name="allowusercreatedgroup"></td></tr>
-
-</table>
-</form>
-<?php
+       global $CONFIG_VARS, $BASE_URL;
+
+       echo "<h1>Global Configuration</h1>";
+       echo "<form method=\"post\" action=\"$BASE_URL/admin/configupdate\">";
+       echo "<table>";
+       foreach($CONFIG_VARS as $key=>$var) {
+               $name = $key;
+               $text = $var["text"];
+               $cval = gwvp_getConfigVal($name);
+               $curtypeval = "";
+               switch($var["type"]) {
+                       case "bool":
+                               $ltype = "checkbox";
+                               if($cval == 1) $curtypeval = "checked";
+                               break;
+                       case "int":
+                               $ltype = "text";
+                               $curtypeval = "value=\"$cval\"";
+                               break;
+                       case "text":
+                               $ltype = "text";
+                               $curtypeval = "value=\"$cval\"";
+                               break;
+                       default:
+                               $ltype = "text";
+                               $curtypeval = "value=\"$cval\"";
+                               break;
+               }
+               error_log("go config $name as $ltype, $curtypeval");
+               echo "<tr><td>$text</td><td><input type=\"$ltype\" name=\"$name\" $curtypeval></td></tr>";
+       }
+       
+       echo "</table>";
+       echo "<input type=\"submit\" name=\"Update\" value=\"Update\">";
+       echo "</form>";
 }
 
 ?>
\ No newline at end of file