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 1593 2012-02-01 22:29:36Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/upgrade-script.php $
14
 * @lastmodified    $Date: 2012-02-01 23:29:36 +0100 (Wed, 01 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
			'[TEMPLATE]/argos_theme/templates/login.htt',
80
			'[TEMPLATE]/argos_theme/templates/login_forgot.htt',
81
			'[TEMPLATE]/argos_theme/templates/media.htt',
82
			'[TEMPLATE]/argos_theme/templates/media_browse.htt',
83
			'[TEMPLATE]/argos_theme/templates/media_rename.htt',
84
			'[TEMPLATE]/argos_theme/templates/modules.htt',
85
			'[TEMPLATE]/argos_theme/templates/modules_details.htt',
86
			'[TEMPLATE]/argos_theme/templates/pages.htt',
87
			'[TEMPLATE]/argos_theme/templates/pages_modify.htt',
88
			'[TEMPLATE]/argos_theme/templates/pages_sections.htt',
89
			'[TEMPLATE]/argos_theme/templates/pages_settings.htt',
90
			'[TEMPLATE]/argos_theme/templates/preferences.htt',
91
			'[TEMPLATE]/argos_theme/templates/setparameter.htt',
92
			'[TEMPLATE]/argos_theme/templates/settings.htt',
93
			'[TEMPLATE]/argos_theme/templates/start.htt',
94
			'[TEMPLATE]/argos_theme/templates/success.htt',
95
			'[TEMPLATE]/argos_theme/templates/templates.htt',
96
			'[TEMPLATE]/argos_theme/templates/templates_details.htt',
97
			'[TEMPLATE]/argos_theme/templates/users.htt',
98
			'[TEMPLATE]/argos_theme/templates/users_form.htt',
99

    
100
			'[TEMPLATE]/wb_theme/templates/access.htt',
101
			'[TEMPLATE]/wb_theme/templates/addons.htt',
102
			'[TEMPLATE]/wb_theme/templates/admintools.htt',
103
			'[TEMPLATE]/wb_theme/templates/error.htt',
104
			'[TEMPLATE]/wb_theme/templates/groups.htt',
105
			'[TEMPLATE]/wb_theme/templates/groups_form.htt',
106
			'[TEMPLATE]/wb_theme/templates/languages.htt',
107
			'[TEMPLATE]/wb_theme/templates/languages_details.htt',
108
			'[TEMPLATE]/wb_theme/templates/login.htt',
109
			'[TEMPLATE]/wb_theme/templates/login_forgot.htt',
110
			'[TEMPLATE]/wb_theme/templates/media.htt',
111
			'[TEMPLATE]/wb_theme/templates/media_browse.htt',
112
			'[TEMPLATE]/wb_theme/templates/media_rename.htt',
113
			'[TEMPLATE]/wb_theme/templates/modules.htt',
114
			'[TEMPLATE]/wb_theme/templates/modules_details.htt',
115
			'[TEMPLATE]/wb_theme/templates/pages.htt',
116
			'[TEMPLATE]/wb_theme/templates/pages_modify.htt',
117
			'[TEMPLATE]/wb_theme/templates/pages_sections.htt',
118
			'[TEMPLATE]/wb_theme/templates/pages_settings.htt',
119
			'[TEMPLATE]/wb_theme/templates/preferences.htt',
120
			'[TEMPLATE]/wb_theme/templates/setparameter.htt',
121
			'[TEMPLATE]/wb_theme/templates/settings.htt',
122
			'[TEMPLATE]/wb_theme/templates/start.htt',
123
			'[TEMPLATE]/wb_theme/templates/success.htt',
124
			'[TEMPLATE]/wb_theme/templates/templates.htt',
125
			'[TEMPLATE]/wb_theme/templates/templates_details.htt',
126
			'[TEMPLATE]/wb_theme/templates/users.htt',
127
			'[TEMPLATE]/wb_theme/templates/users_form.htt',
128

    
129
		 );
