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

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

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

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

    
70
$bDebugModus = false;
71

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

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

    
85
$stepID = 0;
86
$filesRemove = array();
87
$aFilesToRemove = array();
88
$dirRemove = array(
89
/*
90
			'[TEMPLATE]/allcss/',
91
			'[TEMPLATE]/blank/',
92
			'[TEMPLATE]/round/',
93
			'[TEMPLATE]/simple/',
94
*/
95
			'[ADMIN]/themes/',
96
		 );
97
//
98
	$filesRemove['0'] = array(
99

    
100
			'[ADMIN]/preferences/details.php',
101
			'[ADMIN]/preferences/email.php',
102
			'[ADMIN]/preferences/password.php',
103
			'[ADMIN]/pages/settings2.php',
104
			'[ADMIN]/users/users.php',
105
			'[ADMIN]/groups/add.php',
106
			'[ADMIN]/groups/groups.php',
107
			'[ADMIN]/groups/save.php',
108
			'[ADMIN]/skel/themes/htt/groups.htt',
109

    
110
			'[FRAMEWORK]/class.msg_queue.php',
111
			'[FRAMEWORK]/class.logfile.php',
112
			'[MODULES]/droplets/js/mdcr.js',
113

    
114
		 );
115
	$aFilesToRemove = array_merge($filesRemove['0']);
116

    
117
// deleting files below only from less 2.8.4 stable
118
if(version_compare(WB_VERSION, '2.8.4', '<'))
119
{
120
	$filesRemove['1'] = array(
121

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

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

    
181
	$aFilesToRemove = array_merge($aFilesToRemove,$filesRemove['1']);
182

    
183
}
184
/* display a status message on the screen **************************************
185
 * @param string $message: the message to show
186
 * @param string $class:   kind of message as a css-class
187
 * @param string $element: witch HTML-tag use to cover the message
188
 * @return void
189
 */
190
function status_msg($message, $class='check', $element='div')
191
{
192
	// returns a status message
193
	$msg  = '<'.$element.' class="'.$class.'">';
194
	$msg .= '<strong>'.strtoupper(strtok($class, ' ')).'</strong>';
195
	$msg .= $message.'</'.$element.'>';
196
	echo $msg;
197
}
198

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
382
<?php
383

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

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

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

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

    
445
		exit();
446
	}
447

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
580
	/**********************************************************
581
	 *  - Adding password settings to settings table
582
	 */
583
	$aDebugMessage[] = "<span>Adding/updating password settings to settings table</span>";
584
	$cfg = array();
585
	$cfg['password_crypt_loops'] = (defined('PASSWORD_CRYPT_LOOPS') ? PASSWORD_CRYPT_LOOPS : '12');
586
	$cfg['password_hash_type'] = (defined('PASSWORD_HASH_TYPES') ? PASSWORD_HASH_TYPES : 'false');
587
	$cfg['password_length'] = (defined('PASSWORD_LENGTH') ? PASSWORD_LENGTH : '10');
588
	$cfg['password_use_types'] = (defined('PASSWORD_USE_TYPES') ? PASSWORD_USE_TYPES : (int)0xFFFF);
589
    $aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
590

    
591
if($bDebugModus) {
592
    echo implode(PHP_EOL,$aDebugMessage);
593
}
594
echo '</div>';
595

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

    
615
	$aDebugMessage = array();
616
	echo "<h4>Adding/updating field on table pages</h4>";
617
	/**********************************************************
618
	 *  - Add field "page_trail" to table "pages"
619
	 */
620
	$table_name = TABLE_PREFIX.'pages';
621
	$field_name = 'page_trail';
622
	$description = "VARCHAR( 255 ) NOT NULL DEFAULT ''";
623
	add_modify_field_in_database($table_name,$field_name,$description);
624

    
625
	/**********************************************************
626
	 *  - Add field "page_icon" to table "pages"
627
	 */
628
	$table_name = TABLE_PREFIX.'pages';
629
	$field_name = 'page_icon';
630
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '' AFTER `page_title`";
631
	add_modify_field_in_database($table_name,$field_name,$description);
632

    
633
	/**********************************************************
634
	 *  - Add field "page_code" to table "pages"
635
	 */
