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: 2104 $
31
 * @link         $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/upgrade-script.php $
32
 * @lastmodified $Date: 2014-11-20 21:24:59 +0100 (Thu, 20 Nov 2014) $
33
 * @since        File available since 17.01.2013
34
 * @deprecated   
35
 * @description  xyz
36
 */
37
// PHP less then 5.3.2 is prohibited ---
38
if (version_compare(PHP_VERSION, '5.3.2', '<')) {
39
    $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 />'
40
          . 'Please change your PHP-Version to any kind from 5.3.2 and up!<br />'
41
          . 'If you have problems to solve that, ask your hosting provider for it.<br  />'
42
          . 'The very best solution is the use of PHP-5.4 and up</p>';
43
    die($sMsg);
44
}
45
// --- load UpgradeHelper ---
46
if (!class_exists('UpgradeHelper', false)) {
47
    require(__DIR__.'/framework/UpgradeHelper.php');
48
}
49
// --- delete fatal disturbing files before upgrade starts -------------------------------
50
$aPreDeleteFiles = array(
51
// list of files
52
	dirname(__FILE__).'/framework/PasswordHash.php'
53
);
54
$sMsg = '';
55
if (sizeof($aPreDeleteFiles > 0)) {
56
// if there are files defined
57
	foreach ($aPreDeleteFiles as $sFileToDelete) {
58
	// iterate the list
59
		if (file_exists($sFileToDelete)) {
60
			if (!is_writeable($sFileToDelete) || !@unlink($sFileToDelete)) {
61
			// notice if deleting fails
62
				$sMsg .= '<span style="color:red;">FAILED</span> deleting: '
63
				       . $sFileToDelete.'<br />'.PHP_EOL;
64
			}
65
		}
66
	}
67
	if ($sMsg) {
68
	// stop script if there's an error occured
69
		$sMsg .= '<br />'.PHP_EOL.'Please delete all of the files above manually!';
70
		$sMsg .= '<br />'.PHP_EOL.'----------------------------------------------';
71
	}
72
}
73
if ($sMsg) {
74
// stop script if there's an error occured
75
    $sMsg = $sMsg.'<br />'.PHP_EOL.'Please delete all of the files above manually!';
76
    UpgradeHelper::dieWithMessage($sMsg);
77
}
78
unset($aPreDeleteFiles);
79
$sMsg = '';
80
// ---------------------------------------------------------------------------------------
81
// Include config file
82
$config_file = __DIR__.'/config.php';
83
if (is_readable($config_file) && !defined('WB_URL')) {
84
	require_once($config_file);
85
}
86
$oDb  = WbDatabase::getInstance();
87
$oReg = WbAdaptor::getInstance();
88
UpgradeHelper::checkSetupFiles(str_replace('\\', '/', __DIR__).'/');
89
// --- modify table `settings` -----------------------------------------------------------
90
$oDb->removeField($oDb->TablePrefix.'settings', 'setting_id');
91
$oDb->addIndex($oDb->TablePrefix.'settings', 'PRIMARY', 'name', 'PRIMARY');
92
// --- set DEFAULT_THEME and restart if needed -------------------------------------------
93
if (isset($oReg->DefaultTheme) && trim($oReg->DefaultTheme, '/') != 'WbTheme') {
94
    db_update_key_value('settings', 'default_theme', 'WbTheme');
95
    $sLocation = 'Location: '.$oReg->AppUrl.basename(__FILE__);
96
    header($sLocation);
97
    exit;
98
}
99
// ---------------------------------------------------------------------------------------
100
//if (!class_exists('admin', false)) {
101
//	include(WB_PATH.'/framework/class.admin.php');
102
//}
103
$admin = new admin('Addons', 'modules', false, false);
104
// solved wrong pages_directory value before creating access files
105
$sql  = 'SELECT `value` FROM `'.TABLE_PREFIX.'settings` '
106
      . 'WHERE `name`=\'pages_directory\'';
