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: 1977 $
31
 * @link         $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/upgrade-script.php $
32
 * @lastmodified $Date: 2013-10-06 00:19:38 +0200 (Sun, 06 Oct 2013) $
33
 * @since        File available since 17.01.2013
34
 * @deprecated   
35
 * @description  xyz
36
 */
37
// --- delete fatal disturbing files before upgrade starts -------------------------------
38
$aPreDeleteFiles = array(
39
// list of files
40
	dirname(__FILE__).'/framework/PasswordHash.php'
41
);
42
if(sizeof($aPreDeleteFiles > 0))
43
{
44
// if there are files defined
45
	$sMsg = '';
46
	foreach($aPreDeleteFiles as $sFileToDelete)
47
	{
48
	// iterate the list
49
		if(file_exists($sFileToDelete))
50
		{
51
			if(!is_writeable($sFileToDelete) || !@unlink($sFileToDelete))
52
			{
53
			// notice if deleting fails
54
				$sMsg .= '<span style="color:red;">FAILED</span> deleting: '
55
				       . $sFileToDelete.'<br />'.PHP_EOL;
56
			}
57
		}
58
	}
59
	if($sMsg) {
60
	// stop script if there's an error occured
61
		$sMsg = 'Fatal error occured during initial startup.<br /><br />'.PHP_EOL.$sMsg
62
		      . '<br />'.PHP_EOL.'Please delete all of the files above manually and '
63
		      . 'then <a href="http://'.$_SERVER["HTTP_HOST"].$_SERVER["SCRIPT_NAME"].'" '
64
		      . 'title="restart">klick here to restart the upgrade-script</a>.<br />'.PHP_EOL;
65
		die($sMsg);
66
	}
67
}
68
unset($aPreDeleteFiles);
69
$sMsg = '';
70
// ---------------------------------------------------------------------------------------
71
// Include config file
72
$config_file = dirname(__FILE__).'/config.php';
73
if(file_exists($config_file) && !defined('WB_URL'))
74
{
75
	require($config_file);
76
}
77
if(!class_exists('admin', false))
78
{ 
79
	include(WB_PATH.'/framework/class.admin.php');
80
}
81
$admin = new admin('Addons', 'modules', false, false);
82
// solved wrong pages_directory value before creating access files
83
$sql  = 'SELECT `value` FROM `'.TABLE_PREFIX.'settings` '
84
      . 'WHERE `name`=\'pages_directory\'';
85
$sPagesDirectory = WbDatabase::getInstance()->get_one($sql);
86
$sTmp = trim($sPagesDirectory, '/');
87
$sTmpDir = ($sTmp == '' ? '' : '/'.$sTmp);
88
if($sTmp != $sPagesDirectory) {
89
	$sql = 'UPDATE `'.TABLE_PREFIX.'settings` '
90
		 . 'SET `value` = \''.$sTmpDir.'\' '
91
		 . 'WHERE `name`=\'pages_directory\' ';
92
	WbDatabase::getInstance()->query($sql);
93
}
94
require_once(WB_PATH.'/framework/functions.php');
95
// require_once(WB_PATH.'/framework/Database.php');
96

    
97
$oldVersion  = 'Version '.WB_VERSION;
98
$oldVersion .= (defined('WB_SP') ? WB_SP : '');
99
$oldRevision = (defined('WB_REVISION') ? ' Revision ['.WB_REVISION.'] ' : '') ;
100
$newVersion  = 'Version '.VERSION;
101
$newVersion .= (defined('SP') ? SP : '');
102
$newRevision = (defined('REVISION') ? ' Revision ['.REVISION.'] ' : '');
103

    
104
$bDebugModus = false;
105

    
106
// set addition settings if not exists, otherwise upgrade will be breaks
107
if(!defined('WB_SP')) { define('WB_SP',''); }
108
if(!defined('WB_REVISION')) { define('WB_REVISION',''); }
109
// database tables including in WB package
110
$aPackage = array (
111
    'settings','groups','addons','pages','sections','search','users',
112
    'mod_captcha_control','mod_jsadmin','mod_menu_link','mod_output_filter','mod_wrapper','mod_wysiwyg'
113
);
114

    
115
$OK            = ' <span class="ok">OK</span> ';
116
$FAIL          = ' <span class="error">FAILED</span> ';
117
$DEFAULT_THEME = 'wb_theme';
118

    
119
$stepID = 1;
120
$dirRemove = array(
121
/*
122
			'[TEMPLATE]/allcss/',
123
			'[TEMPLATE]/blank/',
124
			'[TEMPLATE]/round/',
125
			'[TEMPLATE]/simple/',
126
*/
127
			'[ADMIN]/themes/',
128
		 );
