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: 1963 $
31
 * @link         $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/upgrade-script.php $
32
 * @lastmodified $Date: 2013-09-18 15:58:12 +0200 (Wed, 18 Sep 2013) $
33
 * @since        File available since 17.01.2013
34
 * @deprecated   
35
 * @description  xyz
36
 */
37
// Include config file
38
$config_file = realpath('config.php');
39
if(file_exists($config_file) && !defined('WB_URL'))
40
{
41
	require($config_file);
42

    
43
}
44
//require_once(WB_PATH.'/framework/class.admin.php');
45
if(!class_exists('admin', false)){ include(WB_PATH.'/framework/class.admin.php'); }
46
$admin = new admin('Addons', 'modules', false, false);
47

    
48
// solved wrong pages_directory value before creating access files
49
$sql  = 'SELECT `value` FROM `'.TABLE_PREFIX.'settings` '
50
      . 'WHERE `name`=\'pages_directory\'';
51
$sPagesDirectory = WbDatabase::getInstance()->get_one($sql);
52
$sTmp = trim($sPagesDirectory, '/');
53
$sTmp = ($sTmp == '' ? '' : '/'.$sTmp);
54
if($sTmp != $sPagesDirectory) {
55
 $sql = 'UPDATE `'.TABLE_PREFIX.'settings` '
56
      . 'SET `value` = \''.$sTmpDir.'\' '
57
      . 'WHERE `name`=\'pages_directory\' ';
58
 WbDatabase::getInstance()->query($sql);
59
}
60
require_once(WB_PATH.'/framework/functions.php');
61
// require_once(WB_PATH.'/framework/Database.php');
62

    
63
$oldVersion  = 'Version '.WB_VERSION;
64
$oldVersion .= (defined('WB_SP') ? WB_SP : '');
65
$oldRevision = (defined('WB_REVISION') ? ' Revision ['.WB_REVISION.'] ' : '') ;
66
$newVersion  = 'Version '.VERSION;
67
$newVersion .= (defined('SP') ? SP : '');
68
$newRevision = (defined('REVISION') ? ' Revision ['.REVISION.'] ' : '');
69

    
70
$bDebugModus = false;
71

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

    
81
$OK            = ' <span class="ok">OK</span> ';
82
$FAIL          = ' <span class="error">FAILED</span> ';
83
$DEFAULT_THEME = 'wb_theme';
84

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

    
107
			'[FRAMEWORK]/class.msg_queue.php',
108
			'[FRAMEWORK]/class.logfile.php',
109
			'[FRAMEWORK]/PasswordHash.php',
110
			'[MODULES]/droplets/js/mdcr.js',
