Project

General

Profile

1
<?php
2
/**
3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
 *
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18

    
19
/**
20
 * 
21
 * 
22
 * @category     Module
23
 * @package      Module_bakery
24
 * @subpackage   Name of the subpackage if needed
25
 * @author       Dietmar W?llbrink <dietmar.woellbrink@websitebaker.org>
26
 * @author       Werner v.d.Decken <wkl@isteam.de>
27
 * @copyright    Werner v.d.Decken <wkl@isteam.de>
28
 * @license      http://www.gnu.org/licenses/gpl.html   GPL License
29
 * @version      0.0.1
30
 * @revision     $Revision: 1870 $
31
 * @link         $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/upgrade-script.php $
32
 * @lastmodified $Date: 2013-02-21 19:07:57 +0100 (Thu, 21 Feb 2013) $
33
 * @since        File available since 17.01.2013
34
 * @deprecated   
35
 * @description  xyz
36
 */
37
// Include config file
38
$config_file = realpath('config.php');
39
if(file_exists($config_file) && !defined('WB_URL'))
40
{
41
	require($config_file);
42

    
43
}
44
// solved wrong pages_directory value before creating access files
45
$sql  = 'SELECT `value` FROM `'.TABLE_PREFIX.'settings` ';
46
$sql .= 'WHERE `name`=\'pages_directory\' ';
47
$sTmpDir = WbDatabase::getInstance()->get_one($sql);
48
$sTmpDir = ( (strpos($sTmpDir,'/',0)===false) && (strlen($sTmpDir)>1)  ? '/'.$sTmpDir : rtrim($sTmpDir,'/') );
49
$sPagesDir = defined('PAGES_DIRECTORY') ? PAGES_DIRECTORY : '';
50
if(($sTmpDir != $sPagesDir)) {
51
	$sql = 'UPDATE `'.TABLE_PREFIX.'settings` SET '
52
		.  '`value` = \''.$sTmpDir.'\' '
53
		.  'WHERE `name`=\'pages_directory\' ';
54
	if(!WbDatabase::getInstance()->query($sql) ) {}
55
}
56
//require_once(WB_PATH.'/framework/class.admin.php');
57
if(!class_exists('admin', false)){ include(WB_PATH.'/framework/class.admin.php'); }
58
require_once(WB_PATH.'/framework/functions.php');
59
// require_once(WB_PATH.'/framework/Database.php');
60
$admin = new admin('Addons', 'modules', false, false);
61

    
62
$oldVersion  = 'Version '.WB_VERSION;
63
$oldVersion .= (defined('WB_SP') ? WB_SP : '');
64
$oldRevision = (defined('WB_REVISION') ? ' Revision ['.WB_REVISION.'] ' : '') ;
65
$newVersion  = 'Version '.VERSION;
66
$newVersion .= (defined('SP') ? SP : '');
67
$newRevision = (defined('REVISION') ? ' Revision ['.REVISION.'] ' : '');
68

    
69
$bDebugModus = false;
70

    
71
// set addition settings if not exists, otherwise upgrade will be breaks
72
if(!defined('WB_SP')) { define('WB_SP',''); }
73
if(!defined('WB_REVISION')) { define('WB_REVISION',''); }
74
// database tables including in WB package
75
$aPackage = array (
76
    'settings','groups','addons','pages','sections','search','users',
77
    'mod_captcha_control','mod_code','mod_droplets',
78
    'mod_jsadmin','mod_menu_link','mod_output_filter','mod_wrapper','mod_wysiwyg',
79
//    'mod_form_fields','mod_form_settings','mod_form_submissions',
80
//    'mod_news_comments','mod_news_groups','mod_news_posts','mod_news_settings',
81
);
82

    
83
$OK            = ' <span class="ok">OK</span> ';
84
$FAIL          = ' <span class="error">FAILED</span> ';
85
$DEFAULT_THEME = 'wb_theme';
86

    
87
$stepID = 0;
88
$aFilesToRemove = array();
89
$dirRemove = array(
90
/*
91
			'[TEMPLATE]/allcss/',
92
			'[TEMPLATE]/blank/',
93
			'[TEMPLATE]/round/',
94
			'[TEMPLATE]/simple/',
95
*/
96
			'[ADMIN]/themes/',
97
		 );
98
//
99
	$filesRemove['0'] = array(
100

    
101
			'[ADMIN]/preferences/details.php',
102
			'[ADMIN]/preferences/email.php',
103
			'[ADMIN]/preferences/password.php',
104
			'[ADMIN]/pages/settings2.php',
105
			'[ADMIN]/users/users.php',
106
			'[ADMIN]/skel/themes/htt/groups.htt',
107

    
108
			'[FRAMEWORK]/class.msg_queue.php',
109
			'[FRAMEWORK]/class.logfile.php',
110
			'[MODULES]/droplets/js/mdcr.js',
111

    
112
		 );
113
	$aFilesToRemove = array_merge($filesRemove['0']);
