Index: branches/2.8.x/CHANGELOG
===================================================================
--- branches/2.8.x/CHANGELOG	(revision 1753)
+++ branches/2.8.x/CHANGELOG	(revision 1754)
@@ -13,6 +13,10 @@
 
 
 
+15 Sep-2012 Build 1754 Dietmar Woellbrink (Luisehahne)
+# fixed Duplicate entry  for key 'PRIMARY' if adding a new  pageX
+  search for ->page['root_parent'] == 0 in module and shoe_menu2 calls
+  page['root_parent'] has always the page_id from the first adding new page in level  
 15 Sep-2012 Build 1753 Dietmar Woellbrink (Luisehahne)
 ! remove summary="" in captcha tables frontend
 ! fixed calendar time, now all Calendar in WB shows right user TIMEZONE
Index: branches/2.8.x/wb/admin/pages/settings_save.php
===================================================================
--- branches/2.8.x/wb/admin/pages/settings_save.php	(revision 1753)
+++ branches/2.8.x/wb/admin/pages/settings_save.php	(revision 1754)
@@ -156,8 +156,12 @@
 	$root_parent = root_parent($parent);
 }
 else {
-	$level = '0';
-	$root_parent = '0';
+//	$level = '0';
+//	$root_parent = '0';
+// Work out level
+    $level = level_count($page_id);
+// Work out root parent
+    $root_parent = root_parent($page_id);
 }
 
 // Work-out what the link should be
Index: branches/2.8.x/wb/admin/pages/add.php
===================================================================
--- branches/2.8.x/wb/admin/pages/add.php	(revision 1753)
+++ branches/2.8.x/wb/admin/pages/add.php	(revision 1754)
@@ -223,19 +223,29 @@
 $position = 1;
 
 // Add new record into the sections table
-$database->query("INSERT INTO ".TABLE_PREFIX."sections (page_id,position,module,block) VALUES ('$page_id','$position', '$module','1')");
+//$database->query("INSERT INTO ".TABLE_PREFIX."sections (page_id,position,module,block) VALUES ('$page_id','$position', '$module','1')");
 
-// Get the section id
-$section_id = $database->get_one("SELECT LAST_INSERT_ID()");
-
-// Include the selected modules add file if it exists
-if(file_exists(WB_PATH.'/modules/'.$module.'/add.php')) {
-	require(WB_PATH.'/modules/'.$module.'/add.php');
+// Insert module into DB
+$sql  = 'INSERT INTO `'.TABLE_PREFIX.'sections` SET ';
+$sql .= '`page_id` = '.(int)$page_id.', ';
+$sql .= '`module` = \''.$module.'\', ';
+$sql .= '`position` = '.(int)$position.', ';
+$sql .= '`block` = \'1\', ';
+$sql .= '`publ_start` = \'0\',';
+$sql .= '`publ_end` = \'0\' ';
+if($database->query($sql)) {
+	// Get the section id
+	$section_id = $database->get_one("SELECT LAST_INSERT_ID()");
+	// Include the selected modules add file if it exists
+	if(file_exists(WB_PATH.'/modules/'.$module.'/add.php'))
+    {
+		require(WB_PATH.'/modules/'.$module.'/add.php');
+	}
 }
 
 // Check if there is a db error, otherwise say successful
 if($database->is_error()) {
-	$admin->print_error($database->get_error());
+	$admin->print_error($database->get_error().' (sections)');
 } else {
 	$admin->print_success($MESSAGE['PAGES_ADDED'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
 }
Index: branches/2.8.x/wb/admin/interface/version.php
===================================================================
--- branches/2.8.x/wb/admin/interface/version.php	(revision 1753)
+++ branches/2.8.x/wb/admin/interface/version.php	(revision 1754)
@@ -51,5 +51,5 @@
 
 // check if defined to avoid errors during installation (redirect to admin panel fails if PHP error/warnings are enabled)
 if(!defined('VERSION')) define('VERSION', '2.8.3');
-if(!defined('REVISION')) define('REVISION', '1753');
+if(!defined('REVISION')) define('REVISION', '1754');
 if(!defined('SP')) define('SP', '');
Index: branches/2.8.x/wb/framework/functions.php
===================================================================
--- branches/2.8.x/wb/framework/functions.php	(revision 1753)
+++ branches/2.8.x/wb/framework/functions.php	(revision 1754)
@@ -478,6 +478,7 @@
 	global $database;
 	// Get page details
 	$sql = 'SELECT `parent`, `level` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.$page_id;
+
 	$query_page = $database->query($sql);
 	$fetch_page = $query_page->fetchRow();
 	$parent = $fetch_page['parent'];
@@ -484,9 +485,9 @@
 	$level = $fetch_page['level'];
 	if($level == 1) {
 		return $parent;
-	}elseif($parent == 0) {
+	} elseif($parent == 0) {
 		return $page_id;
-	}else {	// Figure out what the root parents id is
+	} else {	// Figure out what the root parents id is
 		$parent_ids = array_reverse(get_parent_ids($page_id));
 		return $parent_ids[0];
 	}
Index: branches/2.8.x/wb/modules/wysiwyg/upgrade.php
===================================================================
--- branches/2.8.x/wb/modules/wysiwyg/upgrade.php	(revision 1753)
+++ branches/2.8.x/wb/modules/wysiwyg/upgrade.php	(revision 1754)
@@ -21,7 +21,6 @@
 	throw new IllegalFileException();
 }
 /* -------------------------------------------------------- */
-
 $msg = '';
 $sTable = TABLE_PREFIX.'mod_wysiwyg';
 if(($sOldType = $database->getTableEngine($sTable))) {
@@ -33,6 +32,17 @@
 } else {
 	$msg .= $database->get_error().'<br />';
 }
+
+$sql = 'ALTER TABLE `'.DB_NAME.'`.`'.$sTable.'` DROP PRIMARY KEY';
+if(!$database->query($sql)) {
+	$msg .= $database->get_error().'<br />';
+}
+
+$sql = 'ALTER TABLE `'.$sTable.'`  ADD `wysiwyg_id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST';
+if(!$database->query($sql)) {
+	$msg .= $database->get_error().'<br />';
+}
+
 // change internal absolute links into relative links
 $sTable = TABLE_PREFIX.'mod_wysiwyg';
 $sql  = 'UPDATE `'.$sTable.'` ';
Index: branches/2.8.x/wb/modules/wysiwyg/add.php
===================================================================
--- branches/2.8.x/wb/modules/wysiwyg/add.php	(revision 1753)
+++ branches/2.8.x/wb/modules/wysiwyg/add.php	(revision 1754)
@@ -4,7 +4,7 @@
  * @category        modules
  * @package         wysiwyg
  * @author          WebsiteBaker Project
- * @copyright       2009-2011, Website Baker Org. e.V.
+ * @copyright       2009-2012, WebsiteBaker Org. e.V.
  * @link			http://www.websitebaker2.org/
  * @license         http://www.gnu.org/licenses/gpl.html
  * @platform        WebsiteBaker 2.8.x
@@ -22,6 +22,6 @@
 		die('<head><title>Access denied</title></head><body><h2 style="color:red;margin:3em auto;text-align:center;">Cannot access this file directly</h2></body></html>');
 }
 /* -------------------------------------------------------- */
+
 // Insert an extra row into the database
 $database->query("INSERT INTO ".TABLE_PREFIX."mod_wysiwyg (page_id,section_id) VALUES ('$page_id','$section_id')");
-
