reaplced the git service code (main gitbackendinterface()) with a new
[gwvp.git] / gwvplib / gwvpweb.php
index 8148e00..3cc931c 100644 (file)
@@ -1,9 +1,241 @@
 <?php
 
+// this function is the initial insertion point for the web calls, here we need to determine where we go
+global $CALL_ME_FUNCTIONS;
 
-funciton goWeb()
+// the home_page_provders bit is an array 
+global $HOME_PAGE_PROVIDERS;
+
+$MENU_ITEMS["00home"]["text"] = "Home";
+$MENU_ITEMS["00home"]["link"] = "$BASE_URL";
+
+
+
+function gwvp_goWebBegin()
+{
+       global $CALL_ME_FUNCTIONS;
+       
+       // first we determine if we have a valid setup and run the installer if not
+       if(!gwvp_issetup()) {
+               gwvp_goSetup();
+               return;
+       }
+       
+       // 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
+       // the functions return (i.e. if function returns false, its not it, otherwise it returns a function name we have to call)
+       // this is important for our plugin structure later on - the key on the array serves an an ordering method
+       ksort($CALL_ME_FUNCTIONS);
+       foreach($CALL_ME_FUNCTIONS as $key => $val) {
+               error_log("checking callmefunction $key as $val");
+               $callme = $val();
+               if($callme !== false) {
+                       $callme();
+                       return;
+               }
+       }
+       
+       // we fell-thru to the main web page builder
+       gwvp_goMainPage();
+}
+
+function gwvp_SendMessage($messagetype, $message)
+{
+       $_SESSION["messagetype"] = $messagetype;
+       $_SESSION["message"] = $message;
+}
+
+function gwvp_goMainPage($bodyFunction = null)
+{
+       // the main page will look pretty simple, a title, a menu then a body
+       global $WEB_ROOT_FS, $BASE_URL;
+       
+       // a simple web page layout that loads any css and js files that exist in the css and js directories
+       echo "<html><head><title>GWVP</title>";
+       
+       // load css
+       if(file_exists("$WEB_ROOT_FS/css")) {
+               $dh = opendir("$WEB_ROOT_FS/css");
+               if($dh) {
+                       while(($file = readdir($dh))!==false) {
+                               $mt = preg_match("/.*.css$/", $file);
+                               if($mt > 0) {
+                                       error_log("loading css $file");
+                                       echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$BASE_URL/css/$file\">";
+                                       //echo "required $basedir/$file\n";
+                               }
+                       }
+               }               
+       }
+
+       // load js
+       if(file_exists("$WEB_ROOT_FS/js")) {
+               $dh = opendir("$WEB_ROOT_FS/js");
+               if($dh) {
+                       while(($file = readdir($dh))!==false) {
+                               $mt = preg_match("/.*.js$/", $file);
+                               if($mt > 0) {
+                                       error_log("loading js $file");
+                                       echo "<script type=\"text/javascript\" src=\"$BASE_URL/js/$file\"></script>";
+                                       //echo "required $basedir/$file\n";
+                               }
+                       }
+               }               
+       }
+       
+       
+       // start body
+       echo "</head><body>";
+       
+       echo "<h1>Git over Web Via PHP</h2>";
+       
+       
+       echo "<table width=\"100%\">";
+
+       if(isset($_SESSION["message"])) {
+               echo "<tr width=\"100%\"><td colspan=\"2\">";
+               gwvp_MessageBuilder();
+               echo "</td></tr>";
+       }
+       
+       echo "<tr width=\"100%\" bgcolor=\"#ddffdd\"><td>";
+       gwvp_MenuBuilder();
+       echo "</td><td align=\"right\">";
+       gwvp_LoginBuilder();
+       echo "</td>";
+       
+       echo "</tr>";
+       
+       echo "<tr><td>";
+       if($bodyFunction == null) {
+               gwvp_BodyBuilder();
+       } else {
+               if(function_exists($bodyFunction)) {
+                       $bodyFunction();
+               } else {
+                       error_log("Got called with non-existant body function, $bodyFunction");
+                       gwvp_BodyBuilder();
+               }
+       }
+       echo "</td></tr>";
+       
+       echo "<tr><td>";
+       gwvp_TailBuilder();
+       echo "</td></tr></table></body></html>";
+       
+}
+
+
+// builds the message builder if its needed
+function gwvp_MessageBuilder()
+{
+       $message = "";
+       $messagetype = "info";
+       if(isset($_SESSION["message"])) $message = $_SESSION["message"];
+       if(isset($_SESSION["messagetype"])) $messagetype = $_SESSION["messagetype"];
+       
+       if($message != "") {
+               switch($messagetype) {
+                       case "info":
+                               echo "<table border=\"1\" width=\"100%\"><tr width=\"100%\"><td bgcolor=\"#AAFFAA\">$message</td></tr></table>";
+                               break;
+                       case "error":
+                               echo "<table border=\"1\" width=\"100%\"><tr width=\"100%\"><td bgcolor=\"#FFAAAA\">$message</td></tr></table>";
+                               break;
+               }
+               unset($_SESSION["message"]);
+               if(isset($_SESSION["messagetype"])) unset($_SESSION["messagetype"]);
+       }
+}
+
+// builds the menu structure
+function gwvp_MenuBuilder()
+{
+       global $MENU_ITEMS, $BASE_URL;
+       
+       ksort($MENU_ITEMS);
+       
+       echo "\n\n\n";
+       echo "<table border=\"1\"><tr><td><b><i>Menu</i></b></td>";
+       foreach($MENU_ITEMS as $key => $val) {
+               $link = $val["link"];
+               $text = $val["text"];
+               
+               // TODO: redo this bit with stristr to find urls - special case for home
+               $menucolor = "";
+               if(isset($_REQUEST["q"])) {
+                       $extlink = str_replace("$BASE_URL/", "", $link);
+                       error_log("trying to do replace of $BASE_URL in $link, got $extlink for ".$_REQUEST["q"]);
+                       if(stristr($_REQUEST["q"], $extlink)!==false) {
+                               $menucolor = " bgcolor=\"#ffdddd\"";
+                               
+                       }
+               } else {
+                       // special case for home
+                       if($link == $BASE_URL) $menucolor = " bgcolor=\"#ffdddd\"";
+               }
+               
+               
+               
+               
+               if(isset($val["userlevel"])) {
+                       if(gwvp_CheckAuthLevel($val["userlevel"])) {
+                               echo "<td$menucolor><a href=\"$link\">$text</a></td>";
+                       }
+                       
+               } else {
+                       echo "<td$menucolor><a href=\"$link\">$text</a></td>";
+               }
+       }
+       echo "</tr></table>";
+       echo "\n\n\n";
+       
+}
+
+function gwvp_LoginBuilder()
+{
+       global $WEB_ROOT_FS, $BASE_URL;
+       
+       echo "\n\n\n";
+       $login = gwvp_IsLoggedIn();
+       if($login === false) {
+               gwvp_SingleLineLoginForm();
+       } else {
+               echo "Hello, ".gwvp_GetFullName($login)." <a href=\"$BASE_URL/logout\">logout</a>";
+       }
+       echo "\n\n\n";
+}
+
+// builds the body structure
+function gwvp_BodyBuilder()
 {
+       global $HOME_PAGE_PROVIDERS;
        
+       echo "I AM THE MAIN BODY, FEAR ME!!!! - have no idea whats going to go here";
+       if(isset($HOME_PAGE_PROVIDERS)) {
+               ksort($HOME_PAGE_PROVIDERS);
+               foreach($HOME_PAGE_PROVIDERS as $provider) {
+                       error_log("Loading home_page_provider, $provider");
+                       $provider();
+               }
+       }
+}
+
+// builds the tail structure
+function gwvp_TailBuilder()
+{
+       echo "<font size=\"-1\"><i>Copyright 2011, PJR - licensed under GPL</i></font>";
+}
+
+function gwvp_fourZeroThree()
+{
+       header("HTTP/1.0 403 Permission Denied");
 }
 
+function gwvp_fourZeroFour()
+{
+       header("HTTP/1.0 404 No Such Thing");
+}
+
+
+
 ?>
\ No newline at end of file