Project

General

Profile

1
<?php
2
/**
3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
 *
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18

    
19
/**
20
 * 
21
 * 
22
 * @category     Core
23
 * @package      Core_service
24
 * @subpackage   upgrade-script
25
 * @author       Dietmar Wöllbrink <dietmar.woellbrink@websitebaker.org>
26
 * @author       Werner v.d.Decken <wkl@isteam.de>
27
 * @copyright    Werner v.d.Decken <wkl@isteam.de>
28
 * @license      http://www.gnu.org/licenses/gpl.html   GPL License
29
 * @version      0.0.1
30
 * @revision     $Revision: 1965 $
31
 * @link         $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/upgrade-script.php $
32
 * @lastmodified $Date: 2013-09-19 16:56:40 +0200 (Thu, 19 Sep 2013) $
33
 * @since        File available since 17.01.2013
34
 * @deprecated   
35
 * @description  xyz
36
 */
37
if(!class_exists('PasswordHash', false))
38
{
39
	include(dirname(__FILE__).'/include/phpass/PasswordHash.php');
40
}
41
// Include config file
42
$config_file = dirname(__FILE__).'/config.php';
43
if(file_exists($config_file) && !defined('WB_URL'))
44
{
45
	require($config_file);
46
}
47
if(!class_exists('admin', false))
48
{ 
49
	include(WB_PATH.'/framework/class.admin.php');
50
}
51
$admin = new admin('Addons', 'modules', false, false);
52
// solved wrong pages_directory value before creating access files
53
$sql  = 'SELECT `value` FROM `'.TABLE_PREFIX.'settings` '
54
      . 'WHERE `name`=\'pages_directory\'';
55
$sPagesDirectory = WbDatabase::getInstance()->get_one($sql);
56
$sTmp = trim($sPagesDirectory, '/');
57
$sTmp = ($sTmp == '' ? '' : '/'.$sTmp);
58
if($sTmp != $sPagesDirectory) {
59
	$sql = 'UPDATE `'.TABLE_PREFIX.'settings` '
60
		 . 'SET `value` = \''.$sTmpDir.'\' '
61
		 . 'WHERE `name`=\'pages_directory\' ';
62
	WbDatabase::getInstance()->query($sql);
63
}
64
require_once(WB_PATH.'/framework/functions.php');
65
// require_once(WB_PATH.'/framework/Database.php');
66

    
67
$oldVersion  = 'Version '.WB_VERSION;
68
$oldVersion .= (defined('WB_SP') ? WB_SP : '');
69
$oldRevision = (defined('WB_REVISION') ? ' Revision ['.WB_REVISION.'] ' : '') ;
70
$newVersion  = 'Version '.VERSION;
71
$newVersion .= (defined('SP') ? SP : '');
72
$newRevision = (defined('REVISION') ? ' Revision ['.REVISION.'] ' : '');
73

    
74
$bDebugModus = false;
75

    
76
// set addition settings if not exists, otherwise upgrade will be breaks
77
if(!defined('WB_SP')) { define('WB_SP',''); }
78
if(!defined('WB_REVISION')) { define('WB_REVISION',''); }
79
// database tables including in WB package
80
$aPackage = array (
81
    'settings','groups','addons','pages','sections','search','users',
82
    'mod_captcha_control','mod_jsadmin','mod_menu_link','mod_output_filter','mod_wrapper','mod_wysiwyg'
83
);
84

    
85
$OK            = ' <span class="ok">OK</span> ';
86
$FAIL          = ' <span class="error">FAILED</span> ';
87
$DEFAULT_THEME = 'wb_theme';
88

    
89
$stepID = 0;
90
$dirRemove = array(
91
/*
92
			'[TEMPLATE]/allcss/',
93
			'[TEMPLATE]/blank/',
94
			'[TEMPLATE]/round/',
95
			'[TEMPLATE]/simple/',
96
*/
97
			'[ADMIN]/themes/',
98
		 );
99
//
100
$aRemoveSingleFiles = array(
101
			'[ADMIN]/preferences/details.php',
102
			'[ADMIN]/preferences/email.php',
103
			'[ADMIN]/preferences/password.php',
104
			'[ADMIN]/pages/settings2.php',
105
			'[ADMIN]/users/users.php',
106
			'[ADMIN]/groups/add.php',
107
			'[ADMIN]/groups/groups.php',
108
			'[ADMIN]/groups/save.php',
109
			'[ADMIN]/skel/themes/htt/groups.htt',
110

    
111
			'[FRAMEWORK]/class.msg_queue.php',
112
			'[FRAMEWORK]/class.logfile.php',
113
			'[FRAMEWORK]/PasswordHash.php',
114
			'[MODULES]/droplets/js/mdcr.js',
115

    
116
);
117

    
118
// deleting files below only from less 2.8.4 stable
119
if(version_compare(WB_VERSION, '2.8.4', '<'))
120
{
121
	$aRemoveOldTemplates = array(
122

    
123
			'[TEMPLATE]/argos_theme/templates/access.htt',
124
			'[TEMPLATE]/argos_theme/templates/addons.htt',
125
			'[TEMPLATE]/argos_theme/templates/admintools.htt',
126
			'[TEMPLATE]/argos_theme/templates/error.htt',
127
			'[TEMPLATE]/argos_theme/templates/groups.htt',
128
			'[TEMPLATE]/argos_theme/templates/groups_form.htt',
129
			'[TEMPLATE]/argos_theme/templates/languages.htt',
130
			'[TEMPLATE]/argos_theme/templates/languages_details.htt',
131
			'[TEMPLATE]/argos_theme/templates/login.htt',
132
			'[TEMPLATE]/argos_theme/templates/login_forgot.htt',
133
			'[TEMPLATE]/argos_theme/templates/media.htt',
134
			'[TEMPLATE]/argos_theme/templates/media_browse.htt',
135
			'[TEMPLATE]/argos_theme/templates/media_rename.htt',
136
			'[TEMPLATE]/argos_theme/templates/modules.htt',
137
			'[TEMPLATE]/argos_theme/templates/modules_details.htt',
138
			'[TEMPLATE]/argos_theme/templates/pages.htt',
139
			'[TEMPLATE]/argos_theme/templates/pages_modify.htt',
140
			'[TEMPLATE]/argos_theme/templates/pages_sections.htt',
141
			'[TEMPLATE]/argos_theme/templates/pages_settings.htt',
142
			'[TEMPLATE]/argos_theme/templates/preferences.htt',
143
			'[TEMPLATE]/argos_theme/templates/setparameter.htt',
144
			'[TEMPLATE]/argos_theme/templates/settings.htt',
145
			'[TEMPLATE]/argos_theme/templates/start.htt',
146
			'[TEMPLATE]/argos_theme/templates/success.htt',
147
			'[TEMPLATE]/argos_theme/templates/templates.htt',
148
			'[TEMPLATE]/argos_theme/templates/templates_details.htt',
149
			'[TEMPLATE]/argos_theme/templates/users.htt',
150
			'[TEMPLATE]/argos_theme/templates/users_form.htt',
151

    
152
			'[TEMPLATE]/wb_theme/templates/access.htt',
153
			'[TEMPLATE]/wb_theme/templates/addons.htt',
154
			'[TEMPLATE]/wb_theme/templates/admintools.htt',
155
			'[TEMPLATE]/wb_theme/templates/error.htt',
156
			'[TEMPLATE]/wb_theme/templates/groups.htt',
157
			'[TEMPLATE]/wb_theme/templates/groups_form.htt',
158
			'[TEMPLATE]/wb_theme/templates/languages.htt',
159
			'[TEMPLATE]/wb_theme/templates/languages_details.htt',
160
			'[TEMPLATE]/wb_theme/templates/login.htt',
161
			'[TEMPLATE]/wb_theme/templates/login_forgot.htt',
162
			'[TEMPLATE]/wb_theme/templates/media.htt',
163
			'[TEMPLATE]/wb_theme/templates/media_browse.htt',
164
			'[TEMPLATE]/wb_theme/templates/media_rename.htt',
165
			'[TEMPLATE]/wb_theme/templates/modules.htt',
166
			'[TEMPLATE]/wb_theme/templates/modules_details.htt',
167
			'[TEMPLATE]/wb_theme/templates/pages.htt',
168
			'[TEMPLATE]/wb_theme/templates/pages_modify.htt',
169
			'[TEMPLATE]/wb_theme/templates/pages_sections.htt',
170
			'[TEMPLATE]/wb_theme/templates/pages_settings.htt',
171
			'[TEMPLATE]/wb_theme/templates/preferences.htt',
172
			'[TEMPLATE]/wb_theme/templates/setparameter.htt',
173
			'[TEMPLATE]/wb_theme/templates/settings.htt',
174
			'[TEMPLATE]/wb_theme/templates/start.htt',
175
			'[TEMPLATE]/wb_theme/templates/success.htt',
176
			'[TEMPLATE]/wb_theme/templates/templates.htt',
177
			'[TEMPLATE]/wb_theme/templates/templates_details.htt',
178
			'[TEMPLATE]/wb_theme/templates/users.htt',
179
			'[TEMPLATE]/wb_theme/templates/users_form.htt'
180
	);
181
}else {
182
	$aRemoveOldTemplates = array();
183
}
184
$aFilesToRemove = array_merge($aRemoveSingleFiles, $aRemoveOldTemplates);
185
unset($aRemoveSingleFiles);
186
unset($aRemoveOldTemplates);
187
/* display a status message on the screen **************************************
188
 * @param string $message: the message to show
189
 * @param string $class:   kind of message as a css-class
190
 * @param string $element: witch HTML-tag use to cover the message
191
 * @return void
192
 */
