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: 1966 $
31
 * @link         $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/upgrade-script.php $
32
 * @lastmodified $Date: 2013-09-20 19:27:59 +0200 (Fri, 20 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__).'/framework/PasswordHashInterface.php');
40
	include(dirname(__FILE__).'/include/phpass/PasswordHash.php');
41
}
42
// Include config file
43
$config_file = dirname(__FILE__).'/config.php';
44
if(file_exists($config_file) && !defined('WB_URL'))
45
{
46
	require($config_file);
47
}
48
if(!class_exists('admin', false))
49
{ 
50
	include(WB_PATH.'/framework/class.admin.php');
51
}
52
$admin = new admin('Addons', 'modules', false, false);
53
// solved wrong pages_directory value before creating access files
54
$sql  = 'SELECT `value` FROM `'.TABLE_PREFIX.'settings` '
55
      . 'WHERE `name`=\'pages_directory\'';
56
$sPagesDirectory = WbDatabase::getInstance()->get_one($sql);
57
$sTmp = trim($sPagesDirectory, '/');
58
$sTmp = ($sTmp == '' ? '' : '/'.$sTmp);
59
if($sTmp != $sPagesDirectory) {
60
	$sql = 'UPDATE `'.TABLE_PREFIX.'settings` '
61
		 . 'SET `value` = \''.$sTmpDir.'\' '
62
		 . 'WHERE `name`=\'pages_directory\' ';
63
	WbDatabase::getInstance()->query($sql);
64
}
65
require_once(WB_PATH.'/framework/functions.php');
66
// require_once(WB_PATH.'/framework/Database.php');
67

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

    
75
$bDebugModus = false;
76

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

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

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

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

    
117
);
118

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
384
?>
385
<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>
386

    
387
<?php
388

    
389
/**
390
 * Check if disclaimer was accepted
391
 */
392
$bDebugModus = false;
393
$bDebugModus = ( (isset($_POST['debug_confirmed']) && $_POST['debug_confirmed'] == 'debug') ? true : false);
394
if (!(isset($_POST['backup_confirmed']) && $_POST['backup_confirmed'] == 'confirmed')) { ?>
395
<h2>Step 1: Backup your files</h2>
396
<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>
397
<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>
398

    
399
<form action="<?php echo $_SERVER['SCRIPT_NAME'];?>" method="post">
400
<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>
401
<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>
402
<br /><br /><input name="debug_confirmed" type="checkbox" value="debug" />&nbsp;<strong>Here you can get more details during running upgrade.</strong>
403
<br /><br /><input name="send" type="submit" value="Start upgrade script" />
404
</form>
405
<br />
406

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
764
if(version_compare(WB_REVISION, REVISION, '<='))
765
{
766
	$aDebugMessage = array();
767
	echo '<h3>Step '.(++$stepID).': Updating structure in table users/groups</h3>';
768
	/**********************************************************
769
	 * Modify Administrator on groups table
770
	 */
771
	echo '<div style="margin-left:2em;">';
772
	echo "<h4>Updating Administrator group permissions on table groups</h4>";
773
	$aDebugMessage[] = "<span>Modify Administrator on groups table</span>";
774
	$sModulePermissions = '';
775
	$sTemplatePermissions = '';
776
	$sSystemPermissions  = 'access,addons,admintools,admintools_view,groups,groups_add,groups_delete,groups_modify,groups_view,';
777
	$sSystemPermissions .= 'languages,languages_install,languages_uninstall,languages_view,media,media_create,media_delete,media_rename,media_upload,media_view,';
778
	$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,';
779
	$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';
780

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
965

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

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

    
1027

    
1028
	}
1029

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

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

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

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

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

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

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

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

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

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

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

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

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