636
	$table_name = TABLE_PREFIX.'pages';
637
	$field_name = 'page_code';
638
	$description = "INT NOT NULL DEFAULT '0' AFTER `language`";
639
	add_modify_field_in_database($table_name,$field_name,$description);
640

    
641
	/**********************************************************
642
	 *  - Add field "menu_icon_0" to table "pages"
643
	 */
644
	$table_name = TABLE_PREFIX.'pages';
645
	$field_name = 'menu_icon_0';
646
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '' AFTER `menu_title`";
647
	add_modify_field_in_database($table_name,$field_name,$description);
648

    
649
	/**********************************************************
650
	 *  - Add field "menu_icon_1" to table "pages"
651
	 */
652
	$table_name = TABLE_PREFIX.'pages';
653
	$field_name = 'menu_icon_1';
654
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '' AFTER `menu_icon_0`";
655
	add_modify_field_in_database($table_name,$field_name,$description);
656

    
657
	/**********************************************************
658
	 *  - Add field "tooltip" to table "pages"
659
	 */
660
	$table_name = TABLE_PREFIX.'pages';
661
	$field_name = 'tooltip';
662
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '' AFTER `menu_icon_1`";
663
	add_modify_field_in_database($table_name,$field_name,$description);
664

    
665
	/**********************************************************
666
	 *  - Add field "admin_groups" to table "pages"
667
	 */
668
	$table_name = TABLE_PREFIX.'pages';
669
	$field_name = 'admin_groups';
670
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '1'";
671
	add_modify_field_in_database($table_name,$field_name,$description);
672

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

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

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

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

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

    
713
	if($bDebugModus) {
714
		echo implode(PHP_EOL,$aDebugMessage);
715
	}
716

    
717
	$aDebugMessage = array();
718
	/**********************************************************
719
	 * modify wrong strucre on table sections
720
	 * wrong structure let crash wb
721
	 */
722
	echo "<h4>Change field structure on table sections</h4>";
723
	$table_name = TABLE_PREFIX.'sections';
724
	$description = "VARCHAR( 255 ) NOT NULL DEFAULT ''";
725
	$aDebugMessage[] = "<span>Modify field module on sections table</span>";
726
	$aDebugMessage[] = ($database->field_modify($table_name, 'module', $description) ? " $OK<br />" : " $FAIL!<br />");
727
	$aDebugMessage[] = "<span>Modify field block on sections table</span>";
728
	$description = "int(11) NOT NULL DEFAULT '1'";
729
	$aDebugMessage[] = ($database->field_modify($table_name, 'block', $description) ? " $OK<br />" : " $FAIL!<br />");
730
	$description = "int(11) NOT NULL DEFAULT '0'";
731
	$aDebugMessage[] = "<span>Modify field publ_start on sections table</span>";
732
	$aDebugMessage[] = ($database->field_modify($table_name, 'publ_start', $description) ? " $OK<br />" : " $FAIL!<br />");
733
	$aDebugMessage[] = "<span>Modify field publ_end on sections table</span>";
734
	$aDebugMessage[] = ($database->field_modify($table_name, 'publ_end', $description) ? " $OK<br />" : " $FAIL!<br />");
735

    
736
	if($bDebugModus) {
737
		echo implode(PHP_EOL,$aDebugMessage);
738
	}
739
	echo '</div>';
