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;
6 // the home_page_provders bit is an array
7 global $HOME_PAGE_PROVIDERS;
9 $MENU_ITEMS["00home"]["text"] = "Home";
10 $MENU_ITEMS["00home"]["link"] = "$BASE_URL";
14 function gwvpmini_goWeb()
16 global $CALL_ME_FUNCTIONS;
18 // first we determine if we have a valid setup and run the installer if not
19 /*if(!gwvpmini_issetup()) {
24 // 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
25 // the functions return (i.e. if function returns false, its not it, otherwise it returns a function name we have to call)
26 // this is important for our plugin structure later on - the key on the array serves an an ordering method
27 ksort($CALL_ME_FUNCTIONS);
28 foreach($CALL_ME_FUNCTIONS as $key => $val) {
29 error_log("checking callmefunction $key as $val");
31 if($callme !== false) {
37 // we fell-thru to the main web page builder
38 gwvpmini_goMainPage();
41 function gwvpmini_SendMessage($messagetype, $message)
43 $_SESSION["messagetype"] = $messagetype;
44 $_SESSION["message"] = $message;
47 function gwvpmini_goMainPage($bodyFunction = null)
49 // the main page will look pretty simple, a title, a menu then a body
50 global $WEB_ROOT_FS, $BASE_URL;
52 // a simple web page layout that loads any css and js files that exist in the css and js directories
53 echo "<html><head><title>GWVP Mini</title>";
56 if(file_exists("$WEB_ROOT_FS/css")) {
57 $dh = opendir("$WEB_ROOT_FS/css");
59 while(($file = readdir($dh))!==false) {
60 $mt = preg_match("/.*.css$/", $file);
62 error_log("loading css $file");
63 echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$BASE_URL/css/$file\">";
64 //echo "required $basedir/$file\n";
71 if(file_exists("$WEB_ROOT_FS/js")) {
72 $dh = opendir("$WEB_ROOT_FS/js");
74 while(($file = readdir($dh))!==false) {
75 $mt = preg_match("/.*.js$/", $file);
77 error_log("loading js $file");
78 echo "<script type=\"text/javascript\" src=\"$BASE_URL/js/$file\"></script>";
79 //echo "required $basedir/$file\n";
89 echo "<h1>Git over Web Via PHP - Mini Version</h2>";
92 echo "<table width=\"100%\">";
94 if(isset($_SESSION["message"])) {
95 echo "<tr width=\"100%\"><td colspan=\"2\">";
96 gwvpmini_MessageBuilder();
100 echo "<tr width=\"100%\" bgcolor=\"#ddffdd\"><td>";
101 gwvpmini_MenuBuilder();
102 echo "</td><td align=\"right\">";
103 gwvpmini_LoginBuilder();
109 if($bodyFunction == null) {
110 gwvpmini_BodyBuilder();
112 if(function_exists($bodyFunction)) {
115 error_log("Got called with non-existant body function, $bodyFunction");
116 gwvpmini_BodyBuilder();
122 gwvpmini_TailBuilder();
123 echo "</td></tr></table></body></html>";
128 // builds the message builder if its needed
129 function gwvpmini_MessageBuilder()
132 $messagetype = "info";
133 if(isset($_SESSION["message"])) $message = $_SESSION["message"];
134 if(isset($_SESSION["messagetype"])) $messagetype = $_SESSION["messagetype"];
137 switch($messagetype) {
139 echo "<table border=\"1\" width=\"100%\"><tr width=\"100%\"><td bgcolor=\"#AAFFAA\">$message</td></tr></table>";
142 echo "<table border=\"1\" width=\"100%\"><tr width=\"100%\"><td bgcolor=\"#FFAAAA\">$message</td></tr></table>";
145 unset($_SESSION["message"]);
146 if(isset($_SESSION["messagetype"])) unset($_SESSION["messagetype"]);
150 // builds the menu structure
151 function gwvpmini_MenuBuilder()
153 global $MENU_ITEMS, $BASE_URL;
157 echo "<table border=\"1\"><tr><td><b><i>Menu</i></b></td>";
158 foreach($MENU_ITEMS as $key => $val) {
159 $link = $val["link"];
160 $text = $val["text"];
162 // TODO: redo this bit with stristr to find urls - special case for home
164 if(isset($_REQUEST["q"])) {
165 $extlink = str_replace("$BASE_URL/", "", $link);
166 error_log("trying to do replace of $BASE_URL in $link, got $extlink for ".$_REQUEST["q"]);
167 if(stristr($_REQUEST["q"], $extlink)!==false) {
168 $menucolor = " bgcolor=\"#ffdddd\"";
172 // special case for home
173 if($link == $BASE_URL) $menucolor = " bgcolor=\"#ffdddd\"";
179 if(isset($val["userlevel"])) {
180 if(gwvpmini_CheckAuthLevel($val["userlevel"])) {
181 echo "<td$menucolor><a href=\"$link\">$text</a></td>";
185 echo "<td$menucolor><a href=\"$link\">$text</a></td>";
188 echo "</tr></table>";
192 function gwvpmini_LoginBuilder()
194 global $WEB_ROOT_FS, $BASE_URL;
196 $login = gwvpmini_IsLoggedIn();
197 if($login === false) {
198 gwvpmini_SingleLineLoginForm();
200 echo "Hello ".$_SESSION["fullname"]." <a href=\"$BASE_URL/logout\">logout</a>";
204 // builds the body structure
205 function gwvpmini_BodyBuilder()
207 global $HOME_PAGE_PROVIDERS;
209 echo "I AM THE MAIN BODY, FEAR ME!!!! - have no idea whats going to go here";
210 if(isset($HOME_PAGE_PROVIDERS)) {
211 ksort($HOME_PAGE_PROVIDERS);
212 foreach($HOME_PAGE_PROVIDERS as $provider) {
213 error_log("Loading home_page_provider, $provider");
219 // builds the tail structure
220 function gwvpmini_TailBuilder()
222 echo "<font size=\"-1\"><i>Copyright 2011, PJR - licensed under GPL</i></font>";
225 function gwvpmini_fourZeroThree()
227 error_log("403 called");
228 header("HTTP/1.0 403 Permission Denied");
231 function gwvpmini_fourZeroFour()
233 error_log("404 called");
234 header("HTTP/1.0 404 No Such Thing");