107
$sPagesDirectory = $oDb->getOne($sql);
108
$sTmp = trim($sPagesDirectory, '/');
109
$sTmpDir = ($sTmp == '' ? '' : '/'.$sTmp);
110
if($sTmp != $sPagesDirectory) {
111
	$sql = 'UPDATE `'.$oDb->TablePrefix.'settings` '
112
		 . 'SET `value`=\''.$sTmpDir.'\' '
113
		 . 'WHERE `name`=\'pages_directory\' ';
114
	$oDb->doQuery($sql);
115
//	WbDatabase::getInstance()->query($sql);
116
}
117
require_once(WB_PATH.'/framework/functions.php');
118
// require_once(WB_PATH.'/framework/Database.php');
119

    
120
$oldVersion  = 'Version '.WB_VERSION;
121
$oldVersion .= (defined('WB_SP') ? WB_SP : '');
122
$oldRevision = (defined('WB_REVISION') ? ' Revision ['.WB_REVISION.'] ' : '') ;
123
$newVersion  = 'Version '.VERSION;
124
$newVersion .= (defined('SP') ? SP : '');
125
$newRevision = (defined('REVISION') ? ' Revision ['.REVISION.'] ' : '');
126

    
127
$bDebugModus = false;
128

    
129
// set addition settings if not exists, otherwise upgrade will be breaks
130
if(!defined('WB_SP')) { define('WB_SP',''); }
131
if(!defined('WB_REVISION')) { define('WB_REVISION',''); }
132
// database tables including in WB package
133
$aPackage = array (
134
    'settings','groups','addons','pages','sections','search','users'
135
);
136

    
137
$OK            = ' <span class="ok">OK</span> ';
138
$FAIL          = ' <span class="error">FAILED</span> ';
139
$DEFAULT_THEME = 'WbTheme';
140

    
141
$stepID = 1;
142
$dirRemove = array(
143
//			'[TEMPLATE]allcss/',
144
//			'[TEMPLATE]blank/',
145
//			'[TEMPLATE]round/',
146
//			'[TEMPLATE]simple/',
147
            '[TEMPLATE]wb_theme/',
148
			'[ADMIN]themes/'
149
		 );
