dispatcher.inc.php
3.19 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?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 {
var $bLogonRequired = true;
var $bAdminRequired = false;
function permissionDenied () {
print "Permission denied";
}
function dispatch () {
$session = new Session();
$sessionStatus = $session->verify($bDownload);
if ($bLogonRequired !== false) {
if (empty($_SESSION['userID'])) {
$this->permissionDenied();
exit(0);
}
$this->oUser =& User::get($_SESSION['userID']);
if (PEAR::isError($this->oUser) || ($this->oUser === false)) {
$this->permissionDenied();
exit(0);
}
}
if ($bAdminRequired !== false) {
if (!Permission::userIsSystemAdministrator($_SESSION['userID'])) {
$this->permissionDenied();
exit(0);
}
}
if ($this->check() !== true) {
$this->permissionDenied();
exit(0);
}
return parent::dispatch();
}
function check() {
return true;
}
function handleOutput($data) {
global $main;
$main->bFormDisabled = true;
$main->setCentralPayload($data);
$main->render();
}
function errorPage($errorMessage) {
$this->handleOutput($errorMessage);
exit(0);
}
}
class KTAdminDispatcher extends KTStandardDispatcher {
var $bAdminRequired = true;
}
?>