129
//
130
$aRemoveSingleFiles = array(
131
			'[ADMIN]/preferences/details.php',
132
			'[ADMIN]/preferences/email.php',
133
			'[ADMIN]/preferences/password.php',
134
			'[ADMIN]/pages/settings2.php',
135
			'[ADMIN]/users/users.php',
136
			'[ADMIN]/groups/add.php',
137
			'[ADMIN]/groups/groups.php',
138
			'[ADMIN]/groups/save.php',
139
			'[ADMIN]/skel/themes/htt/groups.htt',
140

    
141
			'[FRAMEWORK]/class.msg_queue.php',
142
			'[FRAMEWORK]/class.logfile.php',
143
			'[FRAMEWORK]/PasswordHash.php',
144
			'[MODULES]/droplets/js/mdcr.js',
145

    
146
);
147

    
148
// deleting files below only from less 2.8.4 stable
149
if(version_compare(WB_VERSION, '2.8.4', '<'))
150
{
151
	$aRemoveOldTemplates = array(
152

    
153
			'[TEMPLATE]/argos_theme/templates/access.htt',
154
			'[TEMPLATE]/argos_theme/templates/addons.htt',
155
			'[TEMPLATE]/argos_theme/templates/admintools.htt',
156
			'[TEMPLATE]/argos_theme/templates/error.htt',
157
			'[TEMPLATE]/argos_theme/templates/groups.htt',
158
			'[TEMPLATE]/argos_theme/templates/groups_form.htt',
159
			'[TEMPLATE]/argos_theme/templates/languages.htt',
160
			'[TEMPLATE]/argos_theme/templates/languages_details.htt',
161
			'[TEMPLATE]/argos_theme/templates/login.htt',
162
			'[TEMPLATE]/argos_theme/templates/login_forgot.htt',
163
			'[TEMPLATE]/argos_theme/templates/media.htt',
164
			'[TEMPLATE]/argos_theme/templates/media_browse.htt',
165
			'[TEMPLATE]/argos_theme/templates/media_rename.htt',
166
			'[TEMPLATE]/argos_theme/templates/modules.htt',
167
			'[TEMPLATE]/argos_theme/templates/modules_details.htt',
168
			'[TEMPLATE]/argos_theme/templates/pages.htt',
169
			'[TEMPLATE]/argos_theme/templates/pages_modify.htt',
170
			'[TEMPLATE]/argos_theme/templates/pages_sections.htt',
171
			'[TEMPLATE]/argos_theme/templates/pages_settings.htt',
172
			'[TEMPLATE]/argos_theme/templates/preferences.htt',
173
			'[TEMPLATE]/argos_theme/templates/setparameter.htt',
174
			'[TEMPLATE]/argos_theme/templates/settings.htt',
175
			'[TEMPLATE]/argos_theme/templates/start.htt',
176
			'[TEMPLATE]/argos_theme/templates/success.htt',
177
			'[TEMPLATE]/argos_theme/templates/templates.htt',
178
			'[TEMPLATE]/argos_theme/templates/templates_details.htt',
179
			'[TEMPLATE]/argos_theme/templates/users.htt',
180
			'[TEMPLATE]/argos_theme/templates/users_form.htt',
181

    
182
			'[TEMPLATE]/wb_theme/templates/access.htt',
183
			'[TEMPLATE]/wb_theme/templates/addons.htt',
184
			'[TEMPLATE]/wb_theme/templates/admintools.htt',
185
			'[TEMPLATE]/wb_theme/templates/error.htt',
186
			'[TEMPLATE]/wb_theme/templates/groups.htt',
187
			'[TEMPLATE]/wb_theme/templates/groups_form.htt',
188
			'[TEMPLATE]/wb_theme/templates/languages.htt',
189
			'[TEMPLATE]/wb_theme/templates/languages_details.htt',
190
			'[TEMPLATE]/wb_theme/templates/login.htt',
191
			'[TEMPLATE]/wb_theme/templates/login_forgot.htt',
192
			'[TEMPLATE]/wb_theme/templates/media.htt',
193
			'[TEMPLATE]/wb_theme/templates/media_browse.htt',
194
			'[TEMPLATE]/wb_theme/templates/media_rename.htt',
195
			'[TEMPLATE]/wb_theme/templates/modules.htt',
196
			'[TEMPLATE]/wb_theme/templates/modules_details.htt',
197
			'[TEMPLATE]/wb_theme/templates/pages.htt',
198
			'[TEMPLATE]/wb_theme/templates/pages_modify.htt',
199
			'[TEMPLATE]/wb_theme/templates/pages_sections.htt',
200
			'[TEMPLATE]/wb_theme/templates/pages_settings.htt',
201
			'[TEMPLATE]/wb_theme/templates/preferences.htt',
202
			'[TEMPLATE]/wb_theme/templates/setparameter.htt',
203
			'[TEMPLATE]/wb_theme/templates/settings.htt',
204
			'[TEMPLATE]/wb_theme/templates/start.htt',
205
			'[TEMPLATE]/wb_theme/templates/success.htt',
206
			'[TEMPLATE]/wb_theme/templates/templates.htt',
207
			'[TEMPLATE]/wb_theme/templates/templates_details.htt',
208
			'[TEMPLATE]/wb_theme/templates/users.htt',
209
			'[TEMPLATE]/wb_theme/templates/users_form.htt'
210
	);
211
}else {
212
	$aRemoveOldTemplates = array();
213
}
214
$aFilesToRemove = array_merge($aRemoveSingleFiles, $aRemoveOldTemplates);
215
unset($aRemoveSingleFiles);
216
unset($aRemoveOldTemplates);
217
/* display a status message on the screen **************************************
218
 * @param string $message: the message to show
219
 * @param string $class:   kind of message as a css-class
220
 * @param string $element: witch HTML-tag use to cover the message
221
 * @return void
222
 */
223
function status_msg($message, $class='check', $element='div')
224
{
225
	// returns a status message
226
	$msg  = '<'.$element.' class="'.$class.'">';
227
	$msg .= '<strong>'.strtoupper(strtok($class, ' ')).'</strong>';
228
	$msg .= $message.'</'.$element.'>';
229
	echo $msg;
230
}
231

    
232
/**
233
 * add_modify_field_in_database()
234
 *
235
 * @param mixed $sTable
236
 * @param mixed $sField
237
 * @param mixed $sDescription
238
 * @return
239
 */
240
function add_modify_field_in_database($sTable,$sField,$sDescription){
241
	global $OK,$FAIL,$bDebugModus;
242
	$database=WbDatabase::getInstance();
243
	$aDebugMessage = array();
244
	if(!$database->field_exists($sTable,$sField)) {
245
		$aDebugMessage[] = "<span>Adding field $sField to $sTable table</span>";
246
		$aDebugMessage[] = ($database->field_add($sTable, $sField, $sDescription) ? " $OK<br />" : " $FAIL!<br />");
247
	} else {
248
		$aDebugMessage[] = "<span>Modify field $sField to $sTable table</span>";
249
		$aDebugMessage[] = ($database->field_modify($sTable, $sField, $sDescription) ? " $OK<br />" : " $FAIL!<br />");
250
	}
251
	if($bDebugModus) {
252
		echo implode(PHP_EOL,$aDebugMessage);
253
	}
254
return;
255
}
256

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

    
265
body {
266
	margin:0;
267
	padding:0;
268
	border:0;
269
	background: #EBF7FC;
270
	color:#000;
271
	font-family: 'Trebuchet MS', Verdana, Arial, Helvetica, Sans-Serif;
272
	font-size: small;
273
	height:101%;
274
}
275

    
276
#container {
277
	min-width:48em;
278
    width: 70%;
279
	background: #A8BCCB url(<?php echo WB_URL; ?>/templates/wb_theme/images/background.png) repeat-x;
280
	border:1px solid #000;
281
	color:#000;
282
	margin:2em auto;
283
	padding:0 20px;
284
	min-height: 500px;
285
	text-align:left;