150

    
151
$aRemoveSingleFiles = array(
152
			'[ADMIN]preferences/details.php',
153
			'[ADMIN]preferences/email.php',
154
			'[ADMIN]preferences/password.php',
155
			'[ADMIN]pages/settings2.php',
156
			'[ADMIN]users/users.php',
157
			'[ADMIN]groups/add.php',
158
			'[ADMIN]groups/groups.php',
159
			'[ADMIN]groups/save.php',
160
			'[ADMIN]skel/themes/htt/groups.htt',
161

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

    
221
/**
222
 * add_modify_field_in_database()
223
 *
224
 * @param mixed $sTable
225
 * @param mixed $sField
226
 * @param mixed $sDescription
227
 * @return
228
 */
229
function add_modify_field_in_database($sTable,$sField,$sDescription){
230
	global $OK,$FAIL,$bDebugModus;
231
	$database=WbDatabase::getInstance();
232
	$aDebugMessage = array();
233
	if(!$database->field_exists($sTable,$sField)) {
234
		$aDebugMessage[] = "<span>Adding field $sField to $sTable table</span>";
235
		$aDebugMessage[] = ($database->field_add($sTable, $sField, $sDescription) ? " $OK<br />" : " $FAIL!<br />");
236
	} else {
237
		$aDebugMessage[] = "<span>Modify field $sField to $sTable table</span>";
238
		$aDebugMessage[] = ($database->field_modify($sTable, $sField, $sDescription) ? " $OK<br />" : " $FAIL!<br />");
239
	}
240
	if($bDebugModus) {
241
		echo implode(PHP_EOL,$aDebugMessage);
242
	}
243
return;
244
}
245

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

    
254
body {
255
	margin:0;
256
	padding:0;
257
	border:0;
258
	background: #EBF7FC;
259
	color:#000;
260
	font-family: 'Trebuchet MS', Verdana, Arial, Helvetica, Sans-Serif;
261
	font-size: small;
262
	height:101%;
263
}
264

    
265
#container {
266
	min-width:48em;
267
    width: 70%;
268
	background: #A8BCCB url(<?php echo WB_URL; ?>/templates/<?php echo $DEFAULT_THEME; ?>/images/background.png) repeat-x;
269
	border:1px solid #000;
270
	color:#000;
271
	margin:2em auto;
272
	padding:0 20px;
273
	min-height: 500px;
274
	text-align:left;
275
}
276
.page {
277
	width:100%;
278
    overflow: hidden;
279
}
280
.content {
281
    padding: 10px;
282
}
283
p { line-height:1.5em; }
284

    
285
form {
286
	display: inline-block;
287
	line-height: 20px;
288
	vertical-align: baseline;
289
}
290
input[type="submit"].restart {
291
	background-color: #FFDBDB;
292
	font-weight: bold;
293
}
294

    
295
h1,h2,h3,h4,h5,h6 {
296
	font-family: Verdana, Arial, Helvetica, sans-serif;
297
	color: #26527D;
298
	margin-top: 1.0em;
299
	margin-bottom: 0.1em;
300
}
301

    
302
h1 { font-size:150%; }
303
h2 { font-size: 130%; border-bottom: 1px #CCC solid; }
304
h3 { font-size: 110%; font-weight: bold; }
305

    
306
textarea {
307
	width:100%;
308
	border: 2px groove #0F1D44;
309
	padding: 2px;
310
	color: #000;
311
	font-weight: normal;
312
}
313
.ok, .error { font-weight:bold; }
314
.ok { color:green; }
315
.error { color:red; }
316
.check { color:#555; }
317

    
318
span.ok,
319
span.error {
320
    margin-left: 0em;
321
}
322

    
323
.warning {
324
	background:#FFDBDB;
325
	padding:1em;
326
	margin-top:0.5em;
327
	border: 1px solid #DB0909;
328
}
329
.info {
330
	background:#C7F4C7;
331
	padding:1em;
332
	margin-top:0.5em;
333
	border: 1px solid #277A29;
334
}
335

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

    
402
?>
403
<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>
404

    
405
<?php
406

    
407
/**
408
 * Check if disclaimer was accepted
409
 */
410
$bDebugModus = false;
411
$bDebugModus = ( (isset($_POST['debug_confirmed']) && $_POST['debug_confirmed'] == 'debug') ? true : false);
412
if (!(isset($_POST['backup_confirmed']) && $_POST['backup_confirmed'] == 'confirmed')) { ?>
413
<h2>Step 1: Backup your files</h2>
414
<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>
415
<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>
416

    
417
<form action="<?php echo $_SERVER['SCRIPT_NAME'];?>" method="post">
418
<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>
419
<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>
420
<br /><br /><input name="debug_confirmed" type="checkbox" value="debug" />&nbsp;<strong>Here you can get more details during running upgrade.</strong>
421
<br /><br /><input name="send" type="submit" value="Start upgrade script" />
422
</form>
423
<br />
424

    
425
<?php
426
	status_msg('<strong> Notice:</strong><br />You need to confirm that you have created '
427
			  .'a manual backup of the '.PAGES_DIRECTORY.'/ directory and the MySQL '
428
	          .'database before you can proceed.',
429
	           'warning', 'div');
430
	echo '<br /><br /></div>'
431
	    .'</div>'
432
	    .'</div>'
433
	    .'</body>'
434
	    .'</html>';
435
	exit();
436
}
437

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

    
475
	echo '<h3>Step '.(++$stepID).': Setting default_theme</h3>';
476
	$aDebugMessage = array();
477
	/**********************************************************
478
	 *  - Adding field default_theme to settings table
479
	 */
480
	$aDebugMessage[] = '<div style="margin-left:2em;">';
481
	$aDebugMessage[] = "<span><strong>Adding default_theme to table settings</strong></span>";
482
	// db_update_key_value('settings', 'default_theme', $DEFAULT_THEME);
483
	$cfg = array(
484
		'default_theme' => $DEFAULT_THEME
485
	);
486
	$aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
487
	$aDebugMessage[] = '</div>';
488

    
489
	echo implode(PHP_EOL,$aDebugMessage);
490

    
491
	$aDebugMessage = array();
492
	echo'<h3>Step '.(++$stepID).': Updating core table included in package</h3>';
493
	/**********************************************************
494
	 *  - Adding field sec_anchor to settings table
495
	 */
496
	echo '<div style="margin-left:2em;">';
497
	echo "<h4>Adding/updating entries on table settings</h4>";
498
	$aDebugMessage[] = "<span>Adding/updating sec_anchor to settings table</span>";
499
	$cfg = array(
500
		'sec_anchor' => defined( 'SEC_ANCHOR' )&& (SEC_ANCHOR!='') ? SEC_ANCHOR : 'Sec'
501
	);
502
	$bLogStatus = (db_update_key_value( 'settings', $cfg ) ? true : false );
503
	$aDebugMessage[] = ( ($bLogStatus==true ) ? " $OK<br />" : " $FAIL!<br />");
504

    
505
	/**********************************************************
506
	 *  - Adding redirect timer to settings table
507
	 */
508
	$aDebugMessage[] = "<span>Adding/updating redirect timer to settings table</span>";
509
	$cfg = array(
510
		'redirect_timer' => defined('REDIRECT_TIMER')&& (REDIRECT_TIMER!='') ? REDIRECT_TIMER : '1500'
511
	);
512
	$bLogStatus = (db_update_key_value( 'settings', $cfg ) ? true : false );
513
	$aDebugMessage[] = ( ($bLogStatus==true ) ? " $OK<br />" : " $FAIL!<br />");
514

    
515
	/**********************************************************
516
	 *  - Adding default_time_formatr to settings table
517
	 */
518
	$aDebugMessage[] = "<span>Adding/updating default_time_format to settings table</span>";
519
	$cfg = array(
520
		'default_time_format' => defined('DEFAULT_TIME_FORMAT')&& (DEFAULT_TIME_FORMAT!='') ? DEFAULT_TIME_FORMAT : 'h:i A'
521
	);
522
	$bLogStatus = (db_update_key_value( 'settings', $cfg ) ? true : false );
523
	$aDebugMessage[] = ( ($bLogStatus==true ) ? " $OK<br />" : " $FAIL!<br />");
524

    
525
	/**********************************************************
526
	 *  - Adding rename_files_on_upload to settings table
527
	 */
528
	$aDebugMessage[] = "<span>Adding/Updating rename_files_on_upload to settings table</span>";
529
	$cfg = array(
530
	    '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')
531
	);
532
	if( version_compare( WB_VERSION, '2.8.2', '<' )) {
533
		$cfg = array(
534
		    'rename_files_on_upload' => 'ph.*?,cgi,pl,pm,exe,com,bat,pif,cmd,src,asp,aspx,js'
535
		);
536
	}
537
	$bLogStatus = (db_update_key_value( 'settings', $cfg ) ? true : false );
538
	$aDebugMessage[] = ( ($bLogStatus==true ) ? " $OK<br />" : " $FAIL!<br />");
539

    
540
	/**********************************************************
541
	 *  - Adding mediasettings to settings table
542
	 */
543
	$aDebugMessage[] = "<span>Adding/updating mediasettings to settings table</span>";
544
	$cfg = array(
545
		'mediasettings' => (defined('MEDIASETTINGS')&& (MEDIASETTINGS!='') ? MEDIASETTINGS : ''),
546
	);
547
	$bLogStatus = (db_update_key_value( 'settings', $cfg ) ? true : false );
548
	$aDebugMessage[] = ( ($bLogStatus==true ) ? " $OK<br />" : " $FAIL!<br />");
549

    
550
	/**********************************************************
551
	 *  - Adding fingerprint_with_ip_octets to settings table
552
	 */
553
	$aDebugMessage[] = "<span>Adding/updating fingerprint_with_ip_octets to settings table</span>";
554
	$cfg = array(
555
		'fingerprint_with_ip_octets' => (defined('FINGERPRINT_WITH_IP_OCTETS') ? FINGERPRINT_WITH_IP_OCTETS : '2'),
556
		'secure_form_module' => (defined('SECURE_FORM_MODULE') ? SECURE_FORM_MODULE : '')
557
	);
558
	$bLogStatus = (db_update_key_value( 'settings', $cfg ) ? true : false );
559
	$aDebugMessage[] = ( ($bLogStatus==true ) ? " $OK<br />" : " $FAIL!<br />");
560

    
561
	/**********************************************************
562
	 *  - Adding page_icon_dir to settings table
563
	 */
564
	$aDebugMessage[] = "<span>Adding/updating page_icon_dir to settings table</span>";
565
	$cfg = array(
566
		'page_icon_dir' => (defined('PAGE_ICON_DIR')&& (PAGE_ICON_DIR!='') ? PAGE_ICON_DIR : '/templates/*/title_images'),
567
	);
568
	$bLogStatus = (db_update_key_value( 'settings', $cfg ) ? true : false );
569
	$aDebugMessage[] = ( ($bLogStatus==true ) ? " $OK<br />" : " $FAIL!<br />");
570
	/**********************************************************
571
	 *  - Adding page_extended to settings table
572
	 */
573
	$aDebugMessage[] = "<span>Adding/updating page_extendet to settings table</span>";
574
	$cfg = array(
575
		'page_extendet' => (defined('PAGE_EXTENDET') ? PAGE_EXTENDET : 'true'),
576
	);
577
	$bLogStatus = (db_update_key_value( 'settings', $cfg ) ? true : false );
578
	$aDebugMessage[] = ( ($bLogStatus==true ) ? " $OK<br />" : " $FAIL!<br />");
579

    
580
	/**********************************************************
581
	 *  - Adding wbmail_signature to settings table
582
	 */
583
	$aDebugMessage[] = "<span>Adding/updating wbmail_signature to settings table</span>";
584
	$cfg = array(
585
		'wbmail_signature' => (defined('WBMAIL_SIGNATURE')&& (WBMAIL_SIGNATURE!='') ? WBMAIL_SIGNATURE : '')
586
	);
587
	$bLogStatus = (db_update_key_value( 'settings', $cfg ) ? true : false );
588
	$aDebugMessage[] = ( ($bLogStatus==true ) ? " $OK<br />" : " $FAIL!<br />");
589

    
590
	/**********************************************************
591
	 *  - Adding confirmed_registration to settings table
592
	 */
593
	$aDebugMessage[] = "<span>Adding/updating confirmed_registration to settings table</span>";
594
	$cfg = array(
595
		'confirmed_registration' => (defined('CONFIRMED_REGISTRATION') ? CONFIRMED_REGISTRATION : '0')
596
	);
597
	$bLogStatus = (db_update_key_value( 'settings', $cfg ) ? true : false );
598
	$aDebugMessage[] = ( ($bLogStatus==true ) ? " $OK<br />" : " $FAIL!<br />");
599

    
600
	/**********************************************************
601
	 *  - Adding dev_infos to settings table
602
	 */
603
	$aDebugMessage[] = "<span>Adding/updating dev_infos to settings table</span>";
604
	$cfg = array(
605
		'dev_infos' => (defined('DEV_INFOS') ? DEV_INFOS : 'false')
606
	);
607
	$bLogStatus = (db_update_key_value( 'settings', $cfg ) ? true : false );
608
	$aDebugMessage[] = ( ($bLogStatus==true ) ? " $OK<br />" : " $FAIL!<br />");
609

    
610
	/**********************************************************
611
	 *  - Adding server_timezone to settings table
612
	 */
613
	$aDebugMessage[] = "<span>Adding/updating server_timezone to settings table</span>";
614
	$cfg = array(
615
		'server_timezone' => (defined('SERVER_TIMEZONE') ? SERVER_TIMEZONE : 'UTC')
616
	);
617
	$bLogStatus = (db_update_key_value( 'settings', $cfg ) ? true : false );
618
	$aDebugMessage[] = ( ($bLogStatus==true ) ? " $OK<br />" : " $FAIL!<br />");
619

    
620
	/**********************************************************
621
	 *  - Adding password settings to table settings
622
	 */
623
	$aDebugMessage[] = "<span>Adding/updating password settings to settings table</span>";
624
	$cfg = array();
625
	$cfg['password_crypt_loops'] = (defined('PASSWORD_CRYPT_LOOPS') ? PASSWORD_CRYPT_LOOPS : '12');
626
	$cfg['password_hash_type'] = (defined('PASSWORD_HASH_TYPES') ? PASSWORD_HASH_TYPES : 'false');
627
	$cfg['password_length'] = (defined('PASSWORD_LENGTH') ? PASSWORD_LENGTH : '10');
628
	$cfg['password_use_types'] = (defined('PASSWORD_USE_TYPES') ? PASSWORD_USE_TYPES : (int)0xFFFF);
629
	$bLogStatus = (db_update_key_value( 'settings', $cfg ) ? true : false );
630
	$aDebugMessage[] = ( ($bLogStatus==true ) ? " $OK<br />" : " $FAIL!<br />");
631

    
632
if($bDebugModus) {
633
    echo implode(PHP_EOL,$aDebugMessage);
634
} else {
635
        echo '<strong>Successfully upgraded</strong>'." $OK<br />";	   
636
	}
637
echo '</div>';
638

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

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

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

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

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

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

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

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

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

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

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

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

    
748
	if($bDebugModus) {
749
		echo implode(PHP_EOL,$aDebugMessage);
750
	} else {
751
        echo '<strong>Successfully upgraded</strong>'." $OK<br />";	   
752
	}
753

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

    
773
    /**********************************************************
774
	 *  - Add field "title" to table sections
775
	 */
776
	$table_name = TABLE_PREFIX.'sections';
777
	$field_name = 'title';
778
	$description = "VARCHAR( 255 ) NOT NULL DEFAULT 'Section-ID 0' ";
779
	add_modify_field_in_database($table_name,$field_name,$description);
780

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

    
805
	$sql = 'UPDATE `'.TABLE_PREFIX.'groups` '
806
         . 'SET `name` = \'Administrators\', '
807
         .     '`system_permissions` = \''.$sSystemPermissions.'\', '
808
         .     '`module_permissions` = \''.$sModulePermissions.'\', '
809
         .     '`template_permissions` = \''.$sTemplatePermissions.'\' '
810
         . 'WHERE `group_id` = \'1\' ';
811
	$aDebugMessage[] = ($database->query($sql)) ? " $OK<br />" : " $FAIL!<br />";
812
	if( ($admin->is_authenticated() == true) && ($admin->ami_group_member('1') ) ) {
813
	    $_SESSION['SYSTEM_PERMISSIONS'] = array_merge($_SESSION['SYSTEM_PERMISSIONS'], explode(',', $sSystemPermissions));
814
	}
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
	$aDebugMessage = array();
823
	/**********************************************************
824
	 *   `confirm_code` VARCHAR(32) NOT NULL DEFAULT '',
825
	 *   `confirm_timeout` INT(11) NOT NULL DEFAULT '0',
826
	 */
827
	echo '<div style="margin-left:2em;">';
828
	echo "<h4>Change field structure on table users</h4>";
829
	$table_name = TABLE_PREFIX.'users';
830
	$field_name = 'confirm_code';
831
	$description = "VARCHAR( 32 ) NOT NULL DEFAULT '' AFTER `password` ";
832
	add_modify_field_in_database($table_name,$field_name,$description);
833

    
834
	$table_name = TABLE_PREFIX.'users';
835
	$field_name = 'confirm_timeout';
836
	$description = "INT(11) NOT NULL DEFAULT '0' AFTER `confirm_code` ";
837
	add_modify_field_in_database($table_name,$field_name,$description);
838

    
839
	if($bDebugModus) {
840
	    echo implode(PHP_EOL,$aDebugMessage);
841
	} else {
842
        echo '<strong>Successfully upgraded</strong>'." $OK<br />";	   
843
	}
844
	echo '</div>';
845

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

    
883
	if($bDebugModus) {
884
	// $aDebugMessage[] =
885
	    echo implode(PHP_EOL,$aDebugMessage);
886
	}else {
887
	    echo '<span><strong>'.$iTotalUsers.' users updating the groups</strong></span>'." $OK<br />";
888
	    echo '</div>';
889
	}
890
}
891

    
892
$aDebugMessage = array();
893
echo '<h3>Step '.(++$stepID).': Updating access files in folders</h3>';
894

    
895
echo '<div style="margin-left:2em;">';
896
	/**********************************************************
897
	* upgrade media directory index protect files
898
	*/
