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 1785 2012-10-12 14:08:01Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/upgrade-script.php $
14
 * @lastmodified    $Date: 2012-10-12 16:08:01 +0200 (Fri, 12 Oct 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_once($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, '1785', '<'))
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

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

    
82
		 );
83

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

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

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

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

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

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

    
153
}
154

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
428
        exit();
429
    }
430

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
556

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
741
}
742

    
743
$aDebugMessage = array();
744
/**********************************************************
745
 * This part with changing in mod_wysiwyg will be removed in the final version
746
 * special workout for the tester
747
 *  - Remove/add PRIMARY KEY from/to "section_id" from table "mod_wysiwygs"
748
 */
749
    $aDebugMessage[] = '<div style="margin-left:2em;">';
750

    
751
    $sTable = TABLE_PREFIX.'mod_wysiwyg';
752
    $field_name = 'wysiwyg_id';
753
    if($database->field_exists($sTable, 'wysiwyg_id')) {
754
        if($database->index_exists($sTable, 'PRIMARY')) {
755
            $aDebugMessage[] = "<span>Remove PRIMARY KEY from table mod_wysiwyg.wysiwyg_id</span>";
756
            $aDebugMessage[] = $database->index_remove($sTable, 'PRIMARY') ? " $OK<br />" : " $FAIL!<br />";
757
        }
758
        $aDebugMessage[] = "<span>Remove field 'wysiwyg_id' from table mod_wysiwyg</span>";
759
        $aDebugMessage[] = $database->field_remove($sTable, 'wysiwyg_id') ? " $OK<br />" : " $FAIL!<br />";
760
    }
761

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

    
766
if($bDebugModus) {
767
// $aDebugMessage[] =
768
    echo implode(PHP_EOL,$aDebugMessage);
769
}
770
$aDebugMessage = array();
771

    
772
echo '<h3>Step '.(++$stepID).': Updating acess and protected files in folders</h3>';
773

    
774
echo '<div style="margin-left:2em;">';
775
    /**********************************************************
776
    * upgrade media directory index protect files
777
    */
778
    $dir = (WB_PATH.MEDIA_DIRECTORY);
779
    echo '<h4>Upgrade media directory '.MEDIA_DIRECTORY.'/ index.php protect files</h4>';
780
    $array = rebuildFolderProtectFile($dir);
781
    if( sizeof( $array ) ){
782
    	print '<span><strong>Upgrade '.sizeof( $array ).' directory '.MEDIA_DIRECTORY.'/ protect files</strong></span>'." $OK<br />";
783
    } else {
784
    	print '<span><strong>Upgrade directory '.MEDIA_DIRECTORY.'/ protect files</strong></span>'." $FAIL!<br />";
785
    	print implode ('<br />',$array);
786
    }
787

    
788
    /**********************************************************
789
     * upgrade pages directory index access files
790
     */
791
	echo '<h4>Upgrade pages directory '.PAGES_DIRECTORY.'/  protect and access files</h4>';
792

    
793
    /**********************************************************
794
     *  - Reformat/rebuild all existing access files
795
     */
796
    $sPagePath = (defined('PAGES_DIRECTORY') && (PAGES_DIRECTORY != '') ? PAGES_DIRECTORY : '');
797
    $msg = rebuild_all_accessfiles();
798

    
799
	print implode ('<br />',$msg);
800
    echo '</div>';
801
    /* *****************************************************************************
802
     * - check for deprecated / never needed files
803
     */