286
}
287
.page {
288
	width:100%;
289
    overflow: hidden;
290
}
291
.content {
292
    padding: 10px;
293
}
294
p { line-height:1.5em; }
295

    
296
form {
297
	display: inline-block;
298
	line-height: 20px;
299
	vertical-align: baseline;
300
}
301
input[type="submit"].restart {
302
	background-color: #FFDBDB;
303
	font-weight: bold;
304
}
305

    
306
h1,h2,h3,h4,h5,h6 {
307
	font-family: Verdana, Arial, Helvetica, sans-serif;
308
	color: #26527D;
309
	margin-top: 1.0em;
310
	margin-bottom: 0.1em;
311
}
312

    
313
h1 { font-size:150%; }
314
h2 { font-size: 130%; border-bottom: 1px #CCC solid; }
315
h3 { font-size: 110%; font-weight: bold; }
316

    
317
textarea {
318
	width:100%;
319
	border: 2px groove #0F1D44;
320
	padding: 2px;
321
	color: #000;
322
	font-weight: normal;
323
}
324
.ok, .error { font-weight:bold; }
325
.ok { color:green; }
326
.error { color:red; }
327
.check { color:#555; }
328

    
329
span.ok,
330
span.error {
331
    margin-left: 0em;
332
}
333

    
334
.warning {
335
	background:#FFDBDB;
336
	padding:1em;
337
	margin-top:0.5em;
338
	border: 1px solid #DB0909;
339
}
340
.info {
341
	background:#C7F4C7;
342
	padding:1em;
343
	margin-top:0.5em;
344
	border: 1px solid #277A29;
345
}
346

    
347
</style>
348
</head>
349
<body>
350
<div id="container">
351
<div class="page">
352
<img src="<?php echo WB_URL; ?>/templates/wb_theme/images/logo.png" alt="WebsiteBaker Project" />
353
<div class="content">
354
<h1>WebsiteBaker Upgrade</h1>
355
<?php
356
	if( version_compare( WB_VERSION, '2.7', '<' )) {
357
		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');
358
		echo "</div>
359
		</div>
360
		</div>
361
		</body>
362
		</html>
363
		";
364
		exit();
365
	}
366
if($admin->get_user_id()!=1){
367
	status_msg('<br /><h3>WebsiteBaker upgrading is not possible!<br />Before upgrading '
368
	          .'to Revision '.REVISION.' you have to login as System-Administrator!</h3>',
369
	           'warning', 'div');
370
	echo '<br /><br />';
371
// delete remember key of current user from database
372
	//if (isset($_SESSION['USER_ID']) && isset($database)) {
373
	//	$table = TABLE_PREFIX . 'users';
374
	//	$sql = "UPDATE `$table` SET `remember_key` = '' WHERE `user_id` = '" . (int) $_SESSION['USER_ID'] . "'";
375
	//	$database->query($sql);
376
	//}
377
// delete remember key cookie if set
378
	if (isset($_COOKIE['REMEMBER_KEY']) && !headers_sent() ) {
379
		setcookie('REMEMBER_KEY', '', time() - 3600, '/');
380
	}
381
	// delete most critical session variables manually
382
	$_SESSION['USER_ID'] = null;
383
	$_SESSION['GROUP_ID'] = null;
384
	$_SESSION['GROUPS_ID'] = null;
385
	$_SESSION['USERNAME'] = null;
386
	$_SESSION['PAGE_PERMISSIONS'] = null;
387
	$_SESSION['SYSTEM_PERMISSIONS'] = null;
388
	// overwrite session array
389
	$_SESSION = array();
390
	// delete session cookie if set
391
	if (isset($_COOKIE[session_name()]) && !headers_sent()) {
392
		setcookie(session_name(), '', time() - 42000, '/');
393
	}
394
	// delete the session itself
395
	session_destroy();
396
	status_msg('<br /><h3>You have to login as System-Adminstrator start '
397
	          .'upgrade-script.php again!</h3>',
398
	           'info', 'div');
399
	echo '<br /><br />';
400
	if(defined('ADMIN_URL')) {
401
		echo '<form action="'.ADMIN_URL.'/index.php" method="post">'
402
		    .'&nbsp;<input name="backend_send" type="submit" value="Kick me to the Login" />'
403
		    .'</form>';
404
	}
405
	echo '<br /><br /></div>'
406
	    .'</div>'
407
	    .'</div>'
408
	    .'</body>'
409
	    .'</html>';
410
	exit();
411
}
412

    
413
?>
414
<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>
415

    
416
<?php
417

    
418
/**
419
 * Check if disclaimer was accepted
420
 */
421
$bDebugModus = false;
422
$bDebugModus = ( (isset($_POST['debug_confirmed']) && $_POST['debug_confirmed'] == 'debug') ? true : false);
423
if (!(isset($_POST['backup_confirmed']) && $_POST['backup_confirmed'] == 'confirmed')) { ?>
424
<h2>Step 1: Backup your files</h2>
425
<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>
426
<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>
427

    
428
<form action="<?php echo $_SERVER['SCRIPT_NAME'];?>" method="post">
429
<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>
430
<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>
431
<br /><br /><input name="debug_confirmed" type="checkbox" value="debug" />&nbsp;<strong>Here you can get more details during running upgrade.</strong>
432
<br /><br /><input name="send" type="submit" value="Start upgrade script" />
433
</form>
434
<br />
435

    
436
<?php
437
	status_msg('<strong> Notice:</strong><br />You need to confirm that you have created '
438
			  .'a manual backup of the '.PAGES_DIRECTORY.'/ directory and the MySQL '
439
	          .'database before you can proceed.',
440
	           'warning', 'div');
441
	echo '<br /><br /></div>'
442
	    .'</div>'
443
	    .'</div>'
444
	    .'</body>'
445
	    .'</html>';
446
	exit();
447
}
448

    
449
/**********************************************************
450
 *  - check tables coming with WebsiteBaker
451
 */
452
	$aMissingTables = UpgradeHelper::getMissingTables($aPackage);
453
	if( sizeof($aMissingTables) == 0){
454
        echo '<h4 style="margin-left:0;">NOTICE: '.sizeof($aPackage).' total tables '
455
		    .'included in package are successfully installed into your database `'
456
		    .$database->DbName.'` '.$OK.'</h4>';
457
    } else {
458
        status_msg('<strong>:</strong><br />can\'t run Upgrade, missing tables', 'warning', 'div');
459
        echo '<h4>Missing required tables. You can install them in backend->addons->modules.<br />'
460
            .'Or if you uploaded per FTP install possible by backend->addons->modules->advanced.<br />'
461
            .'First rename or delete the upgrade-script.php, so the script can\'t start automatically by backend<br />'
462
            .'After installing missing tables upload and run again upgrade-script.php<br /><br /></h4>'
463
            .'<h4 class="warning">'
464
            .'Missing required tables.<br /><br />'
465
            .'TABLE `'.implode('` missing! '.$FAIL.'<br />TABLE `',$aMissingTables).'` missing! '.$FAIL
466
            .'<br /><br /></h4>'
467
            .'<br /><br />';
468
        if(isset($_SERVER['SCRIPT_NAME'])) {
469
        	echo '<form action="'.$_SERVER['SCRIPT_NAME'].'/">'
470
        	    .'&nbsp;<input type="submit" value="Start upgrade again" />'
471
        	    .'</form>';
472
        }
473
        if(defined('ADMIN_URL')) {
474
        	echo '<form action="'.ADMIN_URL.'/index.php" method="post">'
475
        	    .'&nbsp;<input name="backend_send" type="submit" value="kick me to the Backend" />'
476
        	    .'</form>';
477
        }
478
        echo '<br /><br /></div>'
479
            .'</div>'
480
            .'</div>'
481
            .'</body>'
482
            .'</html>';
483
		exit();
484
	}
485

    
486
	echo '<h3>Step '.(++$stepID).': Setting default_theme</h3>';
487
	$aDebugMessage = array();
488
	/**********************************************************
489
	 *  - Adding field default_theme to settings table
490
	 */
491
	$aDebugMessage[] = '<div style="margin-left:2em;">';
492
	$aDebugMessage[] = "<br /><span><strong>Adding default_theme to settings table</strong></span>";
493
	// db_update_key_value('settings', 'default_theme', $DEFAULT_THEME);
494
	$cfg = array(
495
		'default_theme' => $DEFAULT_THEME
496
	);
497
	$aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
498
	$aDebugMessage[] = '</div>';
499

    
500
	if($bDebugModus) {
501
		echo implode(PHP_EOL,$aDebugMessage);
502
	}
503
	$aDebugMessage = array();
504
	echo'<h3>Step '.(++$stepID).': Updating core table included in package</h3>';
505
	/**********************************************************
506
	 *  - Adding field sec_anchor to settings table
507
	 */
508
	echo '<div style="margin-left:2em;">';
509
	echo "<h4>Adding/updating entries on table settings</h4>";
510
	$aDebugMessage[] = "<span>Adding/updating sec_anchor to settings table</span>";
511
	$cfg = array(
512
		'sec_anchor' => defined( 'SEC_ANCHOR' )&& (SEC_ANCHOR!='') ? SEC_ANCHOR : 'Sec'
513
	);
514
	$aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
515

    
516
	/**********************************************************
517
	 *  - Adding redirect timer to settings table
518
	 */
519
	$aDebugMessage[] = "<span>Adding/updating redirect timer to settings table</span>";
520
	$cfg = array(
521
		'redirect_timer' => defined('REDIRECT_TIMER')&& (REDIRECT_TIMER!='') ? REDIRECT_TIMER : '1500'
522
	);
523
	$aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
524

    
525
	/**********************************************************
526
	 *  - Adding default_time_formatr to settings table
527
	 */
528
	$aDebugMessage[] = "<span>Adding/updating default_time_format to settings table</span>";
529
	$cfg = array(
530
		'default_time_format' => defined('DEFAULT_TIME_FORMAT')&& (DEFAULT_TIME_FORMAT!='') ? DEFAULT_TIME_FORMAT : 'h:i A'
531
	);
532
	$aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
533

    
534
	/**********************************************************
535
	 *  - Adding rename_files_on_upload to settings table
536
	 */
537
	$aDebugMessage[] = "<span>Adding/Updating rename_files_on_upload to settings table</span>";
538
	$cfg = array(
539
	    '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')
540
	);
541
	if( version_compare( WB_VERSION, '2.8.2', '<' )) {
542
		$cfg = array(
543
		    'rename_files_on_upload' => 'ph.*?,cgi,pl,pm,exe,com,bat,pif,cmd,src,asp,aspx,js'
544
		);
545
	}
546
	$aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
547

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

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

    
558
	/**********************************************************
559
	 *  - Adding fingerprint_with_ip_octets to settings table
560
	 */
561
	$aDebugMessage[] = "<span>Adding/updating fingerprint_with_ip_octets to settings table</span>";
562
	$cfg = array(
563
		'fingerprint_with_ip_octets' => (defined('FINGERPRINT_WITH_IP_OCTETS') ? FINGERPRINT_WITH_IP_OCTETS : '2'),
564
		'secure_form_module' => (defined('SECURE_FORM_MODULE') ? SECURE_FORM_MODULE : '')
565
	);
566

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

    
569
	/**********************************************************
570
	 *  - Adding page_icon_dir to settings table
571
	 */
572
	$aDebugMessage[] = "<span>Adding/updating page_icon_dir to settings table</span>";
573
	$cfg = array(
574
		'page_icon_dir' => (defined('PAGE_ICON_DIR')&& (PAGE_ICON_DIR!='') ? PAGE_ICON_DIR : '/templates/*/title_images'),
575
	);
576

    
577
	$aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
578
	/**********************************************************
579
	 *  - Adding page_extended to settings table
580
	 */
581
	$aDebugMessage[] = "<span>Adding/updating page_extendet to settings table</span>";
582
	$cfg = array(
583
		'page_extendet' => (defined('PAGE_EXTENDET') ? PAGE_EXTENDET : 'true'),
584
	);
585

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

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

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

    
598
	/**********************************************************
599
	 *  - Adding confirmed_registration to settings table
600
	 */
601
	$aDebugMessage[] = "<span>Adding/updating confirmed_registration to settings table</span>";
602
	$cfg = array(
603
		'confirmed_registration' => (defined('CONFIRMED_REGISTRATION') ? CONFIRMED_REGISTRATION : '0')
604
	);
605

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

    
608
	/**********************************************************
609
	 *  - Adding dev_infos to settings table
610
	 */
611
	$aDebugMessage[] = "<span>Adding/updating dev_infos to settings table</span>";
612
	$cfg = array(
613
		'dev_infos' => (defined('DEV_INFOS') ? DEV_INFOS : 'false')
614
	);
615

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

    
618
	/**********************************************************
619
	 *  - Adding server_timezone to settings table
620
	 */
621
	$aDebugMessage[] = "<span>Adding/updating server_timezone to settings table</span>";
622
	$cfg = array(
623
		'server_timezone' => (defined('SERVER_TIMEZONE') ? SERVER_TIMEZONE : 'UTC')
624
	);
625

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

    
628
	/**********************************************************
629
	 *  - Adding password settings to settings table
630
	 */
631
	$aDebugMessage[] = "<span>Adding/updating password settings to settings table</span>";
632
	$cfg = array();
633
	$cfg['password_crypt_loops'] = (defined('PASSWORD_CRYPT_LOOPS') ? PASSWORD_CRYPT_LOOPS : '12');
634
	$cfg['password_hash_type'] = (defined('PASSWORD_HASH_TYPES') ? PASSWORD_HASH_TYPES : 'false');
635
	$cfg['password_length'] = (defined('PASSWORD_LENGTH') ? PASSWORD_LENGTH : '10');
636
	$cfg['password_use_types'] = (defined('PASSWORD_USE_TYPES') ? PASSWORD_USE_TYPES : (int)0xFFFF);
637
    $aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
638

    
639
if($bDebugModus) {
640
    echo implode(PHP_EOL,$aDebugMessage);
641
}
642
echo '</div>';
643

    
644
$aDebugMessage = array();
645
if(version_compare(WB_REVISION, REVISION, '<='))
646
{
647
	echo '<div style="margin-left:2em;">';
648
	/**********************************************************
649
	 *  - Update search no results database filed to create
650
	 *  valid XHTML if search is empty
651
	 */
652
	if (version_compare(WB_VERSION, '2.8', '<'))
653
	{
654
		echo "<h4>Adding/updating fields on table search</h4>";
655
		echo "Updating database field `no_results` on search table: ";
656
		$search_no_results = addslashes('<tr><td><p>[TEXT_NO_RESULTS]</p></td></tr>');
657
		$sql  = 'UPDATE `'.TABLE_PREFIX.'search` ';
658
		$sql .= 'SET `value`=\''.$search_no_results.'\' ';
659
		$sql .= 'WHERE `name`=\'no_results\'';
660
		echo ($database->query($sql)) ? " $OK<br />" : " $FAIL!<br />";
661
	}
662

    
663
	$aDebugMessage = array();
664
	echo "<h4>Adding/updating field on table pages</h4>";
665
	/**********************************************************
666
	 *  - Add field "page_trail" to table "pages"
667
	 */
668
	$table_name = TABLE_PREFIX.'pages';
669
	$field_name = 'page_trail';
670
	$description = "VARCHAR( 255 ) NOT NULL DEFAULT ''";
671
	add_modify_field_in_database($table_name,$field_name,$description);
672

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

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

    
689
	/**********************************************************
690
	 *  - Add field "menu_icon_1" to table "pages"
691
	 */
692
	$table_name = TABLE_PREFIX.'pages';
693
	$field_name = 'menu_icon_1';
694
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '' AFTER `menu_icon_0`";
695
	add_modify_field_in_database($table_name,$field_name,$description);
696

    
697
	/**********************************************************
698
	 *  - Add field "tooltip" to table "pages"
699
	 */
700
	$table_name = TABLE_PREFIX.'pages';
701
	$field_name = 'tooltip';
702
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '' AFTER `menu_icon_1`";
703
	add_modify_field_in_database($table_name,$field_name,$description);
704

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

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

    
721
	/**********************************************************
722
	 *  - Add field "viewing_groups" to table "pages"
723
	 */
724
	$table_name = TABLE_PREFIX.'pages';
725
	$field_name = 'viewing_groups';
726
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '1'";
727
	 add_modify_field_in_database($table_name,$field_name,$description);
728

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

    
737
	/**********************************************************
738
	 *  - Add field "custom01" to table "pages"
739
	 */
740
	$table_name = TABLE_PREFIX.'pages';
741
	$field_name = 'custom01';
742
	$description = "VARCHAR( 255 ) NOT NULL DEFAULT '' ";
743
	add_modify_field_in_database($table_name,$field_name,$description);
744

    
745
	/**********************************************************
746
	 *  - Add field "custom02" to table "pages"
747
	 */
748
	$table_name = TABLE_PREFIX.'pages';
749
	$field_name = 'custom02';
750
	$description = "VARCHAR( 255 ) NOT NULL DEFAULT '' ";
751
	add_modify_field_in_database($table_name,$field_name,$description);
752

    
753
	if($bDebugModus) {
754
		echo implode(PHP_EOL,$aDebugMessage);
755
	}
756

    
757
	$aDebugMessage = array();
758
	/**********************************************************
759
	 * modify wrong strucre on table sections
760
	 * wrong structure let crash wb
761
	 */
762
	echo "<h4>Change field structure on table sections</h4>";
763
	$table_name = TABLE_PREFIX.'sections';
764
	$description = "VARCHAR( 255 ) NOT NULL DEFAULT ''";
765
	$aDebugMessage[] = "<span>Modify field module on sections table</span>";
766
	$aDebugMessage[] = ($database->field_modify($table_name, 'module', $description) ? " $OK<br />" : " $FAIL!<br />");
767
	$aDebugMessage[] = "<span>Modify field block on sections table</span>";
768
	$description = "int(11) NOT NULL DEFAULT '1'";
769
	$aDebugMessage[] = ($database->field_modify($table_name, 'block', $description) ? " $OK<br />" : " $FAIL!<br />");
770
	$description = "int(11) NOT NULL DEFAULT '0'";
771
	$aDebugMessage[] = "<span>Modify field publ_start on sections table</span>";
772
	$aDebugMessage[] = ($database->field_modify($table_name, 'publ_start', $description) ? " $OK<br />" : " $FAIL!<br />");
773
	$aDebugMessage[] = "<span>Modify field publ_end on sections table</span>";
774
	$aDebugMessage[] = ($database->field_modify($table_name, 'publ_end', $description) ? " $OK<br />" : " $FAIL!<br />");
775

    
776
	if($bDebugModus) {
777
		echo implode(PHP_EOL,$aDebugMessage);
778
	}
779
	echo '</div>';
780
}
781

    
782
if(version_compare(WB_REVISION, REVISION, '<='))
783
{
784
	$aDebugMessage = array();
785
	echo '<h3>Step '.(++$stepID).': Updating structure in table users/groups</h3>';
786
	/**********************************************************
787
	 * Modify Administrator on groups table
788
	 */
789
	echo '<div style="margin-left:2em;">';
790
	echo "<h4>Updating Administrator group permissions on table groups</h4>";
791
	$aDebugMessage[] = "<span>Modify Administrator on groups table</span>";
792
	$sModulePermissions = '';
793
	$sTemplatePermissions = '';
794
	$sSystemPermissions  = 'access,addons,admintools,admintools_view,groups,groups_add,groups_delete,groups_modify,groups_view,';
795
	$sSystemPermissions .= 'languages,languages_install,languages_uninstall,languages_view,media,media_create,media_delete,media_rename,media_upload,media_view,';
796
	$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,';
797
	$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';
798

    
799
	$sql  = 'UPDATE `'.TABLE_PREFIX.'groups` ';
800
	$sql .= 'SET `name` = \'Administrators\', ';
801
	$sql .= '`system_permissions` = \''.$sSystemPermissions.'\', ';
802
	$sql .= '`module_permissions` = \''.$sModulePermissions.'\', ';
803
	$sql .= '`template_permissions` = \''.$sTemplatePermissions.'\' ';
804
	$sql .= 'WHERE `group_id` = \'1\' ';
805
	$aDebugMessage[] = ($database->query($sql)) ? " $OK<br />" : " $FAIL!<br />";
806
	if( ($admin->is_authenticated() == true) && ($admin->ami_group_member('1') ) ) {
807
	    $_SESSION['SYSTEM_PERMISSIONS'] = array_merge($_SESSION['SYSTEM_PERMISSIONS'], explode(',', $sSystemPermissions));
808
	}
809

    
810
	if($bDebugModus) {
811
		echo implode(PHP_EOL,$aDebugMessage);
812
	}
813
	echo '</div>';
814
	$aDebugMessage = array();
815
	/**********************************************************
816
	 *   `confirm_code` VARCHAR(32) NOT NULL DEFAULT '',
817
	 *   `confirm_timeout` INT(11) NOT NULL DEFAULT '0',
818
	 */
819
	echo '<div style="margin-left:2em;">';
820
	echo "<h4>Change field structure on table users</h4>";
821
	$table_name = TABLE_PREFIX.'users';
822
	$field_name = 'confirm_code';
823
	$description = "VARCHAR( 32 ) NOT NULL DEFAULT '' AFTER `password` ";
824
	add_modify_field_in_database($table_name,$field_name,$description);
825

    
826
	$table_name = TABLE_PREFIX.'users';
827
	$field_name = 'confirm_timeout';
828
	$description = "INT(11) NOT NULL DEFAULT '0' AFTER `confirm_code` ";
829
	add_modify_field_in_database($table_name,$field_name,$description);
830

    
831
	if($bDebugModus) {
832
	    echo implode(PHP_EOL,$aDebugMessage);
833
	}
834
	echo '</div>';
835

    
836
	$aDebugMessage = array();
837
	/**********************************************************
838
	* Updating group_id in table users
839
	*/
840
	echo '<div style="margin-left:2em;">';
841
	echo "<h4>Updating users groups permissions on table groups</h4>";
842
	    $aUsers = array();
843
		// Get existing values
844
        $sql  = 'SELECT * FROM `'.TABLE_PREFIX.'users` ' ;
845
        $sql .= 'WHERE `user_id` != 1 ';
846
        if($oUser = $database->query($sql)){
847
            $iTotalUsers = $oUser->numRows();
848
            while($Users = $oUser->fetchRow(MYSQL_ASSOC)) {
849
                $aUsers[$Users['user_id']]['groups_id'] = $Users['groups_id'];
850
                $aUsers[$Users['user_id']]['display_name'] = $Users['display_name'];
851
            }
852
        } else {
853
            $aDebugMessage[] = $database->is_error()==false ? " $OK<br />" : " $FAIL!<br />";
854
        }
855
        foreach($aUsers AS $user_id => $value){
856
                // choose group_id from groups_id - workaround for still remaining calls to group_id (to be cleaned-up)
857
                $aGroups_id = explode(',', $aUsers[$user_id]['groups_id']);
858
                $groups_id = $aUsers[$user_id]['groups_id'];
859
                $group_id = 0;
860
                //if user is in administrator-group, get this group else just get the first one
861
                if($admin->is_group_match($aGroups_id,'1')) { $group_id = 1; $groups_id = '1'; } else { $group_id = intval($aGroups_id[0]); }
862
                $sMessage = "<span>Updating group_id ".$TEXT['DISPLAY_NAME']." " .$aUsers[$user_id]['display_name']."</span>";
863
                $sql  = 'UPDATE `'.TABLE_PREFIX.'users` ';
864
                $sql .= 'SET `group_id`  = '.$group_id.', ';
865
                $sql .=     '`groups_id` = \''.$groups_id.'\' ';
866
                $sql .= 'WHERE `user_id` = '.intval($user_id);
867
                if($oRes = $database->query($sql)){  }
868
                $aDebugMessage[] = $database->is_error()==false ? $sMessage." $OK<br />" : $sMessage." $FAIL!<br />";
869
        }
870
        unset($aUsers);
871
	$aDebugMessage[] = '</div>';
872

    
873
	if($bDebugModus) {
874
	// $aDebugMessage[] =
875
	    echo implode(PHP_EOL,$aDebugMessage);
876
	}else {
877
	    echo '<span><strong>'.$iTotalUsers.' users updating the groups</strong></span>'." $OK<br />";
878
	    echo '</div>';
879
	}
880
}
881

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

    
885
echo '<div style="margin-left:2em;">';
886
	/**********************************************************
887
	* upgrade media directory index protect files
888
	*/
889
	echo '<h4>Upgrade media directory '.MEDIA_DIRECTORY.'/ index.php protect files</h4>';
890
	$aDebugMessage = rebuildFolderProtectFile();
891
	if( sizeof( $aDebugMessage ) ){
892
		echo '<span><strong>Upgrade '.sizeof( $aDebugMessage ).' directory '.MEDIA_DIRECTORY.'/ protect files</strong></span>'." $OK<br />";
893
	} else {
894
		echo '<span><strong>Upgrade directory '.MEDIA_DIRECTORY.'/ protect files</strong></span>'." $FAIL!<br />";
895
		echo implode ('<br />',$aDebugMessage);
896
	}
897

    
898
    $aDebugMessage = array();
899
    /**********************************************************
900
     * upgrade pages directory index access files
901
     */
902
	echo '<h4>Upgrade pages directory '.PAGES_DIRECTORY.'/  protect and access files</h4>';
903

    
904
    /**********************************************************
905
     *  - Reformat/rebuild all existing access files
906
     */
907
//    $sPagePath = (defined('PAGES_DIRECTORY') && (PAGES_DIRECTORY != '') ? PAGES_DIRECTORY : '');
908
//	$sPageDir = str_replace('\\','/',WB_PATH.$sPagePath);
909
//	$aProtectedFiles = array(
910
//           $sPageDir.'/intro.php',
911
//           $sPageDir.'/intro/intro.php',
912
//    );
913
    $msg = rebuild_all_accessfiles($bDebugModus);
914
//	$aDebugMessage = rebuildFolderProtectFile($dir);
915
	echo '<strong>'.implode ('<br />',$msg).'</strong>';
916
    echo '</div>';
917

    
918
	/* *****************************************************************************
919
	 * - check for deprecated / never needed files
920
	 */
921
	$iLoaded = sizeof($aFilesToRemove);
922
	if($iLoaded) {
923
		echo '<h3>Step '.(++$stepID).': Remove deprecated and outdated files</h3>';
924
		$iFailed = 0;
925
		$iFound = 0;
926
		$searches = array(
927
			'[ADMIN]',
928
			'[MEDIA]',
929
			'[PAGES]',
930
			'[FRAMEWORK]',
931
			'[MODULES]',
932
			'[TEMPLATE]'
933
		);
934
		$replacements = array(
935
			'/'.substr(ADMIN_PATH, strlen(WB_PATH)+1),
936
			MEDIA_DIRECTORY,
937
			PAGES_DIRECTORY,
938
			'/framework',
939
			'/modules',
940
			'/templates'
941
		);
942

    
943
		$msg = '';
944
		echo '<div style="margin-left:2em;">';
945
		echo '<h4>Search '.$iLoaded.' deprecated and outdated files</h4>';
946
		foreach( $aFilesToRemove as $file )
947
		{
948
			$file = str_replace($searches, $replacements, $file);
949
			if( is_writable(WB_PATH.'/'.$file) ) {
950
				$iFound++;
951
				// try to unlink file
952
				if(!unlink(WB_PATH.$file)) {
953
					$iFailed++;
954
				}
955
			}
956
			if( is_readable(WB_PATH.'/'.$file) ) {
957
				// save in err-list, if failed
958
				$msg .= $file.'<br />';
959
			}
960
		}
961
		$iRemove = $iFound-$iFailed;
962
		echo '<strong>Remove '.$iRemove.' from '.$iFound.' founded</strong> ';
963
		echo ($iFailed == 0) ? $OK : $FAIL;
964
		echo '</div>';
965

    
966
		if($msg != '')
967
		{
968
			$msg = '<br /><br />Following files are deprecated, outdated or a security risk and
969
				    can not be removed automatically.<br /><br />Please delete them
970
					using FTP and restart upgrade-script!<br /><br />'.$msg.'<br />';
971
			status_msg($msg, 'error warning', 'div');
972
			echo '<p style="font-size:120%;"><strong>WARNING: The upgrade script failed ...</strong></p>';
973

    
974
			echo '<form action="'.$_SERVER['SCRIPT_NAME'].'">';
975
			echo '&nbsp;<input name="send" type="submit" value="Restart upgrade script" />';
976
			echo '</form>';
977
			echo "<br /><br /></div>
978
			</div>
979
			</div>
980
			</body>
981
			</html>";
982
			exit;
983
		}
984
	}
985

    
986

    
987
	/**********************************************************
988
	 * - check for deprecated / never needed files
989
	 */
990
	$iLoaded = sizeof($dirRemove);
991
	if($iLoaded) {
992
		echo '<h3>Step  '.(++$stepID).': Remove deprecated and outdated folders</h3>';
993
		$iFailed = 0;
994
		$iFound = 0;
995
		$searches = array(
996
			'[ADMIN]',
997
			'[MEDIA]',
998
			'[PAGES]',
999
			'[TEMPLATE]'
1000
		);
1001
		$replacements = array(
1002
			substr(ADMIN_PATH, strlen(WB_PATH)+1),
1003
			MEDIA_DIRECTORY,
1004
			PAGES_DIRECTORY,
1005
			'/templates',
1006
		);
1007
		$msg = '';
1008
		echo '<div style="margin-left:2em;">';
1009
		echo '<h4>Search '.$iLoaded.' deprecated and outdated folders</h4>';
1010
		foreach( $dirRemove as $dir ) {
1011
			$dir = str_replace($searches, $replacements, $dir);
1012
			$dir = WB_PATH.'/'.$dir;
1013
			if( is_dir( $dir )) {
1014
				$iFound++;
1015
			// try to delete dir
1016
				if(!is_writable( $dir ) || !rm_full_dir($dir)) {
1017
				// save in err-list, if failed
1018
					$iFailed++;
1019
				}
1020
			}
1021
			if( is_readable(WB_PATH.'/'.$dir) ) {
1022
				$msg .= str_replace(WB_PATH,'',$dir).'<br />';
1023
			}
1024
		}
1025
		
1026
		$iRemove = $iFound-$iFailed;
1027
		echo '<strong>Remove '.$iRemove.' from '.$iFound.' founded</strong> ';
1028
		echo ($iFailed == 0) ? $OK : $FAIL;
1029
		echo '</div>';
1030

    
1031
		if($msg != '') {
1032
			$msg = '<br /><br />Following directories are deprecated, outdated or a security risk and
1033
					can not be removed automatically.<br /><br />Please delete them
1034
					using FTP and restart upgrade-script!<br /><br />'.$msg.'<br />';
1035
			status_msg($msg, 'error warning', 'div');
1036
			echo '<p style="font-size:120%;"><strong>WARNING: The upgrade script failed ...</strong></p>';
1037
			echo '<form action="'.$_SERVER['SCRIPT_NAME'].'">';
1038
			echo '&nbsp;<input name="send" type="submit" value="Restart upgrade script" />';
1039
			echo '</form>';
1040
			echo "<br /><br /></div>
1041
			</div>
1042
			</div>
1043
			</body>
1044
			</html>";
1045
			exit;
1046
		}
1047

    
1048

    
1049
	}
1050

    
1051
	/**********************************************************
1052
	 * upgrade modules if newer version is available
1053
	 * $aModuleList list of proofed modules
1054
	 */
1055
	$aModuleList = array(
1056
	              'captcha_control','code','droplets','form','jsadmin',
1057
	              'menu_link','news','output_filter','wrapper','wysiwyg','MultiLingual');
1058
	if(sizeof($aModuleList)) 
1059
	{
1060
		echo '<h3>Step '.(++$stepID).': Upgrade proofed modules</h3>';
1061
		foreach($aModuleList as $sModul) {
1062
			if(file_exists(WB_PATH.'/modules/'.$sModul.'/upgrade.php')) {
1063
				$currModulVersion = get_modul_version ($sModul, false);
1064
				$newModulVersion =  get_modul_version ($sModul, true);
1065
				if((version_compare($currModulVersion, $newModulVersion) <= 0)) {
1066
					echo '<div style="margin-left:2em;">';
1067
					echo '<h4>'.'Upgrade module \''.$sModul.'\' version '.$newModulVersion.'</h4>';
1068
					require(WB_PATH.'/modules/'.$sModul.'/upgrade.php');
1069
					echo '</div>';
1070
				}
1071
			}
1072
		}
1073
	}
1074

    
1075
	/**********************************************************
1076
	 * Reformat/rebuild all existing moules access files
1077
	 * $aModuleList list of modules
1078
	 */
1079
	$aModuleList = array('bakery','topics','news');
1080
	if(sizeof($aModuleList)) 
1081
	{
1082
		echo '<h3>Step '.(++$stepID).': Create/Reorg Accessfiles from modules</h3>';
1083
		foreach($aModuleList as $sModul) {
1084
			$aReturnMsg = array();
1085
			$sModulReorg = 'm_'.$sModul.'_Reorg';
1086
			if(class_exists($sModulReorg)) {
1087
				$sModulVersion =  get_modul_version ($sModul, true);
1088
				echo '<div style="margin-left:2em;">';
1089
				echo '<h4>'.'Create/Reorg Accesfiles for module \''.$sModul.'\' version '.$sModulVersion.'</h4>';
1090
				$oReorg = new $sModulReorg();
1091
				$aReturnMsg = $oReorg->execute(); // show details
1092
				if(is_array($aReturnMsg)) {
1093
					foreach($aReturnMsg as $title) {
1094
					echo '<strong>'.$title.'</strong><br />';
1095
					}
1096
				}
1097
				echo '</div>';
1098
			}
1099
		}
1100
	}
1101
/**********************************************************
1102
 *  - Reload all addons
1103
 */
1104

    
1105
	echo '<h3>Step '.(++$stepID).' : Reload all addons database entry (no upgrade)</h3><br />';
1106
	echo '<div style="margin-left:2em;">';
1107
	$iFound = 0;
1108
	$iLoaded = 0;
1109
	////delete modules
1110
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'module'");
1111
	// Load all modules
1112
	if( ($handle = opendir(WB_PATH.'/modules/')) ) {
1113
		while(false !== ($file = readdir($handle))) {
1114
			if($file != '' && substr($file, 0, 1) != '.' && is_dir(WB_PATH.'/modules/'.$file) ) {
1115
				$iFound++;
1116
				$iLoaded = load_module(WB_PATH.'/modules/'.$file ) ? $iLoaded+1 : $iLoaded;
1117
// 	upgrade_module($file, true);
1118
			}
1119
		}
1120
		closedir($handle);
1121
	}
1122
	echo '<strong><span>'.$iLoaded.' Modules reloaded,</span> found '.$iFound.' directories in folder /modules/</strong><br />';
1123

    
1124
	$iFound = 0;
1125
	$iLoaded = 0;
1126
	////delete templates
1127
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'template'");
1128
	// Load all templates
1129
	if( ($handle = opendir(WB_PATH.'/templates/')) ) {
1130
		while(false !== ($file = readdir($handle))) {
1131
			if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
1132

    
1133
				$iFound++;
1134
				$iLoaded = (load_template(WB_PATH.'/templates/'.$file)==true) ? $iLoaded+1 : $iLoaded;
1135

    
1136
			}
1137
		}
1138
		closedir($handle);
1139
	}