740
}
741

    
742
if(version_compare(WB_REVISION, REVISION, '<='))
743
{
744
	$aDebugMessage = array();
745
	echo '<h3>Step '.(++$stepID).': Updating structure in table users/groups</h3>';
746
	/**********************************************************
747
	 * Modify Administrator on groups table
748
	 */
749
	echo '<div style="margin-left:2em;">';
750
	echo "<h4>Updating Administrator group permissions on table groups</h4>";
751
	$aDebugMessage[] = "<span>Modify Administrator on groups table</span>";
752
	$sModulePermissions = '';
753
	$sTemplatePermissions = '';
754
	$sSystemPermissions  = 'access,addons,admintools,admintools_view,groups,groups_add,groups_delete,groups_modify,groups_view,';
755
	$sSystemPermissions .= 'languages,languages_install,languages_uninstall,languages_view,media,media_create,media_delete,media_rename,media_upload,media_view,';
756
	$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,';
757
	$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';
758

    
759
	$sql  = 'UPDATE `'.TABLE_PREFIX.'groups` ';
760
	$sql .= 'SET `name` = \'Administrators\', ';
761
	$sql .= '`system_permissions` = \''.$sSystemPermissions.'\', ';
762
	$sql .= '`module_permissions` = \''.$sModulePermissions.'\', ';
763
	$sql .= '`template_permissions` = \''.$sTemplatePermissions.'\' ';
764
	$sql .= 'WHERE `group_id` = \'1\' ';
765
	$aDebugMessage[] = ($database->query($sql)) ? " $OK<br />" : " $FAIL!<br />";
766
	if( ($admin->is_authenticated() == true) && ($admin->ami_group_member('1') ) ) {
767
	    $_SESSION['SYSTEM_PERMISSIONS'] = array_merge($_SESSION['SYSTEM_PERMISSIONS'], explode(',', $sSystemPermissions));
768
	}
769

    
770
	if($bDebugModus) {
771
		echo implode(PHP_EOL,$aDebugMessage);
772
	}
773
	echo '</div>';
774
	$aDebugMessage = array();
775
	/**********************************************************
776
	 *   `confirm_code` VARCHAR(32) NOT NULL DEFAULT '',
777
	 *   `confirm_timeout` INT(11) NOT NULL DEFAULT '0',
778
	 */
779
	echo '<div style="margin-left:2em;">';
780
	echo "<h4>Change field structure on table users</h4>";
781
	$table_name = TABLE_PREFIX.'users';
782
	$field_name = 'confirm_code';
783
	$description = "VARCHAR( 32 ) NOT NULL DEFAULT '' AFTER `password` ";
784
	add_modify_field_in_database($table_name,$field_name,$description);
785

    
786
	$table_name = TABLE_PREFIX.'users';
787
	$field_name = 'confirm_timeout';
788
	$description = "INT(11) NOT NULL DEFAULT '0' AFTER `confirm_code` ";
789
	add_modify_field_in_database($table_name,$field_name,$description);
790

    
791
	if($bDebugModus) {
792
	    echo implode(PHP_EOL,$aDebugMessage);
793
	}
794
	echo '</div>';
795

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

    
833
	if($bDebugModus) {
834
	// $aDebugMessage[] =
835
	    echo implode(PHP_EOL,$aDebugMessage);
836
	}else {
837
	    echo '<span><strong>'.$iTotalUsers.' users updating the groups</strong></span>'." $OK<br />";
838
	    echo '</div>';
839
	}
840
}
841

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

    
845
echo '<div style="margin-left:2em;">';
846
	/**********************************************************
847
	* upgrade media directory index protect files
848
	*/
849
	$dir = (WB_PATH.MEDIA_DIRECTORY);
850
	echo '<h4>Upgrade media directory '.MEDIA_DIRECTORY.'/ index.php protect files</h4>';
851
	$aDebugMessage = rebuildFolderProtectFile($dir);
852
	if( sizeof( $aDebugMessage ) ){
853
		echo '<span><strong>Upgrade '.sizeof( $aDebugMessage ).' directory '.MEDIA_DIRECTORY.'/ protect files</strong></span>'." $OK<br />";
854
	} else {
855
		echo '<span><strong>Upgrade directory '.MEDIA_DIRECTORY.'/ protect files</strong></span>'." $FAIL!<br />";
856
		echo implode ('<br />',$aDebugMessage);
857
	}
858

    
859
    $aDebugMessage = array();
860
    /**********************************************************
861
     * upgrade pages directory index access files
862
     */
863
	echo '<h4>Upgrade pages directory '.PAGES_DIRECTORY.'/  protect and access files</h4>';
864

    
865
    /**********************************************************
866
     *  - Reformat/rebuild all existing access files
867
     */
868
    $sPagePath = (defined('PAGES_DIRECTORY') && (PAGES_DIRECTORY != '') ? PAGES_DIRECTORY : '');
869
    $msg = rebuild_all_accessfiles();
870
	$dir = (WB_PATH.PAGES_DIRECTORY);
