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: 2090 $
31
 * @link         $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/upgrade-script.php $
32
 * @lastmodified $Date: 2014-01-19 23:08:22 +0100 (Sun, 19 Jan 2014) $
33
 * @since        File available since 17.01.2013
34
 * @deprecated   
35
 * @description  xyz
36
 */
37
include_once(dirname(__FILE__).'/framework/UpgradeHelper.php');
38
// PHP less then 5.3.2 is prohibited ---
39
if (version_compare(PHP_VERSION, '5.3.2', '<')) {
40
    $sMsg = '<p style="color: #ff0000;">WebsiteBaker 2.8.4 and above is not able to run with PHP-Version less then 5.3.2!!<br />'
41
          . 'Please change your PHP-Version to any kind from 5.3.2 and up!<br />'
42
          . 'If you have problems to solve that, ask your hosting provider for it.<br  />'
43
          . 'The very best solution is the use of PHP-5.4 and up</p>';
44
    die($sMsg);
45
}
46
// --- delete fatal disturbing files before upgrade starts -------------------------------
47
$aPreDeleteFiles = array(
48
// list of files
49
	dirname(__FILE__).'/framework/PasswordHash.php'
50
);
51
if(sizeof($aPreDeleteFiles > 0))
52
{
53
// if there are files defined
54
	$sMsg = '';
55
	foreach($aPreDeleteFiles as $sFileToDelete)
56
	{
57
	// iterate the list
58
		if(file_exists($sFileToDelete))
59
		{
60
			if(!is_writeable($sFileToDelete) || !@unlink($sFileToDelete))
61
			{
62
			// notice if deleting fails
63
				$sMsg .= '<span style="color:red;">FAILED</span> deleting: '
64
				       . $sFileToDelete.'<br />'.PHP_EOL;
65
			}
66
		}
67
	}
68
	if($sMsg) {
69
	// stop script if there's an error occured
70
		$sMsg = $sMsg.'<br />'.PHP_EOL.'Please delete all of the files above manually!';
71
		UpgradeHelper::dieWithMessage($sMsg);
72
	}
73
}
74
unset($aPreDeleteFiles);
75
$sMsg = '';
76
// ---------------------------------------------------------------------------------------
77
// Include config file
78
$config_file = dirname(__FILE__).'/config.php';
79
if (is_readable($config_file) && !defined('WB_URL')) {
80
	require_once($config_file);
81
}
82
$oReg = WbAdaptor::getInstance();
83
UpgradeHelper::checkSetupFiles(dirname(__FILE__).'/');
84

    
85
if (!class_exists('admin', false)) {
86
	include(WB_PATH.'/framework/class.admin.php');
87
}
88
$admin = new admin('Addons', 'modules', false, false);
89
// solved wrong pages_directory value before creating access files
90
$sql  = 'SELECT `value` FROM `'.TABLE_PREFIX.'settings` '
91
      . 'WHERE `name`=\'pages_directory\'';
92
$sPagesDirectory = WbDatabase::getInstance()->get_one($sql);
93
$sTmp = trim($sPagesDirectory, '/');
94
$sTmpDir = ($sTmp == '' ? '' : '/'.$sTmp);
95
if($sTmp != $sPagesDirectory) {
96
	$sql = 'UPDATE `'.TABLE_PREFIX.'settings` '
97
		 . 'SET `value` = \''.$sTmpDir.'\' '
98
		 . 'WHERE `name`=\'pages_directory\' ';
99
	WbDatabase::getInstance()->query($sql);
100
}
101
require_once(WB_PATH.'/framework/functions.php');
102
// require_once(WB_PATH.'/framework/Database.php');
103

    
104
$oldVersion  = 'Version '.WB_VERSION;
105
$oldVersion .= (defined('WB_SP') ? WB_SP : '');
106
$oldRevision = (defined('WB_REVISION') ? ' Revision ['.WB_REVISION.'] ' : '') ;
107
$newVersion  = 'Version '.VERSION;
108
$newVersion .= (defined('SP') ? SP : '');
109
$newRevision = (defined('REVISION') ? ' Revision ['.REVISION.'] ' : '');
110

    
111
$bDebugModus = false;
112

    
113
// set addition settings if not exists, otherwise upgrade will be breaks
114
if(!defined('WB_SP')) { define('WB_SP',''); }
115
if(!defined('WB_REVISION')) { define('WB_REVISION',''); }
116
// database tables including in WB package
117
$aPackage = array (
118
    'settings','groups','addons','pages','sections','search','users',
119
    'mod_captcha_control','mod_jsadmin','mod_menu_link','mod_output_filter','mod_wrapper','mod_wysiwyg'
120
);
121

    
122
$OK            = ' <span class="ok">OK</span> ';
123
$FAIL          = ' <span class="error">FAILED</span> ';
124
$DEFAULT_THEME = 'WbTheme';
125

    
126
$stepID = 1;
127
$dirRemove = array(
128
//			'[TEMPLATE]allcss/',
129
//			'[TEMPLATE]blank/',
130
//			'[TEMPLATE]round/',
131
//			'[TEMPLATE]simple/',
132
            '[TEMPLATE]wb_theme/',
133
			'[ADMIN]themes/'
134
		 );
