completed an install of centos.. yay
[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                 error_log("urldecode: ".urldecode($url));
26                 $call_class->go($url);
27         }
28         
29         private $config;
30         
31 }
32
33 function GLCASMenuBuilder()
34 {
35         global $BASE_URL;
36         ?>
37 <a href="<?php echo $BASE_URL ?>">Home</a>
38 <a href="<?php echo $BASE_URL."/admin/"?>">Admin</a>
39         <?php
40 }
41
42 function GLCASMessageBuilder()
43 {
44         echo "<i>Messages not implemented yet</i>";
45 }
46
47 function GLCASpageBuilder($bodyClass, $bodyFunction, $bodycontent, $title="GLCAS")
48 {
49         global $WEB_ROOT_FS, $BASE_URL;
50         
51         // TODO: load css
52         // header
53         echo "<html><head><title>$title</title>";
54         
55         // load css
56         if(file_exists("$WEB_ROOT_FS/css")) {
57                 $dh = opendir("$WEB_ROOT_FS/css");
58                 if($dh) {
59                         while(($file = readdir($dh))!==false) {
60                                 $mt = preg_match("/.*.css$/", $file);
61                                 if($mt > 0) {
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";
65                                 }
66                         }
67                 }               
68         }
69
70         // load js
71         if(file_exists("$WEB_ROOT_FS/js")) {
72                 $dh = opendir("$WEB_ROOT_FS/js");
73                 if($dh) {
74                         while(($file = readdir($dh))!==false) {
75                                 $mt = preg_match("/.*.js$/", $file);
76                                 if($mt > 0) {
77                                         error_log("loading js $file");
78                                         echo "<script type=\"text/javascript\" src=\"$BASE_URL/css/$file\"></script>";
79                                         //echo "required $basedir/$file\n";
80                                 }
81                         }
82                 }               
83         }
84         
85         
86         // start body
87         echo "</head><body>";
88         
89         // page top
90         echo "<h1>GLCAS</h1><br>";
91         echo "<table><tr><td>";
92         GLCASMessageBuilder();
93         echo "<td></tr><tr><td>";
94         
95         // menu, then body
96         echo "<table><tr><td>";
97         GLCASMenuBuilder();
98         echo "</td></tr><tr><td>";
99         // body
100         $url = "/";
101         if(isset($_REQUEST["q"])) {
102                 $url = $_REQUEST["q"];
103         }
104         
105         if($bodyClass != null) {
106                 $bodyClass->$bodyFunction($url);
107         } else if( $bodyFunction != null) {
108                 $bodyFunction($url);
109         } else echo $bodycontent;
110         echo "</td></tr></table>";
111         
112         
113         // close the big wrap-around table
114         echo "</td></tr></table>";
115         
116         // footer
117         echo "<br><font size=\"-1\">Copyright 2011, PJR</font><br></body></html>";
118         
119 }
120
121
122 ?>