Commit 65e378062ac988b4ae5a95f6cfc8da09b9d29d08

Authored by michael
1 parent 87000767

added is_enabled attribute; updated array and db methods (getSectionLinks, getDe…

…faultPage) to filter on enabled before returning


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@628 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing 1 changed file with 35 additions and 21 deletions
lib/session/SiteMap.inc
... ... @@ -63,17 +63,19 @@ class SiteMap {
63 63 /**
64 64 * Adds a site page mapping entry.
65 65 *
66   - * @param string the controller action
67   - * @param string the corresponding page for this action
68   - * @param string the section this page falls under
69   - * @param int the minimum access needed to access this page
70   - * @param string description of the page for link presentation
  66 + * @param string the controller action
  67 + * @param string the corresponding page for this action
  68 + * @param string the section this page falls under
  69 + * @param int the minimum access needed to access this page
  70 + * @param string description of the page for link presentation
  71 + * @param boolean whether this action is enabled or not
71 72 */
72   - function addPage($action, $page, $sectionName, $requiredAccess, $description) {
  73 + function addPage($sAction, $sPage, $sSectionName, $sRequiredAccess, $sLinkText, $bEnabled = true) {
73 74 if (!$this->bUseDB) {
74   - $this->aSiteMap[$sectionName][$requiredAccess][$action] = array ("page" => $page,
75   - "description" => $description,
76   - "default" => false);
  75 + $this->aSiteMap[$sSectionName][$sRequiredAccess][$sAction] = array ("page" => $sPage,
  76 + "description" => $sLinkText,
  77 + "enabled" => (($bEnabled) ? "1" : "0"),
  78 + "default" => "0");
77 79 }
78 80 }
79 81  
... ... @@ -86,11 +88,12 @@ class SiteMap {
86 88 * @param int the minimum access needed to access this page
87 89 * @param string description of the page for link presentation
88 90 */
89   - function addDefaultPage($action, $page, $sectionName, $requiredAccess, $description) {
  91 + function addDefaultPage($sAction, $sPage, $sSectionName, $sRequiredAccess, $sLinkText, $bEnabled = true) {
90 92 if (!$this->bUseDB) {
91   - $this->aSiteMap[$sectionName][$requiredAccess][$action] = array ("page" => $page,
92   - "description" => $description,
93   - "default" => true);
  93 + $this->aSiteMap[$sSectionName][$sRequiredAccess][$sAction] = array ("page" => $sPage,
  94 + "description" => $sLinkText,
  95 + "enabled" => (($bEnabled) ? "1" : "0"),
  96 + "default" => "1");
94 97 }
95 98 }
96 99  
... ... @@ -103,7 +106,7 @@ class SiteMap {
103 106 */
104 107 function hasPermission($requiredAccess) {
105 108 global $default;
106   - $default->log->debug("SiteMap::hasPermission: reqAcces=$requiredAccess");
  109 +
107 110 // if no access control is required
108 111 if ($requiredAccess == None) {
109 112 return true;
... ... @@ -125,7 +128,7 @@ class SiteMap {
125 128 }
126 129 }
127 130 // shouldn't ever get here
128   - $default->log->error("SiteMap::hasPermission THERE IS A WHOLE IN THE PAGE LEVEL ACCESS SECURITY MODEL!!!");
  131 + $default->log->error("SiteMap::hasPermission THERE IS A HOLE IN THE PAGE LEVEL ACCESS SECURITY MODEL!!!");
129 132 $default->log->error("SiteMap::hasPermission requiredAccess=$requiredAccess; userID=" . $_SESSION["userID"]);
130 133 // return false anyway
131 134 return false;
... ... @@ -159,13 +162,14 @@ class SiteMap {
159 162 // initialise result array
160 163 $results = array("descriptions" => array(), "links" => array());
161 164  
162   - if ($sql->query("SELECT link_text, action, access_id FROM $default->owl_sitemap_table WHERE section_id=$sectionID")) {
  165 + if ($sql->query("SELECT link_text, action, access_id FROM $default->owl_sitemap_table WHERE section_id=$sectionID AND is_enabled=1")) {
163 166 while ($sql->next_record()) {
164 167 // check permissions
165 168 if ($this->hasPermission($sql->f("access_id"))) {
166 169 // add this array to the resultset array if there is link text
167 170 if (strlen($sql->f("link_text")) > 0) {
168 171 $results["descriptions"][] = $sql->f("link_text");
  172 + // FIXME: need to pass params to some links
169 173 $results["links"][] = generateControllerUrl($sql->f("action"));
170 174 }
171 175 }
... ... @@ -200,10 +204,14 @@ class SiteMap {
200 204  
201 205 // need to loop through all (access, page) arrays in this section
202 206 foreach ($this->aSiteMap[$sSectionName] as $requiredAccess => $pages) {
  207 + $default->log->debug("SiteMap::getSectionLinks section=$sSectionName, rq=$requiredAccess");//, pages=" . arrayToString($pages));
203 208 if ($this->hasPermission($requiredAccess)) {
204 209 foreach ($pages as $action => $pageDetail) {
205 210 // add this array to the resultset array if there is link text
206   - if (strlen($pages[$action]["description"]) > 0) {
  211 + $default->log->debug("SiteMap::getSectionLinks page=" . arrayToString($pageDetail));
  212 + if ((strlen($pages[$action]["description"]) > 0) &&
  213 + ($pages[$action]["enabled"])) {
  214 + $default->log->debug("SiteMap::getSectionLinks adding $action");
207 215 $results["descriptions"][] = $pages[$action]["description"];
208 216 $results["links"][] = generateControllerUrl($action);
209 217 }
... ... @@ -388,7 +396,7 @@ class SiteMap {
388 396 // lookup the default action for the specified section
389 397 if ($sql->query("SELECT action FROM $default->owl_sitemap_table
390 398 WHERE section_id=$sectionID
391   - AND is_default=1")) {
  399 + AND is_default=1 AND is_enabled=1")) {
392 400 if ($sql->next_record()) {
393 401 // return the section name
394 402 return $sql->f("action");
... ... @@ -425,7 +433,7 @@ class SiteMap {
425 433 //$default->log->debug("Sitemap::getDefaultAction: (section=$sectionName, reqGrp=$requiredGroupName); pages=" . arrayToString($pages));
426 434 foreach ($pages as $action => $pageArray) {
427 435 //$default->log->debug("Sitemap::getDefaultAction: action=$action; pageArray" . arrayToString($pageArray));
428   - if ($pageArray["default"]) {
  436 + if ($pageArray["default"] && $pageArray["enabled"]) {
429 437 return $action;
430 438 }
431 439 }
... ... @@ -529,6 +537,12 @@ class SiteMap {
529 537 } else {
530 538 $default->log->error("Sitemap::syncWithDB remove sections failed");
531 539 }
  540 + // clear sitemap table
  541 + if ($sql->query("DELETE from $default->owl_sitemap_table")) {
  542 + $default->log->debug("Sitemap::syncWithDB removed sitemap");
  543 + } else {
  544 + $default->log->error("Sitemap::syncWithDB remove sitemap failed");
  545 + }
532 546 // for each section
533 547 foreach ($this->aSiteMap as $section => $valArr) {
534 548 // insert into the section
... ... @@ -546,8 +560,8 @@ class SiteMap {
546 560 foreach ($valArr as $requiredAccess => $pageArr) {
547 561 // now loop through all the pages
548 562 foreach ($pageArr as $action => $page) {
549   - $sSiteMapSql = "INSERT INTO $default->owl_sitemap_table (action, page, section_id, access_id, link_text, is_default) " .
550   - "VALUES ('$action', '" . $page["page"] . "', $sectionID, $requiredAccess, '" . $page["description"] . "', " . settype($page["default"], bool) . ")";
  563 + $sSiteMapSql = "INSERT INTO $default->owl_sitemap_table (action, page, section_id, access_id, link_text, is_default, is_enabled) " .
  564 + "VALUES ('$action', '" . $page["page"] . "', $sectionID, $requiredAccess, '" . $page["description"] . "', " . $page["default"] . ", " . $page["enabled"] . ")";
551 565 if ($sql->query($sSiteMapSql)) {
552 566 $default->log->debug("Sitemap::syncWithDb sitemap insert worked for ($action, " . $page["page"] . ")");
553 567 } else {
... ...