Commit 8dab968a08754f30dcc4d219d64d4dc8c78ba6b9
1 parent
a93f299f
formatting update
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@812 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
66 additions
and
66 deletions
lib/session/SiteMap.inc
| ... | ... | @@ -24,12 +24,12 @@ class SiteMap { |
| 24 | 24 | * The underlying site map storage array |
| 25 | 25 | */ |
| 26 | 26 | var $aSiteMap; |
| 27 | - | |
| 27 | + | |
| 28 | 28 | /** |
| 29 | 29 | * Whether to use the database to store the sitemap or not |
| 30 | 30 | */ |
| 31 | 31 | var $bUseDB; |
| 32 | - | |
| 32 | + | |
| 33 | 33 | /** |
| 34 | 34 | * Constructs a new SiteMap |
| 35 | 35 | * If the db is not being used, the array is initialised. |
| ... | ... | @@ -42,7 +42,7 @@ class SiteMap { |
| 42 | 42 | $this->aSiteMap = array(); |
| 43 | 43 | } |
| 44 | 44 | } |
| 45 | - | |
| 45 | + | |
| 46 | 46 | /** |
| 47 | 47 | * Sets the database flag |
| 48 | 48 | * |
| ... | ... | @@ -51,15 +51,15 @@ class SiteMap { |
| 51 | 51 | function setUseDB($bUseDB) { |
| 52 | 52 | $this->bUseDB = $bUseDB; |
| 53 | 53 | } |
| 54 | - | |
| 54 | + | |
| 55 | 55 | /** |
| 56 | 56 | * Returns the database flag |
| 57 | 57 | */ |
| 58 | 58 | function getUseDB() { |
| 59 | 59 | return $this->bUseDB; |
| 60 | 60 | } |
| 61 | - | |
| 62 | - | |
| 61 | + | |
| 62 | + | |
| 63 | 63 | /** |
| 64 | 64 | * Adds a site page mapping entry. |
| 65 | 65 | * |
| ... | ... | @@ -72,13 +72,13 @@ class SiteMap { |
| 72 | 72 | */ |
| 73 | 73 | function addPage($sAction, $sPage, $sSectionName, $sRequiredAccess, $sLinkText, $bEnabled = true) { |
| 74 | 74 | if (!$this->bUseDB) { |
| 75 | - $this->aSiteMap[$sSectionName][$sRequiredAccess][$sAction] = array ("page" => $sPage, | |
| 76 | - "description" => $sLinkText, | |
| 77 | - "enabled" => (($bEnabled) ? "1" : "0"), | |
| 78 | - "default" => "0"); | |
| 75 | + $this->aSiteMap[$sSectionName][$sRequiredAccess][$sAction] = array ("page" => $sPage, | |
| 76 | + "description" => $sLinkText, | |
| 77 | + "enabled" => (($bEnabled) ? "1" : "0"), | |
| 78 | + "default" => "0"); | |
| 79 | 79 | } |
| 80 | 80 | } |
| 81 | - | |
| 81 | + | |
| 82 | 82 | /** |
| 83 | 83 | * Adds a site page mapping entry- the default page for the section. |
| 84 | 84 | * |
| ... | ... | @@ -87,16 +87,16 @@ class SiteMap { |
| 87 | 87 | * @param string the section this page falls under |
| 88 | 88 | * @param int the minimum access needed to access this page |
| 89 | 89 | * @param string description of the page for link presentation |
| 90 | - */ | |
| 90 | + */ | |
| 91 | 91 | function addDefaultPage($sAction, $sPage, $sSectionName, $sRequiredAccess, $sLinkText, $bEnabled = true) { |
| 92 | 92 | if (!$this->bUseDB) { |
| 93 | - $this->aSiteMap[$sSectionName][$sRequiredAccess][$sAction] = array ("page" => $sPage, | |
| 94 | - "description" => $sLinkText, | |
| 95 | - "enabled" => (($bEnabled) ? "1" : "0"), | |
| 96 | - "default" => "1"); | |
| 93 | + $this->aSiteMap[$sSectionName][$sRequiredAccess][$sAction] = array ("page" => $sPage, | |
| 94 | + "description" => $sLinkText, | |
| 95 | + "enabled" => (($bEnabled) ? "1" : "0"), | |
| 96 | + "default" => "1"); | |
| 97 | 97 | } |
| 98 | 98 | } |
| 99 | - | |
| 99 | + | |
| 100 | 100 | /** |
| 101 | 101 | * Returns true if the user has the necessary rights to access |
| 102 | 102 | * a sitemap entry |
| ... | ... | @@ -114,7 +114,7 @@ class SiteMap { |
| 114 | 114 | // if you're a system administrator, you've got access to everything |
| 115 | 115 | if (Permission::userIsSystemAdministrator()) { |
| 116 | 116 | return true; |
| 117 | - } else { | |
| 117 | + } else { | |
| 118 | 118 | if (Permission::userIsUnitAdministrator()) { |
| 119 | 119 | // if you're a unit administrator, then you have access to everything |
| 120 | 120 | // including and less than UA |
| ... | ... | @@ -133,13 +133,13 @@ class SiteMap { |
| 133 | 133 | // return false anyway |
| 134 | 134 | return false; |
| 135 | 135 | } |
| 136 | - | |
| 136 | + | |
| 137 | 137 | /** |
| 138 | 138 | * Returns controller links for a section. |
| 139 | 139 | * Checks whether to use the db or not and calls the appropriate method |
| 140 | 140 | * |
| 141 | 141 | * @param string the section to return links for |
| 142 | - */ | |
| 142 | + */ | |
| 143 | 143 | function getSectionLinks($sSectionName) { |
| 144 | 144 | if ($this->bUseDB) { |
| 145 | 145 | return $this->getSectionLinksUsingDB($sSectionName); |
| ... | ... | @@ -147,7 +147,7 @@ class SiteMap { |
| 147 | 147 | return $this->getSectionLinksUsingArray($sSectionName); |
| 148 | 148 | } |
| 149 | 149 | } |
| 150 | - | |
| 150 | + | |
| 151 | 151 | /** |
| 152 | 152 | * Returns controller links for a section (uses the db) |
| 153 | 153 | * |
| ... | ... | @@ -161,17 +161,17 @@ class SiteMap { |
| 161 | 161 | if ($sectionID) { |
| 162 | 162 | // initialise result array |
| 163 | 163 | $results = array("descriptions" => array(), "links" => array()); |
| 164 | - | |
| 165 | - if ($sql->query("SELECT link_text, action, access_id FROM $default->owl_sitemap_table WHERE section_id=$sectionID AND is_enabled=1")) { | |
| 164 | + | |
| 165 | + if ($sql->query("SELECT link_text, action, access_id FROM $default->owl_sitemap_table WHERE section_id=$sectionID AND is_enabled=1")) { | |
| 166 | 166 | while ($sql->next_record()) { |
| 167 | 167 | // check permissions |
| 168 | 168 | if ($this->hasPermission($sql->f("access_id"))) { |
| 169 | 169 | // add this array to the resultset array if there is link text |
| 170 | 170 | if (strlen($sql->f("link_text")) > 0) { |
| 171 | - $results["descriptions"][] = $sql->f("link_text"); | |
| 171 | + $results["descriptions"][] = $sql->f("link_text"); | |
| 172 | 172 | // if fFolderID is set and fFolderID is in the page string |
| 173 | 173 | // append folderID to the controller link |
| 174 | - $results["links"][] = $fFolderID ? generateControllerUrl($sql->f("action") . "&fFolderID=$fFolderID") : generateControllerUrl($sql->f("action")); | |
| 174 | + $results["links"][] = $fFolderID ? generateControllerUrl($sql->f("action"), "fFolderID=$fFolderID") : generateControllerUrl($sql->f("action")); | |
| 175 | 175 | } |
| 176 | 176 | } |
| 177 | 177 | } |
| ... | ... | @@ -180,7 +180,7 @@ class SiteMap { |
| 180 | 180 | return $results; |
| 181 | 181 | } else { |
| 182 | 182 | return false; |
| 183 | - } | |
| 183 | + } | |
| 184 | 184 | } else { |
| 185 | 185 | $_SESSION["errorMessage"] = $lang_err_database; |
| 186 | 186 | return false; |
| ... | ... | @@ -190,7 +190,7 @@ class SiteMap { |
| 190 | 190 | return false; |
| 191 | 191 | } |
| 192 | 192 | } |
| 193 | - | |
| 193 | + | |
| 194 | 194 | /** |
| 195 | 195 | * Returns controller links for a section (uses the array) |
| 196 | 196 | * |
| ... | ... | @@ -199,24 +199,24 @@ class SiteMap { |
| 199 | 199 | function getSectionLinksUsingArray($sSectionName) { |
| 200 | 200 | global $default, $fFolderID, $fDocumentID; |
| 201 | 201 | // TODO: same for documentID |
| 202 | - | |
| 202 | + | |
| 203 | 203 | // check if the section exists |
| 204 | 204 | if (is_array($this->aSiteMap[$sSectionName])) { |
| 205 | 205 | // initialise result array |
| 206 | 206 | $results = array("descriptions" => array(), "links" => array()); |
| 207 | - | |
| 207 | + | |
| 208 | 208 | // need to loop through all (access, page) arrays in this section |
| 209 | 209 | foreach ($this->aSiteMap[$sSectionName] as $requiredAccess => $pages) { |
| 210 | 210 | if ($this->hasPermission($requiredAccess)) { |
| 211 | 211 | foreach ($pages as $action => $pageDetail) { |
| 212 | 212 | // add this array to the resultset array if there is link text |
| 213 | 213 | if ((strlen($pages[$action]["description"]) > 0) && |
| 214 | - ($pages[$action]["enabled"])) { | |
| 214 | + ($pages[$action]["enabled"])) { | |
| 215 | 215 | |
| 216 | 216 | $results["descriptions"][] = $pages[$action]["description"]; |
| 217 | 217 | // if fFolderID is set and fFolderID is in the page string |
| 218 | 218 | // append folderID to the controller link |
| 219 | - $results["links"][] = $fFolderID ? generateControllerUrl($action . "&fFolderID=$fFolderID") : generateControllerUrl($action); | |
| 219 | + $results["links"][] = $fFolderID ? generateControllerUrl($action, "fFolderID=$fFolderID") : generateControllerUrl($action); | |
| 220 | 220 | } |
| 221 | 221 | } |
| 222 | 222 | } |
| ... | ... | @@ -226,20 +226,20 @@ class SiteMap { |
| 226 | 226 | return $results; |
| 227 | 227 | } else { |
| 228 | 228 | return false; |
| 229 | - } | |
| 229 | + } | |
| 230 | 230 | } else { |
| 231 | 231 | $_SESSION["errorMessage"] = "No such section name ($sSectionName) in the sitemap"; |
| 232 | 232 | return false; |
| 233 | 233 | } |
| 234 | 234 | } |
| 235 | - | |
| 235 | + | |
| 236 | 236 | /** |
| 237 | 237 | * Returns the page mapped to the (action, groupName) pair. |
| 238 | 238 | * Checks whether to use the db or not and calls the appropriate method |
| 239 | 239 | * |
| 240 | 240 | * @param string the action to lookup pages for |
| 241 | 241 | * @return string the page to redirect to, or false if the user doesn't have access to the page |
| 242 | - */ | |
| 242 | + */ | |
| 243 | 243 | function getPage($action) { |
| 244 | 244 | if ($this->bUseDB) { |
| 245 | 245 | return $this->getPageUsingDB($action); |
| ... | ... | @@ -247,7 +247,7 @@ class SiteMap { |
| 247 | 247 | return $this->getPageUsingArray($action); |
| 248 | 248 | } |
| 249 | 249 | } |
| 250 | - | |
| 250 | + | |
| 251 | 251 | /** |
| 252 | 252 | * Returns the page mapped to the (action, groupName) pair. (uses the db) |
| 253 | 253 | * |
| ... | ... | @@ -258,7 +258,7 @@ class SiteMap { |
| 258 | 258 | global $default, $lang_err_database; |
| 259 | 259 | $sql = $default->db; |
| 260 | 260 | // lookup the page and access_id from the sitemap |
| 261 | - if ($sql->query("SELECT page, access_id FROM $default->owl_sitemap_table WHERE action='$action'")) { | |
| 261 | + if ($sql->query("SELECT page, access_id FROM $default->owl_sitemap_table WHERE action='$action'")) { | |
| 262 | 262 | if ($sql->next_record()) { |
| 263 | 263 | // check permissions |
| 264 | 264 | if ($this->hasPermission($sql->f("access_id"))) { |
| ... | ... | @@ -274,7 +274,7 @@ class SiteMap { |
| 274 | 274 | return false; |
| 275 | 275 | } |
| 276 | 276 | } |
| 277 | - | |
| 277 | + | |
| 278 | 278 | /** |
| 279 | 279 | * Returns the page mapped to the (action, groupName) pair. (uses the array) |
| 280 | 280 | * |
| ... | ... | @@ -283,10 +283,10 @@ class SiteMap { |
| 283 | 283 | */ |
| 284 | 284 | function getPageUsingArray($action) { |
| 285 | 285 | global $default; |
| 286 | - | |
| 286 | + | |
| 287 | 287 | $default->log->info("SiteMap::getPage: checking ($action, " . $_SESSION["userID"] . ")"); |
| 288 | 288 | $groupIDs = array(); |
| 289 | - | |
| 289 | + | |
| 290 | 290 | // for each section |
| 291 | 291 | foreach ($this->aSiteMap as $section => $valArr) { |
| 292 | 292 | $default->log->debug("Sitemap::getPage section=$section"); |
| ... | ... | @@ -308,7 +308,7 @@ class SiteMap { |
| 308 | 308 | $default->log->info("Sitemap::getPage: access denied for ($action, " . $_SESSION["userID"] . ")"); |
| 309 | 309 | return false; |
| 310 | 310 | } |
| 311 | - | |
| 311 | + | |
| 312 | 312 | /** |
| 313 | 313 | * Returns the section name of the supplied page |
| 314 | 314 | * Checks whether to use the db or not and calls the appropriate method |
| ... | ... | @@ -329,12 +329,12 @@ class SiteMap { |
| 329 | 329 | * @param string the page to lookup the section for |
| 330 | 330 | */ |
| 331 | 331 | function getSectionNameUsingDB($sRequiredPage) { |
| 332 | - global $default, $lang_err_database; | |
| 332 | + global $default, $lang_err_database; | |
| 333 | 333 | $sql = $default->db; |
| 334 | 334 | // lookup the page and access_id from the sitemap |
| 335 | - if ($sql->query("SELECT SSL.name FROM $default->owl_sitemap_table AS S | |
| 336 | - INNER JOIN $default->owl_site_sections_table AS SSL ON S.section_id=SSL.id | |
| 337 | - WHERE S.page='$sRequiredPage'")) { | |
| 335 | + if ($sql->query("SELECT SSL.name FROM $default->owl_sitemap_table AS S | |
| 336 | + INNER JOIN $default->owl_site_sections_table AS SSL ON S.section_id=SSL.id | |
| 337 | + WHERE S.page='$sRequiredPage'")) { | |
| 338 | 338 | if ($sql->next_record()) { |
| 339 | 339 | // return the section name |
| 340 | 340 | return $sql->f("name"); |
| ... | ... | @@ -347,13 +347,13 @@ class SiteMap { |
| 347 | 347 | return false; |
| 348 | 348 | } |
| 349 | 349 | } |
| 350 | - | |
| 350 | + | |
| 351 | 351 | /** |
| 352 | 352 | * Returns the section name of the supplied page (uses the array) |
| 353 | 353 | * |
| 354 | 354 | * @param string the page to lookup the section for |
| 355 | 355 | */ |
| 356 | - function getSectionNameUsingArray($sRequiredPage) { | |
| 356 | + function getSectionNameUsingArray($sRequiredPage) { | |
| 357 | 357 | global $default; |
| 358 | 358 | // for each section |
| 359 | 359 | foreach ($this->aSiteMap as $section => $valArr) { |
| ... | ... | @@ -366,9 +366,9 @@ class SiteMap { |
| 366 | 366 | } |
| 367 | 367 | } |
| 368 | 368 | } |
| 369 | - } | |
| 369 | + } | |
| 370 | 370 | } |
| 371 | - | |
| 371 | + | |
| 372 | 372 | /** |
| 373 | 373 | * Returns the default action for the supplied section |
| 374 | 374 | * Checks whether to use the db or not and calls the appropriate method |
| ... | ... | @@ -383,7 +383,7 @@ class SiteMap { |
| 383 | 383 | return $this->getDefaultActionUsingArray($sSectionName); |
| 384 | 384 | } |
| 385 | 385 | } |
| 386 | - | |
| 386 | + | |
| 387 | 387 | /** |
| 388 | 388 | * Returns the default action for the supplied section (uses the db) |
| 389 | 389 | * |
| ... | ... | @@ -397,9 +397,9 @@ class SiteMap { |
| 397 | 397 | $sectionID = lookupID($default->owl_site_sections_table, "name", $sSectionName); |
| 398 | 398 | if ($sectionID) { |
| 399 | 399 | // lookup the default action for the specified section |
| 400 | - if ($sql->query("SELECT action FROM $default->owl_sitemap_table | |
| 401 | - WHERE section_id=$sectionID | |
| 402 | - AND is_default=1 AND is_enabled=1")) { | |
| 400 | + if ($sql->query("SELECT action FROM $default->owl_sitemap_table | |
| 401 | + WHERE section_id=$sectionID | |
| 402 | + AND is_default=1 AND is_enabled=1")) { | |
| 403 | 403 | if ($sql->next_record()) { |
| 404 | 404 | // return the section name |
| 405 | 405 | return $sql->f("action"); |
| ... | ... | @@ -416,14 +416,14 @@ class SiteMap { |
| 416 | 416 | return false; |
| 417 | 417 | } |
| 418 | 418 | } |
| 419 | - | |
| 419 | + | |
| 420 | 420 | /** |
| 421 | 421 | * Returns the default action for the supplied section (uses the array) |
| 422 | 422 | * |
| 423 | 423 | * @param string the section name to return the default action for |
| 424 | 424 | * @return string the controller action for the default page for this section |
| 425 | 425 | */ |
| 426 | - function getDefaultActionUsingArray($sSectionName) { | |
| 426 | + function getDefaultActionUsingArray($sSectionName) { | |
| 427 | 427 | global $default; |
| 428 | 428 | // check if the section exists |
| 429 | 429 | if (is_array($this->aSiteMap[$sSectionName])) { |
| ... | ... | @@ -446,7 +446,7 @@ class SiteMap { |
| 446 | 446 | // TODO: internal error code? |
| 447 | 447 | $_SESSION["errorMessage"] = "$sSectionName not in SiteMap!"; |
| 448 | 448 | return false; |
| 449 | - } | |
| 449 | + } | |
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | /** |
| ... | ... | @@ -463,7 +463,7 @@ class SiteMap { |
| 463 | 463 | return $this->getActionFromPageUsingArray($sPage); |
| 464 | 464 | } |
| 465 | 465 | } |
| 466 | - | |
| 466 | + | |
| 467 | 467 | /** |
| 468 | 468 | * Returns the action for a specific page- to enable redirects (uses the db) |
| 469 | 469 | * |
| ... | ... | @@ -473,9 +473,9 @@ class SiteMap { |
| 473 | 473 | function getActionFromPageUsingDB($sPage) { |
| 474 | 474 | global $default, $lang_err_database; |
| 475 | 475 | $sql = $default->db; |
| 476 | - | |
| 476 | + | |
| 477 | 477 | // lookup the action for the specified page |
| 478 | - if ($sql->query("SELECT action FROM $default->owl_sitemap_table WHERE page='$sPage'")) { | |
| 478 | + if ($sql->query("SELECT action FROM $default->owl_sitemap_table WHERE page='$sPage'")) { | |
| 479 | 479 | if ($sql->next_record()) { |
| 480 | 480 | // return the section name |
| 481 | 481 | return $sql->f("action"); |
| ... | ... | @@ -488,14 +488,14 @@ class SiteMap { |
| 488 | 488 | return false; |
| 489 | 489 | } |
| 490 | 490 | } |
| 491 | - | |
| 491 | + | |
| 492 | 492 | /** |
| 493 | 493 | * Returns the action for a specific page- to enable redirects (uses the array) |
| 494 | 494 | * |
| 495 | 495 | * @param string the page to perform the reverse lookup for |
| 496 | 496 | * @return string the action for this page |
| 497 | 497 | */ |
| 498 | - function getActionFromPageUsingArray($sPage) { | |
| 498 | + function getActionFromPageUsingArray($sPage) { | |
| 499 | 499 | global $default; |
| 500 | 500 | $default->log->debug("Sitemap::getActionFromPage: page=$sPage"); |
| 501 | 501 | // for each section |
| ... | ... | @@ -515,7 +515,7 @@ class SiteMap { |
| 515 | 515 | } |
| 516 | 516 | } |
| 517 | 517 | } |
| 518 | - | |
| 518 | + | |
| 519 | 519 | /** |
| 520 | 520 | * Prints the current site map |
| 521 | 521 | */ |
| ... | ... | @@ -524,14 +524,14 @@ class SiteMap { |
| 524 | 524 | return arrayToString($this->aSiteMap); |
| 525 | 525 | } |
| 526 | 526 | } |
| 527 | - | |
| 527 | + | |
| 528 | 528 | /** |
| 529 | 529 | * Writes the current sitemap from the array to the DB |
| 530 | 530 | */ |
| 531 | 531 | function syncWithDB() { |
| 532 | 532 | global $default; |
| 533 | 533 | $sql = $default->db; |
| 534 | - | |
| 534 | + | |
| 535 | 535 | // only if we're using the array |
| 536 | 536 | if (!$this->bUseDB) { |
| 537 | 537 | // clear section table |
| ... | ... | @@ -545,20 +545,20 @@ class SiteMap { |
| 545 | 545 | $default->log->debug("Sitemap::syncWithDB removed sitemap"); |
| 546 | 546 | } else { |
| 547 | 547 | $default->log->error("Sitemap::syncWithDB remove sitemap failed"); |
| 548 | - } | |
| 548 | + } | |
| 549 | 549 | // for each section |
| 550 | 550 | foreach ($this->aSiteMap as $section => $valArr) { |
| 551 | 551 | // insert into the section |
| 552 | 552 | $sSectionSql = "INSERT INTO $default->owl_site_sections_table (name) VALUES ('$section')"; |
| 553 | 553 | $default->log->debug("Sitemap::syncWithDB insert=$sSectionSql"); |
| 554 | - | |
| 554 | + | |
| 555 | 555 | if ($sql->query($sSectionSql)) { |
| 556 | 556 | $sectionID = $sql->insert_id(); |
| 557 | 557 | $default->log->debug("Sitemap::syncWithDB added section $section; $sectionID"); |
| 558 | 558 | } else { |
| 559 | 559 | $default->log->error("Sitemap::syncWithDB add section $section failed"); |
| 560 | 560 | } |
| 561 | - | |
| 561 | + | |
| 562 | 562 | // for each group, page array combination |
| 563 | 563 | foreach ($valArr as $requiredAccess => $pageArr) { |
| 564 | 564 | // now loop through all the pages | ... | ... |