Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        backend
5
 * @package         installation
6
 * @author          WebsiteBaker Project
7
 * @copyright       2009-2012, WebsiteBaker Org. e.V.
8
 * @link            http://www.websitebaker2.org/
9
 * @license         http://www.gnu.org/licenses/gpl.html
10
 * @platform        WebsiteBaker 2.8.x
11
 * @requirements    PHP 5.2.2 and higher
12
 * @version         $Id: upgrade-script.php 1813 2012-11-10 20:27:32Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/upgrade-script.php $
14
 * @lastmodified    $Date: 2012-11-10 21:27:32 +0100 (Sat, 10 Nov 2012) $
15
 *
16
 */
17

    
18
// Include config file
19
$config_file = realpath('config.php');
20
if(file_exists($config_file) && !defined('WB_URL'))
21
{
22
	require($config_file);
23
}
24

    
25
//require_once(WB_PATH.'/framework/class.admin.php');
26
if(!class_exists('admin', false)){ include(WB_PATH.'/framework/class.admin.php'); }
27
require_once(WB_PATH.'/framework/functions.php');
28
// require_once(WB_PATH.'/framework/Database.php');
29
$admin = new admin('Addons', 'modules', false, false);
30

    
31
$oldVersion  = 'Version '.WB_VERSION;
32
$oldVersion .= (defined('WB_SP') ? WB_SP : '');
33
$oldRevision = (defined('WB_REVISION') ? ' Revision ['.WB_REVISION.'] ' : '') ;
34
$newVersion  = 'Version '.VERSION;
35
$newVersion .= (defined('SP') ? SP : '');
36
$newRevision = (defined('REVISION') ? ' Revision ['.REVISION.'] ' : '');
37

    
38
$bDebugModus = false;
39

    
40
// set addition settings if not exists, otherwise upgrade will be breaks
41
if(!defined('WB_SP')) { define('WB_SP',''); }
42
if(!defined('WB_REVISION')) { define('WB_REVISION',''); }
43

    
44
// database tables including in WB package
45
$aPackage = array (
46
    'settings','groups','addons','pages','sections','search','users',
47
    'mod_captcha_control','mod_code','mod_droplets','mod_form_fields',
48
    'mod_form_settings','mod_form_submissions','mod_jsadmin','mod_menu_link',
49
    'mod_news_comments','mod_news_groups','mod_news_posts','mod_news_settings',
50
    'mod_output_filter','mod_wrapper','mod_wysiwyg'
51
);
52

    
53
$OK            = ' <span class="ok">OK</span> ';
54
$FAIL          = ' <span class="error">FAILED</span> ';
55
$DEFAULT_THEME = 'wb_theme';
56

    
57
$stepID = 0;
58
$aFilesToRemove = array();
59
$dirRemove = array(
60
/*
61
			'[TEMPLATE]/allcss/',
62
			'[TEMPLATE]/blank/',
63
			'[TEMPLATE]/round/',
64
			'[TEMPLATE]/simple/',
65
*/
66
			'[ADMIN]/themes/',
67
		 );
