96d30b186052c0abe5c833e2aab4e9243fc647bf
[glcas.git] / libglcas / web.php
1 <?php 
2
3 // if i believed in name spacing in php, i'd use it.
4 error_log("glcasweb loaded");
5
6 class GLCASWeb {
7         
8         function __construct($config)
9         {
10                 $this->config = $config;
11         }
12         
13         function go($urlhandlers)
14         {
15                 $url = "/";
16                 if(isset($_REQUEST["q"])) {
17                         $url = $_REQUEST["q"];
18                 }
19                 
20                 // create a url parser
21                 $urlparser = new GLCASUrlParser($urlhandlers, $this->config);
22                 
23                 // 
24                 $call_class = $urlparser->getClass($url);
25                 $call_class->go($url);
26         }
27         
28         private $config;
29         
30 }
31
32 function GLCASMenuBuilder()
33 {
34         global $BASE_URL;
35         ?>
36 <a href="<?php echo $BASE_URL ?>">Home</a>
37 <a href="<?php echo $BASE_URL."/admin/"?>">Admin</a>
38         <?php
39 }
40
41 function GLCASMessageBuilder()
42 {
43         echo "<i>Messages not implemented yet</i>";
44 }
45
46 function GLCASpageBuilder($bodyClass, $bodyFunction, $bodycontent, $title="GLCAS")
47 {
48         global $WEB_ROOT_FS, $BASE_URL;
49         
50         // TODO: load css
51         // header
52         echo "<html><head><title>$title</title>";
53         
54         // load css
55         if(file_exists("$WEB_ROOT_FS/css")) {
56                 $dh = opendir("$WEB_ROOT_FS/css");
57                 if($dh) {
58                         while(($file = readdir($dh))!==false) {
59                                 $mt = preg_match("/.*.css$/", $file);
60                                 if($mt > 0) {
61                                         error_log("loading css $file");
62                                         echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$BASE_URL/css/$file\">";
63                                         //echo "required $basedir/$file\n";
64                                 }
65                         }
66                 }               
67         }
68
69         // load js
70         if(file_exists("$WEB_ROOT_FS/js")) {
71                 $dh = opendir("$WEB_ROOT_FS/js");
72                 if($dh) {
73                         while(($file = readdir($dh))!==false) {
74                                 $mt = preg_match("/.*.js$/", $file);
75                                 if($mt > 0) {
76                                         error_log("loading js $file");
77                                         echo "<script type=\"text/javascript\" src=\"$BASE_URL/css/$file\"></script>";
78                                         //echo "required $basedir/$file\n";
79                                 }
80                         }
81                 }               
82         }
83         
84         
85         // start body
86         echo "</head><body>";
87         
88         // page top
89         echo "<h1>GLCAS</h1><br>";
90         echo "<table><tr><td>";
91         GLCASMessageBuilder();
92         echo "<td></tr><tr><td>";
93         
94         // menu, then body
95         echo "<table><tr><td>";
96         GLCASMenuBuilder();
97         echo "</td></tr><tr><td>";
98         // body
99         $url = "/";
100         if(isset($_REQUEST["q"])) {
101                 $url = $_REQUEST["q"];
102         }
103         
104         if($bodyClass != null) {
105                 $bodyClass->$bodyFunction($url);
106         } else if( $bodyFunction != null) {
107                 $bodyFunction($url);
108         } else echo $bodycontent;
109         echo "</td></tr></table>";
110         
111         
112         // close the big wrap-around table
113         echo "</td></tr></table>";
114         
115         // footer
116         echo "<br><font size=\"-1\">Copyright 2011, PJR</font><br></body></html>";
117         
118 }
119
120
121 ?>