Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        backend
5
 * @package         installation
6
 * @author          WebsiteBaker Project
7
 * @copyright       2009-2011, Website Baker Org. e.V.
8
 * @link			http://www.websitebaker2.org/
9
 * @license         http://www.gnu.org/licenses/gpl.html
10
 * @platform        WebsiteBaker 2.8.x
11
 * @requirements    PHP 5.2.2 and higher
12
 * @version         $Id: upgrade-script.php 1625 2012-02-29 00:50:57Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/upgrade-script.php $
14
 * @lastmodified    $Date: 2012-02-29 01:50:57 +0100 (Wed, 29 Feb 2012) $
15
 *
16
 */
17

    
18
@require_once('config.php');
19

    
20
require_once(WB_PATH.'/framework/functions.php');
21
require_once(WB_PATH.'/framework/class.admin.php');
22
$admin = new admin('Addons', 'modules', false, false);
23

    
24
/* display a status message on the screen **************************************
25
 * @param string $message: the message to show
26
 * @param string $class:   kind of message as a css-class
27
 * @param string $element: witch HTML-tag use to cover the message
28
 * @return void
29
 */
30
function status_msg($message, $class='check', $element='span')
31
{
32
	// returns a status message
33
	$msg  = '<'.$element.' class="'.$class.'">';
34
	$msg .= '<strong>'.strtoupper(strtok($class, ' ')).'</strong>';
35
	$msg .= $message.'</'.$element.'>';
36
	echo $msg;
37
}
38

    
39
// database tables including in WB package
40
$table_list = array (
41
    'settings','groups','addons','pages','sections','search','users',
42
    'mod_captcha_control','mod_code','mod_droplets','mod_form_fields',
43
    'mod_form_settings','mod_form_submissions','mod_jsadmin','mod_menu_link',
44
    'mod_news_comments','mod_news_groups','mod_news_posts','mod_news_settings',
45
    'mod_output_filter','mod_wrapper','mod_wysiwyg'
46
);
47

    
48
$OK            = ' <span class="ok">OK</span> ';
49
$FAIL          = ' <span class="error">FAILED</span> ';
50
$DEFAULT_THEME = 'wb_theme';
51
$stepID = 1;
52
$dirRemove = array(
53
/*
54
			'[TEMPLATE]/allcss/',
55
			'[TEMPLATE]/blank/',
56
			'[TEMPLATE]/round/',
57
			'[TEMPLATE]/simple/',
58
*/
59
		 );
60

    
61
$filesRemove['0'] = array(
62

    
63
			'[ADMIN]/preferences/details.php',
64
			'[ADMIN]/preferences/email.php',
65
			'[ADMIN]/preferences/password.php'
66

    
67
		 );
