Index: branches/2.8.x/CHANGELOG
===================================================================
--- branches/2.8.x/CHANGELOG	(revision 1915)
+++ branches/2.8.x/CHANGELOG	(revision 1916)
@@ -12,6 +12,10 @@
 ===============================================================================
 
 
+07 Jun-2013 Build 1916 Dietmar Woellbrink (Luisehahne)
+! /modules/droplets/ set to version 1.3.0
+  installing module with sql import
+  make upgrade.php compatible with upgrade-scrip.php
 07 Jun-2013 Build 1915 Dietmar Woellbrink (Luisehahne)
 ! recoding /modules/code/add.php with exception
 07 Jun-2013 Build 1914 Dietmar Woellbrink (Luisehahne)
Index: branches/2.8.x/wb/admin/interface/version.php
===================================================================
--- branches/2.8.x/wb/admin/interface/version.php	(revision 1915)
+++ branches/2.8.x/wb/admin/interface/version.php	(revision 1916)
@@ -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', '1915');
+if(!defined('REVISION')) define('REVISION', '1916');
 if(!defined('SP')) define('SP', '');
Index: branches/2.8.x/wb/modules/droplets/info.php
===================================================================
--- branches/2.8.x/wb/modules/droplets/info.php	(revision 1915)
+++ branches/2.8.x/wb/modules/droplets/info.php	(revision 1916)
@@ -5,14 +5,13 @@
  * @package         droplet
  * @author          Ruud Eisinga (Ruud) John (PCWacht)
  * @author          WebsiteBaker Project
- * @copyright       2004-2009, Ryan Djurovich
- * @copyright       2009-2011, Website Baker Org. e.V.
- * @link			http://www.websitebaker2.org/
+ * @copyright       2009-2013, Website Baker Org. e.V.
+ * @link            http://www.websitebaker.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$
  *
  */
@@ -28,7 +27,7 @@
 $module_directory = 'droplets';
 $module_name = 'Droplets';
 $module_function = 'tool';
-$module_version = '1.2.0';
+$module_version = '1.3.0';
 $module_platform = '2.8.x';
 $module_author = 'Ruud and pcwacht';
 $module_license = 'GNU General Public License';