68

    
69
if(version_compare(WB_REVISION, VERSION, '<='))
70
{
71
    $filesRemove['0'] = array(
72

    
73
			'[ADMIN]/preferences/details.php',
74
			'[ADMIN]/preferences/email.php',
75
			'[ADMIN]/preferences/password.php',
76
			'[ADMIN]/pages/settings2.php',
77
			'[ADMIN]/users/users.php',
78

    
79
			'[FRAMEWORK]/class.msg_queue.php',
80
			'[FRAMEWORK]/class.logfile.php',
81
			'[MODULES]/droplets/js/mdcr.js',
82

    
83
		 );
84

    
85
	$filesRemove['1'] = array(
86

    
87
			'[TEMPLATE]/argos_theme/templates/access.htt',
88
			'[TEMPLATE]/argos_theme/templates/addons.htt',
89
			'[TEMPLATE]/argos_theme/templates/admintools.htt',
90
			'[TEMPLATE]/argos_theme/templates/error.htt',
91
			'[TEMPLATE]/argos_theme/templates/groups.htt',
92
			'[TEMPLATE]/argos_theme/templates/groups_form.htt',
93
			'[TEMPLATE]/argos_theme/templates/languages.htt',
94
			'[TEMPLATE]/argos_theme/templates/languages_details.htt',
95
	/*
96
			'[TEMPLATE]/argos_theme/templates/login.htt',
97
			'[TEMPLATE]/argos_theme/templates/login_forgot.htt',
98
	*/
99
			'[TEMPLATE]/argos_theme/templates/media.htt',
100
			'[TEMPLATE]/argos_theme/templates/media_browse.htt',
101
			'[TEMPLATE]/argos_theme/templates/media_rename.htt',
102
			'[TEMPLATE]/argos_theme/templates/modules.htt',
103
			'[TEMPLATE]/argos_theme/templates/modules_details.htt',
104
			'[TEMPLATE]/argos_theme/templates/pages.htt',
105
			'[TEMPLATE]/argos_theme/templates/pages_modify.htt',
106
			'[TEMPLATE]/argos_theme/templates/pages_sections.htt',
107
			'[TEMPLATE]/argos_theme/templates/pages_settings.htt',
108
			'[TEMPLATE]/argos_theme/templates/preferences.htt',
109
			'[TEMPLATE]/argos_theme/templates/setparameter.htt',
110
			'[TEMPLATE]/argos_theme/templates/settings.htt',
111
			'[TEMPLATE]/argos_theme/templates/start.htt',
112
			'[TEMPLATE]/argos_theme/templates/success.htt',
113
			'[TEMPLATE]/argos_theme/templates/templates.htt',
114
			'[TEMPLATE]/argos_theme/templates/templates_details.htt',
115
			'[TEMPLATE]/argos_theme/templates/users.htt',
116
			'[TEMPLATE]/argos_theme/templates/users_form.htt',
117

    
118
			'[TEMPLATE]/wb_theme/templates/access.htt',
119
			'[TEMPLATE]/wb_theme/templates/addons.htt',
120
			'[TEMPLATE]/wb_theme/templates/admintools.htt',
121
			'[TEMPLATE]/wb_theme/templates/error.htt',
122
			'[TEMPLATE]/wb_theme/templates/groups.htt',
123
			'[TEMPLATE]/wb_theme/templates/groups_form.htt',
124
			'[TEMPLATE]/wb_theme/templates/languages.htt',
125
			'[TEMPLATE]/wb_theme/templates/languages_details.htt',
126

    
127
	/*
128
			'[TEMPLATE]/wb_theme/templates/login.htt',
129
			'[TEMPLATE]/wb_theme/templates/login_forgot.htt',
130
	*/
131

    
132
			'[TEMPLATE]/wb_theme/templates/media.htt',
133
			'[TEMPLATE]/wb_theme/templates/media_browse.htt',
134
			'[TEMPLATE]/wb_theme/templates/media_rename.htt',
135
			'[TEMPLATE]/wb_theme/templates/modules.htt',
136
			'[TEMPLATE]/wb_theme/templates/modules_details.htt',
137
			'[TEMPLATE]/wb_theme/templates/pages.htt',
138
			'[TEMPLATE]/wb_theme/templates/pages_modify.htt',
139
			'[TEMPLATE]/wb_theme/templates/pages_sections.htt',
140
			'[TEMPLATE]/wb_theme/templates/pages_settings.htt',
141
			'[TEMPLATE]/wb_theme/templates/preferences.htt',
142
			'[TEMPLATE]/wb_theme/templates/setparameter.htt',
143
			'[TEMPLATE]/wb_theme/templates/settings.htt',
144
			'[TEMPLATE]/wb_theme/templates/start.htt',
145
			'[TEMPLATE]/wb_theme/templates/success.htt',
146
			'[TEMPLATE]/wb_theme/templates/templates.htt',
147
			'[TEMPLATE]/wb_theme/templates/templates_details.htt',
148
			'[TEMPLATE]/wb_theme/templates/users.htt',
149
			'[TEMPLATE]/wb_theme/templates/users_form.htt',
150
		 );
151

    
152
    $aFilesToRemove = array_merge($filesRemove['0'],$filesRemove['1']);
153

    
154
}
155

    
156
/* display a status message on the screen **************************************
157
 * @param string $message: the message to show
158
 * @param string $class:   kind of message as a css-class
159
 * @param string $element: witch HTML-tag use to cover the message
160
 * @return void
161
 */