899
//	echo '<h4>Upgrade media directory '.MEDIA_DIRECTORY.'/ index.php protect files</h4>';
900
//	$aDebugMessage = rebuildFolderProtectFile();
901
//	if( sizeof( $aDebugMessage ) ){
902
//		echo '<span><strong>Upgrade '.sizeof( $aDebugMessage ).' directory '.MEDIA_DIRECTORY.'/ protect files</strong></span>'." $OK<br />";
903
//	} else {
904
//		echo '<span><strong>Upgrade directory '.MEDIA_DIRECTORY.'/ protect files</strong></span>'." $FAIL!<br />";
905
//		echo implode ('<br />',$aDebugMessage);
906
//	}
907
//
908
//    $aDebugMessage = array();
909
    /**********************************************************
910
     * upgrade pages directory index access files
911
     */
912
	echo '<h4>Upgrade pages directory '.PAGES_DIRECTORY.'/  access files</h4>';
913

    
914
	/**********************************************************
915
	 * Repair inconsistent PageTree
916
	 */
917
	$iCount = UpgradeHelper::sanitizePagesTreeLinkStructure();
918
	if (false === $iCount) {
919
		echo '<span><strong>Repair PageTree links </strong></span> '.$FAIL.'<br />';
920
	} else {
921
		echo '<span><strong>'.$iCount.' PageTree links repaired.</strong></span> '.$OK.'<br />';
922
	}
