User page code for user/group admin
[gwvp.git] / gwvplib / gwvpweb.php
1 <?php
2
3 // this function is the initial insertion point for the web calls, here we need to determine where we go
4 global $CALL_ME_FUNCTIONS;
5
6 $MENU_ITEMS["00home"]["text"] = "Home";
7 $MENU_ITEMS["00home"]["link"] = "$BASE_URL";
8
9
10
11 function gwvp_goWebBegin()
12 {
13         global $CALL_ME_FUNCTIONS;
14         
15         // first we determine if we have a valid setup and run the installer if not
16         if(!gwvp_issetup()) {
17                 gwvp_goSetup();
18                 return;
19         }
20         
21         // next, we go thru the CALL_ME_FUNCTIONS - the purpose of call_me_functions is to determine if a function should be called based on
22         // the functions return (i.e. if function returns false, its not it, otherwise it returns a function name we have to call)
23         // this is important for our plugin structure later on - the key on the array serves an an ordering method
24         ksort($CALL_ME_FUNCTIONS);
25         foreach($CALL_ME_FUNCTIONS as $key => $val) {
26                 error_log("checking callmefunction $key as $val");
27                 $callme = $val();
28                 if($callme !== false) {
29                         $callme();
30                         return;
31                 }
32         }
33         
34         // we fell-thru to the main web page builder
35         gwvp_goMainPage();
36 }
37
38 function gwvp_SendMessage($messagetype, $message)
39 {
40         $_SESSION["messagetype"] = $messagetype;
41         $_SESSION["message"] = $message;
42 }
43
44 function gwvp_goMainPage($bodyFunction = null)
45 {
46         // the main page will look pretty simple, a title, a menu then a body
47         global $WEB_ROOT_FS, $BASE_URL;
48         
49         // a simple web page layout that loads any css and js files that exist in the css and js directories
50         echo "<html><head><title>GWVP</title>";
51         
52         // load css
53         if(file_exists("$WEB_ROOT_FS/css")) {
54                 $dh = opendir("$WEB_ROOT_FS/css");
55                 if($dh) {
56                         while(($file = readdir($dh))!==false) {
57                                 $mt = preg_match("/.*.css$/", $file);
58                                 if($mt > 0) {
59                                         error_log("loading css $file");
60                                         echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$BASE_URL/css/$file\">";
61                                         //echo "required $basedir/$file\n";
62                                 }
63                         }
64                 }               
65         }
66
67         // load js
68         if(file_exists("$WEB_ROOT_FS/js")) {
69                 $dh = opendir("$WEB_ROOT_FS/js");
70                 if($dh) {
71                         while(($file = readdir($dh))!==false) {
72                                 $mt = preg_match("/.*.js$/", $file);
73                                 if($mt > 0) {
74                                         error_log("loading js $file");
75                                         echo "<script type=\"text/javascript\" src=\"$BASE_URL/js/$file\"></script>";
76                                         //echo "required $basedir/$file\n";
77                                 }
78                         }
79                 }               
80         }
81         
82         
83         // start body
84         echo "</head><body>";
85         
86         echo "<h1>Git over Web Via PHP</h2>";
87         
88         
89         echo "<table width=\"100%\">";
90
91         if(isset($_SESSION["message"])) {
92                 echo "<tr width=\"100%\"><td colspan=\"2\">";
93                 gwvp_MessageBuilder();
94                 echo "</td></tr>";
95         }
96         
97         echo "<tr width=\"100%\"><td>";
98         gwvp_MenuBuilder();
99         echo "</td><td align=\"right\">";
100         gwvp_LoginBuilder();
101         echo "</td>";
102         
103         echo "</tr>";
104         
105         echo "<tr><td>";
106         if($bodyFunction == null) {
107                 gwvp_BodyBuilder();
108         } else {
109                 if(function_exists($bodyFunction)) {
110                         $bodyFunction();
111                 } else {
112                         error_log("Got called with non-existant body function");
113                         gwvp_BodyBuilder();
114                 }
115         }
116         echo "</td></tr>";
117         
118         echo "<tr><td>";
119         gwvp_TailBuilder();
120         echo "</td></tr></table></body></html>";
121         
122 }
123
124
125 // builds the message builder if its needed
126 function gwvp_MessageBuilder()
127 {
128         $message = "";
129         $messagetype = "info";
130         if(isset($_SESSION["message"])) $message = $_SESSION["message"];
131         if(isset($_SESSION["messagetype"])) $messagetype = $_SESSION["messagetype"];
132         
133         if($message != "") {
134                 switch($messagetype) {
135                         case "info":
136                                 echo "<table border=\"1\" width=\"100%\"><tr width=\"100%\"><td bgcolor=\"#AAFFAA\">$message</td></tr></table>";
137                                 break;
138                         case "error":
139                                 echo "<table border=\"1\" width=\"100%\"><tr width=\"100%\"><td bgcolor=\"#FFAAAA\">$message</td></tr></table>";
140                                 break;
141                 }
142                 unset($_SESSION["message"]);
143                 if(isset($_SESSION["messagetype"])) unset($_SESSION["messagetype"]);
144         }
145 }
146
147 // builds the menu structure
148 function gwvp_MenuBuilder()
149 {
150         global $MENU_ITEMS;
151         
152         ksort($MENU_ITEMS);
153         
154         echo "<table border=\"1\"><tr><td>Menu</td>";
155         foreach($MENU_ITEMS as $key => $val) {
156                 $link = $val["link"];
157                 $text = $val["text"];
158                 echo "<td><a href=\"$link\">$text</a></td>";
159         }
160         echo "</tr></table>";
161         
162 }
163
164 function gwvp_LoginBuilder()
165 {
166         global $WEB_ROOT_FS, $BASE_URL;
167         
168         $login = gwvp_IsLoggedIn();
169         if($login === false) {
170                 gwvp_SingleLineLoginForm();
171         } else {
172                 echo "Hello, ".gwvp_GetFullName($login);
173         }
174 }
175
176 // builds the body structure
177 function gwvp_BodyBuilder()
178 {
179         echo "I AM THE MAIN BODY, FEAR ME!!!!";
180 }
181
182 // builds the tail structure
183 function gwvp_TailBuilder()
184 {
185         echo "<font size=\"-1\"><i>Copyright 2011, PJR - licensed under GPL</i></font>";
186 }
187
188 ?>