114

    
115
// deleting files below only from less 2.8.4 stable
116
if(version_compare(WB_REVISION, REVISION, '<='))
117
{
118
	$filesRemove['1'] = array(
119

    
120
			'[TEMPLATE]/argos_theme/templates/access.htt',
121
			'[TEMPLATE]/argos_theme/templates/addons.htt',
122
			'[TEMPLATE]/argos_theme/templates/admintools.htt',
123
			'[TEMPLATE]/argos_theme/templates/error.htt',
124
			'[TEMPLATE]/argos_theme/templates/groups.htt',
125
			'[TEMPLATE]/argos_theme/templates/groups_form.htt',
126
			'[TEMPLATE]/argos_theme/templates/languages.htt',
127
			'[TEMPLATE]/argos_theme/templates/languages_details.htt',
128
			'[TEMPLATE]/argos_theme/templates/login.htt',
129
			'[TEMPLATE]/argos_theme/templates/login_forgot.htt',
130
			'[TEMPLATE]/argos_theme/templates/media.htt',
131
			'[TEMPLATE]/argos_theme/templates/media_browse.htt',
132
			'[TEMPLATE]/argos_theme/templates/media_rename.htt',
133
			'[TEMPLATE]/argos_theme/templates/modules.htt',
134
			'[TEMPLATE]/argos_theme/templates/modules_details.htt',
135
			'[TEMPLATE]/argos_theme/templates/pages.htt',
136
			'[TEMPLATE]/argos_theme/templates/pages_modify.htt',
137
			'[TEMPLATE]/argos_theme/templates/pages_sections.htt',
138
			'[TEMPLATE]/argos_theme/templates/pages_settings.htt',
139
			'[TEMPLATE]/argos_theme/templates/preferences.htt',
140
			'[TEMPLATE]/argos_theme/templates/setparameter.htt',
141
			'[TEMPLATE]/argos_theme/templates/settings.htt',
142
			'[TEMPLATE]/argos_theme/templates/start.htt',
143
			'[TEMPLATE]/argos_theme/templates/success.htt',
144
			'[TEMPLATE]/argos_theme/templates/templates.htt',
145
			'[TEMPLATE]/argos_theme/templates/templates_details.htt',
146
			'[TEMPLATE]/argos_theme/templates/users.htt',
147
			'[TEMPLATE]/argos_theme/templates/users_form.htt',
148

    
149
			'[TEMPLATE]/wb_theme/templates/access.htt',
150
			'[TEMPLATE]/wb_theme/templates/addons.htt',
151
			'[TEMPLATE]/wb_theme/templates/admintools.htt',
152
			'[TEMPLATE]/wb_theme/templates/error.htt',
153
			'[TEMPLATE]/wb_theme/templates/groups.htt',
154
			'[TEMPLATE]/wb_theme/templates/groups_form.htt',
155
			'[TEMPLATE]/wb_theme/templates/languages.htt',
156
			'[TEMPLATE]/wb_theme/templates/languages_details.htt',
157
			'[TEMPLATE]/wb_theme/templates/login.htt',
158
			'[TEMPLATE]/wb_theme/templates/login_forgot.htt',
159
			'[TEMPLATE]/wb_theme/templates/media.htt',
160
			'[TEMPLATE]/wb_theme/templates/media_browse.htt',
161
			'[TEMPLATE]/wb_theme/templates/media_rename.htt',
162
			'[TEMPLATE]/wb_theme/templates/modules.htt',
163
			'[TEMPLATE]/wb_theme/templates/modules_details.htt',
164
			'[TEMPLATE]/wb_theme/templates/pages.htt',
165
			'[TEMPLATE]/wb_theme/templates/pages_modify.htt',
166
			'[TEMPLATE]/wb_theme/templates/pages_sections.htt',
167
			'[TEMPLATE]/wb_theme/templates/pages_settings.htt',
168
			'[TEMPLATE]/wb_theme/templates/preferences.htt',
169
			'[TEMPLATE]/wb_theme/templates/setparameter.htt',
170
			'[TEMPLATE]/wb_theme/templates/settings.htt',
171
			'[TEMPLATE]/wb_theme/templates/start.htt',
172
			'[TEMPLATE]/wb_theme/templates/success.htt',
173
			'[TEMPLATE]/wb_theme/templates/templates.htt',
174
			'[TEMPLATE]/wb_theme/templates/templates_details.htt',
175
			'[TEMPLATE]/wb_theme/templates/users.htt',
176
			'[TEMPLATE]/wb_theme/templates/users_form.htt'
177
		 );
178

    
179
	$aFilesToRemove = array_merge($aFilesToRemove,$filesRemove['1']);
180

    
181
}
182
/* display a status message on the screen **************************************
183
 * @param string $message: the message to show
184
 * @param string $class:   kind of message as a css-class
185
 * @param string $element: witch HTML-tag use to cover the message
186
 * @return void
187
 */
188
function status_msg($message, $class='check', $element='div')
189
{
190
	// returns a status message
191
	$msg  = '<'.$element.' class="'.$class.'">';
192
	$msg .= '<strong>'.strtoupper(strtok($class, ' ')).'</strong>';
193
	$msg .= $message.'</'.$element.'>';
194
	echo $msg;
195
}
196

    
197
/**
198
 * add_modify_field_in_database()
199
 *
200
 * @param mixed $sTable
201
 * @param mixed $sField
202
 * @param mixed $sDescription
203
 * @return
204
 */
205
function add_modify_field_in_database($sTable,$sField,$sDescription){
206
	global $database,$OK,$FAIL,$bDebugModus;
207
	$aDebugMessage = array();
208
	if(!$database->field_exists($sTable,$sField)) {
209
		$aDebugMessage[] = "<span>Adding field $sField to $sTable table</span>";
210
		$aDebugMessage[] = ($database->field_add($sTable, $sField, $sDescription) ? " $OK<br />" : " $FAIL!<br />");
211
	} else {
212
		$aDebugMessage[] = "<span>Modify field $sField to $sTable table</span>";
213
		$aDebugMessage[] = ($database->field_modify($sTable, $sField, $sDescription) ? " $OK<br />" : " $FAIL!<br />");
214
	}
215
	if($bDebugModus) {
216
		echo implode(PHP_EOL,$aDebugMessage);
217
	}
218
return;
219
}
220

    
221
/**
222
 * check existings tables for upgrade or install
223
 *
224
 * check_wb_tables()
225
 *
226
 * @return
227
 */
228
function check_wb_tables()
229
{
230
	global $database,$aPackage;
231

    
232
// if prefix inludes '_' or '%'
233
	$search_for = addcslashes ( TABLE_PREFIX, '%_' );
234
	$get_result = $database->query( 'SHOW TABLES LIKE "'.$search_for.'%"');
235

    
236
	// $get_result = $database->query( "SHOW TABLES FROM ".DB_NAME);
237
    $all_tables = array();
238
    $aTable = array();
239
    if($get_result->numRows() > 0)
240
    {
241
        while ($data = $get_result->fetchRow()) {
242
            $tmp = preg_replace('/^'.preg_quote(TABLE_PREFIX, '/').'/s', '', $data[0]);
243
            if(in_array($tmp,$aPackage)) {
244
                $all_tables[] = $tmp;
245
            } else {
246
                $aTable[] = $tmp;
247
            }
248
        }
249
    }
250

    
251
    return array_merge ( $all_tables, $aTable );
252
}
253

    
254
// check existing tables
255
$all_tables = check_wb_tables();
256

    
257
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
258
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
259
<head>
260
<title>Upgrade script</title>
261
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
262
<style type="text/css">
263
html { overflow-y: scroll; /* Force firefox to always show room for a vertical scrollbar */ }
264

    
265
body {
266
	margin:0;
267
	padding:0;
268
	border:0;
269
	background: #EBF7FC;
270
	color:#000;
271
	font-family: 'Trebuchet MS', Verdana, Arial, Helvetica, Sans-Serif;
272
	font-size: small;
273
	height:101%;
274
}
275

    
276
#container {
277
	min-width:48em;
278
    width: 70%;
279
	background: #A8BCCB url(<?php echo WB_URL; ?>/templates/wb_theme/images/background.png) repeat-x;
280
	border:1px solid #000;
281
	color:#000;
282
	margin:2em auto;
283
	padding:0 20px;
284
	min-height: 500px;
285
	text-align:left;