871
//	$aDebugMessage = rebuildFolderProtectFile($dir);
872
	echo '<strong>'.implode ('<br />',$msg).'</strong>';
873
    echo '</div>';
874

    
875
	/* *****************************************************************************
876
	 * - check for deprecated / never needed files
877
	 */
878
	$iLoaded = sizeof($aFilesToRemove);
879
	if($iLoaded) {
880
		echo '<h3>Step '.(++$stepID).': Remove deprecated and outdated files</h3>';
881
		$iFailed = 0;
882
		$iFound = 0;
883
		$searches = array(
884
			'[ADMIN]',
885
			'[MEDIA]',
886
			'[PAGES]',
887
			'[FRAMEWORK]',
888
			'[MODULES]',
889
			'[TEMPLATE]'
890
		);
891
		$replacements = array(
892
			'/'.substr(ADMIN_PATH, strlen(WB_PATH)+1),
893
			MEDIA_DIRECTORY,
894
			PAGES_DIRECTORY,
895
			'/framework',
896
			'/modules',
897
			'/templates'
898
		);
899

    
900
		$msg = '';
901
		echo '<div style="margin-left:2em;">';
902
		echo '<h4>Search '.$iLoaded.' deprecated and outdated files</h4>';
903
		foreach( $aFilesToRemove as $file )
904
		{
905
			$file = str_replace($searches, $replacements, $file);
906
			if( is_writable(WB_PATH.'/'.$file) ) {
907
				$iFound++;
908
				// try to unlink file
909
				if(!unlink(WB_PATH.$file)) {
910
					$iFailed++;
911
				}
912
			}
913
			if( is_readable(WB_PATH.'/'.$file) ) {
914
				// save in err-list, if failed
915
				$msg .= $file.'<br />';
916
			}
917
		}
918
		$iRemove = $iFound-$iFailed;
919
		echo '<strong>Remove '.$iRemove.' from '.$iFound.' founded</strong> ';
920
		echo ($iFailed == 0) ? $OK : $FAIL;
921
		echo '</div>';
922

    
923
		if($msg != '')
924
		{
925
			$msg = '<br /><br />Following files are deprecated, outdated or a security risk and
926
				    can not be removed automatically.<br /><br />Please delete them
927
					using FTP and restart upgrade-script!<br /><br />'.$msg.'<br />';
928
			status_msg($msg, 'error warning', 'div');
929
			echo '<p style="font-size:120%;"><strong>WARNING: The upgrade script failed ...</strong></p>';
930

    
931
			echo '<form action="'.$_SERVER['SCRIPT_NAME'].'">';
932
			echo '&nbsp;<input name="send" type="submit" value="Restart upgrade script" />';
933
			echo '</form>';
934
			echo "<br /><br /></div>
935
			</div>
936
			</div>
937
			</body>
938
			</html>";
939
			exit;
940
		}
941
	}
942

    
943

    
944
	/**********************************************************
945
	 * - check for deprecated / never needed files
946
	 */
947
	$iLoaded = sizeof($dirRemove);
948
	if($iLoaded) {
949
		echo '<h3>Step  '.(++$stepID).': Remove deprecated and outdated folders</h3>';
950
		$iFailed = 0;
951
		$iFound = 0;
952
		$searches = array(
953
			'[ADMIN]',
954
			'[MEDIA]',
955
			'[PAGES]',
956
			'[TEMPLATE]'
957
		);
958
		$replacements = array(
959
			substr(ADMIN_PATH, strlen(WB_PATH)+1),
960
			MEDIA_DIRECTORY,
961
			PAGES_DIRECTORY,
962
			'/templates',
963
		);
964
		$msg = '';
965
		echo '<div style="margin-left:2em;">';
966
		echo '<h4>Search '.$iLoaded.' deprecated and outdated folders</h4>';
967
		foreach( $dirRemove as $dir ) {
968
			$dir = str_replace($searches, $replacements, $dir);
969
			$dir = WB_PATH.'/'.$dir;
970
			if( is_dir( $dir )) {
971
				$iFound++;
972
			// try to delete dir
973
				if(!is_writable( $dir ) || !rm_full_dir($dir)) {
974
				// save in err-list, if failed
975
					$iFailed++;
976
				}
977
			}
978
			if( is_readable(WB_PATH.'/'.$dir) ) {
979
				$msg .= str_replace(WB_PATH,'',$dir).'<br />';
980
			}
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
			$msg = '<br /><br />Following directories are deprecated, outdated or a security risk and
990
					can not be removed automatically.<br /><br />Please delete them
991
					using FTP and restart upgrade-script!<br /><br />'.$msg.'<br />';
992
			status_msg($msg, 'error warning', 'div');
993
			echo '<p style="font-size:120%;"><strong>WARNING: The upgrade script failed ...</strong></p>';
994
			echo '<form action="'.$_SERVER['SCRIPT_NAME'].'">';
995
			echo '&nbsp;<input name="send" type="submit" value="Restart upgrade script" />';
996
			echo '</form>';
997
			echo "<br /><br /></div>
998
			</div>
999
			</div>
1000
			</body>
1001
			</html>";
1002
			exit;
1003
		}
1004

    
1005

    
1006
	}
