Index: branches/2.8.x/CHANGELOG
===================================================================
--- branches/2.8.x/CHANGELOG	(revision 1888)
+++ branches/2.8.x/CHANGELOG	(revision 1889)
@@ -11,6 +11,12 @@
 ! = Update/Change
 ===============================================================================
 
+
+
+19 Mar-2013 Build 1889 Dietmar Woellbrink (Luisehahne)
+# bugfix solved sections block update
+! update sections table change some varchar to int(11)
++ upgradeHelper class for better module upgrade
 12 Mar-2013 Build 1888 Dietmar Woellbrink (Luisehahne)
 # fixed Deprecated: preg_replace(): modules\show_menu2\include.php
   The /e modifier is deprecated, replaced with preg_replace_callback 
Index: branches/2.8.x/wb/upgrade-script.php
===================================================================
--- branches/2.8.x/wb/upgrade-script.php	(revision 1888)
+++ branches/2.8.x/wb/upgrade-script.php	(revision 1889)
@@ -74,10 +74,7 @@
 // database tables including in WB package
 $aPackage = array (
     'settings','groups','addons','pages','sections','search','users',
-    'mod_captcha_control','mod_jsadmin','mod_menu_link','mod_output_filter','mod_wrapper','mod_wysiwyg',
-//    'mod_code','mod_droplets',
-//    'mod_form_fields','mod_form_settings','mod_form_submissions',
-//    'mod_news_comments','mod_news_groups','mod_news_posts','mod_news_settings',
+    'mod_captcha_control','mod_jsadmin','mod_menu_link','mod_output_filter','mod_wrapper','mod_wysiwyg'
 );
 
 $OK            = ' <span class="ok">OK</span> ';
@@ -207,7 +204,8 @@
  * @return
  */
 function add_modify_field_in_database($sTable,$sField,$sDescription){
-	global $database,$OK,$FAIL,$bDebugModus;
+	global $OK,$FAIL,$bDebugModus;
+	$database=WbDatabase::getInstance();
 	$aDebugMessage = array();
 	if(!$database->field_exists($sTable,$sField)) {
 		$aDebugMessage[] = "<span>Adding field $sField to $sTable table</span>";
@@ -222,42 +220,6 @@
 return;
 }
 
-/**
- * check existings tables for upgrade or install
- *
- * check_wb_tables()
- *
- * @return
- */
-function check_wb_tables()
-{
-	global $database,$aPackage;
-
-// if prefix inludes '_' or '%'
-	$search_for = addcslashes ( TABLE_PREFIX, '%_' );
-	$get_result = $database->query( 'SHOW TABLES LIKE "'.$search_for.'%"');
-
-	// $get_result = $database->query( "SHOW TABLES FROM ".DB_NAME);
-	$all_tables = array();
-	$aTable = array();
-	if($get_result->numRows() > 0)
-	{
-		while ($data = $get_result->fetchRow()) {
-		    $tmp = preg_replace('/^'.preg_quote(TABLE_PREFIX, '/').'/s', '', $data[0]);
-		    if(in_array($tmp,$aPackage)) {
-		        $all_tables[] = $tmp;
-		    } else {
-		        $aTable[] = $tmp;
-		    }
-		}
-	}
-
-	return array_merge ( $all_tables, $aTable );
-}
-
-// check existing tables
-$all_tables = check_wb_tables();
-
 ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 <head>
@@ -402,41 +364,22 @@
 	exit();
 }
 
-// check again all tables, to get a new array
-// if(sizeof($all_tables) < sizeof($aTable)) { $all_tables = check_wb_tables(); }
 /**********************************************************
  *  - check tables coming with WebsiteBaker
  */