804
    if(sizeof($aFilesToRemove)) {
805
    	echo '<h3>Step '.(++$stepID).': Remove deprecated and old files</h3>';
806
    	$searches = array(
807
    		'[ADMIN]',
808
    		'[MEDIA]',
809
    		'[PAGES]',
810
    		'[FRAMEWORK]',
811
    		'[MODULES]',
812
    		'[TEMPLATE]'
813
    	);
814
    	$replacements = array(
815
    		'/'.substr(ADMIN_PATH, strlen(WB_PATH)+1),
816
    		MEDIA_DIRECTORY,
817
    		PAGES_DIRECTORY,
818
    		'/framework',
819
    		'/modules',
820
    		'/templates'
821
    	);
822

    
823
		$msg = '';
824
    	foreach( $aFilesToRemove as $file )
825
    	{
826
			$file = str_replace($searches, $replacements, $file);
827
			if( is_writable(WB_PATH.'/'.$file) ) {
828
				// try to unlink file
829
				if(!unlink(WB_PATH.$file)) {
830
					// save in err-list, if failed
831
					$msg .= $file.'<br />';
832
				} else {
833
					$msg .= $file.'<br />';
834
    			}
835
			}
836
    	}
837

    
838
		if($msg != '')
839
		{
840
			$msg = '<br /><br />Following files are deprecated, outdated or a security risk and
841
				    can not be removed automatically.<br /><br />Please delete them
842
					using FTP and restart upgrade-script!<br /><br />'.$msg.'<br />';
843
	        status_msg($msg, 'error warning', 'div');
844
			echo '<p style="font-size:120%;"><strong>WARNING: The upgrade script failed ...</strong></p>';
845

    
846
			echo '<form action="'.$_SERVER['SCRIPT_NAME'].'">';
847
			echo '&nbsp;<input name="send" type="submit" value="Restart upgrade script" />';
848
			echo '</form>';
849
            echo "<br /><br /></div>
850
            </div>
851
            </div>
852
            </body>
853
            </html>
854
            ";
855
			exit;
856
		}
857
    }
858

    
859

    
860
/**********************************************************
861
 * - check for deprecated / never needed files
862
 */
863
	if(sizeof($dirRemove)) {
864
		echo '<h3>Step  '.(++$stepID).': Remove deprecated and old folders</h3>';
865
		$searches = array(
866
			'[ADMIN]',
867
			'[MEDIA]',
868
			'[PAGES]',
869
			'[TEMPLATE]'
870
		);
871
		$replacements = array(
872
			substr(ADMIN_PATH, strlen(WB_PATH)+1),
873
			MEDIA_DIRECTORY,
874
			PAGES_DIRECTORY,
875
			'/templates',
876
		);
877
		$msg = '';
878
		foreach( $dirRemove as $dir ) {
879
			$dir = str_replace($searches, $replacements, $dir);
880
			$dir = WB_PATH.'/'.$dir;
881
			if( is_dir( $dir )) {
882
			// try to delete dir
883
				if(!is_writable( $dir ) || !rm_full_dir($dir)) {
884
				// save in err-list, if failed
885
					$msg .= str_replace(WB_PATH,'',$dir).'<br />';
886
				}
887
			}
888
		}
889

    
890
		if($msg != '') {
891
			$msg = '<br /><br />Following directories are deprecated, outdated or a security risk and
892
					can not be removed automatically.<br /><br />Please delete them
893
					using FTP and restart upgrade-script!<br /><br />'.$msg.'<br />';
894
			status_msg($msg, 'error warning', 'div');
895
			echo '<p style="font-size:120%;"><strong>WARNING: The upgrade script failed ...</strong></p>';
896
			echo '<form action="'.$_SERVER['SCRIPT_NAME'].'">';
897
			echo '&nbsp;<input name="send" type="submit" value="Restart upgrade script" />';
898
			echo '</form>';
899
            echo "<br /><br /></div>
900
            </div>
901
            </div>
902
            </body>
903
            </html>
904
            ";
905
			exit;
906
		}
907
	}
908

    
909
    /**********************************************************
910
     * upgrade modules if newer version is available
911
     * $aModuleList list of proofed modules
912
     */
913
    $sModuleList = 'news,wysiwyg,form,any';
914
    $aModuleList = explode(',', (defined('MODULES_UPGRADE_LIST') ? MODULES_UPGRADE_LIST : $sModuleList));
915
    echo '<h3>Step '.(++$stepID).': Upgrade proofed modules</h3>';
916
//	$aModuleList = array('news');
917
	foreach($aModuleList as $sModul) {
918
		if(file_exists(WB_PATH.'/modules/'.$sModul.'/upgrade.php')) {
919
			$currModulVersion = get_modul_version ($sModul, false);
920
			$newModulVersion =  get_modul_version ($sModul, true);
921
			if((version_compare($currModulVersion, $newModulVersion) <= 0)) {
922
                echo '<div style="margin-left:2em;">';
923
				echo '<h4>'.'Upgrade module \''.$sModul.'\' version '.$newModulVersion.'</h4>';
924
				require_once(WB_PATH.'/modules/'.$sModul.'/upgrade.php');
925
                echo '</div>';
926
			}
927
		}
928
	}
929

    
930
/**********************************************************
931
 *  - Reload all addons
932
 */
933

    
934
	echo '<h3>Step '.(++$stepID).' : Reload all addons database entry (no upgrade)</h3><br />';
