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     Module
23
 * @package      Module_bakery
24
 * @subpackage   Name of the subpackage if needed
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: 1866 $
31
 * @link         $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/upgrade-script.php $
32
 * @lastmodified $Date: 2013-02-19 21:47:39 +0100 (Tue, 19 Feb 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
require_once(WB_PATH.'/framework/functions.php');
47
// require_once(WB_PATH.'/framework/Database.php');
48
$admin = new admin('Addons', 'modules', false, false);
49

    
50
$oldVersion  = 'Version '.WB_VERSION;
51
$oldVersion .= (defined('WB_SP') ? WB_SP : '');
52
$oldRevision = (defined('WB_REVISION') ? ' Revision ['.WB_REVISION.'] ' : '') ;
53
$newVersion  = 'Version '.VERSION;
54
$newVersion .= (defined('SP') ? SP : '');
55
$newRevision = (defined('REVISION') ? ' Revision ['.REVISION.'] ' : '');
56

    
57
$bDebugModus = false;
58

    
59
// set addition settings if not exists, otherwise upgrade will be breaks
60
if(!defined('WB_SP')) { define('WB_SP',''); }
61
if(!defined('WB_REVISION')) { define('WB_REVISION',''); }
62

    
63
// database tables including in WB package
64
$aPackage = array (
65
    'settings','groups','addons','pages','sections','search','users',
66
    'mod_captcha_control','mod_code','mod_droplets',
67
    'mod_jsadmin','mod_menu_link','mod_output_filter','mod_wrapper','mod_wysiwyg',
68
//    'mod_form_fields','mod_form_settings','mod_form_submissions',
69
//    'mod_news_comments','mod_news_groups','mod_news_posts','mod_news_settings',
70
);
71

    
72
$OK            = ' <span class="ok">OK</span> ';
73
$FAIL          = ' <span class="error">FAILED</span> ';
74
$DEFAULT_THEME = 'wb_theme';
75

    
76
$stepID = 0;
77
$aFilesToRemove = array();
78
$dirRemove = array(
79
/*
80
			'[TEMPLATE]/allcss/',
81
			'[TEMPLATE]/blank/',
82
			'[TEMPLATE]/round/',
83
			'[TEMPLATE]/simple/',
84
*/
85
			'[ADMIN]/themes/',
86
		 );
87
//
88
	$filesRemove['0'] = array(
89

    
90
			'[ADMIN]/preferences/details.php',
91
			'[ADMIN]/preferences/email.php',
92
			'[ADMIN]/preferences/password.php',
93
			'[ADMIN]/pages/settings2.php',
94
			'[ADMIN]/users/users.php',
95
			'[ADMIN]/skel/themes/htt/groups.htt',
96

    
97
			'[FRAMEWORK]/class.msg_queue.php',
98
			'[FRAMEWORK]/class.logfile.php',
99
			'[MODULES]/droplets/js/mdcr.js',
100

    
101
		 );
102
	$aFilesToRemove = array_merge($filesRemove['0']);
103

    
104
// deleting files below only from less 2.8.4 stable
105
if(version_compare(WB_REVISION, REVISION, '<='))
106
{
107
	$filesRemove['1'] = array(
108

    
109
			'[TEMPLATE]/argos_theme/templates/access.htt',
110
			'[TEMPLATE]/argos_theme/templates/addons.htt',
111
			'[TEMPLATE]/argos_theme/templates/admintools.htt',
112
			'[TEMPLATE]/argos_theme/templates/error.htt',
113
			'[TEMPLATE]/argos_theme/templates/groups.htt',
114
			'[TEMPLATE]/argos_theme/templates/groups_form.htt',
115
			'[TEMPLATE]/argos_theme/templates/languages.htt',
116
			'[TEMPLATE]/argos_theme/templates/languages_details.htt',
117
			'[TEMPLATE]/argos_theme/templates/login.htt',
118
			'[TEMPLATE]/argos_theme/templates/login_forgot.htt',
119
			'[TEMPLATE]/argos_theme/templates/media.htt',
120
			'[TEMPLATE]/argos_theme/templates/media_browse.htt',
121
			'[TEMPLATE]/argos_theme/templates/media_rename.htt',
122
			'[TEMPLATE]/argos_theme/templates/modules.htt',
123
			'[TEMPLATE]/argos_theme/templates/modules_details.htt',
124
			'[TEMPLATE]/argos_theme/templates/pages.htt',
125
			'[TEMPLATE]/argos_theme/templates/pages_modify.htt',
126
			'[TEMPLATE]/argos_theme/templates/pages_sections.htt',
127
			'[TEMPLATE]/argos_theme/templates/pages_settings.htt',
128
			'[TEMPLATE]/argos_theme/templates/preferences.htt',
129
			'[TEMPLATE]/argos_theme/templates/setparameter.htt',
130
			'[TEMPLATE]/argos_theme/templates/settings.htt',
131
			'[TEMPLATE]/argos_theme/templates/start.htt',
132
			'[TEMPLATE]/argos_theme/templates/success.htt',
133
			'[TEMPLATE]/argos_theme/templates/templates.htt',
134
			'[TEMPLATE]/argos_theme/templates/templates_details.htt',
135
			'[TEMPLATE]/argos_theme/templates/users.htt',
136
			'[TEMPLATE]/argos_theme/templates/users_form.htt',
137

    
138
			'[TEMPLATE]/wb_theme/templates/access.htt',
139
			'[TEMPLATE]/wb_theme/templates/addons.htt',
140
			'[TEMPLATE]/wb_theme/templates/admintools.htt',
141
			'[TEMPLATE]/wb_theme/templates/error.htt',
142
			'[TEMPLATE]/wb_theme/templates/groups.htt',
143
			'[TEMPLATE]/wb_theme/templates/groups_form.htt',
144
			'[TEMPLATE]/wb_theme/templates/languages.htt',
145
			'[TEMPLATE]/wb_theme/templates/languages_details.htt',
146
			'[TEMPLATE]/wb_theme/templates/login.htt',
147
			'[TEMPLATE]/wb_theme/templates/login_forgot.htt',
148
			'[TEMPLATE]/wb_theme/templates/media.htt',
149
			'[TEMPLATE]/wb_theme/templates/media_browse.htt',
150
			'[TEMPLATE]/wb_theme/templates/media_rename.htt',
151
			'[TEMPLATE]/wb_theme/templates/modules.htt',
152
			'[TEMPLATE]/wb_theme/templates/modules_details.htt',
153
			'[TEMPLATE]/wb_theme/templates/pages.htt',
154
			'[TEMPLATE]/wb_theme/templates/pages_modify.htt',
155
			'[TEMPLATE]/wb_theme/templates/pages_sections.htt',
156
			'[TEMPLATE]/wb_theme/templates/pages_settings.htt',
157
			'[TEMPLATE]/wb_theme/templates/preferences.htt',
158
			'[TEMPLATE]/wb_theme/templates/setparameter.htt',
159
			'[TEMPLATE]/wb_theme/templates/settings.htt',
160
			'[TEMPLATE]/wb_theme/templates/start.htt',
161
			'[TEMPLATE]/wb_theme/templates/success.htt',
162
			'[TEMPLATE]/wb_theme/templates/templates.htt',
163
			'[TEMPLATE]/wb_theme/templates/templates_details.htt',
164
			'[TEMPLATE]/wb_theme/templates/users.htt',
165
			'[TEMPLATE]/wb_theme/templates/users_form.htt'
166
		 );
167

    
168
	$aFilesToRemove = array_merge($aFilesToRemove,$filesRemove['1']);
169

    
170
}
171
/* display a status message on the screen **************************************
172
 * @param string $message: the message to show
173
 * @param string $class:   kind of message as a css-class
174
 * @param string $element: witch HTML-tag use to cover the message
175
 * @return void
176
 */
177
function status_msg($message, $class='check', $element='div')
178
{
179
	// returns a status message
180
	$msg  = '<'.$element.' class="'.$class.'">';
181
	$msg .= '<strong>'.strtoupper(strtok($class, ' ')).'</strong>';
182
	$msg .= $message.'</'.$element.'>';
183
	echo $msg;
184
}
185

    
186
/**
187
 * add_modify_field_in_database()
188
 *
189
 * @param mixed $sTable
190
 * @param mixed $sField
191
 * @param mixed $sDescription
192
 * @return
193
 */
194
function add_modify_field_in_database($sTable,$sField,$sDescription){
195
	global $database,$OK,$FAIL,$bDebugModus;
196
	$aDebugMessage = array();
197
	if(!$database->field_exists($sTable,$sField)) {
198
		$aDebugMessage[] = "<span>Adding field $sField to $sTable table</span>";
199
		$aDebugMessage[] = ($database->field_add($sTable, $sField, $sDescription) ? " $OK<br />" : " $FAIL!<br />");
200
	} else {
201
		$aDebugMessage[] = "<span>Modify field $sField to $sTable table</span>";
202
		$aDebugMessage[] = ($database->field_modify($sTable, $sField, $sDescription) ? " $OK<br />" : " $FAIL!<br />");
203
	}
204
	if($bDebugModus) {
205
		echo implode(PHP_EOL,$aDebugMessage);
206
	}
207
return;
208
}
209

    
210
/**
211
 * check existings tables for upgrade or install
212
 *
213
 * check_wb_tables()
214
 *
215
 * @return
216
 */
217
function check_wb_tables()
218
{
219
	global $database,$aPackage;
220

    
221
// if prefix inludes '_' or '%'
222
	$search_for = addcslashes ( TABLE_PREFIX, '%_' );
223
	$get_result = $database->query( 'SHOW TABLES LIKE "'.$search_for.'%"');
224

    
225
	// $get_result = $database->query( "SHOW TABLES FROM ".DB_NAME);
226
    $all_tables = array();
227
    $aTable = array();
228
    if($get_result->numRows() > 0)
229
    {
230
        while ($data = $get_result->fetchRow()) {
231
            $tmp = preg_replace('/^'.preg_quote(TABLE_PREFIX, '/').'/s', '', $data[0]);
232
            if(in_array($tmp,$aPackage)) {
233
                $all_tables[] = $tmp;
234
            } else {
235
                $aTable[] = $tmp;
236
            }
237
        }
238
    }
239

    
240
    return array_merge ( $all_tables, $aTable );
241
}
242

    
243
// check existing tables
244
$all_tables = check_wb_tables();
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/wb_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/wb_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('<strong>Warning:</strong><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 '<br /><br />';
348
		echo "</div>
349
		</div>
350
		</div>
351
		</body>
352
		</html>
353
		";
354
		exit();
355
	}
356

    
357
?>
358
<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>
359

    
360
<?php
361
/**
362
 * Check if disclaimer was accepted
363
 */
364
$bDebugModus = false;
365
$bDebugModus = ( (isset($_POST['debug_confirmed']) && $_POST['debug_confirmed'] == 'debug') ? true : false);
366
if (!(isset($_POST['backup_confirmed']) && $_POST['backup_confirmed'] == 'confirmed')) { ?>
367
<h2>Step 1: Backup your files</h2>
368
<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>
369
<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>
370

    
371
<form action="<?php echo $_SERVER['SCRIPT_NAME'];?>" method="post">
372
<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>
373
<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>
374
<br /><br /><input name="debug_confirmed" type="checkbox" value="debug" />&nbsp;<strong>Here you can get more details during running upgrade.</strong>
375
<br /><br /><input name="send" type="submit" value="Start upgrade script" />
376
</form>
377
<br />
378

    
379
<?php
380
	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');
381
	echo "<br /><br /></div>
382
	</div>
383
	</div>
384
	</body>
385
	</html>";
386
	exit();
387
}
388

    
389
// check again all tables, to get a new array
390
// if(sizeof($all_tables) < sizeof($aTable)) { $all_tables = check_wb_tables(); }
391
/**********************************************************
392
 *  - check tables coming with WebsiteBaker
393
 */
394
    $check_text = 'total ';
395
    // $check_tables = mysqlCheckTables( DB_NAME ) ;
396
    $aTable = array();
397
    foreach ($all_tables as $data) {
398
        $tmp = str_replace(TABLE_PREFIX, '', $data);
399
        if(in_array($tmp,$aPackage)) {
400
            $aTable[] = $tmp;
401
        }
402
    }
403

    
404
    if( (sizeof($all_tables) >= sizeof($aPackage)) && (sizeof($aTable) == sizeof($aPackage)) )
405
    {
406
        echo '<h4 style="margin-left:0;">NOTICE: Your database '.DB_NAME.' has '.sizeof($all_tables).' '.$check_text.' tables from '.sizeof($aPackage).' included in package '.$OK.'</h4>';
407
    }
408
    else
409
    {
410
        status_msg('<strong>:</strong><br />can\'t run Upgrade, missing tables', 'warning', 'div');
411
        echo '<h4>Missing required tables. You can install them in backend->addons->modules.<br />';
412
        echo 'Or if you uploaded per FTP install possible by backend->addons->modules->advanced.<br />';
413
        echo 'First rename or delete the upgrade-script.php, so the script can\'t start automatically by backend<br />';
414
        echo 'After installing missing tables upload and run again upgrade-script.php</h4>';
415
        $result = array_diff ( $aPackage, $aTable );
416

    
417
        echo '<h4 class="warning"><br />';
418
        while ( list ( $key, $val ) = each ( $result ) )
419
        {
420
            echo 'TABLE ´'.TABLE_PREFIX.$val.'´ '.$FAIL.'<br>';
421
        }
422

    
423
        echo '<br /></h4>';
424
        echo '<br /><br />';
425
        if(isset($_SERVER['SCRIPT_NAME'])) {
426
        	echo '<form action="'.$_SERVER['SCRIPT_NAME'].'/">';
427
        	echo '&nbsp;<input type="submit" value="Start upgrade again" />';
428
        	echo '</form>';
429
        }
430
        if(defined('ADMIN_URL')) {
431
        	echo '<form action="'.ADMIN_URL.'/index.php" method="post">';
432
        	echo '&nbsp;<input name="backend_send" type="submit" value="kick me to the Backend" />';
433
        	echo '</form>';
434
        }
435
        echo "<br /><br /></div>
436
        </div>
437
        </div>
438
        </body>
439
        </html>";
440

    
441
        exit();
442
    }
443

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

    
455
if($bDebugModus) {
456
    echo implode(PHP_EOL,$aDebugMessage);
457
}
458
$aDebugMessage = array();
459
echo'<h3>Step '.(++$stepID).': Updating tables included in package</h3>';
460
    /**********************************************************
461
     *  - Adding field sec_anchor to settings table
462
     */
463
    echo '<div style="margin-left:2em;">';
464
    echo "<h4>Adding/updating entries on table settings</h4>";
465
    $aDebugMessage[] = "<span>Adding/updating sec_anchor to settings table</span>";
466
    $cfg = array(
467
    	'sec_anchor' => defined('SEC_ANCHOR') ? SEC_ANCHOR : 'section_'
468
    );
469
   $aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
470

    
471
    /**********************************************************
472
     *  - Adding redirect timer to settings table
473
     */
474
    $aDebugMessage[] = "<span>Adding/updating redirect timer to settings table</span>";
475
    $cfg = array(
476
    	'redirect_timer' => defined('REDIRECT_TIMER') ? REDIRECT_TIMER : '1500'
477
    );
478
    $aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
479

    
480
    /**********************************************************
481
     *  - Adding rename_files_on_upload to settings table
482
     */
483
    $aDebugMessage[] = "<span>Adding/Updating rename_files_on_upload to settings table</span>";
484
    $cfg = array(
485
    	'rename_files_on_upload' => (defined('RENAME_FILES_ON_UPLOAD') ? RENAME_FILES_ON_UPLOAD : 'ph.*?,cgi,pl,pm,exe,com,bat,pif,cmd,src,asp,aspx,js')
486
    );
487
    $aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
488

    
489
    /**********************************************************
490
     *  - Adding mediasettings to settings table
491
     */
492
    $aDebugMessage[] = "<span>Adding/updating mediasettings to settings table</span>";
493
    $cfg = array(
494
    	'mediasettings' => (defined('MEDIASETTINGS') ? MEDIASETTINGS : ''),
495
    );
496

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

    
499
    /**********************************************************
500
     *  - Adding fingerprint_with_ip_octets to settings table
501
     */
502
    $aDebugMessage[] = "<span>Adding/updating fingerprint_with_ip_octets to settings table</span>";
503
    $cfg = array(
504
    	'fingerprint_with_ip_octets' => (defined('FINGERPRINT_WITH_IP_OCTETS') ? FINGERPRINT_WITH_IP_OCTETS : '2'),
505
    	'secure_form_module' => (defined('SECURE_FORM_MODULE') ? SECURE_FORM_MODULE : '')
506
    );
507

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

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

    
518
    $aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
519
    /**********************************************************
520
     *  - Adding page_extended to settings table
521
     */
522
    $aDebugMessage[] = "<span>Adding/updating page_extendet to settings table</span>";
523
    $cfg = array(
524
    	'page_extendet' => (defined('PAGE_EXTENDET') ? PAGE_EXTENDET : 'true'),
525
    );
526

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

    
529
    /**********************************************************
530
     *  - Adding wbmail_signature to settings table
531
     */
532
    $aDebugMessage[] = "<span>Adding/updating wbmail_signature to settings table</span>";
533
    $cfg = array(
534
    	'wbmail_signature' => (defined('WBMAIL_SIGNATURE') ? WBMAIL_SIGNATURE : '')
535
    );
536

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

    
539
    /**********************************************************
540
     *  - Adding confirmed_registration to settings table
541
     */
542
    $aDebugMessage[] = "<span>Adding/updating confirmed_registration to settings table</span>";
543
    $cfg = array(
544
    	'confirmed_registration' => (defined('CONFIRMED_REGISTRATION') ? CONFIRMED_REGISTRATION : '0')
545
    );
546

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

    
549
    /**********************************************************
550
     *  - Adding dev_infos to settings table
551
     */
552
    $aDebugMessage[] = "<span>Adding/updating dev_infos to settings table</span>";
553
    $cfg = array(
554
    	'dev_infos' => (defined('DEV_INFOS') ? DEV_INFOS : 'false')
555
    );
556

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

    
559
if($bDebugModus) {
560
    echo implode(PHP_EOL,$aDebugMessage);
561
}
562
echo '</div>';
563

    
564
$aDebugMessage = array();
565
if(version_compare(WB_REVISION, REVISION, '<='))
566
{
567
    echo '<div style="margin-left:2em;">';
568
	/**********************************************************
569
	 *  - Update search no results database filed to create
570
	 *  valid XHTML if search is empty
571
	 */
572
	if (version_compare(WB_VERSION, '2.8', '<'))
573
	{
574
        echo "<h4>Adding/updating fields on table search</h4>";
575
	    echo "Updating database field `no_results` on search table: ";
576
	    $search_no_results = addslashes('<tr><td><p>[TEXT_NO_RESULTS]</p></td></tr>');
577
	    $sql  = 'UPDATE `'.TABLE_PREFIX.'search` ';
578
		$sql .= 'SET `value`=\''.$search_no_results.'\' ';
579
		$sql .= 'WHERE `name`=\'no_results\'';
580
	    echo ($database->query($sql)) ? " $OK<br />" : " $FAIL!<br />";
581
	}
582

    
583
    echo "<h4>Adding/updating field on table mod_menu_link</h4>";
584
	/**********************************************************
585
     *  - Add field "redirect_type" to table "mod_menu_link"
586
     *  has to be moved later to upgrade.php in modul menu_link, because modul can be removed
587
     */
588
	$table_name = TABLE_PREFIX.'mod_menu_link';
589
	$field_name = 'redirect_type';
590
	$description = "INT NOT NULL DEFAULT '301' AFTER `target_page_id`";
591
    add_modify_field_in_database($table_name,$field_name,$description);
592

    
593
    if($bDebugModus) {
594
        echo implode(PHP_EOL,$aDebugMessage);
595
    }
596

    
597
    $aDebugMessage = array();
598
    echo "<h4>Adding/updating field on table pages</h4>";
599
	/**********************************************************
600
	 *  - Add field "page_trail" to table "pages"
601
	 */
602
	$table_name = TABLE_PREFIX.'pages';
603
	$field_name = 'page_trail';
604
	$description = "VARCHAR( 255 ) NOT NULL DEFAULT ''";
605
    add_modify_field_in_database($table_name,$field_name,$description);
606

    
607
	/**********************************************************
608
     *  - Add field "page_icon" to table "pages"
609
     */
610
	$table_name = TABLE_PREFIX.'pages';
611
	$field_name = 'page_icon';
612
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '' AFTER `page_title`";
613
    add_modify_field_in_database($table_name,$field_name,$description);
614

    
615
	/**********************************************************
616
	 *  - Add field "page_code" to table "pages"
617
	 */
618
	$table_name = TABLE_PREFIX.'pages';
619
	$field_name = 'page_code';
620
	$description = "INT NOT NULL DEFAULT '0' AFTER `language`";
621
    add_modify_field_in_database($table_name,$field_name,$description);
622

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

    
631
	/**********************************************************
632
	 *  - Add field "menu_icon_1" to table "pages"
633
     */
634
	$table_name = TABLE_PREFIX.'pages';
635
	$field_name = 'menu_icon_1';
636
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '' AFTER `menu_icon_0`";
637
    add_modify_field_in_database($table_name,$field_name,$description);
638

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

    
647
	/**********************************************************
648
	 *  - Add field "admin_groups" to table "pages"
649
     */
650
	$table_name = TABLE_PREFIX.'pages';
651
	$field_name = 'admin_groups';
652
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '1'";
653
    add_modify_field_in_database($table_name,$field_name,$description);
654

    
655
	/**********************************************************
656
	 *  - Add field "admin_users" to table "pages"
657
	 */
658
	$table_name = TABLE_PREFIX.'pages';
659
	$field_name = 'admin_users';
660
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT ''";
661
    add_modify_field_in_database($table_name,$field_name,$description);
662

    
663
	/**********************************************************
664
	 *  - Add field "viewing_groups" to table "pages"
665
	 */
666
	$table_name = TABLE_PREFIX.'pages';
667
	$field_name = 'viewing_groups';
668
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '1'";
669
//	echo "<span>Modify field viewing_groups to pages table</span>";
670
//	echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
671
    add_modify_field_in_database($table_name,$field_name,$description);
672

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

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

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

    
697
    if($bDebugModus) {
698
        echo implode(PHP_EOL,$aDebugMessage);
699
    }
700

    
701
	$aDebugMessage = array();
702
	/**********************************************************
703
     * modify wrong strucre on table sections
704
     * wrong structure let crash wb
705
     */
706
	echo "<h4>Change field structure on table sections</h4>";
707
	$table_name = TABLE_PREFIX.'sections';
708
	$description = "VARCHAR( 255 ) NOT NULL DEFAULT ''";
709
	$aDebugMessage[] = "<span>Modify field module on sections table</span>";
710
	$aDebugMessage[] = ($database->field_modify($table_name, 'module', $description) ? " $OK<br />" : " $FAIL!<br />");
711
	$aDebugMessage[] = "<span>Modify field block on sections table</span>";
712
	$aDebugMessage[] = ($database->field_modify($table_name, 'block', $description) ? " $OK<br />" : " $FAIL!<br />");
713
	$aDebugMessage[] = "<span>Modify field publ_start on sections table</span>";
714
	$aDebugMessage[] = ($database->field_modify($table_name, 'publ_start', $description) ? " $OK<br />" : " $FAIL!<br />");
715
	$aDebugMessage[] = "<span>Modify field publ_end on sections table</span>";
716
	$aDebugMessage[] = ($database->field_modify($table_name, 'publ_end', $description) ? " $OK<br />" : " $FAIL!<br />");
717

    
718
    if($bDebugModus) {
719
        echo implode(PHP_EOL,$aDebugMessage);
720
    }
721

    
722
	$aDebugMessage = array();
723
	/**********************************************************
724
     *   `confirm_code` VARCHAR(32) NOT NULL DEFAULT '',
725
     *   `confirm_timeout` INT(11) NOT NULL DEFAULT '0',
726
     */
727
	echo "<h4>Change field structure on table users</h4>";
728
	$table_name = TABLE_PREFIX.'users';
729
	$field_name = 'confirm_code';
730
	$description = "VARCHAR( 32 ) NOT NULL DEFAULT '' AFTER `password` ";
731
    add_modify_field_in_database($table_name,$field_name,$description);
732

    
733
	$table_name = TABLE_PREFIX.'users';
734
	$field_name = 'confirm_timeout';
735
	$description = "INT(11) NOT NULL DEFAULT '0' AFTER `confirm_code` ";
736
    add_modify_field_in_database($table_name,$field_name,$description);
737

    
738
    if($bDebugModus) {
739
        echo implode(PHP_EOL,$aDebugMessage);
740
    }
741

    
742
    $aDebugMessage = array();
743
	/**********************************************************
744
     * Modify Administrator on groups table
745
     */
746
	echo "<h4>Update group Administrator on table groups</h4>";
747
	$aDebugMessage[] = "<span>Modify Administrator on groups table</span>";
748
	$sModulePermissions = '';
749
	$sTemplatePermissions = '';
750
	$sSystemPermissions  = 'access,addons,admintools,admintools_view,groups,groups_add,groups_delete,groups_modify,groups_view,';
751
	$sSystemPermissions .= 'languages,languages_install,languages_uninstall,languages_view,media,media_create,media_delete,media_rename,media_upload,media_view,';
752
	$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,';
753
	$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';
754

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

    
766
    if($bDebugModus) {
767
        echo implode(PHP_EOL,$aDebugMessage);
768
    }
769
    echo '</div>';
770

    
771
}
772

    
773
if(version_compare(WB_REVISION, '1800', '<'))
774
{
775
    $aDebugMessage = array();
776
    /**********************************************************
777
     * This part with changing in mod_wysiwyg will be removed in the final version
778
     * special workout for the tester
779
     *  - Remove/add PRIMARY KEY from/to "section_id" from table "mod_wysiwygs"
780
     */
781
    $aDebugMessage[] = '<div style="margin-left:2em;">';
782

    
783
    $sTable = TABLE_PREFIX.'mod_wysiwyg';
784
    $field_name = 'wysiwyg_id';
785
    if($database->field_exists($sTable, 'wysiwyg_id')) {
786
        if($database->index_exists($sTable, 'PRIMARY')) {
787
            $aDebugMessage[] = "<span>Remove PRIMARY KEY from table mod_wysiwyg.wysiwyg_id</span>";
788
            $aDebugMessage[] = $database->index_remove($sTable, 'PRIMARY') ? " $OK<br />" : " $FAIL!<br />";
789
        }
790
        $aDebugMessage[] = "<span>Remove field 'wysiwyg_id' from table mod_wysiwyg</span>";
791
        $aDebugMessage[] = $database->field_remove($sTable, 'wysiwyg_id') ? " $OK<br />" : " $FAIL!<br />";
792
    }
793

    
794
    $aDebugMessage[] = "<br /><span>Create PRIMARY KEY ( `section_id` ) on table mod_wysiwygs.</span>";
795
    $aDebugMessage[] = $database->index_add($sTable, '', 'section_id', 'PRIMARY') ? " $OK<br />" : " $FAIL!<br />";
796
    $aDebugMessage[] = '</div>';
797

    
798
    if($bDebugModus) {
799
    // $aDebugMessage[] =
800
        echo implode(PHP_EOL,$aDebugMessage);
801
    }
802
}
803

    
804
if(version_compare(WB_REVISION, REVISION, '<='))
805
{
806
    $aDebugMessage = array();
807
    echo '<h3>Step '.(++$stepID).': Updating group_id in table users</h3>';
808
    /**********************************************************
809
    * Updating group_id in table users
810
    */
811
        echo '<div style="margin-left:2em;">';
812
        $aUsers = array();
813
		// Get existing values
814
        $sql  = 'SELECT * FROM `'.TABLE_PREFIX.'users` ' ;
815
        $sql .= 'WHERE `user_id` != 1 ';
816
        if($oUser = $database->query($sql)){
817
            $iTotalUsers = $oUser->numRows();
818
            while($Users = $oUser->fetchRow(MYSQL_ASSOC)) {
819

    
820
                $aUsers[$Users['user_id']]['groups_id'] = $Users['groups_id'];
821
                $aUsers[$Users['user_id']]['display_name'] = $Users['display_name'];
822
            }
823
        } else {
824
            $aDebugMessage[] = $database->is_error()==false ? " $OK<br />" : " $FAIL!<br />";
825
        }
826

    
827
        foreach($aUsers AS $user_id => $value){
828
                // choose group_id from groups_id - workaround for still remaining calls to group_id (to be cleaned-up)
829
                $aGroups_id = explode(',', $aUsers[$user_id]['groups_id']);
830
                $groups_id = $aUsers[$user_id]['groups_id'];
831
                $group_id = 0;
832
                //if user is in administrator-group, get this group else just get the first one
833
                if($admin->is_group_match($aGroups_id,'1')) { $group_id = 1; $groups_id = '1'; } else { $group_id = intval($aGroups_id[0]); }
834

    
835
                $sMessage = "<span>Updating group_id ".$TEXT['DISPLAY_NAME']." " .$aUsers[$user_id]['display_name']."</span>";
836
                $sql  = 'UPDATE `'.TABLE_PREFIX.'users` ';
837
                $sql .= 'SET `group_id`  = '.$group_id.', ';
838
                $sql .=     '`groups_id` = \''.$groups_id.'\' ';
839
                $sql .= 'WHERE `user_id` = '.intval($user_id);
840

    
841
                if($oRes = $database->query($sql)){  }
842
                $aDebugMessage[] = $database->is_error()==false ? $sMessage." $OK<br />" : $sMessage." $FAIL!<br />";
843
        }
844
        unset($aUsers);
845

    
846
    $aDebugMessage[] = '</div>';
847

    
848
    if($bDebugModus) {
849
    // $aDebugMessage[] =
850
        echo implode(PHP_EOL,$aDebugMessage);
851
    }else {
852
        echo '<span><strong>'.$iTotalUsers.' users updating the group_id</strong></span>'." $OK<br />";
853
        echo '</div>';
854
    }
855
}
856

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

    
860
echo '<div style="margin-left:2em;">';
861
    /**********************************************************
862
    * upgrade media directory index protect files
863
    */
864
    $dir = (WB_PATH.MEDIA_DIRECTORY);
865
    echo '<h4>Upgrade media directory '.MEDIA_DIRECTORY.'/ index.php protect files</h4>';
866
    $aDebugMessage = rebuildFolderProtectFile($dir);
867
    if( sizeof( $aDebugMessage ) ){
868
    	echo '<span><strong>Upgrade '.sizeof( $aDebugMessage ).' directory '.MEDIA_DIRECTORY.'/ protect files</strong></span>'." $OK<br />";
869
    } else {
870
    	echo '<span><strong>Upgrade directory '.MEDIA_DIRECTORY.'/ protect files</strong></span>'." $FAIL!<br />";
871
    	echo implode ('<br />',$aDebugMessage);
872
    }
873

    
874
    $aDebugMessage = array();
875
    /**********************************************************
876
     * upgrade pages directory index access files
877
     */
878
	echo '<h4>Upgrade pages directory '.PAGES_DIRECTORY.'/  protect and access files</h4>';
879

    
880
    /**********************************************************
881
     *  - Reformat/rebuild all existing access files
882
     */
883
    $sPagePath = (defined('PAGES_DIRECTORY') && (PAGES_DIRECTORY != '') ? PAGES_DIRECTORY : '');
884
    $msg = rebuild_all_accessfiles();
885

    
886
	echo '<strong>'.implode ('<br />',$msg).'</strong>';
887
    echo '</div>';
888

    
889
    /* *****************************************************************************
890
     * - check for deprecated / never needed files
891
     */
892
    if(sizeof($aFilesToRemove)) {
893
    	echo '<h3>Step '.(++$stepID).': Remove deprecated and old files</h3>';
894
    	$searches = array(
895
    		'[ADMIN]',
896
    		'[MEDIA]',
897
    		'[PAGES]',
898
    		'[FRAMEWORK]',
899
    		'[MODULES]',
900
    		'[TEMPLATE]'
901
    	);
902
    	$replacements = array(
903
    		'/'.substr(ADMIN_PATH, strlen(WB_PATH)+1),
904
    		MEDIA_DIRECTORY,
905
    		PAGES_DIRECTORY,
906
    		'/framework',
907
    		'/modules',
908
    		'/templates'
909
    	);
910

    
911
		$msg = '';
912
    	foreach( $aFilesToRemove as $file )
913
    	{
914
			$file = str_replace($searches, $replacements, $file);
915
			if( is_writable(WB_PATH.'/'.$file) ) {
916
				// try to unlink file
917
				if(!unlink(WB_PATH.$file)) {
918
					// save in err-list, if failed
919
				}
920
			}
921
            if( is_readable(WB_PATH.'/'.$file) ) {
922
                $msg .= $file.'<br />';
923
            }
924
    	}
925

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

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

    
946

    
947
/**********************************************************
948
 * - check for deprecated / never needed files
949
 */
950
	if(sizeof($dirRemove)) {
951
		echo '<h3>Step  '.(++$stepID).': Remove deprecated and old folders</h3>';
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
		foreach( $dirRemove as $dir ) {
966
			$dir = str_replace($searches, $replacements, $dir);
967
			$dir = WB_PATH.'/'.$dir;
968
			if( is_dir( $dir )) {
969
			// try to delete dir
970
				if(!is_writable( $dir ) || !rm_full_dir($dir)) {
971
				// save in err-list, if failed
972
                    if( is_readable(WB_PATH.'/'.$file) ) {
973
                    	$msg .= str_replace(WB_PATH,'',$dir).'<br />';
974
                    }
975
				}
976
			}
977
		}
978

    
979
		if($msg != '') {
980
			$msg = '<br /><br />Following directories 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
			echo '<form action="'.$_SERVER['SCRIPT_NAME'].'">';
986
			echo '&nbsp;<input name="send" type="submit" value="Restart upgrade script" />';
987
			echo '</form>';
988
			echo "<br /><br /></div>
989
			</div>
990
			</div>
991
			</body>
992
			</html>";
993
			exit;
994
		}
995
	}
996

    
997
    /**********************************************************
998
     * upgrade modules if newer version is available
999
     * $aModuleList list of proofed modules
1000
     */
1001
    $aModuleList = array('news','wysiwyg','form');
1002
	if(sizeof($aModuleList)) 
1003
	{
1004
	    echo '<h3>Step '.(++$stepID).': Upgrade proofed modules</h3>';
1005
		foreach($aModuleList as $sModul) {
1006
			if(file_exists(WB_PATH.'/modules/'.$sModul.'/upgrade.php')) {
1007
				$currModulVersion = get_modul_version ($sModul, false);
1008
				$newModulVersion =  get_modul_version ($sModul, true);
1009
				if((version_compare($currModulVersion, $newModulVersion) <= 0)) {
1010
	                echo '<div style="margin-left:2em;">';
1011
					echo '<h4>'.'Upgrade module \''.$sModul.'\' version '.$newModulVersion.'</h4>';
1012
					require(WB_PATH.'/modules/'.$sModul.'/upgrade.php');
1013
	                echo '</div>';
1014
				}
1015
			}
1016
		}
1017
	}
1018

    
1019
    /**********************************************************
1020
     * Reformat/rebuild all existing moules access files
1021
     * $aModuleList list of modules
1022
     */
1023
    $aModuleList = array('bakery','topics','news');
1024
	if(sizeof($aModuleList)) 
1025
	{
1026
		echo '<h3>Step '.(++$stepID).': Create/Reorg Accessfiles from modules</h3>';
1027
		foreach($aModuleList as $sModul) {
1028
			$aReturnMsg = array();
1029
			$sModulReorg = 'm_'.$sModul.'_Reorg';
1030
			if(class_exists($sModulReorg)) {
1031
				$sModulVersion =  get_modul_version ($sModul, true);
1032
				echo '<div style="margin-left:2em;">';
1033
				echo '<h4>'.'Create/Reorg Accesfiles for module \''.$sModul.'\' version '.$sModulVersion.'</h4>';
1034
				$oReorg = new $sModulReorg();
1035
				$aReturnMsg = $oReorg->execute(); // show details
1036
				if($bDebugModus && is_array($aReturnMsg)) {
1037
					foreach($aReturnMsg as $title) {
1038
					echo '<strong>'.$title.'</strong><br />';
1039
					}
1040
				}
1041
				echo '</div>';
1042
			}
1043
		}
1044
	}
1045
/**********************************************************
1046
 *  - Reload all addons
1047
 */
1048

    
1049
	echo '<h3>Step '.(++$stepID).' : Reload all addons database entry (no upgrade)</h3><br />';
1050
    echo '<div style="margin-left:2em;">';
1051
    $iFound = 0;
1052
    $iLoaded = 0;
1053
	////delete modules
1054
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'module'");
1055
	// Load all modules
1056
	if( ($handle = opendir(WB_PATH.'/modules/')) ) {
1057
		while(false !== ($file = readdir($handle))) {
1058
			if($file != '' && substr($file, 0, 1) != '.' && is_dir(WB_PATH.'/modules/'.$file) ) {
1059
                $iFound++;
1060
				$iLoaded = load_module(WB_PATH.'/modules/'.$file ) ? $iLoaded+1 : $iLoaded;
1061
			   // 	upgrade_module($file, true);
1062
			}
1063
		}
1064
		closedir($handle);
1065
	}
1066
	echo '<strong><span>'.$iLoaded.' Modules reloaded,</span> found '.$iFound.' directories in folder /modules/</strong><br />';
1067

    
1068
    $iFound = 0;
1069
    $iLoaded = 0;
1070
	////delete templates
1071
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'template'");
1072
	// Load all templates
1073
	if( ($handle = opendir(WB_PATH.'/templates/')) ) {
1074
		while(false !== ($file = readdir($handle))) {
1075
			if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
1076

    
1077
                $iFound++;
1078
				$iLoaded = (load_template(WB_PATH.'/templates/'.$file)==true) ? $iLoaded+1 : $iLoaded;
1079

    
1080
			}
1081
		}
1082
		closedir($handle);
1083
	}
1084
	echo '<strong><span>'.$iLoaded.' Templates reloaded,</span> found '.$iFound.' directories in folder /templates/</strong><br />';
1085

    
1086
    $iFound = 0;
1087
    $iLoaded = 0;
1088
	////delete languages
1089
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'language'");
1090
	// Load all languages
1091
	if( ($handle = opendir(WB_PATH.'/languages/')) ) {
1092
		while(false !== ($file = readdir($handle))) {
1093
			if($file != '' AND (preg_match('#^([A-Z]{2}.php)#', basename($file)))) {
1094
                $iFound++;
1095
				$iLoaded = load_language(WB_PATH.'/languages/'.$file) ? $iLoaded+1 : $iLoaded;
1096
			}
1097
		}
1098
		closedir($handle);
1099
	}
1100
	echo '<strong><span>'.$iLoaded.' Languages reloaded,</span> found '.$iFound.' files in folder /languages/</strong><br />';
1101
    echo '</div>';
1102

    
1103
/**********************************************************
1104
 *  - install new droplets
1105
	$drops = (!in_array ( "mod_droplets", $all_tables)) ? "<br />Install droplets<br />" : "<br />Upgrade droplets<br />";
1106
	echo $drops;
1107
	$file_name = (!in_array ( "mod_droplets", $all_tables) ? "install.php" : "upgrade.php");
1108
	require_once (WB_PATH."/modules/droplets/".$file_name);
1109
********************************************************** */
1110

    
1111
/**********************************************************
1112
 *  - End of upgrade script
1113
 */
1114
	if(!defined('DEFAULT_THEME')) { define('DEFAULT_THEME', $DEFAULT_THEME); }
1115
	if(!defined('THEME_PATH')) { define('THEME_PATH', WB_PATH.'/templates/'.DEFAULT_THEME);}
1116
/**********************************************************
1117
 *  - Set Version to new Version
1118
 */
1119
echo '<h3>Step '.(++$stepID).': Update database version number </h3>';
1120
echo '<div style="margin-left:2em;">';
1121

    
1122
$cfg = array(
1123
	'wb_version' => VERSION,
1124
	'wb_revision' => REVISION,
1125
	'wb_sp' => SP
1126
);
1127
echo '<br /><span><strong>Set database version number to '.VERSION.' '.SP.' '.' Revision ['.REVISION.'] : </strong></span>';
1128
echo (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
1129
echo '</div>';
1130

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

    
1136
if(defined('WB_URL')) {
1137
	echo '<form action="'.WB_URL.'/">';
1138
	echo '&nbsp;<input type="submit" value="kick me to the Frontend" />';
1139
	echo '</form>';
1140
}
1141
if(defined('ADMIN_URL')) {
1142
	echo '<form action="'.ADMIN_URL.'/">';
1143
	echo '&nbsp;<input type="submit" value="kick me to the Backend" />';
1144
	echo '</form>';
1145
}
1146

    
1147
echo "<br /><br /></div>
1148
</div>
1149
</div>
1150
</body>
1151
</html>
1152
";
1153
exit();
(5-5/5)