1007

    
1008
	/**********************************************************
1009
	 * upgrade modules if newer version is available
1010
	 * $aModuleList list of proofed modules
1011
	 */
1012
	$aModuleList = array(
1013
	              'captcha_control','code','droplets','form','jsadmin',
1014
	              'menu_link','news','output_filter','wrapper','wysiwyg','MultiLingual');
1015
	if(sizeof($aModuleList)) 
1016
	{
1017
		echo '<h3>Step '.(++$stepID).': Upgrade proofed modules</h3>';
1018
		foreach($aModuleList as $sModul) {
1019
			if(file_exists(WB_PATH.'/modules/'.$sModul.'/upgrade.php')) {
1020
				$currModulVersion = get_modul_version ($sModul, false);
1021
				$newModulVersion =  get_modul_version ($sModul, true);
1022
				if((version_compare($currModulVersion, $newModulVersion) <= 0)) {
1023
					echo '<div style="margin-left:2em;">';
1024
					echo '<h4>'.'Upgrade module \''.$sModul.'\' version '.$newModulVersion.'</h4>';
1025
					require(WB_PATH.'/modules/'.$sModul.'/upgrade.php');
1026
					echo '</div>';
1027
				}
1028
			}
1029
		}
1030
	}
1031

    
1032
	/**********************************************************
1033
	 * Reformat/rebuild all existing moules access files
1034
	 * $aModuleList list of modules
1035
	 */
1036
	$aModuleList = array('bakery','topics','news');
1037
	if(sizeof($aModuleList)) 
1038
	{
1039
		echo '<h3>Step '.(++$stepID).': Create/Reorg Accessfiles from modules</h3>';
1040
		foreach($aModuleList as $sModul) {
1041
			$aReturnMsg = array();
1042
			$sModulReorg = 'm_'.$sModul.'_Reorg';
1043
			if(class_exists($sModulReorg)) {
1044
				$sModulVersion =  get_modul_version ($sModul, true);
1045
				echo '<div style="margin-left:2em;">';
1046
				echo '<h4>'.'Create/Reorg Accesfiles for module \''.$sModul.'\' version '.$sModulVersion.'</h4>';
1047
				$oReorg = new $sModulReorg();
1048
				$aReturnMsg = $oReorg->execute(); // show details
1049
				if(is_array($aReturnMsg)) {
1050
					foreach($aReturnMsg as $title) {
1051
					echo '<strong>'.$title.'</strong><br />';
1052
					}
1053
				}
1054
				echo '</div>';
1055
			}
1056
		}
1057
	}
1058
/**********************************************************
1059
 *  - Reload all addons
1060
 */
1061

    
1062
	echo '<h3>Step '.(++$stepID).' : Reload all addons database entry (no upgrade)</h3><br />';
1063
	echo '<div style="margin-left:2em;">';
1064
	$iFound = 0;
1065
	$iLoaded = 0;
1066
	////delete modules
1067
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'module'");
1068
	// Load all modules