935
    echo '<div style="margin-left:2em;">';
936
    $iFound = 0;
937
    $iLoaded = 0;
938
	////delete modules
939
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'module'");
940
	// Load all modules
941
	if( ($handle = opendir(WB_PATH.'/modules/')) ) {
942
		while(false !== ($file = readdir($handle))) {
943
			if($file != '' && substr($file, 0, 1) != '.' && is_dir(WB_PATH.'/modules/'.$file) ) {
944
                $iFound++;
945
				$iLoaded = load_module(WB_PATH.'/modules/'.$file ) ? $iLoaded+1 : $iLoaded;
946
			   // 	upgrade_module($file, true);
947
			}
948
		}
949
		closedir($handle);
950
	}
951
	echo '<span><strong>'.$iLoaded.' Modules reloaded,</span> found '.$iFound.' directories in folder /modules/</strong><br />';
952

    
953
    $iFound = 0;
954
    $iLoaded = 0;
955
	////delete templates
956
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'template'");
957
	// Load all templates
958
	if( ($handle = opendir(WB_PATH.'/templates/')) ) {
959
		while(false !== ($file = readdir($handle))) {
960
			if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
961

    
962
                $iFound++;
963
				$iLoaded = (load_template(WB_PATH.'/templates/'.$file)==true) ? $iLoaded+1 : $iLoaded;
964

    
965
			}
966
		}
967
		closedir($handle);
968
	}
969
	echo '<span><strong>'.$iLoaded.' Templates reloaded,</span> found '.$iFound.' directories in folder /templates/</strong><br />';
970

    
971
    $iFound = 0;
972
    $iLoaded = 0;
973
	////delete languages
974
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'language'");
975
	// Load all languages
976
	if( ($handle = opendir(WB_PATH.'/languages/')) ) {
977
		while(false !== ($file = readdir($handle))) {
978
			if($file != '' AND (preg_match('#^([A-Z]{2}.php)#', basename($file)))) {
979
                $iFound++;
980
				$iLoaded = load_language(WB_PATH.'/languages/'.$file) ? $iLoaded+1 : $iLoaded;
981
			}
982
		}
983
		closedir($handle);
984
	}
985
	echo '<span><strong>'.$iLoaded.' Languages reloaded,</span> found '.$iFound.' files in folder /languages/</strong><br />';
986
    echo '</div>';
987

    
988
/**********************************************************
989
 *  - install new droplets
990
	$drops = (!in_array ( "mod_droplets", $all_tables)) ? "<br />Install droplets<br />" : "<br />Upgrade droplets<br />";
991
	echo $drops;
992
	$file_name = (!in_array ( "mod_droplets", $all_tables) ? "install.php" : "upgrade.php");
993
	require_once (WB_PATH."/modules/droplets/".$file_name);
994
********************************************************** */
995

    
996
/**********************************************************
997
 *  - End of upgrade script
998
 */
999
	if(!defined('DEFAULT_THEME')) { define('DEFAULT_THEME', $DEFAULT_THEME); }
1000
	if(!defined('THEME_PATH')) { define('THEME_PATH', WB_PATH.'/templates/'.DEFAULT_THEME);}
1001
/**********************************************************
1002
 *  - Set Version to new Version
1003
 */
1004
echo '<h3>Step '.(++$stepID).': Update database version number </h3>';
1005
echo '<div style="margin-left:2em;">';
1006

    
1007
$cfg = array(
1008
	'wb_version' => VERSION,
1009
	'wb_revision' => REVISION,
1010
	'wb_sp' => SP
1011
);
1012
echo '<br /><span><strong>Set database version number to '.VERSION.' '.SP.' '.' Revision ['.REVISION.'] : </strong></span>';
1013
echo (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
1014
echo '</div>';
1015

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

    
1021
if(defined('WB_URL')) {
1022
	echo '<form action="'.WB_URL.'/">';
1023
	echo '&nbsp;<input type="submit" value="kick me to the Frontend" />';
1024
	echo '</form>';
1025
}
1026
if(defined('ADMIN_URL')) {
1027
	echo '<form action="'.ADMIN_URL.'/">';
1028
	echo '&nbsp;<input type="submit" value="kick me to the Backend" />';
1029
	echo '</form>';
1030
}
1031

    
1032
echo "<br /><br /></div>
1033
</div>
1034
</div>
1035
</body>
1036
</html>
1037
";
1038
exit();
(5-5/5)