111

    
112
);
113

    
114
// deleting files below only from less 2.8.4 stable
115
if(version_compare(WB_VERSION, '2.8.4', '<'))
116
{
117
	$aRemoveOldTemplates = array(
118

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

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

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

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

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

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

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

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

    
279
h1 { font-size:150%; }
280
h2 { font-size: 130%; border-bottom: 1px #CCC solid; }
281
h3 { font-size: 110%; font-weight: bold; }
282

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

    
295
span.ok,
296
span.error {
297
    margin-left: 0em;
298
}
299

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

    
313
</style>
314
</head>
315
<body>
316
<div id="container">
317
<div class="page">
318
<img src="<?php echo WB_URL; ?>/templates/wb_theme/images/logo.png" alt="WebsiteBaker Project" />
319
<div class="content">
320
<h1>WebsiteBaker Upgrade</h1>
321
<?php
322
	if( version_compare( WB_VERSION, '2.7', '<' )) {
323
		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');
324
		echo "</div>
325
		</div>
326
		</div>
327
		</body>
328
		</html>
329
		";
330
		exit();
331
	}
332
if($admin->get_user_id()!=1){
333
	status_msg('<br /><h3>WebsiteBaker upgrading is not possible!<br />Before upgrading to Revision '.REVISION.' you have to login as System-Administrator!</h3>', 'warning', 'div');
334
        echo '<br /><br />';
335
// delete remember key of current user from database
336
//if (isset($_SESSION['USER_ID']) && isset($database)) {
337
//	$table = TABLE_PREFIX . 'users';
338
//	$sql = "UPDATE `$table` SET `remember_key` = '' WHERE `user_id` = '" . (int) $_SESSION['USER_ID'] . "'";
339
//	$database->query($sql);
340
//}
341

    
342
// delete remember key cookie if set
343
if (isset($_COOKIE['REMEMBER_KEY']) && !headers_sent() ) {
344
	setcookie('REMEMBER_KEY', '', time() - 3600, '/');
345
}
346

    
347
// delete most critical session variables manually
348
$_SESSION['USER_ID'] = null;
349
$_SESSION['GROUP_ID'] = null;
350
$_SESSION['GROUPS_ID'] = null;
351
$_SESSION['USERNAME'] = null;
352
$_SESSION['PAGE_PERMISSIONS'] = null;
353
$_SESSION['SYSTEM_PERMISSIONS'] = null;
354
// overwrite session array
355
$_SESSION = array();
356
// delete session cookie if set
357
if (isset($_COOKIE[session_name()]) && !headers_sent()) {
358
    setcookie(session_name(), '', time() - 42000, '/');
359
}
360
// delete the session itself
361
session_destroy();
362
status_msg('<br /><h3>After login as System-Adminstrator you have to start upgrade-script.php again!</h3>', 'info', 'div');
363
        echo '<br /><br />';
364
        if(defined('ADMIN_URL')) {
365
        	echo '<form action="'.ADMIN_URL.'/index.php" method="post">';
366
        	echo '&nbsp;<input name="backend_send" type="submit" value="Kick me to the Login" />';
367
        	echo '</form>';
368
        }
369
echo "<br /><br /></div>
370
	</div>
371
	</div>
372
	</body>
373
	</html>
374
	";
375
	exit();
376
}
377

    
378
?>
379
<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>
380

    
381
<?php
382

    
383
/**
384
 * Check if disclaimer was accepted
385
 */
386
$bDebugModus = false;
387
$bDebugModus = ( (isset($_POST['debug_confirmed']) && $_POST['debug_confirmed'] == 'debug') ? true : false);
388
if (!(isset($_POST['backup_confirmed']) && $_POST['backup_confirmed'] == 'confirmed')) { ?>
389
<h2>Step 1: Backup your files</h2>
390
<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>
391
<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>
392

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

    
401
<?php
402
	status_msg('<strong> Notice:</strong><br />You need to confirm that you have created a manual backup of the '.PAGES_DIRECTORY.'/ directory and the MySQL database before you can proceed.', 'warning', 'div');
403
	echo "<br /><br /></div>
404
	</div>
405
	</div>
406
	</body>
407
	</html>";
408
	exit();
409
}
410

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

    
444
		exit();
445
	}
446

    
447
echo '<h3>Step '.(++$stepID).': Setting default_theme</h3>';
448
$aDebugMessage = array();
449
	/**********************************************************
450
	 *  - Adding field default_theme to settings table
451
	 */
452
	$aDebugMessage[] = '<div style="margin-left:2em;">';
453
	$aDebugMessage[] = "<br /><span><strong>Adding default_theme to settings table</strong></span>";
454
	// db_update_key_value('settings', 'default_theme', $DEFAULT_THEME);
455
	$cfg = array(
456
		'default_theme' => $DEFAULT_THEME
457
	);
458
	$aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
459
	$aDebugMessage[] = '</div>';
460

    
461
if($bDebugModus) {
462
	echo implode(PHP_EOL,$aDebugMessage);
463
}
464
$aDebugMessage = array();
465
echo'<h3>Step '.(++$stepID).': Updating core table included in package</h3>';
466
	/**********************************************************
467
	 *  - Adding field sec_anchor to settings table
468
	 */
469
	echo '<div style="margin-left:2em;">';
470
	echo "<h4>Adding/updating entries on table settings</h4>";
471
	$aDebugMessage[] = "<span>Adding/updating sec_anchor to settings table</span>";
472
	$cfg = array(
473
		'sec_anchor' => defined( 'SEC_ANCHOR' )&& (SEC_ANCHOR!='') ? SEC_ANCHOR : 'Sec'
474
	);
475
	$aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
476

    
477
	/**********************************************************
478
	 *  - Adding redirect timer to settings table
479
	 */
480
	$aDebugMessage[] = "<span>Adding/updating redirect timer to settings table</span>";
481
	$cfg = array(
482
		'redirect_timer' => defined('REDIRECT_TIMER')&& (REDIRECT_TIMER!='') ? REDIRECT_TIMER : '1500'
483
	);
484
	$aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
485

    
486
	/**********************************************************
487
	 *  - Adding default_time_formatr to settings table
488
	 */
489
	$aDebugMessage[] = "<span>Adding/updating default_time_format to settings table</span>";
490
	$cfg = array(
491
		'default_time_format' => defined('DEFAULT_TIME_FORMAT')&& (DEFAULT_TIME_FORMAT!='') ? DEFAULT_TIME_FORMAT : 'h:i A'
492
	);
493
	$aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
494

    
495
	/**********************************************************
496
	 *  - Adding rename_files_on_upload to settings table
497
	 */
498
	$aDebugMessage[] = "<span>Adding/Updating rename_files_on_upload to settings table</span>";
499
	$cfg = array(
500
	    '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')
501
	);
502
	if( version_compare( WB_VERSION, '2.8.2', '<' )) {
503
		$cfg = array(
504
		    'rename_files_on_upload' => 'ph.*?,cgi,pl,pm,exe,com,bat,pif,cmd,src,asp,aspx,js'
505
		);
506
	}
507
	$aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
508

    
509
	/**********************************************************
510
	 *  - Adding mediasettings to settings table
511
	 */
512
	$aDebugMessage[] = "<span>Adding/updating mediasettings to settings table</span>";
513
	$cfg = array(
514
		'mediasettings' => (defined('MEDIASETTINGS')&& (MEDIASETTINGS!='') ? MEDIASETTINGS : ''),
515
	);
516

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

    
519
	/**********************************************************
520
	 *  - Adding fingerprint_with_ip_octets to settings table
521
	 */
522
	$aDebugMessage[] = "<span>Adding/updating fingerprint_with_ip_octets to settings table</span>";
523
	$cfg = array(
524
		'fingerprint_with_ip_octets' => (defined('FINGERPRINT_WITH_IP_OCTETS') ? FINGERPRINT_WITH_IP_OCTETS : '2'),
525
		'secure_form_module' => (defined('SECURE_FORM_MODULE') ? SECURE_FORM_MODULE : '')
526
	);
527

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

    
530
	/**********************************************************
531
	 *  - Adding page_icon_dir to settings table
532
	 */
533
	$aDebugMessage[] = "<span>Adding/updating page_icon_dir to settings table</span>";
534
	$cfg = array(
535
		'page_icon_dir' => (defined('PAGE_ICON_DIR')&& (PAGE_ICON_DIR!='') ? PAGE_ICON_DIR : '/templates/*/title_images'),
536
	);
537

    
538
	$aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
539
	/**********************************************************
540
	 *  - Adding page_extended to settings table
541
	 */
542
	$aDebugMessage[] = "<span>Adding/updating page_extendet to settings table</span>";
543
	$cfg = array(
544
		'page_extendet' => (defined('PAGE_EXTENDET') ? PAGE_EXTENDET : 'true'),
545
	);
546

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

    
549
	/**********************************************************
550
	 *  - Adding wbmail_signature to settings table
551
	 */
552
	$aDebugMessage[] = "<span>Adding/updating wbmail_signature to settings table</span>";
553
	$cfg = array(
554
		'wbmail_signature' => (defined('WBMAIL_SIGNATURE')&& (WBMAIL_SIGNATURE!='') ? WBMAIL_SIGNATURE : '')
555
	);
556

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

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

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

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

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

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

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

    
589
	/**********************************************************
590
	 *  - Adding password settings to settings table
591
	 */
592
	$aDebugMessage[] = "<span>Adding/updating password settings to settings table</span>";
593
	$cfg = array();
594
	$cfg['password_crypt_loops'] = (defined('PASSWORD_CRYPT_LOOPS') ? PASSWORD_CRYPT_LOOPS : '12');
595
	$cfg['password_hash_type'] = (defined('PASSWORD_HASH_TYPES') ? PASSWORD_HASH_TYPES : 'false');
596
	$cfg['password_length'] = (defined('PASSWORD_LENGTH') ? PASSWORD_LENGTH : '10');
597
	$cfg['password_use_types'] = (defined('PASSWORD_USE_TYPES') ? PASSWORD_USE_TYPES : (int)0xFFFF);
598
    $aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
599

    
600
if($bDebugModus) {
601
    echo implode(PHP_EOL,$aDebugMessage);
602
}
603
echo '</div>';
604

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

    
624
	$aDebugMessage = array();
625
	echo "<h4>Adding/updating field on table pages</h4>";
626
	/**********************************************************
627
	 *  - Add field "page_trail" to table "pages"
628
	 */
629
	$table_name = TABLE_PREFIX.'pages';
630
	$field_name = 'page_trail';
631
	$description = "VARCHAR( 255 ) NOT NULL DEFAULT ''";
632
	add_modify_field_in_database($table_name,$field_name,$description);
633

    
634
	/**********************************************************
635
	 *  - Add field "page_icon" to table "pages"
636
	 */
637
	$table_name = TABLE_PREFIX.'pages';
638
	$field_name = 'page_icon';
639
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '' AFTER `page_title`";
640
	add_modify_field_in_database($table_name,$field_name,$description);
641

    
642
	/**********************************************************
643
	 *  - Add field "page_code" to table "pages"
644
	 *
645
	 *  will be done in upgrade.php of the module MultiLingual
646
	 *  until the module is integrated completely
647
	 */
648
//	$table_name = TABLE_PREFIX.'pages';
649
//	$field_name = 'page_code';
650
//	$description = "INT NOT NULL DEFAULT '0' AFTER `language`";
651
//	add_modify_field_in_database($table_name,$field_name,$description);
652

    
653
	/**********************************************************
654
	 *  - Add field "menu_icon_0" to table "pages"
655
	 */
656
	$table_name = TABLE_PREFIX.'pages';
657
	$field_name = 'menu_icon_0';
658
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '' AFTER `menu_title`";
659
	add_modify_field_in_database($table_name,$field_name,$description);
660

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

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

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

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

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

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

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

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

    
725
	if($bDebugModus) {
726
		echo implode(PHP_EOL,$aDebugMessage);
727
	}
728

    
729
	$aDebugMessage = array();
730
	/**********************************************************
731
	 * modify wrong strucre on table sections
732
	 * wrong structure let crash wb
733
	 */
734
	echo "<h4>Change field structure on table sections</h4>";
735
	$table_name = TABLE_PREFIX.'sections';
736
	$description = "VARCHAR( 255 ) NOT NULL DEFAULT ''";
737
	$aDebugMessage[] = "<span>Modify field module on sections table</span>";
738
	$aDebugMessage[] = ($database->field_modify($table_name, 'module', $description) ? " $OK<br />" : " $FAIL!<br />");
739
	$aDebugMessage[] = "<span>Modify field block on sections table</span>";
740
	$description = "int(11) NOT NULL DEFAULT '1'";
741
	$aDebugMessage[] = ($database->field_modify($table_name, 'block', $description) ? " $OK<br />" : " $FAIL!<br />");
742
	$description = "int(11) NOT NULL DEFAULT '0'";
743
	$aDebugMessage[] = "<span>Modify field publ_start on sections table</span>";
744
	$aDebugMessage[] = ($database->field_modify($table_name, 'publ_start', $description) ? " $OK<br />" : " $FAIL!<br />");
745
	$aDebugMessage[] = "<span>Modify field publ_end on sections table</span>";
746
	$aDebugMessage[] = ($database->field_modify($table_name, 'publ_end', $description) ? " $OK<br />" : " $FAIL!<br />");
747

    
748
	if($bDebugModus) {
749
		echo implode(PHP_EOL,$aDebugMessage);
750
	}
751
	echo '</div>';
752
}
753

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

    
771
	$sql  = 'UPDATE `'.TABLE_PREFIX.'groups` ';
