Commit d6b4b95fb5ffd79deb8c4450eb0e05eaa47967d9

Authored by michael
1 parent 33dd0c12

added method to sync with the database (write the array contents to the db)


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@616 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing 1 changed file with 46 additions and 1 deletions
lib/session/SiteMap.inc
... ... @@ -460,7 +460,7 @@ class SiteMap {
460 460 * @return string the action for this page
461 461 */
462 462 function getActionFromPageUsingDB($sPage) {
463   - global $default, $lang_err_database;
  463 + global $default, $lang_err_database;
464 464 $sql = new Owl_DB();
465 465  
466 466 // lookup the action for the specified page
... ... @@ -513,5 +513,50 @@ class SiteMap {
513 513 return arrayToString($this->aSiteMap);
514 514 }
515 515 }
  516 +
  517 + /**
  518 + * Writes the current sitemap from the array to the DB
  519 + */
  520 + function syncWithDB() {
  521 + global $default;
  522 + $sql = new Owl_DB();
  523 +
  524 + // only if we're using the array
  525 + if (!$this->bUseDB) {
  526 + // clear section table
  527 + if ($sql->query("DELETE from $default->owl_site_sections_table")) {
  528 + $default->log->debug("Sitemap::syncWithDB removed sections");
  529 + } else {
  530 + $default->log->error("Sitemap::syncWithDB remove sections failed");
  531 + }
  532 + // for each section
  533 + foreach ($this->aSiteMap as $section => $valArr) {
  534 + // insert into the section
  535 + $sSectionSql = "INSERT INTO $default->owl_site_sections_table (name) VALUES ('$section')";
  536 + $default->log->debug("Sitemap::syncWithDB insert=$sSectionSql");
  537 +
  538 + if ($sql->query($sSectionSql)) {
  539 + $sectionID = $sql->insert_id();
  540 + $default->log->debug("Sitemap::syncWithDB added section $section; $sectionID");
  541 + } else {
  542 + $default->log->error("Sitemap::syncWithDB add section $section failed");
  543 + }
  544 +
  545 + // for each group, page array combination
  546 + foreach ($valArr as $requiredAccess => $pageArr) {
  547 + // now loop through all the pages
  548 + 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) . ")";
  551 + if ($sql->query($sSiteMapSql)) {
  552 + $default->log->debug("Sitemap::syncWithDb sitemap insert worked for ($action, " . $page["page"] . ")");
  553 + } else {
  554 + $default->log->debug("Sitemap::syncWithDB sitemap insert failed ($sSiteMapSql)");
  555 + }
  556 + }
  557 + }
  558 + }
  559 + }
  560 + }
516 561 }
517 562 ?>
... ...