Index: branches/2.8.x/wb/modules/droplets/droplets.functions.php
===================================================================
--- branches/2.8.x/wb/modules/droplets/droplets.functions.php	(nonexistent)
+++ branches/2.8.x/wb/modules/droplets/droplets.functions.php	(revision 1916)
@@ -0,0 +1,169 @@
+<?php
+/**
+ *
+ * @category        module
+ * @package         droplet
+ * @author          Ruud Eisinga (Ruud) John (PCWacht)
+ * @author          WebsiteBaker Project
+ * @copyright       2009-2013, WebsiteBaker Org. e.V.
+ * @link            http://www.websitebaker.org/
+ * @license         http://www.gnu.org/licenses/gpl.html
+ * @platform        WebsiteBaker 2.8.x
+ * @requirements    PHP 5.2.2 and higher
+ * @version         $Id: upgrade.php 1717 2012-08-29 14:09:09Z Luisehahne $
+ * @filesource      $HeadURL: svn://isteam.dynxs.de/wb_svn/wb280/branches/2.8.x/wb/modules/droplets/upgrade.php $
+ * @lastmodified    $Date: 2012-08-29 16:09:09 +0200 (Mi, 29. Aug 2012) $
+ *
+ */
+/* -------------------------------------------------------- */
+// Must include code to stop this file being accessed directly
+if(!defined('WB_PATH')) {
+
+	require_once(dirname(dirname(dirname(__FILE__))).'/framework/globalExceptionHandler.php');
+	throw new IllegalFileException();
+}
+
+/* -------------------------------------------------------- */
+
+function prepareDropletToFile($aDroplet) {
+	$retVal = '';
+	$sDescription = '//:'.($aDroplet['description']!='') ? $aDroplet['description']: 'Desription';
+	$sComments = '';
+	$aComments = explode("\n",$aDroplet['comments']);
+	$sCode = '';
+	$aCode = explode("\n",$aDroplet['code']);
+	if( (sizeof($aComments)) ){
+		foreach($aComments AS $isComment) {
+			$sComments .= '//:'.$isComment;
+		}
+	} else {
+		$sComments .= '//:use [['.$aDroplet['name'].']]';
+	}
+	if( (sizeof($aCode)) ){
+		foreach($aCode AS $isCode) {
+			$sCode .= $isCode;
+		}
+	}
+ 
+	$retVal = $sDescription."\n".$sComments."\n".$sCode;
+	return $retVal;
+}
+// 
+function backupDropletFromDatabase($sTmpDir) {
+	$retVal = '';
+	$database=WbDatabase::getInstance();
+	$sql = 'SELECT `name`,`description`,`comments`,`code`  FROM `'.$database->TablePrefix.'mod_droplets` '
+	     . 'ORDER BY `modified_when` DESC';
+	if( $oRes = $database->query($sql) ) {
+		while($aDroplet = $oRes->fetchRow(MYSQL_ASSOC)) {
+			$sData = prepareDropletToFile($aDroplet);
+			$sFileName = $sTmpDir.$aDroplet['name'].'.php';
+			if(file_put_contents($sFileName,$sData)) {
+				$retVal .= $sFileName.',';
+			}
+		}
+		
+	}
+	return $retVal;
+}
+
+
+function insertDropletFile($aDropletFiles,&$msg,$bOverwriteDroplets,$admin)
+{
+	$OK  = ' <span style="color:#006400; font-weight:bold;">OK</span> ';
+	$FAIL = ' <span style="color:#ff0000; font-weight:bold;">FAILED</span> ';
+	$database=WbDatabase::getInstance();
+	foreach ($aDropletFiles as $sDropletFile) {
+		$msgSql = '';
+		$extraSql = '';
+		$sDropletName = pathinfo ($sDropletFile, PATHINFO_FILENAME);
+		$sql = 'SELECT `code` FROM `'.$database->TablePrefix.'mod_droplets` WHERE `name` LIKE "'.$sDropletName.'" ';
+		if( !($database->get_one($sql)) ) {
+			$sql = 'INSERT INTO `'.$database->TablePrefix.'mod_droplets`';
+			$msgSql = 'INSERT Droplet `'.$sDropletName.'` INTO`'.$database->TablePrefix.'mod_droplets`'." $OK";
+		} elseif ($bOverwriteDroplets) {
+			$sql = 'UPDATE `'.$database->TablePrefix.'mod_droplets` ';
+			$extraSql = 'WHERE `name` = \''.$sDropletName.'\' ';
+			$msgSql = 'UPDATE Droplet `'.$sDropletName.'` INTO`'.$database->TablePrefix.'mod_droplets`'." $OK";
+		}
+// get description, comments and oode
+		$sDropletFile = preg_replace('/^\xEF\xBB\xBF/', '', $sDropletFile);
+		if( ($msgSql!='') && ($aFileData = file($sDropletFile)) ) {
+			$bDescription = false;
+			$bComments = false;
+			$bCode = false;
+			$sDescription = '';
+			$sComments = '';
+			$sCode = '';
+			$sPattern = "#//:#im";
+			while ( sizeof($aFileData) > 0 ) {
+				$sSqlLine = trim(array_shift($aFileData));
+				$isNotCode = (bool)preg_match($sPattern, $sSqlLine);
+				if( $isNotCode==true ) {
+// first step line is description
+					if($bDescription==false) {
+						$sDescription .= str_replace('//:','',$sSqlLine);
+						$bDescription = true;
+					} else {
+// second step fill comments
+						$sComments .= str_replace('//:','',$sSqlLine).PHP_EOL;
+					}
+				} else {
+// third step fill code
+					$sCode .= str_replace('//:','',$sSqlLine).PHP_EOL;
+				}
+			}
+		$iModifiedWhen = time();
+		$iModifiedBy = (method_exists($admin, 'get_user_id') && ($admin->get_user_id()!=null) ? $admin->get_user_id() : 1);
+		$sql .= 'SET  `name` =\''.$sDropletName.'\','
+		     .       '`description` =\''.$sDescription.'\','
+		     .       '`comments` =\''.$sComments.'\','
+		     .       '`code` =\''.$database->escapeString($sCode).'\','
+		     .       '`modified_when` = '.$iModifiedWhen.','
+		     .       '`modified_by` = '.$iModifiedBy.','
+		     .       '`active` = 1'
+		     .       $extraSql;
+		}
+		if( $database->query($sql) ) {
+			if( $msgSql!='' ) { $msg[] = $msgSql; }
+		} else {
+			$msg[] = $database->get_error();
+		}
+	}
+	return;
+}
+/* -------------------------------------------------------- */
+
+function isDropletFile($sFileName)
+{
+	$bRetval = false;
+	$matches = array();
+	if(($sFileData = file_get_contents($sFileName)) !== false)
+	{
+//		$sPattern = "#(?://:)+[\w]*\w?#is";
+//		$sPattern = "#//:[\w].+#imS";
+		$sPattern = "#//:#im";
+		$bRetval = (bool)preg_match_all($sPattern, $sFileData, $matches, PREG_SET_ORDER);
+	}
+	return $bRetval;
+}
+
+/* -------------------------------------------------------- */
+	function getDropletFromFiles($sBaseDir)
+	{
+		$aRetval = array();
+		$oIterator = new DirectoryIterator($sBaseDir);
+		foreach ($oIterator as $fileInfo) {
+		// iterate the directory
+			if($fileInfo->isDot()) continue;
+			$sFileName = rtrim(str_replace('\\', '/', $fileInfo->getPathname()), '/');
+			if($fileInfo->isFile()) {
+			// only droplets are interesting
+				if((file_exists($sFileName) && isDropletFile($sFileName))) {
+				// if dir has no corresponding accessfile remember it
+					$aRetval[] = $sFileName;
+				}
+			}
+		}
+		return $aRetval;
+	}
Index: branches/2.8.x/wb/modules/droplets/install.php
===================================================================
--- branches/2.8.x/wb/modules/droplets/install.php	(revision 1915)
+++ branches/2.8.x/wb/modules/droplets/install.php	(revision 1916)
@@ -5,14 +5,13 @@
  * @package         droplet
  * @author          Ruud Eisinga (Ruud) John (PCWacht)
  * @author          WebsiteBaker Project
