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 1529 2011-11-25 05:03:32Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/upgrade-script.php $
14
 * @lastmodified    $Date: 2011-11-25 06:03:32 +0100 (Fri, 25 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
			'[TEMPLATE]/argos_theme/templates/access.htt',
68
			'[TEMPLATE]/argos_theme/templates/addons.htt',
69
			'[TEMPLATE]/argos_theme/templates/admintools.htt',
70
			'[TEMPLATE]/argos_theme/templates/error.htt',
71
			'[TEMPLATE]/argos_theme/templates/groups.htt',
72
			'[TEMPLATE]/argos_theme/templates/groups_form.htt',
73
			'[TEMPLATE]/argos_theme/templates/languages.htt',
74
			'[TEMPLATE]/argos_theme/templates/languages_details.htt',
75
			'[TEMPLATE]/argos_theme/templates/login.htt',
76
			'[TEMPLATE]/argos_theme/templates/login_forgot.htt',
77
			'[TEMPLATE]/argos_theme/templates/media.htt',
78
			'[TEMPLATE]/argos_theme/templates/media_browse.htt',
79
			'[TEMPLATE]/argos_theme/templates/media_rename.htt',
80
			'[TEMPLATE]/argos_theme/templates/modules.htt',
81
			'[TEMPLATE]/argos_theme/templates/modules_details.htt',
82
			'[TEMPLATE]/argos_theme/templates/pages.htt',
83
			'[TEMPLATE]/argos_theme/templates/pages_modify.htt',
84
			'[TEMPLATE]/argos_theme/templates/pages_sections.htt',
85
			'[TEMPLATE]/argos_theme/templates/pages_settings.htt',
86
			'[TEMPLATE]/argos_theme/templates/preferences.htt',
87
			'[TEMPLATE]/argos_theme/templates/setparameter.htt',
88
			'[TEMPLATE]/argos_theme/templates/settings.htt',
89
			'[TEMPLATE]/argos_theme/templates/start.htt',
90
			'[TEMPLATE]/argos_theme/templates/success.htt',
91
			'[TEMPLATE]/argos_theme/templates/templates.htt',
92
			'[TEMPLATE]/argos_theme/templates/templates_details.htt',
93
			'[TEMPLATE]/argos_theme/templates/users.htt',
94
			'[TEMPLATE]/argos_theme/templates/users_form.htt',
95

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

    
125
		 );
126

    
127

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

    
138
    while( ( $row = @mysql_fetch_array( $result, MYSQL_NUM ) ) == true )
