| 1 | <?php | 
| 2 |  | 
| 3 | /** | 
| 4 | * This example illustrates the use of the | 
| 5 | * permissions checking mechanism built into the | 
| 6 | * PageWidget object. | 
| 7 | * | 
| 8 | * | 
| 9 | * $Id: widget13.php,v 1.2 2004/02/03 23:46:51 hemna Exp $ | 
| 10 | * | 
| 11 | * @author Walter A. Boring IV <waboring@buildabetterweb.com> | 
| 12 | * @package phpHtmlLib | 
| 13 | * @subpackage widget-examples | 
| 14 | * @version 2.4.0 | 
| 15 | * | 
| 16 | */ | 
| 17 |  | 
| 18 | /** | 
| 19 | * Include the phphtmllib libraries | 
| 20 | * | 
| 21 | */ | 
| 22 | include_once("includes.inc"); | 
| 23 |  | 
| 24 | class PermissionsCheckTestPage extends PageWidget { | 
| 25 |  | 
| 26 |  | 
| 27 | function PermissionsCheckTestPage($title) { | 
| 28 | //turn on the ability to do a permissions check | 
| 29 | $this->allow_permissions_checks(TRUE); | 
| 30 |  | 
| 31 | $this->PageWidget($title, HTML); | 
| 32 |  | 
| 33 | //we need this for the css defined for the InfoTable | 
| 34 | //for the DialogWidget.  The DialogWidget uses InfoTable. | 
| 35 | $this->add_css_link("/phphtmllib/css/defaulttheme.php"); | 
| 36 | } | 
| 37 |  | 
| 38 | /** | 
| 39 | * This method is called during constructor time to check | 
| 40 | * to make sure the page is allowed to build and render | 
| 41 | * any content. | 
| 42 | * | 
| 43 | * @return boolean FALSE = not allowed. | 
| 44 | */ | 
| 45 | function permission() { | 
| 46 | //If you want to see a 'permissions' error | 
| 47 | //on this page then pass in the query string | 
| 48 | //variable 'failed=1' on the url to this script. | 
| 49 | if (isset($_REQUEST["failed"])) { | 
| 50 | //ok we 'failed'.  Lets set the specialized | 
| 51 | //error message with a link to go back. | 
| 52 | $this->set_permissions_message( | 
| 53 | container("You don't have permissions!", | 
| 54 | html_br(2), | 
| 55 | html_a($_SERVER["PHP_SELF"],"GO BACK"))); | 
| 56 | return false; | 
| 57 | } | 
| 58 | return true; | 
| 59 | } | 
| 60 |  | 
| 61 | /** | 
| 62 | * This will only get called if we have permissions to | 
| 63 | * build and render the content for this page object. | 
| 64 | * | 
| 65 | * @return object | 
| 66 | */ | 
| 67 | function body_content() { | 
| 68 | $dialog = new MessageBoxWidget("Some title", "400", | 
| 69 | container("This is a message", | 
| 70 | html_br(2), | 
| 71 | "Want to see a permissions error?", | 
| 72 | html_br(), | 
| 73 | html_a($_SERVER["PHP_SELF"]."?failed=1", | 
| 74 | "Click Here")) | 
| 75 | ); | 
| 76 |  | 
| 77 | return $dialog; | 
| 78 | } | 
| 79 | } | 
| 80 |  | 
| 81 | //build the Page object and try and | 
| 82 | //render it's content. | 
| 83 | //the permissions checking happens at | 
| 84 | //'constructor' time. | 
| 85 | $page = new PermissionsCheckTestPage("testing"); | 
| 86 |  | 
| 87 | //the render method will not call the | 
| 88 | //content building methods if the permissions | 
| 89 | //fail. | 
| 90 | print $page->render(); | 
| 91 | ?> |