193
function status_msg($message, $class='check', $element='div')
194
{
195
	// returns a status message
196
	$msg  = '<'.$element.' class="'.$class.'">';
197
	$msg .= '<strong>'.strtoupper(strtok($class, ' ')).'</strong>';
198
	$msg .= $message.'</'.$element.'>';
199
	echo $msg;
200
}
201

    
202
/**
203
 * add_modify_field_in_database()
204
 *
205
 * @param mixed $sTable
206
 * @param mixed $sField
207
 * @param mixed $sDescription
208
 * @return
209
 */
210
function add_modify_field_in_database($sTable,$sField,$sDescription){
211
	global $OK,$FAIL,$bDebugModus;
212
	$database=WbDatabase::getInstance();
213
	$aDebugMessage = array();
214
	if(!$database->field_exists($sTable,$sField)) {
215
		$aDebugMessage[] = "<span>Adding field $sField to $sTable table</span>";
216
		$aDebugMessage[] = ($database->field_add($sTable, $sField, $sDescription) ? " $OK<br />" : " $FAIL!<br />");
217
	} else {
218
		$aDebugMessage[] = "<span>Modify field $sField to $sTable table</span>";
219
		$aDebugMessage[] = ($database->field_modify($sTable, $sField, $sDescription) ? " $OK<br />" : " $FAIL!<br />");
220
	}
221
	if($bDebugModus) {
222
		echo implode(PHP_EOL,$aDebugMessage);
223
	}
224
return;
225
}
226

    
227
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
228
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
229
<head>
230
<title>Upgrade script</title>
231
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
232
<style type="text/css">
233
html { overflow-y: scroll; /* Force firefox to always show room for a vertical scrollbar */ }
234

    
235
body {
236
	margin:0;
237
	padding:0;
238
	border:0;
239
	background: #EBF7FC;
240
	color:#000;
241
	font-family: 'Trebuchet MS', Verdana, Arial, Helvetica, Sans-Serif;
242
	font-size: small;
243
	height:101%;
244
}
245

    
246
#container {
247
	min-width:48em;
248
    width: 70%;
249
	background: #A8BCCB url(<?php echo WB_URL; ?>/templates/wb_theme/images/background.png) repeat-x;
250
	border:1px solid #000;
251
	color:#000;
252
	margin:2em auto;
253
	padding:0 20px;
254
	min-height: 500px;
255
	text-align:left;