68

    
69
$filesRemove['1'] = array(
70

    
71
			'[TEMPLATE]/argos_theme/templates/access.htt',
72
			'[TEMPLATE]/argos_theme/templates/addons.htt',
73
			'[TEMPLATE]/argos_theme/templates/admintools.htt',
74
			'[TEMPLATE]/argos_theme/templates/error.htt',
75
			'[TEMPLATE]/argos_theme/templates/groups.htt',
76
			'[TEMPLATE]/argos_theme/templates/groups_form.htt',
77
			'[TEMPLATE]/argos_theme/templates/languages.htt',
78
			'[TEMPLATE]/argos_theme/templates/languages_details.htt',
79
/*
80
			'[TEMPLATE]/argos_theme/templates/login.htt',
81
			'[TEMPLATE]/argos_theme/templates/login_forgot.htt',
82
*/
83
			'[TEMPLATE]/argos_theme/templates/media.htt',
84
			'[TEMPLATE]/argos_theme/templates/media_browse.htt',
85
			'[TEMPLATE]/argos_theme/templates/media_rename.htt',
86
			'[TEMPLATE]/argos_theme/templates/modules.htt',
87
			'[TEMPLATE]/argos_theme/templates/modules_details.htt',
88
			'[TEMPLATE]/argos_theme/templates/pages.htt',
89
			'[TEMPLATE]/argos_theme/templates/pages_modify.htt',
90
			'[TEMPLATE]/argos_theme/templates/pages_sections.htt',
91
			'[TEMPLATE]/argos_theme/templates/pages_settings.htt',
92
			'[TEMPLATE]/argos_theme/templates/preferences.htt',
93
			'[TEMPLATE]/argos_theme/templates/setparameter.htt',
94
			'[TEMPLATE]/argos_theme/templates/settings.htt',
95
			'[TEMPLATE]/argos_theme/templates/start.htt',
96
			'[TEMPLATE]/argos_theme/templates/success.htt',
97
			'[TEMPLATE]/argos_theme/templates/templates.htt',
98
			'[TEMPLATE]/argos_theme/templates/templates_details.htt',
99
			'[TEMPLATE]/argos_theme/templates/users.htt',
100
			'[TEMPLATE]/argos_theme/templates/users_form.htt',
101

    
102
/*
103
			'[TEMPLATE]/wb_theme/templates/access.htt',
104
			'[TEMPLATE]/wb_theme/templates/addons.htt',
105
			'[TEMPLATE]/wb_theme/templates/admintools.htt',
106
			'[TEMPLATE]/wb_theme/templates/error.htt',
107
			'[TEMPLATE]/wb_theme/templates/groups.htt',
108
			'[TEMPLATE]/wb_theme/templates/groups_form.htt',
109
			'[TEMPLATE]/wb_theme/templates/languages.htt',
110
			'[TEMPLATE]/wb_theme/templates/languages_details.htt',
111

    
112
			'[TEMPLATE]/wb_theme/templates/login.htt',
113
			'[TEMPLATE]/wb_theme/templates/login_forgot.htt',
114

    
115
			'[TEMPLATE]/wb_theme/templates/media.htt',
116
			'[TEMPLATE]/wb_theme/templates/media_browse.htt',
117
			'[TEMPLATE]/wb_theme/templates/media_rename.htt',
118
			'[TEMPLATE]/wb_theme/templates/modules.htt',
119
			'[TEMPLATE]/wb_theme/templates/modules_details.htt',
120
			'[TEMPLATE]/wb_theme/templates/pages.htt',
121
			'[TEMPLATE]/wb_theme/templates/pages_modify.htt',
122
			'[TEMPLATE]/wb_theme/templates/pages_sections.htt',
123
			'[TEMPLATE]/wb_theme/templates/pages_settings.htt',
124
			'[TEMPLATE]/wb_theme/templates/preferences.htt',
125
			'[TEMPLATE]/wb_theme/templates/setparameter.htt',
126
			'[TEMPLATE]/wb_theme/templates/settings.htt',
127
			'[TEMPLATE]/wb_theme/templates/start.htt',
128
			'[TEMPLATE]/wb_theme/templates/success.htt',
129
			'[TEMPLATE]/wb_theme/templates/templates.htt',
130
			'[TEMPLATE]/wb_theme/templates/templates_details.htt',
131
			'[TEMPLATE]/wb_theme/templates/users.htt',
132
			'[TEMPLATE]/wb_theme/templates/users_form.htt',
133
*/
134
		 );