923
    /**********************************************************
924
     *  - Reformat/rebuild all existing access files
925
     */
926
    $msg = rebuild_all_accessfiles($bDebugModus);
927
	echo '<strong>'.implode ('<br />',$msg).'</strong>';
928
    echo '</div>';
929

    
930
	/* *****************************************************************************
931
	 * - check for deprecated / never needed files
932
	 */
933
	$iLoaded = sizeof($aFilesToRemove);
934
	if($iLoaded) {
935
		echo '<h3>Step '.(++$stepID).': Remove deprecated and outdated files</h3>';
936
		$iFailed = 0;
937
		$iFound = 0;
938
		$searches = array(
939
			'[ADMIN]',
940
			'[MEDIA]',
941
			'[PAGES]',
942
			'[FRAMEWORK]',
943
			'[MODULES]',
944
			'[TEMPLATE]'
945
		);
946
		$replacements = array(
947
            $oReg->AcpDir,
948
            $oReg->MediaDir,
949
            $oReg->PagesDir,
950
			'framework/',
951
			'modules/',
952
			'templates/'
953
		);
954

    
955
		$msg = '';
956
		echo '<div style="margin-left:2em;">';
957
		echo '<h4>Search '.$iLoaded.' deprecated and outdated files</h4>';
958
		foreach( $aFilesToRemove as $file )
959
		{
960
			$file = str_replace($searches, $replacements, $file);
961
			if( is_writable($oReg->AppDir.$file) ) {
962
				$iFound++;
963
				// try to unlink file
964
				if(!unlink($oReg->AppDir.$file)) {
965
					$iFailed++;
966
				}
967
			}
968
			if( is_readable($oReg->AppDir.$file) ) {
969
				// save in err-list, if failed
970
				$msg .= $file.'<br />';
971
			}
972
		}
973
		$iRemove = $iFound-$iFailed;
974
		echo '<strong>Remove '.$iRemove.' from '.$iFound.' founded</strong> ';
975
		echo ($iFailed == 0) ? $OK : $FAIL;
976
		echo '</div>';
977

    
978
		if($msg != '')
979
		{
980
			$msg = '<br /><br />Following files are deprecated, outdated or a security risk and
981
				    can not be removed automatically.<br /><br />Please delete them
982
					using FTP and restart upgrade-script!<br /><br />'.$msg.'<br />';
983
			status_msg($msg, 'error warning', 'div');
984
			echo '<p style="font-size:120%;"><strong>WARNING: The upgrade script failed ...</strong></p>';
985

    
986
			echo '<form action="'.$_SERVER['SCRIPT_NAME'].'">';
987
			echo '&nbsp;<input name="send" type="submit" value="Restart upgrade script" />';
988
			echo '</form>';
989
			echo "<br /><br /></div>
990
			</div>
991
			</div>
992
			</body>
993
			</html>";
994
			exit;
995
		}
996
	}