-    $check_text = 'total ';
-    // $check_tables = mysqlCheckTables( DB_NAME ) ;
-    $aTable = array();
-    foreach ($all_tables as $data) {
-        $tmp = str_replace(TABLE_PREFIX, '', $data);
-        if(in_array($tmp,$aPackage)) {
-            $aTable[] = $tmp;
-        }
-    }
-
-    if( (sizeof($all_tables) >= sizeof($aPackage)) && (sizeof($aTable) == sizeof($aPackage)) )
-    {
-        echo '<h4 style="margin-left:0;">NOTICE: Your database '.$database->DbName.' has '.sizeof($all_tables).' '.$check_text.' tables from '.sizeof($aPackage).' included in package '.$OK.'</h4>';
-    }
-    else
-    {
+	$aMissingTables = UpgradeHelper::existsAllTables($aPackage);
+	if( sizeof($aMissingTables) == 0){
+        echo '<h4 style="margin-left:0;">NOTICE: '.sizeof($aPackage).' total tables included in package are successful installed your database `'.$database->DbName.'` '.$OK.'</h4>';
+    } else {
         status_msg('<strong>:</strong><br />can\'t run Upgrade, missing tables', 'warning', 'div');
         echo '<h4>Missing required tables. You can install them in backend->addons->modules.<br />';
         echo 'Or if you uploaded per FTP install possible by backend->addons->modules->advanced.<br />';
         echo 'First rename or delete the upgrade-script.php, so the script can\'t start automatically by backend<br />';
-        echo 'After installing missing tables upload and run again upgrade-script.php</h4>';
-        $result = array_diff ( $aPackage, $aTable );
-
-        echo '<h4 class="warning"><br />';
-        while ( list ( $key, $val ) = each ( $result ) )
-        {
-            echo 'TABLE ´'.TABLE_PREFIX.$val.'´ '.$FAIL.'<br>';
-        }
-
-        echo '<br /></h4>';
+        echo 'After installing missing tables upload and run again upgrade-script.php<br /><br /></h4>';
+        echo '<h4 class="warning">';
+        echo 'Missing required tables.<br /><br />';
+        echo 'TABLE `'.implode('` missing! '.$FAIL.'<br />TABLE `',$aMissingTables).'` missing! '.$FAIL;
+        echo '<br /><br /></h4>';
         echo '<br /><br />';
         if(isset($_SERVER['SCRIPT_NAME'])) {
         	echo '<form action="'.$_SERVER['SCRIPT_NAME'].'/">';
@@ -465,7 +408,10 @@
     $aDebugMessage[] = '<div style="margin-left:2em;">';
     $aDebugMessage[] = "<br /><span><strong>Adding default_theme to settings table</strong></span>";
     // db_update_key_value('settings', 'default_theme', $DEFAULT_THEME);
-    $aDebugMessage[] = (db_update_key_value( 'settings', 'default_theme', $DEFAULT_THEME ) ? " $OK<br />" : " $FAIL!<br />");
+    $cfg = array(
+    	'default_theme' => defined('DEFAULT_THEME')&& (DEFAULT_THEME!='') ? DEFAULT_THEME : $DEFAULT_THEME
+    );
+    $aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
     $aDebugMessage[] = '</div>';
 
 if($bDebugModus) {
@@ -472,7 +418,7 @@
     echo implode(PHP_EOL,$aDebugMessage);
 }
 $aDebugMessage = array();
-echo'<h3>Step '.(++$stepID).': Updating tables included in package</h3>';
+echo'<h3>Step '.(++$stepID).': Updating core table included in package</h3>';
     /**********************************************************
      *  - Adding field sec_anchor to settings table
      */
@@ -480,7 +426,7 @@
     echo "<h4>Adding/updating entries on table settings</h4>";
     $aDebugMessage[] = "<span>Adding/updating sec_anchor to settings table</span>";
     $cfg = array(
-    	'sec_anchor' => defined('SEC_ANCHOR') ? SEC_ANCHOR : 'section_'
+    	'sec_anchor' => defined('SEC_ANCHOR')&& (SEC_ANCHOR!='') ? SEC_ANCHOR : 'section_'
     );
    $aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
 
@@ -489,16 +435,25 @@
      */
     $aDebugMessage[] = "<span>Adding/updating redirect timer to settings table</span>";
     $cfg = array(
-    	'redirect_timer' => defined('REDIRECT_TIMER') ? REDIRECT_TIMER : '1500'
+    	'redirect_timer' => defined('REDIRECT_TIMER')&& (REDIRECT_TIMER!='') ? REDIRECT_TIMER : '1500'
     );
     $aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
 
     /**********************************************************
+     *  - Adding default_time_formatr to settings table
+     */
+    $aDebugMessage[] = "<span>Adding/updating default_time_format to settings table</span>";
+    $cfg = array(
+    	'default_time_format' => defined('DEFAULT_TIME_FORMAT')&& (DEFAULT_TIME_FORMAT!='') ? DEFAULT_TIME_FORMAT : 'h:i A'
+    );
+    $aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
+
+    /**********************************************************
      *  - Adding rename_files_on_upload to settings table
      */
     $aDebugMessage[] = "<span>Adding/Updating rename_files_on_upload to settings table</span>";
     $cfg = array(
-    	'rename_files_on_upload' => (defined('RENAME_FILES_ON_UPLOAD') ? RENAME_FILES_ON_UPLOAD : 'ph.*?,cgi,pl,pm,exe,com,bat,pif,cmd,src,asp,aspx,js')
+        'rename_files_on_upload' => (defined('RENAME_FILES_ON_UPLOAD')&& (RENAME_FILES_ON_UPLOAD!='') ? RENAME_FILES_ON_UPLOAD : 'ph.*?,cgi,pl,pm,exe,com,bat,pif,cmd,src,asp,aspx,js')
     );
     $aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
 
@@ -507,7 +462,7 @@
      */
     $aDebugMessage[] = "<span>Adding/updating mediasettings to settings table</span>";
     $cfg = array(
-    	'mediasettings' => (defined('MEDIASETTINGS') ? MEDIASETTINGS : ''),
+    	'mediasettings' => (defined('MEDIASETTINGS')&& (MEDIASETTINGS!='') ? MEDIASETTINGS : ''),
     );
 
     $aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
@@ -528,7 +483,7 @@
      */
     $aDebugMessage[] = "<span>Adding/updating page_icon_dir to settings table</span>";
     $cfg = array(
-    	'page_icon_dir' => (defined('PAGE_ICON_DIR') ? PAGE_ICON_DIR : '/templates/*/title_images'),
+    	'page_icon_dir' => (defined('PAGE_ICON_DIR')&& (PAGE_ICON_DIR!='') ? PAGE_ICON_DIR : '/templates/*/title_images'),
     );
 
     $aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
@@ -547,7 +502,7 @@
      */
     $aDebugMessage[] = "<span>Adding/updating wbmail_signature to settings table</span>";
     $cfg = array(
-    	'wbmail_signature' => (defined('WBMAIL_SIGNATURE') ? WBMAIL_SIGNATURE : '')
+    	'wbmail_signature' => (defined('WBMAIL_SIGNATURE')&& (WBMAIL_SIGNATURE!='') ? WBMAIL_SIGNATURE : '')
     );
 
     $aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
@@ -596,7 +551,7 @@
 	    echo ($database->query($sql)) ? " $OK<br />" : " $FAIL!<br />";
 	}
 
-    echo "<h4>Adding/updating field on table mod_menu_link</h4>";
+	echo "<h4>Adding/updating field on table mod_menu_link</h4>";
 	/**********************************************************
      *  - Add field "redirect_type" to table "mod_menu_link"
      *  has to be moved later to upgrade.php in modul menu_link, because modul can be removed
@@ -604,7 +559,7 @@
 	$table_name = TABLE_PREFIX.'mod_menu_link';
 	$field_name = 'redirect_type';
 	$description = "INT NOT NULL DEFAULT '301' AFTER `target_page_id`";
-    add_modify_field_in_database($table_name,$field_name,$description);
+	add_modify_field_in_database($table_name,$field_name,$description);
 
     if($bDebugModus) {
         echo implode(PHP_EOL,$aDebugMessage);
@@ -618,7 +573,7 @@
 	$table_name = TABLE_PREFIX.'pages';
 	$field_name = 'page_trail';
 	$description = "VARCHAR( 255 ) NOT NULL DEFAULT ''";
-    add_modify_field_in_database($table_name,$field_name,$description);
+	add_modify_field_in_database($table_name,$field_name,$description);
 
 	/**********************************************************
      *  - Add field "page_icon" to table "pages"
@@ -725,7 +680,9 @@
 	$aDebugMessage[] = "<span>Modify field module on sections table</span>";
 	$aDebugMessage[] = ($database->field_modify($table_name, 'module', $description) ? " $OK<br />" : " $FAIL!<br />");
 	$aDebugMessage[] = "<span>Modify field block on sections table</span>";
+	$description = "int(11) NOT NULL DEFAULT '1'";
 	$aDebugMessage[] = ($database->field_modify($table_name, 'block', $description) ? " $OK<br />" : " $FAIL!<br />");
+	$description = "int(11) NOT NULL DEFAULT '0'";
 	$aDebugMessage[] = "<span>Modify field publ_start on sections table</span>";
 	$aDebugMessage[] = ($database->field_modify($table_name, 'publ_start', $description) ? " $OK<br />" : " $FAIL!<br />");
 	$aDebugMessage[] = "<span>Modify field publ_end on sections table</span>";
@@ -786,40 +743,9 @@
 
 }
 
-if(version_compare(WB_REVISION, '1800', '<'))
+if(version_compare(WB_REVISION, REVISION, '<'))
 {
     $aDebugMessage = array();
-    /**********************************************************
-     * This part with changing in mod_wysiwyg will be removed in the final version
-     * special workout for the tester
-     *  - Remove/add PRIMARY KEY from/to "section_id" from table "mod_wysiwygs"
-     */
-    $aDebugMessage[] = '<div style="margin-left:2em;">';
-
-    $sTable = TABLE_PREFIX.'mod_wysiwyg';
-    $field_name = 'wysiwyg_id';
-    if($database->field_exists($sTable, 'wysiwyg_id')) {
-        if($database->index_exists($sTable, 'PRIMARY')) {
-            $aDebugMessage[] = "<span>Remove PRIMARY KEY from table mod_wysiwyg.wysiwyg_id</span>";
-            $aDebugMessage[] = $database->index_remove($sTable, 'PRIMARY') ? " $OK<br />" : " $FAIL!<br />";
-        }
-        $aDebugMessage[] = "<span>Remove field 'wysiwyg_id' from table mod_wysiwyg</span>";
-        $aDebugMessage[] = $database->field_remove($sTable, 'wysiwyg_id') ? " $OK<br />" : " $FAIL!<br />";
-    }
-
-    $aDebugMessage[] = "<br /><span>Create PRIMARY KEY ( `section_id` ) on table mod_wysiwygs.</span>";
-    $aDebugMessage[] = $database->index_add($sTable, '', 'section_id', 'PRIMARY') ? " $OK<br />" : " $FAIL!<br />";
-    $aDebugMessage[] = '</div>';
-
-    if($bDebugModus) {
-    // $aDebugMessage[] =
-        echo implode(PHP_EOL,$aDebugMessage);
-    }
-}
-
-if(version_compare(WB_REVISION, REVISION, '<='))
-{
-    $aDebugMessage = array();
     echo '<h3>Step '.(++$stepID).': Updating group_id in table users</h3>';
     /**********************************************************
     * Updating group_id in table users
@@ -955,7 +881,7 @@
 			$msg = '<br /><br />Following files are deprecated, outdated or a security risk and
 				    can not be removed automatically.<br /><br />Please delete them
 					using FTP and restart upgrade-script!<br /><br />'.$msg.'<br />';
-	        status_msg($msg, 'error warning', 'div');
+			status_msg($msg, 'error warning', 'div');
 			echo '<p style="font-size:120%;"><strong>WARNING: The upgrade script failed ...</strong></p>';
 
 			echo '<form action="'.$_SERVER['SCRIPT_NAME'].'">';
@@ -968,7 +894,7 @@
 			</html>";
 			exit;
 		}
-    }
+	}
 
 
 	/**********************************************************
@@ -1039,7 +965,8 @@
 	 * upgrade modules if newer version is available
 	 * $aModuleList list of proofed modules
 	 */
-	$aModuleList = array('news','wysiwyg','form');
+//	$aModuleList = array('wysiwyg','news','form','captcha_control','output_filter');
+	$aModuleList = array('wysiwyg','form');
 	if(sizeof($aModuleList)) 
 	{
 	    echo '<h3>Step '.(++$stepID).': Upgrade proofed modules</h3>';
@@ -1097,9 +1024,9 @@
 	if( ($handle = opendir(WB_PATH.'/modules/')) ) {
 		while(false !== ($file = readdir($handle))) {
 			if($file != '' && substr($file, 0, 1) != '.' && is_dir(WB_PATH.'/modules/'.$file) ) {
-                $iFound++;
+				$iFound++;
 				$iLoaded = load_module(WB_PATH.'/modules/'.$file ) ? $iLoaded+1 : $iLoaded;
-			   // 	upgrade_module($file, true);
+// 	upgrade_module($file, true);
 			}
 		}
 		closedir($handle);
@@ -1106,8 +1033,8 @@
 	}
 	echo '<strong><span>'.$iLoaded.' Modules reloaded,</span> found '.$iFound.' directories in folder /modules/</strong><br />';
 
-    $iFound = 0;
-    $iLoaded = 0;
+	$iFound = 0;
+	$iLoaded = 0;
 	////delete templates
 	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'template'");
 	// Load all templates
@@ -1115,7 +1042,7 @@
 		while(false !== ($file = readdir($handle))) {
 			if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
 
-                $iFound++;
+				$iFound++;
 				$iLoaded = (load_template(WB_PATH.'/templates/'.$file)==true) ? $iLoaded+1 : $iLoaded;
 
 			}
@@ -1124,8 +1051,8 @@
 	}
 	echo '<strong><span>'.$iLoaded.' Templates reloaded,</span> found '.$iFound.' directories in folder /templates/</strong><br />';
 
-    $iFound = 0;
-    $iLoaded = 0;
+	$iFound = 0;
+	$iLoaded = 0;
 	////delete languages
 	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'language'");
 	// Load all languages
@@ -1132,7 +1059,7 @@
 	if( ($handle = opendir(WB_PATH.'/languages/')) ) {
 		while(false !== ($file = readdir($handle))) {
 			if($file != '' AND (preg_match('#^([A-Z]{2}.php)#', basename($file)))) {
-                $iFound++;
+				$iFound++;
 				$iLoaded = load_language(WB_PATH.'/languages/'.$file) ? $iLoaded+1 : $iLoaded;
 			}
 		}
@@ -1139,7 +1066,7 @@
 		closedir($handle);
 	}
 	echo '<strong><span>'.$iLoaded.' Languages reloaded,</span> found '.$iFound.' files in folder /languages/</strong><br />';
-    echo '</div>';
+	echo '</div>';
 
 /**********************************************************
  *  - install new droplets

Property changes on: branches/2.8.x/wb/upgrade-script.php
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: branches/2.8.x/wb/admin/pages/sections_save.php
===================================================================
--- branches/2.8.x/wb/admin/pages/sections_save.php	(revision 1888)
+++ branches/2.8.x/wb/admin/pages/sections_save.php	(revision 1889)
@@ -7,12 +7,12 @@
  * @author          Ryan Djurovich, WebsiteBaker Project
  * @copyright       2004-2009, Ryan Djurovich
  * @copyright       2009-2012, Website Baker Org. e.V.
- * @link			http://www.websitebaker2.org/
+ * @link            http://www.websitebaker2.org/
  * @license         http://www.gnu.org/licenses/gpl.html
  * @platform        WebsiteBaker 2.8.x
  * @requirements    PHP 5.2.2 and higher
  * @version         $Id$
- * @filesource		$HeadURL$
+ * @filesource      $HeadURL$
  * @lastmodified    $Date$
  *
  */
@@ -23,7 +23,9 @@
 require_once(WB_PATH."/include/jscalendar/jscalendar-functions.php");
 /**/
 // Create new admin object
-require_once(WB_PATH.'/framework/class.admin.php');
+if(!class_exists('admin')) {
+	require_once(WB_PATH.'/framework/class.admin.php');
+}
 // suppress to print the header, so no new FTAN will be set
 $admin = new admin('Pages', 'pages_modify',false);
 
@@ -32,72 +34,57 @@
 	$admin->send_header('Location: '.ADMIN_URL.'/pages/index.php');
 	exit(0);
 }
-
 // Get page id
-if(!isset($_GET['page_id']) || !is_numeric($_GET['page_id'])) {
+$iPageId = (isset($_GET['page_id']) ? intval($_GET['page_id']) : 0);
+if(!$iPageId) {
 	$admin->send_header("Location: index.php");
 	exit(0);
-} else {
-	$page_id = (int)$_GET['page_id'];
 }
-
-if (!$admin->checkFTAN())
-{
+if (!$admin->checkFTAN()) {
 	$admin->print_header();
-	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],ADMIN_URL.'/pages/sections.php?page_id='.$page_id);
+	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],ADMIN_URL.'/pages/sections.php?page_id='.$iPageId);
 }