772
	$sql .= 'SET `name` = \'Administrators\', ';
773
	$sql .= '`system_permissions` = \''.$sSystemPermissions.'\', ';
774
	$sql .= '`module_permissions` = \''.$sModulePermissions.'\', ';
775
	$sql .= '`template_permissions` = \''.$sTemplatePermissions.'\' ';
776
	$sql .= 'WHERE `group_id` = \'1\' ';
777
	$aDebugMessage[] = ($database->query($sql)) ? " $OK<br />" : " $FAIL!<br />";
778
	if( ($admin->is_authenticated() == true) && ($admin->ami_group_member('1') ) ) {
779
	    $_SESSION['SYSTEM_PERMISSIONS'] = array_merge($_SESSION['SYSTEM_PERMISSIONS'], explode(',', $sSystemPermissions));
780
	}
781

    
782
	if($bDebugModus) {
783
		echo implode(PHP_EOL,$aDebugMessage);
784
	}
785
	echo '</div>';
786
	$aDebugMessage = array();
787
	/**********************************************************
788
	 *   `confirm_code` VARCHAR(32) NOT NULL DEFAULT '',
789
	 *   `confirm_timeout` INT(11) NOT NULL DEFAULT '0',
790
	 */
791
	echo '<div style="margin-left:2em;">';
