started implementing the configuration dialog stuff
[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         foreach($CONFIG_VARS as $key=>$var) {
77                 $name = $key;
78                 $text = $var["text"];
79                 $cval = gwvp_getConfigVal($name);
80                 $curtypeval = "";
81                 switch($var["type"]) {
82                         case "bool":
83                                 $ltype = "checkbox";
84                                 if($cval == 1) $curtypeval = "checked";
85                                 break;
86                         case "int":
87                                 $ltype = "text";
88                                 $curtypeval = "value=\"$cval\"";
89                                 break;
90                         case "text":
91                                 $ltype = "text";
92                                 $curtypeval = "value=\"$cval\"";
93                                 break;
94                         default:
95                                 $ltype = "text";
96                                 $curtypeval = "value=\"$cval\"";
97                                 break;
98                 }
99                 error_log("go config $name as $ltype, $curtypeval");
100                 echo "<tr><td>$text</td><td><input type=\"$ltype\" name=\"$name\" $curtypeval></td></tr>";
101         }
102         
103         echo "</table>";
104         echo "<input type=\"submit\" name=\"Update\" value=\"Update\">";
105         echo "</form>";
106 }
107
108 ?>