Commit 48533f15293e3184586d77e51a350c01b87a84e8

Authored by Conrad Vermeulen
1 parent ea6d6b5c

KTS-673

"The search algorithm needs some work"
Updated.

Committed By: Conrad Vermeulen
Reviewed By: Kevin Fourie

git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@7190 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/templating/kt3template.inc.php
... ... @@ -6,7 +6,7 @@
6 6 * License Version 1.1.2 ("License"); You may not use this file except in
7 7 * compliance with the License. You may obtain a copy of the License at
8 8 * http://www.knowledgetree.com/KPL
9   - *
  9 + *
10 10 * Software distributed under the License is distributed on an "AS IS"
11 11 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
12 12 * See the License for the specific language governing rights and
... ... @@ -17,9 +17,9 @@
17 17 * (ii) the KnowledgeTree copyright notice
18 18 * in the same form as they appear in the distribution. See the License for
19 19 * requirements.
20   - *
  20 + *
21 21 * The Original Code is: KnowledgeTree Open Source
22   - *
  22 + *
23 23 * The Initial Developer of the Original Code is The Jam Warehouse Software
24 24 * (Pty) Ltd, trading as KnowledgeTree.
25 25 * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright
... ... @@ -33,15 +33,16 @@
33 33 * KT3 Template Base
34 34 *
35 35 * Represents core UI logic, including how sub-components interact with
36   - * the overall page.
  36 + * the overall page.
37 37 *
38 38 * For the meaning of each of the variables and functions, see inline.
39 39 *
40 40 */
41   -
  41 +
42 42 require_once(KT_LIB_DIR . "/plugins/pluginregistry.inc.php");
43 43 require_once(KT_LIB_DIR . "/templating/templating.inc.php");
44 44 require_once(KT_LIB_DIR . "/session/control.inc");
  45 +require_once(KT_DIR . '/search2/search/search.inc.php');
