Commit 1fff13ce5afe5d56a6955f156856c613fb215bbf
1 parent
77cbe551
updated phpdocs
added getSectionLinks and getSectionName methods git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@374 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
95 additions
and
42 deletions
lib/SiteMap.inc
| 1 | 1 | <?php |
| 2 | + | |
| 3 | +require_once("$default->owl_fs_root/lib/security/permission.inc"); | |
| 4 | + | |
| 2 | 5 | /** |
| 3 | 6 | * $Id$ |
| 4 | 7 | * |
| 5 | 8 | * Maintains (page, access) access map, as well as (section, page) map. |
| 6 | 9 | * |
| 7 | 10 | * @version $Revision$ |
| 8 | - * @author michael@jamwarehouse.com | |
| 9 | - * @package dms | |
| 11 | + * @author Michael Joseph <michael@jamwarehouse.com>, Jam Warehouse (Pty) Ltd, South Africa | |
| 12 | + * @package lib.session | |
| 10 | 13 | */ |
| 11 | 14 | class SiteMap { |
| 12 | 15 | |
| ... | ... | @@ -25,10 +28,10 @@ class SiteMap { |
| 25 | 28 | /** |
| 26 | 29 | * Adds a site page mapping entry. |
| 27 | 30 | * |
| 28 | - * @param $action the controller action | |
| 29 | - * @param $page the corresponding page for this action | |
| 30 | - * @param $sectionName the section this page falls under | |
| 31 | - * @param $groupName the user group with access to this page | |
| 31 | + * @param string the controller action | |
| 32 | + * @param string the corresponding page for this action | |
| 33 | + * @param string the section this page falls under | |
| 34 | + * @param string the user group with access to this page | |
| 32 | 35 | */ |
| 33 | 36 | function addPage($action, $page, $sectionName, $groupName) { |
| 34 | 37 | // add to map |
| ... | ... | @@ -36,53 +39,104 @@ class SiteMap { |
| 36 | 39 | } |
| 37 | 40 | |
| 38 | 41 | /** |
| 42 | + * Adds a site page mapping entry- the default page for the section. | |
| 43 | + * | |
| 44 | + * @param string the controller action | |
| 45 | + * @param string the corresponding page for this action | |
| 46 | + * @param string the section this page falls under | |
| 47 | + * @param string the user group with access to this page | |
| 48 | + */ | |
| 49 | + function addDefaultPage($action, $page, $sectionName, $groupName) { | |
| 50 | + } | |
| 51 | + | |
| 52 | + /** | |
| 53 | + * Returns the section name of the supplied page | |
| 54 | + * | |
| 55 | + * @param string the page to lookup the section for | |
| 56 | + */ | |
| 57 | + function getSectionName($sRequiredPage) { | |
| 58 | + global $default; | |
| 59 | + // for each section | |
| 60 | + foreach ($this->siteMapArray as $section => $valArr) { | |
| 61 | + $default->log->debug("Sitemap::getSectionName section=$section; arr=" . arrayToString($valArr)); | |
| 62 | + // for each group, page array combination | |
| 63 | + foreach ($valArr as $requiredGroupName => $pageArr) { | |
| 64 | + $default->log->debug("Sitemap::getSectionName ($requiredGroupName, " . arrayToString($pageArr) . ")"); | |
| 65 | + // now loop through pages until we find the right one | |
| 66 | + foreach ($pageArr as $action => $page) { | |
| 67 | + $default->log->debug("Sitemap::getSectionName ($sRequiredPage == $page)"); | |
| 68 | + if ($sRequiredPage == $page) { | |
| 69 | + return $section; | |
| 70 | + } | |
| 71 | + } | |
| 72 | + } | |
| 73 | + } | |
| 74 | + } | |
| 75 | + | |
| 76 | + /** | |
| 77 | + * Returns controller links for a section | |
| 78 | + * | |
| 79 | + * @param string the section to return links for | |
| 80 | + */ | |
| 81 | + function getSectionLinks($sSectionName) { | |
| 82 | + global $default; | |
| 83 | + // check if the section exists | |
| 84 | + if (is_array($this->siteMapArray[$sSectionName])) { | |
| 85 | + // initialise result array | |
| 86 | + $results = array(); | |
| 87 | + // need to loop through all (groupName, page) arrays in this section | |
| 88 | + foreach ($this->siteMapArray[$sSectionName] as $requiredGroupName => $pages) { | |
| 89 | + $default->log->debug("Sitemap::getSectionLinks: requiredGroup=$requiredGroupName, pages=" . arrayToString($pages)); | |
| 90 | + // if anonymous | |
| 91 | + // or the user is in the required group or the user is the SA | |
| 92 | + if ( ($requiredGroupName == "Anonymous") || | |
| 93 | + ( Permission::userIsInGroupName($requiredGroupName) || | |
| 94 | + Permission::userIsInGroupName("System Administrators") ) ) { | |
| 95 | + // add this array to the resultset array | |
| 96 | + $default->log->debug("Sitemap::getSectionLinks: about to add " . arrayToString($pages)); | |
| 97 | + //$results = array_merge($results, $this->siteMapArray[$sectionName][$requiredGroupName]); | |
| 98 | + $results = array_merge($results, $pages); | |
| 99 | + } | |
| 100 | + } | |
| 101 | + // now check if we have anything in the results array before returning it | |
| 102 | + if (count($results) > 0) { | |
| 103 | + return $results; | |
| 104 | + } else { | |
| 105 | + return false; | |
| 106 | + } | |
| 107 | + } else { | |
| 108 | + $_SESSION["errorMessage"] = "No such section name ($sSectionName) in the sitemap"; | |
| 109 | + return false; | |
| 110 | + } | |
| 111 | + } | |
| 112 | + | |
| 113 | + /** | |
| 39 | 114 | * Returns the page mapped to the (action, groupName) pair. |
| 40 | 115 | * |
| 41 | - * @param $action the action to lookup pages for | |
| 42 | - * @param $userID the user requesting the action | |
| 116 | + * @param string the action to lookup pages for | |
| 43 | 117 | * @return string the page to redirect to, or false if the user doesn't have access to the page |
| 44 | 118 | */ |
| 45 | - function getPage($action, $userID) { | |
| 119 | + function getPage($action) { | |
| 46 | 120 | global $default; |
| 47 | 121 | |
| 122 | + $default->log->info("SiteMap::getPage: checking ($action, " . $_SESSION["userID"] . ")"); | |
| 48 | 123 | $groupIDs = array(); |
| 49 | 124 | |
| 50 | - // if there is no session (ie. requesting login page) | |
| 51 | - // then userID will be "" or unset or something | |
| 52 | - if (!$userID) { | |
| 53 | - // no session, so set groupID to Anonymous group | |
| 54 | - $groupIDs[] = lookupID($default->owl_groups_table, "name", "Anonymous"); | |
| 55 | - } else { | |
| 56 | - // lookup the groups this user is in | |
| 57 | - $groupIDs = lookupGroupIDs($userID); | |
| 58 | - } | |
| 59 | - | |
| 60 | - $default->log->debug("Sitemap::getPage function start; action=$action; userID=$userID; groupIDs=" . arrayToString($groupIDs)); | |
| 61 | - | |
| 62 | 125 | // for each section |
| 63 | 126 | foreach ($this->siteMapArray as $section => $valArr) { |
| 64 | 127 | $default->log->debug("Sitemap::getPage section=$section"); |
| 65 | 128 | // for each group, page array combination |
| 66 | 129 | foreach ($valArr as $requiredGroupName => $pageArr) { |
| 67 | - // lookup the id of the group with access to this page | |
| 68 | - $reqGrpID = lookupID($default->owl_groups_table, "name", "$requiredGroupName"); | |
| 69 | - $default->log->debug("Sitemap::getPage requiredGroupName=$requiredGroupName; id=$reqGrpID"); | |
| 70 | 130 | // now loop through pages until we find the right one |
| 71 | 131 | foreach ($pageArr as $ackshin => $page) { |
| 72 | 132 | if ($ackshin == $action) { |
| 73 | - // FIXME: this won't work once we have lots of groups will it?? | |
| 74 | - // we're assuming that the default groups will be created in the right | |
| 75 | - // order, so that groups with sys and unit access have lower ids than | |
| 76 | - // the required ones! | |
| 77 | - | |
| 78 | - // now check if we have the right group access by | |
| 79 | - // looping through the groupID array and returning the page | |
| 80 | - // if the current groupID <= $reqGrpID | |
| 81 | - for ($i = 0; $i<count($groupIDs); $i++) { | |
| 82 | - $default->log->debug("Sitemap::getPage current groupid=" . $groupIDs[$i] . "; reqGrpID=$reqGrpID"); | |
| 83 | - if ($groupIDs[$i] <= $reqGrpID) { | |
| 84 | - return $page; | |
| 85 | - } | |
| 133 | + $default->log->debug("Sitemap::getPage current requiredGroup=$requiredGroupName, action=$ackshin"); | |
| 134 | + // if anonymous | |
| 135 | + // or the user is in the required group or the user is the SA | |
| 136 | + if ( ($requiredGroupName == "Anonymous") || | |
| 137 | + ( Permission::userIsInGroupName($requiredGroupName) || | |
| 138 | + Permission::userIsInGroupName("System Administrators") ) ) { | |
| 139 | + return $page; | |
| 86 | 140 | } |
| 87 | 141 | } |
| 88 | 142 | } |
| ... | ... | @@ -90,7 +144,7 @@ class SiteMap { |
| 90 | 144 | } |
| 91 | 145 | // if the function hasn't returned already then the specified |
| 92 | 146 | // userGroup does not have access to the action |
| 93 | - $default->log->info("Sitemap::getPage access denied for ($action, $userID)"); | |
| 147 | + $default->log->info("Sitemap::getPage: access denied for ($action, " . $_SESSION["userID"] . ")"); | |
| 94 | 148 | return false; |
| 95 | 149 | } |
| 96 | 150 | |
| ... | ... | @@ -98,11 +152,10 @@ class SiteMap { |
| 98 | 152 | * Returns the pages in the specified section accessible to the |
| 99 | 153 | * specified userClass. |
| 100 | 154 | * |
| 101 | - * @param $sectionName the section to retrieve pages for | |
| 102 | - * @param $userID the user class to return pages for | |
| 155 | + * @param string the section to retrieve pages for | |
| 103 | 156 | * @return array the actions for the specified section |
| 104 | 157 | */ |
| 105 | - function getSection($sectionName, $userID) { | |
| 158 | + function getSection($sectionName) { | |
| 106 | 159 | // check if the section exists |
| 107 | 160 | if (is_array($this->siteMapArray[$sectionName])) { |
| 108 | 161 | // initialise result array |
| ... | ... | @@ -112,7 +165,7 @@ class SiteMap { |
| 112 | 165 | // lookup groupID for requiredGroupName |
| 113 | 166 | $reqGrpID = lookupID($default->owl_groups_table, "name", "$requiredGroupName"); |
| 114 | 167 | // lookup groupIDs for the user |
| 115 | - $groupIDs = lookupGroupIDs($userID); | |
| 168 | + $groupIDs = lookupGroupIDs($_SESSION["userID"]); | |
| 116 | 169 | // loop through the user's groups and check against the requiredGroup |
| 117 | 170 | for ($i = 0; $i<count($groupIDs); $i++) { |
| 118 | 171 | $default->log->debug("getPage current groupid=" . $groupIDs[$i] . "; reqGrpID=$reqGrpID"); | ... | ... |