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 1765 2012-09-22 20:06:49Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/upgrade-script.php $
14
 * @lastmodified    $Date: 2012-09-22 22:06:49 +0200 (Sat, 22 Sep 2012) $
15
 *
16
 */
17

    
18
require_once('config.php');
19

    
20
require_once(WB_PATH.'/framework/functions.php');
21
require_once(WB_PATH.'/framework/class.admin.php');
22
// require_once(WB_PATH.'/framework/Database.php');
23
$admin = new admin('Addons', 'modules', false, false);
24

    
25
$oldVersion  = 'Version '.WB_VERSION;
26
$oldVersion .= (defined('WB_SP') ? WB_SP : '');
27
$oldRevision = (defined('WB_REVISION') ? ' Revision ['.WB_REVISION.'] ' : '') ;
28
$newVersion  = 'Version '.VERSION;
29
$newVersion .= (defined('SP') ? SP : '');
30
$newRevision = (defined('REVISION') ? ' Revision ['.REVISION.'] ' : '');
31

    
32
$bDebugModus = false;
33

    
34
// set addition settings if not exists, otherwise upgrade will be breaks
35
if(!defined('WB_SP')) { define('WB_SP',''); }
36
if(!defined('WB_REVISION')) { define('WB_REVISION',''); }
37

    
38
// database tables including in WB package
39
$aPackage = array (
40
    'settings','groups','addons','pages','sections','search','users',
41
    'mod_captcha_control','mod_code','mod_droplets','mod_form_fields',
42
    'mod_form_settings','mod_form_submissions','mod_jsadmin','mod_menu_link',
43
    'mod_news_comments','mod_news_groups','mod_news_posts','mod_news_settings',
44
    'mod_output_filter','mod_wrapper','mod_wysiwyg'
45
);
46

    
47
$OK            = ' <span class="ok">OK</span> ';
48
$FAIL          = ' <span class="error">FAILED</span> ';
49
$DEFAULT_THEME = 'wb_theme';
50

    
51
$stepID = 0;
52
$aFilesToRemove = array();
53
$dirRemove = array(
54
/*
55
			'[TEMPLATE]/allcss/',
56
			'[TEMPLATE]/blank/',
57
			'[TEMPLATE]/round/',
58
			'[TEMPLATE]/simple/',
59
*/
60
			'[ADMIN]/themes/',
61
		 );
