From 2ada71aab05805649f97f63ef8d48394e5283a5b Mon Sep 17 00:00:00 2001 From: Neil Blakey-Milner Date: Wed, 27 Jul 2005 09:31:21 +0000 Subject: [PATCH] Add a simple dispatcher mechanism for developing pages. --- lib/dispatcher.inc.php | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+), 0 deletions(-) create mode 100644 lib/dispatcher.inc.php diff --git a/lib/dispatcher.inc.php b/lib/dispatcher.inc.php new file mode 100644 index 0000000..9b7d53d --- /dev/null +++ b/lib/dispatcher.inc.php @@ -0,0 +1,55 @@ +event_var, $_REQUEST)) { + $event = $_REQUEST[$this->event_var]; + if (method_exists($this, 'do_' . $event)) { + $method = 'do_' . $event; + } + } + + $ret = $this->$method(); + $this->handleOutput($ret); + } + + function errorRedirectTo($event, $error_message) { + /* $method = 'do_main'; + if (method_exists($this, 'do_' . $event)) { + $method = 'do_' . $event; + }*/ + $_SESSION['KTErrorMessage'][] = $error_message; + exit(redirect($_SERVER["PHP_SELF"] . '?action=' . $event)); + //return $this->$method(); + } + + function redirectTo($event, $sQuery) { + exit(redirect($_SERVER["PHP_SELF"] . '?action=' . $event . "&" . $sQuery)); + } + + function errorRedirectToMain($error_message) { + return $this->errorRedirectTo('main', $error_message); + } + + function handleOutput($sOutput) { + print $sOutput; + } +} + +class KTAdminDispatcher extends KTDispatcher { + function permissionDenied () { + print "Permission denied"; + } + + function dispatch () { + if (!checkSession()) { + exit($this->permissionDenied()); + } + return parent::dispatch(); + } +} + +?> -- libgit2 0.21.4