dispatcher.inc.php
2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
class KTDispatcher {
var $event_var = "action";
function dispatch () {
$method = 'do_main';
if (array_key_exists($this->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, $sQuery = "") {
/* $method = 'do_main';
if (method_exists($this, 'do_' . $event)) {
$method = 'do_' . $event;
}*/
$_SESSION['KTErrorMessage'][] = $error_message;
//exit(redirect($_SERVER["PHP_SELF"] . '?action=' . $event));
exit($this->redirectTo($event, $sQuery));
//return $this->$method();
}
function redirectTo($event, $sQuery = "") {
if (is_array($sQuery)) {
$sQuery['action'] = $event;
$aQueryStrings = array();
foreach ($sQuery as $k => $v) {
$aQueryStrings[] = urlencode($k) . "=" . urlencode($v);
}
$sQuery = "?" . join('&', $aQueryStrings);
} else {
if (!empty($sQuery)) {
$sQuery = '?action=' . $event . '&' . $sQuery;
} else {
$sQuery = '?action=' . $event;
}
}
exit(redirect($_SERVER["PHP_SELF"] . $sQuery));
}
function errorRedirectToMain($error_message, $sQuery = "") {
return $this->errorRedirectTo('main', $error_message, $sQuery);
}
function redirectToMain($sQuery = "") {
return $this->redirectTo('main', $sQuery);
}
function handleOutput($sOutput) {
print $sOutput;
}
}
class KTStandardDispatcher extends KTDispatcher {
function permissionDenied () {
print "Permission denied";
}
function dispatch () {
if (!checkSession()) {
exit($this->permissionDenied());
}
return parent::dispatch();
}
}
class KTAdminDispatcher extends KTStandardDispatcher {
}
?>