62

    
63
if(version_compare(WB_REVISION, '1762', '<'))
64
{
65
    $filesRemove['0'] = array(
66

    
67
			'[ADMIN]/preferences/details.php',
68
			'[ADMIN]/preferences/email.php',
69
			'[ADMIN]/preferences/password.php',
70
			'[ADMIN]/pages/settings2.php',
71

    
72
			'[FRAMEWORK]/class.msg_queue.php',
73
			'[FRAMEWORK]/class.logfile.php',
74
//			'[FRAMEWORK]/class.database.php',
75

    
76
		 );
77

    
78
	$filesRemove['1'] = array(
79

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

    
111
			'[TEMPLATE]/wb_theme/templates/access.htt',
112
			'[TEMPLATE]/wb_theme/templates/addons.htt',
113
			'[TEMPLATE]/wb_theme/templates/admintools.htt',
114
			'[TEMPLATE]/wb_theme/templates/error.htt',
115
			'[TEMPLATE]/wb_theme/templates/groups.htt',
116
			'[TEMPLATE]/wb_theme/templates/groups_form.htt',
117
			'[TEMPLATE]/wb_theme/templates/languages.htt',
118
			'[TEMPLATE]/wb_theme/templates/languages_details.htt',
119

    
120
	/*
121
			'[TEMPLATE]/wb_theme/templates/login.htt',
122
			'[TEMPLATE]/wb_theme/templates/login_forgot.htt',
123
	*/
124

    
125
			'[TEMPLATE]/wb_theme/templates/media.htt',
126
			'[TEMPLATE]/wb_theme/templates/media_browse.htt',
127
			'[TEMPLATE]/wb_theme/templates/media_rename.htt',
128
			'[TEMPLATE]/wb_theme/templates/modules.htt',
129
			'[TEMPLATE]/wb_theme/templates/modules_details.htt',
130
			'[TEMPLATE]/wb_theme/templates/pages.htt',
131
			'[TEMPLATE]/wb_theme/templates/pages_modify.htt',
132
			'[TEMPLATE]/wb_theme/templates/pages_sections.htt',
133
			'[TEMPLATE]/wb_theme/templates/pages_settings.htt',
134
			'[TEMPLATE]/wb_theme/templates/preferences.htt',
135
			'[TEMPLATE]/wb_theme/templates/setparameter.htt',
136
			'[TEMPLATE]/wb_theme/templates/settings.htt',
137
			'[TEMPLATE]/wb_theme/templates/start.htt',
138
			'[TEMPLATE]/wb_theme/templates/success.htt',
139
			'[TEMPLATE]/wb_theme/templates/templates.htt',
140
			'[TEMPLATE]/wb_theme/templates/templates_details.htt',
141
			'[TEMPLATE]/wb_theme/templates/users.htt',
142
			'[TEMPLATE]/wb_theme/templates/users_form.htt',
143
		 );
144

    
145
    $aFilesToRemove = array_merge($filesRemove['0'],$filesRemove['1']);
146

    
147
}
148

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

    
164
// analyze/check database tables
165
function mysqlCheckTables( $dbName )
166
{
167
    global $aTable;
168
    $table_prefix = TABLE_PREFIX;
169
    $sql = "SHOW TABLES FROM " . $dbName;
170
    $result = @mysql_query( $sql );
171
    $data = array();
172
    $x = 0;
173

    
174
    while( ( $row = mysql_fetch_array( $result, MYSQL_NUM ) ) == true )
175
    {
176
        $tmp = str_replace($table_prefix, '', $row[0]);
177

    
178
        if( stristr( $row[0], $table_prefix )&& in_array($tmp,$aTable) )
179
        {
180
            $sql = "CHECK TABLE " . $dbName . '.' . $row[0];
181
            $analyze = mysql_query( $sql );
182
            $rowFetch = mysql_fetch_array( $analyze, MYSQL_ASSOC );
183
            $data[$x]['Op'] = $rowFetch["Op"];
184
            $data[$x]['Msg_type'] = $rowFetch["Msg_type"];
185
            $msgColor = '<span class="error">';
186
            $data[$x]['Table'] = $row[0];
187
           // print  " ";
188
            $msgColor = ($rowFetch["Msg_text"] == 'OK') ? '<span class="ok">' : '<span class="error">';
189
            $data[$x]['Msg_text'] = $msgColor.$rowFetch["Msg_text"].'</span>';
190
           // print  "<br />";
191
            $x++;
192
        }
193
    }
194
    return $data;
195
}
196

    
197
// check existings tables for upgrade or install
198
function check_wb_tables()
199
{
200
    global $database,$aPackage;
201

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

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

    
221
    return array_merge ( $all_tables, $aTable );
222
}
223

    
224
// check existing tables
225
$all_tables = check_wb_tables();
226

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

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

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

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

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

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

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

    
299
span.ok,
300
span.error {
301
    margin-left: 0em;
302
}
303

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

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

    
338
?>
339
<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>
340

    
341
<?php
342
/**
343
 * Check if disclaimer was accepted
344
 */
345
$bDebugModus = false;
346
$bDebugModus = ( (isset($_POST['debug_confirmed']) && $_POST['debug_confirmed'] == 'debug') ? true : false);
347
if (!(isset($_POST['backup_confirmed']) && $_POST['backup_confirmed'] == 'confirmed')) { ?>
348
<h2>Step 1: Backup your files</h2>
349
<p>It is highly recommended to <strong>create a manual backup</strong> of the entire <strong><?php echo  PAGES_DIRECTORY ?>/ folder</strong> and the <strong>MySQL database</strong> before proceeding.<br /><strong class="error">Note: </strong>The upgrade script alters some settings of your existing database!!! You need to confirm the disclaimer before proceeding.</p>
350

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

    
359
<?php
360
	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');
361
	echo '<br /><br />';
362
    echo "</div>
363
    </div>
364
    </div>
365
    </body>
366
    </html>
367
    ";
368
	exit();
369
}
370

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

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

    
398
        echo '<h4 class="warning"><br />';