-/*
-if( (!($page_id = $admin->checkIDKEY('page_id', 0, $_SERVER['REQUEST_METHOD']))) )
-{
-	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS']);
-	exit();
-}
-*/
 
 // After check print the header
 $admin->print_header();
+$sBackLink = ADMIN_URL.'/pages/sections.php?page_id='.$iPageId;
 
-$sBackLink = ADMIN_URL.'/pages/sections.php?page_id='.$page_id;
-
 // Get perms
 // Get page details
 $sql  = 'SELECT * FROM `'.TABLE_PREFIX.'pages` ';
-$sql .= 'WHERE page_id = '.$page_id.'';
-
-if($oPage = $database->query($sql)){
-    $results_array = $oPage->fetchRow();
-} else {
-	$admin->print_error($database->get_error());
-    $aMsg = array();
-    $aMsg[] = $MESSAGE['GENERIC_NOT_UPGRADED'];
-    if($results->numRows() == 0) {
+$sql .= 'WHERE `page_id`='.$iPageId;
+$aMsg = array();
+if(($oPage = $database->query($sql))) {
+    if(!$oPage->numRows()) {
     	$aMsg[] = $MESSAGE['PAGES_NOT_FOUND'];
-    }
+	}else {
+		if(!($aPage = $oPage->fetchRow())) {
+			$aMsg[] = $MESSAGE['PAGES_NOT_FOUND'];
+		}
+	}
+}else {
     if($database->is_error()) {
     	$aMsg[] = $database->get_error();
     }
+}
+if(sizeof($aMsg)>0) {
+    array_unshift($aMsg, $MESSAGE['GENERIC_NOT_UPGRADED']);
 	$admin->print_error(implode('<br />',$aMsg), $sBackLink );
+	exit;
 }
 
-$old_admin_users  = explode(',', $results_array['admin_users']);
-$old_admin_groups = explode(',', $results_array['admin_groups']);
-$in_old_group = false;
-foreach($admin->get_groups_id() as $cur_gid){
-    if (in_array($cur_gid, $old_admin_groups)) {
-        $in_old_group = TRUE;
-    }
+if(!$admin->ami_group_member($aPage['admin_users']) &&
+   !$admin->is_group_match($admin->get_groups_id(), $aPage['admin_groups']))
+{
+	$admin->print_error($MESSAGE['PAGES_INSUFFICIENT_PERMISSIONS'], $sBackLink);
 }
-if((!$in_old_group) && !is_numeric(array_search($admin->get_user_id(), $old_admin_users))) {
-	$admin->print_error($MESSAGE['PAGES_INSUFFICIENT_PERMISSIONS']);
-}
 
 // Set module permissions
-$module_permissions = $_SESSION['MODULE_PERMISSIONS'];
+// $module_permissions = $_SESSION['MODULE_PERMISSIONS'];
 $aMsg = array();
 $sql  = 'SELECT * FROM `'.TABLE_PREFIX.'sections` ';
-$sql .= 'WHERE page_id = '.$page_id.' ';
-$sql .= 'ORDER BY position ASC';
-
+$sql .= 'WHERE `page_id`='.$iPageId.' ';
+$sql .= 'ORDER BY `position` ASC';
 if(!($oSection = $database->query($sql))) {
     $aMsg = array();
     $aMsg[] = $MESSAGE['GENERIC_NOT_UPGRADED'];
@@ -105,48 +92,44 @@
     	$aMsg[] = $database->get_error();
     }
 	$admin->print_error(implode('<br />',$aMsg), $sBackLink );
+	exit;
 }
 
-$aSqlSection = array();
-// Loop through sections and set sql values for update
-while($section = $oSection->fetchRow(MYSQL_ASSOC)) {
-
-    $section_id  = $section['section_id'];
-    $sid = 'wb'.$section_id;
-
-    $dst = date('I') ? ' UTC' : ''; // daylight saving time? date('P')
-
-    $iBlock      = $admin->get_post_escaped('block'.$section_id);
-    $iBlock      = ($iBlock==null) ? $section['block'] : $iBlock;
-
-    $sStartDate  = $admin->get_post_escaped('start_date'.$section_id);;
-    $sStartDate  = ($sStartDate==null)||($sStartDate=='') ? 0 : jscalendar_to_timestamp($sStartDate)-TIMEZONE;
-
-    $sEndDate   = $admin->get_post_escaped('end_date'.$section_id);
-    $sEndDate   = ($sEndDate==null)||($sEndDate=='') ? 0 : jscalendar_to_timestamp($sEndDate)-TIMEZONE;
-
-    $aSqlSection[$sid][]  = 'UPDATE `'.TABLE_PREFIX.'sections` SET ';
-    $aSqlSection[$sid][] .= '`block`= \''.$iBlock.'\', ';
-    $aSqlSection[$sid][] .= '`module` = \''.$section['module'].'\', ';
-    $aSqlSection[$sid][] .= '`publ_start` = \''.$sStartDate.'\',';
-    $aSqlSection[$sid][] .= '`publ_end` = \''.$sEndDate.'\' ';
-    $aSqlSection[$sid][] .= 'WHERE `section_id` = \''.$section_id.'\' ';
+$aSql = array();
+// Loop through sections and build sql statements for update
+while($section = $oSection->fetchRow(MYSQL_ASSOC)) 
+{
+	$section_id  = $section['section_id'];
+	$sid = 'wb'.$section_id;
+	$dst = date('I') ? ' UTC' : ''; // daylight saving time? date('P')
+	$iBlock      = $admin->get_post_escaped('block'.$section_id);
+// be sure it's numeric, can failed if block is disabled
+	$iBlock      = (is_numeric($iBlock) ? $iBlock : $section['block']);
+//workout set block to default if you add a section
+	$iBlock      = ( ( $iBlock!==0 ) ? $iBlock : '1');
+	$sStartDate  = $admin->get_post_escaped('start_date'.$section_id);
+	$sStartDate  = ($sStartDate==null)||($sStartDate=='') ? 0 : jscalendar_to_timestamp($sStartDate)-TIMEZONE;
+	$sEndDate    = $admin->get_post_escaped('end_date'.$section_id);
+	$sEndDate    = ($sEndDate==null)||($sEndDate=='') ? 0 : jscalendar_to_timestamp($sEndDate)-TIMEZONE;
+	$aSql[]  = 'UPDATE `'.TABLE_PREFIX.'sections` '
+	         . 'SET `block`=\''.(int)$iBlock.'\', '
+	         .     '`module`=\''.$section['module'].'\', '
+	         .     '`publ_start`=\''.$sStartDate.'\','
+	         .     '`publ_end`=\''.$sEndDate.'\' '
+	         . 'WHERE `section_id`='.(int)$section_id;
 }
-
-foreach( $aSqlSection as $sid ) {
-
-    $sql = implode('',$sid);
-    if(!($oSection = $database->query($sql))) {
-        $aMsg = array();
-        $aMsg[] = $MESSAGE['GENERIC_NOT_UPGRADED'];
-        if($database->is_error()) {
-            $aMsg[] = $database->get_error();
-        }
-    $admin->print_error(implode('<br />',$aMsg), $sBackLink );
-    }
+// Update all of the sql statements
+foreach( $aSql as $sSql ) {
+	if(!$database->query($sSql)) {
+	    $aMsg = array();
+	    $aMsg[] = $MESSAGE['GENERIC_NOT_UPGRADED'];
+	    if($database->is_error()) {
+	        $aMsg[] = $database->get_error();
+	    }
+	$admin->print_error(implode('<br />',$aMsg), $sBackLink );
+	}
 }
 
 $admin->print_success($MESSAGE['PAGES_SECTIONS_PROPERTIES_SAVED'], $sBackLink );
-
 // Print admin footer
 $admin->print_footer();
Index: branches/2.8.x/wb/admin/pages/modify.php
===================================================================
--- branches/2.8.x/wb/admin/pages/modify.php	(revision 1888)
+++ branches/2.8.x/wb/admin/pages/modify.php	(revision 1889)
@@ -210,32 +210,26 @@
 		$section_id = $section['section_id'];
 		$module = $section['module'];
 		//Have permission?
-		if(!is_numeric(array_search($module, $module_permissions)))
-        {
+		if(!is_numeric(array_search($module, $module_permissions))) {
 			// Include the modules editing script if it exists
-			if(file_exists(WB_PATH.'/modules/'.$module.'/modify.php'))
-            {
+			if(file_exists(WB_PATH.'/modules/'.$module.'/modify.php')) {
 				print /* '<a name="'.$section_id.'"></a>'. */"\n";
 				// output block name if blocks are enabled
-				if (SECTION_BLOCKS) {
-					if (isset($block[$section['block']]) && trim(strip_tags(($block[$section['block']]))) != '')
-                    {
+//				if (SECTION_BLOCKS) {
+					if (isset($block[$section['block']]) && trim(strip_tags(($block[$section['block']]))) != '') {
 						$block_name = htmlentities(strip_tags($block[$section['block']]));
 					} else {
-						if ($section['block'] == 1)
-                        {
+						if ($section['block'] == 1) {
 							$block_name = $TEXT['MAIN'];
 						} else {
 							$block_name = '#' . (int) $section['block'];
 						}
 					}
-
-                    $sec_anchor = (defined( 'SEC_ANCHOR' ) && ( SEC_ANCHOR != '' )  ? 'id="'.SEC_ANCHOR.$section['section_id'].'"' : 'section_'.$section_id);
+					$sec_anchor = (defined( 'SEC_ANCHOR' ) && ( SEC_ANCHOR != '' )  ? 'id="'.SEC_ANCHOR.$section['section_id'].'"' : 'section_'.$section_id);
 					print '<div class="section-info" '.$sec_anchor.' ><b>' . $TEXT['BLOCK'] . ': </b>' . $block_name;
 					print '<b>  Modul: </b>' . $section['module']." ";
 					print '<b>  ID: </b>' . $section_id."</div>\n";
-
-				}
+//				}
 				require(WB_PATH.'/modules/'.$module.'/modify.php');
 			}
 		}
Index: branches/2.8.x/wb/admin/interface/version.php
===================================================================
--- branches/2.8.x/wb/admin/interface/version.php	(revision 1888)
+++ branches/2.8.x/wb/admin/interface/version.php	(revision 1889)
@@ -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', '1888');
+if(!defined('REVISION')) define('REVISION', '1889');
 if(!defined('SP')) define('SP', '');
Index: branches/2.8.x/wb/framework/WbDatabase.php
===================================================================
--- branches/2.8.x/wb/framework/WbDatabase.php	(revision 1888)
+++ branches/2.8.x/wb/framework/WbDatabase.php	(revision 1889)
@@ -41,7 +41,7 @@
 	private $_db_handle  = null; // readonly from outside
 	private $_db_name    = '';
 	protected $sTablePrefix = '';
-	protected $sCharset     = 'utf8';
+	protected $sCharset     = '';
 	protected $connected    = false;
 	protected $error        = '';
 	protected $error_type   = '';
@@ -489,7 +489,14 @@
 	// Run a query
 	function query($statement, $dbHandle) {
 		$this->_db_handle = $dbHandle;
-		$this->result = mysql_query($statement, $this->_db_handle);
+		$this->result = @mysql_query($statement, $this->_db_handle);
+		if($this->result === false) {
+			if(DEBUG) {
+				throw new WbDatabaseException(mysql_error($this->_db_handle));
+			}else{
+				throw new WbDatabaseException('Error in SQL-Statement');
+			}
+		}
 		$this->error = mysql_error($this->_db_handle);
 		return $this->result;
 	}
Index: branches/2.8.x/wb/framework/initialize.php
===================================================================
--- branches/2.8.x/wb/framework/initialize.php	(revision 1888)
+++ branches/2.8.x/wb/framework/initialize.php	(revision 1889)
@@ -142,7 +142,7 @@
 			$db['port'] = isset($db['port']) ? $db['port'] : '3306';
 			$db['port'] = ($db['port'] != '3306') ? $db['port'] : '';
 			$db['name'] = isset($db['name']) ? $db['name'] : 'dummy';
-			$db['charset'] = isset($db['charset']) ? $db['charset'] : 'utf8';
+			$db['charset'] = isset($db['charset']) ? trim($db['charset']) : '';
 			$db['table_prefix'] = (isset($db['table_prefix']) ? $db['table_prefix'] : '');
 			if(!defined('TABLE_PREFIX')) { define('TABLE_PREFIX', $db['table_prefix']); }
 			if($sRetvalType == 'dsn') {
Index: branches/2.8.x/wb/framework/class.wb.php
===================================================================
--- branches/2.8.x/wb/framework/class.wb.php	(revision 1888)
+++ branches/2.8.x/wb/framework/class.wb.php	(revision 1889)
@@ -86,12 +86,15 @@
      * @return array Associative array containing the different components
      * 
      */
-    public function mb_parse_url($url) {
-        $encodedUrl = preg_replace('%[^:/?#&=\.]+%usDe', 'urlencode(\'$0\')', $url);
-        $components = parse_url($encodedUrl);
-        foreach ($components as &$component)
-            $component = urldecode($component);
-        return $components;
+		public function mb_parse_url($url) {
+		$encodedUrl = preg_replace_callback('%[^:/?#&=\.]+%usD',
+		              create_function('$aMatches', ';return urlencode($aMatches[0]);'),
+/*		                           'urlencode(\'$0\')', */
+		                           $url);
+		$components = parse_url($encodedUrl);
+		foreach ($components as &$component)
+			$component = urldecode($component);
+return $components;
     }
 
 /* ****************
@@ -107,12 +110,10 @@
 	{
 		if( $groups_list1 == '' ) { return false; }
 		if( $groups_list2 == '' ) { return false; }
-		if( !is_array($groups_list1) )
-		{
+		if( !is_array($groups_list1) ) {
 			$groups_list1 = explode(',', $groups_list1);
 		}
-		if( !is_array($groups_list2) )
-		{
+		if( !is_array($groups_list2) ) {
 			$groups_list2 = explode(',', $groups_list2);
 		}
 		$matches = array_intersect( $groups_list1, $groups_list2);
Index: branches/2.8.x/wb/framework/UpgradeHelper.php
===================================================================
--- branches/2.8.x/wb/framework/UpgradeHelper.php	(nonexistent)
+++ branches/2.8.x/wb/framework/UpgradeHelper.php	(revision 1889)
@@ -0,0 +1,55 @@
+<?php
+
+/**
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * UpgradeHelper.php
+ *
+ * @category     Core
+ * @package      Core_Upgrade
+ * @copyright    Werner v.d.Decken <wkl@isteam.de>
+ * @author       Werner v.d.Decken <wkl@isteam.de>
+ * @license      http://www.gnu.org/licenses/gpl.html   GPL License
+ * @version      0.0.1
+ * @revision     $Revision: $
+ * @link         $HeadURL: $
+ * @lastmodified $Date: $
+ * @since        File available since 17.03.2013
+ * @description  some helper function for upgrade-script.php
+ */
+class UpgradeHelper {
+
+	public static function existsAllTables(array $aPackage)
+	{
+		$aPackage = array_flip($aPackage);
+		$oDb = WbDatabase::getInstance();
+		$sPattern = addcslashes ( $oDb->TablePrefix, '%_' );
+		if(($oTables = $oDb->query( 'SHOW TABLES LIKE "'.$sPattern.'%"'))) {
+			while($aTable = $oTables->fetchRow(MYSQL_NUM)) {
+				$sTable =  preg_replace('/^'.preg_quote($oDb->TablePrefix, '/').'/s', '', $aTable[0]);
+				if(isset($aPackage[$sTable])) {
+					unset($aPackage[$sTable]);
+				}
+			}
+		}
+		return array_flip($aPackage);
+	}
+
+
+} // end of class UpgradeHelper
+
Index: branches/2.8.x/wb/install/sql/websitebaker.sql
===================================================================
--- branches/2.8.x/wb/install/sql/websitebaker.sql	(revision 1888)
+++ branches/2.8.x/wb/install/sql/websitebaker.sql	(revision 1889)
@@ -83,9 +83,9 @@
   `page_id` int(11) NOT NULL DEFAULT '0',
   `position` int(11) NOT NULL DEFAULT '0',
   `module` varchar(255){TABLE_COLLATION} NOT NULL DEFAULT '',
-  `block` varchar(255){TABLE_COLLATION} NOT NULL DEFAULT '',
-  `publ_start` varchar(255){TABLE_COLLATION} NOT NULL DEFAULT '0',
-  `publ_end` varchar(255){TABLE_COLLATION} NOT NULL DEFAULT '0',
+  `block` int(11) NOT NULL DEFAULT '1',
+  `publ_start` int(11) NOT NULL DEFAULT '0',
+  `publ_end` int(11) NOT NULL DEFAULT '0',
   PRIMARY KEY (`section_id`)
 ) {TABLE_ENGINE};
 --
Index: branches/2.8.x/wb/modules/admin.php
===================================================================
--- branches/2.8.x/wb/modules/admin.php	(revision 1888)
+++ branches/2.8.x/wb/modules/admin.php	(revision 1889)
@@ -199,9 +199,8 @@
 	// unset($print_info_banner);
 	unset($template);
 
-	if (SECTION_BLOCKS) {
-		if (isset($block[$section['block']]) && trim(strip_tags(($block[$section['block']]))) != '')
-                 {
+//	if (SECTION_BLOCKS) {
+		if (isset($block[$section['block']]) && trim(strip_tags(($block[$section['block']]))) != '') {
 			$block_name = htmlentities(strip_tags($block[$section['block']]));
 		} else {
 			if ($section['block'] == 1) {
@@ -210,14 +209,12 @@
 				$block_name = '#' . (int) $section['block'];
 			}
 		}
-
-        $sec_anchor = '#'.(defined( 'SEC_ANCHOR' ) && ( SEC_ANCHOR != '' )  ? SEC_ANCHOR.$section_id : 'section_'.$section_id );
+		$sec_anchor = '#'.(defined( 'SEC_ANCHOR' ) && ( SEC_ANCHOR != '' )  ? SEC_ANCHOR.$section_id : 'section_'.$section_id );
 		//print '<div class="section-info" ><b>' . $TEXT['BLOCK'] . ': </b>' . $block_name;
 		print '<div class="section-info" '.$sec_anchor.' ><b>' . $TEXT['BLOCK'] . ': </b>' . $block_name;
 		print '<b>  Modul: </b>' . $section['module']." ";
 		print '<b>  ID: </b>' . $section_id."</div>\n";
-	}
-
+//	}
 } //
 
 // Work-out if the developer wants us to update the timestamp for when the page was last modified