135

    
136
$aRemoveSingleFiles = array(
137
			'[ADMIN]preferences/details.php',
138
			'[ADMIN]preferences/email.php',
139
			'[ADMIN]preferences/password.php',
140
			'[ADMIN]pages/settings2.php',
141
			'[ADMIN]users/users.php',
142
			'[ADMIN]groups/add.php',
143
			'[ADMIN]groups/groups.php',
144
			'[ADMIN]groups/save.php',
145
			'[ADMIN]skel/themes/htt/groups.htt',
146

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

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

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

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

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

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

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

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

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

    
303
span.ok,
304
span.error {
305
    margin-left: 0em;
306
}
307

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

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

    
387
?>
388
<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>
389

    
390
<?php
391

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

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

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

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

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

    
474
	echo implode(PHP_EOL,$aDebugMessage);
475

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

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

    
500
	/**********************************************************
501
	 *  - Adding default_time_formatr to settings table
502
	 */
503
	$aDebugMessage[] = "<span>Adding/updating default_time_format to settings table</span>";
504
	$cfg = array(
505
		'default_time_format' => defined('DEFAULT_TIME_FORMAT')&& (DEFAULT_TIME_FORMAT!='') ? DEFAULT_TIME_FORMAT : 'h:i A'
506
	);
507
	$bLogStatus = (db_update_key_value( 'settings', $cfg ) ? true : false );
508
	$aDebugMessage[] = ( ($bLogStatus==true ) ? " $OK<br />" : " $FAIL!<br />");
509

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

    
525
	/**********************************************************
526
	 *  - Adding mediasettings to settings table
527
	 */
528
	$aDebugMessage[] = "<span>Adding/updating mediasettings to settings table</span>";
529
	$cfg = array(
530
		'mediasettings' => (defined('MEDIASETTINGS')&& (MEDIASETTINGS!='') ? MEDIASETTINGS : ''),
531
	);
532
	$bLogStatus = (db_update_key_value( 'settings', $cfg ) ? true : false );
533
	$aDebugMessage[] = ( ($bLogStatus==true ) ? " $OK<br />" : " $FAIL!<br />");
534

    
535
	/**********************************************************
536
	 *  - Adding fingerprint_with_ip_octets to settings table
537
	 */
538
	$aDebugMessage[] = "<span>Adding/updating fingerprint_with_ip_octets to settings table</span>";
539
	$cfg = array(
540
		'fingerprint_with_ip_octets' => (defined('FINGERPRINT_WITH_IP_OCTETS') ? FINGERPRINT_WITH_IP_OCTETS : '2'),
541
		'secure_form_module' => (defined('SECURE_FORM_MODULE') ? SECURE_FORM_MODULE : '')
542
	);
543
	$bLogStatus = (db_update_key_value( 'settings', $cfg ) ? true : false );
544
	$aDebugMessage[] = ( ($bLogStatus==true ) ? " $OK<br />" : " $FAIL!<br />");
545

    
546
	/**********************************************************
547
	 *  - Adding page_icon_dir to settings table
548
	 */
549
	$aDebugMessage[] = "<span>Adding/updating page_icon_dir to settings table</span>";
550
	$cfg = array(
551
		'page_icon_dir' => (defined('PAGE_ICON_DIR')&& (PAGE_ICON_DIR!='') ? PAGE_ICON_DIR : '/templates/*/title_images'),
552
	);
553
	$bLogStatus = (db_update_key_value( 'settings', $cfg ) ? true : false );
554
	$aDebugMessage[] = ( ($bLogStatus==true ) ? " $OK<br />" : " $FAIL!<br />");
555
	/**********************************************************
556
	 *  - Adding page_extended to settings table
557
	 */
558
	$aDebugMessage[] = "<span>Adding/updating page_extendet to settings table</span>";
559
	$cfg = array(
560
		'page_extendet' => (defined('PAGE_EXTENDET') ? PAGE_EXTENDET : 'true'),
561
	);
562
	$bLogStatus = (db_update_key_value( 'settings', $cfg ) ? true : false );
563
	$aDebugMessage[] = ( ($bLogStatus==true ) ? " $OK<br />" : " $FAIL!<br />");
564

    
565
	/**********************************************************
566
	 *  - Adding wbmail_signature to settings table
567
	 */
568
	$aDebugMessage[] = "<span>Adding/updating wbmail_signature to settings table</span>";
569
	$cfg = array(
570
		'wbmail_signature' => (defined('WBMAIL_SIGNATURE')&& (WBMAIL_SIGNATURE!='') ? WBMAIL_SIGNATURE : '')
571
	);
572
	$bLogStatus = (db_update_key_value( 'settings', $cfg ) ? true : false );
573
	$aDebugMessage[] = ( ($bLogStatus==true ) ? " $OK<br />" : " $FAIL!<br />");
574

    
575
	/**********************************************************
576
	 *  - Adding confirmed_registration to settings table
577
	 */
578
	$aDebugMessage[] = "<span>Adding/updating confirmed_registration to settings table</span>";
579
	$cfg = array(
580
		'confirmed_registration' => (defined('CONFIRMED_REGISTRATION') ? CONFIRMED_REGISTRATION : '0')
581
	);
582
	$bLogStatus = (db_update_key_value( 'settings', $cfg ) ? true : false );
583
	$aDebugMessage[] = ( ($bLogStatus==true ) ? " $OK<br />" : " $FAIL!<br />");
584

    
585
	/**********************************************************
586
	 *  - Adding dev_infos to settings table
587
	 */
588
	$aDebugMessage[] = "<span>Adding/updating dev_infos to settings table</span>";
589
	$cfg = array(
590
		'dev_infos' => (defined('DEV_INFOS') ? DEV_INFOS : 'false')
591
	);
592
	$bLogStatus = (db_update_key_value( 'settings', $cfg ) ? true : false );
593
	$aDebugMessage[] = ( ($bLogStatus==true ) ? " $OK<br />" : " $FAIL!<br />");
594

    
595
	/**********************************************************
596
	 *  - Adding server_timezone to settings table
597
	 */
598
	$aDebugMessage[] = "<span>Adding/updating server_timezone to settings table</span>";
599
	$cfg = array(
600
		'server_timezone' => (defined('SERVER_TIMEZONE') ? SERVER_TIMEZONE : 'UTC')
601
	);
602
	$bLogStatus = (db_update_key_value( 'settings', $cfg ) ? true : false );
603
	$aDebugMessage[] = ( ($bLogStatus==true ) ? " $OK<br />" : " $FAIL!<br />");
604

    
605
	/**********************************************************
606
	 *  - Adding password settings to table settings
607
	 */
608
	$aDebugMessage[] = "<span>Adding/updating password settings to settings table</span>";
609
	$cfg = array();
610
	$cfg['password_crypt_loops'] = (defined('PASSWORD_CRYPT_LOOPS') ? PASSWORD_CRYPT_LOOPS : '12');
611
	$cfg['password_hash_type'] = (defined('PASSWORD_HASH_TYPES') ? PASSWORD_HASH_TYPES : 'false');
612
	$cfg['password_length'] = (defined('PASSWORD_LENGTH') ? PASSWORD_LENGTH : '10');
613
	$cfg['password_use_types'] = (defined('PASSWORD_USE_TYPES') ? PASSWORD_USE_TYPES : (int)0xFFFF);
614
	$bLogStatus = (db_update_key_value( 'settings', $cfg ) ? true : false );
615
	$aDebugMessage[] = ( ($bLogStatus==true ) ? " $OK<br />" : " $FAIL!<br />");
616

    
617
if($bDebugModus) {
618
    echo implode(PHP_EOL,$aDebugMessage);
619
} else {
620
        echo '<strong>Successfully upgraded</strong>'." $OK<br />";	   
621
	}
622
echo '</div>';
623

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

    
643
	$aDebugMessage = array();
644
	echo "<h4>Adding/updating field on table pages</h4>";
645
	/**********************************************************
646
	 *  - Add field "page_trail" to table "pages"
647
	 */
648
	$table_name = TABLE_PREFIX.'pages';
649
	$field_name = 'page_trail';
650
	$description = "VARCHAR( 255 ) NOT NULL DEFAULT ''";
651
	add_modify_field_in_database($table_name,$field_name,$description);
652

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

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

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

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

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

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

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

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

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

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

    
733
	if($bDebugModus) {
734
		echo implode(PHP_EOL,$aDebugMessage);
735
	} else {
736
        echo '<strong>Successfully upgraded</strong>'." $OK<br />";	   
737
	}
738

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

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

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

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

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

    
816
	if($bDebugModus) {
817
	    echo implode(PHP_EOL,$aDebugMessage);
818
	} else {
819
        echo '<strong>Successfully upgraded</strong>'." $OK<br />";	   
820
	}
821
	echo '</div>';
822

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

    
860
	if($bDebugModus) {
861
	// $aDebugMessage[] =
862
	    echo implode(PHP_EOL,$aDebugMessage);
863
	}else {
864
	    echo '<span><strong>'.$iTotalUsers.' users updating the groups</strong></span>'." $OK<br />";
865
	    echo '</div>';
866
	}
867
}
868

    
869
$aDebugMessage = array();
870
echo '<h3>Step '.(++$stepID).': Updating access files in folders</h3>';
871

    
872
echo '<div style="margin-left:2em;">';
873
	/**********************************************************
874
	* upgrade media directory index protect files
875
	*/