997

    
998

    
999
	/**********************************************************
1000
	 * - check for deprecated / never needed folders
1001
	 */
1002
	$iLoaded = sizeof($dirRemove);
1003
	if($iLoaded) {
1004
		echo '<h3>Step  '.(++$stepID).': Remove deprecated and outdated folders</h3>';
1005
		$iFailed = 0;
1006
		$iFound = 0;
1007
		$searches = array(
1008
			'[ADMIN]',
1009
			'[MEDIA]',
1010
			'[PAGES]',
1011
			'[FRAMEWORK]',
1012
			'[MODULES]',
1013
			'[TEMPLATE]'
1014
		);
1015
		$replacements = array(
1016
            $oReg->AcpDir,
1017
            $oReg->MediaDir,
1018
            $oReg->PagesDir,
1019
			'framework/',
1020
			'modules/',
1021
			'templates/'
1022
		);
1023
		$msg = '';
1024
		echo '<div style="margin-left:2em;">';
1025
		echo '<h4>Search '.$iLoaded.' deprecated and outdated folders</h4>';
1026
		foreach( $dirRemove as $sRootDir ) {
1027
			$sRootDir = str_replace($searches, $replacements, $sRootDir);
1028
            if (file_exists($oReg->AppPath.$sRootDir)) {
1029
                if (!UpgradeHelper::delTree($oReg->AppPath.$sRootDir, UpgradeHelper::DEL_ROOT_DELETE)) {
1030
                    $iFailed = sizeof(($msg = UpgradeHelper::getDelTreeLog()));
1031
                    $msg = implode('<br />', $msg);
1032
                }
1033
            }
1034
        }
1035
		echo ($iFailed == 0) ? $OK : $FAIL;
1036
		echo '</div>';
1037
		if($msg != '') {
1038
			$msg = '<br /><br />Following directories are deprecated, outdated or a security risk and
1039
					can not be removed automatically.<br /><br />Please delete them
1040
					using FTP and restart upgrade-script!<br /><br />'.$msg.'<br />';
1041
			status_msg($msg, 'error warning', 'div');
1042
			echo '<p style="font-size:120%;"><strong>WARNING: The upgrade script failed ...</strong></p>';
1043
			echo '<form action="'.$_SERVER['SCRIPT_NAME'].'">';
1044
			echo '&nbsp;<input name="send" type="submit" value="Restart upgrade script" />';
1045
			echo '</form>';
1046
			echo "<br /><br /></div>
1047
			</div>
1048
			</div>
1049
			</body>
1050
			</html>";
1051
			exit;
1052
		}
1053
	}
