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: 2075 $
31
 * @link         $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/upgrade-script.php $
32
 * @lastmodified $Date: 2014-01-06 23:55:03 +0100 (Mon, 06 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
UpgradeHelper::checkSetupFiles(dirname(__FILE__).'/');
83

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

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

    
110
$bDebugModus = false;
111

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

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

    
125
$stepID = 1;
126
$dirRemove = array(
127
/*
128
			'[TEMPLATE]/allcss/',
129
			'[TEMPLATE]/blank/',
130
			'[TEMPLATE]/round/',
131
			'[TEMPLATE]/simple/',
132
*/
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
);
153

    
154
// deleting files below only from less 2.8.4 stable
155
if(version_compare(WB_VERSION, '2.8.4', '<'))
156
{
157
	$aRemoveOldTemplates = array(
158

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

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

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

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

    
271
body {
272
	margin:0;
273
	padding:0;
274
	border:0;
275
	background: #EBF7FC;
276
	color:#000;
277
	font-family: 'Trebuchet MS', Verdana, Arial, Helvetica, Sans-Serif;
278
	font-size: small;
279
	height:101%;
280
}
281

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

    
302
form {
303
	display: inline-block;
304
	line-height: 20px;
305
	vertical-align: baseline;
306
}
307
input[type="submit"].restart {
308
	background-color: #FFDBDB;
309
	font-weight: bold;
310
}
311

    
312
h1,h2,h3,h4,h5,h6 {
313
	font-family: Verdana, Arial, Helvetica, sans-serif;
314
	color: #26527D;
315
	margin-top: 1.0em;
316
	margin-bottom: 0.1em;
317
}
318

    
319
h1 { font-size:150%; }
320
h2 { font-size: 130%; border-bottom: 1px #CCC solid; }
321
h3 { font-size: 110%; font-weight: bold; }
322

    
323
textarea {
324
	width:100%;
325
	border: 2px groove #0F1D44;
326
	padding: 2px;
327
	color: #000;
328
	font-weight: normal;
329
}
330
.ok, .error { font-weight:bold; }
331
.ok { color:green; }
332
.error { color:red; }
333
.check { color:#555; }
334

    
335
span.ok,
336
span.error {
337
    margin-left: 0em;
338
}
339

    
340
.warning {
341
	background:#FFDBDB;
342
	padding:1em;
343
	margin-top:0.5em;
344
	border: 1px solid #DB0909;
345
}
346
.info {
347
	background:#C7F4C7;
348
	padding:1em;
349
	margin-top:0.5em;
350
	border: 1px solid #277A29;
351
}
352

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

    
419
?>
420
<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>
421

    
422
<?php
423

    
424
/**
425
 * Check if disclaimer was accepted
426
 */
427
$bDebugModus = false;
428
$bDebugModus = ( (isset($_POST['debug_confirmed']) && $_POST['debug_confirmed'] == 'debug') ? true : false);
429
if (!(isset($_POST['backup_confirmed']) && $_POST['backup_confirmed'] == 'confirmed')) { ?>
430
<h2>Step 1: Backup your files</h2>
431
<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>
432
<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>
433

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

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

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

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

    
506
	echo implode(PHP_EOL,$aDebugMessage);
507

    
508
	$aDebugMessage = array();
509
	echo'<h3>Step '.(++$stepID).': Updating core table included in package</h3>';
510
	/**********************************************************
511
	 *  - Adding field sec_anchor to settings table
512
	 */
513
	echo '<div style="margin-left:2em;">';
514
	echo "<h4>Adding/updating entries on table settings</h4>";
515
	$aDebugMessage[] = "<span>Adding/updating sec_anchor to settings table</span>";
516
	$cfg = array(
517
		'sec_anchor' => defined( 'SEC_ANCHOR' )&& (SEC_ANCHOR!='') ? SEC_ANCHOR : 'Sec'
518
	);
519
	$bLogStatus = (db_update_key_value( 'settings', $cfg ) ? true : false );
520
	$aDebugMessage[] = ( ($bLogStatus==true ) ? " $OK<br />" : " $FAIL!<br />");
521

    
522
	/**********************************************************
523
	 *  - Adding redirect timer to settings table
524
	 */
525
	$aDebugMessage[] = "<span>Adding/updating redirect timer to settings table</span>";
526
	$cfg = array(
527
		'redirect_timer' => defined('REDIRECT_TIMER')&& (REDIRECT_TIMER!='') ? REDIRECT_TIMER : '1500'
528
	);
529
	$bLogStatus = (db_update_key_value( 'settings', $cfg ) ? true : false );
530
	$aDebugMessage[] = ( ($bLogStatus==true ) ? " $OK<br />" : " $FAIL!<br />");
531

    
532
	/**********************************************************
533
	 *  - Adding default_time_formatr to settings table
534
	 */
535
	$aDebugMessage[] = "<span>Adding/updating default_time_format to settings table</span>";
536
	$cfg = array(
537
		'default_time_format' => defined('DEFAULT_TIME_FORMAT')&& (DEFAULT_TIME_FORMAT!='') ? DEFAULT_TIME_FORMAT : 'h:i A'
538
	);
539
	$bLogStatus = (db_update_key_value( 'settings', $cfg ) ? true : false );
540
	$aDebugMessage[] = ( ($bLogStatus==true ) ? " $OK<br />" : " $FAIL!<br />");
541

    
542
	/**********************************************************
543
	 *  - Adding rename_files_on_upload to settings table
544
	 */
545
	$aDebugMessage[] = "<span>Adding/Updating rename_files_on_upload to settings table</span>";
546
	$cfg = array(
547
	    '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')
548
	);
549
	if( version_compare( WB_VERSION, '2.8.2', '<' )) {
550
		$cfg = array(
551
		    'rename_files_on_upload' => 'ph.*?,cgi,pl,pm,exe,com,bat,pif,cmd,src,asp,aspx,js'
552
		);
553
	}
554
	$bLogStatus = (db_update_key_value( 'settings', $cfg ) ? true : false );
555
	$aDebugMessage[] = ( ($bLogStatus==true ) ? " $OK<br />" : " $FAIL!<br />");
556

    
557
	/**********************************************************
558
	 *  - Adding mediasettings to settings table
559
	 */
560
	$aDebugMessage[] = "<span>Adding/updating mediasettings to settings table</span>";
561
	$cfg = array(
562
		'mediasettings' => (defined('MEDIASETTINGS')&& (MEDIASETTINGS!='') ? MEDIASETTINGS : ''),
563
	);
564
	$bLogStatus = (db_update_key_value( 'settings', $cfg ) ? true : false );
565
	$aDebugMessage[] = ( ($bLogStatus==true ) ? " $OK<br />" : " $FAIL!<br />");
566

    
567
	/**********************************************************
568
	 *  - Adding fingerprint_with_ip_octets to settings table
569
	 */
570
	$aDebugMessage[] = "<span>Adding/updating fingerprint_with_ip_octets to settings table</span>";
571
	$cfg = array(
572
		'fingerprint_with_ip_octets' => (defined('FINGERPRINT_WITH_IP_OCTETS') ? FINGERPRINT_WITH_IP_OCTETS : '2'),
573
		'secure_form_module' => (defined('SECURE_FORM_MODULE') ? SECURE_FORM_MODULE : '')
574
	);
575
	$bLogStatus = (db_update_key_value( 'settings', $cfg ) ? true : false );
576
	$aDebugMessage[] = ( ($bLogStatus==true ) ? " $OK<br />" : " $FAIL!<br />");
577

    
578
	/**********************************************************
579
	 *  - Adding page_icon_dir to settings table
580
	 */
581
	$aDebugMessage[] = "<span>Adding/updating page_icon_dir to settings table</span>";
582
	$cfg = array(
583
		'page_icon_dir' => (defined('PAGE_ICON_DIR')&& (PAGE_ICON_DIR!='') ? PAGE_ICON_DIR : '/templates/*/title_images'),
584
	);
585
	$bLogStatus = (db_update_key_value( 'settings', $cfg ) ? true : false );
586
	$aDebugMessage[] = ( ($bLogStatus==true ) ? " $OK<br />" : " $FAIL!<br />");
587
	/**********************************************************
588
	 *  - Adding page_extended to settings table
589
	 */
590
	$aDebugMessage[] = "<span>Adding/updating page_extendet to settings table</span>";
591
	$cfg = array(
592
		'page_extendet' => (defined('PAGE_EXTENDET') ? PAGE_EXTENDET : 'true'),
593
	);
594
	$bLogStatus = (db_update_key_value( 'settings', $cfg ) ? true : false );
595
	$aDebugMessage[] = ( ($bLogStatus==true ) ? " $OK<br />" : " $FAIL!<br />");
596

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

    
607
	/**********************************************************
608
	 *  - Adding confirmed_registration to settings table
609
	 */
610
	$aDebugMessage[] = "<span>Adding/updating confirmed_registration to settings table</span>";
611
	$cfg = array(
612
		'confirmed_registration' => (defined('CONFIRMED_REGISTRATION') ? CONFIRMED_REGISTRATION : '0')
613
	);
614
	$bLogStatus = (db_update_key_value( 'settings', $cfg ) ? true : false );
615
	$aDebugMessage[] = ( ($bLogStatus==true ) ? " $OK<br />" : " $FAIL!<br />");
616

    
617
	/**********************************************************
618
	 *  - Adding dev_infos to settings table
619
	 */
620
	$aDebugMessage[] = "<span>Adding/updating dev_infos to settings table</span>";
621
	$cfg = array(
622
		'dev_infos' => (defined('DEV_INFOS') ? DEV_INFOS : 'false')
623
	);
624
	$bLogStatus = (db_update_key_value( 'settings', $cfg ) ? true : false );
625
	$aDebugMessage[] = ( ($bLogStatus==true ) ? " $OK<br />" : " $FAIL!<br />");
626

    
627
	/**********************************************************
628
	 *  - Adding server_timezone to settings table
629
	 */
630
	$aDebugMessage[] = "<span>Adding/updating server_timezone to settings table</span>";
631
	$cfg = array(
632
		'server_timezone' => (defined('SERVER_TIMEZONE') ? SERVER_TIMEZONE : 'UTC')
633
	);
634
	$bLogStatus = (db_update_key_value( 'settings', $cfg ) ? true : false );
635
	$aDebugMessage[] = ( ($bLogStatus==true ) ? " $OK<br />" : " $FAIL!<br />");
636

    
637
	/**********************************************************
638
	 *  - Adding password settings to table settings
639
	 */
640
	$aDebugMessage[] = "<span>Adding/updating password settings to settings table</span>";
641
	$cfg = array();
642
	$cfg['password_crypt_loops'] = (defined('PASSWORD_CRYPT_LOOPS') ? PASSWORD_CRYPT_LOOPS : '12');
643
	$cfg['password_hash_type'] = (defined('PASSWORD_HASH_TYPES') ? PASSWORD_HASH_TYPES : 'false');
644
	$cfg['password_length'] = (defined('PASSWORD_LENGTH') ? PASSWORD_LENGTH : '10');
645
	$cfg['password_use_types'] = (defined('PASSWORD_USE_TYPES') ? PASSWORD_USE_TYPES : (int)0xFFFF);
646
	$bLogStatus = (db_update_key_value( 'settings', $cfg ) ? true : false );
647
	$aDebugMessage[] = ( ($bLogStatus==true ) ? " $OK<br />" : " $FAIL!<br />");
648

    
649
if($bDebugModus) {
650
    echo implode(PHP_EOL,$aDebugMessage);
651
} else {
652
        echo '<strong>Successfully upgraded</strong>'." $OK<br />";	   
653
	}
654
echo '</div>';
655

    
656
$aDebugMessage = array();
657
if(version_compare(WB_REVISION, REVISION, '<='))
658
{
659
	echo '<div style="margin-left:2em;">';
660
	/**********************************************************
661
	 *  - Update search no results database filed to create
662
	 *  valid XHTML if search is empty
663
	 */
664
	if (version_compare(WB_VERSION, '2.8', '<'))
665
	{
666
		echo "<h4>Adding/updating fields on table search</h4>";
667
		echo "Updating database field `no_results` on search table: ";
668
		$search_no_results = addslashes('<tr><td><p>[TEXT_NO_RESULTS]</p></td></tr>');
669
		$sql  = 'UPDATE `'.TABLE_PREFIX.'search` ';
670
		$sql .= 'SET `value`=\''.$search_no_results.'\' ';
671
		$sql .= 'WHERE `name`=\'no_results\'';
672
		echo ($database->query($sql)) ? " $OK<br />" : " $FAIL!<br />";
673
	}
674

    
675
	$aDebugMessage = array();
676
	echo "<h4>Adding/updating field on table pages</h4>";
677
	/**********************************************************
678
	 *  - Add field "page_trail" to table "pages"
679
	 */
680
	$table_name = TABLE_PREFIX.'pages';
681
	$field_name = 'page_trail';
682
	$description = "VARCHAR( 255 ) NOT NULL DEFAULT ''";
683
	add_modify_field_in_database($table_name,$field_name,$description);
684

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

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

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

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

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

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

    
733
	/**********************************************************
734
	 *  - Add field "viewing_groups" to table "pages"
735
	 */
736
	$table_name = TABLE_PREFIX.'pages';
737
	$field_name = 'viewing_groups';
738
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '1'";
739
	 add_modify_field_in_database($table_name,$field_name,$description);
740

    
741
	/**********************************************************
742
	 *  - Add field "viewing_users" to table "pages"
743
	 */
744
	$table_name = TABLE_PREFIX.'pages';
745
	$field_name = 'viewing_users';
746
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT ''";
747
	add_modify_field_in_database($table_name,$field_name,$description);
748

    
749
	/**********************************************************
750
	 *  - Add field "custom01" to table "pages"
751
	 */
752
	$table_name = TABLE_PREFIX.'pages';
753
	$field_name = 'custom01';
754
	$description = "VARCHAR( 255 ) NOT NULL DEFAULT '' ";
755
	add_modify_field_in_database($table_name,$field_name,$description);
756

    
757
	/**********************************************************
758
	 *  - Add field "custom02" to table "pages"
759
	 */
760
	$table_name = TABLE_PREFIX.'pages';
761
	$field_name = 'custom02';
762
	$description = "VARCHAR( 255 ) NOT NULL DEFAULT '' ";
763
	add_modify_field_in_database($table_name,$field_name,$description);
764

    
765
	if($bDebugModus) {
766
		echo implode(PHP_EOL,$aDebugMessage);
767
	} else {
768
        echo '<strong>Successfully upgraded</strong>'." $OK<br />";	   
769
	}
770

    
771
	$aDebugMessage = array();
772
	/**********************************************************
773
	 * modify wrong strucre on table sections
774
	 * wrong structure let crash wb
775
	 */
776
	echo "<h4>Change field structure on table sections</h4>";
777
	$table_name = TABLE_PREFIX.'sections';
778
	$description = "VARCHAR( 255 ) NOT NULL DEFAULT ''";
779
	$aDebugMessage[] = "<span>Modify field module on sections table</span>";
780
	$aDebugMessage[] = ($database->field_modify($table_name, 'module', $description) ? " $OK<br />" : " $FAIL!<br />");
781
	$aDebugMessage[] = "<span>Modify field block on sections table</span>";
782
	$description = "int(11) NOT NULL DEFAULT '1'";
783
	$aDebugMessage[] = ($database->field_modify($table_name, 'block', $description) ? " $OK<br />" : " $FAIL!<br />");
784
	$description = "int(11) NOT NULL DEFAULT '0'";
785
	$aDebugMessage[] = "<span>Modify field publ_start on sections table</span>";
786
	$aDebugMessage[] = ($database->field_modify($table_name, 'publ_start', $description) ? " $OK<br />" : " $FAIL!<br />");
787
	$aDebugMessage[] = "<span>Modify field publ_end on sections table</span>";
788
	$aDebugMessage[] = ($database->field_modify($table_name, 'publ_end', $description) ? " $OK<br />" : " $FAIL!<br />");
789

    
790
	if($bDebugModus) {
791
		echo implode(PHP_EOL,$aDebugMessage);
792
	} else {
793
        echo '<strong>Successfully upgraded</strong>'." $OK<br />";	   
794
	}
795
	echo '</div>';
796
}
797

    
798
if(version_compare(WB_REVISION, REVISION, '<='))
799
{
800
	$aDebugMessage = array();
801
	echo '<h3>Step '.(++$stepID).': Updating structure in table users/groups</h3>';
802
	/**********************************************************
803
	 * Modify Administrator on groups table
804
	 */
805
	echo '<div style="margin-left:2em;">';
806
	echo "<h4>Updating Administrator group permissions on table groups</h4>";
807
	$aDebugMessage[] = "<span>Modify Administrator on groups table</span>";
808
	$sModulePermissions = '';
809
	$sTemplatePermissions = '';
810
	$sSystemPermissions  = 'access,addons,admintools,admintools_view,groups,groups_add,groups_delete,groups_modify,groups_view,';
811
	$sSystemPermissions .= 'languages,languages_install,languages_uninstall,languages_view,media,media_create,media_delete,media_rename,media_upload,media_view,';
812
	$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,';
813
	$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';
814

    
815
	$sql  = 'UPDATE `'.TABLE_PREFIX.'groups` ';
816
	$sql .= 'SET `name` = \'Administrators\', ';
817
	$sql .= '`system_permissions` = \''.$sSystemPermissions.'\', ';
818
	$sql .= '`module_permissions` = \''.$sModulePermissions.'\', ';
819
	$sql .= '`template_permissions` = \''.$sTemplatePermissions.'\' ';
820
	$sql .= 'WHERE `group_id` = \'1\' ';
821
	$aDebugMessage[] = ($database->query($sql)) ? " $OK<br />" : " $FAIL!<br />";
822
	if( ($admin->is_authenticated() == true) && ($admin->ami_group_member('1') ) ) {
823
	    $_SESSION['SYSTEM_PERMISSIONS'] = array_merge($_SESSION['SYSTEM_PERMISSIONS'], explode(',', $sSystemPermissions));
824
	}
825

    
826
	if($bDebugModus) {
827
		echo implode(PHP_EOL,$aDebugMessage);
828
	} else {
829
        echo '<strong>Successfully upgraded</strong>'." $OK<br />";	   
830
	}
831
	echo '</div>';
832
	$aDebugMessage = array();
833
	/**********************************************************
834
	 *   `confirm_code` VARCHAR(32) NOT NULL DEFAULT '',
835
	 *   `confirm_timeout` INT(11) NOT NULL DEFAULT '0',
836
	 */
837
	echo '<div style="margin-left:2em;">';
838
	echo "<h4>Change field structure on table users</h4>";
839
	$table_name = TABLE_PREFIX.'users';
840
	$field_name = 'confirm_code';
841
	$description = "VARCHAR( 32 ) NOT NULL DEFAULT '' AFTER `password` ";
842
	add_modify_field_in_database($table_name,$field_name,$description);
843

    
844
	$table_name = TABLE_PREFIX.'users';
845
	$field_name = 'confirm_timeout';
846
	$description = "INT(11) NOT NULL DEFAULT '0' AFTER `confirm_code` ";
847
	add_modify_field_in_database($table_name,$field_name,$description);
848

    
849
	if($bDebugModus) {
850
	    echo implode(PHP_EOL,$aDebugMessage);
851
	} else {
852
        echo '<strong>Successfully upgraded</strong>'." $OK<br />";	   
853
	}
854
	echo '</div>';
855

    
856
	$aDebugMessage = array();
857
	/**********************************************************
858
	* Updating group_id in table users
859
	*/
860
	echo '<div style="margin-left:2em;">';
861
	echo "<h4>Updating users groups permissions on table groups</h4>";
862
	    $aUsers = array();
863
		// Get existing values
864
        $sql  = 'SELECT * FROM `'.TABLE_PREFIX.'users` ' ;
865
        $sql .= 'WHERE `user_id` != 1 ';
866
        if($oUser = $database->query($sql)){
867
            $iTotalUsers = $oUser->numRows();
868
            while($Users = $oUser->fetchRow(MYSQL_ASSOC)) {
869
                $aUsers[$Users['user_id']]['groups_id'] = $Users['groups_id'];
870
                $aUsers[$Users['user_id']]['display_name'] = $Users['display_name'];
871
            }
872
        } else {
873
            $aDebugMessage[] = $database->is_error()==false ? " $OK<br />" : " $FAIL!<br />";
874
        }
875
        foreach($aUsers AS $user_id => $value){
876
                // choose group_id from groups_id - workaround for still remaining calls to group_id (to be cleaned-up)
877
                $aGroups_id = explode(',', $aUsers[$user_id]['groups_id']);
878
                $groups_id = $aUsers[$user_id]['groups_id'];
879
                $group_id = 0;
880
                //if user is in administrator-group, get this group else just get the first one
881
                if($admin->is_group_match($aGroups_id,'1')) { $group_id = 1; $groups_id = '1'; } else { $group_id = intval($aGroups_id[0]); }
882
                $sMessage = "<span>Updating group_id ".$TEXT['DISPLAY_NAME']." " .$aUsers[$user_id]['display_name']."</span>";
883
                $sql  = 'UPDATE `'.TABLE_PREFIX.'users` ';
884
                $sql .= 'SET `group_id`  = '.$group_id.', ';
885
                $sql .=     '`groups_id` = \''.$groups_id.'\' ';
886
                $sql .= 'WHERE `user_id` = '.intval($user_id);
887
                if($oRes = $database->query($sql)){  }
888
                $aDebugMessage[] = $database->is_error()==false ? $sMessage." $OK<br />" : $sMessage." $FAIL!<br />";
889
        }
890
        unset($aUsers);
891
	$aDebugMessage[] = '</div>';
892

    
893
	if($bDebugModus) {
894
	// $aDebugMessage[] =
895
	    echo implode(PHP_EOL,$aDebugMessage);
896
	}else {
897
	    echo '<span><strong>'.$iTotalUsers.' users updating the groups</strong></span>'." $OK<br />";
898
	    echo '</div>';
899
	}
900
}
901

    
902
$aDebugMessage = array();
903
echo '<h3>Step '.(++$stepID).': Updating access files in folders</h3>';
904

    
905
echo '<div style="margin-left:2em;">';
906
	/**********************************************************
907
	* upgrade media directory index protect files
908
	*/
909
//	echo '<h4>Upgrade media directory '.MEDIA_DIRECTORY.'/ index.php protect files</h4>';
910
//	$aDebugMessage = rebuildFolderProtectFile();
911
//	if( sizeof( $aDebugMessage ) ){
912
//		echo '<span><strong>Upgrade '.sizeof( $aDebugMessage ).' directory '.MEDIA_DIRECTORY.'/ protect files</strong></span>'." $OK<br />";
913
//	} else {
914
//		echo '<span><strong>Upgrade directory '.MEDIA_DIRECTORY.'/ protect files</strong></span>'." $FAIL!<br />";
915
//		echo implode ('<br />',$aDebugMessage);
916
//	}
917
//
918
//    $aDebugMessage = array();
919
    /**********************************************************
920
     * upgrade pages directory index access files
921
     */
922
	echo '<h4>Upgrade pages directory '.PAGES_DIRECTORY.'/  access files</h4>';
923

    
924
	/**********************************************************
925
	 * Repair inconsistent PageTree
926
	 */
927
	$iCount = UpgradeHelper::sanitizePagesTreeLinkStructure();
928
	if (false === $iCount) {
929
		echo '<span><strong>Repair PageTree links </strong></span> '.$FAIL.'<br />';
930
	} else {
931
		echo '<span><strong>'.$iCount.' PageTree links repaired.</strong></span> '.$OK.'<br />';
932
	}
933
    /**********************************************************
934
     *  - Reformat/rebuild all existing access files
935
     */
936
    $msg = rebuild_all_accessfiles($bDebugModus);
937
	echo '<strong>'.implode ('<br />',$msg).'</strong>';
938
    echo '</div>';
939

    
940
	/* *****************************************************************************
941
	 * - check for deprecated / never needed files
942
	 */
943
	$iLoaded = sizeof($aFilesToRemove);
944
	if($iLoaded) {
945
		echo '<h3>Step '.(++$stepID).': Remove deprecated and outdated files</h3>';
946
		$iFailed = 0;
947
		$iFound = 0;
948
		$searches = array(
949
			'[ADMIN]',
950
			'[MEDIA]',
951
			'[PAGES]',
952
			'[FRAMEWORK]',
953
			'[MODULES]',
954
			'[TEMPLATE]'
955
		);
956
		$replacements = array(
957
			'/'.substr(ADMIN_PATH, strlen(WB_PATH)+1),
958
			MEDIA_DIRECTORY,
959
			PAGES_DIRECTORY,
960
			'/framework',
961
			'/modules',
962
			'/templates'
963
		);
964

    
965
		$msg = '';
966
		echo '<div style="margin-left:2em;">';
967
		echo '<h4>Search '.$iLoaded.' deprecated and outdated files</h4>';
968
		foreach( $aFilesToRemove as $file )
969
		{
970
			$file = str_replace($searches, $replacements, $file);
971
			if( is_writable(WB_PATH.'/'.$file) ) {
972
				$iFound++;
973
				// try to unlink file
974
				if(!unlink(WB_PATH.$file)) {
975
					$iFailed++;
976
				}
977
			}
978
			if( is_readable(WB_PATH.'/'.$file) ) {
979
				// save in err-list, if failed
980
				$msg .= $file.'<br />';
981
			}
982
		}
983
		$iRemove = $iFound-$iFailed;
984
		echo '<strong>Remove '.$iRemove.' from '.$iFound.' founded</strong> ';
985
		echo ($iFailed == 0) ? $OK : $FAIL;
986
		echo '</div>';
987

    
988
		if($msg != '')
989
		{
990
			$msg = '<br /><br />Following files are deprecated, outdated or a security risk and
991
				    can not be removed automatically.<br /><br />Please delete them
992
					using FTP and restart upgrade-script!<br /><br />'.$msg.'<br />';
993
			status_msg($msg, 'error warning', 'div');
994
			echo '<p style="font-size:120%;"><strong>WARNING: The upgrade script failed ...</strong></p>';
995

    
996
			echo '<form action="'.$_SERVER['SCRIPT_NAME'].'">';
997
			echo '&nbsp;<input name="send" type="submit" value="Restart upgrade script" />';
998
			echo '</form>';
999
			echo "<br /><br /></div>
1000
			</div>
1001
			</div>
1002
			</body>
1003
			</html>";
1004
			exit;
1005
		}
1006
	}
1007

    
1008

    
1009
	/**********************************************************
1010
	 * - check for deprecated / never needed files
1011
	 */
1012
	$iLoaded = sizeof($dirRemove);
1013
	if($iLoaded) {
1014
		echo '<h3>Step  '.(++$stepID).': Remove deprecated and outdated folders</h3>';
1015
		$iFailed = 0;
1016
		$iFound = 0;
1017
		$searches = array(
1018
			'[ADMIN]',
1019
			'[MEDIA]',
1020
			'[PAGES]',
1021
			'[TEMPLATE]'
1022
		);
1023
		$replacements = array(
1024
			substr(ADMIN_PATH, strlen(WB_PATH)+1),
1025
			MEDIA_DIRECTORY,
1026
			PAGES_DIRECTORY,
1027
			'/templates',
1028
		);
1029
		$msg = '';
1030
		echo '<div style="margin-left:2em;">';
1031
		echo '<h4>Search '.$iLoaded.' deprecated and outdated folders</h4>';
1032
		foreach( $dirRemove as $dir ) {
1033
			$dir = str_replace($searches, $replacements, $dir);
1034
			$dir = WB_PATH.'/'.$dir;
1035
			if( is_dir( $dir )) {
1036
				$iFound++;
1037
			// try to delete dir
1038
				if(!is_writable( $dir ) || !rm_full_dir($dir)) {
1039
				// save in err-list, if failed
1040
					$iFailed++;
1041
				}
1042
			}
1043
			if( is_readable(WB_PATH.'/'.$dir) ) {
1044
				$msg .= str_replace(WB_PATH,'',$dir).'<br />';
1045
			}
1046
		}
1047
		
1048
		$iRemove = $iFound-$iFailed;
1049
		echo '<strong>Remove '.$iRemove.' from '.$iFound.' founded</strong> ';
1050
		echo ($iFailed == 0) ? $OK : $FAIL;
1051
		echo '</div>';
1052

    
1053
		if($msg != '') {
1054
			$msg = '<br /><br />Following directories are deprecated, outdated or a security risk and
1055
					can not be removed automatically.<br /><br />Please delete them
1056
					using FTP and restart upgrade-script!<br /><br />'.$msg.'<br />';
1057
			status_msg($msg, 'error warning', 'div');
1058
			echo '<p style="font-size:120%;"><strong>WARNING: The upgrade script failed ...</strong></p>';
1059
			echo '<form action="'.$_SERVER['SCRIPT_NAME'].'">';
1060
			echo '&nbsp;<input name="send" type="submit" value="Restart upgrade script" />';
1061
			echo '</form>';
1062
			echo "<br /><br /></div>
1063
			</div>
1064
			</div>
1065
			</body>
1066
			</html>";
1067
			exit;
1068
		}
1069

    
1070

    
1071
	}
1072

    
1073
	/**********************************************************
1074
	 * upgrade modules if newer version is available
1075
	 * $aModuleList list of proofed modules
1076
	 */
1077
	$aProofedModuleList = array(
1078
	              'captcha_control','code','droplets','form','jsadmin',
1079
	              'menu_link','news','output_filter','wrapper','wysiwyg','MultiLingual');
1080
	if(sizeof($aProofedModuleList)) 
1081
	{
1082
		echo '<h3>Step '.(++$stepID).': Upgrade proofed modules</h3>';
1083
		foreach($aProofedModuleList as $sModul) {
1084
			if(file_exists(WB_PATH.'/modules/'.$sModul.'/upgrade.php')) {
1085
				$currModulVersion = get_modul_version ($sModul, false);
1086
				$newModulVersion =  get_modul_version ($sModul, true);
1087
				if((version_compare($currModulVersion, $newModulVersion) <= 0)) {
1088
					echo '<div style="margin-left:2em;">';
1089
					echo '<h4>'.'Upgrade module \''.$sModul.'\' version '.$newModulVersion.'</h4>';
1090
					require(WB_PATH.'/modules/'.$sModul.'/upgrade.php');
1091
					echo '</div>';
1092
				}
1093
			}
1094
		}
1095
	}
1096

    
1097
	/**********************************************************
1098
	 * Reformat/rebuild all existing moules access files
1099
	 * $aModuleList list of modules
1100
	 */
1101
	$aModuleList = array('bakery','topics','news');
1102
	if(sizeof($aModuleList)) 
1103
	{
1104
		echo '<h3>Step '.(++$stepID).': Create/Reorg Accessfiles from modules</h3>';
1105
		foreach($aModuleList as $sModul) {
1106
			$aReturnMsg = array();
1107
			$sModulReorg = 'm_'.$sModul.'_Reorg';
1108
			if(class_exists($sModulReorg)) {
1109
				$sModulVersion =  get_modul_version ($sModul, true);
1110
				echo '<div style="margin-left:2em;">';
1111
				echo '<h4>'.'Create/Reorg Accessfiles for module \''.$sModul.'\' version '.$sModulVersion.'</h4>';
1112
				$oReorg = new $sModulReorg(ModuleReorgAbstract::LOG_EXTENDED);
1113
				$aReturnMsg = $oReorg->execute(); // show details
1114
                $aReport = $oReorg->getReport();
1115
                unset($oReorg);
1116
                if($bDebugModus) {
1117
                    foreach($aReport['Failed'] as $sValue) {
1118
                        echo $sValue.'<br />';
1119
                    }
1120
                    foreach($aReport['Success'] as $sValue) {
1121
                        echo $sValue.'<br />';
1122
                    }
1123
    			}
1124
//				echo '<strong>'.$aReport['FilesDeleted'].' Files successful deleted</strong><br />';
1125
				echo '<strong>Number of new formated access files: '.$aReport['FilesCreated'].'</strong><br />';
1126

    
1127
				echo '</div>';
1128
			}
1129
		}
1130
	}
1131
/**********************************************************
1132
 *  - Reload all addons
1133
 */
1134

    
1135
	echo '<h3>Step '.(++$stepID).' : Reload all addons database entry (no upgrade)</h3><br />';
1136
	echo '<div style="margin-left:2em;">';
1137
	$iFound = 0;
1138
	$iLoaded = 0;
1139
	////delete modules
1140
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'module'");
1141
	// Load all modules
1142
	if( ($handle = opendir(WB_PATH.'/modules/')) ) {
1143
		while(false !== ($file = readdir($handle))) {
1144
			if($file != '' && substr($file, 0, 1) != '.' && is_dir(WB_PATH.'/modules/'.$file) ) {
1145
				$iFound++;
1146
				$iLoaded = load_module(WB_PATH.'/modules/'.$file ) ? $iLoaded+1 : $iLoaded;
1147
// 	upgrade_module($file, true);
1148
			}
1149
		}
1150
		closedir($handle);
1151
	}
1152
	echo '<strong><span>'.$iLoaded.' Modules reloaded,</span> found '.$iFound.' directories in folder /modules/</strong><br />';
1153

    
1154
	$iFound = 0;
1155
	$iLoaded = 0;
1156
	////delete templates
1157
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'template'");
1158
	// Load all templates
1159
	if( ($handle = opendir(WB_PATH.'/templates/')) ) {
1160
		while(false !== ($file = readdir($handle))) {
1161
			if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
1162

    
1163
				$iFound++;
1164
				$iLoaded = (load_template(WB_PATH.'/templates/'.$file)==true) ? $iLoaded+1 : $iLoaded;
1165

    
1166
			}
1167
		}
1168
		closedir($handle);
1169
	}
1170
	echo '<strong><span>'.$iLoaded.' Templates reloaded,</span> found '.$iFound.' directories in folder /templates/</strong><br />';
1171
	$iFound = 0;
1172
	$iLoaded = 0;
1173
	////delete languages
1174
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'language'");
1175
	// Load all languages
1176
	if( ($handle = opendir(WB_PATH.'/languages/')) ) {
1177
		while(false !== ($file = readdir($handle))) {
1178
			if($file != '' AND (preg_match('#^([A-Z]{2}.php)#', basename($file)))) {
1179
				$iFound++;
1180
				$iLoaded = load_language(WB_PATH.'/languages/'.$file) ? $iLoaded+1 : $iLoaded;
1181
			}
1182
		}
1183
		closedir($handle);
1184
	}
1185
	echo '<strong><span>'.$iLoaded.' Languages reloaded,</span> found '.$iFound.' files in folder /languages/</strong><br />';
1186
	$sTransCachePath = WB_PATH.'/temp/TranslationTable/cache/';
1187
	if (is_writeable($sTransCachePath)) {
1188
		if (rm_full_dir($sTransCachePath, true)) {
1189
			echo '<strong><span>Translation Cache cleaned</span></strong> '.$OK.'<br />';
1190
		} else {
1191
			echo '<strong><span>Clean Translation Cache</span></strong> '.$FAIL.'<br />';
1192
		}
1193
	}
1194
	echo '</div>';
1195

    
1196
/**********************************************************
1197
 *  - install new droplets
1198
	$drops = (!in_array ( "mod_droplets", $all_tables)) ? "<br />Install droplets<br />" : "<br />Upgrade droplets<br />";
1199
	echo $drops;
1200
	$file_name = (!in_array ( "mod_droplets", $all_tables) ? "install.php" : "upgrade.php");
1201
	require_once (WB_PATH."/modules/droplets/".$file_name);
1202
********************************************************** */
1203

    
1204
/**********************************************************
1205
 *  - End of upgrade script
1206
 */
1207
	if(!defined('DEFAULT_THEME')) { define('DEFAULT_THEME', $DEFAULT_THEME); }
1208
	if(!defined('THEME_PATH')) { define('THEME_PATH', WB_PATH.'/templates/'.DEFAULT_THEME);}
1209
/**********************************************************
1210
 *  - Set Version to new Version
1211
 */
1212
echo '<h3>Step '.(++$stepID).': Update database version number </h3>';
1213
echo '<div style="margin-left:2em;">';
1214

    
1215
$cfg = array(
1216
	'wb_version' => VERSION,
1217
	'wb_revision' => REVISION,
1218
	'wb_sp' => SP
1219
);
1220
echo '<br /><span><strong>Set WebsiteBaker version number to '.VERSION.' '.SP.' '.' Revision ['.REVISION.'] : </strong></span>';
1221
echo (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
1222
echo '</div>';
1223

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

    
1229
if(defined('WB_URL')) {
1230
	echo '<form action="'.WB_URL.'/">';
1231
	echo '&nbsp;<input type="submit" value="kick me to the Frontend" />';
1232
	echo '</form>';
1233
}
1234
if(defined('ADMIN_URL')) {
1235
	echo '<form action="'.ADMIN_URL.'/">';
1236
	echo '&nbsp;<input type="submit" value="kick me to the Backend" />';
1237
	echo '</form>';
1238
}
1239

    
1240
echo "<br /><br /></div>
1241
</div>
1242
</div>
1243
</body>
1244
</html>
1245
";
1246
exit();
(6-6/6)