162
function status_msg($message, $class='check', $element='div')
163
{
164
	// returns a status message
165
	$msg  = '<'.$element.' class="'.$class.'">';
166
	$msg .= '<strong>'.strtoupper(strtok($class, ' ')).'</strong>';
167
	$msg .= $message.'</'.$element.'>';
168
	echo $msg;
169
}
170

    
171
/**
172
 * add_modify_field_in_database()
173
 *
174
 * @param mixed $sTable
175
 * @param mixed $sField
176
 * @param mixed $sDescription
177
 * @return
178
 */
179
function add_modify_field_in_database($sTable,$sField,$sDescription){
180
    global $database,$OK,$FAIL,$bDebugModus;
181
    $aDebugMessage = array();
182
	if(!$database->field_exists($sTable,$sField)) {
183
		$aDebugMessage[] = "<span>Adding field $sField to $sTable table</span>";
184
		$aDebugMessage[] = ($database->field_add($sTable, $sField, $sDescription) ? " $OK<br />" : " $FAIL!<br />");
185
	} else {
186
		$aDebugMessage[] = "<span>Modify field $sField to $sTable table</span>";
187
		$aDebugMessage[] = ($database->field_modify($sTable, $sField, $sDescription) ? " $OK<br />" : " $FAIL!<br />");
188
	}
189
    if($bDebugModus) {
190
        echo implode(PHP_EOL,$aDebugMessage);
191
    }
192
    return;
193
}
194

    
195
/**
196
 * check existings tables for upgrade or install
197
 *
198
 * check_wb_tables()
199
 *
200
 * @return
201
 */
202
function check_wb_tables()
203
{
204
    global $database,$aPackage;
205

    
206
// if prefix inludes '_' or '%'
207
    $search_for = addcslashes ( TABLE_PREFIX, '%_' );
208
    $get_result = $database->query( 'SHOW TABLES LIKE "'.$search_for.'%"');
209

    
210
    // $get_result = $database->query( "SHOW TABLES FROM ".DB_NAME);
211
    $all_tables = array();
212
    $aTable = array();
213
    if($get_result->numRows() > 0)
214
    {
215
        while ($data = $get_result->fetchRow()) {
216
            $tmp = str_replace(TABLE_PREFIX, '', $data[0]);
217
            if(in_array($tmp,$aPackage)) {
218
                $all_tables[] = $tmp;
219
            } else {
220
                $aTable[] = $tmp;
221
            }
222
        }
223
    }
224

    
225
    return array_merge ( $all_tables, $aTable );
226
}
227

    
228
// check existing tables
229
$all_tables = check_wb_tables();
230

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

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

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

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

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

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

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

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

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

    
321
</style>
322
</head>
323
<body>
324
<div id="container">
325
<div class="page">
326
<img src="templates/wb_theme/images/logo.png" alt="WebsiteBaker Project" />
327
<div class="content">
328
<h1>WebsiteBaker Upgrade</h1>
329
<?php
330
	if( version_compare( WB_VERSION, '2.7', '<' )) {
331
		status_msg('<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');
332
		echo '<br /><br />';
333
		echo "</div>
334
        </div>
335
        </div>
336
		</body>
337
		</html>
338
		";
339
		exit();
340
	}
341

    
342
?>
343
<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>
344

    
345
<?php
346
/**
347
 * Check if disclaimer was accepted
348
 */
349
$bDebugModus = false;
350
$bDebugModus = ( (isset($_POST['debug_confirmed']) && $_POST['debug_confirmed'] == 'debug') ? true : false);
351
if (!(isset($_POST['backup_confirmed']) && $_POST['backup_confirmed'] == 'confirmed')) { ?>
352
<h2>Step 1: Backup your files</h2>
353
<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>
354
<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>
355

    
356
<form name="send" action="<?php echo $_SERVER['SCRIPT_NAME'];?>" method="post">
357
<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>
358
<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>
359
<br /><br /><input name="debug_confirmed" type="checkbox" value="debug" />&nbsp;<strong>Here you can get more details during running upgrade.</strong>
360
<br /><br /><input name="send" type="submit" value="Start upgrade script" />
361
</form>
362
<br />
363

    
364
<?php
365
	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');
366
	echo '<br /><br />';
367
    echo "</div>
368
    </div>
369
    </div>
370
    </body>
371
    </html>
372
    ";
373
	exit();
374
}
375

    
376
// check again all tables, to get a new array
377
// if(sizeof($all_tables) < sizeof($aTable)) { $all_tables = check_wb_tables(); }
378
/**********************************************************
379
 *  - check tables coming with WebsiteBaker
380
 */