792
	echo "<h4>Change field structure on table users</h4>";
793
	$table_name = TABLE_PREFIX.'users';
794
	$field_name = 'confirm_code';
795
	$description = "VARCHAR( 32 ) NOT NULL DEFAULT '' AFTER `password` ";
796
	add_modify_field_in_database($table_name,$field_name,$description);
797

    
798
	$table_name = TABLE_PREFIX.'users';
799
	$field_name = 'confirm_timeout';
800
	$description = "INT(11) NOT NULL DEFAULT '0' AFTER `confirm_code` ";
801
	add_modify_field_in_database($table_name,$field_name,$description);
802

    
803
	if($bDebugModus) {
804
	    echo implode(PHP_EOL,$aDebugMessage);
805
	}
806
	echo '</div>';
807

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

    
845
	if($bDebugModus) {
846
	// $aDebugMessage[] =
847
	    echo implode(PHP_EOL,$aDebugMessage);
848
	}else {
849
	    echo '<span><strong>'.$iTotalUsers.' users updating the groups</strong></span>'." $OK<br />";
850
	    echo '</div>';
851
	}
852
}
853

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

    
857
echo '<div style="margin-left:2em;">';
858
	/**********************************************************
859
	* upgrade media directory index protect files
860
	*/
861
	$dir = (WB_PATH.MEDIA_DIRECTORY);
