help.php
7.17 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<?php
/**
* $Id$
*
* The contents of this file are subject to the KnowledgeTree Public
* License Version 1.1 ("License"); You may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.knowledgetree.com/KPL
*
* Software distributed under the License is distributed on an "AS IS"
* basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is: KnowledgeTree Open Source
*
* The Initial Developer of the Original Code is The Jam Warehouse Software
* (Pty) Ltd, trading as KnowledgeTree.
* Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright
* (C) 2007 The Jam Warehouse Software (Pty) Ltd;
* All Rights Reserved.
*
*/
// main library routines and defaults
require_once("config/dmsDefaults.php");
require_once(KT_LIB_DIR . "/templating/templating.inc.php");
require_once(KT_LIB_DIR . "/templating/kt3template.inc.php");
require_once(KT_LIB_DIR . "/dispatcher.inc.php");
require_once(KT_LIB_DIR . "/util/ktutil.inc");
require_once(KT_LIB_DIR . "/security/Permission.inc");
require_once(KT_LIB_DIR . "/help/helpreplacement.inc.php");
require_once(KT_LIB_DIR . "/help/help.inc.php");
/*
* KT3 Help functionality.
*
* The KT3 help works slightly differently to the previous versions of KT.
* This page takes subpath-info, and uses that to resolve the help documentation
* as appropriate.
*
* This documentation should be placed into KT_DIR/kthelp/COMPONENT_NAME/LANG/...
* Currently images and html files are the ONLY supported types.
*
* Within these directories, local addressing is _relative_ as expected.
*
* File names _should not be changed_ from their reference values when translating,
* since files are referred to WITHOUT the lang-code (e.g. EN, IT).
*/
class HelpDispatcher extends KTStandardDispatcher {
var $sSection = "dashboard";
var $bIsReplacement = false;
function HelpDispatcher() {
$this->aBreadcrumbs[] = array('action' => 'dashboard', 'name' => _kt('Dashboard'));
$this->aBreadcrumbs[] = array('name' => _kt('Help'));
parent::KTStandardDispatcher();
}
function is_replacement() { return $this->bIsReplacement; }
function do_main() {
// store referer
$sBackKey = KTUtil::arrayGet($_REQUEST, 'back_key', false);
$sSubPath = KTUtil::arrayGet($_SERVER, 'PATH_INFO');
// we want to be able to say "i left the system at point x. go back there"
if(!$sBackKey) {
$sReferer = KTUtil::arrayGet($_SERVER ,'HTTP_REFERER');
$sBackKey = KTUtil::randomString();
$_SESSION[$sBackKey] = $sReferer;
}
// no path specified
if (empty($sSubPath)) {
$this->oPage->setTitle(_kt('No help page specified.'));
$this->oPage->addError(_kt('No help page specified.'));
return ' ';
}
// simple test to see if this user is active.
$bCanEdit = Permission::userIsSystemAdministrator($_SESSION['userID']);
global $default;
$sLangCode = $default->defaultLanguage;
/*
now we need to know a few things.
1. can we find this help file?
2. if we can, display it
2.1 images directly
2.2 html wrapped.
3. if now, fail out.
this is essentially handled by asking help.inc.php for the
subpath we've been given, PLUS THE LANGUAGE, and checking for
a PEAR::raiseError.
The "Correct" response we care about is a dictionary:
{
'is_image': string
'title': string
'body': string
}
*/
$aHelpData = KTHelp::getHelpInfo($sSubPath);
if (PEAR::isError($aHelpData)) {
$this->oPage->setTitle($aHelpData->getMessage());
$this->oPage->addError($aHelpData->getMessage());
return ' ';
}
$aLocInfo = KTHelp::_getLocationInfo($sSubPath);
if ($aHelpData['is_image']) {
KTHelp::outputHelpImage($sSubPath);
exit(0); // done.
} else {
$this->oPage->setTitle($aHelpData['title']);
$this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => $aHelpData['title']);
$oTemplating =& KTTemplating::getSingleton();
$oTemplate = $oTemplating->loadTemplate("ktcore/help_with_edit");
$aTemplateData = array(
"context" => $this,
"help_body" => $aHelpData['body'],
"help_title" => $aHelpData['title'],
"target_name" => KTUtil::arrayGet($aLocInfo, 'subpath'),
"back_key" => $sBackKey,
'can_edit' => $bCanEdit,
);
return $oTemplate->render($aTemplateData);
}
/*
$help_path = KTHelp::getHelpSubPath($pathinfo);
if ($help_path == false) {
$this->oPage->setTitle(_kt('Invalid help location specified.'));
$this->oPage->addError(_kt('Invalid help location specified.'));
return ' ';
}
// We now check for substitute help files. try to generate an error.
$oReplacementHelp = KTHelpReplacement::getByName($help_path);
if (KTHelp::isImageFile($help_path)) {
KTHelp::outputHelpImage($help_path);
} else {
// not an image, so:
$aHelpInfo = KTHelp::getHelpFromFile($pathinfo)
}
// NORMAL users never see edit-option.
if (!$can_edit) {
if (!PEAR::isError($oReplacementHelp)) {
$this->oPage->setTitle($oReplacementHelp->getTitle());
//return $oReplacementHelp->getDescription();
} elseif ($aHelpInfo != false) {
$this->oPage->setTitle($aHelpInfo['title']);
//return $aHelpInfo['body'];
} else {
$this->oPage->setTitle(_kt('Invalid help location specified.'));
$this->oPage->addError(_kt('Invalid help location specified.'));
return ' ';
}
}
if (!PEAR::isError($oReplacementHelp)) {
$aHelpInfo['title'] = $oReplacementHelp->getTitle();
$aHelpInfo['body'] = $oReplacementHelp->getDescription();
}
// we now _can_ edit.
$this->oPage->setTitle($aHelpInfo['title']);
$this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => $aHelpInfo['title']);
*/
}
function do_go_back() {
// get referer
$sBackKey = KTUtil::arrayGet($_REQUEST, 'back_key', false);
if($sBackKey) {
$sReferer = $_SESSION[$sBackKey];
redirect($sReferer);
exit(0);
} else {
$this->errorRedirectToMain(_kt("Invalid return key from help system."));
}
}
}
$oDispatcher = new HelpDispatcher();
$oDispatcher->dispatch();
?>