135

    
136
// analyze/check database tables
137
function mysqlCheckTables( $dbName )
138
{
139
    global $table_list;
140
    $table_prefix = TABLE_PREFIX;
141
    $sql = "SHOW TABLES FROM " . $dbName;
142
    $result = @mysql_query( $sql );
143
    $data = array();
144
    $x = 0;
145

    
146
    while( ( $row = @mysql_fetch_array( $result, MYSQL_NUM ) ) == true )
147
    {
148
        $tmp = str_replace($table_prefix, '', $row[0]);
149

    
150
        if( stristr( $row[0], $table_prefix )&& in_array($tmp,$table_list) )
151
        {
152
            $sql = "CHECK TABLE " . $dbName . '.' . $row[0];
153
            $analyze = @mysql_query( $sql );
154
            $rowFetch = @mysql_fetch_array( $analyze, MYSQL_ASSOC );
155
            $data[$x]['Op'] = $rowFetch["Op"];
156
            $data[$x]['Msg_type'] = $rowFetch["Msg_type"];
157
            $msgColor = '<span class="error">';
158
            $data[$x]['Table'] = $row[0];
159
           // print  " ";
160
            $msgColor = ($rowFetch["Msg_text"] == 'OK') ? '<span class="ok">' : '<span class="error">';
161
            $data[$x]['Msg_text'] = $msgColor.$rowFetch["Msg_text"].'</span>';
162
           // print  "<br />";
163
            $x++;
164
        }
165
    }
166
    return $data;
167
}
168

    
169
// check existings tables for upgrade or install
170
function check_wb_tables()
171
{
172
    global $database,$table_list;
173

    
174
 // if prefix inludes '_' or '%'
175
 $search_for = addcslashes ( TABLE_PREFIX, '%_' );
176
 $get_result = $database->query( 'SHOW TABLES LIKE "'.$search_for.'%"');
177

    
178
        // $get_result = $database->query( "SHOW TABLES FROM ".DB_NAME);
179
        $all_tables = array();
180
        if($get_result->numRows() > 0)
181
        {
182
            while ($data = $get_result->fetchRow())
183
            {
184
                $tmp = str_replace(TABLE_PREFIX, '', $data[0]);
185
                if(in_array($tmp,$table_list))
186
                {
187
                    $all_tables[] = $tmp;
188
                }
189
            }
190
        }
191
     return $all_tables;
192
}
193

    
194
// check existing tables
195
$all_tables = check_wb_tables();
196

    
197
?>
198
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
199
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
200
<head>
201
<title>Upgrade script</title>
202
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
203
<style type="text/css">
204
html { overflow: -moz-scrollbars-vertical; /* Force firefox to always show room for a vertical scrollbar */ }
205

    
206
body {
207
	margin:0;
208
	padding:0;
209
	border:0;
210
	background: #EBF7FC;
211
	color:#000;
212
	font-family: 'Trebuchet MS', Verdana, Arial, Helvetica, Sans-Serif;
213
	font-size: small;
214
	height:101%;
215
}
216

    
217
#container {
218
	width:85%;
219
	background: #A8BCCB url(templates/wb_theme/images/background.png) repeat-x;
220
	border:1px solid #000;
221
	color:#000;
222
	margin:2em auto;
223
	padding:0 15px;
224
	min-height: 500px;
225
	text-align:left;
