SiteMap.inc
4.75 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
<?php
/**
* $Id$
*
* Maintains page-level access map, as well as section, page map.
*
* @version $Revision$
* @author michael@jamwarehouse.com
* @package dms
*/
class SiteMap {
/**
* The underlying site map storage array
*/
var $siteMapArray;
/**
* Constructs a new SiteMap, initialising the array.
*/
function SiteMap() {
$this->siteMapArray = array();
}
/**
* Adds a site page mapping entry.
*
* @param $action
* the controller action
* @param $page
* the corresponding page for this action
* @param $sectionName
* the section this page falls under
* @param $groupID
* the user group with access to this page
*/
function addPage($action, $page, $sectionName, $groupID) {
// add to map
$this->siteMapArray[$sectionName][$groupID][$action] = $page;
}
/**
* Returns the page mapped to the action, userClass pair.
*
* @param $action
* the action to lookup pages for
* @param $groupIDs
* array of user group IDs to perform page level validation against
* @return
* the page to redirect to, or false if the user class doesn't
* have access to the page
*/
function getPage($action, $groupIDs) {
global $default;
$default->log->debug("Sitemap::getPage function start; action=$action; groupIDs=" . arrayToString($groupIDs));
// for each section
foreach ($this->siteMapArray as $section => $valArr) {
$default->log->debug("Sitemap::getPage section=$section");
// for each group, page array combination
foreach ($valArr as $requiredGroup => $pageArr) {
$reqGrpID = lookupID($default->owl_groups_table, "name", $requiredGroup);
$default->log->debug("Sitemap::getPage requiredGroup=$requiredGroup; reqGrpID=$reqGrpID");
// now loop through pages until we find the right one
foreach ($pageArr as $ackshin => $page) {
if ($ackshin == $action) {
// now check if we have the right group access by
// looping through the groupID array and returning the page
// if the current groupID <= $reqGrpID
// FIXME: this won't work once we have lots of groups will it??
// we're assuming that the default groups will be created in the right
// order, so that groups with sys and unit access have lower ids than
// the required ones!
for ($i = 0; $i<count($groupIDs); $i++) {
$default->log->debug("Sitemap::getPage current groupid=" . $groupIDs[$i] . "; reqGrpID=$reqGrpID");
if ($groupIDs[$i] <= $reqGrpID) {
return $page;
}
}
}
}
}
}
// if the function hasn't returned already then the specified
// userGroup does not have access to the action
return false;
}
/**
* Returns the pages in the specified section accessible to the
* specified userClass.
*
* @param $sectionName
* the section to retrieve pages for
* @param $userClass
* the user class to return pages for
* @return
* an array containing the actions for the specified section
*/
function getSection($sectionName, $userClass) {
// check if the section exists
if (is_array($this->siteMapArray[$sectionName])) {
// initialise result array
$results = array();
// need to loop through all user class arrays in this section
foreach ($this->siteMapArray[$sectionName] as $uc => $pages) {
if (constant($userClass) <= constant($uc)) {
// add this array to the resultset array
$results = array_merge($results, $this->siteMapArray[$sectionName][$uc]);
}
}
// now check if we have anything in the results array before returning it
if (count($results) > 0) {
return $results;
} else {
return false;
}
} else {
// supplied section not in sitemap
// TODO: internal error code?
$_SESSION["errorMessage"] = "$sectionName not in SiteMap!";
return false;
}
}
/**
* Prints the current site map
*/
function printMap() {
return arrayToString($this->siteMapArray);
}
}
?>