Commit 62f89fdc6eb1c437c018f3414ea5e4845026eb08
1 parent
97930996
KTS-2358
"php5 migration" Updated. Removed & from &new. Committed By: Conrad Vermeulen Reviewed By: Kevin Fourie git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@7198 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
49 additions
and
49 deletions
lib/dispatcher.inc.php
| @@ -6,7 +6,7 @@ | @@ -6,7 +6,7 @@ | ||
| 6 | * License Version 1.1.2 ("License"); You may not use this file except in | 6 | * License Version 1.1.2 ("License"); You may not use this file except in |
| 7 | * compliance with the License. You may obtain a copy of the License at | 7 | * compliance with the License. You may obtain a copy of the License at |
| 8 | * http://www.knowledgetree.com/KPL | 8 | * http://www.knowledgetree.com/KPL |
| 9 | - * | 9 | + * |
| 10 | * Software distributed under the License is distributed on an "AS IS" | 10 | * Software distributed under the License is distributed on an "AS IS" |
| 11 | * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. | 11 | * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing rights and | 12 | * See the License for the specific language governing rights and |
| @@ -17,9 +17,9 @@ | @@ -17,9 +17,9 @@ | ||
| 17 | * (ii) the KnowledgeTree copyright notice | 17 | * (ii) the KnowledgeTree copyright notice |
| 18 | * in the same form as they appear in the distribution. See the License for | 18 | * in the same form as they appear in the distribution. See the License for |
| 19 | * requirements. | 19 | * requirements. |
| 20 | - * | 20 | + * |
| 21 | * The Original Code is: KnowledgeTree Open Source | 21 | * The Original Code is: KnowledgeTree Open Source |
| 22 | - * | 22 | + * |
| 23 | * The Initial Developer of the Original Code is The Jam Warehouse Software | 23 | * The Initial Developer of the Original Code is The Jam Warehouse Software |
| 24 | * (Pty) Ltd, trading as KnowledgeTree. | 24 | * (Pty) Ltd, trading as KnowledgeTree. |
| 25 | * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright | 25 | * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright |
| @@ -53,12 +53,12 @@ class KTDispatcher { | @@ -53,12 +53,12 @@ class KTDispatcher { | ||
| 53 | var $bTransactionStarted = false; | 53 | var $bTransactionStarted = false; |
| 54 | var $oValidator = null; | 54 | var $oValidator = null; |
| 55 | var $sParentUrl = null; // it is handy for subdispatched items to have an "exit" url, for cancels, etc. | 55 | var $sParentUrl = null; // it is handy for subdispatched items to have an "exit" url, for cancels, etc. |
| 56 | - | 56 | + |
| 57 | var $aPersistParams = array(); | 57 | var $aPersistParams = array(); |
| 58 | 58 | ||
| 59 | function KTDispatcher() { | 59 | function KTDispatcher() { |
| 60 | - $this->oValidator =& new KTDispatcherValidation($this); | ||
| 61 | - $this->oRedirector =& new KTDispatchStandardRedirector($this); | 60 | + $this->oValidator =new KTDispatcherValidation($this); |
| 61 | + $this->oRedirector =new KTDispatchStandardRedirector($this); | ||
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | function redispatch($event_var, $action_prefix = null, $orig_dispatcher = null, $parent_url = null) { | 64 | function redispatch($event_var, $action_prefix = null, $orig_dispatcher = null, $parent_url = null) { |
| @@ -68,11 +68,11 @@ class KTDispatcher { | @@ -68,11 +68,11 @@ class KTDispatcher { | ||
| 68 | if ($action_prefix) { | 68 | if ($action_prefix) { |
| 69 | $this->action_prefix = $action_prefix; | 69 | $this->action_prefix = $action_prefix; |
| 70 | } | 70 | } |
| 71 | - | 71 | + |
| 72 | if (!is_null($orig_dispatcher)) { | 72 | if (!is_null($orig_dispatcher)) { |
| 73 | $this->persistParams($orig_dispatcher->aPersistParams); | 73 | $this->persistParams($orig_dispatcher->aPersistParams); |
| 74 | - $this->persistParams(array($orig_dispatcher->event_var)); | ||
| 75 | - $core = array('aBreadcrumbs', | 74 | + $this->persistParams(array($orig_dispatcher->event_var)); |
| 75 | + $core = array('aBreadcrumbs', | ||
| 76 | 'bTransactionStarted', | 76 | 'bTransactionStarted', |
| 77 | 'oUser', | 77 | 'oUser', |
| 78 | 'session', | 78 | 'session', |
| @@ -82,10 +82,10 @@ class KTDispatcher { | @@ -82,10 +82,10 @@ class KTDispatcher { | ||
| 82 | if(isset($orig_dispatcher->$k)) { | 82 | if(isset($orig_dispatcher->$k)) { |
| 83 | $this->$k = $orig_dispatcher->$k; | 83 | $this->$k = $orig_dispatcher->$k; |
| 84 | } | 84 | } |
| 85 | - } | 85 | + } |
| 86 | } | 86 | } |
| 87 | - $this->event_var = $event_var; | ||
| 88 | - | 87 | + $this->event_var = $event_var; |
| 88 | + | ||
| 89 | return $this->dispatch(); | 89 | return $this->dispatch(); |
| 90 | } | 90 | } |
| 91 | 91 | ||
| @@ -126,14 +126,14 @@ class KTDispatcher { | @@ -126,14 +126,14 @@ class KTDispatcher { | ||
| 126 | 126 | ||
| 127 | $ret = $this->$method(); | 127 | $ret = $this->$method(); |
| 128 | $this->handleOutput($ret); | 128 | $this->handleOutput($ret); |
| 129 | - | 129 | + |
| 130 | if ($this->bTransactionStarted) { | 130 | if ($this->bTransactionStarted) { |
| 131 | $this->commitTransaction(); | 131 | $this->commitTransaction(); |
| 132 | } | 132 | } |
| 133 | } | 133 | } |
| 134 | 134 | ||
| 135 | function subDispatch(&$oOrigDispatcher) { | 135 | function subDispatch(&$oOrigDispatcher) { |
| 136 | - $core = array('aBreadcrumbs', | 136 | + $core = array('aBreadcrumbs', |
| 137 | 'bTransactionStarted', | 137 | 'bTransactionStarted', |
| 138 | 'oUser', | 138 | 'oUser', |
| 139 | 'session', | 139 | 'session', |
| @@ -185,14 +185,14 @@ class KTDispatcher { | @@ -185,14 +185,14 @@ class KTDispatcher { | ||
| 185 | } | 185 | } |
| 186 | $this->redirectTo($event, $sQuery); | 186 | $this->redirectTo($event, $sQuery); |
| 187 | } | 187 | } |
| 188 | - | 188 | + |
| 189 | function errorRedirectToParent($error_message) { | 189 | function errorRedirectToParent($error_message) { |
| 190 | if ($this->bTransactionStarted) { | 190 | if ($this->bTransactionStarted) { |
| 191 | $this->rollbackTransaction(); | 191 | $this->rollbackTransaction(); |
| 192 | } | 192 | } |
| 193 | 193 | ||
| 194 | $_SESSION['KTErrorMessage'][] = $error_message; | 194 | $_SESSION['KTErrorMessage'][] = $error_message; |
| 195 | - redirect($this->sParentUrl); | 195 | + redirect($this->sParentUrl); |
| 196 | exit(0); | 196 | exit(0); |
| 197 | } | 197 | } |
| 198 | 198 | ||
| @@ -203,14 +203,14 @@ class KTDispatcher { | @@ -203,14 +203,14 @@ class KTDispatcher { | ||
| 203 | if (!empty($info_message)) { | 203 | if (!empty($info_message)) { |
| 204 | $_SESSION['KTInfoMessage'][] = $info_message; | 204 | $_SESSION['KTInfoMessage'][] = $info_message; |
| 205 | } | 205 | } |
| 206 | - redirect($this->sParentUrl); | 206 | + redirect($this->sParentUrl); |
| 207 | exit(0); | 207 | exit(0); |
| 208 | - } | 208 | + } |
| 209 | 209 | ||
| 210 | function redirectTo($event, $sQuery = "") { | 210 | function redirectTo($event, $sQuery = "") { |
| 211 | // meld persistant options | 211 | // meld persistant options |
| 212 | $sQuery = $this->meldPersistQuery($sQuery, $event); | 212 | $sQuery = $this->meldPersistQuery($sQuery, $event); |
| 213 | - | 213 | + |
| 214 | $sRedirect = KTUtil::addQueryString($_SERVER['PHP_SELF'], $sQuery); | 214 | $sRedirect = KTUtil::addQueryString($_SERVER['PHP_SELF'], $sQuery); |
| 215 | $this->oRedirector->redirect($sRedirect); | 215 | $this->oRedirector->redirect($sRedirect); |
| 216 | exit(0); | 216 | exit(0); |
| @@ -231,14 +231,14 @@ class KTDispatcher { | @@ -231,14 +231,14 @@ class KTDispatcher { | ||
| 231 | function handleOutput($sOutput) { | 231 | function handleOutput($sOutput) { |
| 232 | print $sOutput; | 232 | print $sOutput; |
| 233 | } | 233 | } |
| 234 | - | 234 | + |
| 235 | /* persist the following parameters between requests (via redirect), unless a value is passed in. */ | 235 | /* persist the following parameters between requests (via redirect), unless a value is passed in. */ |
| 236 | function persistParams($aParamKeys) { | 236 | function persistParams($aParamKeys) { |
| 237 | $this->aPersistParams = kt_array_merge($this->aPersistParams, $aParamKeys); | 237 | $this->aPersistParams = kt_array_merge($this->aPersistParams, $aParamKeys); |
| 238 | } | 238 | } |
| 239 | - | ||
| 240 | - function meldPersistQuery($sQuery = "", $event = "", $asArray = false) { | ||
| 241 | - | 239 | + |
| 240 | + function meldPersistQuery($sQuery = "", $event = "", $asArray = false) { | ||
| 241 | + | ||
| 242 | if (is_array($sQuery)) { | 242 | if (is_array($sQuery)) { |
| 243 | $aQuery = $sQuery; | 243 | $aQuery = $sQuery; |
| 244 | } else { | 244 | } else { |
| @@ -248,11 +248,11 @@ class KTDispatcher { | @@ -248,11 +248,11 @@ class KTDispatcher { | ||
| 248 | } else { | 248 | } else { |
| 249 | $aQuery = array(); | 249 | $aQuery = array(); |
| 250 | } | 250 | } |
| 251 | - } | 251 | + } |
| 252 | // now try to grab each persisted entry | 252 | // now try to grab each persisted entry |
| 253 | - // don't overwrite the existing values, if added. | 253 | + // don't overwrite the existing values, if added. |
| 254 | 254 | ||
| 255 | - if (is_array($this->aPersistParams)) { | 255 | + if (is_array($this->aPersistParams)) { |
| 256 | foreach ($this->aPersistParams as $k) { | 256 | foreach ($this->aPersistParams as $k) { |
| 257 | if (!array_key_exists($k, $aQuery)) { | 257 | if (!array_key_exists($k, $aQuery)) { |
| 258 | $v = KTUtil::arrayGet($_REQUEST, $k); | 258 | $v = KTUtil::arrayGet($_REQUEST, $k); |
| @@ -260,10 +260,10 @@ class KTDispatcher { | @@ -260,10 +260,10 @@ class KTDispatcher { | ||
| 260 | $aQuery[$k] = $v; | 260 | $aQuery[$k] = $v; |
| 261 | } | 261 | } |
| 262 | } | 262 | } |
| 263 | - // handle the case where action is passed in already. | ||
| 264 | - } | 263 | + // handle the case where action is passed in already. |
| 264 | + } | ||
| 265 | } | 265 | } |
| 266 | - // if it isn't already set | 266 | + // if it isn't already set |
| 267 | if ((!array_key_exists($this->event_var, $aQuery)) && (!empty($event))) { | 267 | if ((!array_key_exists($this->event_var, $aQuery)) && (!empty($event))) { |
| 268 | $aQuery[$this->event_var] = urlencode($event); | 268 | $aQuery[$this->event_var] = urlencode($event); |
| 269 | } | 269 | } |
| @@ -291,26 +291,26 @@ class KTStandardDispatcher extends KTDispatcher { | @@ -291,26 +291,26 @@ class KTStandardDispatcher extends KTDispatcher { | ||
| 291 | var $oPage = false; | 291 | var $oPage = false; |
| 292 | var $sHelpPage = null; | 292 | var $sHelpPage = null; |
| 293 | var $bJSONMode = false; | 293 | var $bJSONMode = false; |
| 294 | - | 294 | + |
| 295 | function KTStandardDispatcher() { | 295 | function KTStandardDispatcher() { |
| 296 | if (empty($GLOBALS['main'])) { | 296 | if (empty($GLOBALS['main'])) { |
| 297 | - $GLOBALS['main'] =& new KTPage; | 297 | + $GLOBALS['main'] =new KTPage; |
| 298 | } | 298 | } |
| 299 | $this->oPage =& $GLOBALS['main']; | 299 | $this->oPage =& $GLOBALS['main']; |
| 300 | parent::KTDispatcher(); | 300 | parent::KTDispatcher(); |
| 301 | } | 301 | } |
| 302 | 302 | ||
| 303 | function permissionDenied () { | 303 | function permissionDenied () { |
| 304 | - // handle anonymous specially. | 304 | + // handle anonymous specially. |
| 305 | if ($this->oUser->getId() == -2) { | 305 | if ($this->oUser->getId() == -2) { |
| 306 | redirect(KTUtil::ktLink('login.php','',sprintf("redirect=%s&errorMessage=%s", urlencode($_SERVER['REQUEST_URI']), urlencode(_kt("You must be logged in to perform this action"))))); exit(0); | 306 | redirect(KTUtil::ktLink('login.php','',sprintf("redirect=%s&errorMessage=%s", urlencode($_SERVER['REQUEST_URI']), urlencode(_kt("You must be logged in to perform this action"))))); exit(0); |
| 307 | - } | ||
| 308 | - | 307 | + } |
| 308 | + | ||
| 309 | global $default; | 309 | global $default; |
| 310 | - | 310 | + |
| 311 | $msg = '<h2>' . _kt('Permission Denied') . '</h2>'; | 311 | $msg = '<h2>' . _kt('Permission Denied') . '</h2>'; |
| 312 | $msg .= '<p>' . _kt('If you feel that this is incorrect, please report both the action and your username to a system administrator.') . '</p>'; | 312 | $msg .= '<p>' . _kt('If you feel that this is incorrect, please report both the action and your username to a system administrator.') . '</p>'; |
| 313 | - | 313 | + |
| 314 | $this->oPage->setPageContents($msg); | 314 | $this->oPage->setPageContents($msg); |
| 315 | $this->oPage->setUser($this->oUser); | 315 | $this->oPage->setUser($this->oUser); |
| 316 | $this->oPage->hideSection(); | 316 | $this->oPage->hideSection(); |
| @@ -324,11 +324,11 @@ class KTStandardDispatcher extends KTDispatcher { | @@ -324,11 +324,11 @@ class KTStandardDispatcher extends KTDispatcher { | ||
| 324 | if ($oKTConfig->get('allowAnonymousLogin', false)) { | 324 | if ($oKTConfig->get('allowAnonymousLogin', false)) { |
| 325 | // anonymous logins are now allowed. | 325 | // anonymous logins are now allowed. |
| 326 | // the anonymous user is -1. | 326 | // the anonymous user is -1. |
| 327 | - // | 327 | + // |
| 328 | // we short-circuit the login mechanisms, setup the session, and go. | 328 | // we short-circuit the login mechanisms, setup the session, and go. |
| 329 | - | 329 | + |
| 330 | $oUser =& User::get(-2); | 330 | $oUser =& User::get(-2); |
| 331 | - if (PEAR::isError($oUser) || ($oUser->getName() != 'Anonymous')) { | 331 | + if (PEAR::isError($oUser) || ($oUser->getName() != 'Anonymous')) { |
| 332 | ; // do nothing - the database integrity would break if we log the user in now. | 332 | ; // do nothing - the database integrity would break if we log the user in now. |
| 333 | } else { | 333 | } else { |
| 334 | $session = new Session(); | 334 | $session = new Session(); |
| @@ -339,7 +339,7 @@ class KTStandardDispatcher extends KTDispatcher { | @@ -339,7 +339,7 @@ class KTStandardDispatcher extends KTDispatcher { | ||
| 339 | } | 339 | } |
| 340 | } | 340 | } |
| 341 | } | 341 | } |
| 342 | - | 342 | + |
| 343 | $sErrorMessage = ""; | 343 | $sErrorMessage = ""; |
| 344 | if (PEAR::isError($this->sessionStatus)) { | 344 | if (PEAR::isError($this->sessionStatus)) { |
| 345 | $sErrorMessage = $this->sessionStatus->getMessage(); | 345 | $sErrorMessage = $this->sessionStatus->getMessage(); |
| @@ -348,8 +348,8 @@ class KTStandardDispatcher extends KTDispatcher { | @@ -348,8 +348,8 @@ class KTStandardDispatcher extends KTDispatcher { | ||
| 348 | // check if we're in JSON mode - in which case, throw error | 348 | // check if we're in JSON mode - in which case, throw error |
| 349 | // but JSON mode only gets set later, so gonna have to check action | 349 | // but JSON mode only gets set later, so gonna have to check action |
| 350 | if(KTUtil::arrayGet($_REQUEST, 'action', '') == 'json') { //$this->bJSONMode) { | 350 | if(KTUtil::arrayGet($_REQUEST, 'action', '') == 'json') { //$this->bJSONMode) { |
| 351 | - $this->handleOutputJSON(array('error'=>true, | ||
| 352 | - 'type'=>'kt.not_logged_in', | 351 | + $this->handleOutputJSON(array('error'=>true, |
| 352 | + 'type'=>'kt.not_logged_in', | ||
| 353 | 'alert'=>true, | 353 | 'alert'=>true, |
| 354 | 'message'=>_kt('Your session has expired, please log in again.'))); | 354 | 'message'=>_kt('Your session has expired, please log in again.'))); |
| 355 | exit(0); | 355 | exit(0); |
| @@ -410,8 +410,8 @@ class KTStandardDispatcher extends KTDispatcher { | @@ -410,8 +410,8 @@ class KTStandardDispatcher extends KTDispatcher { | ||
| 410 | } | 410 | } |
| 411 | 411 | ||
| 412 | function addInfoMessage($sMessage) { $_SESSION['KTInfoMessage'][] = $sMessage; } | 412 | function addInfoMessage($sMessage) { $_SESSION['KTInfoMessage'][] = $sMessage; } |
| 413 | - | ||
| 414 | - function addErrorMessage($sMessage) { $_SESSION['KTErrorMessage'][] = $sMessage; } | 413 | + |
| 414 | + function addErrorMessage($sMessage) { $_SESSION['KTErrorMessage'][] = $sMessage; } | ||
| 415 | 415 | ||
| 416 | function errorPage($errorMessage, $oException = null) { | 416 | function errorPage($errorMessage, $oException = null) { |
| 417 | if ($this->bTransactionStarted) { | 417 | if ($this->bTransactionStarted) { |
| @@ -442,7 +442,7 @@ class KTStandardDispatcher extends KTDispatcher { | @@ -442,7 +442,7 @@ class KTStandardDispatcher extends KTDispatcher { | ||
| 442 | $this->oPage->setPageContents($data); | 442 | $this->oPage->setPageContents($data); |
| 443 | $this->oPage->setUser($this->oUser); | 443 | $this->oPage->setUser($this->oUser); |
| 444 | $this->oPage->setHelp($this->sHelpPage); | 444 | $this->oPage->setHelp($this->sHelpPage); |
| 445 | - | 445 | + |
| 446 | // handle errors that were set using KTErrorMessage. | 446 | // handle errors that were set using KTErrorMessage. |
| 447 | $errors = KTUtil::arrayGet($_SESSION, 'KTErrorMessage', array()); | 447 | $errors = KTUtil::arrayGet($_SESSION, 'KTErrorMessage', array()); |
| 448 | if (!empty($errors)) { | 448 | if (!empty($errors)) { |
| @@ -454,7 +454,7 @@ class KTStandardDispatcher extends KTDispatcher { | @@ -454,7 +454,7 @@ class KTStandardDispatcher extends KTDispatcher { | ||
| 454 | 454 | ||
| 455 | // handle notices that were set using KTInfoMessage. | 455 | // handle notices that were set using KTInfoMessage. |
| 456 | $info = KTUtil::arrayGet($_SESSION, 'KTInfoMessage', array()); | 456 | $info = KTUtil::arrayGet($_SESSION, 'KTInfoMessage', array()); |
| 457 | - | 457 | + |
| 458 | if (!empty($info)) { | 458 | if (!empty($info)) { |
| 459 | foreach ($info as $sInfo) { | 459 | foreach ($info as $sInfo) { |
| 460 | $this->oPage->addInfo($sInfo); | 460 | $this->oPage->addInfo($sInfo); |
| @@ -480,17 +480,17 @@ class KTStandardDispatcher extends KTDispatcher { | @@ -480,17 +480,17 @@ class KTStandardDispatcher extends KTDispatcher { | ||
| 480 | print $oJSON->encode($data); | 480 | print $oJSON->encode($data); |
| 481 | exit(0); | 481 | exit(0); |
| 482 | } | 482 | } |
| 483 | - | 483 | + |
| 484 | function do_json() { | 484 | function do_json() { |
| 485 | $this->bJSONMode = true; | 485 | $this->bJSONMode = true; |
| 486 | - $this->redispatch('json_action', 'json'); | 486 | + $this->redispatch('json_action', 'json'); |
| 487 | } | 487 | } |
| 488 | 488 | ||
| 489 | function json_main() { | 489 | function json_main() { |
| 490 | return array('type'=>'error', 'value'=>'Not implemented'); | 490 | return array('type'=>'error', 'value'=>'Not implemented'); |
| 491 | } | 491 | } |
| 492 | 492 | ||
| 493 | - | 493 | + |
| 494 | 494 | ||
| 495 | } | 495 | } |
| 496 | 496 |