130

    
131
// analyze/check database tables
132
function mysqlCheckTables( $dbName )
133
{
134
    global $table_list;
135
    $table_prefix = TABLE_PREFIX;
136
    $sql = "SHOW TABLES FROM " . $dbName;
137
    $result = @mysql_query( $sql );
138
    $data = array();
139
    $x = 0;
140

    
141
    while( ( $row = @mysql_fetch_array( $result, MYSQL_NUM ) ) == true )
142
    {
143
        $tmp = str_replace($table_prefix, '', $row[0]);
144

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

    
164
// check existings tables for upgrade or install
165
function check_wb_tables()
166
{
167
    global $database,$table_list;
168

    
169
 // if prefix inludes '_' or '%'
170
 $search_for = addcslashes ( TABLE_PREFIX, '%_' );
171
 $get_result = $database->query( 'SHOW TABLES LIKE "'.$search_for.'%"');
172

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

    
189
// check existing tables
190
$all_tables = check_wb_tables();
191

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

    
201
body {
202
	margin:0;
203
	padding:0;
204
	border:0;
205
	background: #EBF7FC;
206
	color:#000;
207
	font-family: 'Trebuchet MS', Verdana, Arial, Helvetica, Sans-Serif;
208
	font-size: small;
209
	height:101%;
210
}
211

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

    
223
p { line-height:1.5em; }
224

    
225
form {
226
	display: inline-block;
227
	line-height: 20px;
228
	vertical-align: baseline;
229
}
230
input[type="submit"].restart {
231
	background-color: #FFDBDB;
232
	font-weight: bold;
233
}
234

    
235
h1,h2,h3,h4,h5,h6 {
236
	font-family: Verdana, Arial, Helvetica, sans-serif;
237
	color: #369;
238
	margin-top: 1.0em;
239
	margin-bottom: 0.1em;
240
}
241

    
242
h1 { font-size:150%; }
243
h2 { font-size: 130%; border-bottom: 1px #CCC solid; }
244
h3 { font-size: 120%; }
245

    
246
.ok, .error { font-weight:bold; }
247
.ok { color:green; }
248
.error { color:red; }
249
.check { color:#555; }
250

    
251
.warning {
252
	width: 98%;
253
	background:#FFDBDB;
254
	padding:0.2em;
255
	margin-top:0.5em;
256
	border: 1px solid black;
257
}
258
.info {
259
	width: 98%;
260
	background:#99CC99;
261
	padding:0.2em;
262
	margin-top:0.5em;
263
	border: 1px solid black;
264
}
265

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

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

    
293
?>
294
<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>
295

    
296
<?php
297
/**
298
 * Check if disclaimer was accepted
299
 */
300
if (!(isset($_POST['backup_confirmed']) && $_POST['backup_confirmed'] == 'confirmed')) { ?>
301
<h2>Step 1: Backup your files</h2>
302
<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>
303

    
304
<form name="send" action="<?php echo $_SERVER['SCRIPT_NAME'];?>" method="post">
305
<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>
306
<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.
307
<br /><br /><input name="send" type="submit" value="Start upgrade script" />
308
</form>
309
<br />
310

    
311
<?php
312
	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');
313
	echo '<br /><br />';
314
    echo "</div>
315
    </body>
316
    </html>
317
    ";
318
	exit();
319
}
320

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

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

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

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

    
376
     $file_name = (!in_array ( "mod_droplets", $all_tables) ? "install.php" : "upgrade.php");
377
     require_once (WB_PATH."/modules/droplets/".$file_name);
378

    
379
// check again all tables, to get a new array
380
 if(sizeof($all_tables) < 22) { $all_tables = check_wb_tables(); }
381
/**********************************************************
382
 *  - check tables comin with WebsiteBaker
383
 */
384
    $check_text = 'total ';
385
    // $check_tables = mysqlCheckTables( DB_NAME ) ;
386

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

    
418
/**********************************************************
419
 *  - Adding field sec_anchor to settings table
420
 */
421
echo "<br />Adding sec_anchor to settings table<br />";
422
$cfg = array(
423
	'sec_anchor' => 'wb_'
424
);
425
foreach($cfg as $key=>$value) {
426
	db_add_key_value($key, $value);
427
}
428

    
429
/**********************************************************
430
 *  - Adding redirect timer to settings table
431
 */
432
echo "<br />Adding redirect timer to settings table<br />";
433
$cfg = array(
434
	'redirect_timer' => '1500'
435
);
436
foreach($cfg as $key=>$value) {
437
	db_add_key_value($key, $value);
438
}
439

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

    
449
/**********************************************************
450
 *  - Adding mediasettings to settings table
451
 */
452
echo "<br />Adding mediasettings to settings table<br />";
453
$cfg = array(
454
	'mediasettings' => '',
455
);
456

    
457
foreach($cfg as $key=>$value) {
458
	db_add_key_value($key, $value);
459
}
460

    
461
/**********************************************************
462
 *  - Adding fingerprint_with_ip_octets to settings table
463
 */
464
echo "<br />Adding fingerprint_with_ip_octets to settings table<br />";
465
$cfg = array(
466
	'fingerprint_with_ip_octets' => '2',
467
	'secure_form_module' => ''
468
);
469
foreach($cfg as $key=>$value) {
470
	db_add_key_value($key, $value);
471
}
472

    
473
/**********************************************************
474
 *  - Add field "redirect_type" to table "mod_menu_link"
475
 */
476
echo "<br />Adding field redirect_type to mod_menu_link table<br />";
477
db_add_field('redirect_type', 'mod_menu_link', "INT NOT NULL DEFAULT '302' AFTER `target_page_id`");
478

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

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

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

    
563
			echo '<form action="'.$_SERVER['SCRIPT_NAME'].'">';
564
			echo '&nbsp;<input name="send" type="submit" value="Restart upgrade script" />';
565
			echo '</form>';
566
			echo '<br /><br /></div></body></html>';
567
			exit;
568
		}
569
	}
570

    
571

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

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

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

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

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

    
674
/**********************************************************
675
 *  - End of upgrade script
676
 */
677

    
678
// require(WB_PATH.'/framework/initialize.php');
679

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

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

    
696
	if(defined('WB_URL')) {
697
		echo '<form action="'.WB_URL.'/">';
698
		echo '&nbsp;<input type="submit" value="kick me to the Frontend" />';
699
		echo '</form>';
700
	}
701
	if(defined('ADMIN_URL')) {
702
		echo '<form action="'.ADMIN_URL.'/">';
703
		echo '&nbsp;<input type="submit" value="kick me to the Backend" />';
704
		echo '</form>';
705
	}
706

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