286
}
287
.page {
288
	width:100%;
289
    overflow: hidden;
290
}
291
.content {
292
    padding: 10px;
293
}
294
p { line-height:1.5em; }
295

    
296
form {
297
	display: inline-block;
298
	line-height: 20px;
299
	vertical-align: baseline;
300
}
301
input[type="submit"].restart {
302
	background-color: #FFDBDB;
303
	font-weight: bold;
304
}
305

    
306
h1,h2,h3,h4,h5,h6 {
307
	font-family: Verdana, Arial, Helvetica, sans-serif;
308
	color: #26527D;
309
	margin-top: 1.0em;
310
	margin-bottom: 0.1em;
311
}
312

    
313
h1 { font-size:150%; }
314
h2 { font-size: 130%; border-bottom: 1px #CCC solid; }
315
h3 { font-size: 110%; font-weight: bold; }
316

    
317
textarea {
318
	width:100%;
319
	border: 2px groove #0F1D44;
320
	padding: 2px;
321
	color: #000;
322
	font-weight: normal;
323
}
324
.ok, .error { font-weight:bold; }
325
.ok { color:green; }
326
.error { color:red; }
327
.check { color:#555; }
328

    
329
span.ok,
330
span.error {
331
    margin-left: 0em;
332
}
333

    
334
.warning {
335
	background:#FFDBDB;
336
	padding:1em;
337
	margin-top:0.5em;
338
	border: 1px solid #DB0909;
339
}
340
.info {
341
	background:#C7F4C7;
342
	padding:1em;
343
	margin-top:0.5em;
344
	border: 1px solid #277A29;
345
}
346

    
347
</style>
348
</head>
349
<body>
350
<div id="container">
351
<div class="page">
352
<img src="<?php echo WB_URL; ?>/templates/wb_theme/images/logo.png" alt="WebsiteBaker Project" />
353
<div class="content">
354
<h1>WebsiteBaker Upgrade</h1>
355
<?php
356
	if( version_compare( WB_VERSION, '2.7', '<' )) {
357
		status_msg('<strong>Warning:</strong><br />It is not possible to upgrade from WebsiteBaker Versions before 2.7.<br />For upgrading to version '.VERSION.' you must upgrade first to v.2.7 at least!!!', 'warning', 'div');
358
		echo '<br /><br />';
359
		echo "</div>
360
		</div>
361
		</div>
362
		</body>
363
		</html>
364
		";
365
		exit();
366
	}
367

    
368
?>
369
<p class="info">This script upgrades an existing WebsiteBaker <strong> <?php echo $oldRevision; ?></strong> installation to the <strong> <?php echo $newRevision ?> </strong>.<br />The upgrade script alters the existing WB database to reflect the changes introduced with WB 2.8.x</p>
370

    
371
<?php
372

    
373
/**
374
 * Check if disclaimer was accepted
375
 */
376
$bDebugModus = false;
377
$bDebugModus = ( (isset($_POST['debug_confirmed']) && $_POST['debug_confirmed'] == 'debug') ? true : false);
378
if (!(isset($_POST['backup_confirmed']) && $_POST['backup_confirmed'] == 'confirmed')) { ?>
379
<h2>Step 1: Backup your files</h2>
380
<h5 class="warning">It is highly recommended to <strong>create a manual backup</strong> of the entire <strong class="error"><?php echo  PAGES_DIRECTORY ?>/</strong> folder and the <strong>MySQL database</strong> before proceeding.</h5>
381
<p><strong class="error">Note: </strong>The upgrade script alters some settings of your existing database!!! You need to confirm the disclaimer before proceeding.</p>
382

    
383
<form action="<?php echo $_SERVER['SCRIPT_NAME'];?>" method="post">
384
<textarea cols="92" rows="5">DISCLAIMER: The WebsiteBaker upgrade script 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. One needs to confirm that a manual backup of the <?php echo  PAGES_DIRECTORY ?>/ folder (including all files and subfolders contained in it) and backup of the entire WebsiteBaker MySQL database was created before you can proceed.</textarea>
385
<br /><br /><input name="backup_confirmed" type="checkbox" value="confirmed" />&nbsp;<strong>I confirm that a manual backup of the <?php echo  PAGES_DIRECTORY ?>/ folder and the MySQL database was created.</strong>
386
<br /><br /><input name="debug_confirmed" type="checkbox" value="debug" />&nbsp;<strong>Here you can get more details during running upgrade.</strong>
387
<br /><br /><input name="send" type="submit" value="Start upgrade script" />
388
</form>
389
<br />
390

    
391
<?php
392
	status_msg('<strong> Notice:</strong><br />You need to confirm that you have created a manual backup of the '.PAGES_DIRECTORY.'/ directory and the MySQL database before you can proceed.', 'warning', 'div');
393
	echo "<br /><br /></div>
394
	</div>
395
	</div>
396
	</body>
397
	</html>";
398
	exit();
399
}
400

    
401
// check again all tables, to get a new array
402
// if(sizeof($all_tables) < sizeof($aTable)) { $all_tables = check_wb_tables(); }
403
/**********************************************************
404
 *  - check tables coming with WebsiteBaker
405
 */
406
    $check_text = 'total ';
407
    // $check_tables = mysqlCheckTables( DB_NAME ) ;
408
    $aTable = array();
409
    foreach ($all_tables as $data) {
410
        $tmp = str_replace(TABLE_PREFIX, '', $data);
411
        if(in_array($tmp,$aPackage)) {
412
            $aTable[] = $tmp;
413
        }
414
    }
415

    
416
    if( (sizeof($all_tables) >= sizeof($aPackage)) && (sizeof($aTable) == sizeof($aPackage)) )
417
    {
418
        echo '<h4 style="margin-left:0;">NOTICE: Your database '.DB_NAME.' has '.sizeof($all_tables).' '.$check_text.' tables from '.sizeof($aPackage).' included in package '.$OK.'</h4>';
419
    }
420
    else
421
    {
422
        status_msg('<strong>:</strong><br />can\'t run Upgrade, missing tables', 'warning', 'div');
423
        echo '<h4>Missing required tables. You can install them in backend->addons->modules.<br />';
424
        echo 'Or if you uploaded per FTP install possible by backend->addons->modules->advanced.<br />';
425
        echo 'First rename or delete the upgrade-script.php, so the script can\'t start automatically by backend<br />';
426
        echo 'After installing missing tables upload and run again upgrade-script.php</h4>';
427
        $result = array_diff ( $aPackage, $aTable );
428

    
429
        echo '<h4 class="warning"><br />';
430
        while ( list ( $key, $val ) = each ( $result ) )
431
        {
432
            echo 'TABLE ´'.TABLE_PREFIX.$val.'´ '.$FAIL.'<br>';
433
        }
434

    
435
        echo '<br /></h4>';
436
        echo '<br /><br />';
437
        if(isset($_SERVER['SCRIPT_NAME'])) {
438
        	echo '<form action="'.$_SERVER['SCRIPT_NAME'].'/">';
439
        	echo '&nbsp;<input type="submit" value="Start upgrade again" />';
440
        	echo '</form>';
441
        }
442
        if(defined('ADMIN_URL')) {
443
        	echo '<form action="'.ADMIN_URL.'/index.php" method="post">';
444
        	echo '&nbsp;<input name="backend_send" type="submit" value="kick me to the Backend" />';
445
        	echo '</form>';
446
        }
447
        echo "<br /><br /></div>
448
        </div>
449
        </div>
450
        </body>
451
        </html>";
452

    
453
        exit();
454
    }
455

    
456
echo '<h3>Step '.(++$stepID).': Setting default_theme</h3>';
457
$aDebugMessage = array();
458
    /**********************************************************
459
     *  - Adding field default_theme to settings table
460
     */
461
    $aDebugMessage[] = '<div style="margin-left:2em;">';
462
    $aDebugMessage[] = "<br /><span><strong>Adding default_theme to settings table</strong></span>";
463
    // db_update_key_value('settings', 'default_theme', $DEFAULT_THEME);
464
    $aDebugMessage[] = (db_update_key_value( 'settings', 'default_theme', $DEFAULT_THEME ) ? " $OK<br />" : " $FAIL!<br />");
465
    $aDebugMessage[] = '</div>';
466

    
467
if($bDebugModus) {
468
    echo implode(PHP_EOL,$aDebugMessage);
469
}
470
$aDebugMessage = array();
471
echo'<h3>Step '.(++$stepID).': Updating tables included in package</h3>';
472
    /**********************************************************
473
     *  - Adding field sec_anchor to settings table
474
     */
475
    echo '<div style="margin-left:2em;">';
476
    echo "<h4>Adding/updating entries on table settings</h4>";
477
    $aDebugMessage[] = "<span>Adding/updating sec_anchor to settings table</span>";
478
    $cfg = array(
479
    	'sec_anchor' => defined('SEC_ANCHOR') ? SEC_ANCHOR : 'section_'
480
    );
481
   $aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
482

    
483
    /**********************************************************
484
     *  - Adding redirect timer to settings table
485
     */
486
    $aDebugMessage[] = "<span>Adding/updating redirect timer to settings table</span>";
487
    $cfg = array(
488
    	'redirect_timer' => defined('REDIRECT_TIMER') ? REDIRECT_TIMER : '1500'
489
    );
490
    $aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
491

    
492
    /**********************************************************
493
     *  - Adding rename_files_on_upload to settings table
494
     */
495
    $aDebugMessage[] = "<span>Adding/Updating rename_files_on_upload to settings table</span>";
496
    $cfg = array(
497
    	'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')
498
    );
499
    $aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
500

    
501
    /**********************************************************
502
     *  - Adding mediasettings to settings table
503
     */
504
    $aDebugMessage[] = "<span>Adding/updating mediasettings to settings table</span>";
505
    $cfg = array(
506
    	'mediasettings' => (defined('MEDIASETTINGS') ? MEDIASETTINGS : ''),
507
    );
508

    
509
    $aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
510

    
511
    /**********************************************************
512
     *  - Adding fingerprint_with_ip_octets to settings table
513
     */
514
    $aDebugMessage[] = "<span>Adding/updating fingerprint_with_ip_octets to settings table</span>";
515
    $cfg = array(
516
    	'fingerprint_with_ip_octets' => (defined('FINGERPRINT_WITH_IP_OCTETS') ? FINGERPRINT_WITH_IP_OCTETS : '2'),
517
    	'secure_form_module' => (defined('SECURE_FORM_MODULE') ? SECURE_FORM_MODULE : '')
518
    );
519

    
520
    $aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
521

    
522
    /**********************************************************
523
     *  - Adding page_icon_dir to settings table
524
     */
525
    $aDebugMessage[] = "<span>Adding/updating page_icon_dir to settings table</span>";
526
    $cfg = array(
527
    	'page_icon_dir' => (defined('PAGE_ICON_DIR') ? PAGE_ICON_DIR : '/templates/*/title_images'),
528
    );
529

    
530
    $aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
531
    /**********************************************************
532
     *  - Adding page_extended to settings table
533
     */
534
    $aDebugMessage[] = "<span>Adding/updating page_extendet to settings table</span>";
535
    $cfg = array(
536
    	'page_extendet' => (defined('PAGE_EXTENDET') ? PAGE_EXTENDET : 'true'),
537
    );
538

    
539
    $aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
540

    
541
    /**********************************************************
542
     *  - Adding wbmail_signature to settings table
543
     */
544
    $aDebugMessage[] = "<span>Adding/updating wbmail_signature to settings table</span>";
545
    $cfg = array(
546
    	'wbmail_signature' => (defined('WBMAIL_SIGNATURE') ? WBMAIL_SIGNATURE : '')
547
    );
548

    
549
    $aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
550

    
551
    /**********************************************************
552
     *  - Adding confirmed_registration to settings table
553
     */
554
    $aDebugMessage[] = "<span>Adding/updating confirmed_registration to settings table</span>";
555
    $cfg = array(
556
    	'confirmed_registration' => (defined('CONFIRMED_REGISTRATION') ? CONFIRMED_REGISTRATION : '0')
557
    );
558

    
559
    $aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
560

    
561
    /**********************************************************
562
     *  - Adding dev_infos to settings table
563
     */
564
    $aDebugMessage[] = "<span>Adding/updating dev_infos to settings table</span>";
565
    $cfg = array(
566
    	'dev_infos' => (defined('DEV_INFOS') ? DEV_INFOS : 'false')
567
    );
568

    
569
    $aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
570

    
571
if($bDebugModus) {
572
    echo implode(PHP_EOL,$aDebugMessage);
573
}
574
echo '</div>';
575

    
576
$aDebugMessage = array();
577
if(version_compare(WB_REVISION, REVISION, '<='))
578
{
579
    echo '<div style="margin-left:2em;">';
580
	/**********************************************************
581
	 *  - Update search no results database filed to create
582
	 *  valid XHTML if search is empty
583
	 */
584
	if (version_compare(WB_VERSION, '2.8', '<'))
585
	{
586
        echo "<h4>Adding/updating fields on table search</h4>";
587
	    echo "Updating database field `no_results` on search table: ";
588
	    $search_no_results = addslashes('<tr><td><p>[TEXT_NO_RESULTS]</p></td></tr>');
589
	    $sql  = 'UPDATE `'.TABLE_PREFIX.'search` ';
590
		$sql .= 'SET `value`=\''.$search_no_results.'\' ';
591
		$sql .= 'WHERE `name`=\'no_results\'';
592
	    echo ($database->query($sql)) ? " $OK<br />" : " $FAIL!<br />";
593
	}
594

    
595
    echo "<h4>Adding/updating field on table mod_menu_link</h4>";
596
	/**********************************************************
597
     *  - Add field "redirect_type" to table "mod_menu_link"
598
     *  has to be moved later to upgrade.php in modul menu_link, because modul can be removed
599
     */
600
	$table_name = TABLE_PREFIX.'mod_menu_link';
601
	$field_name = 'redirect_type';
602
	$description = "INT NOT NULL DEFAULT '301' AFTER `target_page_id`";
603
    add_modify_field_in_database($table_name,$field_name,$description);
604

    
605
    if($bDebugModus) {
606
        echo implode(PHP_EOL,$aDebugMessage);
607
    }
608

    
609
    $aDebugMessage = array();
610
    echo "<h4>Adding/updating field on table pages</h4>";
611
	/**********************************************************
612
	 *  - Add field "page_trail" to table "pages"
613
	 */
614
	$table_name = TABLE_PREFIX.'pages';
615
	$field_name = 'page_trail';
616
	$description = "VARCHAR( 255 ) NOT NULL DEFAULT ''";
617
    add_modify_field_in_database($table_name,$field_name,$description);
618

    
619
	/**********************************************************
620
     *  - Add field "page_icon" to table "pages"
621
     */
622
	$table_name = TABLE_PREFIX.'pages';
623
	$field_name = 'page_icon';
624
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '' AFTER `page_title`";
625
    add_modify_field_in_database($table_name,$field_name,$description);
626

    
627
	/**********************************************************
628
	 *  - Add field "page_code" to table "pages"
629
	 */
630
	$table_name = TABLE_PREFIX.'pages';
631
	$field_name = 'page_code';
632
	$description = "INT NOT NULL DEFAULT '0' AFTER `language`";
633
    add_modify_field_in_database($table_name,$field_name,$description);
634

    
635
	/**********************************************************
636
     *  - Add field "menu_icon_0" to table "pages"
637
     */
638
	$table_name = TABLE_PREFIX.'pages';
639
	$field_name = 'menu_icon_0';
640
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '' AFTER `menu_title`";
641
    add_modify_field_in_database($table_name,$field_name,$description);
642

    
643
	/**********************************************************
644
	 *  - Add field "menu_icon_1" to table "pages"
645
     */
646
	$table_name = TABLE_PREFIX.'pages';
647
	$field_name = 'menu_icon_1';
648
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '' AFTER `menu_icon_0`";
649
    add_modify_field_in_database($table_name,$field_name,$description);
650

    
651
	/**********************************************************
652
	 *  - Add field "tooltip" to table "pages"
653
     */
654
	$table_name = TABLE_PREFIX.'pages';
655
	$field_name = 'tooltip';
656
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '' AFTER `menu_icon_1`";
657
    add_modify_field_in_database($table_name,$field_name,$description);
658

    
659
	/**********************************************************
660
	 *  - Add field "admin_groups" to table "pages"
661
     */
662
	$table_name = TABLE_PREFIX.'pages';
663
	$field_name = 'admin_groups';
664
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '1'";
665
    add_modify_field_in_database($table_name,$field_name,$description);
666

    
667
	/**********************************************************
668
	 *  - Add field "admin_users" to table "pages"
669
	 */
670
	$table_name = TABLE_PREFIX.'pages';
671
	$field_name = 'admin_users';
672
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT ''";
673
    add_modify_field_in_database($table_name,$field_name,$description);
674

    
675
	/**********************************************************
676
	 *  - Add field "viewing_groups" to table "pages"
677
	 */
678
	$table_name = TABLE_PREFIX.'pages';
679
	$field_name = 'viewing_groups';
680
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '1'";
681
//	echo "<span>Modify field viewing_groups to pages table</span>";
682
//	echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
683
    add_modify_field_in_database($table_name,$field_name,$description);
684

    
685
	/**********************************************************
686
	 *  - Add field "viewing_users" to table "pages"
687
	 */
688
	$table_name = TABLE_PREFIX.'pages';
689
	$field_name = 'viewing_users';
690
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT ''";
691
    add_modify_field_in_database($table_name,$field_name,$description);
692

    
693
	/**********************************************************
694
     *  - Add field "custom01" to table "pages"
695
     */
696
	$table_name = TABLE_PREFIX.'pages';
697
	$field_name = 'custom01';
698
	$description = "VARCHAR( 255 ) NOT NULL DEFAULT '' ";
699
    add_modify_field_in_database($table_name,$field_name,$description);
700

    
701
	/**********************************************************
702
     *  - Add field "custom02" to table "pages"
703
     */
704
	$table_name = TABLE_PREFIX.'pages';
705
	$field_name = 'custom02';
706
	$description = "VARCHAR( 255 ) NOT NULL DEFAULT '' ";
707
    add_modify_field_in_database($table_name,$field_name,$description);
708

    
709
    if($bDebugModus) {
710
        echo implode(PHP_EOL,$aDebugMessage);
711
    }
712

    
713
	$aDebugMessage = array();
714
	/**********************************************************
715
     * modify wrong strucre on table sections
716
     * wrong structure let crash wb
717
     */
718
	echo "<h4>Change field structure on table sections</h4>";
719
	$table_name = TABLE_PREFIX.'sections';
720
	$description = "VARCHAR( 255 ) NOT NULL DEFAULT ''";
721
	$aDebugMessage[] = "<span>Modify field module on sections table</span>";
722
	$aDebugMessage[] = ($database->field_modify($table_name, 'module', $description) ? " $OK<br />" : " $FAIL!<br />");
723
	$aDebugMessage[] = "<span>Modify field block on sections table</span>";
724
	$aDebugMessage[] = ($database->field_modify($table_name, 'block', $description) ? " $OK<br />" : " $FAIL!<br />");
725
	$aDebugMessage[] = "<span>Modify field publ_start on sections table</span>";
726
	$aDebugMessage[] = ($database->field_modify($table_name, 'publ_start', $description) ? " $OK<br />" : " $FAIL!<br />");
727
	$aDebugMessage[] = "<span>Modify field publ_end on sections table</span>";
728
	$aDebugMessage[] = ($database->field_modify($table_name, 'publ_end', $description) ? " $OK<br />" : " $FAIL!<br />");
729

    
730
    if($bDebugModus) {
731
        echo implode(PHP_EOL,$aDebugMessage);
732
    }
733

    
734
	$aDebugMessage = array();
735
	/**********************************************************
736
     *   `confirm_code` VARCHAR(32) NOT NULL DEFAULT '',
737
     *   `confirm_timeout` INT(11) NOT NULL DEFAULT '0',
738
     */
739
	echo "<h4>Change field structure on table users</h4>";
740
	$table_name = TABLE_PREFIX.'users';
741
	$field_name = 'confirm_code';
742
	$description = "VARCHAR( 32 ) NOT NULL DEFAULT '' AFTER `password` ";
743
    add_modify_field_in_database($table_name,$field_name,$description);
744

    
745
	$table_name = TABLE_PREFIX.'users';
746
	$field_name = 'confirm_timeout';
747
	$description = "INT(11) NOT NULL DEFAULT '0' AFTER `confirm_code` ";
748
    add_modify_field_in_database($table_name,$field_name,$description);
749

    
750
    if($bDebugModus) {
751
        echo implode(PHP_EOL,$aDebugMessage);
752
    }
753

    
754
    $aDebugMessage = array();
755
	/**********************************************************
756
     * Modify Administrator on groups table
757
     */
758
	echo "<h4>Update group Administrator on table groups</h4>";
759
	$aDebugMessage[] = "<span>Modify Administrator on groups table</span>";
760
	$sModulePermissions = '';
761
	$sTemplatePermissions = '';
762
	$sSystemPermissions  = 'access,addons,admintools,admintools_view,groups,groups_add,groups_delete,groups_modify,groups_view,';
763
	$sSystemPermissions .= 'languages,languages_install,languages_uninstall,languages_view,media,media_create,media_delete,media_rename,media_upload,media_view,';
764
	$sSystemPermissions .= 'modules,modules_advanced,modules_install,modules_uninstall,modules_view,pages,pages_add,pages_add_l0,pages_delete,pages_intro,pages_modify,pages_settings,pages_view,';
765
	$sSystemPermissions .= 'preferences,preferences_view,settings,settings_advanced,settings_basic,settings_view,templates,templates_install,templates_uninstall,templates_view,users,users_add,users_delete,users_modify,users_view';
766

    
767
	$sql  = 'UPDATE `'.TABLE_PREFIX.'groups` ';
768
	$sql .= 'SET `name` = \'Administrators\', ';
769
	$sql .= '`system_permissions` = \''.$sSystemPermissions.'\', ';
770
	$sql .= '`module_permissions` = \''.$sModulePermissions.'\', ';
771
	$sql .= '`template_permissions` = \''.$sTemplatePermissions.'\' ';
772
	$sql .= 'WHERE `group_id` = \'1\' ';
773
    $aDebugMessage[] = ($database->query($sql)) ? " $OK<br />" : " $FAIL!<br />";
774
    if( ($admin->is_authenticated() == true) && ($admin->ami_group_member('1') ) ) {
775
        $_SESSION['SYSTEM_PERMISSIONS'] = array_merge($_SESSION['SYSTEM_PERMISSIONS'], explode(',', $sSystemPermissions));
776
    }
777

    
778
    if($bDebugModus) {
779
        echo implode(PHP_EOL,$aDebugMessage);
780
    }
781
    echo '</div>';
782

    
783
}
784

    
785
if(version_compare(WB_REVISION, '1800', '<'))
786
{
787
    $aDebugMessage = array();
788
    /**********************************************************
789
     * This part with changing in mod_wysiwyg will be removed in the final version
790
     * special workout for the tester
791
     *  - Remove/add PRIMARY KEY from/to "section_id" from table "mod_wysiwygs"
792
     */
793
    $aDebugMessage[] = '<div style="margin-left:2em;">';
794

    
795
    $sTable = TABLE_PREFIX.'mod_wysiwyg';
796
    $field_name = 'wysiwyg_id';
797
    if($database->field_exists($sTable, 'wysiwyg_id')) {
798
        if($database->index_exists($sTable, 'PRIMARY')) {
799
            $aDebugMessage[] = "<span>Remove PRIMARY KEY from table mod_wysiwyg.wysiwyg_id</span>";
800
            $aDebugMessage[] = $database->index_remove($sTable, 'PRIMARY') ? " $OK<br />" : " $FAIL!<br />";
801
        }
802
        $aDebugMessage[] = "<span>Remove field 'wysiwyg_id' from table mod_wysiwyg</span>";
803
        $aDebugMessage[] = $database->field_remove($sTable, 'wysiwyg_id') ? " $OK<br />" : " $FAIL!<br />";
804
    }
805

    
806
    $aDebugMessage[] = "<br /><span>Create PRIMARY KEY ( `section_id` ) on table mod_wysiwygs.</span>";
807
    $aDebugMessage[] = $database->index_add($sTable, '', 'section_id', 'PRIMARY') ? " $OK<br />" : " $FAIL!<br />";
808
    $aDebugMessage[] = '</div>';
809

    
810
    if($bDebugModus) {
811
    // $aDebugMessage[] =
812
        echo implode(PHP_EOL,$aDebugMessage);
813
    }
814
}
815

    
816
if(version_compare(WB_REVISION, REVISION, '<='))
817
{
818
    $aDebugMessage = array();
819
    echo '<h3>Step '.(++$stepID).': Updating group_id in table users</h3>';
820
    /**********************************************************
821
    * Updating group_id in table users
822
    */
823
        echo '<div style="margin-left:2em;">';
824
        $aUsers = array();
825
		// Get existing values
826
        $sql  = 'SELECT * FROM `'.TABLE_PREFIX.'users` ' ;
827
        $sql .= 'WHERE `user_id` != 1 ';
828
        if($oUser = $database->query($sql)){
829
            $iTotalUsers = $oUser->numRows();
830
            while($Users = $oUser->fetchRow(MYSQL_ASSOC)) {
831

    
832
                $aUsers[$Users['user_id']]['groups_id'] = $Users['groups_id'];
833
                $aUsers[$Users['user_id']]['display_name'] = $Users['display_name'];
834
            }
835
        } else {
836
            $aDebugMessage[] = $database->is_error()==false ? " $OK<br />" : " $FAIL!<br />";
837
        }
838

    
839
        foreach($aUsers AS $user_id => $value){
840
                // choose group_id from groups_id - workaround for still remaining calls to group_id (to be cleaned-up)
841
                $aGroups_id = explode(',', $aUsers[$user_id]['groups_id']);
842
                $groups_id = $aUsers[$user_id]['groups_id'];
843
                $group_id = 0;
844
                //if user is in administrator-group, get this group else just get the first one
845
                if($admin->is_group_match($aGroups_id,'1')) { $group_id = 1; $groups_id = '1'; } else { $group_id = intval($aGroups_id[0]); }
846

    
847
                $sMessage = "<span>Updating group_id ".$TEXT['DISPLAY_NAME']." " .$aUsers[$user_id]['display_name']."</span>";
848
                $sql  = 'UPDATE `'.TABLE_PREFIX.'users` ';
849
                $sql .= 'SET `group_id`  = '.$group_id.', ';
850
                $sql .=     '`groups_id` = \''.$groups_id.'\' ';
851
                $sql .= 'WHERE `user_id` = '.intval($user_id);
852

    
853
                if($oRes = $database->query($sql)){  }
854
                $aDebugMessage[] = $database->is_error()==false ? $sMessage." $OK<br />" : $sMessage." $FAIL!<br />";
855
        }
856
        unset($aUsers);
857

    
858
    $aDebugMessage[] = '</div>';
859

    
860
    if($bDebugModus) {
861
    // $aDebugMessage[] =
862
        echo implode(PHP_EOL,$aDebugMessage);
863
    }else {
864
        echo '<span><strong>'.$iTotalUsers.' users updating the group_id</strong></span>'." $OK<br />";
865
        echo '</div>';
866
    }
867
}
868

    
869
$aDebugMessage = array();
870
echo '<h3>Step '.(++$stepID).': Updating access and protected files in folders</h3>';
871

    
872
echo '<div style="margin-left:2em;">';
873
    /**********************************************************
874
    * upgrade media directory index protect files
875
    */
876
    $dir = (WB_PATH.MEDIA_DIRECTORY);
877
    echo '<h4>Upgrade media directory '.MEDIA_DIRECTORY.'/ index.php protect files</h4>';
878
    $aDebugMessage = rebuildFolderProtectFile($dir);
879
    if( sizeof( $aDebugMessage ) ){
880
    	echo '<span><strong>Upgrade '.sizeof( $aDebugMessage ).' directory '.MEDIA_DIRECTORY.'/ protect files</strong></span>'." $OK<br />";
881
    } else {
882
    	echo '<span><strong>Upgrade directory '.MEDIA_DIRECTORY.'/ protect files</strong></span>'." $FAIL!<br />";
883
    	echo implode ('<br />',$aDebugMessage);
884
    }
885

    
886
    $aDebugMessage = array();
887
    /**********************************************************
888
     * upgrade pages directory index access files
889
     */
890
	echo '<h4>Upgrade pages directory '.PAGES_DIRECTORY.'/  protect and access files</h4>';
891

    
892
    /**********************************************************
893
     *  - Reformat/rebuild all existing access files
894
     */
895
    $sPagePath = (defined('PAGES_DIRECTORY') && (PAGES_DIRECTORY != '') ? PAGES_DIRECTORY : '');
896
    $msg = rebuild_all_accessfiles();
897

    
898
	echo '<strong>'.implode ('<br />',$msg).'</strong>';
899
    echo '</div>';
900

    
901
    /* *****************************************************************************
902
     * - check for deprecated / never needed files
903
     */
904
    if(sizeof($aFilesToRemove)) {
905
    	echo '<h3>Step '.(++$stepID).': Remove deprecated and old files</h3>';
906
    	$searches = array(
907
    		'[ADMIN]',
908
    		'[MEDIA]',
909
    		'[PAGES]',
910
    		'[FRAMEWORK]',
911
    		'[MODULES]',
912
    		'[TEMPLATE]'
913
    	);
914
    	$replacements = array(
915
    		'/'.substr(ADMIN_PATH, strlen(WB_PATH)+1),
916
    		MEDIA_DIRECTORY,
917
    		PAGES_DIRECTORY,
918
    		'/framework',
919
    		'/modules',
920
    		'/templates'
921
    	);
922

    
923
		$msg = '';
924
    	foreach( $aFilesToRemove as $file )
925
    	{
926
			$file = str_replace($searches, $replacements, $file);
927
			if( is_writable(WB_PATH.'/'.$file) ) {
928
				// try to unlink file
929
				if(!unlink(WB_PATH.$file)) {
930
					// save in err-list, if failed
931
				}
932
			}
933
            if( is_readable(WB_PATH.'/'.$file) ) {
934
                $msg .= $file.'<br />';
935
            }
936
    	}
937

    
938
		if($msg != '')
939
		{
940
			$msg = '<br /><br />Following files are deprecated, outdated or a security risk and
941
				    can not be removed automatically.<br /><br />Please delete them
942
					using FTP and restart upgrade-script!<br /><br />'.$msg.'<br />';
943
	        status_msg($msg, 'error warning', 'div');
944
			echo '<p style="font-size:120%;"><strong>WARNING: The upgrade script failed ...</strong></p>';
945

    
946
			echo '<form action="'.$_SERVER['SCRIPT_NAME'].'">';
947
			echo '&nbsp;<input name="send" type="submit" value="Restart upgrade script" />';
948
			echo '</form>';
949
			echo "<br /><br /></div>
950
			</div>
951
			</div>
952
			</body>
953
			</html>";
954
			exit;
955
		}
956
    }
957

    
958

    
959
/**********************************************************
960
 * - check for deprecated / never needed files
961
 */
962
	if(sizeof($dirRemove)) {
963
		echo '<h3>Step  '.(++$stepID).': Remove deprecated and old folders</h3>';
964
		$searches = array(
965
			'[ADMIN]',
966
			'[MEDIA]',
967
			'[PAGES]',
968
			'[TEMPLATE]'
969
		);
970
		$replacements = array(
971
			substr(ADMIN_PATH, strlen(WB_PATH)+1),
972
			MEDIA_DIRECTORY,
973
			PAGES_DIRECTORY,
974
			'/templates',
975
		);
976
		$msg = '';
977
		foreach( $dirRemove as $dir ) {
978
			$dir = str_replace($searches, $replacements, $dir);
979
			$dir = WB_PATH.'/'.$dir;
980
			if( is_dir( $dir )) {
981
			// try to delete dir
982
				if(!is_writable( $dir ) || !rm_full_dir($dir)) {
983
				// save in err-list, if failed
984
                    if( is_readable(WB_PATH.'/'.$file) ) {
985
                    	$msg .= str_replace(WB_PATH,'',$dir).'<br />';
986
                    }
987
				}
988
			}
989
		}
990

    
991
		if($msg != '') {
992
			$msg = '<br /><br />Following directories are deprecated, outdated or a security risk and
993
					can not be removed automatically.<br /><br />Please delete them
994
					using FTP and restart upgrade-script!<br /><br />'.$msg.'<br />';
995
			status_msg($msg, 'error warning', 'div');
996
			echo '<p style="font-size:120%;"><strong>WARNING: The upgrade script failed ...</strong></p>';
997
			echo '<form action="'.$_SERVER['SCRIPT_NAME'].'">';
998
			echo '&nbsp;<input name="send" type="submit" value="Restart upgrade script" />';
999
			echo '</form>';
1000
			echo "<br /><br /></div>
1001
			</div>
1002
			</div>
1003
			</body>
1004
			</html>";
1005
			exit;
1006
		}
1007
	}
1008

    
1009
    /**********************************************************
1010
     * upgrade modules if newer version is available
1011
     * $aModuleList list of proofed modules
1012
     */
1013
    $aModuleList = array('news','wysiwyg','form');
1014
	if(sizeof($aModuleList)) 
1015
	{
1016
	    echo '<h3>Step '.(++$stepID).': Upgrade proofed modules</h3>';
1017
		foreach($aModuleList as $sModul) {
1018
			if(file_exists(WB_PATH.'/modules/'.$sModul.'/upgrade.php')) {
1019
				$currModulVersion = get_modul_version ($sModul, false);
1020
				$newModulVersion =  get_modul_version ($sModul, true);
1021
				if((version_compare($currModulVersion, $newModulVersion) <= 0)) {
1022
	                echo '<div style="margin-left:2em;">';
1023
					echo '<h4>'.'Upgrade module \''.$sModul.'\' version '.$newModulVersion.'</h4>';
1024
					require(WB_PATH.'/modules/'.$sModul.'/upgrade.php');
1025
	                echo '</div>';
1026
				}
1027
			}
1028
		}
1029
	}
1030

    
1031
    /**********************************************************
1032
     * Reformat/rebuild all existing moules access files
1033
     * $aModuleList list of modules
1034
     */
1035
    $aModuleList = array('bakery','topics','news');
1036
	if(sizeof($aModuleList)) 
1037
	{
1038
		echo '<h3>Step '.(++$stepID).': Create/Reorg Accessfiles from modules</h3>';
1039
		foreach($aModuleList as $sModul) {
1040
			$aReturnMsg = array();
1041
			$sModulReorg = 'm_'.$sModul.'_Reorg';
1042
			if(class_exists($sModulReorg)) {
1043
				$sModulVersion =  get_modul_version ($sModul, true);
1044
				echo '<div style="margin-left:2em;">';
1045
				echo '<h4>'.'Create/Reorg Accesfiles for module \''.$sModul.'\' version '.$sModulVersion.'</h4>';
1046
				$oReorg = new $sModulReorg();
1047
				$aReturnMsg = $oReorg->execute(); // show details
1048
				if($bDebugModus && is_array($aReturnMsg)) {
1049
					foreach($aReturnMsg as $title) {
1050
					echo '<strong>'.$title.'</strong><br />';
1051
					}
1052
				}
1053
				echo '</div>';
1054
			}
1055
		}
1056
	}
1057
/**********************************************************
1058
 *  - Reload all addons
1059
 */
1060

    
1061
	echo '<h3>Step '.(++$stepID).' : Reload all addons database entry (no upgrade)</h3><br />';
1062
    echo '<div style="margin-left:2em;">';
1063
    $iFound = 0;
1064
    $iLoaded = 0;
1065
	////delete modules
1066
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'module'");
1067
	// Load all modules
1068
	if( ($handle = opendir(WB_PATH.'/modules/')) ) {
1069
		while(false !== ($file = readdir($handle))) {
1070
			if($file != '' && substr($file, 0, 1) != '.' && is_dir(WB_PATH.'/modules/'.$file) ) {
1071
                $iFound++;
1072
				$iLoaded = load_module(WB_PATH.'/modules/'.$file ) ? $iLoaded+1 : $iLoaded;
1073
			   // 	upgrade_module($file, true);
1074
			}
1075
		}
1076
		closedir($handle);
1077
	}
1078
	echo '<strong><span>'.$iLoaded.' Modules reloaded,</span> found '.$iFound.' directories in folder /modules/</strong><br />';
1079

    
1080
    $iFound = 0;
1081
    $iLoaded = 0;
1082
	////delete templates
1083
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'template'");
1084
	// Load all templates
1085
	if( ($handle = opendir(WB_PATH.'/templates/')) ) {
1086
		while(false !== ($file = readdir($handle))) {
1087
			if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
1088

    
1089
                $iFound++;
1090
				$iLoaded = (load_template(WB_PATH.'/templates/'.$file)==true) ? $iLoaded+1 : $iLoaded;
1091

    
1092
			}
1093
		}
1094
		closedir($handle);
1095
	}