876
//	echo '<h4>Upgrade media directory '.MEDIA_DIRECTORY.'/ index.php protect files</h4>';
877
//	$aDebugMessage = rebuildFolderProtectFile();
878
//	if( sizeof( $aDebugMessage ) ){
879
//		echo '<span><strong>Upgrade '.sizeof( $aDebugMessage ).' directory '.MEDIA_DIRECTORY.'/ protect files</strong></span>'." $OK<br />";
880
//	} else {
881
//		echo '<span><strong>Upgrade directory '.MEDIA_DIRECTORY.'/ protect files</strong></span>'." $FAIL!<br />";
882
//		echo implode ('<br />',$aDebugMessage);
883
//	}
884
//
885
//    $aDebugMessage = array();
886
    /**********************************************************
887
     * upgrade pages directory index access files
888
     */
889
	echo '<h4>Upgrade pages directory '.PAGES_DIRECTORY.'/  access files</h4>';
890

    
891
	/**********************************************************
892
	 * Repair inconsistent PageTree
893
	 */
894
	$iCount = UpgradeHelper::sanitizePagesTreeLinkStructure();
895
	if (false === $iCount) {
896
		echo '<span><strong>Repair PageTree links </strong></span> '.$FAIL.'<br />';
897
	} else {
898
		echo '<span><strong>'.$iCount.' PageTree links repaired.</strong></span> '.$OK.'<br />';
899
	}