1140
	echo '<strong><span>'.$iLoaded.' Templates reloaded,</span> found '.$iFound.' directories in folder /templates/</strong><br />';
1141

    
1142
	$iFound = 0;
1143
	$iLoaded = 0;
1144
	////delete languages
1145
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'language'");
1146
	// Load all languages
1147
	if( ($handle = opendir(WB_PATH.'/languages/')) ) {
1148
		while(false !== ($file = readdir($handle))) {
1149
			if($file != '' AND (preg_match('#^([A-Z]{2}.php)#', basename($file)))) {
1150
				$iFound++;
1151
				$iLoaded = load_language(WB_PATH.'/languages/'.$file) ? $iLoaded+1 : $iLoaded;
1152
			}
1153
		}
1154
		closedir($handle);
1155
	}
1156
	echo '<strong><span>'.$iLoaded.' Languages reloaded,</span> found '.$iFound.' files in folder /languages/</strong><br />';
1157
	echo '</div>';
1158

    
1159
/**********************************************************
1160
 *  - install new droplets
1161
	$drops = (!in_array ( "mod_droplets", $all_tables)) ? "<br />Install droplets<br />" : "<br />Upgrade droplets<br />";
1162
	echo $drops;
1163
	$file_name = (!in_array ( "mod_droplets", $all_tables) ? "install.php" : "upgrade.php");
1164
	require_once (WB_PATH."/modules/droplets/".$file_name);
1165
********************************************************** */
1166

    
1167
/**********************************************************
1168
 *  - End of upgrade script
1169
 */