1054

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

    
1079
	/**********************************************************
1080
	 * Reformat/rebuild all existing moules access files
1081
	 * $aModuleList list of modules
1082
	 */
1083
	$aModuleList = array('bakery','topics','news');
1084
	if(sizeof($aModuleList)) 
1085
	{
1086
		echo '<h3>Step '.(++$stepID).': Create/Reorg Accessfiles from modules</h3>';
1087
		foreach($aModuleList as $sModul) {
1088
			$aReturnMsg = array();
1089
			$sModulReorg = 'm_'.$sModul.'_Reorg';
1090
			if(class_exists($sModulReorg)) {
1091
				$sModulVersion =  get_modul_version ($sModul, true);
1092
				echo '<div style="margin-left:2em;">';
1093
				echo '<h4>'.'Create/Reorg Accessfiles for module \''.$sModul.'\' version '.$sModulVersion.'</h4>';
1094
				$oReorg = new $sModulReorg(ModuleReorgAbstract::LOG_EXTENDED);
1095
				$aReturnMsg = $oReorg->execute(); // show details
1096
                $aReport = $oReorg->getReport();
1097
                unset($oReorg);
1098
                if($bDebugModus) {
1099
                    foreach($aReport['Failed'] as $sValue) {
1100
                        echo $sValue.'<br />';
1101
                    }
1102
                    foreach($aReport['Success'] as $sValue) {
1103
                        echo $sValue.'<br />';
1104
                    }
1105
    			}
1106
//				echo '<strong>'.$aReport['FilesDeleted'].' Files successful deleted</strong><br />';
1107
				echo '<strong>Number of new formated access files: '.$aReport['FilesCreated'].'</strong><br />';
1108

    
1109
				echo '</div>';
1110
			}
1111
		}
1112
	}
1113
/**********************************************************
1114
 *  - Reload all addons
1115
 */
1116

    
1117
	echo '<h3>Step '.(++$stepID).' : Reload all addons database entry (no upgrade)</h3><br />';
1118
	echo '<div style="margin-left:2em;">';
1119
	$iFound = 0;
1120
	$iLoaded = 0;
1121
	////delete modules
1122
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'module'");
1123
	// Load all modules
