Project

General

Profile

1 1457 Luisehahne
<?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$
13
 * @filesource		$HeadURL$
14
 * @lastmodified    $Date$
15
 *
16
 */
17
18
@require_once('config.php');
19
20 1484 Luisehahne
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 1457 Luisehahne
	// returns a status message
33 1484 Luisehahne
	$msg  = '<'.$element.' class="'.$class.'">';
34 1532 Luisehahne
	$msg .= '<strong>'.strtoupper(strtok($class, ' ')).'</strong>';
35 1484 Luisehahne
	$msg .= $message.'</'.$element.'>';
36
	echo $msg;
37 1457 Luisehahne
}
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 1484 Luisehahne
$OK            = ' <span class="ok">OK</span> ';
49
$FAIL          = ' <span class="error">FAILED</span> ';
50
$DEFAULT_THEME = 'wb_theme';
51 1532 Luisehahne
$stepID = 1;
52
$dirRemove = array(
53 1484 Luisehahne
/*
54
			'[TEMPLATE]/allcss/',
55
			'[TEMPLATE]/blank/',
56
			'[TEMPLATE]/round/',
57
			'[TEMPLATE]/simple/',
58
*/
59
		 );
60
61 1532 Luisehahne
$filesRemove['0'] = array(
62 1484 Luisehahne
63 1525 Luisehahne
			'[ADMIN]/preferences/details.php',
64
			'[ADMIN]/preferences/email.php',
65 1532 Luisehahne
			'[ADMIN]/preferences/password.php'
66 1525 Luisehahne
67 1532 Luisehahne
		 );
68
69
$filesRemove['1'] = array(
70
71 1529 Luisehahne
			'[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 1525 Luisehahne
		 );
130
131 1457 Luisehahne
// 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 1532 Luisehahne
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 1457 Luisehahne
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 1525 Luisehahne
	if( version_compare( WB_VERSION, '2.7', '<' )) {
274 1529 Luisehahne
		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 1457 Luisehahne
		echo '<br /><br />';
276
		echo "</div>
277
		</body>
278
		</html>
279
		";
280
		exit();
281
	}
282 1532 Luisehahne
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 1457 Luisehahne
?>
294 1532 Luisehahne
<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 1457 Luisehahne
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 1532 Luisehahne
<form name="send" action="<?php echo $_SERVER['SCRIPT_NAME'];?>" method="post">
305 1457 Luisehahne
<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 1532 Luisehahne
echo '<h2>Step '.(++$stepID).' : Updating database entries</h2>';
322
323 1457 Luisehahne
// 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 1484 Luisehahne
db_update_key_value('settings', 'default_theme', $DEFAULT_THEME);
370 1457 Luisehahne
/**********************************************************
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 1533 Luisehahne
     $file_name = (!in_array ( "mod_droplets", $all_tables) ? "install.php" : "upgrade.php");
377 1457 Luisehahne
     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 1532 Luisehahne
 *  - 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 1457 Luisehahne
 *  - Adding mediasettings to settings table
451
 */
452
echo "<br />Adding mediasettings to settings table<br />";
453
$cfg = array(
454 1476 Luisehahne
	'mediasettings' => '',
455 1457 Luisehahne
);
456 1484 Luisehahne
457 1457 Luisehahne
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 1476 Luisehahne
	'fingerprint_with_ip_octets' => '2',
467
	'secure_form_module' => ''
468 1457 Luisehahne
);
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 1588 darkviper
/**********************************************************
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 1457 Luisehahne
{
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 1588 darkviper
    $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 1457 Luisehahne
}
492
/**********************************************************
493
 * upgrade media folder index protect files
494
 */
495 1588 darkviper
	$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 1457 Luisehahne
	}
504 1484 Luisehahne
/* *****************************************************************************
505
 * - check for deprecated / never needed files
506
 */
507 1588 darkviper
	if(sizeof($filesRemove)) {
508
		echo '<h2>Step '.(++$stepID).': Remove deprecated and old files</h2>';
509
	}
510 1484 Luisehahne
	$searches = array(
511
		'[ADMIN]',
512
		'[MEDIA]',
513 1525 Luisehahne
		'[PAGES]',
514 1533 Luisehahne
		'[FRAMEWORK]',
515
		'[MODULES]',
516 1525 Luisehahne
		'[TEMPLATE]'
517 1484 Luisehahne
	);