381
    $check_text = 'total ';
382
    // $check_tables = mysqlCheckTables( DB_NAME ) ;
383
    $aTable = array();
384
    foreach ($all_tables as $data) {
385
        $tmp = str_replace(TABLE_PREFIX, '', $data);
386
        if(in_array($tmp,$aPackage)) {
387
            $aTable[] = $tmp;
388
        }
389
    }
390

    
391
    if( (sizeof($all_tables) >= sizeof($aPackage)) && (sizeof($aTable) == sizeof($aPackage)) )
392
    {
393
        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>';
394
    }
395
    else
396
    {
397
        status_msg('<strong>:</strong><br />can\'t run Upgrade, missing tables', 'warning', 'div');
398
        echo '<h4>Missing required tables. You can install them in backend->addons->modules.<br />';
399
        echo 'Or if you uploaded per FTP install possible by backend->addons->modules->advanced.<br />';
400
        echo 'After installing missing tables again run upgrade-script.php</h4>';
401
        $result = array_diff ( $aPackage, $aTable );
402

    
403
        echo '<h4 class="warning"><br />';
404
        while ( list ( $key, $val ) = each ( $result ) )
405
        {
406
            echo 'TABLE ´'.TABLE_PREFIX.$val.'´ '.$FAIL.'<br>';
407
        }
408

    
409
        echo '<br /></h4>';
410
        echo '<br /><br />';
411
        if(isset($_SERVER['SCRIPT_NAME'])) {
412
        	echo '<form action="'.$_SERVER['SCRIPT_NAME'].'/">';
413
        	echo '&nbsp;<input type="submit" value="Start upgrade again" />';
414
        	echo '</form>';
415
        }
416
        if(defined('ADMIN_URL')) {
417
        	echo '<form action="'.ADMIN_URL.'/">';
418
        	echo '&nbsp;<input type="submit" value="kick me to the Backend" />';
419
        	echo '</form>';
420
        }
421

    
422
        echo "<br /><br /></div>
423
        </div>
424
        </div>
425
        </body>
426
        </html>
427
        ";
428

    
429
        exit();
430
    }
431

    
432
echo '<h3>Step '.(++$stepID).': Setting default_theme</h3>';
433
$aDebugMessage = array();
434
    /**********************************************************
435
     *  - Adding field default_theme to settings table
436
     */
437
    $aDebugMessage[] = '<div style="margin-left:2em;">';
438
    $aDebugMessage[] = "<br /><span><strong>Adding default_theme to settings table</strong></span>";
439
    // db_update_key_value('settings', 'default_theme', $DEFAULT_THEME);
440
    $aDebugMessage[] = (db_update_key_value( 'settings', 'default_theme', $DEFAULT_THEME ) ? " $OK<br />" : " $FAIL!<br />");
441
    $aDebugMessage[] = '</div>';
442

    
443
if($bDebugModus) {
444
    echo implode(PHP_EOL,$aDebugMessage);
445
}
446
$aDebugMessage = array();
447
echo'<h3>Step '.(++$stepID).': Updating core tables</h3>';
448
    /**********************************************************
449
     *  - Adding field sec_anchor to settings table
450
     */
451
    echo '<div style="margin-left:2em;">';
452
    echo "<h4>Adding/updating entries on table settings</h4>";
453
    $aDebugMessage[] = "<span>Adding/updating sec_anchor to settings table</span>";
454
    $cfg = array(
455
    	'sec_anchor' => defined('SEC_ANCHOR') ? SEC_ANCHOR : 'section_'
456
    );
457
   $aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