226
}
227

    
228
p { line-height:1.5em; }
229

    
230
form {
231
	display: inline-block;
232
	line-height: 20px;
233
	vertical-align: baseline;
234
}
235
input[type="submit"].restart {
236
	background-color: #FFDBDB;
237
	font-weight: bold;
238
}
239

    
240
h1,h2,h3,h4,h5,h6 {
241
	font-family: Verdana, Arial, Helvetica, sans-serif;
242
	color: #369;
243
	margin-top: 1.0em;
244
	margin-bottom: 0.1em;
245
}
246

    
247
h1 { font-size:150%; }
248
h2 { font-size: 130%; border-bottom: 1px #CCC solid; }
249
h3 { font-size: 120%; }
250

    
251
.ok, .error { font-weight:bold; }
252
.ok { color:green; }
253
.error { color:red; }
254
.check { color:#555; }
255

    
256
.warning {
257
	width: 98%;
258
	background:#FFDBDB;
259
	padding:0.2em;
260
	margin-top:0.5em;
261
	border: 1px solid black;
262
}
263
.info {
264
	width: 98%;
265
	background:#99CC99;
266
	padding:0.2em;
267
	margin-top:0.5em;
268
	border: 1px solid black;
269
}
270

    
271
</style>
272
</head>
273
<body>
274
<div id="container">
275
<img src="templates/wb_theme/images/logo.png" alt="WebsiteBaker Project" />
276
<h1>WebsiteBaker Upgrade</h1>
277
<?php
278
	if( version_compare( WB_VERSION, '2.7', '<' )) {
279
		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');
280
		echo '<br /><br />';
281
		echo "</div>
282
		</body>
283
		</html>
284
		";
285
		exit();
286
	}
287

    
288
$oldVersion  = 'Version '.WB_VERSION;
289
$oldVersion .= (defined('WB_SP') ? ' '.WB_SP : '');
290
$oldVersion .= (defined('WB_REVISION') ? ' Revision ['.WB_REVISION.'] ' : '') ;
291
$newVersion  = 'Version '.VERSION;
292
$newVersion .= (defined('SP') ? ' '.SP : '');
293
$newVersion .= (defined('REVISION') ? ' Revision ['.REVISION.'] ' : '');
294
// set addition settings if not exists, otherwise upgrade will be breaks
295
if(!defined('WB_SP')) { define('WB_SP',''); }
296
if(!defined('WB_REVISION')) { define('WB_REVISION',''); }
297

    
298
?>
299
<p>This script upgrades an existing WebsiteBaker <strong> <?php echo $oldVersion; ?></strong> installation to the <strong> <?php echo $newVersion ?> </strong>.<br />The upgrade script alters the existing WB database to reflect the changes introduced with WB 2.8.x</p>
300

    
301
<?php
302
/**
303
 * Check if disclaimer was accepted
304
 */
305
if (!(isset($_POST['backup_confirmed']) && $_POST['backup_confirmed'] == 'confirmed')) { ?>
306
<h2>Step 1: Backup your files</h2>
307
<p>It is highly recommended to <strong>create a manual backup</strong> of the entire <strong>/pages folder</strong> and the <strong>MySQL database</strong> before proceeding.<br /><strong class="error">Note: </strong>The upgrade script alters some settings of your existing database!!! You need to confirm the disclaimer before proceeding.</p>
308

    
309
<form name="send" action="<?php echo $_SERVER['SCRIPT_NAME'];?>" method="post">
310
<textarea cols="80" 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 /pages folder (including all files and subfolders contained in it) and backup of the entire WebsiteBaker MySQL database was created before you can proceed.</textarea>
311
<br /><br /><input name="backup_confirmed" type="checkbox" value="confirmed" />&nbsp;I confirm that a manual backup of the /pages folder and the MySQL database was created.
312
<br /><br /><input name="send" type="submit" value="Start upgrade script" />
313
</form>
314
<br />
315

    
316
<?php
317
	status_msg('<strong>Notice:</strong><br />You need to confirm that you have created a manual backup of the /pages directory and the MySQL database before you can proceed.', 'warning', 'div');
318
	echo '<br /><br />';
319
    echo "</div>
320
    </body>
321
    </html>
322
    ";
323
	exit();
324
}
325

    
326
echo '<h2>Step '.(++$stepID).' : Updating database entries</h2>';
327

    
328
// function to add a var/value-pair into settings-table
329
function db_add_key_value($key, $value) {
330
	global $database; global $OK; global $FAIL;
331
	$table = TABLE_PREFIX.'settings';
332
	$query = $database->query("SELECT value FROM $table WHERE name = '$key' LIMIT 1");
333
	if($query->numRows() > 0) {
334
		echo "$key: already exists. $OK.<br />";
335
		return true;
336
	} else {
337
		$database->query("INSERT INTO $table (name,value) VALUES ('$key', '$value')");
338
		echo (mysql_error()?mysql_error().'<br />':'');
339
		$query = $database->query("SELECT value FROM $table WHERE name = '$key' LIMIT 1");
340
		if($query->numRows() > 0) {
341
			echo "$key: $OK.<br />";
342
			return true;
343
		} else {
344
			echo "$key: $FAIL!<br />";
345
			return false;
346
		}
347
	}
348
}
349

    
350
// function to add a new field into a table
351
function db_add_field($field, $table, $desc) {
352
	global $database; global $OK; global $FAIL;
353
	$table = TABLE_PREFIX.$table;
354
	$query = $database->query("DESCRIBE $table '$field'");
355
	if($query->numRows() == 0) { // add field
356
		$query = $database->query("ALTER TABLE $table ADD $field $desc");
357
		echo (mysql_error()?mysql_error().'<br />':'');
358
		$query = $database->query("DESCRIBE $table '$field'");
359
		echo (mysql_error()?mysql_error().'<br />':'');
360
		if($query->numRows() > 0) {
361
			echo "'$field' added. $OK.<br />";
362
		} else {
363
			echo "adding '$field' $FAIL!<br />";
364
		}
365
	} else {
366
		echo "'$field' already exists. $OK.<br />";
367
	}
368
}
369

    
370
/**********************************************************
371
 *  - Adding field default_theme to settings table
372
 */
373
echo "<br />Adding default_theme to settings table<br />";
374
db_update_key_value('settings', 'default_theme', $DEFAULT_THEME);
375
/**********************************************************
376
 *  - install droplets
377
 */
378
    $drops = (!in_array ( "mod_droplets", $all_tables)) ? "<br />Install droplets<br />" : "<br />Upgrade droplets<br />";
379
    echo $drops;
380

    
381
     $file_name = (!in_array ( "mod_droplets", $all_tables) ? "install.php" : "upgrade.php");
382
     require_once (WB_PATH."/modules/droplets/".$file_name);
383

    
384
// check again all tables, to get a new array
385
 if(sizeof($all_tables) < 22) { $all_tables = check_wb_tables(); }
386
/**********************************************************
387
 *  - check tables comin with WebsiteBaker
388
 */
389
    $check_text = 'total ';
390
    // $check_tables = mysqlCheckTables( DB_NAME ) ;
391

    
392
    if(sizeof($all_tables) == 22)
393
    {
394
        echo '<h4>NOTICE: Your database '.DB_NAME.' has '.sizeof($all_tables).' '.$check_text.' tables from '.sizeof($table_list).' included in package '.$OK.'</h4>';
395
    }
396
    else
397
    {
398
        status_msg('<strong>WARNING:</strong><br />can\'t run Upgrade, missing tables', 'warning', 'div');
399
    	echo '<h4>Missing required tables. You can install them in backend->addons->modules->advanced. Then again run upgrade-script.php</h4>';
400
        $result = array_diff ( $table_list, $all_tables );
401
        echo '<h4 class="warning"><br />';
402
        while ( list ( $key, $val ) = each ( $result ) )
403
        {
404
            echo TABLE_PREFIX.$val.' '.$FAIL.'<br>';
405
        }
406
        echo '<br /></h4>';
407
    	echo '<br /><form action="'. $_SERVER['PHP_SELF'] .'">';
408
    	echo '<input type="submit" value="kick me back" style="float:left;" />';
409
    	echo '</form>';
410
        if(defined('ADMIN_URL'))
411
        {
412
        	echo '<form action="'.ADMIN_URL.'" target="_self">';
413
        	echo '&nbsp;<input type="submit" value="kick me to the Backend" />';
414
        	echo '</form>';
415
        }
416
        echo "<br /><br /></div>
417
        </body>
418
        </html>
419
        ";
420
        exit();
421
    }
422

    
423
/**********************************************************
424
 *  - Adding field sec_anchor to settings table
425
 */
426
echo "<br />Adding sec_anchor to settings table<br />";
427
$cfg = array(
428
	'sec_anchor' => 'wb_'
429
);
430
foreach($cfg as $key=>$value) {
431
	db_add_key_value($key, $value);
432
}
433

    
434
/**********************************************************
435
 *  - Adding redirect timer to settings table
436
 */
437
echo "<br />Adding redirect timer to settings table<br />";
438
$cfg = array(
439
	'redirect_timer' => '1500'
440
);
441
foreach($cfg as $key=>$value) {
442
	db_add_key_value($key, $value);
443
}
444

    
445
/**********************************************************
446
 *  - Adding rename_files_on_upload to settings table
447
 */
448
echo "<br />Updating rename_files_on_upload to settings table<br />";
449
$cfg = array(
450
	'rename_files_on_upload' => 'ph.*?,cgi,pl,pm,exe,com,bat,pif,cmd,src,asp,aspx,js'
451
);
452
db_update_key_value('settings', 'rename_files_on_upload', $cfg['rename_files_on_upload']);
453

    
454
/**********************************************************
455
 *  - Adding mediasettings to settings table
456
 */
457
echo "<br />Adding mediasettings to settings table<br />";
458
$cfg = array(
459
	'mediasettings' => '',
460
);
461

    
462
foreach($cfg as $key=>$value) {
463
	db_add_key_value($key, $value);
464
}
465

    
466
/**********************************************************
467
 *  - Adding fingerprint_with_ip_octets to settings table
468
 */
469
echo "<br />Adding fingerprint_with_ip_octets to settings table<br />";
470
$cfg = array(
471
	'fingerprint_with_ip_octets' => '2',
472
	'secure_form_module' => ''
473
);
474
foreach($cfg as $key=>$value) {
475
	db_add_key_value($key, $value);
476
}
477

    
478
/**********************************************************
479
 *  - Add field "redirect_type" to table "mod_menu_link"
480
 */
481
echo "<br />Adding field redirect_type to mod_menu_link table<br />";
482
db_add_field('redirect_type', 'mod_menu_link', "INT NOT NULL DEFAULT '302' AFTER `target_page_id`");
483

    
484
/**********************************************************
485
 *  - Update search no results database filed to create
486
 *  valid XHTML if search is empty
487
 */
488
if (version_compare(WB_VERSION, '2.8', '<'))
489
{
490
    echo "<br />Updating database field `no_results` of search table: ";
491
    $search_no_results = addslashes('<tr><td><p>[TEXT_NO_RESULTS]</p></td></tr>');
492
    $sql  = 'UPDATE `'.TABLE_PREFIX.'search` ';
493
	$sql .= 'SET `value`=\''.$search_no_results.'\' ';
494
	$sql .= 'WHERE `name`=\'no_results\'';
495
    echo ($database->query($sql)) ? ' $OK<br />' : ' $FAIL<br />';
496
}
497
/**********************************************************
498
 * upgrade media folder index protect files
499
 */
500
	$dir = (WB_PATH.MEDIA_DIRECTORY);
501
	echo '<h4>Upgrade '.MEDIA_DIRECTORY.'/ index.php protect files</h4><br />';
502
	$array = rebuildFolderProtectFile($dir);
503
	if( sizeof( $array ) ){
504
		print '<br /><strong>Upgrade '.sizeof( $array ).' '.MEDIA_DIRECTORY.'/ protect files</strong>'." $OK<br />";
505
	} else {
506
		print '<br /><strong>Upgrade '.MEDIA_DIRECTORY.'/ protect files</strong>'." $FAIL!<br />";
507
		print implode ('<br />',$array);
508
	}
509
/**********************************************************
510
 * upgrade posts folder index protect files
511
 */
512
	$sPostsPath = WB_PATH.PAGES_DIRECTORY.'/posts';
513
	echo '<h4>Upgrade /posts/ index.php protect files</h4><br />';
514
	$array = rebuildFolderProtectFile($sPostsPath);
515
	if( sizeof( $array ) ){
516
		print '<br /><strong>Upgrade '.sizeof( $array ).' /posts/ protect files</strong>'." $OK<br />";
517
	} else {
518
		print '<br /><strong>Upgrade /posts/ protect files</strong>'." $FAIL!<br />";
519
		print implode ('<br />',$array);
520
	}
521
/* *****************************************************************************
522
 * - check for deprecated / never needed files
523
 */
524
	if(sizeof($filesRemove)) {
525
		echo '<h2>Step '.(++$stepID).': Remove deprecated and old files</h2>';
526
	}
527
	$searches = array(
528
		'[ADMIN]',
529
		'[MEDIA]',
530
		'[PAGES]',
531
		'[FRAMEWORK]',
532
		'[MODULES]',
533
		'[TEMPLATE]'
534
	);
535
	$replacements = array(
536
		substr(ADMIN_PATH, strlen(WB_PATH)+1),
537
		MEDIA_DIRECTORY,
538
		PAGES_DIRECTORY,
539
		'/framework',
540
		'/modules',
541
		'/templates'
542
	);
543

    
544
	foreach( $filesRemove as $filesId )
545
	{
546
		$msg = '';
547
		foreach( $filesId as $file )
548
		{
549
			$file = str_replace($searches, $replacements, $file);
550
			$file = WB_PATH.'/'.$file;
551
			if( file_exists($file) ) {
552
				// try to unlink file
553
				if(!is_writable( $file ) || !unlink($file)) {
554
					// save in err-list, if failed
555
					$msg .= $file.'<br />';
556
				}
557
			}
558
		}
559

    
560
		if($msg != '')
561
		{
562
			$msg = '<br /><br />Following files are deprecated, outdated or a security risk and
563
				    can not be removed automatically.<br /><br />Please delete them
564
					using FTP and restart upgrade-script!<br /><br />'.$msg.'<br />';
565
	        status_msg($msg, 'error warning', 'div');
566
			echo '<p style="font-size:120%;"><strong>WARNING: The upgrade script failed ...</strong></p>';
567

    
568
			echo '<form action="'.$_SERVER['SCRIPT_NAME'].'">';
569
			echo '&nbsp;<input name="send" type="submit" value="Restart upgrade script" />';
570
			echo '</form>';
571
			echo '<br /><br /></div></body></html>';
572
			exit;
573
		}
574
	}
575

    
576

    
577
/**********************************************************
578
 * - check for deprecated / never needed files
579
 */
580
	if(sizeof($dirRemove)) {
581
		echo '<h2>Step  '.(++$stepID).': Remove deprecated and old folders</h2>';
582
		$searches = array(
583
			'[ADMIN]',
584
			'[MEDIA]',
585
			'[PAGES]',
586
			'[TEMPLATE]'
587
		);
588
		$replacements = array(
589
			substr(ADMIN_PATH, strlen(WB_PATH)+1),
590
			MEDIA_DIRECTORY,
591
			PAGES_DIRECTORY,
592
			'/templates',
593
		);
594
		$msg = '';
595
		foreach( $dirRemove as $dir ) {
596
			$dir = str_replace($searches, $replacements, $dir);
597
			$dir = WB_PATH.'/'.$dir;
598
			if( is_dir( $dir )) {
599
			// try to delete dir
600
				if(!rm_full_dir($dir)) {
601
				// save in err-list, if failed
602
					$msg .= $dir.'<br />';
603
				}
604
			}
605
		}
606
		if($msg != '') {
607
			$msg = '<br /><br />Following files are deprecated, outdated or a security risk and
608
					can not be removed automatically.<br /><br />Please delete them
609
					using FTP and restart upgrade-script!<br /><br />'.$msg.'<br />';
610
			status_msg($msg, 'error warning', 'div');
611
			echo '<p style="font-size:120%;"><strong>WARNING: The upgrade script failed ...</strong></p>';
612
			echo '<form action="'.$_SERVER['SCRIPT_NAME'].'">';
613
			echo '&nbsp;<input name="send" type="submit" value="Restart upgrade script" />';
614
			echo '</form>';
615
			echo '<br /><br /></div></body></html>';
616
			exit;
617
		}
618
	}
619

    
620
/**********************************************************
621
 * upgrade modules if newer version is available
622
 */
623
	$aModuleList = array('news');
624
	foreach($aModuleList as $sModul) {
625
		if(file_exists(WB_PATH.'/modules/'.$sModul.'/upgrade.php')) {
626
			$currModulVersion = get_modul_version ($sModul, false);
627
			$newModulVersion =  get_modul_version ($sModul, true);
628
			if((version_compare($currModulVersion, $newModulVersion) <= 0)) {
629
				echo '<h2>Step '.(++$stepID).' : Upgrade module \''.$sModul.'\' to version '.$newModulVersion.'</h2>';
630
				require_once(WB_PATH.'/modules/'.$sModul.'/upgrade.php');
631
			}
632
		}
633
	}
634
/**********************************************************
635
 *  - Reload all addons
636
 */
637

    
638
	echo '<h2>Step '.(++$stepID).' : Reload all addons database entry (no upgrade)</h2>';
639
	////delete modules
640
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'module'");
641
	// Load all modules
642
	if( ($handle = opendir(WB_PATH.'/modules/')) ) {
643
		while(false !== ($file = readdir($handle))) {
644
			if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'admin.php' AND $file != 'index.php') {
645
				load_module(WB_PATH.'/modules/'.$file );
646
			   // 	upgrade_module($file, true);
647
			}
648
		}
649
		closedir($handle);
650
	}
651
	echo '<br />Modules reloaded<br />';
652

    
653
	////delete templates
654
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'template'");
655
	// Load all templates
656
	if( ($handle = opendir(WB_PATH.'/templates/')) ) {
657
		while(false !== ($file = readdir($handle))) {
658
			if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
659
				load_template(WB_PATH.'/templates/'.$file);
660
			}
661
		}
662
		closedir($handle);
663
	}