- * @copyright       2004-2009, Ryan Djurovich
- * @copyright       2009-2011, Website Baker Org. e.V.
- * @link			http://www.websitebaker2.org/
+ * @copyright       2009-2013, WebsiteBaker Org. e.V.
+ * @link            http://www.websitebaker.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$
  *
  */
@@ -19,95 +18,20 @@
 /* -------------------------------------------------------- */
 // Must include code to stop this file being accessed directly
 if(!defined('WB_PATH')) {
-
 	require_once(dirname(dirname(dirname(__FILE__))).'/framework/globalExceptionHandler.php');
 	throw new IllegalFileException();
-}
-/* -------------------------------------------------------- */
-
-	// global $admin;
-
+} else {
+	if(!function_exists('insertDropletFile')) { require('droplets.functions.php'); }
+	$database = WbDatabase::getInstance();
+	$sError = '';
 	$msg = array();
-	$sql  = 'DROP TABLE IF EXISTS `'.TABLE_PREFIX.'mod_droplets` ';
-	if( !$database->query($sql) ) {
-		$msg[] = $database->get_error();
+	$sBaseDir = realpath(dirname(__FILE__).'/example/');
+	$sBaseDir    = rtrim(str_replace('\\', '/', $sBaseDir), '/').'/';
+	// Create table
+	if($database->SqlImport(dirname(__FILE__).'/sql/mod_droplet.sql','',false)){
+		$aDropletFiles = getDropletFromFiles($sBaseDir);
+		$bOverwriteDroplets = true;
+		insertDropletFile($aDropletFiles,$msg,$bOverwriteDroplets,$admin);
 	}
 
-	$sql  = 'CREATE TABLE IF NOT EXISTS `'.TABLE_PREFIX.'mod_droplets` ( ';
-	$sql .= '`id` INT NOT NULL auto_increment, ';
-	$sql .= '`name` VARCHAR(32) CHARACTER SET utf8 COLLATE utf8_unicode_ci  NOT NULL, ';
-	$sql .= '`code` LONGTEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci  NOT NULL , ';
-	$sql .= '`description` TEXT  CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, ';
-	$sql .= '`modified_when` INT NOT NULL default \'0\', ';
-	$sql .= '`modified_by` INT NOT NULL default \'0\', ';
-	$sql .= '`active` INT NOT NULL default \'0\', ';
-	$sql .= '`admin_edit` INT NOT NULL default \'0\', ';
-	$sql .= '`admin_view` INT NOT NULL default \'0\', ';
-	$sql .= '`show_wysiwyg` INT NOT NULL default \'0\', ';
-	$sql .= '`comments` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci  NOT NULL, ';
-	$sql .= 'PRIMARY KEY ( `id` ) ';
-	$sql .= ') ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci';
-	if( !$database->query($sql) ) {
-		$msg[] = $database->get_error();
-	}
-
-	//add all droplets from the droplet subdirectory
-	$folder=opendir(WB_PATH.'/modules/droplets/example/.');
-	$names = array();
-	while ($file = readdir($folder)) {
-		$ext=strtolower(substr($file,-4));
-		if ($ext==".php"){
-			if ($file<>"index.php" ) {
-				$names[count($names)] = $file;
-			}
-		}
-	}
-	closedir($folder);
-
-	foreach ($names as $dropfile)
-	{
-		$droplet = addslashes(getDropletCodeFromFile($dropfile));
-		if ($droplet != "")
-		{
-			$description = "Example Droplet";
-			$comments = "Example Droplet";
-			$cArray = explode("\n",$droplet);
-			if (substr($cArray[0],0,3) == "//:") {
-				$description = trim(substr($cArray[0],3));
-				array_shift ( $cArray );
-			}
-			if (substr($cArray[0],0,3) == "//:") {
-				$comments = trim(substr($cArray[0],3));
-				array_shift ( $cArray );
-			}
-			$droplet = implode ( "\n", $cArray );
-			$name = substr($dropfile,0,-4);
-			$modified_when = time();
-			$modified_by = (method_exists($admin, 'get_user_id') && ($admin->get_user_id()!=null) ? $admin->get_user_id() : 1);
-			$sql  = 'INSERT INTO `'.TABLE_PREFIX.'mod_droplets` SET ';
-			$sql .= '`name` = \''.$name.'\', ';
-			$sql .= '`code` = \''.$droplet.'\', ';
-			$sql .= '`description` = \''.$description.'\', ';
-			$sql .= '`comments` = \''.$comments.'\', ';
-			$sql .= '`active` = 1, ';
-			$sql .= '`modified_when` = '.$modified_when.', ';
-			$sql .= '`modified_by` = '.$modified_by;
-			if( !$database->query($sql) ) {
-				$msg[] = $database->get_error();
-			}
-			// do not output anything if this script is called during fresh installation
-			// if (method_exists($admin, 'get_user_id')) echo "Droplet import: $name<br/>";
-		}
-	}
-
-	function getDropletCodeFromFile ( $dropletfile ) {
-		$data = '';
-		$filename = WB_PATH."/modules/droplets/example/".$dropletfile;
-		if (file_exists($filename)) {
-			$filehandle = fopen ($filename, "r");
-			$data = fread ($filehandle, filesize ($filename));
-			fclose($filehandle);
-			// unlink($filename); doesnt work in unix
-		}
-		return $data;
-	}
+}
Index: branches/2.8.x/wb/modules/droplets/sql/mod_droplet.sql
===================================================================
--- branches/2.8.x/wb/modules/droplets/sql/mod_droplet.sql	(nonexistent)
+++ branches/2.8.x/wb/modules/droplets/sql/mod_droplet.sql	(revision 1916)
@@ -0,0 +1,30 @@
+-- phpMyAdmin SQL Dump
+-- Erstellungszeit: 15. Mrz 2013 um 18:21
+-- Server-Version: 5.5.27
+--
+SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
+-- --------------------------------------------------------
+-- Database structure for WebsiteBaker core
+--
+-- Replacements: {TABLE_PREFIX}, {TABLE_ENGINE}, {TABLE_COLLATION}
+--
+-- --------------------------------------------------------
+--
+-- Tabellenstruktur für Tabelle `{TABLE_PREFIX}mod_droplets`
+--
+DROP TABLE IF EXISTS `{TABLE_PREFIX}mod_droplets`;
+CREATE TABLE IF NOT EXISTS `{TABLE_PREFIX}mod_droplets` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `name` varchar(32){TABLE_COLLATION} NOT NULL DEFAULT '',
+  `code` longtext{TABLE_COLLATION} NOT NULL DEFAULT '',
+  `description` text{TABLE_COLLATION} NOT NULL DEFAULT '',
+  `modified_when` int(11) NOT NULL DEFAULT '0',
+  `modified_by` int(11) NOT NULL DEFAULT '0',
+  `active` int(11) NOT NULL DEFAULT '0',
+  `admin_edit` int(11) NOT NULL DEFAULT '0',
+  `admin_view` int(11) NOT NULL DEFAULT '0',
+  `show_wysiwyg` int(11) NOT NULL DEFAULT '0',
+  `comments` text{TABLE_COLLATION} NOT NULL DEFAULT '',
+  PRIMARY KEY (`id`)
+){TABLE_ENGINE};
+-- EndOfFile
\ No newline at end of file
Index: branches/2.8.x/wb/modules/droplets/backup_droplets.php
===================================================================
--- branches/2.8.x/wb/modules/droplets/backup_droplets.php	(revision 1915)
+++ branches/2.8.x/wb/modules/droplets/backup_droplets.php	(revision 1916)
@@ -4,13 +4,13 @@
  * @category        module
  * @package         droplet
  * @author          Ruud Eisinga (Ruud) John (PCWacht), WebsiteBaker Project