1069
	if( ($handle = opendir(WB_PATH.'/modules/')) ) {
1070
		while(false !== ($file = readdir($handle))) {
1071
			if($file != '' && substr($file, 0, 1) != '.' && is_dir(WB_PATH.'/modules/'.$file) ) {
1072
				$iFound++;
1073
				$iLoaded = load_module(WB_PATH.'/modules/'.$file ) ? $iLoaded+1 : $iLoaded;
1074
// 	upgrade_module($file, true);
1075
			}
1076
		}
1077
		closedir($handle);
1078
	}
1079
	echo '<strong><span>'.$iLoaded.' Modules reloaded,</span> found '.$iFound.' directories in folder /modules/</strong><br />';
1080

    
1081
	$iFound = 0;
1082
	$iLoaded = 0;
1083
	////delete templates
1084
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'template'");
1085
	// Load all templates
1086
	if( ($handle = opendir(WB_PATH.'/templates/')) ) {
1087
		while(false !== ($file = readdir($handle))) {
1088
			if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
1089

    
1090
				$iFound++;
1091
				$iLoaded = (load_template(WB_PATH.'/templates/'.$file)==true) ? $iLoaded+1 : $iLoaded;
1092

    
1093
			}
1094
		}
1095
		closedir($handle);
1096
	}
1097
	echo '<strong><span>'.$iLoaded.' Templates reloaded,</span> found '.$iFound.' directories in folder /templates/</strong><br />';
1098

    
1099
	$iFound = 0;
1100
	$iLoaded = 0;
1101
	////delete languages
1102
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'language'");
1103
	// Load all languages
1104
	if( ($handle = opendir(WB_PATH.'/languages/')) ) {
1105
		while(false !== ($file = readdir($handle))) {
1106
			if($file != '' AND (preg_match('#^([A-Z]{2}.php)#', basename($file)))) {
1107
				$iFound++;
1108
				$iLoaded = load_language(WB_PATH.'/languages/'.$file) ? $iLoaded+1 : $iLoaded;
1109
			}
1110
		}
1111
		closedir($handle);
1112
	}
1113
	echo '<strong><span>'.$iLoaded.' Languages reloaded,</span> found '.$iFound.' files in folder /languages/</strong><br />';
1114
	echo '</div>';
1115

    
1116
/**********************************************************
1117
 *  - install new droplets
1118
	$drops = (!in_array ( "mod_droplets", $all_tables)) ? "<br />Install droplets<br />" : "<br />Upgrade droplets<br />";
1119
	echo $drops;
1120
	$file_name = (!in_array ( "mod_droplets", $all_tables) ? "install.php" : "upgrade.php");
1121
	require_once (WB_PATH."/modules/droplets/".$file_name);
1122
********************************************************** */
1123

    
1124
/**********************************************************
1125
 *  - End of upgrade script
1126
 */
1127
	if(!defined('DEFAULT_THEME')) { define('DEFAULT_THEME', $DEFAULT_THEME); }
1128
	if(!defined('THEME_PATH')) { define('THEME_PATH', WB_PATH.'/templates/'.DEFAULT_THEME);}
1129
/**********************************************************
1130
 *  - Set Version to new Version
1131
 */
1132
echo '<h3>Step '.(++$stepID).': Update database version number </h3>';
1133
echo '<div style="margin-left:2em;">';
1134

    
1135
$cfg = array(
1136
	'wb_version' => VERSION,
1137
	'wb_revision' => REVISION,
1138
	'wb_sp' => SP
1139
);
1140
echo '<br /><span><strong>Set WebsiteBaker version number to '.VERSION.' '.SP.' '.' Revision ['.REVISION.'] : </strong></span>';
1141
echo (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
1142
echo '</div>';
1143

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

    
1149
if(defined('WB_URL')) {
1150
	echo '<form action="'.WB_URL.'/">';
1151
	echo '&nbsp;<input type="submit" value="kick me to the Frontend" />';
1152
	echo '</form>';
1153
}
1154
if(defined('ADMIN_URL')) {
1155
	echo '<form action="'.ADMIN_URL.'/">';
1156
	echo '&nbsp;<input type="submit" value="kick me to the Backend" />';
1157
	echo '</form>';
1158
}
1159

    
1160
echo "<br /><br /></div>
1161
</div>
1162
</div>
1163
</body>
1164
</html>
1165
";
1166
exit();
(6-6/6)