664
	echo '<br />Templates reloaded<br />';
665

    
666
	////delete languages
667
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'language'");
668
	// Load all languages
669
	if( ($handle = opendir(WB_PATH.'/languages/')) ) {
670
		while(false !== ($file = readdir($handle))) {
671
			if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
672
				load_language(WB_PATH.'/languages/'.$file);
673
			}
674
		}
675
		closedir($handle);
676
	}
677
	echo '<br />Languages reloaded<br />';
678

    
679
/**********************************************************
680
 *  - End of upgrade script
681
 */
682

    
683
// require(WB_PATH.'/framework/initialize.php');
684

    
685
	if(!defined('DEFAULT_THEME')) { define('DEFAULT_THEME', $DEFAULT_THEME); }
686
	if(!defined('THEME_PATH')) { define('THEME_PATH', WB_PATH.'/templates/'.DEFAULT_THEME);}
687
/**********************************************************
688
 *  - Set Version to new Version
689
 */
690
	echo '<br />Update database version number to '.VERSION.' '.SP.' '.' Revision ['.REVISION.'] : ';
691
	// echo ($database->query("UPDATE `".TABLE_PREFIX."settings` SET `value`='".VERSION."' WHERE `name` = 'wb_version'")) ? " $OK<br />" : " $FAIL<br />";
692
	db_update_key_value('settings', 'wb_version', VERSION);
693
	db_update_key_value('settings', 'wb_revision', REVISION);
694
	db_update_key_value('settings', 'wb_sp', SP);
695

    
696
	echo '<p style="font-size:120%;"><strong>Congratulations: The upgrade script is finished ...</strong></p>';
697
	status_msg('<strong>Warning:</strong><br />Please delete the file <strong>upgrade-script.php</strong> via FTP before proceeding.', 'warning', 'div');
698
	// show buttons to go to the backend or frontend
699
	echo '<br />';
700

    
701
	if(defined('WB_URL')) {
702
		echo '<form action="'.WB_URL.'/">';
703
		echo '&nbsp;<input type="submit" value="kick me to the Frontend" />';
704
		echo '</form>';
705
	}
706
	if(defined('ADMIN_URL')) {
707
		echo '<form action="'.ADMIN_URL.'/">';
708
		echo '&nbsp;<input type="submit" value="kick me to the Backend" />';
709
		echo '</form>';
710
	}
711

    
712
	echo '<br /><br /></div></body></html>';
(5-5/5)