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 1525 2011-11-15 12:37:48Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/upgrade-script.php $
14
 * @lastmodified    $Date: 2011-11-15 13:37:48 +0100 (Tue, 15 Nov 2011) $
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><br />';
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

    
52
$dir2remove = array(
53
/*
54
			'[TEMPLATE]/allcss/',
55
			'[TEMPLATE]/blank/',
56
			'[TEMPLATE]/round/',
57
			'[TEMPLATE]/simple/',
58
*/
59
		 );
60

    
61
$files2remove = array(
62

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

    
67
		 );
68

    
69

    
70
// analyze/check database tables
71
function mysqlCheckTables( $dbName )
72
{
73
    global $table_list;
74
    $table_prefix = TABLE_PREFIX;
75
    $sql = "SHOW TABLES FROM " . $dbName;
76
    $result = @mysql_query( $sql );
77
    $data = array();
78
    $x = 0;
79

    
80
    while( ( $row = @mysql_fetch_array( $result, MYSQL_NUM ) ) == true )
81
    {
82
        $tmp = str_replace($table_prefix, '', $row[0]);
83

    
84
        if( stristr( $row[0], $table_prefix )&& in_array($tmp,$table_list) )
85
        {
86
            $sql = "CHECK TABLE " . $dbName . '.' . $row[0];
87
            $analyze = @mysql_query( $sql );
88
            $rowFetch = @mysql_fetch_array( $analyze, MYSQL_ASSOC );
89
            $data[$x]['Op'] = $rowFetch["Op"];
90
            $data[$x]['Msg_type'] = $rowFetch["Msg_type"];
91
            $msgColor = '<span class="error">';
92
            $data[$x]['Table'] = $row[0];
93
           // print  " ";
94
            $msgColor = ($rowFetch["Msg_text"] == 'OK') ? '<span class="ok">' : '<span class="error">';
95
            $data[$x]['Msg_text'] = $msgColor.$rowFetch["Msg_text"].'</span>';
96
           // print  "<br />";
97
            $x++;
98
        }
99
    }
100
    return $data;
101
}
102

    
103
// check existings tables for upgrade or install
104
function check_wb_tables()
105
{
106
    global $database,$table_list;
107

    
108
 // if prefix inludes '_' or '%'
109
 $search_for = addcslashes ( TABLE_PREFIX, '%_' );
110
 $get_result = $database->query( 'SHOW TABLES LIKE "'.$search_for.'%"');
111

    
112
        // $get_result = $database->query( "SHOW TABLES FROM ".DB_NAME);
113
        $all_tables = array();
114
        if($get_result->numRows() > 0)
115
        {
116
            while ($data = $get_result->fetchRow())
117
            {
118
                $tmp = str_replace(TABLE_PREFIX, '', $data[0]);
119
                if(in_array($tmp,$table_list))
120
                {
121
                    $all_tables[] = $tmp;
122
                }
123
            }
124
        }
125
     return $all_tables;
126
}
127

    
128
// check existing tables
129
$all_tables = check_wb_tables();
130

    
131
?>
132
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
133
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
134
<head>
135
<title>Upgrade script</title>
136
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
137
<style type="text/css">
138
html { overflow: -moz-scrollbars-vertical; /* Force firefox to always show room for a vertical scrollbar */ }
139

    
140
body {
141
	margin:0;
142
	padding:0;
143
	border:0;
144
	background: #EBF7FC;
145
	color:#000;
146
	font-family: 'Trebuchet MS', Verdana, Arial, Helvetica, Sans-Serif;
147
	font-size: small;
148
	height:101%;
149
}
150

    
151
#container {
152
	width:85%;
153
	background: #A8BCCB url(templates/wb_theme/images/background.png) repeat-x;
154
	border:1px solid #000;
155
	color:#000;
156
	margin:2em auto;
157
	padding:0 15px;
158
	min-height: 500px;
159
	text-align:left;