900
    /**********************************************************
901
     *  - Reformat/rebuild all existing access files
902
     */
903
    $msg = rebuild_all_accessfiles($bDebugModus);
904
	echo '<strong>'.implode ('<br />',$msg).'</strong>';
905
    echo '</div>';
906

    
907
	/* *****************************************************************************
908
	 * - check for deprecated / never needed files
909
	 */
910
	$iLoaded = sizeof($aFilesToRemove);
911
	if($iLoaded) {
912
		echo '<h3>Step '.(++$stepID).': Remove deprecated and outdated files</h3>';
913
		$iFailed = 0;
914
		$iFound = 0;
915
		$searches = array(
916
			'[ADMIN]',
917
			'[MEDIA]',
918
			'[PAGES]',
919
			'[FRAMEWORK]',
920
			'[MODULES]',
921
			'[TEMPLATE]'
922
		);
923
		$replacements = array(
924
            $oReg->AcpDir,
925
            $oReg->MediaDir,
926
            $oReg->PagesDir,
927
			'framework/',
928
			'modules/',
929
			'templates/'
930
		);
931

    
932
		$msg = '';
933
		echo '<div style="margin-left:2em;">';
934
		echo '<h4>Search '.$iLoaded.' deprecated and outdated files</h4>';
935
		foreach( $aFilesToRemove as $file )
936
		{
937
			$file = str_replace($searches, $replacements, $file);
938
			if( is_writable($oReg->AppDir.$file) ) {
939
				$iFound++;
940
				// try to unlink file
941
				if(!unlink($oReg->AppDir.$file)) {
942
					$iFailed++;
943
				}
944
			}
945
			if( is_readable($oReg->AppDir.$file) ) {
946
				// save in err-list, if failed
947
				$msg .= $file.'<br />';
948
			}
949
		}
950
		$iRemove = $iFound-$iFailed;
951
		echo '<strong>Remove '.$iRemove.' from '.$iFound.' founded</strong> ';
952
		echo ($iFailed == 0) ? $OK : $FAIL;
953
		echo '</div>';
954

    
955
		if($msg != '')
956
		{
957
			$msg = '<br /><br />Following files are deprecated, outdated or a security risk and
958
				    can not be removed automatically.<br /><br />Please delete them
959
					using FTP and restart upgrade-script!<br /><br />'.$msg.'<br />';
960
			status_msg($msg, 'error warning', 'div');
961
			echo '<p style="font-size:120%;"><strong>WARNING: The upgrade script failed ...</strong></p>';
962

    
963
			echo '<form action="'.$_SERVER['SCRIPT_NAME'].'">';
964
			echo '&nbsp;<input name="send" type="submit" value="Restart upgrade script" />';
965
			echo '</form>';
966
			echo "<br /><br /></div>
967
			</div>
968
			</div>
969
			</body>
970
			</html>";
971
			exit;
972
		}
973
	}