139
    {
140
        $tmp = str_replace($table_prefix, '', $row[0]);
141

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

    
161
// check existings tables for upgrade or install
162
function check_wb_tables()
163
{
164
    global $database,$table_list;
165

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

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

    
186
// check existing tables
187
$all_tables = check_wb_tables();
188

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

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

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

    
220
p { line-height:1.5em; }
221

    
222
h1,h2,h3,h4,h5,h6 {
223
	font-family: Verdana, Arial, Helvetica, sans-serif;
224
	color: #369;
225
	margin-top: 1.0em;
226
	margin-bottom: 0.1em;
227
}
228

    
229
h1 { font-size:150%; }
230
h2 { font-size: 130%; border-bottom: 1px #CCC solid; }
231
h3 { font-size: 120%; }
232

    
233
.ok, .error { font-weight:bold; }
234
.ok { color:green; }
235
.error { color:red; }
236
.check { color:#555; }
237

    
238
.warning {
239
	width: 98%;
240
	background:#FFDBDB;
241
	padding:0.2em;
242
	margin-top:0.5em;
243
	border: 1px solid black;
244
}
245
.info {
246
	width: 98%;
247
	background:#99CC99;
248
	padding:0.2em;
249
	margin-top:0.5em;
250
	border: 1px solid black;
251
}
252

    
253
</style>
254
</head>
255
<body>
256
<div id="container">
257
<img src="templates/wb_theme/images/logo.png" alt="WebsiteBaker Project" />
258
<h1>WebsiteBaker Upgrade</h1>
259
<?php
260
	if( version_compare( WB_VERSION, '2.7', '<' )) {
261
		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');
262
		echo '<br /><br />';
263
		echo "</div>
264
		</body>
265
		</html>
266
		";
267
		exit();
268
	}
269
?>
270
<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>
271

    
272
<?php
273
/**
274
 * Check if disclaimer was accepted
275
 */
276
if (!(isset($_POST['backup_confirmed']) && $_POST['backup_confirmed'] == 'confirmed')) { ?>
277
<h2>Step 1: Backup your files</h2>
278
<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>
279

    
280
<form name="send" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
281
<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>
282
<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.
283
<br /><br /><input name="send" type="submit" value="Start upgrade script" />
284
</form>
285
<br />
286

    
287
<?php
288
	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');
289
	echo '<br /><br />';
290
    echo "</div>
291
    </body>
292
    </html>
293
    ";
294
	exit();
295
}
296
echo '<h2>Step 2: Updating database entries</h2>';
297

    
298
// function to add a var/value-pair into settings-table
299
function db_add_key_value($key, $value) {
300
	global $database; global $OK; global $FAIL;
301
	$table = TABLE_PREFIX.'settings';
302
	$query = $database->query("SELECT value FROM $table WHERE name = '$key' LIMIT 1");
303
	if($query->numRows() > 0) {
304
		echo "$key: already exists. $OK.<br />";
305
		return true;
306
	} else {
307
		$database->query("INSERT INTO $table (name,value) VALUES ('$key', '$value')");
308
		echo (mysql_error()?mysql_error().'<br />':'');
309
		$query = $database->query("SELECT value FROM $table WHERE name = '$key' LIMIT 1");
310
		if($query->numRows() > 0) {
311
			echo "$key: $OK.<br />";
312
			return true;
313
		} else {
314
			echo "$key: $FAIL!<br />";
315
			return false;
316
		}
317
	}
318
}
319

    
320
// function to add a new field into a table
321
function db_add_field($field, $table, $desc) {
322
	global $database; global $OK; global $FAIL;
323
	$table = TABLE_PREFIX.$table;
324
	$query = $database->query("DESCRIBE $table '$field'");
325
	if($query->numRows() == 0) { // add field
326
		$query = $database->query("ALTER TABLE $table ADD $field $desc");
327
		echo (mysql_error()?mysql_error().'<br />':'');
328
		$query = $database->query("DESCRIBE $table '$field'");
329
		echo (mysql_error()?mysql_error().'<br />':'');
330
		if($query->numRows() > 0) {
331
			echo "'$field' added. $OK.<br />";
332
		} else {
333
			echo "adding '$field' $FAIL!<br />";
334
		}
335
	} else {
336
		echo "'$field' already exists. $OK.<br />";
337
	}
338
}
339

    
340
/**********************************************************
341
 *  - Adding field default_theme to settings table
342
 */
343
echo "<br />Adding default_theme to settings table<br />";
344
db_update_key_value('settings', 'default_theme', $DEFAULT_THEME);
345
/*
346
$cfg = array(
347
	'default_theme' => 'wb_theme'
348
);
349
foreach($cfg as $key=>$value) {
350
	db_add_key_value($key, $value);
351
}
352
*/
353
/**********************************************************
354
 *  - install droplets
355
 */
356
    $drops = (!in_array ( "mod_droplets", $all_tables)) ? "<br />Install droplets<br />" : "<br />Upgrade droplets<br />";
357
    echo $drops;
358

    
359
     $file_name = (!in_array ( "mod_droplets", $all_tables)) ? "install.php" : "upgrade.php";
360
     require_once (WB_PATH."/modules/droplets/".$file_name);
361

    
362
// check again all tables, to get a new array
363
 if(sizeof($all_tables) < 22) { $all_tables = check_wb_tables(); }
364
/**********************************************************
365
 *  - check tables comin with WebsiteBaker
366
 */
367
    $check_text = 'total ';
368
    // $check_tables = mysqlCheckTables( DB_NAME ) ;
369

    
370
    if(sizeof($all_tables) == 22)
371
    {
372
        echo '<h4>NOTICE: Your database '.DB_NAME.' has '.sizeof($all_tables).' '.$check_text.' tables from '.sizeof($table_list).' included in package '.$OK.'</h4>';
373
    }
374
    else
375
    {
376
        status_msg('<strong>WARNING:</strong><br />can\'t run Upgrade, missing tables', 'warning', 'div');
377
    	echo '<h4>Missing required tables. You can install them in backend->addons->modules->advanced. Then again run upgrade-script.php</h4>';
378
        $result = array_diff ( $table_list, $all_tables );
379
        echo '<h4 class="warning"><br />';
380
        while ( list ( $key, $val ) = each ( $result ) )
381
        {
382
            echo TABLE_PREFIX.$val.' '.$FAIL.'<br>';
383
        }
384
        echo '<br /></h4>';
385
    	echo '<br /><form action="'. $_SERVER['PHP_SELF'] .'">';
386
    	echo '<input type="submit" value="kick me back" style="float:left;" />';
387
    	echo '</form>';
388
        if(defined('ADMIN_URL'))
389
        {
390
        	echo '<form action="'.ADMIN_URL.'" target="_self">';
391
        	echo '&nbsp;<input type="submit" value="kick me to the Backend" />';
392
        	echo '</form>';
393
        }
394
        echo "<br /><br /></div>
395
        </body>
396
        </html>
397
        ";
398
        exit();
399
    }
400

    
401
/**********************************************************
402
 *  - Adding field sec_anchor to settings table
403
 */
404
echo "<br />Adding sec_anchor to settings table<br />";
405
$cfg = array(
406
	'sec_anchor' => 'wb_'
407
);
408
foreach($cfg as $key=>$value) {
409
	db_add_key_value($key, $value);
410
}
411

    
412
/**********************************************************
413
 *  - Adding redirect timer to settings table
414
 */
415
echo "<br />Adding redirect timer to settings table<br />";
416
$cfg = array(
417
	'redirect_timer' => '1500'
418
);
419
foreach($cfg as $key=>$value) {
420
	db_add_key_value($key, $value);
421
}
422

    
423
/**********************************************************
424
 *  - Adding mediasettings to settings table
425
 */
426
echo "<br />Adding mediasettings to settings table<br />";
427
$cfg = array(
428
	'mediasettings' => '',
429
	'rename_files_on_upload' => 'ph.*?,cgi,pl,pm,exe,com,bat,pif,cmd,src,asp,aspx,js'
430
);
431
db_update_key_value('settings', 'rename_files_on_upload', $cfg['rename_files_on_upload']);
432

    
433
foreach($cfg as $key=>$value) {
434
	db_add_key_value($key, $value);
435
}
436

    
437
/**********************************************************
438
 *  - Adding fingerprint_with_ip_octets to settings table
439
 */
440
echo "<br />Adding fingerprint_with_ip_octets to settings table<br />";
441
$cfg = array(
442
	'fingerprint_with_ip_octets' => '2',
443
	'secure_form_module' => ''
444
);
445
foreach($cfg as $key=>$value) {
446
	db_add_key_value($key, $value);
447
}
448

    
449
/**********************************************************
450
 *  - Add field "redirect_type" to table "mod_menu_link"
451
 */
452
echo "<br />Adding field redirect_type to mod_menu_link table<br />";
453
db_add_field('redirect_type', 'mod_menu_link', "INT NOT NULL DEFAULT '302' AFTER `target_page_id`");
454

    
455
if (version_compare(WB_VERSION, '2.8') < 0)
456
{
457
    /**********************************************************
458
     *  - Update search no results database filed to create
459
     *  valid XHTML if search is empty
460
     */
461
    echo "<br />Updating database field `no_results` of search table: ";
462
    $search_no_results = addslashes('<tr><td><p>[TEXT_NO_RESULTS]</p></td></tr>');
463
    $sql = "UPDATE `" . TABLE_PREFIX . "search` SET `value` = '$search_no_results' WHERE `name`= 'no_results'";
464
    $database->query($sql);
465
    echo ($database->query($sql)) ? " $OK<br />" : " $FAIL<br />";
466
    /**********************************************************
467
     *  - Update settings of News Modul
468
     */
469

    
470
    // These are the default setting
471
    $header = '<table cellpadding=\"0\" cellspacing=\"0\" class=\"loop-header\">'."\n";
472
    $post_loop = '<tr class=\"post_top\">
473
<td class=\"post_title\"><a href=\"[LINK]\">[TITLE]</a></td>
474
<td class=\"post_date\">[PUBLISHED_TIME], [PUBLISHED_DATE]</td>
475
</tr>
476
<tr>
477
<td class=\"post_short\" colspan=\"2\">
478
[SHORT]
479
<span style=\"visibility:[SHOW_READ_MORE];\"><a href=\"[LINK]\">[TEXT_READ_MORE]</a></span>
480
</td>
481
</tr>';
482
    $footer = '</table>
483
<table cellpadding="0" cellspacing="0" class="page-header" style="display: [DISPLAY_PREVIOUS_NEXT_LINKS]">
484
<tr>
485
<td class="page-left">[PREVIOUS_PAGE_LINK]</td>
486
<td class="page-center">[OF]</td>
487
<td class="page-right">[NEXT_PAGE_LINK]</td>
488
</tr>
489
</table>';
490
    $post_header = addslashes('<table cellpadding="0" cellspacing="0" class="post-header">
491
<tr>
492
<td><h1>[TITLE]</h1></td>
493
<td rowspan="3" style="display: [DISPLAY_IMAGE]">[GROUP_IMAGE]</td>
494
</tr>
495
<tr>
496
<td class="public-info"><b>[TEXT_POSTED_BY] [DISPLAY_NAME] ([USERNAME]) [TEXT_ON] [PUBLISHED_DATE]</b></td>
497
</tr>
498
<tr style="display: [DISPLAY_GROUP]">
499
<td class="group-page"><a href="[BACK]">[PAGE_TITLE]</a> &gt;&gt; <a href="[BACK]?g=[GROUP_ID]">[GROUP_TITLE]</a></td>
500
</tr>
501
</table>');
502
    $post_footer = '<p>[TEXT_LAST_CHANGED]: [MODI_DATE] [TEXT_AT] [MODI_TIME]</p>
503
<a href=\"[BACK]\">[TEXT_BACK]</a>';
504
    $comments_header = addslashes('<br /><br />
505
<h2>[TEXT_COMMENTS]</h2>
506
<table cellpadding="2" cellspacing="0" class="comment-header">');
507
    $comments_loop = addslashes('<tr>
508
<td class="comment_title">[TITLE]</td>
509
<td class="comment_info">[TEXT_BY] [DISPLAY_NAME] [TEXT_ON] [DATE] [TEXT_AT] [TIME]</td>
510
</tr>
511
<tr>
512
<td colspan="2" class="comment_text">[COMMENT]</td>
513
</tr>');
514
    $comments_footer = '</table>
515
<br /><a href=\"[ADD_COMMENT_URL]\">[TEXT_ADD_COMMENT]</a>';
516
    $comments_page = '<h1>[TEXT_COMMENT]</h1>
517
<h2>[POST_TITLE]</h2>
518
<br />';
519

    
520
	if(in_array('mod_news_settings', $all_tables))
521
	{
522
	   // Insert default settings into database
523
	   $query_dates = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_settings where section_id != 0 and page_id != 0");
524
	   if($query_dates->numRows() > 1)
525
	   {
526
	        while($result = $query_dates->fetchRow())
527
	        {
528

    
529
	        	echo "<br /><u>Add default settings to database for news section_id= ".$result['section_id']."</u><br />";
530
	        	$section_id = $result['section_id'];
531

    
532
	        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `header` = '$header' WHERE `section_id` = $section_id")) {
533
	        		echo 'Database data header added successfully';
534
	        	}
535
	        	echo mysql_error().'<br />';
536

    
537
	        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_loop` = '$post_loop' WHERE `section_id` = $section_id")) {
538
	        		echo 'Database data post_loop added successfully';
539
	        	}
540
	        	echo mysql_error().'<br />';
541

    
542
	        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `footer` = '$footer' WHERE `section_id` = $section_id")) {
543
	        		echo 'Database data footer added successfully';
544
	        	}
545
	        	echo mysql_error().'<br />';
546

    
547
	        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_header` = '$post_header' WHERE `section_id` = $section_id")) {
548
	        		echo 'Database data post_header added successfully';
549
	        	}
550
	        	echo mysql_error().'<br />';
551

    
552
	        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_footer` = '$post_footer' WHERE `section_id` = $section_id")) {
553
	        		echo 'Database data post_footer added successfully';
554
	        	}
555
	        	echo mysql_error().'<br />';
556

    
557
	        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `comments_header` = '$comments_header' WHERE `section_id` = $section_id")) {
558
	        		echo 'Database data comments_header added successfully';
559
	        	}
560
	        	echo mysql_error().'<br />';
561

    
562
	        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `comments_loop` = '$comments_loop' WHERE `section_id` = $section_id")) {
563
	        		echo 'Database data comments_loop added successfully';
564
	        	}
565
	        	echo mysql_error().'<br />';
566

    
567
	        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `comments_footer` = '$comments_footer' WHERE `section_id` = $section_id")) {
568
	        		echo 'Database data comments_footer added successfully';
569
	        	}
570
	        	echo mysql_error().'<br />';
571

    
572
	        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `comments_page` = '$comments_page' WHERE `section_id` = $section_id")) {
573
	        		echo 'Database data comments_page added successfully';
574
	        	}
575
	        	echo mysql_error().'<br />';
576

    
577
	        }
578
	     }
579
	   }
580
}
581
/**********************************************************
582
 * upgrade media folder index protect files
583
 */
584
$dir = (WB_PATH.MEDIA_DIRECTORY);
585
echo '<h4>Upgrade '.MEDIA_DIRECTORY.'/ index.php protect files</h4><br />';
586
$array = rebuildFolderProtectFile($dir);
587
if( sizeof( $array ) ){
588
	print '<br /><strong>Upgrade '.sizeof( $array ).' '.MEDIA_DIRECTORY.'/ protect files</strong>'." $OK<br />";
589
} else {
590
	print '<br /><strong>Upgrade '.MEDIA_DIRECTORY.'/ protect files</strong>'." $FAIL!<br />";
591
	print implode ('<br />',$array);
592
}
593

    
594
/**********************************************************
595
 * upgrade news if newer version is available
596
 */
597
	if(file_exists(WB_PATH.'/modules/news/upgrade.php'))
598
	{
599
		$currNewsVersion = get_modul_version ('news', false);
600
		$newNewsVersion =  get_modul_version ('news', true);
601
		if((version_compare($currNewsVersion, $newNewsVersion) <= 0)) {
602
			echo '<h4>Upgrade existings basically news module</h4><br />';
603
			// change old postfiles to new postfiles
604
			require_once(WB_PATH."/modules/news/upgrade.php");
605
		}
606
	}
607
/**********************************************************
608
 *  - Set Version to new Version
609
 */
610
echo '<br />Update database version number to '.VERSION.' : ';
611
// echo ($database->query("UPDATE `".TABLE_PREFIX."settings` SET `value`='".VERSION."' WHERE `name` = 'wb_version'")) ? " $OK<br />" : " $FAIL<br />";
612
db_update_key_value('settings', 'wb_version', VERSION);
613

    
614
/* *****************************************************************************
615
 * - check for deprecated / never needed files
616
 */
617
?>
618
<h2>Step 3: Remove deprecated and old files</h2>
619
<?php
620

    
621
	$searches = array(
622
		'[ADMIN]',
623
		'[MEDIA]',
624
		'[PAGES]',
625
		'[TEMPLATE]'
626
	);
627
	$replacements = array(
628
		substr(ADMIN_PATH, strlen(WB_PATH)+1),
629
		MEDIA_DIRECTORY,
630
		PAGES_DIRECTORY,
631
		'/templates',
632
	);
633

    
634
	$msg = '';
635
	foreach( $files2remove as $file )
636
	{
637
		$file = str_replace($searches, $replacements, $file);
638
		$file = WB_PATH.'/'.$file;
639
		if( file_exists( $file ))
640
		{ // try to unlink file
641
			if(!unlink($file))
642
			{ // save in err-list, if failed
643
				$msg .= $file.'<br />';
644
			}
645
		}
646
	}
647

    
648
	if($msg != '')
649
	{
650
		$msg = 'Following files are deprecated, outdated or a security risk and
651
			    can not be removed automatically.<br /><br />Please delete them
652
				using FTP and restart upgrade-script!<br /><br />'.$msg;
653
        status_msg($msg, 'error warning', 'div');
654
		echo '<br /><br /><br /><br /></div></body></html>';
655
		exit();
656
	}
657
/**********************************************************
658
 * - check for deprecated / never needed files
659
 */
660
?>
661
<h2>Step 4: Remove deprecated and old Templates</h2>
662
<?php
663

    
664
	$searches = array(
665
		'[ADMIN]',
666
		'[MEDIA]',
667
		'[PAGES]',
668
		'[TEMPLATE]'
669
	);
670
	$replacements = array(
671
		substr(ADMIN_PATH, strlen(WB_PATH)+1),
672
		MEDIA_DIRECTORY,
673
		PAGES_DIRECTORY,
674
		'/templates',
675
	);
676

    
677
	$msg = '';
678
	foreach( $dir2remove as $dir )
679
	{
680
		$dir = str_replace($searches, $replacements, $dir);
681
		$dir = WB_PATH.'/'.$dir;
682
		if( is_dir( $dir ))
683
		{ // try to delete dir
684
			if(!rm_full_dir($dir))
685
			{ // save in err-list, if failed
686
				$msg .= $dir.'<br />';
687
			}
688
		}
689
	}
690
	if($msg != '')
691
	{
692
		$msg = 'Following directories are deprecated, outdated or a security risk and
693
			    can not be removed automatically.<br /><br />Please delete them
694
				using FTP!<br /><br />'.$msg;
695
        status_msg($msg, 'error warning', 'div');
696
		echo '<br /><br /><br /><br /></div>';
697
	}
698
/**********************************************************
699
 *  - Reload all addons
700
 */
701

    
702
////delete modules
703
//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'module'");
704
// Load all modules
705
if( ($handle = opendir(WB_PATH.'/modules/')) ) {
706
	while(false !== ($file = readdir($handle))) {
707
		if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'admin.php' AND $file != 'index.php') {
708
			load_module(WB_PATH.'/modules/'.$file );
709
		   // 	upgrade_module($file, true);
710
		}
711
	}
712
	closedir($handle);
713
}
714
echo '<br />Modules reloaded<br />';
715

    
716
////delete templates
717
//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'template'");
718
// Load all templates
719
if( ($handle = opendir(WB_PATH.'/templates/')) ) {
720
	while(false !== ($file = readdir($handle))) {
721
		if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
722
			load_template(WB_PATH.'/templates/'.$file);
723
		}
724
	}
725
	closedir($handle);
726
}
727
echo '<br />Templates reloaded<br />';
728

    
729
////delete languages
730
//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'language'");
731
// Load all languages
732
if( ($handle = opendir(WB_PATH.'/languages/')) ) {
733
	while(false !== ($file = readdir($handle))) {
734
		if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
735
			load_language(WB_PATH.'/languages/'.$file);
736
		}
737
	}
738
	closedir($handle);
739
}
740
echo '<br />Languages reloaded<br />';
741

    
742

    
743
/**********************************************************
744
 *  - End of upgrade script
745
 */
746

    
747
// require(WB_PATH.'/framework/initialize.php');
748

    
749
if(!defined('DEFAULT_THEME')) { define('DEFAULT_THEME', $DEFAULT_THEME); }
750
if(!defined('THEME_PATH')) { define('THEME_PATH', WB_PATH.'/templates/'.DEFAULT_THEME);}
751

    
752
echo '<p style="font-size:120%;"><strong>Congratulations: The upgrade script is finished ...</strong></p>';
753
status_msg('<strong>Warning:</strong><br />Please delete the file <strong>upgrade-script.php</strong> via FTP before proceeding.', 'warning', 'div');
754
// show buttons to go to the backend or frontend
755
echo '<br />';
756
if(defined('WB_URL')) {
757
	echo '<form action="'.WB_URL.'">';
758
	echo '<input type="submit" value="kick me to the Frontend" style="float:left;" />';
759
	echo '</form>';
760
}
761
if(defined('ADMIN_URL')) {
762
	echo '<form action="'.ADMIN_URL.'">';
763
	echo '&nbsp;<input type="submit" value="kick me to the Backend" />';
764
	echo '</form>';
765
}
766
echo '<p>&nbsp;</p>';
767

    
768
?>
769
</div>
770
</body>
771
</html>
(5-5/5)