256
}
257
.page {
258
	width:100%;
259
    overflow: hidden;
260
}
261
.content {
262
    padding: 10px;
263
}
264
p { line-height:1.5em; }
265

    
266
form {
267
	display: inline-block;
268
	line-height: 20px;
269
	vertical-align: baseline;
270
}
271
input[type="submit"].restart {
272
	background-color: #FFDBDB;
273
	font-weight: bold;
274
}
275

    
276
h1,h2,h3,h4,h5,h6 {
277
	font-family: Verdana, Arial, Helvetica, sans-serif;
278
	color: #26527D;
279
	margin-top: 1.0em;
280
	margin-bottom: 0.1em;
281
}
282

    
283
h1 { font-size:150%; }
284
h2 { font-size: 130%; border-bottom: 1px #CCC solid; }
285
h3 { font-size: 110%; font-weight: bold; }
286

    
287
textarea {
288
	width:100%;
289
	border: 2px groove #0F1D44;
290
	padding: 2px;
291
	color: #000;
292
	font-weight: normal;
293
}
294
.ok, .error { font-weight:bold; }
295
.ok { color:green; }
296
.error { color:red; }
297
.check { color:#555; }
298

    
299
span.ok,
300
span.error {
301
    margin-left: 0em;
302
}
303

    
304
.warning {
305
	background:#FFDBDB;
306
	padding:1em;
307
	margin-top:0.5em;
308
	border: 1px solid #DB0909;
309
}
310
.info {
311
	background:#C7F4C7;
312
	padding:1em;
313
	margin-top:0.5em;
314
	border: 1px solid #277A29;
315
}
316

    
317
</style>
318
</head>
319
<body>
320
<div id="container">
321
<div class="page">
322
<img src="<?php echo WB_URL; ?>/templates/wb_theme/images/logo.png" alt="WebsiteBaker Project" />
323
<div class="content">
324
<h1>WebsiteBaker Upgrade</h1>
325
<?php
326
	if( version_compare( WB_VERSION, '2.7', '<' )) {
327
		status_msg('<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');
328
		echo "</div>
329
		</div>
330
		</div>
331
		</body>
332
		</html>
333
		";
334
		exit();
335
	}
336
if($admin->get_user_id()!=1){
337
	status_msg('<br /><h3>WebsiteBaker upgrading is not possible!<br />Before upgrading '
338
	          .'to Revision '.REVISION.' you have to login as System-Administrator!</h3>',
339
	           'warning', 'div');
340
	echo '<br /><br />';
341
// delete remember key of current user from database
342
	//if (isset($_SESSION['USER_ID']) && isset($database)) {
343
	//	$table = TABLE_PREFIX . 'users';
344
	//	$sql = "UPDATE `$table` SET `remember_key` = '' WHERE `user_id` = '" . (int) $_SESSION['USER_ID'] . "'";
345
	//	$database->query($sql);
346
	//}
347
// delete remember key cookie if set
348
	if (isset($_COOKIE['REMEMBER_KEY']) && !headers_sent() ) {
349
		setcookie('REMEMBER_KEY', '', time() - 3600, '/');
350
	}
351
	// delete most critical session variables manually
352
	$_SESSION['USER_ID'] = null;
353
	$_SESSION['GROUP_ID'] = null;
354
	$_SESSION['GROUPS_ID'] = null;
355
	$_SESSION['USERNAME'] = null;
356
	$_SESSION['PAGE_PERMISSIONS'] = null;
357
	$_SESSION['SYSTEM_PERMISSIONS'] = null;
358
	// overwrite session array
359
	$_SESSION = array();
360
	// delete session cookie if set
361
	if (isset($_COOKIE[session_name()]) && !headers_sent()) {
362
		setcookie(session_name(), '', time() - 42000, '/');
363
	}
364
	// delete the session itself
365
	session_destroy();
366
	status_msg('<br /><h3>You have to login as System-Adminstrator start '
367
	          .'upgrade-script.php again!</h3>',
368
	           'info', 'div');
369
	echo '<br /><br />';
370
	if(defined('ADMIN_URL')) {
371
		echo '<form action="'.ADMIN_URL.'/index.php" method="post">'
372
		    .'&nbsp;<input name="backend_send" type="submit" value="Kick me to the Login" />'
373
		    .'</form>';
374
	}
375
	echo '<br /><br /></div>'
376
	    .'</div>'
377
	    .'</div>'
378
	    .'</body>'
379
	    .'</html>';
380
	exit();
381
}
382

    
383
?>
384
<p class="info">This script upgrades an existing WebsiteBaker <strong> <?php echo $oldRevision; ?></strong> installation to the <strong> <?php echo $newRevision ?> </strong>.<br />The upgrade script alters the existing WB database to reflect the changes introduced with WB 2.8.x</p>
385

    
386
<?php
387

    
388
/**
389
 * Check if disclaimer was accepted
390
 */
391
$bDebugModus = false;
392
$bDebugModus = ( (isset($_POST['debug_confirmed']) && $_POST['debug_confirmed'] == 'debug') ? true : false);
393
if (!(isset($_POST['backup_confirmed']) && $_POST['backup_confirmed'] == 'confirmed')) { ?>
394
<h2>Step 1: Backup your files</h2>
395
<h5 class="warning">It is highly recommended to <strong>create a manual backup</strong> of the entire <strong class="error"><?php echo  PAGES_DIRECTORY ?>/</strong> folder and the <strong>MySQL database</strong> before proceeding.</h5>
396
<p><strong class="error">Note: </strong>The upgrade script alters some settings of your existing database!!! You need to confirm the disclaimer before proceeding.</p>
397

    
398
<form action="<?php echo $_SERVER['SCRIPT_NAME'];?>" method="post">
399
<textarea cols="92" 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 <?php echo  PAGES_DIRECTORY ?>/ folder (including all files and subfolders contained in it) and backup of the entire WebsiteBaker MySQL database was created before you can proceed.</textarea>
400
<br /><br /><input name="backup_confirmed" type="checkbox" value="confirmed" />&nbsp;<strong>I confirm that a manual backup of the <?php echo  PAGES_DIRECTORY ?>/ folder and the MySQL database was created.</strong>
401
<br /><br /><input name="debug_confirmed" type="checkbox" value="debug" />&nbsp;<strong>Here you can get more details during running upgrade.</strong>
402
<br /><br /><input name="send" type="submit" value="Start upgrade script" />
403
</form>
404
<br />
405

    
406
<?php
407
	status_msg('<strong> Notice:</strong><br />You need to confirm that you have created '
408
			  .'a manual backup of the '.PAGES_DIRECTORY.'/ directory and the MySQL '
409
	          .'database before you can proceed.',
410
	           'warning', 'div');
411
	echo '<br /><br /></div>'
412
	    .'</div>'
413
	    .'</div>'
414
	    .'</body>'
415
	    .'</html>';
416
	exit();
417
}
418

    
419
/**********************************************************
420
 *  - check tables coming with WebsiteBaker
421
 */
422
	$aMissingTables = UpgradeHelper::getMissingTables($aPackage);
423
	if( sizeof($aMissingTables) == 0){
424
        echo '<h4 style="margin-left:0;">NOTICE: '.sizeof($aPackage).' total tables '
425
		    .'included in package are successfully installed into your database `'
426
		    .$database->DbName.'` '.$OK.'</h4>';
427
    } else {
428
        status_msg('<strong>:</strong><br />can\'t run Upgrade, missing tables', 'warning', 'div');
429
        echo '<h4>Missing required tables. You can install them in backend->addons->modules.<br />'
430
            .'Or if you uploaded per FTP install possible by backend->addons->modules->advanced.<br />'
431
            .'First rename or delete the upgrade-script.php, so the script can\'t start automatically by backend<br />'
432
            .'After installing missing tables upload and run again upgrade-script.php<br /><br /></h4>'
433
            .'<h4 class="warning">'
434
            .'Missing required tables.<br /><br />'
435
            .'TABLE `'.implode('` missing! '.$FAIL.'<br />TABLE `',$aMissingTables).'` missing! '.$FAIL
436
            .'<br /><br /></h4>'
437
            .'<br /><br />';
438
        if(isset($_SERVER['SCRIPT_NAME'])) {
439
        	echo '<form action="'.$_SERVER['SCRIPT_NAME'].'/">'
440
        	    .'&nbsp;<input type="submit" value="Start upgrade again" />'
441
        	    .'</form>';
442
        }
443
        if(defined('ADMIN_URL')) {
444
        	echo '<form action="'.ADMIN_URL.'/index.php" method="post">'
445
        	    .'&nbsp;<input name="backend_send" type="submit" value="kick me to the Backend" />'
446
        	    .'</form>';
447
        }
448
        echo '<br /><br /></div>'
449
            .'</div>'
450
            .'</div>'
451
            .'</body>'
452
            .'</html>';
453
		exit();
454
	}
455

    
456
	echo '<h3>Step '.(++$stepID).': Setting default_theme</h3>';
457
	$aDebugMessage = array();
458
	/**********************************************************
459
	 *  - Adding field default_theme to settings table
460
	 */
461
	$aDebugMessage[] = '<div style="margin-left:2em;">';
462
	$aDebugMessage[] = "<br /><span><strong>Adding default_theme to settings table</strong></span>";
463
	// db_update_key_value('settings', 'default_theme', $DEFAULT_THEME);
464
	$cfg = array(
465
		'default_theme' => $DEFAULT_THEME
466
	);
467
	$aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
468
	$aDebugMessage[] = '</div>';
469

    
470
	if($bDebugModus) {
471
		echo implode(PHP_EOL,$aDebugMessage);
472
	}
473
	$aDebugMessage = array();
474
	echo'<h3>Step '.(++$stepID).': Updating core table included in package</h3>';
475
	/**********************************************************
476
	 *  - Adding field sec_anchor to settings table
477
	 */
478
	echo '<div style="margin-left:2em;">';
479
	echo "<h4>Adding/updating entries on table settings</h4>";
480
	$aDebugMessage[] = "<span>Adding/updating sec_anchor to settings table</span>";
481
	$cfg = array(
482
		'sec_anchor' => defined( 'SEC_ANCHOR' )&& (SEC_ANCHOR!='') ? SEC_ANCHOR : 'Sec'
483
	);
484
	$aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
485

    
486
	/**********************************************************
487
	 *  - Adding redirect timer to settings table
488
	 */
489
	$aDebugMessage[] = "<span>Adding/updating redirect timer to settings table</span>";
490
	$cfg = array(
491
		'redirect_timer' => defined('REDIRECT_TIMER')&& (REDIRECT_TIMER!='') ? REDIRECT_TIMER : '1500'
492
	);
493
	$aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
494

    
495
	/**********************************************************
496
	 *  - Adding default_time_formatr to settings table
497
	 */
498
	$aDebugMessage[] = "<span>Adding/updating default_time_format to settings table</span>";
499
	$cfg = array(
500
		'default_time_format' => defined('DEFAULT_TIME_FORMAT')&& (DEFAULT_TIME_FORMAT!='') ? DEFAULT_TIME_FORMAT : 'h:i A'
501
	);
502
	$aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
503

    
504
	/**********************************************************
505
	 *  - Adding rename_files_on_upload to settings table
506
	 */
507
	$aDebugMessage[] = "<span>Adding/Updating rename_files_on_upload to settings table</span>";
508
	$cfg = array(
509
	    'rename_files_on_upload' => (defined('RENAME_FILES_ON_UPLOAD')&& (RENAME_FILES_ON_UPLOAD!='') ? RENAME_FILES_ON_UPLOAD : 'ph.*?,cgi,pl,pm,exe,com,bat,pif,cmd,src,asp,aspx,js')
510
	);
511
	if( version_compare( WB_VERSION, '2.8.2', '<' )) {
512
		$cfg = array(
513
		    'rename_files_on_upload' => 'ph.*?,cgi,pl,pm,exe,com,bat,pif,cmd,src,asp,aspx,js'
514
		);
515
	}
516
	$aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
517

    
518
	/**********************************************************
519
	 *  - Adding mediasettings to settings table
520
	 */
521
	$aDebugMessage[] = "<span>Adding/updating mediasettings to settings table</span>";
522
	$cfg = array(
523
		'mediasettings' => (defined('MEDIASETTINGS')&& (MEDIASETTINGS!='') ? MEDIASETTINGS : ''),
524
	);
525

    
526
	$aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
527

    
528
	/**********************************************************
529
	 *  - Adding fingerprint_with_ip_octets to settings table
530
	 */
531
	$aDebugMessage[] = "<span>Adding/updating fingerprint_with_ip_octets to settings table</span>";
532
	$cfg = array(
533
		'fingerprint_with_ip_octets' => (defined('FINGERPRINT_WITH_IP_OCTETS') ? FINGERPRINT_WITH_IP_OCTETS : '2'),
534
		'secure_form_module' => (defined('SECURE_FORM_MODULE') ? SECURE_FORM_MODULE : '')
535
	);
536

    
537
	$aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
538

    
539
	/**********************************************************
540
	 *  - Adding page_icon_dir to settings table
541
	 */
542
	$aDebugMessage[] = "<span>Adding/updating page_icon_dir to settings table</span>";
543
	$cfg = array(
544
		'page_icon_dir' => (defined('PAGE_ICON_DIR')&& (PAGE_ICON_DIR!='') ? PAGE_ICON_DIR : '/templates/*/title_images'),
545
	);
546

    
547
	$aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
548
	/**********************************************************
549
	 *  - Adding page_extended to settings table
550
	 */
551
	$aDebugMessage[] = "<span>Adding/updating page_extendet to settings table</span>";
552
	$cfg = array(
553
		'page_extendet' => (defined('PAGE_EXTENDET') ? PAGE_EXTENDET : 'true'),
554
	);
555

    
556
	$aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
557

    
558
	/**********************************************************
559
	 *  - Adding wbmail_signature to settings table
560
	 */
561
	$aDebugMessage[] = "<span>Adding/updating wbmail_signature to settings table</span>";
562
	$cfg = array(
563
		'wbmail_signature' => (defined('WBMAIL_SIGNATURE')&& (WBMAIL_SIGNATURE!='') ? WBMAIL_SIGNATURE : '')
564
	);
565

    
566
	$aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
567

    
568
	/**********************************************************
569
	 *  - Adding confirmed_registration to settings table
570
	 */
571
	$aDebugMessage[] = "<span>Adding/updating confirmed_registration to settings table</span>";
572
	$cfg = array(
573
		'confirmed_registration' => (defined('CONFIRMED_REGISTRATION') ? CONFIRMED_REGISTRATION : '0')
574
	);
575

    
576
	$aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
577

    
578
	/**********************************************************
579
	 *  - Adding dev_infos to settings table
580
	 */
581
	$aDebugMessage[] = "<span>Adding/updating dev_infos to settings table</span>";
582
	$cfg = array(
583
		'dev_infos' => (defined('DEV_INFOS') ? DEV_INFOS : 'false')
584
	);
585

    
586
    $aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
587

    
588
	/**********************************************************
589
	 *  - Adding server_timezone to settings table
590
	 */
591
	$aDebugMessage[] = "<span>Adding/updating server_timezone to settings table</span>";
592
	$cfg = array(
593
		'server_timezone' => (defined('SERVER_TIMEZONE') ? SERVER_TIMEZONE : 'UTC')
594
	);
595

    
596
    $aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
597

    
598
	/**********************************************************
599
	 *  - Adding password settings to settings table
600
	 */
601
	$aDebugMessage[] = "<span>Adding/updating password settings to settings table</span>";
602
	$cfg = array();
603
	$cfg['password_crypt_loops'] = (defined('PASSWORD_CRYPT_LOOPS') ? PASSWORD_CRYPT_LOOPS : '12');
604
	$cfg['password_hash_type'] = (defined('PASSWORD_HASH_TYPES') ? PASSWORD_HASH_TYPES : 'false');
605
	$cfg['password_length'] = (defined('PASSWORD_LENGTH') ? PASSWORD_LENGTH : '10');
606
	$cfg['password_use_types'] = (defined('PASSWORD_USE_TYPES') ? PASSWORD_USE_TYPES : (int)0xFFFF);
607
    $aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
608

    
609
if($bDebugModus) {
610
    echo implode(PHP_EOL,$aDebugMessage);
611
}
612
echo '</div>';
613

    
614
$aDebugMessage = array();
615
if(version_compare(WB_REVISION, REVISION, '<='))
616
{
617
	echo '<div style="margin-left:2em;">';
618
	/**********************************************************
619
	 *  - Update search no results database filed to create
620
	 *  valid XHTML if search is empty
621
	 */
622
	if (version_compare(WB_VERSION, '2.8', '<'))
623
	{
624
		echo "<h4>Adding/updating fields on table search</h4>";
625
		echo "Updating database field `no_results` on search table: ";
626
		$search_no_results = addslashes('<tr><td><p>[TEXT_NO_RESULTS]</p></td></tr>');
627
		$sql  = 'UPDATE `'.TABLE_PREFIX.'search` ';
628
		$sql .= 'SET `value`=\''.$search_no_results.'\' ';
629
		$sql .= 'WHERE `name`=\'no_results\'';
630
		echo ($database->query($sql)) ? " $OK<br />" : " $FAIL!<br />";
631
	}
632

    
633
	$aDebugMessage = array();
634
	echo "<h4>Adding/updating field on table pages</h4>";
635
	/**********************************************************
636
	 *  - Add field "page_trail" to table "pages"
637
	 */
638
	$table_name = TABLE_PREFIX.'pages';
639
	$field_name = 'page_trail';
640
	$description = "VARCHAR( 255 ) NOT NULL DEFAULT ''";
641
	add_modify_field_in_database($table_name,$field_name,$description);
642

    
643
	/**********************************************************
644
	 *  - Add field "page_icon" to table "pages"
645
	 */
646
	$table_name = TABLE_PREFIX.'pages';
647
	$field_name = 'page_icon';
648
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '' AFTER `page_title`";
649
	add_modify_field_in_database($table_name,$field_name,$description);
650

    
651
	/**********************************************************
652
	 *  - Add field "page_code" to table "pages"
653
	 *
654
	 *  will be done in upgrade.php of the module MultiLingual
655
	 *  until the module is integrated completely
656
	 */
657
//	$table_name = TABLE_PREFIX.'pages';
658
//	$field_name = 'page_code';
659
//	$description = "INT NOT NULL DEFAULT '0' AFTER `language`";
660
//	add_modify_field_in_database($table_name,$field_name,$description);
661

    
662
	/**********************************************************
663
	 *  - Add field "menu_icon_0" to table "pages"
664
	 */
665
	$table_name = TABLE_PREFIX.'pages';
666
	$field_name = 'menu_icon_0';
667
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '' AFTER `menu_title`";
668
	add_modify_field_in_database($table_name,$field_name,$description);
669

    
670
	/**********************************************************
671
	 *  - Add field "menu_icon_1" to table "pages"
672
	 */
673
	$table_name = TABLE_PREFIX.'pages';
674
	$field_name = 'menu_icon_1';
675
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '' AFTER `menu_icon_0`";
676
	add_modify_field_in_database($table_name,$field_name,$description);
677

    
678
	/**********************************************************
679
	 *  - Add field "tooltip" to table "pages"
680
	 */
681
	$table_name = TABLE_PREFIX.'pages';
682
	$field_name = 'tooltip';
683
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '' AFTER `menu_icon_1`";
684
	add_modify_field_in_database($table_name,$field_name,$description);
685

    
686
	/**********************************************************
687
	 *  - Add field "admin_groups" to table "pages"
688
	 */
689
	$table_name = TABLE_PREFIX.'pages';
690
	$field_name = 'admin_groups';
691
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '1'";
692
	add_modify_field_in_database($table_name,$field_name,$description);
693

    
694
	/**********************************************************
695
	 *  - Add field "admin_users" to table "pages"
696
	 */
697
	$table_name = TABLE_PREFIX.'pages';
698
	$field_name = 'admin_users';
699
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT ''";
700
	add_modify_field_in_database($table_name,$field_name,$description);
701

    
702
	/**********************************************************
703
	 *  - Add field "viewing_groups" to table "pages"
704
	 */
705
	$table_name = TABLE_PREFIX.'pages';
706
	$field_name = 'viewing_groups';
707
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '1'";
708
	 add_modify_field_in_database($table_name,$field_name,$description);
709

    
710
	/**********************************************************
711
	 *  - Add field "viewing_users" to table "pages"
712
	 */
713
	$table_name = TABLE_PREFIX.'pages';
714
	$field_name = 'viewing_users';
715
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT ''";
716
	add_modify_field_in_database($table_name,$field_name,$description);
717

    
718
	/**********************************************************
719
	 *  - Add field "custom01" to table "pages"
720
	 */
721
	$table_name = TABLE_PREFIX.'pages';
722
	$field_name = 'custom01';
723
	$description = "VARCHAR( 255 ) NOT NULL DEFAULT '' ";
724
	add_modify_field_in_database($table_name,$field_name,$description);
725

    
726
	/**********************************************************
727
	 *  - Add field "custom02" to table "pages"
728
	 */
729
	$table_name = TABLE_PREFIX.'pages';
730
	$field_name = 'custom02';
731
	$description = "VARCHAR( 255 ) NOT NULL DEFAULT '' ";
732
	add_modify_field_in_database($table_name,$field_name,$description);
733

    
734
	if($bDebugModus) {
735
		echo implode(PHP_EOL,$aDebugMessage);
736
	}
737

    
738
	$aDebugMessage = array();
739
	/**********************************************************
740
	 * modify wrong strucre on table sections
741
	 * wrong structure let crash wb
742
	 */
743
	echo "<h4>Change field structure on table sections</h4>";
744
	$table_name = TABLE_PREFIX.'sections';
745
	$description = "VARCHAR( 255 ) NOT NULL DEFAULT ''";
746
	$aDebugMessage[] = "<span>Modify field module on sections table</span>";
747
	$aDebugMessage[] = ($database->field_modify($table_name, 'module', $description) ? " $OK<br />" : " $FAIL!<br />");
748
	$aDebugMessage[] = "<span>Modify field block on sections table</span>";
749
	$description = "int(11) NOT NULL DEFAULT '1'";
750
	$aDebugMessage[] = ($database->field_modify($table_name, 'block', $description) ? " $OK<br />" : " $FAIL!<br />");
751
	$description = "int(11) NOT NULL DEFAULT '0'";
752
	$aDebugMessage[] = "<span>Modify field publ_start on sections table</span>";
753
	$aDebugMessage[] = ($database->field_modify($table_name, 'publ_start', $description) ? " $OK<br />" : " $FAIL!<br />");
754
	$aDebugMessage[] = "<span>Modify field publ_end on sections table</span>";
755
	$aDebugMessage[] = ($database->field_modify($table_name, 'publ_end', $description) ? " $OK<br />" : " $FAIL!<br />");
756

    
757
	if($bDebugModus) {
758
		echo implode(PHP_EOL,$aDebugMessage);
759
	}
760
	echo '</div>';
761
}
762

    
763
if(version_compare(WB_REVISION, REVISION, '<='))
764
{
765
	$aDebugMessage = array();
766
	echo '<h3>Step '.(++$stepID).': Updating structure in table users/groups</h3>';
767
	/**********************************************************
768
	 * Modify Administrator on groups table
769
	 */
770
	echo '<div style="margin-left:2em;">';
771
	echo "<h4>Updating Administrator group permissions on table groups</h4>";
772
	$aDebugMessage[] = "<span>Modify Administrator on groups table</span>";
773
	$sModulePermissions = '';
774
	$sTemplatePermissions = '';
775
	$sSystemPermissions  = 'access,addons,admintools,admintools_view,groups,groups_add,groups_delete,groups_modify,groups_view,';
776
	$sSystemPermissions .= 'languages,languages_install,languages_uninstall,languages_view,media,media_create,media_delete,media_rename,media_upload,media_view,';
777
	$sSystemPermissions .= 'modules,modules_advanced,modules_install,modules_uninstall,modules_view,pages,pages_add,pages_add_l0,pages_delete,pages_intro,pages_modify,pages_settings,pages_view,';
778
	$sSystemPermissions .= 'preferences,preferences_view,settings,settings_advanced,settings_basic,settings_view,templates,templates_install,templates_uninstall,templates_view,users,users_add,users_delete,users_modify,users_view';
779

    
780
	$sql  = 'UPDATE `'.TABLE_PREFIX.'groups` ';
781
	$sql .= 'SET `name` = \'Administrators\', ';
782
	$sql .= '`system_permissions` = \''.$sSystemPermissions.'\', ';
783
	$sql .= '`module_permissions` = \''.$sModulePermissions.'\', ';
784
	$sql .= '`template_permissions` = \''.$sTemplatePermissions.'\' ';
785
	$sql .= 'WHERE `group_id` = \'1\' ';
786
	$aDebugMessage[] = ($database->query($sql)) ? " $OK<br />" : " $FAIL!<br />";
787
	if( ($admin->is_authenticated() == true) && ($admin->ami_group_member('1') ) ) {
788
	    $_SESSION['SYSTEM_PERMISSIONS'] = array_merge($_SESSION['SYSTEM_PERMISSIONS'], explode(',', $sSystemPermissions));
789
	}
790

    
791
	if($bDebugModus) {
792
		echo implode(PHP_EOL,$aDebugMessage);
793
	}
794
	echo '</div>';
795
	$aDebugMessage = array();
796
	/**********************************************************
797
	 *   `confirm_code` VARCHAR(32) NOT NULL DEFAULT '',
798
	 *   `confirm_timeout` INT(11) NOT NULL DEFAULT '0',
799
	 */
800
	echo '<div style="margin-left:2em;">';
801
	echo "<h4>Change field structure on table users</h4>";
802
	$table_name = TABLE_PREFIX.'users';
803
	$field_name = 'confirm_code';
804
	$description = "VARCHAR( 32 ) NOT NULL DEFAULT '' AFTER `password` ";
805
	add_modify_field_in_database($table_name,$field_name,$description);
806

    
807
	$table_name = TABLE_PREFIX.'users';
808
	$field_name = 'confirm_timeout';
809
	$description = "INT(11) NOT NULL DEFAULT '0' AFTER `confirm_code` ";
810
	add_modify_field_in_database($table_name,$field_name,$description);
811

    
812
	if($bDebugModus) {
813
	    echo implode(PHP_EOL,$aDebugMessage);
814
	}
815
	echo '</div>';
816

    
817
	$aDebugMessage = array();
818
	/**********************************************************
819
	* Updating group_id in table users
820
	*/
821
	echo '<div style="margin-left:2em;">';
822
	echo "<h4>Updating users groups permissions on table groups</h4>";
823
	    $aUsers = array();
824
		// Get existing values
825
        $sql  = 'SELECT * FROM `'.TABLE_PREFIX.'users` ' ;
826
        $sql .= 'WHERE `user_id` != 1 ';
827
        if($oUser = $database->query($sql)){
828
            $iTotalUsers = $oUser->numRows();
829
            while($Users = $oUser->fetchRow(MYSQL_ASSOC)) {
830
                $aUsers[$Users['user_id']]['groups_id'] = $Users['groups_id'];
831
                $aUsers[$Users['user_id']]['display_name'] = $Users['display_name'];
832
            }
833
        } else {
834
            $aDebugMessage[] = $database->is_error()==false ? " $OK<br />" : " $FAIL!<br />";
835
        }
836
        foreach($aUsers AS $user_id => $value){
837
                // choose group_id from groups_id - workaround for still remaining calls to group_id (to be cleaned-up)
838
                $aGroups_id = explode(',', $aUsers[$user_id]['groups_id']);
839
                $groups_id = $aUsers[$user_id]['groups_id'];
840
                $group_id = 0;
841
                //if user is in administrator-group, get this group else just get the first one
842
                if($admin->is_group_match($aGroups_id,'1')) { $group_id = 1; $groups_id = '1'; } else { $group_id = intval($aGroups_id[0]); }
843
                $sMessage = "<span>Updating group_id ".$TEXT['DISPLAY_NAME']." " .$aUsers[$user_id]['display_name']."</span>";
844
                $sql  = 'UPDATE `'.TABLE_PREFIX.'users` ';
845
                $sql .= 'SET `group_id`  = '.$group_id.', ';
846
                $sql .=     '`groups_id` = \''.$groups_id.'\' ';
847
                $sql .= 'WHERE `user_id` = '.intval($user_id);
848
                if($oRes = $database->query($sql)){  }
849
                $aDebugMessage[] = $database->is_error()==false ? $sMessage." $OK<br />" : $sMessage." $FAIL!<br />";
850
        }
851
        unset($aUsers);
852
	$aDebugMessage[] = '</div>';
853

    
854
	if($bDebugModus) {
855
	// $aDebugMessage[] =
856
	    echo implode(PHP_EOL,$aDebugMessage);
857
	}else {
858
	    echo '<span><strong>'.$iTotalUsers.' users updating the groups</strong></span>'." $OK<br />";
859
	    echo '</div>';
860
	}
861
}
862

    
863
$aDebugMessage = array();
864
echo '<h3>Step '.(++$stepID).': Updating access and protected files in folders</h3>';
865

    
866
echo '<div style="margin-left:2em;">';
867
	/**********************************************************
868
	* upgrade media directory index protect files
869
	*/
870
	$dir = (WB_PATH.MEDIA_DIRECTORY);
871
	echo '<h4>Upgrade media directory '.MEDIA_DIRECTORY.'/ index.php protect files</h4>';
872
	$aDebugMessage = rebuildFolderProtectFile($dir);
873
	if( sizeof( $aDebugMessage ) ){
874
		echo '<span><strong>Upgrade '.sizeof( $aDebugMessage ).' directory '.MEDIA_DIRECTORY.'/ protect files</strong></span>'." $OK<br />";
875
	} else {
876
		echo '<span><strong>Upgrade directory '.MEDIA_DIRECTORY.'/ protect files</strong></span>'." $FAIL!<br />";
877
		echo implode ('<br />',$aDebugMessage);
878
	}
879

    
880
    $aDebugMessage = array();
881
    /**********************************************************
882
     * upgrade pages directory index access files
883
     */
884
	echo '<h4>Upgrade pages directory '.PAGES_DIRECTORY.'/  protect and access files</h4>';
885

    
886
    /**********************************************************
887
     *  - Reformat/rebuild all existing access files
888
     */
889
    $sPagePath = (defined('PAGES_DIRECTORY') && (PAGES_DIRECTORY != '') ? PAGES_DIRECTORY : '');
890
    $msg = rebuild_all_accessfiles();
891
	$dir = (WB_PATH.PAGES_DIRECTORY);
892
//	$aDebugMessage = rebuildFolderProtectFile($dir);
893
	echo '<strong>'.implode ('<br />',$msg).'</strong>';
894
    echo '</div>';
895

    
896
	/* *****************************************************************************
897
	 * - check for deprecated / never needed files
898
	 */
899
	$iLoaded = sizeof($aFilesToRemove);
900
	if($iLoaded) {
901
		echo '<h3>Step '.(++$stepID).': Remove deprecated and outdated files</h3>';
902
		$iFailed = 0;
903
		$iFound = 0;
904
		$searches = array(
905
			'[ADMIN]',
906
			'[MEDIA]',
907
			'[PAGES]',
908
			'[FRAMEWORK]',
909
			'[MODULES]',
910
			'[TEMPLATE]'
911
		);
912
		$replacements = array(
913
			'/'.substr(ADMIN_PATH, strlen(WB_PATH)+1),
914
			MEDIA_DIRECTORY,
915
			PAGES_DIRECTORY,
916
			'/framework',
917
			'/modules',
918
			'/templates'
919
		);
920

    
921
		$msg = '';
922
		echo '<div style="margin-left:2em;">';
923
		echo '<h4>Search '.$iLoaded.' deprecated and outdated files</h4>';
924
		foreach( $aFilesToRemove as $file )
925
		{
926
			$file = str_replace($searches, $replacements, $file);
927
			if( is_writable(WB_PATH.'/'.$file) ) {
928
				$iFound++;
929
				// try to unlink file
930
				if(!unlink(WB_PATH.$file)) {
931
					$iFailed++;
932
				}
933
			}
934
			if( is_readable(WB_PATH.'/'.$file) ) {
935
				// save in err-list, if failed
936
				$msg .= $file.'<br />';
937
			}
938
		}
939
		$iRemove = $iFound-$iFailed;
940
		echo '<strong>Remove '.$iRemove.' from '.$iFound.' founded</strong> ';
941
		echo ($iFailed == 0) ? $OK : $FAIL;
942
		echo '</div>';
943

    
944
		if($msg != '')
945
		{
946
			$msg = '<br /><br />Following files are deprecated, outdated or a security risk and
947
				    can not be removed automatically.<br /><br />Please delete them
948
					using FTP and restart upgrade-script!<br /><br />'.$msg.'<br />';
949
			status_msg($msg, 'error warning', 'div');
950
			echo '<p style="font-size:120%;"><strong>WARNING: The upgrade script failed ...</strong></p>';
951

    
952
			echo '<form action="'.$_SERVER['SCRIPT_NAME'].'">';
953
			echo '&nbsp;<input name="send" type="submit" value="Restart upgrade script" />';
954
			echo '</form>';
955
			echo "<br /><br /></div>
956
			</div>
957
			</div>
958
			</body>
959
			</html>";
960
			exit;
961
		}
962
	}
963

    
964

    
965
	/**********************************************************
966
	 * - check for deprecated / never needed files
967
	 */
968
	$iLoaded = sizeof($dirRemove);
969
	if($iLoaded) {
970
		echo '<h3>Step  '.(++$stepID).': Remove deprecated and outdated folders</h3>';
971
		$iFailed = 0;
972
		$iFound = 0;
973
		$searches = array(
974
			'[ADMIN]',
975
			'[MEDIA]',
976
			'[PAGES]',
977
			'[TEMPLATE]'
978
		);
979
		$replacements = array(
980
			substr(ADMIN_PATH, strlen(WB_PATH)+1),
981
			MEDIA_DIRECTORY,
982
			PAGES_DIRECTORY,
983
			'/templates',
984
		);
985
		$msg = '';
986
		echo '<div style="margin-left:2em;">';
987
		echo '<h4>Search '.$iLoaded.' deprecated and outdated folders</h4>';
988
		foreach( $dirRemove as $dir ) {
989
			$dir = str_replace($searches, $replacements, $dir);
990
			$dir = WB_PATH.'/'.$dir;
991
			if( is_dir( $dir )) {
992
				$iFound++;
993
			// try to delete dir
994
				if(!is_writable( $dir ) || !rm_full_dir($dir)) {
995
				// save in err-list, if failed
996
					$iFailed++;
997
				}
998
			}
999
			if( is_readable(WB_PATH.'/'.$dir) ) {
1000
				$msg .= str_replace(WB_PATH,'',$dir).'<br />';
1001
			}
1002
		}
1003
		
1004
		$iRemove = $iFound-$iFailed;
1005
		echo '<strong>Remove '.$iRemove.' from '.$iFound.' founded</strong> ';
1006
		echo ($iFailed == 0) ? $OK : $FAIL;
1007
		echo '</div>';
1008

    
1009
		if($msg != '') {
1010
			$msg = '<br /><br />Following directories are deprecated, outdated or a security risk and
1011
					can not be removed automatically.<br /><br />Please delete them
1012
					using FTP and restart upgrade-script!<br /><br />'.$msg.'<br />';
1013
			status_msg($msg, 'error warning', 'div');
1014
			echo '<p style="font-size:120%;"><strong>WARNING: The upgrade script failed ...</strong></p>';
1015
			echo '<form action="'.$_SERVER['SCRIPT_NAME'].'">';
1016
			echo '&nbsp;<input name="send" type="submit" value="Restart upgrade script" />';
1017
			echo '</form>';
1018
			echo "<br /><br /></div>
1019
			</div>
1020
			</div>
1021
			</body>
1022
			</html>";
1023
			exit;
1024
		}
1025

    
1026

    
1027
	}
1028

    
1029
	/**********************************************************
1030
	 * upgrade modules if newer version is available
1031
	 * $aModuleList list of proofed modules
1032
	 */
1033
	$aModuleList = array(
1034
	              'captcha_control','code','droplets','form','jsadmin',
1035
	              'menu_link','news','output_filter','wrapper','wysiwyg','MultiLingual');
1036
	if(sizeof($aModuleList)) 
1037
	{
1038
		echo '<h3>Step '.(++$stepID).': Upgrade proofed modules</h3>';
1039
		foreach($aModuleList as $sModul) {
1040
			if(file_exists(WB_PATH.'/modules/'.$sModul.'/upgrade.php')) {
1041
				$currModulVersion = get_modul_version ($sModul, false);
1042
				$newModulVersion =  get_modul_version ($sModul, true);
1043
				if((version_compare($currModulVersion, $newModulVersion) <= 0)) {
1044
					echo '<div style="margin-left:2em;">';
1045
					echo '<h4>'.'Upgrade module \''.$sModul.'\' version '.$newModulVersion.'</h4>';
1046
					require(WB_PATH.'/modules/'.$sModul.'/upgrade.php');
1047
					echo '</div>';
1048
				}
1049
			}
1050
		}
1051
	}
1052

    
1053
	/**********************************************************
1054
	 * Reformat/rebuild all existing moules access files
1055
	 * $aModuleList list of modules
1056
	 */
1057
	$aModuleList = array('bakery','topics','news');
1058
	if(sizeof($aModuleList)) 
1059
	{
1060
		echo '<h3>Step '.(++$stepID).': Create/Reorg Accessfiles from modules</h3>';
1061
		foreach($aModuleList as $sModul) {
1062
			$aReturnMsg = array();
1063
			$sModulReorg = 'm_'.$sModul.'_Reorg';
1064
			if(class_exists($sModulReorg)) {
1065
				$sModulVersion =  get_modul_version ($sModul, true);
1066
				echo '<div style="margin-left:2em;">';
1067
				echo '<h4>'.'Create/Reorg Accesfiles for module \''.$sModul.'\' version '.$sModulVersion.'</h4>';
1068
				$oReorg = new $sModulReorg();
1069
				$aReturnMsg = $oReorg->execute(); // show details
1070
				if(is_array($aReturnMsg)) {
1071
					foreach($aReturnMsg as $title) {
1072
					echo '<strong>'.$title.'</strong><br />';
1073
					}
1074
				}
1075
				echo '</div>';
1076
			}
1077
		}
1078
	}
1079
/**********************************************************
1080
 *  - Reload all addons
1081
 */
1082

    
1083
	echo '<h3>Step '.(++$stepID).' : Reload all addons database entry (no upgrade)</h3><br />';
1084
	echo '<div style="margin-left:2em;">';
1085
	$iFound = 0;
1086
	$iLoaded = 0;
1087
	////delete modules
1088
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'module'");
1089
	// Load all modules
1090
	if( ($handle = opendir(WB_PATH.'/modules/')) ) {
1091
		while(false !== ($file = readdir($handle))) {
1092
			if($file != '' && substr($file, 0, 1) != '.' && is_dir(WB_PATH.'/modules/'.$file) ) {
1093
				$iFound++;
1094
				$iLoaded = load_module(WB_PATH.'/modules/'.$file ) ? $iLoaded+1 : $iLoaded;
1095
// 	upgrade_module($file, true);
1096
			}
1097
		}
1098
		closedir($handle);
1099
	}
1100
	echo '<strong><span>'.$iLoaded.' Modules reloaded,</span> found '.$iFound.' directories in folder /modules/</strong><br />';
1101

    
1102
	$iFound = 0;
1103
	$iLoaded = 0;
1104
	////delete templates
1105
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'template'");
1106
	// Load all templates
1107
	if( ($handle = opendir(WB_PATH.'/templates/')) ) {
1108
		while(false !== ($file = readdir($handle))) {
1109
			if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
1110

    
1111
				$iFound++;
1112
				$iLoaded = (load_template(WB_PATH.'/templates/'.$file)==true) ? $iLoaded+1 : $iLoaded;
1113

    
1114
			}
1115
		}
1116
		closedir($handle);
1117
	}
1118
	echo '<strong><span>'.$iLoaded.' Templates reloaded,</span> found '.$iFound.' directories in folder /templates/</strong><br />';
1119

    
1120
	$iFound = 0;
1121
	$iLoaded = 0;
1122
	////delete languages
1123
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'language'");
1124
	// Load all languages
1125
	if( ($handle = opendir(WB_PATH.'/languages/')) ) {
1126
		while(false !== ($file = readdir($handle))) {
1127
			if($file != '' AND (preg_match('#^([A-Z]{2}.php)#', basename($file)))) {
1128
				$iFound++;
1129
				$iLoaded = load_language(WB_PATH.'/languages/'.$file) ? $iLoaded+1 : $iLoaded;
1130
			}
1131
		}
1132
		closedir($handle);
1133
	}
1134
	echo '<strong><span>'.$iLoaded.' Languages reloaded,</span> found '.$iFound.' files in folder /languages/</strong><br />';
1135
	echo '</div>';
1136

    
1137
/**********************************************************
1138
 *  - install new droplets
1139
	$drops = (!in_array ( "mod_droplets", $all_tables)) ? "<br />Install droplets<br />" : "<br />Upgrade droplets<br />";
1140
	echo $drops;
1141
	$file_name = (!in_array ( "mod_droplets", $all_tables) ? "install.php" : "upgrade.php");
1142
	require_once (WB_PATH."/modules/droplets/".$file_name);
1143
********************************************************** */
1144

    
1145
/**********************************************************
1146
 *  - End of upgrade script
1147
 */
1148
	if(!defined('DEFAULT_THEME')) { define('DEFAULT_THEME', $DEFAULT_THEME); }
1149
	if(!defined('THEME_PATH')) { define('THEME_PATH', WB_PATH.'/templates/'.DEFAULT_THEME);}
1150
/**********************************************************
1151
 *  - Set Version to new Version
1152
 */
1153
echo '<h3>Step '.(++$stepID).': Update database version number </h3>';
1154
echo '<div style="margin-left:2em;">';
1155

    
1156
$cfg = array(
1157
	'wb_version' => VERSION,
1158
	'wb_revision' => REVISION,
1159
	'wb_sp' => SP
1160
);
1161
echo '<br /><span><strong>Set WebsiteBaker version number to '.VERSION.' '.SP.' '.' Revision ['.REVISION.'] : </strong></span>';
1162
echo (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
1163
echo '</div>';
1164

    
1165
echo '<p style="font-size:140%;"><strong>Congratulations: The upgrade script is finished ...</strong></p>';
1166
status_msg('<strong>:</strong><br />Please delete the file <strong>upgrade-script.php</strong> via FTP before proceeding.', 'warning', 'div');
1167
// show buttons to go to the backend or frontend
1168
echo '<br />';
1169

    
1170
if(defined('WB_URL')) {
1171
	echo '<form action="'.WB_URL.'/">';
1172
	echo '&nbsp;<input type="submit" value="kick me to the Frontend" />';
1173
	echo '</form>';
1174
}
1175
if(defined('ADMIN_URL')) {
1176
	echo '<form action="'.ADMIN_URL.'/">';
1177
	echo '&nbsp;<input type="submit" value="kick me to the Backend" />';
1178
	echo '</form>';
1179
}
1180

    
1181
echo "<br /><br /></div>
1182
</div>
1183
</div>
1184
</body>
1185
</html>
1186
";
1187
exit();
(6-6/6)