reaplced the git service code (main gitbackendinterface()) with a new
[gwvp.git] / gwvplib / gwvpconfig.php
1 <?php
2
3 // setup the call me function for useradmin - matches on url of admin/users
4
5 // crap, this wont work
6 //if(isset($_SESSION["usertype"])) if($_SESSION["usertype"] == "admin") {
7 $CALL_ME_FUNCTIONS["config"] = "gwvp_ConfigCallMe";
8 $MENU_ITEMS["40config"]["text"] = "Configuration";
9 $MENU_ITEMS["40config"]["link"] = "$BASE_URL/admin/config";
10 $MENU_ITEMS["40config"]["userlevel"] = "admin";
11 //}
12
13 // config types are bool, int, or text
14 $CONFIG_VARS["userreg"]["type"] = "bool";
15 $CONFIG_VARS["userreg"]["text"] = "Allow User Registration"; 
16
17 $CONFIG_VARS["usercreategroups"]["type"] = "bool";
18 $CONFIG_VARS["usercreategroups"]["text"] = "Allow User Created Groups";
19
20 $CONFIG_VARS["repodir"]["type"] = "text";
21 $CONFIG_VARS["repodir"]["text"] = "Repository Storage Directory";
22
23
24 global $data_directory, $CONFIG_VARS; 
25
26 function gwvp_ConfigCallMe()
27 {
28         if(isset($_REQUEST["q"])) {
29                 $query = $_REQUEST["q"];
30                 if($query == "admin/config") return "gwvp_ConfigPage";
31                 if($query == "admin/configupdate") return "gwvp_ConfigUpdatePage";
32                 else return false;
33         }
34         
35         return false;
36 }
37
38 function gwvp_ConfigPage()
39 {
40         gwvp_goMainPage("gwvp_ConfigPageBody");
41 }
42
43 function gwvp_ConfigUpdatePage()
44 {
45         global $CONFIG_VARS, $BASE_URL;
46         
47         foreach($CONFIG_VARS as $key => $val) {
48                 switch($val["type"]) {
49                         case "bool":
50                                 if(isset($_REQUEST["$key"])) {
51                                         $pushval = 1;
52                                 } else {
53                                         $pushval = 0;
54                                 }
55                                 
56                                 break;
57                         default:
58                                 $pushval = $_REQUEST["$key"];
59                 }
60                 error_log("pushing value, $pushval for $key");
61                 gwvp_setConfigVal($key, $pushval);
62         }
63         
64         gwvp_SendMessage("info", "Configuration Updated");
65         header("Location: $BASE_URL/admin/config");
66         
67 }
68
69 function gwvp_ConfigPageBody()
70 {
71         global $CONFIG_VARS, $BASE_URL;
72
73         echo "<h1>Global Configuration</h1>";
74         echo "<form method=\"post\" action=\"$BASE_URL/admin/configupdate\">";
75         echo "<table>";
76         echo "<tr><th bgcolor=\"#eeeeff\">Configuration Variable</th><th bgcolor=\"#eeeeff\">Value</th></tr>";
77         foreach($CONFIG_VARS as $key=>$var) {
78                 $name = $key;
79                 $text = $var["text"];
80                 $cval = gwvp_getConfigVal($name);
81                 $curtypeval = "";
82                 switch($var["type"]) {
83                         case "bool":
84                                 $ltype = "checkbox";
85                                 if($cval == 1) $curtypeval = "checked";
86                                 break;
87                         case "int":
88                                 $ltype = "text";
89                                 $curtypeval = "value=\"$cval\"";
90                                 break;
91                         case "text":
92                                 $ltype = "text";
93                                 $curtypeval = "value=\"$cval\"";
94                                 break;
95                         default:
96                                 $ltype = "text";
97                                 $curtypeval = "value=\"$cval\"";
98                                 break;
99                 }
100                 error_log("go config $name as $ltype, $curtypeval");
101                 echo "<tr><td>$text</td><td bgcolor=\"#eeeeee\"><input type=\"$ltype\" name=\"$name\" $curtypeval></td></tr>";
102         }
103         
104         echo "</table>";
105         echo "<input type=\"submit\" name=\"Update\" value=\"Update\">";
106         echo "</form>";
107 }
108
109 ?>