45 46  
46 47 class KTPage {
47 48 var $hide_section = false;
... ... @@ -55,13 +56,13 @@ class KTPage {
55 56 var $theme_ie_only_css = Array();
56 57 var $js_standalone = Array();
57 58 var $css_standalone = Array();
58   -
  59 +
59 60 /** context-relevant information */
60 61 var $errStack = Array();
61 62 var $infoStack = Array();
62 63 var $portlets = Array();
63 64 var $show_portlets = true;
64   -
  65 +
65 66 /** miscellaneous items */
66 67 var $title = '';
67 68 var $systemName = APP_NAME;
... ... @@ -72,11 +73,11 @@ class KTPage {
72 73 var $menu = null;
73 74 var $userMenu = null;
74 75 var $helpPage = null;
75   -
  76 +
76 77 /** the "component". Used to set the page header (see documentation for explanation). */
77 78 var $componentLabel = 'Browse Documents';
78 79 var $componentClass = 'browse_collections';
79   -
  80 +
80 81 /** $contents is the center of the page. In KT < 3, this was CentralPayload. */
81 82 var $contents = '';
82 83  
... ... @@ -84,14 +85,14 @@ class KTPage {
84 85  
85 86 var $contentType = 'text/html';
86 87 var $charset = 'UTF-8';
87   -
  88 +
88 89 var $content_class;
89   -
  90 +
90 91 /* further initialisation */
91 92 function KTPage() {
92   - global $default;
  93 + global $default;
93 94 $oConfig = KTConfig::getSingleton();
94   -
  95 +
95 96 /* default css files initialisation */
96 97 $aCSS = Array(
97 98 "resources/css/kt-framing.css",
... ... @@ -99,7 +100,7 @@ class KTPage {
99 100 "resources/css/kt-headings.css"
100 101 );
101 102 $this->requireCSSResources($aCSS);
102   -
  103 +
103 104 if($oConfig->get('ui/morphEnabled') == '1'){
104 105 $morphTheme = $oConfig->get('ui/morphTo');
105 106 $this->requireThemeCSSResource('skins/kts_'.$oConfig->get('ui/morphTo').'/kt-morph.css');
... ... @@ -107,13 +108,13 @@ class KTPage {
107 108 }
108 109 // IE only
109 110 $this->requireCSSResource("resources/css/kt-ie-icons.css", true);
110   -
  111 +
111 112 /* default js files initialisation */
112 113 $aJS = Array();
113 114  
114 115 $aJS[] = 'thirdpartyjs/yui/yahoo/yahoo.js';
115 116 $aJS[] = 'thirdpartyjs/yui/utilities/utilities.js';
116   - /*
  117 + /*
117 118 $aJS[] = 'thirdpartyjs/MochiKit/MochiKit.js';
118 119 $aJS[] = 'thirdpartyjs/MochiKit/New.js';
119 120 $aJS[] = 'thirdpartyjs/MochiKit/DragAndDrop.js';
... ... @@ -127,31 +128,32 @@ class KTPage {
127 128 $aJS[] = 'thirdpartyjs/curvycorners/rounded_corners.inc.js';
128 129 $aJS[] = 'resources/js/loader.js';
129 130 $aJS[] = 'thirdpartyjs/yui/tools/tools.js';
130   -
  131 + $aJS[] = 'thirdpartyjs/yui/connection/connection.js';
  132 +
  133 +
131 134  
132   -
133 135 //$aJS[] = 'thirdpartyjs/MochiKit/Iter.js';
134 136 //$aJS[] = 'thirdpartyjs/MochiKit/DOM.js';
135 137 //$aJS[] = 'thirdpartyjs/MochiKit/Logging.js';
136 138 //$aJS[] = 'thirdpartyjs/MochiKit/Async.js';
137   - //$aJS[] = 'thirdpartyjs/MochiKit/Signal.js';
  139 + //$aJS[] = 'thirdpartyjs/MochiKit/Signal.js';
138 140 //$aJS[] = 'thirdpartyjs/MochiKit/.js';
139 141 //$aJS[] = 'resources/js/translate.js';
140 142  
141 143 $this->requireJSResources($aJS);
142   -
  144 +
143 145 // this is horrid, but necessary.
144 146 $this->requireJSStandalone('addLoadEvent(partial(initDeleteProtection, "' . _kt('Are you sure you wish to delete this item?') . '"));');
145   -
  147 +
146 148 /* menu initialisation*/
147 149 // FIXME: how do we want to handle the menu?
148 150 $this->initMenu();
149   -
  151 +
150 152 /* portlet initialisation */
151 153 $this->show_portlets = true;
152 154 /* breadcrumbs */
153 155 }
154   -
  156 +
155 157 // initiliase the menu.
156 158 function initMenu() {
157 159 // FIXME: we lost the getDefaultAction stuff - do we care?
... ... @@ -160,25 +162,25 @@ class KTPage {
160 162 "browse" => $this->_actionHelper(array("name" => _kt("Browse Documents"), "action" => "browse", "active" => 0)),
161 163 "administration" => $this->_actionHelper(array("name" => _kt("DMS Administration"), "action" => "administration", "active" => 0)),);
162 164 }
163   -
164   -
165   - function setTitle($sTitle) {
166   - $this->title = $sTitle;
  165 +
  166 +
  167 + function setTitle($sTitle) {
  168 + $this->title = $sTitle;
167 169 }
168   -
169   - /* javascript handling */
  170 +
  171 + /* javascript handling */
170 172 // require that the specified JS file is referenced.
171 173 function requireJSResource($sResourceURL) {
172   - $this->js_resources[$sResourceURL] = 1; // use the keys to prevent multiple copies.
  174 + $this->js_resources[$sResourceURL] = 1; // use the keys to prevent multiple copies.
173 175 }
174   -
  176 +
175 177 // require that the specified JS files are referenced.
176 178 function requireJSResources($aResourceURLs) {
177 179 foreach ($aResourceURLs as $sResourceURL) {
178 180 $this->js_resources[$sResourceURL] = 1;
179 181 }
180 182 }
181   -
  183 +
182 184 // list the distinct js resources.
183 185 function getJSResources() {
184 186 return array_keys($this->js_resources);
... ... @@ -191,7 +193,7 @@ class KTPage {
191 193 function getJSStandalone() {
192 194 return array_keys($this->js_standalone);
193 195 }
194   -
  196 +
195 197 /* css handling */
196 198 // require that the specified CSS file is referenced.
197 199 function requireCSSResource($sResourceURL, $ieOnly = false) {
... ... @@ -201,7 +203,7 @@ class KTPage {
201 203 $this->ie_only_css[$sResourceURL] = 1;
202 204 }
203 205 }
204   -
  206 +
205 207 // require that the specified CSS file is referenced.
206 208 function requireThemeCSSResource($sResourceURL, $ieOnly = false) {
207 209 if ($ieOnly !== true) {
... ... @@ -210,28 +212,28 @@ class KTPage {
210 212 $this->theme_ie_only_css[$sResourceURL] = 1;
211 213 }
212 214 }
213   -
  215 +
214 216 // require that the specified CSS files are referenced.
215 217 function requireCSSResources($aResourceURLs) {
216 218 foreach ($aResourceURLs as $sResourceURL) {
217 219 $this->css_resources[$sResourceURL] = 1;
218 220 }
219 221 }
220   -
  222 +
221 223 // list the distinct CSS resources.
222 224 function getCSSResources() {
223 225 return array_keys($this->css_resources);
224 226 }
225   -
  227 +
226 228 // list the distinct CSS resources.
227 229 function getThemeCSSResources() {
228 230 return array_keys($this->theme_css_resources);
229 231 }
230   -
  232 +
231 233 function getCSSResourcesForIE() {
232 234 return array_keys($this->ie_only_css);
233 235 }
234   -
  236 +
235 237 function getThemeCSSResourcesForIE() {
236 238 return array_keys($this->theme_ie_only_css);
237 239 }
... ... @@ -243,13 +245,13 @@ class KTPage {
243 245 function getCSSStandalone() {
244 246 return array_keys($this->css_standalone);
245 247 }
246   -
  248 +
247 249 function setPageContents($contents) { $this->contents = $contents; }
248 250 function setShowPortlets($bShow) { $this->show_portlets = $bShow; }
249   -
  251 +
250 252 /* set the breadcrumbs. the first item is the area name.
251 253 the rest are breadcrumbs. */
252   - function setBreadcrumbs($aBreadcrumbs) {
  254 + function setBreadcrumbs($aBreadcrumbs) {
253 255 $breadLength = count($aBreadcrumbs);
254 256 if ($breadLength != 0) {
255 257 $this->breadcrumbSection = $this->_actionhelper($aBreadcrumbs[0]);
... ... @@ -262,12 +264,12 @@ class KTPage {
262 264 $this->breadcrumbs = array_map(array(&$this, "_actionhelper"), array_slice($aBreadcrumbs, 1));
263 265 }
264 266 }
265   -
  267 +
266 268 function setBreadcrumbDetails($sBreadcrumbDetails) { $this->breadcrumbDetails = $sBreadcrumbDetails; }
267 269 function setUser($oUser) { $this->user = $oUser; }
268   -
269   - function setContentClass($sClass) { $this->content_class = $sClass; }
270   -
  270 +
  271 + function setContentClass($sClass) { $this->content_class = $sClass; }
  272 +
271 273 // FIXME refactor setSection to be generic, not an if-else.
272 274 // assume this is admin for now.
273 275 function setSection($sSection) {
... ... @@ -277,54 +279,54 @@ class KTPage {
277 279 $this->menu['administration']['active'] = 1;
278 280 } else if ($sSection == 'dashboard') {
279 281 $this->componentLabel = _kt('Dashboard');
280   - $this->componentClass = 'dashboard';
  282 + $this->componentClass = 'dashboard';
281 283 } else if ($sSection == 'browse') {
282 284 $this->componentLabel = _kt('Browse Documents');
283   - $this->componentClass = 'browse_collections';
  285 + $this->componentClass = 'browse_collections';
284 286 } else if ($sSection == 'view_details') {
285 287 $this->componentLabel = _kt('Document Details');
286   - $this->componentClass = 'document_details';
  288 + $this->componentClass = 'document_details';
287 289 } else if ($sSection == 'search') {
288 290 $this->componentLabel = _kt('Search');
289   - $this->componentClass = 'search';
  291 + $this->componentClass = 'search';
290 292 } else if ($sSection == 'preferences') {
291 293 $this->componentLabel = _kt('Preferences');
292   - $this->componentClass = 'preferences';
  294 + $this->componentClass = 'preferences';
293 295 } else {
294 296 $this->componentLabel = _kt('Dashboard');
295   - $this->componentClass = 'dashboard';
  297 + $this->componentClass = 'dashboard';
296 298 }
297 299  
298 300 }
299 301  
300 302 function addError($sError) { array_push($this->errStack, $sError); }
301 303 function addInfo($sInfo) { array_push($this->infoStack, $sInfo); }
302   -
  304 +
303 305 /** no-one cares what a portlet is, but it should be renderable, and have its ->title member set. */
304 306 function addPortlet($oPortlet) {
305 307 array_push($this->portlets, $oPortlet);
306 308 }
307   -
  309 +
308 310 /* LEGACY */
309 311 var $deprecationWarning = "Legacy UI API: ";
310 312 function setCentralPayload($sCentral) {
311 313 $this->contents = $sCentral;
312 314 $this->addError($this->deprecationWarning . "called <strong>setCentralPayload</strong>");
313 315 }
314   -
  316 +
315 317 function setOnloadJavascript($appendix) { $this->addError($this->deprecationWarning . "called <strong>setOnloadJavascript (no-act)</strong>"); }
316 318 function setDHtmlScrolling($appendix) { $this->addError($this->deprecationWarning . "called <strong>setDHTMLScrolling (no-act)</strong>"); }
317 319 function setFormAction($appendix) { $this->addError($this->deprecationWarning . "called <strong>setFormAction (no-act)</strong>"); }
318 320 function setSubmitMethod($appendix) { $this->addError($this->deprecationWarning . "called <strong>setSubmitMethod (no-act)</strong>"); }
319 321 function setHasRequiredFields($appendix) { $this->addError($this->deprecationWarning . "called <strong>setHasRequiredFields (no-act)</strong>"); }
320 322 function setAdditionalJavascript($appendix) { $this->addError($this->deprecationWarning . "called <strong>setAdditionalJavascript (no-act)</strong>"); }
321   -
  323 +
322 324 function hideSection() { $this->hide_section = true; }
323 325 function setSecondaryTitle($sSecondary) { $this->secondary_title = $sSecondary; }
324   -
  326 +
325 327 /* final render call. */
326 328 function render() {
327   - global $default;
  329 + global $default;
328 330 $oConfig = KTConfig::getSingleton();
329 331  
330 332 if (empty($this->contents)) {
... ... @@ -335,16 +337,16 @@ class KTPage {
335 337 $this->addError(_kt("This page did not produce any content"));
336 338 $this->contents = "";
337 339 }
338   -
  340 +
339 341 if (!is_string($this->contents)) {
340 342 $this->contents = $this->contents->render();
341 343 }
342   -
  344 +
343 345 // if we have no portlets, make the ui a tad nicer.
344 346 if (empty($this->portlets)) {
345 347 $this->show_portlets = false;
346 348 }
347   -
  349 +
348 350 if (empty($this->title)) {
349 351 if (!empty($this->breadcrumbDetails)) {
350 352 $this->title = $this->breadcrumbDetails;
... ... @@ -357,9 +359,9 @@ class KTPage {
357 359 $this->title = $this->componentLabel;
358 360 }
359 361 }
360   -
  362 +
361 363 $this->userMenu = array();
362   - if (!(PEAR::isError($this->user) || is_null($this->user) || $this->user->isAnonymous())) {
  364 + if (!(PEAR::isError($this->user) || is_null($this->user) || $this->user->isAnonymous())) {
363 365 if ($oConfig->get("user_prefs/restrictPreferences", false) && !Permission::userIsSystemAdministrator($this->user->getId())) {
364 366 $this->userMenu = array("logout" => $this->_actionHelper(array("name" => _kt("Logout"), "action" => "logout", "active" => 0)),);
365 367 } else {
... ... @@ -369,42 +371,46 @@ class KTPage {
369 371 }
370 372 } else {
371 373 $this->userMenu = array("login" => $this->_actionHelper(array("name" => _kt("Login"), "action" => "login")),);
372   - }
373   -
  374 + }
  375 +
374 376 // FIXME we need a more complete solution to navigation restriction
375 377 if (!is_null($this->menu['administration']) && !is_null($this->user)) {
376 378 if (!Permission::userIsSystemAdministrator($this->user->getId())) {
377 379 unset($this->menu['administration']);
378 380 }
379 381 }
380   -
  382 +
381 383 $sContentType = 'Content-type: ' . $this->contentType;
382 384 if(!empty($this->charset)) {
383 385 $sContentType .= '; charset=' . $this->charset;
384 386 };
385   -
  387 +
386 388  
387 389 header($sContentType);
388   -
389   - $oTemplating =& KTTemplating::getSingleton();
  390 +
  391 + $savedSearches = SearchHelper::getSavedSearches($_SESSION['userID']);
  392 +
  393 + $oTemplating =& KTTemplating::getSingleton();
390 394 $oTemplate = $oTemplating->loadTemplate($this->template);
391   - $aTemplateData = array("page" => $this,
392   - "systemversion" => $default->systemVersion,
393   - "versionname" => $default->versionName,);
  395 + $aTemplateData = array(
  396 + "page" => $this,
  397 + "systemversion" => $default->systemVersion,
  398 + "versionname" => $default->versionName,
  399 + 'savedSearches'=> $savedSearches);
394 400 if ($oConfig->get("ui/automaticRefresh", false)) {
395 401 $aTemplateData['refreshTimeout'] = (int)$oConfig->get("session/sessionTimeout") + 3;
396 402 }
397   -
  403 +
398 404 // unlike the rest of KT, we use echo here.
399 405 echo $oTemplate->render($aTemplateData);
400 406 }
401   -
  407 +
402 408  
403 409 /** heler functions */
404 410 // returns an array ("url", "label")
405 411 function _actionhelper($aActionTuple) {
406 412 $aTuple = Array("label" => $aActionTuple["name"]);
407   - if ($aActionTuple["action"]) {
  413 + if ($aActionTuple["action"]) {
408 414 $aTuple["url"] = generateControllerLink($aActionTuple["action"], $aActionTuple["query"]);
409 415 } else if ($aActionTuple["url"]) {
410 416 $sUrl = $aActionTuple["url"];
... ... @@ -418,22 +424,22 @@ class KTPage {
418 424 } else {
419 425 $aTuple["url"] = false;
420 426 }
421   -
  427 +
422 428 return $aTuple;
423 429 }
424   -
  430 +
425 431 function setHelp($sHelpPage) {
426 432 $this->helpPage = $sHelpPage;
427 433 }
428   -
  434 +
429 435 function getHelpURL() {
430   - if (empty($this->helpPage)) {
  436 + if (empty($this->helpPage)) {
431 437 return null;
432 438 }
433   -
434   - return KTUtil::ktLink('help.php',$this->helpPage);
  439 +
  440 + return KTUtil::ktLink('help.php',$this->helpPage);
435 441 }
436   -
  442 +
437 443 function getReqTime() {
438 444 $microtime_simple = explode(' ', microtime());
439 445 $finaltime = (float) $microtime_simple[1] + (float) $microtime_simple[0];
... ... @@ -449,7 +455,7 @@ class KTPage {
449 455 return;
450 456 }
451 457 }
452   -
  458 +
453 459 }
454 460  
455 461 ?>
... ...