458

    
459
    /**********************************************************
460
     *  - Adding redirect timer to settings table
461
     */
462
    $aDebugMessage[] = "<span>Adding/updating redirect timer to settings table</span>";
463
    $cfg = array(
464
    	'redirect_timer' => defined('REDIRECT_TIMER') ? REDIRECT_TIMER : '1500'
465
    );
466
    $aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
467

    
468
    /**********************************************************
469
     *  - Adding rename_files_on_upload to settings table
470
     */
471
    $aDebugMessage[] = "<span>Adding/Updating rename_files_on_upload to settings table</span>";
472
    $cfg = array(
473
    	'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')
474
    );
475
    $aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
476

    
477
    /**********************************************************
478
     *  - Adding mediasettings to settings table
479
     */
480
    $aDebugMessage[] = "<span>Adding/updating mediasettings to settings table</span>";
481
    $cfg = array(
482
    	'mediasettings' => (defined('MEDIASETTINGS') ? MEDIASETTINGS : ''),
483
    );
484

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

    
487
    /**********************************************************
488
     *  - Adding fingerprint_with_ip_octets to settings table
489
     */
490
    $aDebugMessage[] = "<span>Adding/updating fingerprint_with_ip_octets to settings table</span>";
491
    $cfg = array(
492
    	'fingerprint_with_ip_octets' => (defined('FINGERPRINT_WITH_IP_OCTETS') ? FINGERPRINT_WITH_IP_OCTETS : '2'),
493
    	'secure_form_module' => (defined('SECURE_FORM_MODULE') ? SECURE_FORM_MODULE : '')
494
    );
495

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

    
498
    /**********************************************************
499
     *  - Adding page_icon_dir to settings table
500
     */
501
    $aDebugMessage[] = "<span>Adding/updating page_icon_dir to settings table</span>";
502
    $cfg = array(
503
    	'page_icon_dir' => (defined('PAGE_ICON_DIR') ? PAGE_ICON_DIR : '/templates/*/title_images'),
504
    );
505

    
506
    $aDebugMessage[] = (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
507
    /**********************************************************
508
     *  - Adding page_extended to settings table
509
     */
510
    $aDebugMessage[] = "<span>Adding/updating page_extended to settings table</span>";
511
    $cfg = array(
512
    	'page_extended' => (defined('PAGE_EXTENDED') ? PAGE_EXTENDED : 'true'),
513
    );
514

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

    
517
    /**********************************************************
518
     *  - Adding website_signature to settings table
519
     */
520
    $aDebugMessage[] = "<span>Adding/updating website_signature to settings table</span>";
521
    $cfg = array(
522
    	'website_signature' => (defined('WEBSITE_SIGNATURE') && (WEBSITE_SIGNATURE=='') ? '' : WEBSITE_SIGNATURE)
523
    );
524

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

    
527
    /**********************************************************
528
     *  - Adding confirmed_registration to settings table
529
     */
530
    $aDebugMessage[] = "<span>Adding/updating confirmed_registration to settings table</span>";
531
    $cfg = array(
532
    	'confirmed_registration' => (defined('CONFIRMED_REGISTRATION') && (CONFIRMED_REGISTRATION=='') ? '' : CONFIRMED_REGISTRATION)
533
    );
534

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

    
537
    /**********************************************************
538
     *  - Adding dev_infos to settings table
539
     */
540
    $aDebugMessage[] = "<span>Adding/updating dev_infos to settings table</span>";
541
    $cfg = array(
542
    	'dev_infos' => (defined('DEV_INFOS') ? DEV_INFOS : 'false')
543
    );
544

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

    
547
    /**********************************************************
548
     *  - Adding dev_infos to settings table
549
     */
550
    $aDebugMessage[] = "<span>Adding/updating modules_upgrade_list to settings table</span>";
551
    $cfg = array(
552
    	'modules_upgrade_list' => (defined('MODULES_UPGRADE_LIST') ? MODULES_UPGRADE_LIST : 'news')
553
    );
554

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

    
557

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
771
}
772

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

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

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

    
796
if($bDebugModus) {
797
// $aDebugMessage[] =
798
    echo implode(PHP_EOL,$aDebugMessage);
799
}
800
$aDebugMessage = array();
801
echo '<h3>Step '.(++$stepID).': Updating group_id in table users</h3>';
802
    /**********************************************************
803
    * Updating group_id in table users
804
    */