1096
	echo '<strong><span>'.$iLoaded.' Templates reloaded,</span> found '.$iFound.' directories in folder /templates/</strong><br />';
1097

    
1098
    $iFound = 0;
1099
    $iLoaded = 0;
1100
	////delete languages
1101
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'language'");
1102
	// Load all languages
1103
	if( ($handle = opendir(WB_PATH.'/languages/')) ) {
1104
		while(false !== ($file = readdir($handle))) {
1105
			if($file != '' AND (preg_match('#^([A-Z]{2}.php)#', basename($file)))) {
1106
                $iFound++;
1107
				$iLoaded = load_language(WB_PATH.'/languages/'.$file) ? $iLoaded+1 : $iLoaded;
1108
			}
1109
		}
1110
		closedir($handle);
1111
	}
1112
	echo '<strong><span>'.$iLoaded.' Languages reloaded,</span> found '.$iFound.' files in folder /languages/</strong><br />';
1113
    echo '</div>';
1114

    
1115
/**********************************************************
1116
 *  - install new droplets
1117
	$drops = (!in_array ( "mod_droplets", $all_tables)) ? "<br />Install droplets<br />" : "<br />Upgrade droplets<br />";
1118
	echo $drops;
1119
	$file_name = (!in_array ( "mod_droplets", $all_tables) ? "install.php" : "upgrade.php");
1120
	require_once (WB_PATH."/modules/droplets/".$file_name);
1121
********************************************************** */
1122

    
1123
/**********************************************************
1124
 *  - End of upgrade script
1125
 */