1124
	if( ($handle = opendir(WB_PATH.'/modules/')) ) {
1125
		while(false !== ($file = readdir($handle))) {
1126
			if($file != '' && substr($file, 0, 1) != '.' && is_dir(WB_PATH.'/modules/'.$file) ) {
1127
				$iFound++;
1128
				$iLoaded = load_module(WB_PATH.'/modules/'.$file ) ? $iLoaded+1 : $iLoaded;
1129
// 	upgrade_module($file, true);
1130
			}
1131
		}
1132
		closedir($handle);
1133
	}
1134
	echo '<strong><span>'.$iLoaded.' Modules reloaded,</span> found '.$iFound.' directories in folder /modules/</strong><br />';
1135

    
1136
	$iFound = 0;
1137
	$iLoaded = 0;
1138
	////delete templates
1139
	$oDb->doQuery('DELETE FROM `'.$oDb->TablePrefix.'addons` WHERE `type`=\'template\'');
1140
	// Load all templates
1141
	if( ($handle = opendir(WB_PATH.'/templates/')) ) {
1142
		while(false !== ($file = readdir($handle))) {
1143
			if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
1144
				$iFound++;
1145
				$iLoaded = (load_template(WB_PATH.'/templates/'.$file)==true) ? $iLoaded+1 : $iLoaded;
1146
			}
1147
		}
1148
		closedir($handle);
1149
	}
1150
	echo '<strong><span>'.$iLoaded.' Templates reloaded,</span> found '.$iFound.' directories in folder /templates/</strong><br />';
1151
	$iFound = 0;
1152
	$iLoaded = 0;
1153
	////delete languages
1154
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'language'");
1155
	// Load all languages
1156
	if( ($handle = opendir(WB_PATH.'/languages/')) ) {
1157
		while(false !== ($file = readdir($handle))) {
1158
			if($file != '' AND (preg_match('#^([A-Z]{2}.php)#', basename($file)))) {
1159
				$iFound++;
1160
				$iLoaded = load_language(WB_PATH.'/languages/'.$file) ? $iLoaded+1 : $iLoaded;
1161
			}
1162
		}
1163
		closedir($handle);
1164
	}
1165
	echo '<strong><span>'.$iLoaded.' Languages reloaded,</span> found '.$iFound.' files in folder /languages/</strong><br />';
1166
	$sTransCachePath = WB_PATH.'/temp/TranslationTable/cache/';
1167
	if (is_writeable($sTransCachePath)) {
1168
		if (rm_full_dir($sTransCachePath, true)) {
1169
			echo '<strong><span>Translation Cache cleaned</span></strong> '.$OK.'<br />';
1170
		} else {
1171
			echo '<strong><span>Clean Translation Cache</span></strong> '.$FAIL.'<br />';
1172
		}
1173
	}
1174
	echo '</div>';
1175

    
1176
/**********************************************************
1177
 *  - install new droplets
1178
	$drops = (!in_array ( "mod_droplets", $all_tables)) ? "<br />Install droplets<br />" : "<br />Upgrade droplets<br />";
1179
	echo $drops;
1180
	$file_name = (!in_array ( "mod_droplets", $all_tables) ? "install.php" : "upgrade.php");
1181
	require_once (WB_PATH."/modules/droplets/".$file_name);
1182
********************************************************** */
1183

    
1184
/**********************************************************
1185
 *  - End of upgrade script
1186
 */
1187
	if(!defined('DEFAULT_THEME')) { define('DEFAULT_THEME', $DEFAULT_THEME); }
1188
	if(!defined('THEME_PATH')) { define('THEME_PATH', WB_PATH.'/templates/'.DEFAULT_THEME);}
1189
/**********************************************************
1190
 *  - Set Version to new Version
1191
 */
1192
echo '<h3>Step '.(++$stepID).': Update database version number </h3>';
1193
echo '<div style="margin-left:2em;">';
1194

    
1195
$cfg = array(
1196
	'wb_version' => VERSION,
1197
	'wb_revision' => REVISION,
1198
	'wb_sp' => SP
1199
);
1200
echo '<br /><span><strong>Set WebsiteBaker version number to '.VERSION.' '.SP.' '.' Revision ['.REVISION.'] : </strong></span>';
1201
echo (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
1202
echo '</div>';
1203

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

    
1209
if(defined('WB_URL')) {
1210
	echo '<form action="'.WB_URL.'/">';
1211
	echo '&nbsp;<input type="submit" value="kick me to the Frontend" />';
1212
	echo '</form>';
1213
}
1214
if(defined('ADMIN_URL')) {
1215
	echo '<form action="'.ADMIN_URL.'/">';
1216
	echo '&nbsp;<input type="submit" value="kick me to the Backend" />';
1217
	echo '</form>';
1218
}
1219

    
1220
echo "<br /><br /></div>
1221
</div>
1222
</div>
1223
</body>
1224
</html>
1225
";
1226
exit();
(6-6/6)