974

    
975

    
976
	/**********************************************************
977
	 * - check for deprecated / never needed folders
978
	 */
979
	$iLoaded = sizeof($dirRemove);
980
	if($iLoaded) {
981
		echo '<h3>Step  '.(++$stepID).': Remove deprecated and outdated folders</h3>';
982
		$iFailed = 0;
983
		$iFound = 0;
984
		$searches = array(
985
			'[ADMIN]',
986
			'[MEDIA]',
987
			'[PAGES]',
988
			'[FRAMEWORK]',
989
			'[MODULES]',
990
			'[TEMPLATE]'
991
		);
992
		$replacements = array(
993
            $oReg->AcpDir,
994
            $oReg->MediaDir,
995
            $oReg->PagesDir,
996
			'framework/',
997
			'modules/',
998
			'templates/'
999
		);
1000
		$msg = '';
1001
		echo '<div style="margin-left:2em;">';
1002
		echo '<h4>Search '.$iLoaded.' deprecated and outdated folders</h4>';
1003
		foreach( $dirRemove as $sRootDir ) {
1004
			$sRootDir = str_replace($searches, $replacements, $sRootDir);
1005
            if (file_exists($oReg->AppPath.$sRootDir)) {
1006
                if (!UpgradeHelper::delTree($oReg->AppPath.$sRootDir, UpgradeHelper::DEL_ROOT_DELETE)) {
1007
                    $iFailed = sizeof(($msg = UpgradeHelper::getDelTreeLog()));
1008
                    $msg = implode('<br />', $msg);
1009
                }
1010
            }
1011
        }
1012
		echo ($iFailed == 0) ? $OK : $FAIL;
1013
		echo '</div>';
1014
		if($msg != '') {
1015
			$msg = '<br /><br />Following directories are deprecated, outdated or a security risk and
1016
					can not be removed automatically.<br /><br />Please delete them
1017
					using FTP and restart upgrade-script!<br /><br />'.$msg.'<br />';
1018
			status_msg($msg, 'error warning', 'div');
1019
			echo '<p style="font-size:120%;"><strong>WARNING: The upgrade script failed ...</strong></p>';
1020
			echo '<form action="'.$_SERVER['SCRIPT_NAME'].'">';
1021
			echo '&nbsp;<input name="send" type="submit" value="Restart upgrade script" />';
1022
			echo '</form>';
1023
			echo "<br /><br /></div>
1024
			</div>
1025
			</div>
1026
			</body>
1027
			</html>";
1028
			exit;
1029
		}
1030
	}