1126
	if(!defined('DEFAULT_THEME')) { define('DEFAULT_THEME', $DEFAULT_THEME); }
1127
	if(!defined('THEME_PATH')) { define('THEME_PATH', WB_PATH.'/templates/'.DEFAULT_THEME);}
1128
/**********************************************************
1129
 *  - Set Version to new Version
1130
 */
1131
echo '<h3>Step '.(++$stepID).': Update database version number </h3>';
1132
echo '<div style="margin-left:2em;">';
1133

    
1134
$cfg = array(
1135
	'wb_version' => VERSION,
1136
	'wb_revision' => REVISION,
1137
	'wb_sp' => SP
1138
);
1139
echo '<br /><span><strong>Set database version number to '.VERSION.' '.SP.' '.' Revision ['.REVISION.'] : </strong></span>';
1140
echo (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
1141
echo '</div>';
1142

    
1143
echo '<p style="font-size:140%;"><strong>Congratulations: The upgrade script is finished ...</strong></p>';
1144
status_msg('<strong>:</strong><br />Please delete the file <strong>upgrade-script.php</strong> via FTP before proceeding.', 'warning', 'div');
1145
// show buttons to go to the backend or frontend
1146
echo '<br />';
1147

    
1148
if(defined('WB_URL')) {
1149
	echo '<form action="'.WB_URL.'/">';
1150
	echo '&nbsp;<input type="submit" value="kick me to the Frontend" />';
1151
	echo '</form>';
1152
}
1153
if(defined('ADMIN_URL')) {
1154
	echo '<form action="'.ADMIN_URL.'/">';
1155
	echo '&nbsp;<input type="submit" value="kick me to the Backend" />';
1156
	echo '</form>';
1157
}
1158

    
1159
echo "<br /><br /></div>
1160
</div>
1161
</div>
1162
</body>
1163
</html>
1164
";
1165
exit();
(5-5/5)