862
	echo '<h4>Upgrade media directory '.MEDIA_DIRECTORY.'/ index.php protect files</h4>';
863
	$aDebugMessage = rebuildFolderProtectFile($dir);
864
	if( sizeof( $aDebugMessage ) ){
865
		echo '<span><strong>Upgrade '.sizeof( $aDebugMessage ).' directory '.MEDIA_DIRECTORY.'/ protect files</strong></span>'." $OK<br />";
866
	} else {
867
		echo '<span><strong>Upgrade directory '.MEDIA_DIRECTORY.'/ protect files</strong></span>'." $FAIL!<br />";
868
		echo implode ('<br />',$aDebugMessage);
869
	}
870

    
871
    $aDebugMessage = array();
872
    /**********************************************************
873
     * upgrade pages directory index access files
874
     */
875
	echo '<h4>Upgrade pages directory '.PAGES_DIRECTORY.'/  protect and access files</h4>';
876

    
877
    /**********************************************************
878
     *  - Reformat/rebuild all existing access files
879
     */
880
    $sPagePath = (defined('PAGES_DIRECTORY') && (PAGES_DIRECTORY != '') ? PAGES_DIRECTORY : '');
881
    $msg = rebuild_all_accessfiles();
882
	$dir = (WB_PATH.PAGES_DIRECTORY);