518
	$replacements = array(
519 1525 Luisehahne
		substr(ADMIN_PATH, strlen(WB_PATH)+1),
520 1484 Luisehahne
		MEDIA_DIRECTORY,
521 1525 Luisehahne
		PAGES_DIRECTORY,
522 1533 Luisehahne
		'/framework',
523
		'/modules',
524
		'/templates'
525 1484 Luisehahne
	);
526
527 1532 Luisehahne
	foreach( $filesRemove as $filesId )
528 1484 Luisehahne
	{
529 1532 Luisehahne
		$msg = '';
530
		foreach( $filesId as $file )
531
		{
532
			$file = str_replace($searches, $replacements, $file);
533
			$file = WB_PATH.'/'.$file;
534 1588 darkviper
			if( file_exists($file) ) {
535
				// try to unlink file
536
				if(!is_writable( $file ) || !unlink($file)) {
537
					// save in err-list, if failed
538 1532 Luisehahne
					$msg .= $file.'<br />';
539
				}
540 1484 Luisehahne
			}
541
		}
542 1532 Luisehahne
543
		if($msg != '')
544
		{
545
			$msg = '<br /><br />Following files are deprecated, outdated or a security risk and
546
				    can not be removed automatically.<br /><br />Please delete them
547
					using FTP and restart upgrade-script!<br /><br />'.$msg.'<br />';
548
	        status_msg($msg, 'error warning', 'div');
549
			echo '<p style="font-size:120%;"><strong>WARNING: The upgrade script failed ...</strong></p>';
550
551
			echo '<form action="'.$_SERVER['SCRIPT_NAME'].'">';
552
			echo '&nbsp;<input name="send" type="submit" value="Restart upgrade script" />';
553
			echo '</form>';
554
			echo '<br /><br /></div></body></html>';
555
			exit;
556
		}
557 1484 Luisehahne
	}
558
559 1532 Luisehahne
560 1457 Luisehahne
/**********************************************************
561 1525 Luisehahne
 * - check for deprecated / never needed files
562
 */
563 1588 darkviper
	if(sizeof($dirRemove)) {
564
		echo '<h2>Step  '.(++$stepID).': Remove deprecated and old folders</h2>';
565
		$searches = array(
566
			'[ADMIN]',
567
			'[MEDIA]',
568
			'[PAGES]',
569
			'[TEMPLATE]'
570
		);
571
		$replacements = array(
572
			substr(ADMIN_PATH, strlen(WB_PATH)+1),
573
			MEDIA_DIRECTORY,
574
			PAGES_DIRECTORY,
575
			'/templates',
576
		);
577
		$msg = '';
578
		foreach( $dirRemove as $dir ) {
579
			$dir = str_replace($searches, $replacements, $dir);
580
			$dir = WB_PATH.'/'.$dir;
581
			if( is_dir( $dir )) {
582
			// try to delete dir
583
				if(!rm_full_dir($dir)) {
584
				// save in err-list, if failed
585
					$msg .= $dir.'<br />';
586
				}
587 1525 Luisehahne
			}
588
		}
589 1588 darkviper
		if($msg != '') {
590
			$msg = '<br /><br />Following files are deprecated, outdated or a security risk and
591
					can not be removed automatically.<br /><br />Please delete them
592
					using FTP and restart upgrade-script!<br /><br />'.$msg.'<br />';
593
			status_msg($msg, 'error warning', 'div');
594
			echo '<p style="font-size:120%;"><strong>WARNING: The upgrade script failed ...</strong></p>';
595
			echo '<form action="'.$_SERVER['SCRIPT_NAME'].'">';
596
			echo '&nbsp;<input name="send" type="submit" value="Restart upgrade script" />';
597
			echo '</form>';
598
			echo '<br /><br /></div></body></html>';
599
			exit;
600
		}
601 1525 Luisehahne
	}
602 1532 Luisehahne
603 1588 darkviper
/**********************************************************
604
 * upgrade modules if newer version is available
605
 */
606
	$aModuleList = array('news');
607
	foreach($aModuleList as $sModul) {
608
		if(file_exists(WB_PATH.'/modules/'.$sModul.'/upgrade.php')) {
609
			$currModulVersion = get_modul_version ($sModul, false);
610
			$newModulVersion =  get_modul_version ($sModul, true);
611
			if((version_compare($currModulVersion, $newModulVersion) <= 0)) {
612
				echo '<h2>Step '.(++$stepID).' : Upgrade module \''.$sModul.'\' to version '.$newModulVersion.'</h2>';
613
				require_once(WB_PATH.'/modules/'.$sModul.'/upgrade.php');
614
			}
615
		}
616 1525 Luisehahne
	}