- * @copyright       2009-2012, WebsiteBaker Org. e.V.
- * @link			http://www.websitebaker.org/
+ * @copyright       2009-2013, WebsiteBaker Org. e.V.
+ * @link            http://www.websitebaker.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$
  *
  */
@@ -20,6 +20,7 @@
 // tool_edit.php
 require_once('../../config.php');
 require_once(WB_PATH.'/framework/class.admin.php');
+if(!function_exists('insertDropletFile')) { require('droplets.functions.php'); }
 
 require_once(WB_PATH.'/framework/functions.php');
 // create admin object depending on platform (admin tools were moved out of settings with WB 2.7)
@@ -46,61 +47,40 @@
 $OK  = ' <span style="color:#006400; font-weight:bold;">OK</span> ';
 $FAIL = ' <span style="color:#ff0000; font-weight:bold;">FAILED</span> ';
 $sBackupName = strftime('%Y%m%d_%H%M%S', time()+ TIMEZONE ).'_droplets.zip';
-$temp_dir = '/temp/droplets/';
-$temp_file = $temp_dir.$sBackupName;
-
-if(is_writeable(dirname(WB_PATH.$temp_dir))) {
- 	rm_full_dir ( WB_PATH.$temp_dir );
+$tempDir = '/temp/droplets/';
+$tempFile = $tempDir.$sBackupName;
+// delete old backup
+if(is_writeable(dirname(WB_PATH.$tempDir))) {
+	rm_full_dir ( WB_PATH.$tempDir );
 }
 
-/*
-// make the temporary working directory
-if(!make_dir(WB_PATH.$temp_dir, octdec('0777') )){
-//  $admin->print_error($MESSAGE['MEDIA_DIR_NOT_MADE'], $module_edit_link);
-}
-*/
-
-$msg = createFolderProtectFile(rtrim( WB_PATH.$temp_dir,'/') );
+$msg = createFolderProtectFile(rtrim( WB_PATH.$tempDir,'/') );
 if(sizeof($msg)) {
 	print '<h4 class="warning">';
 	echo implode('<br />',$msg).'<br />'.$MESSAGE['MEDIA_DIR_NOT_MADE'].'<br />';
 	print '</h4>';
 }
-
-	$sFilesToZip = '';
-	$sql  = 'SELECT * FROM `'.TABLE_PREFIX.'mod_droplets`  ';
-	$sql .= 'ORDER BY `modified_when` DESC';
-
-	$query_droplets = $database->query($sql);
-	while($droplet = $query_droplets->fetchRow()) {
-		echo 'Saving: '.$droplet["name"].'.php';
-		$sFile = $droplet["name"].'.php';
-		if($fh = fopen(WB_PATH.$temp_dir.$sFile, 'w'))
-		{
-			fwrite($fh, '//:'.$droplet['description']."\n");
-			fwrite($fh, '//:'.str_replace("\n"," ",$droplet['comments'])."\n");
-			fwrite($fh, $droplet['code']);
-			fclose($fh);
-			echo " $OK<br />";
-		} else {
-			echo " $FAIL<br />";		}
-	$sFilesToZip .= WB_PATH.$temp_dir.$sFile.',';
-	}
-
+$sFilesToZip = backupDropletFromDatabase(WB_PATH.$tempDir);
+// remove last comma
 $sFilesToZip = rtrim($sFilesToZip,',');
 
 echo '<br />Create archive: <strong>'.$sBackupName.'</strong><br />';
 
-require_once(WB_PATH.'/include/pclzip/pclzip.lib.php');
-$archive = new PclZip(WB_PATH.$temp_file);
+if( !class_exists('PclZip',false) ) { require(WB_PATH.'/include/pclzip/pclzip.lib.php'); }
+$archive = new PclZip(WB_PATH.$tempFile);
 
-$file_list = $archive->create($sFilesToZip , PCLZIP_OPT_REMOVE_ALL_PATH );
-if ($file_list == 0){
+$archiveList = $archive->create($sFilesToZip , PCLZIP_OPT_REMOVE_ALL_PATH );
+
+if ($archiveList == 0){
 	echo "Packaging error: '.$archive->errorInfo(true).'";
 	die("Error : ".$archive->errorInfo(true));
 }
-elseif(is_readable(WB_PATH.$temp_file)) {
-	echo '<br /><br />Backup created - <a href="'.WB_URL.$temp_file.'">Download</a>';
+elseif(is_readable(WB_PATH.$tempFile)) {
+	echo '<br /><ol>';
+	foreach($archiveList AS $key=>$aDroplet ) {
+		echo '<li>Backup <strong> '.$aDroplet['stored_filename'].'</strong></li>';
+	}
+	echo '</ol><br /><br />Backup created - <a href="'.WB_URL.$tempFile.'">Download</a>';
 }
 else {
 	echo '<br /><br />Backup not created - <a href="'.$module_edit_link.'">'.$TEXT['BACK'].'</a>';
Index: branches/2.8.x/wb/modules/droplets/upgrade.php
===================================================================
--- branches/2.8.x/wb/modules/droplets/upgrade.php	(revision 1915)
+++ branches/2.8.x/wb/modules/droplets/upgrade.php	(revision 1916)
@@ -5,14 +5,13 @@
  * @package         droplet
  * @author          Ruud Eisinga (Ruud) John (PCWacht)
  * @author          WebsiteBaker Project
- * @copyright       2004-2009, Ryan Djurovich
- * @copyright       2009-2011, Website Baker Org. e.V.
- * @link			http://www.websitebaker2.org/
+ * @copyright       2009-2013, WebsiteBaker Org. e.V.
+ * @link            http://www.websitebaker.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$
  *
  */
@@ -24,9 +23,91 @@
 	throw new IllegalFileException();
 }
 /* -------------------------------------------------------- */
-$database=WbDatabase::getInstance();
-$table_name = TABLE_PREFIX .'mod_droplets';
-$description = 'INT NOT NULL default 0 ';
-$database->field_add($table_name,'show_wysiwyg',$description.'AFTER `active`' );
-$database->field_add($table_name,'admin_view',$description.'AFTER `active`' );
-$database->field_add($table_name,'admin_edit',$description.'AFTER `active`' );
+
+if(!function_exists('insertDropletFile')) { require('droplets.functions.php'); }
+
+	function mod_droplets_upgrade($bDebug=false) {
+		global $admin;
+		$OK  = ' <span style="color:#006400; font-weight:bold;">OK</span> ';
+		$FAIL = ' <span style="color:#ff0000; font-weight:bold;">FAILED</span> ';
+		$database=WbDatabase::getInstance();
+		$msg = array();
+		$callingScript = $_SERVER["SCRIPT_NAME"];
+		// check if upgrade startet by upgrade-script to echo a message
+		$tmp = 'upgrade-script.php';
+		$globalStarted = substr_compare($callingScript, $tmp,(0-strlen($tmp)),strlen($tmp)) === 0;
+// check for missing tables, if true stop the upgrade
+		$aTable = array('mod_droplets');
+		$aPackage = UpgradeHelper::existsAllTables($aTable);
+		if( sizeof($aPackage) > 0){
+			$msg[] =  'TABLE '.implode(' missing! '.$FAIL.'<br />TABLE ',$aPackage).' missing! '.$FAIL;
+			$msg[] = 'Droplets upgrade failed'." $FAIL";
+			if($globalStarted) {
+				echo '<strong>'.implode('<br />',$msg).'</strong><br />';
+			}
+			return ( ($globalStarted==true ) ? $globalStarted : $msg);
+		} else {
+			for($x=0; $x<sizeof($aTable);$x++) {
+				if(($sOldType = $database->getTableEngine($database->TablePrefix.$aTable[$x]))) {
+					if(('myisam' != strtolower($sOldType))) {
+						if(!$database->query('ALTER TABLE `'.$database->TablePrefix.$aTable[$x].'` Engine = \'MyISAM\' ')) {
+							$msg[] = $database->get_error();
+						} else{
+							$msg[] = 'TABLE `'.$database->TablePrefix.$aTable[$x].'` changed to Engine = \'MyISAM\''." $OK";
+						}
+					} else {
+						$msg[] = 'TABLE `'.$database->TablePrefix.$aTable[$x].'` has Engine = \'MyISAM\''." $OK";
+					}
+				} else {
+					$msg[] = $database->get_error();
+				}
+			}
+			$table_name = $database->TablePrefix.'mod_droplets';
+			$description = "INT NOT NULL DEFAULT '0' AFTER `active`";
+			$field_name = 'show_wysiwyg';
+			if(!$database->field_exists($table_name,$field_name)) {
+				$database->field_add($table_name, $field_name, $description);
+				$msg[] = 'Add field `show_wysiwyg` AFTER `active`';
+			} else {
+				$msg[] = 'Field `show_wysiwyg` already exists'." $OK";
+			}
+			$field_name = 'admin_view';
+			if(!$database->field_exists($table_name,$field_name)) {
+				$database->field_add($table_name, $field_name, $description);
+				$msg[] = 'Add field `admin_view` AFTER `active`';
+			} else {
+				$msg[] = 'Field `admin_view` already exists'." $OK";
+			}
+			$field_name = 'admin_edit';
+			if(!$database->field_exists($table_name,$field_name)) {
+				$database->field_add($table_name, $field_name, $description);
+				$msg[] = 'Add field `admin_edit` AFTER `active`';
+			} else {
+				$msg[] = 'Field `admin_edit` already exists'." $OK";
+			}
+
+			$sBaseDir = realpath(dirname(__FILE__).'/example/');
+			$sBaseDir    = rtrim(str_replace('\\', '/', $sBaseDir), '/').'/';
+			$aDropletFiles = getDropletFromFiles($sBaseDir);
+
+			$bOverwriteDroplets = false;
+			insertDropletFile($aDropletFiles,$msg,$bOverwriteDroplets,$admin);
+// only for upgrade-script
+			if($globalStarted) {
+				if($bDebug) {
+					echo '<strong>'.implode('<br />',$msg).'</strong><br />';
+				}
+			}
+		}
+		$msg[] = 'Droplets upgrade successfull finished ';
+		if($globalStarted) {
+			echo "<strong>Droplets upgrade successfull finished $OK</strong><br />";
+		}
+		return ( ($globalStarted==true ) ? $globalStarted : $msg);
+	}
+// ------------------------------------
+
+$bDebugModus = ((isset($bDebugModus)) ? $bDebugModus : false);
+if( is_array($msg = mod_droplets_upgrade($bDebugModus))) {
+	echo '<strong>'.implode('<br />',$msg).'</strong><br />';
+}
