14 |
require_once($phphtmllib."/widgets/HTMLPageClass.inc"); |
require_once($phphtmllib."/widgets/HTMLPageClass.inc"); |
15 |
|
|
16 |
/** |
/** |
17 |
|
* We need to make sure we have the MessageBoxWidget loaded |
18 |
|
* for the permissions checking. |
19 |
|
* |
20 |
|
* NOTE: The InfoTable css classes must be included in any |
21 |
|
* page that uses the permissions checking. |
22 |
|
*/ |
23 |
|
require_once($phphtmllib."/widgets/MessageBoxWidget.inc"); |
24 |
|
|
25 |
|
/** |
26 |
* This class is used to build content |
* This class is used to build content |
27 |
* for an entire page. It uses the |
* for an entire page. It uses the |
28 |
* HTMLPageClass widget from phphtmllib |
* HTMLPageClass widget from phphtmllib |
33 |
*/ |
*/ |
34 |
class PageWidget extends HTMLPageClass { |
class PageWidget extends HTMLPageClass { |
35 |
|
|
36 |
/** CLASS VARS **/ |
/** CLASS VARS **/ |
37 |
|
|
38 |
/** |
/** |
39 |
* This enables the ability to view the |
* This enables the ability to view the |
40 |
* source of a page bu setting debug=1 |
* source of a page bu setting debug=1 |
41 |
* in the query string. |
* in the query string. |
42 |
* |
* |
43 |
*/ |
*/ |
44 |
var $_enable_debug = FALSE; |
var $_enable_debug = FALSE; |
45 |
|
|
46 |
|
|
47 |
/** |
/** |
51 |
*/ |
*/ |
52 |
var $_title_text = NULL; |
var $_title_text = NULL; |
53 |
|
|
54 |
|
/** |
55 |
|
* Does the user have permission |
56 |
|
* to build and view the content? |
57 |
|
*/ |
58 |
|
var $_perm_options = array("allowed" => TRUE, |
59 |
|
"message" => "You are not allowed to view this page.", |
60 |
|
"url" => NULL); |
61 |
|
|
62 |
|
/** |
63 |
|
* the message box for displaying |
64 |
|
* permissions errors |
65 |
|
*/ |
66 |
|
var $_permission_box = NULL; |
67 |
|
|
68 |
/** |
/** |
69 |
* Constructor: |
* This is to enable/disable the |
70 |
* |
* permissions checking. |
71 |
|
* By default it is off. |
72 |
|
*/ |
73 |
|
var $_allow_permissions_checks = FALSE; |
74 |
|
|
75 |
|
|
76 |
|
/** |
77 |
|
* The width of the permissions dialog |
78 |
|
* table. |
79 |
|
*/ |
80 |
|
var $_permissions_error_width = "50%"; |
81 |
|
|
82 |
|
|
83 |
|
/** |
84 |
|
* Constructor: |
85 |
|
* |
86 |
* @param mixed - $title Title string or TITLEtag object for the page. |
* @param mixed - $title Title string or TITLEtag object for the page. |
87 |
* @param string - one of 3 types of html to render. Setting this will |
* @param string - one of 3 types of html to render. Setting this will |
88 |
* make the object declare the gobal define which tells |
* make the object declare the gobal define which tells |
96 |
* - doctype is XHTML transitional. |
* - doctype is XHTML transitional. |
97 |
* "xhtml_strict" - render xhtml instead of html 4.0. |
* "xhtml_strict" - render xhtml instead of html 4.0. |
98 |
* - doctype is XHTML strict. |
* - doctype is XHTML strict. |
99 |
* @param int - one of 2 types. INDENT_NICE or INDENT_LEFT_JUSTIFY |
* @param int - one of 2 types. INDENT_NICE or INDENT_LEFT_JUSTIFY |
100 |
* This tells the page how to render the indenting of the |
* This tells the page how to render the indenting of the |
101 |
* output. By default it is set to INDENT_NICE, which nicely |
* output. By default it is set to INDENT_NICE, which nicely |
102 |
* indents each nested tag. You can have all tags rendered |
* indents each nested tag. You can have all tags rendered |
103 |
* left justified (smaller size in output) by using |
* left justified (smaller size in output) by using |
104 |
* INDENT_LEFT_JUSTIFY |
* INDENT_LEFT_JUSTIFY |
105 |
* |
* |
106 |
*/ |
*/ |
107 |
function PageWidget( $title, $render_type = HTML, $indent_style=INDENT_NICE ) { |
function PageWidget( $title, $render_type = HTML, $indent_style=INDENT_NICE ) { |
108 |
|
|
109 |
if ( defined("DEBUG") && |
if ( defined("DEBUG") && |
110 |
(isset($_GET["debug"]) || |
(isset($_GET["debug"]) || |
111 |
isset($_POST["debug"]) ) ) { |
isset($_POST["debug"]) ) ) { |
112 |
$this->enable_debug( TRUE ); |
$this->enable_debug( TRUE ); |
113 |
} |
} |
114 |
//save the title for later. |
//save the title for later. |
115 |
$this->_title_text = $title; |
$this->_title_text = $title; |
116 |
|
|
117 |
//call the parent's constructor |
//call the parent's constructor |
118 |
$this->HTMLPageClass( $title, $render_type, $indent_style ); |
$this->HTMLPageClass( $title, $render_type, $indent_style ); |
119 |
} |
|
120 |
|
//see if we are allowed to check permissions |
121 |
|
//You need to have the CSS definitions for the |
122 |
|
//InfoTable defined in order to see the error |
123 |
|
//table correctly. Or you can override the |
124 |
|
//_build_permission_box() method to provide |
125 |
|
//a different object for displaying the |
126 |
|
//permission errors. |
127 |
|
if ($this->_allow_permissions_checks) { |
128 |
|
//check the permissions on this page |
129 |
|
$this->_check_permissions(); |
130 |
|
} |
131 |
|
} |
132 |
|
|
133 |
/** |
/** |
134 |
* gets the current title of the page. |
* gets the current title of the page. |
139 |
return $this->_title_text; |
return $this->_title_text; |
140 |
} |
} |
141 |
|
|
142 |
/** |
/** |
143 |
* This function is used to build |
* This function is used to build |
144 |
* addition head content that isn't |
* addition head content that isn't |
145 |
* built by the HTMLPageClass parent |
* built by the HTMLPageClass parent |
146 |
* class by default. |
* class by default. |
147 |
* NOTE: you can add addition content |
* NOTE: you can add addition content |
148 |
* to the head in 1 of 2 ways. |
* to the head in 1 of 2 ways. |
149 |
* 1) inside the call return the |
* 1) inside the call return the |
150 |
* addition content in the |
* addition content in the |
151 |
* return $foo; |
* return $foo; |
152 |
* 2) or use the HTMLPageClass' |
* 2) or use the HTMLPageClass' |
153 |
* $this->add_head_content() |
* $this->add_head_content() |
154 |
* from within the head_content() |
* from within the head_content() |
155 |
* call. |
* call. |
156 |
* |
* |
157 |
* @return mixed. |
* @return mixed. |
158 |
*/ |
*/ |
159 |
function head_content() { |
function head_content() { |
160 |
return NULL; |
return NULL; |
161 |
} |
} |
162 |
|
|
163 |
|
|
164 |
/** |
/** |
165 |
* This function is meant to be overridden |
* This function is meant to be overridden |
166 |
* by the child class. |
* by the child class. |
167 |
* This provides all of the content |
* This provides all of the content |
168 |
* for the page. |
* for the page. |
169 |
* NOTE: You add the content to the |
* NOTE: You add the content to the |
170 |
* body in 1 of 2 ways. |
* body in 1 of 2 ways. |
171 |
* 1) return the content from this |
* 1) return the content from this |
172 |
* call. |
* call. |
173 |
* 2) inside the call, you can |
* 2) inside the call, you can |
174 |
* just call $this->add(); |
* just call $this->add(); |
175 |
* and then return NULL; |
* and then return NULL; |
176 |
* |
* |
177 |
* @return mixed. |
* @return mixed. |
178 |
*/ |
*/ |
179 |
function body_content() { |
function body_content() { |
180 |
return NULL; |
return NULL; |
181 |
} |
} |
182 |
|
|
183 |
|
|
184 |
/** |
/** |
185 |
* This function is used to save |
* This function is used to save |
186 |
* a frameset to the page. This will |
* a frameset to the page. This will |
187 |
* automatically output a properly |
* automatically output a properly |
188 |
* formatted |
* formatted |
189 |
*/ |
*/ |
190 |
function frameset() { |
function frameset() { |
191 |
return NULL; |
return NULL; |
192 |
} |
} |
193 |
|
|
194 |
/** |
/** |
195 |
* This function is called to build |
* This function is called to build |
196 |
* any JavaScript that is needed in the |
* any JavaScript that is needed in the |
197 |
* <HEAD> portion of a document. |
* <HEAD> portion of a document. |
198 |
* |
* |
199 |
* @return string - the raw JS code to be |
* @return string - the raw JS code to be |
200 |
* put inside the <head> |
* put inside the <head> |
201 |
*/ |
*/ |
202 |
function head_javascript() { |
function head_javascript() { |
203 |
return NULL; |
return NULL; |
204 |
} |
} |
205 |
|
|
206 |
|
|
207 |
/** |
/** |
208 |
* This sets the debug option for |
* This sets the debug option for |
209 |
* the HTMLPageClass |
* the HTMLPageClass |
210 |
* |
* |
211 |
* @param boolean TRUE for on, FALSE for off |
* @param boolean TRUE for on, FALSE for off |
212 |
*/ |
*/ |
213 |
function enable_debug( $flag = TRUE ) { |
function enable_debug( $flag = TRUE ) { |
214 |
$this->_enable_debug = $flag; |
$this->_enable_debug = $flag; |
215 |
} |
} |
216 |
|
|
217 |
|
|
218 |
/** |
/** |
219 |
* This is the function that renders the HTML |
* This is the function that renders the HTML |
220 |
* for this widget. |
* for this widget. |
221 |
* |
* |
222 |
* @return string - the HTML |
* @return string - the HTML |
223 |
*/ |
*/ |
224 |
function render() { |
function render() { |
225 |
|
|
226 |
//test to see if they want debugging of |
//test to see if they want debugging of |
227 |
//output enabled. |
//output enabled. |
228 |
if ( $this->_enable_debug ) { |
if ( $this->_enable_debug ) { |
229 |
if ( isset($_GET["debug"]) ) { |
if ( isset($_GET["debug"]) ) { |
230 |
$this->set_text_debug( TRUE ); |
$this->set_text_debug( TRUE ); |
231 |
} |
} |
232 |
} |
} |
233 |
|
|
234 |
//check to see if they want to render a frameset |
//see if we have permissions to build the |
235 |
$frameset = $this->frameset(); |
//content for this page. If permissions checks |
236 |
if ( $frameset != NULL ) { |
//aren't allowed, this will pass. |
237 |
//add and set the page output |
if ($this->_has_permission()) { |
238 |
//to be a frameset. |
//check to see if they want to render a frameset |
239 |
$this->set_frameset( $frameset ); |
$frameset = $this->frameset(); |
240 |
} else { |
if ( $frameset != NULL ) { |
241 |
|
//add and set the page output |
242 |
//Try and get some more head content |
//to be a frameset. |
243 |
$content = ""; |
$this->set_frameset( $frameset ); |
244 |
$content = $this->head_content(); |
} else { |
245 |
if ( $content != "" ) { |
|
246 |
$this->add_head_content( $content ); |
//Try and get some more head content |
247 |
} |
$content = ""; |
248 |
|
$content = $this->head_content(); |
249 |
//try and get the body content. |
if ( $content != "" ) { |
250 |
//the user could just have added |
$this->add_head_content( $content ); |
251 |
//the data manually. |
} |
252 |
$content = ""; |
|
253 |
$content = $this->body_content(); |
//try and get the body content. |
254 |
if ( $content != "" ) { |
//the user could just have added |
255 |
$this->add( $content ); |
//the data manually. |
256 |
} |
$content = ""; |
257 |
} |
$content = $this->body_content(); |
258 |
|
if ( $content != "" ) { |
259 |
//Lets see if they have any javascript |
$this->add( $content ); |
260 |
//for the head |
} |
261 |
$js = $this->head_javascript(); |
} |
262 |
if ( $js != NULL ) { |
|
263 |
$this->add_head_js( $js ); |
//Lets see if they have any javascript |
264 |
} |
//for the head |
265 |
|
$js = $this->head_javascript(); |
266 |
|
if ( $js != NULL ) { |
267 |
|
$this->add_head_js( $js ); |
268 |
|
} |
269 |
|
} else { |
270 |
|
$this->add( html_br(), $this->_permission_box); |
271 |
|
} |
272 |
|
|
273 |
|
return HTMLPageClass::render(); |
274 |
|
} |
275 |
|
|
276 |
|
|
277 |
return HTMLPageClass::render(); |
/** |
278 |
} |
* This method is used to enable or disable the |
279 |
|
* built in permissions checking mechanism. |
280 |
|
* |
281 |
|
* @param boolean TRUE = enable permissions checks |
282 |
|
*/ |
283 |
|
function allow_permissions_checks($flag=true) { |
284 |
|
$this->_allow_permissions_checks = $flag; |
285 |
|
} |
286 |
|
|
287 |
|
|
288 |
|
/** |
289 |
|
* This method allows all PageWidget children to |
290 |
|
* do any kind of permissions checking before |
291 |
|
* any content methods are called. |
292 |
|
* This allows for a very secure method of building |
293 |
|
* and rendering the page content. |
294 |
|
* |
295 |
|
*/ |
296 |
|
function _check_permissions() { |
297 |
|
//call the child permission() method |
298 |
|
if ( !$this->permission() ) { |
299 |
|
//looks like the user doesn't have |
300 |
|
//permissions to view this page |
301 |
|
$this->_set_perms( FALSE ); |
302 |
|
|
303 |
|
$this->_build_permission_box(); |
304 |
|
} |
305 |
|
} |
306 |
|
|
307 |
|
/** |
308 |
|
* This is meant to be extended by the child class |
309 |
|
* to do any generic permissions checking for access |
310 |
|
* to the content that the child builds |
311 |
|
* |
312 |
|
* @return boolean - TRUE = has permissions to build |
313 |
|
* and view content. |
314 |
|
*/ |
315 |
|
function permission() { |
316 |
|
//by default return true. |
317 |
|
return true; |
318 |
|
} |
319 |
|
|
320 |
|
/** |
321 |
|
* set the value of the permissions |
322 |
|
* |
323 |
|
* @param boolean - TRUE = has permission |
324 |
|
*/ |
325 |
|
function _set_perms( $flag ) { |
326 |
|
$this->_perm_options["allowed"] = $flag; |
327 |
|
} |
328 |
|
|
329 |
|
/** |
330 |
|
* do we have permissions to build/view the content? |
331 |
|
* |
332 |
|
* @return boolean |
333 |
|
*/ |
334 |
|
function _has_permission() { |
335 |
|
if (!$this->_allow_permissions_checks) { |
336 |
|
//permissions checks aren't allowed |
337 |
|
//so just return true. |
338 |
|
return TRUE; |
339 |
|
} else { |
340 |
|
return $this->_perm_options["allowed"]; |
341 |
|
} |
342 |
|
} |
343 |
|
|
344 |
|
/** |
345 |
|
* This is used to set the various options for displaying |
346 |
|
* the failed permissions box. This should be called |
347 |
|
* prior to returning false in the permissions() method |
348 |
|
* |
349 |
|
* @param string - the permissions message |
350 |
|
* NOTE: NULL message means use the default. |
351 |
|
* @param string - the url where to go to. |
352 |
|
* NOTE: if NULL, then there will be no |
353 |
|
* button shown |
354 |
|
*/ |
355 |
|
function set_permissions_message($message=NULL, $url=NULL) { |
356 |
|
if ( $message != NULL ) { |
357 |
|
$this->_perm_options["message"] = $message; |
358 |
|
} |
359 |
|
$this->_perm_options["url"] = $url; |
360 |
|
} |
361 |
|
|
362 |
|
/** |
363 |
|
* This is the method used to build the |
364 |
|
* object to display the permissions error. |
365 |
|
* |
366 |
|
* By default it uses either the MessageBoxWidget |
367 |
|
* or the MessageBoxOK widget which both rely on |
368 |
|
* having the InfoTable object's css included in the page. |
369 |
|
* |
370 |
|
* @return none |
371 |
|
*/ |
372 |
|
function _build_permission_box() { |
373 |
|
if ( $this->_perm_options["url"] == NULL ) { |
374 |
|
$this->_permission_box = new MessageBoxWidget("Error", $this->_permissions_error_width, |
375 |
|
$this->_perm_options["message"]); |
376 |
|
} else { |
377 |
|
$this->_permission_box = new MessageBoxOK("Error", $this->_permissions_error_width, |
378 |
|
$this->_perm_options["message"], |
379 |
|
$this->_perm_options["url"]); |
380 |
|
} |
381 |
|
} |
382 |
} |
} |
383 |
?> |
?> |