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 1688 2012-05-07 23:33:24Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/upgrade-script.php $
14
 * @lastmodified    $Date: 2012-05-08 01:33:24 +0200 (Tue, 08 May 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
// set addition settings if not exists, otherwise upgrade will be breaks
33
if(!defined('WB_SP')) { define('WB_SP',''); }
34
if(!defined('WB_REVISION')) { define('WB_REVISION',''); }
35

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

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

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

    
60
$filesRemove['0'] = array(
61

    
62
			'[ADMIN]/preferences/details.php',
63
			'[ADMIN]/preferences/email.php',
64
			'[ADMIN]/preferences/password.php',
65
			'[ADMIN]/pages/settings2.php',
66

    
67
			'[FRAMEWORK]/class.msg_queue.php',
68
			'[FRAMEWORK]/class.database.php',
69

    
70
		 );
71

    
72
if(version_compare(WB_REVISION, '1681', '<'))
73
{
74
	$filesRemove['1'] = array(
75

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

    
107
			'[TEMPLATE]/wb_theme/templates/access.htt',
108
			'[TEMPLATE]/wb_theme/templates/addons.htt',
109
			'[TEMPLATE]/wb_theme/templates/admintools.htt',
110
			'[TEMPLATE]/wb_theme/templates/error.htt',
111
			'[TEMPLATE]/wb_theme/templates/groups.htt',
112
			'[TEMPLATE]/wb_theme/templates/groups_form.htt',
113
			'[TEMPLATE]/wb_theme/templates/languages.htt',
114
			'[TEMPLATE]/wb_theme/templates/languages_details.htt',
115

    
116
	/*
117
			'[TEMPLATE]/wb_theme/templates/login.htt',
118
			'[TEMPLATE]/wb_theme/templates/login_forgot.htt',
119
	*/
120

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

    
142
/* display a status message on the screen **************************************
143
 * @param string $message: the message to show
144
 * @param string $class:   kind of message as a css-class
145
 * @param string $element: witch HTML-tag use to cover the message
146
 * @return void
147
 */
148
function status_msg($message, $class='check', $element='span')
149
{
150
	// returns a status message
151
	$msg  = '<'.$element.' class="'.$class.'">';
152
	$msg .= '<strong>'.strtoupper(strtok($class, ' ')).'</strong>';
153
	$msg .= $message.'</'.$element.'>';
154
	echo $msg;
155
}
156

    
157
// analyze/check database tables
158
function mysqlCheckTables( $dbName )
159
{
160
    global $aTable;
161
    $table_prefix = TABLE_PREFIX;
162
    $sql = "SHOW TABLES FROM " . $dbName;
163
    $result = @mysql_query( $sql );
164
    $data = array();
165
    $x = 0;
166

    
167
    while( ( $row = mysql_fetch_array( $result, MYSQL_NUM ) ) == true )
168
    {
169
        $tmp = str_replace($table_prefix, '', $row[0]);
170

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

    
190
// check existings tables for upgrade or install
191
function check_wb_tables()
192
{
193
    global $database,$aTable;
194

    
195
 // if prefix inludes '_' or '%'
196
 $search_for = addcslashes ( TABLE_PREFIX, '%_' );
197
 $get_result = $database->query( 'SHOW TABLES LIKE "'.$search_for.'%"');
198

    
199
        // $get_result = $database->query( "SHOW TABLES FROM ".DB_NAME);
200
        $all_tables = array();
201
        if($get_result->numRows() > 0)
202
        {
203
            while ($data = $get_result->fetchRow())
204
            {
205
                $tmp = str_replace(TABLE_PREFIX, '', $data[0]);
206
                if(in_array($tmp,$aTable))
207
                {
208
                    $all_tables[] = $tmp;
209
                }
210
            }
211
        }
212
     return $all_tables;
213
}
214

    
215
// check existing tables
216
$all_tables = check_wb_tables();
217

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

    
226
body {
227
	margin:0;
228
	padding:0;
229
	border:0;
230
	background: #EBF7FC;
231
	color:#000;
232
	font-family: 'Trebuchet MS', Verdana, Arial, Helvetica, Sans-Serif;
233
	font-size: small;
234
	height:101%;
235
}
236

    
237
#container {
238
	width:85%;
239
	background: #A8BCCB url(templates/wb_theme/images/background.png) repeat-x;
240
	border:1px solid #000;
241
	color:#000;
242
	margin:2em auto;
243
	padding:0 15px;
244
	min-height: 500px;
245
	text-align:left;
246
}
247

    
248
p { line-height:1.5em; }
249

    
250
form {
251
	display: inline-block;
252
	line-height: 20px;
253
	vertical-align: baseline;
254
}
255
input[type="submit"].restart {
256
	background-color: #FFDBDB;
257
	font-weight: bold;
258
}
259

    
260
h1,h2,h3,h4,h5,h6 {
261
	font-family: Verdana, Arial, Helvetica, sans-serif;
262
	color: #369;
263
	margin-top: 1.0em;
264
	margin-bottom: 0.1em;
265
}
266

    
267
h1 { font-size:150%; }
268
h2 { font-size: 130%; border-bottom: 1px #CCC solid; }
269
h3 { font-size: 110%; font-weight: bold;; }
270

    
271
.ok, .error { font-weight:bold; }
272
.ok { color:green; }
273
.error { color:red; }
274
.check { color:#555; }
275

    
276
.warning {
277
	width: 98%;
278
	background:#FFDBDB;
279
	padding:0.2em;
280
	margin-top:0.5em;
281
	border: 1px solid black;
282
}
283
.info {
284
	width: 98%;
285
	background:#99CC99;
286
	padding:0.2em;
287
	margin-top:0.5em;
288
	border: 1px solid black;
289
}
290

    
291
</style>
292
</head>
293
<body>
294
<div id="container">
295
<img src="templates/wb_theme/images/logo.png" alt="WebsiteBaker Project" />
296
<h1>WebsiteBaker Upgrade</h1>
297
<?php
298
	if( version_compare( WB_VERSION, '2.7', '<' )) {
299
		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');
300
		echo '<br /><br />';
301
		echo "</div>
302
		</body>
303
		</html>
304
		";
305
		exit();
306
	}
307

    
308
?>
309
<p>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>
310

    
311
<?php
312
/**
313
 * Check if disclaimer was accepted
314
 */
315
if (!(isset($_POST['backup_confirmed']) && $_POST['backup_confirmed'] == 'confirmed')) { ?>
316
<h2>Step 1: Backup your files</h2>
317
<p>It is highly recommended to <strong>create a manual backup</strong> of the entire <strong>/pages 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>
318

    
319
<form name="send" action="<?php echo $_SERVER['SCRIPT_NAME'];?>" method="post">
320
<textarea cols="80" 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 /pages folder (including all files and subfolders contained in it) and backup of the entire WebsiteBaker MySQL database was created before you can proceed.</textarea>
321
<br /><br /><input name="backup_confirmed" type="checkbox" value="confirmed" />&nbsp;I confirm that a manual backup of the /pages folder and the MySQL database was created.
322
<br /><br /><input name="send" type="submit" value="Start upgrade script" />
323
</form>
324
<br />
325

    
326
<?php
327
	status_msg('<strong>Notice:</strong><br />You need to confirm that you have created a manual backup of the /pages directory and the MySQL database before you can proceed.', 'warning', 'div');
328
	echo '<br /><br />';
329
    echo "</div>
330
    </body>
331
    </html>
332
    ";
333
	exit();
334
}
335

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

    
338
/**********************************************************
339
 *  - Adding field default_theme to settings table
340
 */
341
echo "<br />Adding default_theme to settings table";
342
// db_update_key_value('settings', 'default_theme', $DEFAULT_THEME);
343
echo (db_update_key_value( 'settings', 'default_theme', $DEFAULT_THEME ) ? " $OK<br />" : " $FAIL!<br />");
344

    
345
// check again all tables, to get a new array
346
 if(sizeof($all_tables) < 22) { $all_tables = check_wb_tables(); }
347
/**********************************************************
348
 *  - check tables comin with WebsiteBaker
349
 */
350
    $check_text = 'total ';
351
    // $check_tables = mysqlCheckTables( DB_NAME ) ;
352

    
353
    if(sizeof($all_tables) == 22)
354
    {
355
        echo '<h4>NOTICE: Your database '.DB_NAME.' has '.sizeof($all_tables).' '.$check_text.' tables from '.sizeof($aTable).' included in package '.$OK.'</h4>';
356
    }
357
    else
358
    {
359
        status_msg('<strong>WARNING:</strong><br />can\'t run Upgrade, missing tables', 'warning', 'div');
360
    	echo '<h4>Missing required tables. You can install them in backend->addons->modules->advanced. Then again run upgrade-script.php</h4>';
361
        $result = array_diff ( $aTable, $all_tables );
362
        echo '<h4 class="warning"><br />';
363
        while ( list ( $key, $val ) = each ( $result ) )
364
        {
365
            echo TABLE_PREFIX.$val.' '.$FAIL.'<br>';
366
        }
367
        echo '<br /></h4>';
368
    	echo '<br /><form action="'. $_SERVER['PHP_SELF'] .'">';
369
    	echo '<input type="submit" value="kick me back" style="float:left;" />';
370
    	echo '</form>';
371
        if(defined('ADMIN_URL'))
372
        {
373
        	echo '<form action="'.ADMIN_URL.'" target="_self">';
374
        	echo '&nbsp;<input type="submit" value="kick me to the Backend" />';
375
        	echo '</form>';
376
        }
377
        echo "<br /><br /></div>
378
        </body>
379
        </html>
380
        ";
381
        exit();
382
    }
383

    
384

    
385
echo '<h3>Step '.(++$stepID).': Updating settings</h3>';
386
/**********************************************************
387
 *  - Adding field sec_anchor to settings table
388
 */
389
echo "<br />Adding sec_anchor to settings table";
390
$cfg = array(
391
	'sec_anchor' => defined('SEC_ANCHOR') ? SEC_ANCHOR : 'wb_'
392
);
393

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

    
396

    
397
/**********************************************************
398
 *  - Adding redirect timer to settings table
399
 */
400
echo "Adding redirect timer to settings table";
401
$cfg = array(
402
	'redirect_timer' => defined('Redirect_Timer') ? Redirect_Timer : '1500'
403
);
404
echo (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
405

    
406
/**********************************************************
407
 *  - Adding rename_files_on_upload to settings table
408
 */
409
echo "Updating rename_files_on_upload to settings table";
410
$cfg = array(
411
	'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')
412
);
413
echo (db_update_key_value( 'settings', $cfg ) ? " $OK<br />" : " $FAIL!<br />");
414

    
415
/**********************************************************
416
 *  - Adding mediasettings to settings table
417
 */
418
echo "Adding mediasettings to settings table";
419
$cfg = array(
420
	'mediasettings' => (defined('MEDIASETTINGS') ? MEDIASETTINGS : ''),
421
);
422

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

    
425
/**********************************************************
426
 *  - Adding fingerprint_with_ip_octets to settings table
427
 */
428
echo "Adding fingerprint_with_ip_octets to settings table";
429
$cfg = array(
430
	'fingerprint_with_ip_octets' => (defined('FINGERPRINT_WITH_IP_OCTETS') ? FINGERPRINT_WITH_IP_OCTETS : '2'),
431
	'secure_form_module' => (defined('SECURE_FORM_MODULE') ? SECURE_FORM_MODULE : '')
432
);
433

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

    
436
/**********************************************************
437
 *  - Adding page_icon_dir to settings table
438
 */
439
echo "Adding page_icon_dir to settings table";
440
$cfg = array(
441
	'page_icon_dir' => (defined('PAGE_ICON_DIR') ? PAGE_ICON_DIR : '/templates/*/title_images'),
442
);
443

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

    
446
/**********************************************************
447
 *  - Adding dev_infos to settings table
448
 */
449
echo "Adding dev_infos to settings table";
450
$cfg = array(
451
	'dev_infos' => (defined('DEV_INFOS') ? DEV_INFOS : 'false')
452
);
453

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

    
456
if(version_compare(WB_REVISION, REVISION, '<='))
457
{
458
	echo '<h3>Step '.(++$stepID).': Updating core tables</h3>';
459

    
460
	/**********************************************************
461
	 *  - Update search no results database filed to create
462
	 *  valid XHTML if search is empty
463
	 */
464
	if (version_compare(WB_VERSION, '2.8', '<'))
465
	{
466
	    echo "<br />Updating database field `no_results` of search table: ";
467
	    $search_no_results = addslashes('<tr><td><p>[TEXT_NO_RESULTS]</p></td></tr>');
468
	    $sql  = 'UPDATE `'.TABLE_PREFIX.'search` ';
469
		$sql .= 'SET `value`=\''.$search_no_results.'\' ';
470
		$sql .= 'WHERE `name`=\'no_results\'';
471
	    echo ($database->query($sql)) ? ' $OK<br />' : ' $FAIL<br />';
472
	}
473
	/**********************************************************
474
 *  - Add field "redirect_type" to table "mod_menu_link"
475
 */
476
	$table_name = TABLE_PREFIX.'mod_menu_link';
477
	$field_name = 'redirect_type';
478
	$description = "INT NOT NULL DEFAULT '302' AFTER `target_page_id`";
479
	if(!$database->field_exists($table_name,$field_name)) {
480
		echo "<br />Adding field redirect_type to mod_menu_link table";
481
		echo ($database->field_add($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
482
	} else {
483
		echo "<br />Modify field redirect_type to mod_menu_link table";
484
		echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
485
	}
486

    
487
	/**********************************************************
488
	 *  - Add field "page_trail" to table "pages"
489
	 */
490
	$table_name = TABLE_PREFIX.'pages';
491
	$field_name = 'page_trail';
492
	$description = "VARCHAR( 255 ) NOT NULL DEFAULT ''";
493
	echo "Modify field page_trail to pages table";
494
	echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
495

    
496
	/**********************************************************
497
 *  - Add field "page_icon" to table "pages"
498
 */
499
	$table_name = TABLE_PREFIX.'pages';
500
	$field_name = 'page_icon';
501
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '' AFTER `page_title`";
502
	if(!$database->field_exists($table_name,$field_name)) {
503
		echo "Adding field page_icon to pages table";
504
		echo ($database->field_add($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
505
	} else {
506
		echo "Modify field page_icon to pages table";
507
		echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
508
	}
509

    
510
	/**********************************************************
511
	 *  - Add field "tooltip" to table "pages"
512
 */
513
	$table_name = TABLE_PREFIX.'pages';
514
	$field_name = 'tooltip';
515
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '' AFTER `page_icon`";
516
	if(!$database->field_exists($table_name,$field_name)) {
517
		echo "Adding field tooltip to pages table";
518
		echo ($database->field_add($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
519
	} else {
520
	echo "Modify field tooltip to pages table";
521
	echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
522
	}
523

    
524
	/**********************************************************
525
	 *  - Add field "page_code" to table "pages"
526
	 */
527
	$table_name = TABLE_PREFIX.'pages';
528
	$field_name = 'page_code';
529
	$description = "INT NOT NULL DEFAULT '0' AFTER `language`";
530
	if(!$database->field_exists($table_name,$field_name)) {
531
		echo "Adding field page_code to pages table";
532
		echo ($database->field_add($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
533
	} else {
534
		echo "Modify field page_code to pages table";
535
		echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
536
	}
537

    
538
	/**********************************************************
539
 *  - Add field "menu_icon_0" to table "pages"
540
 */
541
	$table_name = TABLE_PREFIX.'pages';
542
	$field_name = 'menu_icon_0';
543
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '' AFTER `menu_title`";
544
	if(!$database->field_exists($table_name,$field_name)) {
545
		echo "Adding field menu_icon_0 to pages table";
546
		echo ($database->field_add($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
547
	} else {
548
		echo "Modify field menu_icon_0 to pages table";
549
		echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
550
	}
551

    
552
	/**********************************************************
553
	 *  - Add field "menu_icon_1" to table "pages"
554
 */
555
	$table_name = TABLE_PREFIX.'pages';
556
	$field_name = 'menu_icon_1';
557
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '' AFTER `menu_icon_0`";
558
	if(!$database->field_exists($table_name,$field_name)) {
559
		echo "Adding field menu_icon_1 to pages table";
560
		echo ($database->field_add($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
561
	} else {
562
		echo "Modify field menu_icon_1 to pages table";
563
		echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
564
	}
565

    
566
	/**********************************************************
567
	 *  - Add field "tooltip" to table "pages"
568
 */
569
	$table_name = TABLE_PREFIX.'pages';
570
	$field_name = 'tooltip';
571
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '' AFTER `menu_icon_1`";
572
	if(!$database->field_exists($table_name,$field_name)) {
573
		echo "Adding field tooltip to pages table";
574
		echo ($database->field_add($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
575
	} else {
576
		echo "Modify field tooltip to pages table";
577
		echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
578
	}
579

    
580
	/**********************************************************
581
	 *  - Add field "admin_groups" to table "pages"
582
 */
583
	$table_name = TABLE_PREFIX.'pages';
584
	$field_name = 'admin_groups';
585
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '1'";
586
	echo "Modify field admin_groups to pages table";
587
	echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
588

    
589
	/**********************************************************
590
	 *  - Add field "admin_users" to table "pages"
591
	 */
592
	$table_name = TABLE_PREFIX.'pages';
593
	$field_name = 'admin_users';
594
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT ''";
595
	echo "Modify field admin_users to pages table";
596
	echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
597

    
598
	/**********************************************************
599
	 *  - Add field "viewing_groups" to table "pages"
600
	 */
601
	$table_name = TABLE_PREFIX.'pages';
602
	$field_name = 'viewing_groups';
603
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT '1'";
604
	echo "Modify field viewing_groups to pages table";
605
	echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
606

    
607
	/**********************************************************
608
	 *  - Add field "viewing_users" to table "pages"
609
	 */
610
	$table_name = TABLE_PREFIX.'pages';
611
	$field_name = 'viewing_users';
612
	$description = "VARCHAR( 512 ) NOT NULL DEFAULT ''";
613
	echo "Modify field viewing_users to pages table";
614
	echo ($database->field_modify($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
615
}
616

    
617
/**********************************************************
618
 * upgrade media folder index protect files
619
 ALTER TABLE `wb_pages` CHANGE `page_icon` `page_icon` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT ''
620
 */
621
	$dir = (WB_PATH.MEDIA_DIRECTORY);
622
	echo '<h4>Upgrade '.MEDIA_DIRECTORY.'/ index.php protect files</h4><br />';
623
	$array = rebuildFolderProtectFile($dir);
624
	if( sizeof( $array ) ){
625
		print '<br /><strong>Upgrade '.sizeof( $array ).' '.MEDIA_DIRECTORY.'/ protect files</strong>'." $OK<br />";
626
	} else {
627
		print '<br /><strong>Upgrade '.MEDIA_DIRECTORY.'/ protect files</strong>'." $FAIL!<br />";
628
		print implode ('<br />',$array);
629
	}
630

    
631
/**********************************************************
632
 * upgrade pages folder index access files
633
 */
634
	echo '<h4>Upgrade /pages/ index.php access files</h4><br />';
635

    
636
    ///**********************************************************
637
    // *  - try to remove access files
638
    // */
639
	$sTempDir = (defined('PAGES_DIRECTORY') && (PAGES_DIRECTORY != '') ? PAGES_DIRECTORY : '');
640
	if(($sTempDir!='') && is_readable(WB_PATH.$sTempDir)==true) {
641
	 	if(rm_full_dir (WB_PATH.$sTempDir, true )==false) {
642
			$msg[] = '<strong>Could not delete existing access files</strong><br />';
643
	 	} else {
644
			$msg[] = createFolderProtectFile(rtrim( WB_PATH.$sTempDir,'/') );
645
        }
646
	}
647

    
648
    ///**********************************************************
649
    // *  - Reformat/rebuild all existing access files
650
    // */
651
    $msg[] = "All existing access files anew format";
652
    $sql = 'SELECT `page_id`,`link`, `level` FROM `'.TABLE_PREFIX.'pages` ORDER BY `link`';
653
    if (($res_pages = $database->query($sql)))
654
    {
655
        $x = 0;
656
        while (($rec_page = $res_pages->fetchRow()))
657
        {
658
            $filename = WB_PATH.PAGES_DIRECTORY.$rec_page['link'].PAGE_EXTENSION;
659
            $msg = create_access_file($filename, $rec_page['page_id'], $rec_page['level']);
660
            $x++;
661
        }
662
        $msg[] = '<strong>Number of the anew formatted access files: '.$x.'</strong><br />';
663
    }
664

    
665
	print implode ('<br />',$msg);
666

    
667
/*
668
	if( sizeof( $msg ) ){
669

    
670
		print '<br /><strong>Upgrade '.sizeof( $msg ).' /pages/ access files</strong>'." $OK<br />";
671
	} else {
672
		print '<br /><strong>Upgrade /pages/ access files</strong>'." $FAIL!<br />";
673
		print implode ('<br />',$msg);
674
	}
675
*/
676
/**********************************************************
677
 * upgrade posts folder index protect files
678
 */
679
	$sPostsPath = WB_PATH.PAGES_DIRECTORY.'/posts';
680
	echo '<h4>Upgrade /posts/ index.php protect files</h4><br />';
681
	$array = rebuildFolderProtectFile($sPostsPath);
682
	if( sizeof( $array ) ){
683
		print '<br /><strong>Upgrade '.sizeof( $array ).' /posts/ protect files</strong>'." $OK<br />";
684
	} else {
685
		print '<br /><strong>Upgrade /posts/ protect files</strong>'." $FAIL!<br />";
686
		print implode ('<br />',$array);
687
	}
688

    
689
/* *****************************************************************************
690
 * - check for deprecated / never needed files
691
 */
692
	if(sizeof($filesRemove)) {
693
		echo '<h3>Step '.(++$stepID).': Remove deprecated and old files</h3>';
694
	}
695
	$searches = array(
696
		'[ADMIN]',
697
		'[MEDIA]',
698
		'[PAGES]',
699
		'[FRAMEWORK]',
700
		'[MODULES]',
701
		'[TEMPLATE]'
702
	);
703
	$replacements = array(
704
		substr(ADMIN_PATH, strlen(WB_PATH)+1),
705
		MEDIA_DIRECTORY,
706
		PAGES_DIRECTORY,
707
		'/framework',
708
		'/modules',
709
		'/templates'
710
	);
711

    
712
	foreach( $filesRemove as $filesId )
713
	{
714
		$msg = '';
715
		foreach( $filesId as $file )
716
		{
717
			$file = str_replace($searches, $replacements, $file);
718
			$file = WB_PATH.'/'.$file;
719
			if( file_exists($file) ) {
720
				// try to unlink file
721
				if(!is_writable( $file ) || !unlink($file)) {
722
					// save in err-list, if failed
723
					$msg .= $file.'<br />';
724
				}
725
			}
726
		}
727

    
728
		if($msg != '')
729
		{
730
			$msg = '<br /><br />Following files are deprecated, outdated or a security risk and
731
				    can not be removed automatically.<br /><br />Please delete them
732
					using FTP and restart upgrade-script!<br /><br />'.$msg.'<br />';
733
	        status_msg($msg, 'error warning', 'div');
734
			echo '<p style="font-size:120%;"><strong>WARNING: The upgrade script failed ...</strong></p>';
735

    
736
			echo '<form action="'.$_SERVER['SCRIPT_NAME'].'">';
737
			echo '&nbsp;<input name="send" type="submit" value="Restart upgrade script" />';
738
			echo '</form>';
739
			echo '<br /><br /></div></body></html>';
740
			exit;
741
		}
742
	}
743

    
744

    
745
/**********************************************************
746
 * - check for deprecated / never needed files
747
 */
748
	if(sizeof($dirRemove)) {
749
		echo '<h3>Step  '.(++$stepID).': Remove deprecated and old folders</h3>';
750
		$searches = array(
751
			'[ADMIN]',
752
			'[MEDIA]',
753
			'[PAGES]',
754
			'[TEMPLATE]'
755
		);
756
		$replacements = array(
757
			substr(ADMIN_PATH, strlen(WB_PATH)+1),
758
			MEDIA_DIRECTORY,
759
			PAGES_DIRECTORY,
760
			'/templates',
761
		);
762
		$msg = '';
763
		foreach( $dirRemove as $dir ) {
764
			$dir = str_replace($searches, $replacements, $dir);
765
			$dir = WB_PATH.'/'.$dir;
766
			if( is_dir( $dir )) {
767
			// try to delete dir
768
				if(!is_writable( $dir ) || !rm_full_dir($dir)) {
769
				// save in err-list, if failed
770
					$msg .= str_replace(WB_PATH,'',$dir).'<br />';
771
				}
772
			}
773
		}
774
		if($msg != '') {
775
			$msg = '<br /><br />Following directories are deprecated, outdated or a security risk and
776
					can not be removed automatically.<br /><br />Please delete them
777
					using FTP and restart upgrade-script!<br /><br />'.$msg.'<br />';
778
			status_msg($msg, 'error warning', 'div');
779
			echo '<p style="font-size:120%;"><strong>WARNING: The upgrade script failed ...</strong></p>';
780
			echo '<form action="'.$_SERVER['SCRIPT_NAME'].'">';
781
			echo '&nbsp;<input name="send" type="submit" value="Restart upgrade script" />';
782
			echo '</form>';
783
			echo '<br /><br /></div></body></html>';
784
			exit;
785
		}
786
	}
787

    
788
/**********************************************************
789
 * upgrade modules if newer version is available
790
 */
791
	$aModuleList = array('news');
792
	foreach($aModuleList as $sModul) {
793
		if(file_exists(WB_PATH.'/modules/'.$sModul.'/upgrade.php')) {
794
			$currModulVersion = get_modul_version ($sModul, false);
795
			$newModulVersion =  get_modul_version ($sModul, true);
796
			if((version_compare($currModulVersion, $newModulVersion) <= 0)) {
797
				echo '<h3>Step '.(++$stepID).' : Upgrade module \''.$sModul.'\' to version '.$newModulVersion.'</h3>';
798
				require_once(WB_PATH.'/modules/'.$sModul.'/upgrade.php');
799
			}
800
		}
801
	}
802
/**********************************************************
803
 *  - Reload all addons
804
 */
805

    
806
	echo '<h3>Step '.(++$stepID).' : Reload all addons database entry (no upgrade)</h3>';
807
	////delete modules
808
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'module'");
809
	// Load all modules
810
	if( ($handle = opendir(WB_PATH.'/modules/')) ) {
811
		while(false !== ($file = readdir($handle))) {
812
			if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'admin.php' AND $file != 'index.php') {
813
				load_module(WB_PATH.'/modules/'.$file );
814
			   // 	upgrade_module($file, true);
815
			}
816
		}
817
		closedir($handle);
818
	}
819
	echo '<br />Modules reloaded<br />';
820

    
821
	////delete templates
822
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'template'");
823
	// Load all templates
824
	if( ($handle = opendir(WB_PATH.'/templates/')) ) {
825
		while(false !== ($file = readdir($handle))) {
826
			if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
827
				load_template(WB_PATH.'/templates/'.$file);
828
			}
829
		}
830
		closedir($handle);
831
	}
832
	echo '<br />Templates reloaded<br />';
833

    
834
	////delete languages
835
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'language'");
836
	// Load all languages
837
	if( ($handle = opendir(WB_PATH.'/languages/')) ) {
838
		while(false !== ($file = readdir($handle))) {
839
			if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
840
				load_language(WB_PATH.'/languages/'.$file);
841
			}
842
		}
843
		closedir($handle);
844
	}
845
	echo '<br />Languages reloaded<br />';
846

    
847
/**********************************************************
848
 *  - install new droplets
849
	$drops = (!in_array ( "mod_droplets", $all_tables)) ? "<br />Install droplets<br />" : "<br />Upgrade droplets<br />";
850
	echo $drops;
851
	$file_name = (!in_array ( "mod_droplets", $all_tables) ? "install.php" : "upgrade.php");
852
	require_once (WB_PATH."/modules/droplets/".$file_name);
853
********************************************************** */
854

    
855
/**********************************************************
856
 *  - End of upgrade script
857
 */
858
	if(!defined('DEFAULT_THEME')) { define('DEFAULT_THEME', $DEFAULT_THEME); }
859
	if(!defined('THEME_PATH')) { define('THEME_PATH', WB_PATH.'/templates/'.DEFAULT_THEME);}
860
/**********************************************************
861
 *  - Set Version to new Version
862
 */
863
echo '<br />Update database version number to '.VERSION.' '.SP.' '.' Revision ['.REVISION.'] : ';
864

    
865
$cfg = array(
866
	'wb_version' => VERSION,
867
	'wb_revision' => REVISION,
868
	'wb_sp' => SP
869
);
870

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

    
873
	echo '<p style="font-size:120%;"><strong>Congratulations: The upgrade script is finished ...</strong></p>';
874
	status_msg('<strong>Warning:</strong><br />Please delete the file <strong>upgrade-script.php</strong> via FTP before proceeding.', 'warning', 'div');
875
	// show buttons to go to the backend or frontend
876
	echo '<br />';
877

    
878
	if(defined('WB_URL')) {
879
		echo '<form action="'.WB_URL.'/">';
880
		echo '&nbsp;<input type="submit" value="kick me to the Frontend" />';
881
		echo '</form>';
882
	}
883
	if(defined('ADMIN_URL')) {
884
		echo '<form action="'.ADMIN_URL.'/">';
885
		echo '&nbsp;<input type="submit" value="kick me to the Backend" />';
886
		echo '</form>';
887
	}
888

    
889
	echo '<br /><br /></div></body></html>';
(5-5/5)