"; if (FOR_REAL) { $existing_content = $db->Query("SELECT * FROM cms_content WHERE cnt_file LIKE 'reporting_%'"); while ($existing_page = $db->GetRow($existing_content)) { $id = $existing_page['cnt_id']; $db->Query("DELETE FROM " . DB_LOGIN_NAME . ".permissions WHERE link_type LIKE '%.cms_content.cnt_id' AND link_id = $id"); $db->Query("DELETE FROM cms_content WHERE cnt_id = $id"); } } // Recursive function to walk to the DOM and build an array of data function buildCMSArray(&$root_node, $first_iteration = false) { if (!$first_iteration) { $this_page_array = array( $root_node->get_attribute("cnt_file"), $root_node->get_attribute("cnt_title"), $root_node->get_attribute("cnt_page_title"), $root_node->get_attribute("cnt_visible"), $root_node->get_attribute("access")); } else { $this_page_array = array(); } if ($root_node->has_child_nodes()) { $sub_pages = $root_node->child_nodes(); $sub_page_array = array(); foreach ($sub_pages as $sub_page) { if ($sub_page->node_type() == XML_ELEMENT_NODE) { $sub_page_array[] = buildCMSArray($sub_page); } } $this_page_array[] = $sub_page_array; } if ($first_iteration) return $this_page_array[0]; else return $this_page_array; } // Recursive function to insert pages into the database function buildContentTree($content_array, $cnt_parent, $component_user_types, $component_admin_types, $component_super_types) { $i = 1.0; $component = COMPONENT; $db = &$GLOBALS['db']; foreach ($content_array as $file) { echo "$i) Adding $file[0]:\n"; $insert_sql = "INSERT INTO cms_content (cnt_file, cnt_title, cnt_page_title, cnt_order, cnt_visible2, cnt_visible1, cnt_description, cnt_keywords, cnt_sys, cnt_cmp_id, cnt_parent2) VALUES ('$file[0]', '$file[1]', '$file[2]', $i, 'N', '$file[3]', '', '', 'Y', $component, $cnt_parent)"; if (FOR_REAL) { $new_parent = $db->GetID(false, $insert_sql); } else { $new_parent = 999; pretty_print_r($insert_sql); } echo "Adding permissions: \n"; // Permission loop follows foreach ($component_super_types as $type) { echo "$type (S) "; $insert_sql = "INSERT INTO " . DB_LOGIN_NAME . ".permissions (group_id, access_view, link_type, link_id) VALUES ($type, 1, '" . DB_NAME . ".cms_content.cnt_id', $new_parent)"; if (FOR_REAL) { $db->Query($insert_sql); } else { pretty_print_r($insert_sql); } } if ($file[4] <= 1) { foreach ($component_admin_types as $type) { echo "$type (A) "; $insert_sql = "INSERT INTO " . DB_LOGIN_NAME . ".permissions (group_id, access_view, link_type, link_id) VALUES ($type, 1, '" . DB_NAME . ".cms_content.cnt_id', $new_parent)"; if (FOR_REAL) { $db->Query($insert_sql); } else { pretty_print_r($insert_sql); } } } if ($file[4] == 0) { foreach ($component_user_types as $type) { echo "$type "; $insert_sql = "INSERT INTO " . DB_LOGIN_NAME . ".permissions (group_id, access_view, link_type, link_id) VALUES ($type, 1, '" . DB_NAME . ".cms_content.cnt_id', $new_parent)"; if (FOR_REAL) { $db->Query($insert_sql); } else { pretty_print_r($insert_sql); } } } $i++; if (is_array($file[5])) buildContentTree($file[5], $new_parent, $component_user_types, $component_admin_types, $component_super_types); echo "\n"; } } // Open the XML Document $doc = domxml_open_file($filename); $root_elem = $doc->document_element(); $cms_array = buildCMSArray($root_elem, true); if (!FOR_REAL) { pretty_print_r($cms_array); } buildContentTree($cms_array, 0, $component_user_types, $component_admin_types, $component_super_types); echo ""; ?>