805

    
806
        echo '<div style="margin-left:2em;">';
807
        $aUsers = array();
808
		// Get existing values
809
        $sql  = 'SELECT * FROM `'.TABLE_PREFIX.'users` ' ;
810
        $sql .= 'WHERE `user_id` != 1 ';
811
        if($oUser = $database->query($sql)){
812
            $iTotalUsers = $oUser->numRows();
813
            while($Users = $oUser->fetchRow(MYSQL_ASSOC)) {
814

    
815
                $aUsers[$Users['user_id']]['groups_id'] = $Users['groups_id'];
816
                $aUsers[$Users['user_id']]['display_name'] = $Users['display_name'];
817
            }
818
        } else {
819
            $aDebugMessage[] = $database->is_error()==false ? " $OK<br />" : " $FAIL!<br />";
820
        }
821

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

    
830
                $sMessage = "<span>Updating group_id ".$TEXT['DISPLAY_NAME']." " .$aUsers[$user_id]['display_name']."</span>";
831
                $sql  = 'UPDATE `'.TABLE_PREFIX.'users` ';
832
                $sql .= 'SET `group_id` = '.$group_id.' ';
833
                $sql .= 'WHERE `user_id` = '.intval($user_id);
834

    
835
                if($oRes = $database->query($sql)){  }
836
                $aDebugMessage[] = $database->is_error()==false ? $sMessage." $OK<br />" : $sMessage." $FAIL!<br />";
837
        }
838
        unset($aUsers);
839

    
840
    $aDebugMessage[] = '</div>';
841

    
842
if($bDebugModus) {
843
// $aDebugMessage[] =
844
    echo implode(PHP_EOL,$aDebugMessage);
845
}else {
846
    echo '<span><strong>'.$iTotalUsers.' users updating the group_id</strong></span>'." $OK<br />";
847
    echo '</div>';
848
}
849

    
850
$aDebugMessage = array();
851
echo '<h3>Step '.(++$stepID).': Updating acess and protected files in folders</h3>';
852

    
853
echo '<div style="margin-left:2em;">';
854
    /**********************************************************
855
    * upgrade media directory index protect files
856
    */
857
    $dir = (WB_PATH.MEDIA_DIRECTORY);
858
    echo '<h4>Upgrade media directory '.MEDIA_DIRECTORY.'/ index.php protect files</h4>';
859
    $array = rebuildFolderProtectFile($dir);
860
    if( sizeof( $array ) ){
861
    	echo '<span><strong>Upgrade '.sizeof( $array ).' directory '.MEDIA_DIRECTORY.'/ protect files</strong></span>'." $OK<br />";
862
    } else {
863
    	echo '<span><strong>Upgrade directory '.MEDIA_DIRECTORY.'/ protect files</strong></span>'." $FAIL!<br />";
864
    	echo implode ('<br />',$array);
865
    }
866

    
867
    /**********************************************************
868
     * upgrade pages directory index access files
869
     */
870
	echo '<h4>Upgrade pages directory '.PAGES_DIRECTORY.'/  protect and access files</h4>';
871

    
872
    /**********************************************************
873
     *  - Reformat/rebuild all existing access files
874
     */
875
    $sPagePath = (defined('PAGES_DIRECTORY') && (PAGES_DIRECTORY != '') ? PAGES_DIRECTORY : '');
876
    $msg = rebuild_all_accessfiles();
877

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

    
902
		$msg = '';
903
    	foreach( $aFilesToRemove as $file )
904
    	{
905
			$file = str_replace($searches, $replacements, $file);
906
			if( is_writable(WB_PATH.'/'.$file) ) {
907
				// try to unlink file
908
				if(!unlink(WB_PATH.$file)) {
909
					// save in err-list, if failed
910
				}
911
			}
912
            if( is_readable(WB_PATH.'/'.$file) ) {
913
                $msg .= $file.'<br />';
914
            }
915
    	}
916

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

    
925
			echo '<form action="'.$_SERVER['SCRIPT_NAME'].'">';