617
/**********************************************************
618 1457 Luisehahne
 *  - Reload all addons
619
 */
620
621 1588 darkviper
	echo '<h2>Step '.(++$stepID).' : Reload all addons database entry (no upgrade)</h2>';
622
	////delete modules
623
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'module'");
624
	// Load all modules
625
	if( ($handle = opendir(WB_PATH.'/modules/')) ) {
626
		while(false !== ($file = readdir($handle))) {
627
			if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'admin.php' AND $file != 'index.php') {
628
				load_module(WB_PATH.'/modules/'.$file );
629
			   // 	upgrade_module($file, true);
630
			}
631 1457 Luisehahne
		}
632 1588 darkviper
		closedir($handle);
633 1457 Luisehahne
	}
634 1588 darkviper
	echo '<br />Modules reloaded<br />';
635 1457 Luisehahne
636 1588 darkviper
	////delete templates
637
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'template'");
638
	// Load all templates
639
	if( ($handle = opendir(WB_PATH.'/templates/')) ) {
640
		while(false !== ($file = readdir($handle))) {
641
			if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
642
				load_template(WB_PATH.'/templates/'.$file);
643
			}
644 1457 Luisehahne
		}
645 1588 darkviper
		closedir($handle);
646 1457 Luisehahne
	}
647 1588 darkviper
	echo '<br />Templates reloaded<br />';
648 1457 Luisehahne
649 1588 darkviper
	////delete languages
650
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'language'");
651
	// Load all languages
652
	if( ($handle = opendir(WB_PATH.'/languages/')) ) {
653
		while(false !== ($file = readdir($handle))) {
654
			if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
655
				load_language(WB_PATH.'/languages/'.$file);
656
			}
657 1457 Luisehahne
		}
658 1588 darkviper
		closedir($handle);
659 1457 Luisehahne
	}
660 1588 darkviper
	echo '<br />Languages reloaded<br />';
661 1457 Luisehahne
662
/**********************************************************
663
 *  - End of upgrade script
664
 */
665
666
// require(WB_PATH.'/framework/initialize.php');
667
668 1588 darkviper
	if(!defined('DEFAULT_THEME')) { define('DEFAULT_THEME', $DEFAULT_THEME); }
669
	if(!defined('THEME_PATH')) { define('THEME_PATH', WB_PATH.'/templates/'.DEFAULT_THEME);}
670 1532 Luisehahne
/**********************************************************
671
 *  - Set Version to new Version
672
 */
673 1588 darkviper
	echo '<br />Update database version number to '.VERSION.' '.SP.' '.' Revision ['.REVISION.'] : ';
674
	// echo ($database->query("UPDATE `".TABLE_PREFIX."settings` SET `value`='".VERSION."' WHERE `name` = 'wb_version'")) ? " $OK<br />" : " $FAIL<br />";
675
	db_update_key_value('settings', 'wb_version', VERSION);
676
	db_update_key_value('settings', 'wb_revision', REVISION);
677
	db_update_key_value('settings', 'wb_sp', SP);
678 1457 Luisehahne
679 1588 darkviper
	echo '<p style="font-size:120%;"><strong>Congratulations: The upgrade script is finished ...</strong></p>';
680
	status_msg('<strong>Warning:</strong><br />Please delete the file <strong>upgrade-script.php</strong> via FTP before proceeding.', 'warning', 'div');
681
	// show buttons to go to the backend or frontend
682
	echo '<br />';
683 1532 Luisehahne
684 1588 darkviper
	if(defined('WB_URL')) {
685
		echo '<form action="'.WB_URL.'/">';
686
		echo '&nbsp;<input type="submit" value="kick me to the Frontend" />';
687
		echo '</form>';
688
	}
689
	if(defined('ADMIN_URL')) {
690
		echo '<form action="'.ADMIN_URL.'/">';
691
		echo '&nbsp;<input type="submit" value="kick me to the Backend" />';
692
		echo '</form>';
693
	}
694 1457 Luisehahne
695 1588 darkviper
	echo '<br /><br /></div></body></html>';