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 1641 2012-03-22 03:28:47Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/upgrade-script.php $
14
 * @lastmodified    $Date: 2012-03-22 04:28:47 +0100 (Thu, 22 Mar 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
			'[ADMIN]/themes/',
60
		 );
61

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

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

    
68
		 );
69

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
299
?>
300
<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>
301

    
302
<?php
303
/**
304
 * Check if disclaimer was accepted
305
 */
306
if (!(isset($_POST['backup_confirmed']) && $_POST['backup_confirmed'] == 'confirmed')) { ?>
307
<h2>Step 1: Backup your files</h2>
308
<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>
309

    
310
<form name="send" action="<?php echo $_SERVER['SCRIPT_NAME'];?>" method="post">
311
<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>
312
<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.
313
<br /><br /><input name="send" type="submit" value="Start upgrade script" />
314
</form>
315
<br />
316

    
317
<?php
318
	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');
319
	echo '<br /><br />';
320
    echo "</div>
321
    </body>
322
    </html>
323
    ";
324
	exit();
325
}
326

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
577

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

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

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

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

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

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

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

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

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

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

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