926
			echo '&nbsp;<input name="send" type="submit" value="Restart upgrade script" />';
927
			echo '</form>';
928
            echo "<br /><br /></div>
929
            </div>
930
            </div>
931
            </body>
932
            </html>
933
            ";
934
			exit;
935
		}
936
    }
937

    
938

    
939
/**********************************************************
940
 * - check for deprecated / never needed files
941
 */
942
	if(sizeof($dirRemove)) {
943
		echo '<h3>Step  '.(++$stepID).': Remove deprecated and old folders</h3>';
944
		$searches = array(
945
			'[ADMIN]',
946
			'[MEDIA]',
947
			'[PAGES]',
948
			'[TEMPLATE]'
949
		);
950
		$replacements = array(
951
			substr(ADMIN_PATH, strlen(WB_PATH)+1),
952
			MEDIA_DIRECTORY,
953
			PAGES_DIRECTORY,
954
			'/templates',
955
		);
956
		$msg = '';
957
		foreach( $dirRemove as $dir ) {
958
			$dir = str_replace($searches, $replacements, $dir);
959
			$dir = WB_PATH.'/'.$dir;
960
			if( is_dir( $dir )) {
961
			// try to delete dir
962
				if(!is_writable( $dir ) || !rm_full_dir($dir)) {
963
				// save in err-list, if failed
964
                    if( is_readable(WB_PATH.'/'.$file) ) {
965
                    	$msg .= str_replace(WB_PATH,'',$dir).'<br />';
966
                    }
967
				}
968
			}
969
		}
970

    
971
		if($msg != '') {
972
			$msg = '<br /><br />Following directories are deprecated, outdated or a security risk and
973
					can not be removed automatically.<br /><br />Please delete them
974
					using FTP and restart upgrade-script!<br /><br />'.$msg.'<br />';
975
			status_msg($msg, 'error warning', 'div');
976
			echo '<p style="font-size:120%;"><strong>WARNING: The upgrade script failed ...</strong></p>';
977
			echo '<form action="'.$_SERVER['SCRIPT_NAME'].'">';
978
			echo '&nbsp;<input name="send" type="submit" value="Restart upgrade script" />';
979
			echo '</form>';
980
            echo "<br /><br /></div>
981
            </div>
982
            </div>
983
            </body>
984
            </html>
985
            ";
986
			exit;
987
		}
988
	}
989

    
990
    /**********************************************************
991
     * upgrade modules if newer version is available
992
     * $aModuleList list of proofed modules
993
     */
994
    $sModuleList = 'news,wysiwyg,form';
995
    $aModuleList = explode(',', (defined('MODULES_UPGRADE_LIST') ? MODULES_UPGRADE_LIST : $sModuleList));
996
    echo '<h3>Step '.(++$stepID).': Upgrade proofed modules</h3>';
997
//	$aModuleList = array('news');
998
	foreach($aModuleList as $sModul) {
999
		if(file_exists(WB_PATH.'/modules/'.$sModul.'/upgrade.php')) {
1000
			$currModulVersion = get_modul_version ($sModul, false);
1001
			$newModulVersion =  get_modul_version ($sModul, true);
1002
			if((version_compare($currModulVersion, $newModulVersion) <= 0)) {
1003
                echo '<div style="margin-left:2em;">';
1004
				echo '<h4>'.'Upgrade module \''.$sModul.'\' version '.$newModulVersion.'</h4>';
1005
				require_once(WB_PATH.'/modules/'.$sModul.'/upgrade.php');
1006
                echo '</div>';
1007
			}
1008
		}
1009
	}
1010

    
1011
/**********************************************************
1012
 *  - Reload all addons
1013
 */
1014

    
1015
	echo '<h3>Step '.(++$stepID).' : Reload all addons database entry (no upgrade)</h3><br />';
1016
    echo '<div style="margin-left:2em;">';
1017
    $iFound = 0;
1018
    $iLoaded = 0;
1019
	////delete modules
1020
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'module'");
1021
	// Load all modules