1031

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

    
1056
	/**********************************************************
1057
	 * Reformat/rebuild all existing moules access files
1058
	 * $aModuleList list of modules
1059
	 */
1060
	$aModuleList = array('bakery','topics','news');
1061
	if(sizeof($aModuleList)) 
1062
	{
1063
		echo '<h3>Step '.(++$stepID).': Create/Reorg Accessfiles from modules</h3>';
1064
		foreach($aModuleList as $sModul) {
1065
			$aReturnMsg = array();
1066
			$sModulReorg = 'm_'.$sModul.'_Reorg';
1067
			if(class_exists($sModulReorg)) {
1068
				$sModulVersion =  get_modul_version ($sModul, true);
1069
				echo '<div style="margin-left:2em;">';
1070
				echo '<h4>'.'Create/Reorg Accessfiles for module \''.$sModul.'\' version '.$sModulVersion.'</h4>';
1071
				$oReorg = new $sModulReorg(ModuleReorgAbstract::LOG_EXTENDED);
1072
				$aReturnMsg = $oReorg->execute(); // show details
1073
                $aReport = $oReorg->getReport();
1074
                unset($oReorg);
1075
                if($bDebugModus) {
1076
                    foreach($aReport['Failed'] as $sValue) {
1077
                        echo $sValue.'<br />';
1078
                    }
1079
                    foreach($aReport['Success'] as $sValue) {
1080
                        echo $sValue.'<br />';
1081
                    }
1082
    			}
1083
//				echo '<strong>'.$aReport['FilesDeleted'].' Files successful deleted</strong><br />';
1084
				echo '<strong>Number of new formated access files: '.$aReport['FilesCreated'].'</strong><br />';
1085

    
1086
				echo '</div>';
1087
			}
1088
		}
1089
	}
1090
/**********************************************************
1091
 *  - Reload all addons
1092
 */
1093

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

    
1113
	$iFound = 0;
1114
	$iLoaded = 0;
1115
	////delete templates
1116
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'template'");
1117
	// Load all templates
1118
	if( ($handle = opendir(WB_PATH.'/templates/')) ) {
1119
		while(false !== ($file = readdir($handle))) {
1120
			if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
1121

    
1122
				$iFound++;
1123
				$iLoaded = (load_template(WB_PATH.'/templates/'.$file)==true) ? $iLoaded+1 : $iLoaded;
1124

    
1125
			}
1126
		}
1127
		closedir($handle);
1128
	}
1129
	echo '<strong><span>'.$iLoaded.' Templates reloaded,</span> found '.$iFound.' directories in folder /templates/</strong><br />';
1130
	$iFound = 0;
1131
	$iLoaded = 0;
1132
	////delete languages
1133
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'language'");
1134
	// Load all languages
1135
	if( ($handle = opendir(WB_PATH.'/languages/')) ) {
1136
		while(false !== ($file = readdir($handle))) {
1137
			if($file != '' AND (preg_match('#^([A-Z]{2}.php)#', basename($file)))) {
1138
				$iFound++;
1139
				$iLoaded = load_language(WB_PATH.'/languages/'.$file) ? $iLoaded+1 : $iLoaded;
1140
			}
1141
		}
1142
		closedir($handle);
1143
	}
1144
	echo '<strong><span>'.$iLoaded.' Languages reloaded,</span> found '.$iFound.' files in folder /languages/</strong><br />';
1145
	$sTransCachePath = WB_PATH.'/temp/TranslationTable/cache/';
1146
	if (is_writeable($sTransCachePath)) {
1147
		if (rm_full_dir($sTransCachePath, true)) {
1148
			echo '<strong><span>Translation Cache cleaned</span></strong> '.$OK.'<br />';
1149
		} else {
1150
			echo '<strong><span>Clean Translation Cache</span></strong> '.$FAIL.'<br />';
1151
		}
1152
	}
1153
	echo '</div>';
1154

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

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

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

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

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

    
1199
echo "<br /><br /></div>
1200
</div>
1201
</div>
1202
</body>
1203
</html>
1204
";
1205
exit();
(6-6/6)