1170
	if(!defined('DEFAULT_THEME')) { define('DEFAULT_THEME', $DEFAULT_THEME); }
1171
	if(!defined('THEME_PATH')) { define('THEME_PATH', WB_PATH.'/templates/'.DEFAULT_THEME);}
1172
/**********************************************************
1173
 *  - Set Version to new Version
1174
 */
1175
echo '<h3>Step '.(++$stepID).': Update database version number </h3>';
1176
echo '<div style="margin-left:2em;">';
1177

    
1178
$cfg = array(
1179
	'wb_version' => VERSION,
1180
	'wb_revision' => REVISION,
1181
	'wb_sp' => SP
1182
);
1183
echo '<br /><span><strong>Set WebsiteBaker version number to '.VERSION.' '.SP.' '.' Revision ['.REVISION.'] : </strong></span>';
1184
echo (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
1185
echo '</div>';
1186

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

    
1192
if(defined('WB_URL')) {
1193
	echo '<form action="'.WB_URL.'/">';
1194
	echo '&nbsp;<input type="submit" value="kick me to the Frontend" />';
1195
	echo '</form>';
1196
}
1197
if(defined('ADMIN_URL')) {
1198
	echo '<form action="'.ADMIN_URL.'/">';
1199
	echo '&nbsp;<input type="submit" value="kick me to the Backend" />';
1200
	echo '</form>';
1201
}
1202

    
1203
echo "<br /><br /></div>
1204
</div>
1205
</div>
1206
</body>
1207
</html>
1208
";
1209
exit();
(6-6/6)