1022
	if( ($handle = opendir(WB_PATH.'/modules/')) ) {
1023
		while(false !== ($file = readdir($handle))) {
1024
			if($file != '' && substr($file, 0, 1) != '.' && is_dir(WB_PATH.'/modules/'.$file) ) {
1025
                $iFound++;
1026
				$iLoaded = load_module(WB_PATH.'/modules/'.$file ) ? $iLoaded+1 : $iLoaded;
1027
			   // 	upgrade_module($file, true);
1028
			}
1029
		}
1030
		closedir($handle);
1031
	}
1032
	echo '<span><strong>'.$iLoaded.' Modules reloaded,</span> found '.$iFound.' directories in folder /modules/</strong><br />';
1033

    
1034
    $iFound = 0;
1035
    $iLoaded = 0;
1036
	////delete templates
1037
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'template'");
1038
	// Load all templates
1039
	if( ($handle = opendir(WB_PATH.'/templates/')) ) {
1040
		while(false !== ($file = readdir($handle))) {
1041
			if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
1042

    
1043
                $iFound++;
1044
				$iLoaded = (load_template(WB_PATH.'/templates/'.$file)==true) ? $iLoaded+1 : $iLoaded;
1045

    
1046
			}
1047
		}
1048
		closedir($handle);
1049
	}
1050
	echo '<span><strong>'.$iLoaded.' Templates reloaded,</span> found '.$iFound.' directories in folder /templates/</strong><br />';
1051

    
1052
    $iFound = 0;
1053
    $iLoaded = 0;
1054
	////delete languages
1055
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'language'");
1056
	// Load all languages
1057
	if( ($handle = opendir(WB_PATH.'/languages/')) ) {
1058
		while(false !== ($file = readdir($handle))) {
1059
			if($file != '' AND (preg_match('#^([A-Z]{2}.php)#', basename($file)))) {
1060
                $iFound++;
1061
				$iLoaded = load_language(WB_PATH.'/languages/'.$file) ? $iLoaded+1 : $iLoaded;
1062
			}
1063
		}
1064
		closedir($handle);
1065
	}
1066
	echo '<span><strong>'.$iLoaded.' Languages reloaded,</span> found '.$iFound.' files in folder /languages/</strong><br />';
1067
    echo '</div>';
1068

    
1069
/**********************************************************
1070
 *  - install new droplets
1071
	$drops = (!in_array ( "mod_droplets", $all_tables)) ? "<br />Install droplets<br />" : "<br />Upgrade droplets<br />";
1072
	echo $drops;
1073
	$file_name = (!in_array ( "mod_droplets", $all_tables) ? "install.php" : "upgrade.php");
1074
	require_once (WB_PATH."/modules/droplets/".$file_name);
1075
********************************************************** */
1076

    
1077
/**********************************************************
1078
 *  - End of upgrade script
1079
 */
1080
	if(!defined('DEFAULT_THEME')) { define('DEFAULT_THEME', $DEFAULT_THEME); }
1081
	if(!defined('THEME_PATH')) { define('THEME_PATH', WB_PATH.'/templates/'.DEFAULT_THEME);}
1082
/**********************************************************
1083
 *  - Set Version to new Version
1084
 */
1085
echo '<h3>Step '.(++$stepID).': Update database version number </h3>';
1086
echo '<div style="margin-left:2em;">';
1087

    
1088
$cfg = array(
1089
	'wb_version' => VERSION,
1090
	'wb_revision' => REVISION,
1091
	'wb_sp' => SP
1092
);
1093
echo '<br /><span><strong>Set database version number to '.VERSION.' '.SP.' '.' Revision ['.REVISION.'] : </strong></span>';
1094
echo (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
1095
echo '</div>';
1096

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

    
1102
if(defined('WB_URL')) {
1103
	echo '<form action="'.WB_URL.'/">';
1104
	echo '&nbsp;<input type="submit" value="kick me to the Frontend" />';
1105
	echo '</form>';
1106
}
1107
if(defined('ADMIN_URL')) {
1108
	echo '<form action="'.ADMIN_URL.'/">';
1109
	echo '&nbsp;<input type="submit" value="kick me to the Backend" />';
1110
	echo '</form>';
1111
}
1112

    
1113
echo "<br /><br /></div>
1114
</div>
1115
</div>
1116
</body>
1117
</html>
1118
";
1119
exit();
(5-5/5)