initial re-coding
[configmanager.git] / lib / www.php
1 <?php
2
3 // some global menu stuff
4 $MENUS["home"]["url"] = "?action=home";
5 $MENUS["home"]["name"] = "Home";
6 $MENUS["hosts"]["url"] = "?action=hosts";
7 $MENUS["hosts"]["name"] = "Hosts";
8 $MENUS["add"]["url"] = "?action=addhost";
9 $MENUS["add"]["name"] = "Add Host";
10 $MENUS["config"]["url"] = "?action=config";
11 $MENUS["config"]["name"] = "Configure";
12
13 $FUNCTIONS["config"] = "www_configure";
14 $FUNCTIONS["addhost"] = "www_addhost";
15 $FUNCTIONS["addhostnext"] = "www_addHostStageTwo";
16 $FUNCTIONS["addhostthree"] = "www_addHostStageThree";
17
18
19 function www_header()
20 {
21         ?>
22 <html>
23 <title>Network Config Manager</title>
24 <body>
25         <?php
26 }
27
28 function www_pageLayout()
29 {
30         ?>
31 <table>
32 <tr><td colspan="2"><h1>Network Config Manager</h1></td></tr>
33 <tr valign="top"><td><?php www_menu() ?></td><td><?php www_body() ?></td></tr>
34 </table>
35         
36         <?php 
37 }
38
39 function www_footer()
40 {
41         ?>
42 <br><font size="-1"><i>Copyright 2003-2011, Paul J Robinson</i></font><br>
43 </body>
44 </html>
45         <?php 
46 }
47
48 function www_menu()
49 {
50         global $MENUS;
51         foreach($MENUS as $menuitems) {
52                 $url = $menuitems["url"];
53                 $name = $menuitems["name"];
54                 echo "<a href=\"$url\">$name</a><br>";
55         }
56 }
57
58 function www_body()
59 {
60         global $FUNCTIONS;
61         
62         $called = false;
63         if(isset($_REQUEST["action"])) {
64                 $req = $_REQUEST["action"];
65                 if(isset($FUNCTIONS["$req"])) {
66                         $func = $FUNCTIONS["$req"];
67                         if(function_exists($func)) {
68                                 $func();
69                                 return true;
70                         }
71                 }
72         }
73         
74         $db = db_getDB();
75         
76         // here we do the normal body, whatever that
77         // we'll list the hosts, the size of the current config and
78         // the last time it was updated, plus the number of versions
79         
80 }
81
82 function www_hostTypesDropDown()
83 {
84         global $HOST_TYPE;
85         
86         foreach($HOST_TYPE as $tloop => $types) {
87                 $typename = $types["name"];
88                 $typever = $tloop;
89                 echo "<option value=\"$typever\">$typename</option>";
90         }
91 }
92
93 function www_addhost()
94 {
95         ?>
96 <form method="post" action="?action=addhostnext">
97 <table>
98 <tr><td>Name</td><td><input type="text" name="cname"></td></tr>
99 <tr><td>Hostname/IP Address</td><td><input type="text" name="hname"></td></tr>
100 <tr><td>Host Type</td><td><select name="hosttype"><?php www_hostTypesDropDown() ?></select></td></tr>
101 </table>
102 <input type="submit" value="Next" name="Next">
103 </form>
104         <?php
105 }
106
107 function www_addHostStageTwo()
108 {
109         global $HOST_TYPE;
110         if(isset($_REQUEST["hosttype"])) {
111                 $htype = $_REQUEST["hosttype"];
112                 $func = $HOST_TYPE["$htype"]["configform"];
113                 if(function_exists($func)) {
114                         echo "<form method=\"post\" action=\"?action=addhostthree&hosttype=$htype\">";
115                         $func();
116                         echo "<input type=\"submit\" value=\"Add\" name=\"Add\">";
117                 } else echo "would call $func for $htype but it doesnt exist\n";
118         }
119 }
120
121 function www_addHostStageThree()
122 {
123         global $HOST_TYPE;
124         if(isset($_REQUEST["hosttype"])) {
125                 $htype = $_REQUEST["htype"];
126                 $func = $HOST_TYPE["$htype"]["postfunction"];
127                 if(function_exists($func)) {
128                         $func();
129                 } else echo "would call $func for $htype but it doesnt exist\n";
130         }
131         
132 }
133 ?>