883
//	$aDebugMessage = rebuildFolderProtectFile($dir);
884
	echo '<strong>'.implode ('<br />',$msg).'</strong>';
885
    echo '</div>';
886

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

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

    
935
		if($msg != '')
936
		{
937
			$msg = '<br /><br />Following files are deprecated, outdated or a security risk and
938
				    can not be removed automatically.<br /><br />Please delete them
939
					using FTP and restart upgrade-script!<br /><br />'.$msg.'<br />';
940
			status_msg($msg, 'error warning', 'div');
941
			echo '<p style="font-size:120%;"><strong>WARNING: The upgrade script failed ...</strong></p>';
942

    
943
			echo '<form action="'.$_SERVER['SCRIPT_NAME'].'">';
944
			echo '&nbsp;<input name="send" type="submit" value="Restart upgrade script" />';
945
			echo '</form>';
946
			echo "<br /><br /></div>
947
			</div>
948
			</div>
949
			</body>
950
			</html>";
951
			exit;
952
		}
953
	}
954

    
955

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

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

    
1017

    
1018
	}
1019

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

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

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

    
1093
	$iFound = 0;
1094
	$iLoaded = 0;
1095
	////delete templates
1096
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'template'");
1097
	// Load all templates
1098
	if( ($handle = opendir(WB_PATH.'/templates/')) ) {
1099
		while(false !== ($file = readdir($handle))) {
1100
			if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
1101

    
1102
				$iFound++;
1103
				$iLoaded = (load_template(WB_PATH.'/templates/'.$file)==true) ? $iLoaded+1 : $iLoaded;
1104

    
1105
			}
1106
		}
1107
		closedir($handle);
1108
	}
1109
	echo '<strong><span>'.$iLoaded.' Templates reloaded,</span> found '.$iFound.' directories in folder /templates/</strong><br />';
1110

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

    
1128
/**********************************************************
1129
 *  - install new droplets
1130
	$drops = (!in_array ( "mod_droplets", $all_tables)) ? "<br />Install droplets<br />" : "<br />Upgrade droplets<br />";
1131
	echo $drops;
1132
	$file_name = (!in_array ( "mod_droplets", $all_tables) ? "install.php" : "upgrade.php");
1133
	require_once (WB_PATH."/modules/droplets/".$file_name);
1134
********************************************************** */
1135

    
1136
/**********************************************************
1137
 *  - End of upgrade script
1138
 */
1139
	if(!defined('DEFAULT_THEME')) { define('DEFAULT_THEME', $DEFAULT_THEME); }
1140
	if(!defined('THEME_PATH')) { define('THEME_PATH', WB_PATH.'/templates/'.DEFAULT_THEME);}
1141
/**********************************************************
1142
 *  - Set Version to new Version
1143
 */
1144
echo '<h3>Step '.(++$stepID).': Update database version number </h3>';
1145
echo '<div style="margin-left:2em;">';
1146

    
1147
$cfg = array(
1148
	'wb_version' => VERSION,
1149
	'wb_revision' => REVISION,
1150
	'wb_sp' => SP
1151
);
1152
echo '<br /><span><strong>Set WebsiteBaker version number to '.VERSION.' '.SP.' '.' Revision ['.REVISION.'] : </strong></span>';
1153
echo (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
1154
echo '</div>';
1155

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

    
1161
if(defined('WB_URL')) {
1162
	echo '<form action="'.WB_URL.'/">';
1163
	echo '&nbsp;<input type="submit" value="kick me to the Frontend" />';
1164
	echo '</form>';
1165
}
1166
if(defined('ADMIN_URL')) {
1167
	echo '<form action="'.ADMIN_URL.'/">';
1168
	echo '&nbsp;<input type="submit" value="kick me to the Backend" />';
1169
	echo '</form>';
1170
}
1171

    
1172
echo "<br /><br /></div>
1173
</div>
1174
</div>
1175
</body>
1176
</html>
1177
";
1178
exit();
(6-6/6)