started implementing the configuration dialog stuff
authorpaulr <me@pjr.cc>
Mon, 7 Nov 2011 10:45:03 +0000 (21:45 +1100)
committerpaulr <me@pjr.cc>
Mon, 7 Nov 2011 10:45:03 +0000 (21:45 +1100)
configuration is "Generic" in that anything could add things to the
configuration page by updating CONFIG_VARS globally.

gwvplib/gwvpconfig.php
gwvplib/gwvpdatabase.php
gwvplib/gwvpdebug.php
gwvplib/gwvpgitcontrol.php
gwvplib/gwvprepoadmin.php
www/config-dist.php
www/index.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
index 792c1f7..28d2832 100644 (file)
@@ -147,15 +147,16 @@ function gwvp_getConfigVal($confname)
        
        $conn = gwvp_ConnectDB();
        
-       $sql = "select * from config where config_name='$confname'";
+       $sql = "select config_value from config where config_name='$confname'";
        
        $res = $conn->query($sql);
        
        $return = null;
        foreach($res as $val) {
-               $return = $val;
+               $return = $val["config_value"];
        }
        
+       return $return;
 }
 
 function gwvp_eraseConfigVal($confname)
@@ -199,7 +200,7 @@ function gwvp_setConfigVal($confname, $confval)
 function gwvp_isDBSetup()
 {
        // for sqlite, we just check if the db exists, for everyone else, we check for a conneciton and go yay or nay
-       global $WEB_ROOT_FS, $BASE_URL, $repo_base, $data_directory, $db_type, $db_url;
+       global $WEB_ROOT_FS, $BASE_URL, $data_directory, $db_type, $db_url;
 
        if($db_type == "sqlite") {
                if(file_exists($db_url)) return true;
@@ -212,7 +213,7 @@ function gwvp_isDBSetup()
 
 function gwvp_ConnectDB()
 {
-       global $WEB_ROOT_FS, $BASE_URL, $repo_base, $data_directory, $db_type, $db_name, $DB_CONNECTION;
+       global $WEB_ROOT_FS, $BASE_URL, $data_directory, $db_type, $db_name, $DB_CONNECTION;
 
        // first check if $DB_CONNECTION IS live
        if($DB_CONNECTION != false) return $DB_CONNECTION;
index d658845..71e0a93 100644 (file)
@@ -110,6 +110,8 @@ function gwvp_DebugCall()
                                        gwvp_AddRepo("repo2", "this is a test repo2", 1);
                                        gwvp_AddRepo("repo2", "this is a test repo3", 1);
                                        
+                                       gwvp_setConfigVal("repodir", "/tmp/");
+                                       
                                        header("Location: $BASE_URL/debug");
                                        break;
                                case "dropallusersandgroups":
index 18956b9..6383f9e 100644 (file)
@@ -30,8 +30,9 @@ function gwvp_repoPermissionCheck($repo, $user)
 function gwvp_gitBackendInterface_new()
 {
        // and this is where i re-code the git backend interface from scratch
-       global $repo_base, $BASE_URL;
+       global $BASE_URL;
        
+       $repo_base = gwvp_getConfigVal("repodir");
        
        $repo = "";
        $newloc = "/";
@@ -50,8 +51,9 @@ function gwvp_gitBackendInterface_new()
 
 function gwvp_gitBackendInterface()
 {
-       global $repo_base, $BASE_URL;
+       global $BASE_URL;
        
+       $repo_base = gwvp_getConfigVal("repodir");
        
        $repo = "";
        $newloc = "/";
@@ -324,7 +326,7 @@ function gwvp_callGitBackend($repo)
 
 function gwvp_repoExists($name)
 {
-       global $repo_base;
+       $repo_base = gwvp_getConfigVal("repodir");
        
        if(file_exists("$repo_base/$name.git")) return true;
        else return false;
@@ -336,7 +338,7 @@ function gwvp_repoExists($name)
 // 2 - only owner can see anything
 function gwvp_createGitRepo($name, $ownerid, $desc, $bundle=null, $defaultperms=0)
 {
-       global $repo_base;
+       $repo_base = gwvp_getConfigVal("repodir");
        
        // phew, this works, but i tell you this - bundles arent quite as nice as they should be
        if($bundle == null) {
index 09f7481..7a2b476 100644 (file)
@@ -93,7 +93,9 @@ function gwvp_DoCreateRepoPage()
 
 function gwvp_CreateRepoPageBody()
 {
-       global $BASE_URL, $repo_base;
+       global $BASE_URL;
+       
+       $repo_base = gwvp_getConfigVal("repodir");
        
        $reponameobv = "";
        $repodescobv = "";
index 728e336..8e63e2a 100644 (file)
@@ -4,7 +4,7 @@
 // all other config will be kept in the db, but not just yet
 
 // the config file, this is as exciting as it gets really
-$repo_base = "/tmp/";
+// no longer valid - $repo_base = "/tmp/";
 $lib_base = "../gwvplib/";
 $plugin_path = "$lib_base/plugins";
 $data_directory = "../data";
index 7ec0950..218c5ad 100644 (file)
@@ -7,7 +7,7 @@ require_once("config.php");
 $WEB_ROOT_FS = realpath(dirname(__FILE__));
 $BASE_URL = dirname($_SERVER["PHP_SELF"]);
 
-global $WEB_ROOT_FS, $BASE_URL, $repo_base, $data_directory, $db_type, $db_name, $db_username, $db_password;
+global $WEB_ROOT_FS, $BASE_URL, $data_directory, $db_type, $db_name, $db_username, $db_password;
 
 // the index will search for the base library depending on:
 // if lib_base is set in config.php, it'll go there and nowhere else