399
        while ( list ( $key, $val ) = each ( $result ) )
400
        {
401
            echo 'TABLE ´'.TABLE_PREFIX.$val.'´ '.$FAIL.'<br>';
402
        }
403

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

    
417
        echo "<br /><br /></div>
418
        </div>
419
        </div>
420
        </body>
421
        </html>
422
        ";
423

    
424
        exit();
425
    }
426

    
427
echo '<h3>Step '.(++$stepID).': Setting default_theme</h3>';
428

    
429
if($bDebugModus) {
430
    /**********************************************************
431
     *  - Adding field default_theme to settings table
432
     */
433
    echo '<div style="margin-left:2em;">';
434
    echo "<br /><span><strong>Adding default_theme to settings table</strong></span>";
435
    // db_update_key_value('settings', 'default_theme', $DEFAULT_THEME);
436
    echo (db_update_key_value( 'settings', 'default_theme', $DEFAULT_THEME ) ? " $OK<br />" : " $FAIL!<br />");
437
    echo '</div>';
438

    
439
}
440
    echo '<h3>Step '.(++$stepID).': Updating core tables</h3>';
441

    
442
if($bDebugModus) {
443
    /**********************************************************
444
     *  - Adding field sec_anchor to settings table
445
     */
446
    echo '<div style="margin-left:2em;">';
447
    echo "<h4>Adding/updating entries on table settings</h4>";
448
    echo "<span>Adding/updating sec_anchor to settings table</span>";
449
    $cfg = array(
450
    	'sec_anchor' => defined('SEC_ANCHOR') ? SEC_ANCHOR : 'section_'
451
    );
452

    
453
    echo (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
454

    
455

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

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

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

    
482
    echo (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
483

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

    
493
    echo (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
494

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

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

    
512
    echo (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
513

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

    
522
    echo (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
523

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

    
532
    echo (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
533

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

    
542
    echo (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
543

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

    
552
    echo (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
553

    
554
    echo '</div>';
555

    
556

    
557
}
558

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

    
577
    echo "<h4>Adding/updating fiekds on table mod_menu_link</h4>";
578
	/**********************************************************
579
     *  - Add field "redirect_type" to table "mod_menu_link"
580
     *  has to be moved later to upgrade.php in modul menu_link, because modul can be removed
581
     */
582
	$table_name = TABLE_PREFIX.'mod_menu_link';
583
	$field_name = 'redirect_type';
584
	$description = "INT NOT NULL DEFAULT '301' AFTER `target_page_id`";
585
	if(!$database->field_exists($table_name,$field_name)) {
586
		echo "<span>Adding field redirect_type to mod_menu_link table</span>";
587
		echo ($database->field_add($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
588
	} else {
589
		echo "<span>Modify field redirect_type to mod_menu_link table</span>";
590
		echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
591
	}
592

    
593
    echo "<h4>Adding/updating fiekds on table pages</h4>";
594
	/**********************************************************
595
	 *  - Add field "page_trail" to table "pages"
596
	 */
597
	$table_name = TABLE_PREFIX.'pages';
598
	$field_name = 'page_trail';
599
	$description = "VARCHAR( 255 ) NOT NULL DEFAULT ''";
600
	echo "<span>Modify field page_trail to pages table</span>";
601
	echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
602

    
603
	/**********************************************************
604
     *  - Add field "page_icon" to table "pages"
605
     */
606
	$table_name = TABLE_PREFIX.'pages';
607
	$field_name = 'page_icon';
608
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '' AFTER `page_title`";
609
	if(!$database->field_exists($table_name,$field_name)) {
610
		echo "<span>Adding field page_icon to pages table</span>";
611
		echo ($database->field_add($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
612
	} else {
613
		echo "<span>Modify field page_icon to pages table</span>";
614
		echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
615
	}
616

    
617
	/**********************************************************
618
	 *  - Add field "page_code" to table "pages"
619
	 */
620
	$table_name = TABLE_PREFIX.'pages';
621
	$field_name = 'page_code';
622
	$description = "INT NOT NULL DEFAULT '0' AFTER `language`";
623
	if(!$database->field_exists($table_name,$field_name)) {
624
		echo "<span>Adding field page_code to pages table</span>";
625
		echo ($database->field_add($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
626
	} else {
627
		echo "<span>Modify field page_code to pages table</span>";
628
		echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
629
	}
630

    
631
	/**********************************************************
632
     *  - Add field "menu_icon_0" to table "pages"
633
     */
634
	$table_name = TABLE_PREFIX.'pages';
635
	$field_name = 'menu_icon_0';
636
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '' AFTER `menu_title`";
637
	if(!$database->field_exists($table_name,$field_name)) {
638
		echo "<span>Adding field menu_icon_0 to pages table</span>";
639
		echo ($database->field_add($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
640
	} else {
641
		echo "<span>Modify field menu_icon_0 to pages table</span>";
642
		echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
643
	}
644

    
645
	/**********************************************************
646
	 *  - Add field "menu_icon_1" to table "pages"
647
     */
648
	$table_name = TABLE_PREFIX.'pages';
649
	$field_name = 'menu_icon_1';
650
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '' AFTER `menu_icon_0`";
651
	if(!$database->field_exists($table_name,$field_name)) {
652
		echo "<span>Adding field menu_icon_1 to pages table</span>";
653
		echo ($database->field_add($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
654
	} else {
655
		echo "<span>Modify field menu_icon_1 to pages table</span>";
656
		echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
657
	}
658

    
659
	/**********************************************************
660
	 *  - Add field "tooltip" to table "pages"
661
     */
662
	$table_name = TABLE_PREFIX.'pages';
663
	$field_name = 'tooltip';
664
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '' AFTER `menu_icon_1`";
665
	if(!$database->field_exists($table_name,$field_name)) {
666
		echo "<span>Adding field tooltip to pages table</span>";
667
		echo ($database->field_add($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
668
	} else {
669
		echo "<span>Modify field tooltip to pages table";
670
		echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
671
	}
672

    
673
	/**********************************************************
674
	 *  - Add field "admin_groups" to table "pages"
675
     */
676
	$table_name = TABLE_PREFIX.'pages';
677
	$field_name = 'admin_groups';
678
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '1'";
679
	echo "<span>Modify field admin_groups to pages table";
680
	echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
681

    
682
	/**********************************************************
683
	 *  - Add field "admin_users" to table "pages"
684
	 */
685
	$table_name = TABLE_PREFIX.'pages';
686
	$field_name = 'admin_users';
687
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT ''";
688
	echo "<span>Modify field admin_users to pages table</span>";
689
	echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
690

    
691
	/**********************************************************
692
	 *  - Add field "viewing_groups" to table "pages"
693
	 */
694
	$table_name = TABLE_PREFIX.'pages';
695
	$field_name = 'viewing_groups';
696
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '1'";
697
	echo "<span>Modify field viewing_groups to pages table</span>";
698
	echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
699

    
700
	/**********************************************************
701
	 *  - Add field "viewing_users" to table "pages"
702
	 */
703
	$table_name = TABLE_PREFIX.'pages';
704
	$field_name = 'viewing_users';
705
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT ''";
706
	echo "<span>Modify field viewing_users to pages table";
707
	echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
708

    
709

    
710
    /**********************************************************
711
     * modify wrong strucre on table sections
712
     * wrong structure let crash wb
713
     */
714
	echo "<h4>Change field structure on table sections</h4>";
715
	$table_name = TABLE_PREFIX.'sections';
716
	$description = "VARCHAR( 255 ) NOT NULL DEFAULT ''";
717
	echo "<span>Modify field module on sections table</span>";
718
	echo ($database->field_modify($table_name, 'module', $description) ? " $OK<br />" : " $FAIL!<br />");
719
	echo "<span>Modify field block on sections table</span>";
720
	echo ($database->field_modify($table_name, 'block', $description) ? " $OK<br />" : " $FAIL!<br />");
721
	echo "<span>Modify field publ_start on sections table</span>";
722
	echo ($database->field_modify($table_name, 'publ_start', $description) ? " $OK<br />" : " $FAIL!<br />");
723
	echo "<span>Modify field publ_end on sections table</span>";
724
	echo ($database->field_modify($table_name, 'publ_end', $description) ? " $OK<br />" : " $FAIL!<br />");
725

    
726
    echo '</div>';
727

    
728
}
729

    
730
/**********************************************************
731
 * This part with changing in mod_wysiwyg will be removed in the final version
732
 * special workout for the tester
733
 *  - Remove/add PRIMARY KEY from/to "section_id" from table "mod_wysiwygs"
734
 */
735
if($bDebugModus) {
736
    echo '<div style="margin-left:2em;">';
737

    
738
    $sTable = TABLE_PREFIX.'mod_wysiwyg';
739
    $field_name = 'wysiwyg_id';
740
    if($database->field_exists($sTable, 'wysiwyg_id')) {
741
        if($database->index_exists($sTable, 'PRIMARY')) {
742
            echo "<span>Remove PRIMARY KEY from table mod_wysiwyg.wysiwyg_id</span>";
743
            echo $database->index_remove($sTable, 'PRIMARY') ? " $OK<br />" : " $FAIL!<br />";
744
        }
745
        echo "<span>Remove field 'wysiwyg_id' from table mod_wysiwyg</span>";
746
        echo $database->field_remove($sTable, 'wysiwyg_id') ? " $OK<br />" : " $FAIL!<br />";
747
    }
748

    
749
    echo "<br /><span>Create PRIMARY KEY ( `section_id` ) on table mod_wysiwygs.</span>";
750
    echo $database->index_add($sTable, '', 'section_id', 'PRIMARY') ? " $OK<br />" : " $FAIL!<br />";
751
    echo '</div>';
752
}
753

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

    
756
echo '<div style="margin-left:2em;">';
757
    /**********************************************************
758
    * upgrade media directory index protect files
759
    */
760
    $dir = (WB_PATH.MEDIA_DIRECTORY);
761
    echo '<h4>Upgrade media directory '.MEDIA_DIRECTORY.'/ index.php protect files</h4>';
762
    $array = rebuildFolderProtectFile($dir);
763
    if( sizeof( $array ) ){
764
    	print '<span><strong>Upgrade '.sizeof( $array ).' directory '.MEDIA_DIRECTORY.'/ protect files</strong></span>'." $OK<br />";
765
    } else {
766
    	print '<span><strong>Upgrade directory '.MEDIA_DIRECTORY.'/ protect files</strong></span>'." $FAIL!<br />";
767
    	print implode ('<br />',$array);
768
    }
769

    
770
    /**********************************************************
771
     * upgrade pages directory index access files
772
     */
773
	echo '<h4>Upgrade pages directory '.PAGES_DIRECTORY.'/  protect and access files</h4>';
774

    
775
    /**********************************************************
776
     *  - Reformat/rebuild all existing access files
777
     */
778
    $sPagePath = (defined('PAGES_DIRECTORY') && (PAGES_DIRECTORY != '') ? PAGES_DIRECTORY : '');
779
    $msg = rebuild_all_accessfiles();
780

    
781
	print implode ('<br />',$msg);
782
    echo '</div>';
783
    /* *****************************************************************************
784
     * - check for deprecated / never needed files
785
     */
786
    if(sizeof($aFilesToRemove)) {
787
    	echo '<h3>Step '.(++$stepID).': Remove deprecated and old files</h3>';
788
    	$searches = array(
789
    		'[ADMIN]',
790
    		'[MEDIA]',
791
    		'[PAGES]',
792
    		'[FRAMEWORK]',
793
    		'[MODULES]',
794
    		'[TEMPLATE]'
795
    	);
796
    	$replacements = array(
797
    		'/'.substr(ADMIN_PATH, strlen(WB_PATH)+1),
798
    		MEDIA_DIRECTORY,
799
    		PAGES_DIRECTORY,
800
    		'/framework',
801
    		'/modules',
802
    		'/templates'
803
    	);
804

    
805
		$msg = '';
806
    	foreach( $aFilesToRemove as $file )
807
    	{
808
			$file = str_replace($searches, $replacements, $file);
809
			if( is_writable(WB_PATH.'/'.$file) ) {
810
				// try to unlink file
811
				if(!unlink(WB_PATH.$file)) {
812
					// save in err-list, if failed
813
					$msg .= $file.'<br />';
814
				} else {
815
					$msg .= $file.'<br />';
816
    			}
817
			}
818
    	}
819

    
820
		if($msg != '')
821
		{
822
			$msg = '<br /><br />Following files are deprecated, outdated or a security risk and
823
				    can not be removed automatically.<br /><br />Please delete them
824
					using FTP and restart upgrade-script!<br /><br />'.$msg.'<br />';
825
	        status_msg($msg, 'error warning', 'div');
826
			echo '<p style="font-size:120%;"><strong>WARNING: The upgrade script failed ...</strong></p>';
827

    
828
			echo '<form action="'.$_SERVER['SCRIPT_NAME'].'">';
829
			echo '&nbsp;<input name="send" type="submit" value="Restart upgrade script" />';
830
			echo '</form>';
831
            echo "<br /><br /></div>
832
            </div>
833
            </div>
834
            </body>
835
            </html>
836
            ";
837
			exit;
838
		}
839
    }
840

    
841

    
842
/**********************************************************
843
 * - check for deprecated / never needed files
844
 */
845
	if(sizeof($dirRemove)) {
846
		echo '<h3>Step  '.(++$stepID).': Remove deprecated and old folders</h3>';
847
		$searches = array(
848
			'[ADMIN]',
849
			'[MEDIA]',
850
			'[PAGES]',
851
			'[TEMPLATE]'
852
		);
853
		$replacements = array(
854
			substr(ADMIN_PATH, strlen(WB_PATH)+1),
855
			MEDIA_DIRECTORY,
856
			PAGES_DIRECTORY,
857
			'/templates',
858
		);
859
		$msg = '';
860
		foreach( $dirRemove as $dir ) {
861
			$dir = str_replace($searches, $replacements, $dir);
862
			$dir = WB_PATH.'/'.$dir;
863
			if( is_dir( $dir )) {
864
			// try to delete dir
865
				if(!is_writable( $dir ) || !rm_full_dir($dir)) {
866
				// save in err-list, if failed
867
					$msg .= str_replace(WB_PATH,'',$dir).'<br />';
868
				}
869
			}
870
		}
871

    
872
		if($msg != '') {
873
			$msg = '<br /><br />Following directories are deprecated, outdated or a security risk and
874
					can not be removed automatically.<br /><br />Please delete them
875
					using FTP and restart upgrade-script!<br /><br />'.$msg.'<br />';
876
			status_msg($msg, 'error warning', 'div');
877
			echo '<p style="font-size:120%;"><strong>WARNING: The upgrade script failed ...</strong></p>';
878
			echo '<form action="'.$_SERVER['SCRIPT_NAME'].'">';
879
			echo '&nbsp;<input name="send" type="submit" value="Restart upgrade script" />';
880
			echo '</form>';
881
            echo "<br /><br /></div>
882
            </div>
883
            </div>
884
            </body>
885
            </html>
886
            ";
887
			exit;
888
		}
889
	}
890

    
891
    /**********************************************************
892
     * upgrade modules if newer version is available
893
     * $aModuleList list of proofed modules
894
     */
895
    $sModuleList = 'news,wysiwyg,form';
896
    $aModuleList = explode(',', (defined('MODULES_UPGRADE_LIST') ? MODULES_UPGRADE_LIST : $sModuleList));
897
    echo '<h3>Step '.(++$stepID).': Upgrade proofed modules</h3>';
898
//	$aModuleList = array('news');
899
	foreach($aModuleList as $sModul) {
900
		if(file_exists(WB_PATH.'/modules/'.$sModul.'/upgrade.php')) {
901
			$currModulVersion = get_modul_version ($sModul, false);
902
			$newModulVersion =  get_modul_version ($sModul, true);
903
			if((version_compare($currModulVersion, $newModulVersion) <= 0)) {
904
                echo '<div style="margin-left:2em;">';
905
				echo '<h4>'.'Upgrade module \''.$sModul.'\' version '.$newModulVersion.'</h4>';
906
				require_once(WB_PATH.'/modules/'.$sModul.'/upgrade.php');
907
                echo '</div>';
908
			}
909
		}
910
	}
911

    
912
/**********************************************************
913
 *  - Reload all addons
914
 */
915

    
916
	echo '<h3>Step '.(++$stepID).' : Reload all addons database entry (no upgrade)</h3><br />';
917
    echo '<div style="margin-left:2em;">';
918
    $iFound = 0;
919
    $iLoaded = 0;
920
	////delete modules
921
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'module'");
922
	// Load all modules
923
	if( ($handle = opendir(WB_PATH.'/modules/')) ) {
924
		while(false !== ($file = readdir($handle))) {
925
			if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'admin.php' AND $file != 'index.php') {
926
                $iFound++;
927
				$iLoaded = load_module(WB_PATH.'/modules/'.$file ) ? $iLoaded+1 : $iLoaded;
928
			   // 	upgrade_module($file, true);
929
			}
930
		}
931
		closedir($handle);
932
	}
933
	echo '<span><strong>'.$iLoaded.' Modules reloaded,</span> found '.$iFound.' directories in folder /modules/</strong><br />';
934

    
935
    $iFound = 0;
936
    $iLoaded = 0;
937
	////delete templates
938
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'template'");
939
	// Load all templates
940
	if( ($handle = opendir(WB_PATH.'/templates/')) ) {
941
		while(false !== ($file = readdir($handle))) {
942
			if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
943
                $iFound++;
944
				$iLoaded = (load_template(WB_PATH.'/templates/'.$file)==true) ? $iLoaded+1 : $iLoaded;
945
			}
946
		}
947
		closedir($handle);
948
	}
949
	echo '<span><strong>'.$iLoaded.' Templates reloaded,</span> found '.$iFound.' directories in folder /templates/</strong><br />';
950

    
951
    $iFound = 0;
952
    $iLoaded = 0;
953
	////delete languages
954
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'language'");
955
	// Load all languages
956
	if( ($handle = opendir(WB_PATH.'/languages/')) ) {
957
		while(false !== ($file = readdir($handle))) {
958
			if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
959
                $iFound++;
960
				$iLoaded = load_language(WB_PATH.'/languages/'.$file) ? $iLoaded+1 : $iLoaded;
961
			}
962
		}
963
		closedir($handle);
964
	}
965
	echo '<span><strong>'.$iLoaded.' Languages reloaded,</span> found '.$iFound.' files in folder /languages/</strong><br />';
966
    echo '</div>';
967

    
968
/**********************************************************
969
 *  - install new droplets
970
	$drops = (!in_array ( "mod_droplets", $all_tables)) ? "<br />Install droplets<br />" : "<br />Upgrade droplets<br />";
971
	echo $drops;
972
	$file_name = (!in_array ( "mod_droplets", $all_tables) ? "install.php" : "upgrade.php");
973
	require_once (WB_PATH."/modules/droplets/".$file_name);
974
********************************************************** */
975

    
976
/**********************************************************
977
 *  - End of upgrade script
978
 */
979
	if(!defined('DEFAULT_THEME')) { define('DEFAULT_THEME', $DEFAULT_THEME); }
980
	if(!defined('THEME_PATH')) { define('THEME_PATH', WB_PATH.'/templates/'.DEFAULT_THEME);}
981
/**********************************************************
982
 *  - Set Version to new Version
983
 */
984
echo '<h3>Step '.(++$stepID).': Update database version number </h3>';
985
echo '<div style="margin-left:2em;">';
986

    
987
$cfg = array(
988
	'wb_version' => VERSION,
989
	'wb_revision' => REVISION,
990
	'wb_sp' => SP
991
);
992
echo '<br /><span><strong>Set database version number to '.VERSION.' '.SP.' '.' Revision ['.REVISION.'] : </strong></span>';
993
echo (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
994
echo '</div>';
995

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

    
1001
if(defined('WB_URL')) {
1002
	echo '<form action="'.WB_URL.'/">';
1003
	echo '&nbsp;<input type="submit" value="kick me to the Frontend" />';
1004
	echo '</form>';
1005
}
1006
if(defined('ADMIN_URL')) {
1007
	echo '<form action="'.ADMIN_URL.'/">';
1008
	echo '&nbsp;<input type="submit" value="kick me to the Backend" />';
1009
	echo '</form>';
1010
}
1011

    
1012
echo "<br /><br /></div>
1013
</div>
1014
</div>
1015
</body>
1016
</html>
1017
";
1018
exit();
(5-5/5)