Commit 2ada71aab05805649f97f63ef8d48394e5283a5b
1 parent
0d33f8e0
Add a simple dispatcher mechanism for developing pages.
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3474 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
55 additions
and
0 deletions
lib/dispatcher.inc.php
0 → 100644
| 1 | +<?php | |
| 2 | + | |
| 3 | +class KTDispatcher { | |
| 4 | + var $event_var = "action"; | |
| 5 | + | |
| 6 | + function dispatch () { | |
| 7 | + $method = 'do_main'; | |
| 8 | + if (array_key_exists($this->event_var, $_REQUEST)) { | |
| 9 | + $event = $_REQUEST[$this->event_var]; | |
| 10 | + if (method_exists($this, 'do_' . $event)) { | |
| 11 | + $method = 'do_' . $event; | |
| 12 | + } | |
| 13 | + } | |
| 14 | + | |
| 15 | + $ret = $this->$method(); | |
| 16 | + $this->handleOutput($ret); | |
| 17 | + } | |
| 18 | + | |
| 19 | + function errorRedirectTo($event, $error_message) { | |
| 20 | + /* $method = 'do_main'; | |
| 21 | + if (method_exists($this, 'do_' . $event)) { | |
| 22 | + $method = 'do_' . $event; | |
| 23 | + }*/ | |
| 24 | + $_SESSION['KTErrorMessage'][] = $error_message; | |
| 25 | + exit(redirect($_SERVER["PHP_SELF"] . '?action=' . $event)); | |
| 26 | + //return $this->$method(); | |
| 27 | + } | |
| 28 | + | |
| 29 | + function redirectTo($event, $sQuery) { | |
| 30 | + exit(redirect($_SERVER["PHP_SELF"] . '?action=' . $event . "&" . $sQuery)); | |
| 31 | + } | |
| 32 | + | |
| 33 | + function errorRedirectToMain($error_message) { | |
| 34 | + return $this->errorRedirectTo('main', $error_message); | |
| 35 | + } | |
| 36 | + | |
| 37 | + function handleOutput($sOutput) { | |
| 38 | + print $sOutput; | |
| 39 | + } | |
| 40 | +} | |
| 41 | + | |
| 42 | +class KTAdminDispatcher extends KTDispatcher { | |
| 43 | + function permissionDenied () { | |
| 44 | + print "Permission denied"; | |
| 45 | + } | |
| 46 | + | |
| 47 | + function dispatch () { | |
| 48 | + if (!checkSession()) { | |
| 49 | + exit($this->permissionDenied()); | |
| 50 | + } | |
| 51 | + return parent::dispatch(); | |
| 52 | + } | |
| 53 | +} | |
| 54 | + | |
| 55 | +?> | ... | ... |