160
}
161

    
162
p { line-height:1.5em; }
163

    
164
h1,h2,h3,h4,h5,h6 {
165
	font-family: Verdana, Arial, Helvetica, sans-serif;
166
	color: #369;
167
	margin-top: 1.0em;
168
	margin-bottom: 0.1em;
169
}
170

    
171
h1 { font-size:150%; }
172
h2 { font-size: 130%; border-bottom: 1px #CCC solid; }
173
h3 { font-size: 120%; }
174

    
175
.ok, .error { font-weight:bold; }
176
.ok { color:green; }
177
.error { color:red; }
178
.check { color:#555; }
179

    
180
.warning {
181
	width: 98%;
182
	background:#FFDBDB;
183
	padding:0.2em;
184
	margin-top:0.5em;
185
	border: 1px solid black;
186
}
187
.info {
188
	width: 98%;
189
	background:#99CC99;
190
	padding:0.2em;
191
	margin-top:0.5em;
192
	border: 1px solid black;
193
}
194

    
195
</style>
196
</head>
197
<body>
198
<div id="container">
199
<img src="templates/wb_theme/images/logo.png" alt="WebsiteBaker Project" />
200
<h1>WebsiteBaker Upgrade</h1>
201
<?php
202
	if( version_compare( WB_VERSION, '2.7', '<' )) {
203
		status_msg('<strong>Warning:</strong><br />It is not possible to upgrade from WebsiteBaker Versions before 2.7.0.<br />For upgrading to version '.VERSION.' you must upgrade first to v.2.7 at least!!!', 'warning', 'div');
204
		echo '<br /><br />';
205
		echo "</div>
206
		</body>
207
		</html>
208
		";
209
		exit();
210
	}
211
?>
212
<p>This script upgrades an existing WebsiteBaker <strong>Version <?php echo WB_VERSION; ?></strong> installation to the <strong>Version <?php echo VERSION ?></strong>. The upgrade script alters the existing WB database to reflect the changes introduced with WB 2.8.x</p>
213

    
214
<?php
215
/**
216
 * Check if disclaimer was accepted
217
 */
218
if (!(isset($_POST['backup_confirmed']) && $_POST['backup_confirmed'] == 'confirmed')) { ?>
219
<h2>Step 1: Backup your files</h2>
220
<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>
221

    
222
<form name="send" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
223
<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>
224
<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.
225
<br /><br /><input name="send" type="submit" value="Start upgrade script" />
226
</form>
227
<br />
228

    
229
<?php
230
	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');
231
	echo '<br /><br />';
232
    echo "</div>
233
    </body>
234
    </html>
235
    ";
236
	exit();
237
}
238
echo '<h2>Step 2: Updating database entries</h2>';
239

    
240
// function to add a var/value-pair into settings-table
241
function db_add_key_value($key, $value) {
242
	global $database; global $OK; global $FAIL;
243
	$table = TABLE_PREFIX.'settings';
244
	$query = $database->query("SELECT value FROM $table WHERE name = '$key' LIMIT 1");
245
	if($query->numRows() > 0) {
246
		echo "$key: already exists. $OK.<br />";
247
		return true;
248
	} else {
249
		$database->query("INSERT INTO $table (name,value) VALUES ('$key', '$value')");
250
		echo (mysql_error()?mysql_error().'<br />':'');
251
		$query = $database->query("SELECT value FROM $table WHERE name = '$key' LIMIT 1");
252
		if($query->numRows() > 0) {
253
			echo "$key: $OK.<br />";
254
			return true;
255
		} else {
256
			echo "$key: $FAIL!<br />";
257
			return false;
258
		}
259
	}
260
}
261

    
262
// function to add a new field into a table
263
function db_add_field($field, $table, $desc) {
264
	global $database; global $OK; global $FAIL;
265
	$table = TABLE_PREFIX.$table;
266
	$query = $database->query("DESCRIBE $table '$field'");
267
	if($query->numRows() == 0) { // add field
268
		$query = $database->query("ALTER TABLE $table ADD $field $desc");
269
		echo (mysql_error()?mysql_error().'<br />':'');
270
		$query = $database->query("DESCRIBE $table '$field'");
271
		echo (mysql_error()?mysql_error().'<br />':'');
272
		if($query->numRows() > 0) {
273
			echo "'$field' added. $OK.<br />";
274
		} else {
275
			echo "adding '$field' $FAIL!<br />";
276
		}
277
	} else {
278
		echo "'$field' already exists. $OK.<br />";
279
	}
280
}
281

    
282
/**********************************************************
283
 *  - Adding field default_theme to settings table
284
 */
285
echo "<br />Adding default_theme to settings table<br />";
286
db_update_key_value('settings', 'default_theme', $DEFAULT_THEME);
287
/*
288
$cfg = array(
289
	'default_theme' => 'wb_theme'
290
);
291
foreach($cfg as $key=>$value) {
292
	db_add_key_value($key, $value);
293
}
294
*/
295
/**********************************************************
296
 *  - install droplets
297
 */
298
    $drops = (!in_array ( "mod_droplets", $all_tables)) ? "<br />Install droplets<br />" : "<br />Upgrade droplets<br />";
299
    echo $drops;
300

    
301
     $file_name = (!in_array ( "mod_droplets", $all_tables)) ? "install.php" : "upgrade.php";
302
     require_once (WB_PATH."/modules/droplets/".$file_name);
303

    
304
// check again all tables, to get a new array
305
 if(sizeof($all_tables) < 22) { $all_tables = check_wb_tables(); }
306
/**********************************************************
307
 *  - check tables comin with WebsiteBaker
308
 */
309
    $check_text = 'total ';
310
    // $check_tables = mysqlCheckTables( DB_NAME ) ;
311

    
312
    if(sizeof($all_tables) == 22)
313
    {
314
        echo '<h4>NOTICE: Your database '.DB_NAME.' has '.sizeof($all_tables).' '.$check_text.' tables from '.sizeof($table_list).' included in package '.$OK.'</h4>';
315
    }
316
    else
317
    {
318
        status_msg('<strong>WARNING:</strong><br />can\'t run Upgrade, missing tables', 'warning', 'div');
319
    	echo '<h4>Missing required tables. You can install them in backend->addons->modules->advanced. Then again run upgrade-script.php</h4>';
320
        $result = array_diff ( $table_list, $all_tables );
321
        echo '<h4 class="warning"><br />';
322
        while ( list ( $key, $val ) = each ( $result ) )
323
        {
324
            echo TABLE_PREFIX.$val.' '.$FAIL.'<br>';
325
        }
326
        echo '<br /></h4>';
327
    	echo '<br /><form action="'. $_SERVER['PHP_SELF'] .'">';
328
    	echo '<input type="submit" value="kick me back" style="float:left;" />';
329
    	echo '</form>';
330
        if(defined('ADMIN_URL'))
331
        {
332
        	echo '<form action="'.ADMIN_URL.'" target="_self">';
333
        	echo '&nbsp;<input type="submit" value="kick me to the Backend" />';
334
        	echo '</form>';
335
        }
336
        echo "<br /><br /></div>
337
        </body>
338
        </html>
339
        ";
340
        exit();
341
    }
342

    
343
/**********************************************************
344
 *  - Adding field sec_anchor to settings table
345
 */
346
echo "<br />Adding sec_anchor to settings table<br />";
347
$cfg = array(
348
	'sec_anchor' => 'wb_'
349
);
350
foreach($cfg as $key=>$value) {
351
	db_add_key_value($key, $value);
352
}
353

    
354
/**********************************************************
355
 *  - Adding redirect timer to settings table
356
 */
357
echo "<br />Adding redirect timer to settings table<br />";
358
$cfg = array(
359
	'redirect_timer' => '1500'
360
);
361
foreach($cfg as $key=>$value) {
362
	db_add_key_value($key, $value);
363
}
364

    
365
/**********************************************************
366
 *  - Adding mediasettings to settings table
367
 */
368
echo "<br />Adding mediasettings to settings table<br />";
369
$cfg = array(
370
	'mediasettings' => '',
371
	'rename_files_on_upload' => 'ph.*?,cgi,pl,pm,exe,com,bat,pif,cmd,src,asp,aspx,js'
372
);
373
db_update_key_value('settings', 'rename_files_on_upload', $cfg['rename_files_on_upload']);
374

    
375
foreach($cfg as $key=>$value) {
376
	db_add_key_value($key, $value);
377
}
378

    
379
/**********************************************************
380
 *  - Adding fingerprint_with_ip_octets to settings table
381
 */
382
echo "<br />Adding fingerprint_with_ip_octets to settings table<br />";
383
$cfg = array(
384
	'fingerprint_with_ip_octets' => '2',
385
	'secure_form_module' => ''
386
);
387
foreach($cfg as $key=>$value) {
388
	db_add_key_value($key, $value);
389
}
390

    
391
/**********************************************************
392
 *  - Add field "redirect_type" to table "mod_menu_link"
393
 */
394
echo "<br />Adding field redirect_type to mod_menu_link table<br />";
395
db_add_field('redirect_type', 'mod_menu_link', "INT NOT NULL DEFAULT '302' AFTER `target_page_id`");
396

    
397
if (version_compare(WB_VERSION, '2.8') < 0)
398
{
399
    /**********************************************************
400
     *  - Update search no results database filed to create
401
     *  valid XHTML if search is empty
402
     */
403
    echo "<br />Updating database field `no_results` of search table: ";
404
    $search_no_results = addslashes('<tr><td><p>[TEXT_NO_RESULTS]</p></td></tr>');
405
    $sql = "UPDATE `" . TABLE_PREFIX . "search` SET `value` = '$search_no_results' WHERE `name`= 'no_results'";
406
    $database->query($sql);
407
    echo ($database->query($sql)) ? " $OK<br />" : " $FAIL<br />";
408
    /**********************************************************
409
     *  - Update settings of News Modul
410
     */
411

    
412
    // These are the default setting
413
    $header = '<table cellpadding=\"0\" cellspacing=\"0\" class=\"loop-header\">'."\n";
414
    $post_loop = '<tr class=\"post_top\">
415
<td class=\"post_title\"><a href=\"[LINK]\">[TITLE]</a></td>
416
<td class=\"post_date\">[PUBLISHED_TIME], [PUBLISHED_DATE]</td>
417
</tr>
418
<tr>
419
<td class=\"post_short\" colspan=\"2\">
420
[SHORT]
421
<span style=\"visibility:[SHOW_READ_MORE];\"><a href=\"[LINK]\">[TEXT_READ_MORE]</a></span>
422
</td>
423
</tr>';
424
    $footer = '</table>
425
<table cellpadding="0" cellspacing="0" class="page-header" style="display: [DISPLAY_PREVIOUS_NEXT_LINKS]">
426
<tr>
427
<td class="page-left">[PREVIOUS_PAGE_LINK]</td>
428
<td class="page-center">[OF]</td>
429
<td class="page-right">[NEXT_PAGE_LINK]</td>
430
</tr>
431
</table>';
432
    $post_header = addslashes('<table cellpadding="0" cellspacing="0" class="post-header">
433
<tr>
434
<td><h1>[TITLE]</h1></td>
435
<td rowspan="3" style="display: [DISPLAY_IMAGE]">[GROUP_IMAGE]</td>
436
</tr>
437
<tr>
438
<td class="public-info"><b>[TEXT_POSTED_BY] [DISPLAY_NAME] ([USERNAME]) [TEXT_ON] [PUBLISHED_DATE]</b></td>
439
</tr>
440
<tr style="display: [DISPLAY_GROUP]">
441
<td class="group-page"><a href="[BACK]">[PAGE_TITLE]</a> &gt;&gt; <a href="[BACK]?g=[GROUP_ID]">[GROUP_TITLE]</a></td>
442
</tr>
443
</table>');
444
    $post_footer = '<p>[TEXT_LAST_CHANGED]: [MODI_DATE] [TEXT_AT] [MODI_TIME]</p>
445
<a href=\"[BACK]\">[TEXT_BACK]</a>';
446
    $comments_header = addslashes('<br /><br />
447
<h2>[TEXT_COMMENTS]</h2>
448
<table cellpadding="2" cellspacing="0" class="comment-header">');
449
    $comments_loop = addslashes('<tr>
450
<td class="comment_title">[TITLE]</td>
451
<td class="comment_info">[TEXT_BY] [DISPLAY_NAME] [TEXT_ON] [DATE] [TEXT_AT] [TIME]</td>
452
</tr>
453
<tr>
454
<td colspan="2" class="comment_text">[COMMENT]</td>
455
</tr>');
456
    $comments_footer = '</table>
457
<br /><a href=\"[ADD_COMMENT_URL]\">[TEXT_ADD_COMMENT]</a>';
458
    $comments_page = '<h1>[TEXT_COMMENT]</h1>
459
<h2>[POST_TITLE]</h2>
460
<br />';
461

    
462
	if(in_array('mod_news_settings', $all_tables))
463
	{
464
	   // Insert default settings into database
465
	   $query_dates = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_settings where section_id != 0 and page_id != 0");
466
	   if($query_dates->numRows() > 1)
467
	   {
468
	        while($result = $query_dates->fetchRow())
469
	        {
470

    
471
	        	echo "<br /><u>Add default settings to database for news section_id= ".$result['section_id']."</u><br />";
472
	        	$section_id = $result['section_id'];
473

    
474
	        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `header` = '$header' WHERE `section_id` = $section_id")) {
475
	        		echo 'Database data header added successfully';
476
	        	}
477
	        	echo mysql_error().'<br />';
478

    
479
	        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_loop` = '$post_loop' WHERE `section_id` = $section_id")) {
480
	        		echo 'Database data post_loop added successfully';
481
	        	}
482
	        	echo mysql_error().'<br />';
483

    
484
	        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `footer` = '$footer' WHERE `section_id` = $section_id")) {
485
	        		echo 'Database data footer added successfully';
486
	        	}
487
	        	echo mysql_error().'<br />';
488

    
489
	        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_header` = '$post_header' WHERE `section_id` = $section_id")) {
490
	        		echo 'Database data post_header added successfully';
491
	        	}
492
	        	echo mysql_error().'<br />';
493

    
494
	        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_footer` = '$post_footer' WHERE `section_id` = $section_id")) {
495
	        		echo 'Database data post_footer added successfully';
496
	        	}
497
	        	echo mysql_error().'<br />';
498

    
499
	        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `comments_header` = '$comments_header' WHERE `section_id` = $section_id")) {
500
	        		echo 'Database data comments_header added successfully';
501
	        	}
502
	        	echo mysql_error().'<br />';
503

    
504
	        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `comments_loop` = '$comments_loop' WHERE `section_id` = $section_id")) {
505
	        		echo 'Database data comments_loop added successfully';
506
	        	}
507
	        	echo mysql_error().'<br />';
508

    
509
	        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `comments_footer` = '$comments_footer' WHERE `section_id` = $section_id")) {
510
	        		echo 'Database data comments_footer added successfully';
511
	        	}
512
	        	echo mysql_error().'<br />';
513

    
514
	        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `comments_page` = '$comments_page' WHERE `section_id` = $section_id")) {
515
	        		echo 'Database data comments_page added successfully';
516
	        	}
517
	        	echo mysql_error().'<br />';
518

    
519
	        }
520
	     }
521
	   }
522
}
523
/**********************************************************
524
 * upgrade media folder index protect files
525
 */
526
$dir = (WB_PATH.MEDIA_DIRECTORY);
527
echo '<h4>Upgrade '.MEDIA_DIRECTORY.'/ index.php protect files</h4><br />';
528
$array = rebuildFolderProtectFile($dir);
529
if( sizeof( $array ) ){
530
	print '<br /><strong>Upgrade '.sizeof( $array ).' '.MEDIA_DIRECTORY.'/ protect files</strong>'." $OK<br />";
531
} else {
532
	print '<br /><strong>Upgrade '.MEDIA_DIRECTORY.'/ protect files</strong>'." $FAIL!<br />";
533
	print implode ('<br />',$array);
534
}
535

    
536
/**********************************************************
537
 * upgrade news if newer version is available
538
 */
539
	if(file_exists(WB_PATH.'/modules/news/upgrade.php'))
540
	{
541
		$currNewsVersion = get_modul_version ('news', false);
542
		$newNewsVersion =  get_modul_version ('news', true);
543
		if((version_compare($currNewsVersion, $newNewsVersion) <= 0)) {
544
			echo '<h4>Upgrade existings basically news module</h4><br />';
545
			// change old postfiles to new postfiles
546
			require_once(WB_PATH."/modules/news/upgrade.php");
547
		}
548
	}
549
/**********************************************************
550
 *  - Set Version to new Version
551
 */
552
echo '<br />Update database version number to '.VERSION.' : ';
553
// echo ($database->query("UPDATE `".TABLE_PREFIX."settings` SET `value`='".VERSION."' WHERE `name` = 'wb_version'")) ? " $OK<br />" : " $FAIL<br />";
554
db_update_key_value('settings', 'wb_version', VERSION);
555

    
556
/* *****************************************************************************
557
 * - check for deprecated / never needed files
558
 */
559
?>
560
<h2>Step 3: Remove deprecated and old files</h2>
561
<?php
562

    
563
	$searches = array(
564
		'[ADMIN]',
565
		'[MEDIA]',
566
		'[PAGES]',
567
		'[TEMPLATE]'
568
	);
569
	$replacements = array(
570
		substr(ADMIN_PATH, strlen(WB_PATH)+1),
571
		MEDIA_DIRECTORY,
572
		PAGES_DIRECTORY,
573
		'/templates',
574
	);
575

    
576
	$msg = '';
577
	foreach( $files2remove as $file )
578
	{
579
		$file = str_replace($searches, $replacements, $file);
580
		$file = WB_PATH.'/'.$file;
581
		if( file_exists( $file ))
582
		{ // try to unlink file
583
			if(!unlink($file))
584
			{ // save in err-list, if failed
585
				$msg .= $file.'<br />';
586
			}
587
		}
588
	}
589

    
590
	if($msg != '')
591
	{
592
		$msg = 'Following files are deprecated, outdated or a security risk and
593
			    can not be removed automatically.<br /><br />Please delete them
594
				using FTP and restart upgrade-script!<br /><br />'.$msg;
595
        status_msg($msg, 'error warning', 'div');
596
		echo '<br /><br /><br /><br /></div></body></html>';
597
		exit();
598
	}
599
/**********************************************************
600
 * - check for deprecated / never needed files
601
 */
602
?>
603
<h2>Step 4: Remove deprecated and old Templates</h2>
604
<?php
605

    
606
	$searches = array(
607
		'[ADMIN]',
608
		'[MEDIA]',
609
		'[PAGES]',
610
		'[TEMPLATE]'
611
	);
612
	$replacements = array(
613
		substr(ADMIN_PATH, strlen(WB_PATH)+1),
614
		MEDIA_DIRECTORY,
615
		PAGES_DIRECTORY,
616
		'/templates',
617
	);
618

    
619
	$msg = '';
620
	foreach( $dir2remove as $dir )
621
	{
622
		$dir = str_replace($searches, $replacements, $dir);
623
		$dir = WB_PATH.'/'.$dir;
624
		if( is_dir( $dir ))
625
		{ // try to delete dir
626
			if(!rm_full_dir($dir))
627
			{ // save in err-list, if failed
628
				$msg .= $dir.'<br />';
629
			}
630
		}
631
	}
632
	if($msg != '')
633
	{
634
		$msg = 'Following directories are deprecated, outdated or a security risk and
635
			    can not be removed automatically.<br /><br />Please delete them
636
				using FTP!<br /><br />'.$msg;
637
        status_msg($msg, 'error warning', 'div');
638
		echo '<br /><br /><br /><br /></div>';
639
	}
640
/**********************************************************
641
 *  - Reload all addons
642
 */
643

    
644
////delete modules
645
//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'module'");
646
// Load all modules
647
if( ($handle = opendir(WB_PATH.'/modules/')) ) {
648
	while(false !== ($file = readdir($handle))) {
649
		if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'admin.php' AND $file != 'index.php') {
650
			load_module(WB_PATH.'/modules/'.$file );
651
		   // 	upgrade_module($file, true);
652
		}
653
	}
654
	closedir($handle);
655
}
656
echo '<br />Modules reloaded<br />';
657

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

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

    
684

    
685
/**********************************************************
686
 *  - End of upgrade script
687
 */
688

    
689
// require(WB_PATH.'/framework/initialize.php');
690

    
691
if(!defined('DEFAULT_THEME')) { define('DEFAULT_THEME', $DEFAULT_THEME); }
692
if(!defined('THEME_PATH')) { define('THEME_PATH', WB_PATH.'/templates/'.DEFAULT_THEME);}
693

    
694
echo '<p style="font-size:120%;"><strong>Congratulations: The upgrade script is finished ...</strong></p>';
695
status_msg('<strong>Warning:</strong><br />Please delete the file <strong>upgrade-script.php</strong> via FTP before proceeding.', 'warning', 'div');
696
// show buttons to go to the backend or frontend
697
echo '<br />';
698
if(defined('WB_URL')) {
699
	echo '<form action="'.WB_URL.'">';
700
	echo '<input type="submit" value="kick me to the Frontend" style="float:left;" />';
701
	echo '</form>';
702
}
703
if(defined('ADMIN_URL')) {
704
	echo '<form action="'.ADMIN_URL.'">';
705
	echo '&nbsp;<input type="submit" value="kick me to the Backend" />';
706
	echo '</form>';
707
}
708
echo '<p>&nbsp;</p>';
709

    
710
?>
711
</div>
712
</body>
713
</html>
(6-6/7)